|
@@ -1041,9 +1041,11 @@ void OptionsTab::SelectedBox::scrollBy(int distance)
|
|
}
|
|
}
|
|
|
|
|
|
OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parent)
|
|
OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parent)
|
|
- : pi(std::make_unique<PlayerInfo>(SEL->getPlayerInfo(S.color)))
|
|
|
|
|
|
+ : CIntObject(LCLICK | KEYBOARD | TEXTINPUT)
|
|
|
|
+ , pi(std::make_unique<PlayerInfo>(SEL->getPlayerInfo(S.color)))
|
|
, s(std::make_unique<PlayerSettings>(S))
|
|
, s(std::make_unique<PlayerSettings>(S))
|
|
, parentTab(parent)
|
|
, parentTab(parent)
|
|
|
|
+ , name(S.name)
|
|
{
|
|
{
|
|
OBJ_CONSTRUCTION;
|
|
OBJ_CONSTRUCTION;
|
|
defActions |= SHARE_POS;
|
|
defActions |= SHARE_POS;
|
|
@@ -1081,7 +1083,13 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
|
}};
|
|
}};
|
|
|
|
|
|
background = std::make_shared<CPicture>(ImagePath::builtin(bgs[s->color]), 0, 0);
|
|
background = std::make_shared<CPicture>(ImagePath::builtin(bgs[s->color]), 0, 0);
|
|
- labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, s->name);
|
|
|
|
|
|
+ if(s->isControlledByAI() || CSH->isGuest())
|
|
|
|
+ labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name);
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, nullptr, false);
|
|
|
|
+ labelPlayerNameEdit->setText(name);
|
|
|
|
+ }
|
|
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
|
|
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
|
|
|
|
|
|
if(SEL->screenType == ESelectionScreen::newGame)
|
|
if(SEL->screenType == ESelectionScreen::newGame)
|
|
@@ -1115,6 +1123,43 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
|
bonus = std::make_shared<SelectedBox>(Point(271, 2), *s, BONUS);
|
|
bonus = std::make_shared<SelectedBox>(Point(271, 2), *s, BONUS);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool OptionsTab::PlayerOptionsEntry::captureThisKey(EShortcut key)
|
|
|
|
+{
|
|
|
|
+ return labelPlayerNameEdit && labelPlayerNameEdit->hasFocus() && key == EShortcut::GLOBAL_ACCEPT;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void OptionsTab::PlayerOptionsEntry::keyPressed(EShortcut key)
|
|
|
|
+{
|
|
|
|
+ if(labelPlayerNameEdit && key == EShortcut::GLOBAL_ACCEPT)
|
|
|
|
+ updateName();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool OptionsTab::PlayerOptionsEntry::receiveEvent(const Point & position, int eventType) const
|
|
|
|
+{
|
|
|
|
+ return eventType == AEventsReceiver::LCLICK; // capture all left clicks (not only within control)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void OptionsTab::PlayerOptionsEntry::clickReleased(const Point & cursorPosition)
|
|
|
|
+{
|
|
|
|
+ if(labelPlayerNameEdit && !labelPlayerNameEdit->pos.isInside(cursorPosition))
|
|
|
|
+ updateName();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void OptionsTab::PlayerOptionsEntry::updateName() {
|
|
|
|
+ if(labelPlayerNameEdit->getText() != name)
|
|
|
|
+ {
|
|
|
|
+ CSH->setPlayerName(s->color, labelPlayerNameEdit->getText());
|
|
|
|
+ if(CSH->isMyColor(s->color))
|
|
|
|
+ {
|
|
|
|
+ Settings set = settings.write["general"]["playerName"];
|
|
|
|
+ set->String() = labelPlayerNameEdit->getText();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ labelPlayerNameEdit->removeFocus();
|
|
|
|
+ name = labelPlayerNameEdit->getText();
|
|
|
|
+}
|
|
|
|
+
|
|
void OptionsTab::onSetPlayerClicked(const PlayerSettings & ps) const
|
|
void OptionsTab::onSetPlayerClicked(const PlayerSettings & ps) const
|
|
{
|
|
{
|
|
if(ps.isControlledByAI() || humanPlayers > 0)
|
|
if(ps.isControlledByAI() || humanPlayers > 0)
|