mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
small refactoring
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class CTextBox;
|
||||
class CButton;
|
||||
class CSlider;
|
||||
class LRClickableArea;
|
||||
class CTextInputWithConfirm;
|
||||
|
||||
class FilledTexturePlayerColored;
|
||||
class TransparentFilledRectangle;
|
||||
@@ -196,7 +197,7 @@ private:
|
||||
std::unique_ptr<PlayerInfo> pi;
|
||||
std::unique_ptr<PlayerSettings> s;
|
||||
std::shared_ptr<CLabel> labelPlayerName;
|
||||
std::shared_ptr<CTextInput> labelPlayerNameEdit;
|
||||
std::shared_ptr<CTextInputWithConfirm> labelPlayerNameEdit;
|
||||
std::shared_ptr<CMultiLineLabel> labelWhoCanPlay;
|
||||
std::shared_ptr<CPicture> background;
|
||||
std::shared_ptr<CButton> buttonTownLeft;
|
||||
@@ -215,10 +216,6 @@ private:
|
||||
|
||||
PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
|
||||
void hideUnavailableButtons();
|
||||
bool captureThisKey(EShortcut key) override;
|
||||
void keyPressed(EShortcut key) override;
|
||||
void clickReleased(const Point & cursorPosition) override;
|
||||
bool receiveEvent(const Point & position, int eventType) const override;
|
||||
|
||||
private:
|
||||
const OptionsTab & parentTab;
|
||||
|
||||
Reference in New Issue
Block a user