1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

small refactoring

This commit is contained in:
Laserlicht
2025-10-05 02:03:18 +02:00
parent e6272fe477
commit 115d90cbb3
2 changed files with 3 additions and 33 deletions

View File

@@ -1035,10 +1035,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
if(s->isControlledByAI() || GAME->server().isGuest())
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name, 95);
else
{
labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, ETextAlignment::CENTER, false);
labelPlayerNameEdit->setText(name);
}
labelPlayerNameEdit = std::make_shared<CTextInputWithConfirm>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, ETextAlignment::CENTER, name, false, [this](){ updateName(); });
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 21, 45, 26), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->arraytxt[206 + whoCanPlay]);
@@ -1114,28 +1111,6 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
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)
{
@@ -1146,8 +1121,6 @@ void OptionsTab::PlayerOptionsEntry::updateName() {
set->String() = labelPlayerNameEdit->getText();
}
}
labelPlayerNameEdit->removeFocus();
name = labelPlayerNameEdit->getText();
}