Laserlicht 2 éve
szülő
commit
7217992898

+ 26 - 6
client/lobby/OptionsTab.cpp

@@ -1041,7 +1041,7 @@ void OptionsTab::SelectedBox::scrollBy(int distance)
 }
 
 OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parent)
-	: CIntObject(KEYBOARD | TEXTINPUT)
+	: CIntObject(LCLICK | KEYBOARD | TEXTINPUT)
 	, pi(std::make_unique<PlayerInfo>(SEL->getPlayerInfo(S.color)))
 	, s(std::make_unique<PlayerSettings>(S))
 	, parentTab(parent)
@@ -1132,14 +1132,34 @@ void OptionsTab::PlayerOptionsEntry::keyPressed(EShortcut key)
 	if(labelPlayerNameEdit)
 	{
 		if(key == EShortcut::GLOBAL_ACCEPT)
-		{
-			CSH->setPlayerName(s->color, labelPlayerNameEdit->getText());
-			Settings name = settings.write["general"]["playerName"];
-			name->String() = labelPlayerNameEdit->getText();
-		}
+			changeName();
 	}
 }
 
+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) && labelPlayerNameEdit->hasFocus())
+	{
+		changeName();
+	}
+}
+
+void OptionsTab::PlayerOptionsEntry::changeName() {
+	if(settings["general"]["playerName"].String() != labelPlayerNameEdit->getText())
+	{
+		CSH->setPlayerName(s->color, labelPlayerNameEdit->getText());
+		Settings set = settings.write["general"]["playerName"];
+		set->String() = labelPlayerNameEdit->getText();
+	}
+
+	labelPlayerNameEdit->removeFocus();
+}
+
 void OptionsTab::onSetPlayerClicked(const PlayerSettings & ps) const
 {
 	if(ps.isControlledByAI() || humanPlayers > 0)

+ 4 - 0
client/lobby/OptionsTab.h

@@ -189,8 +189,12 @@ private:
 		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;
+
+		void changeName();
 	};
 };

+ 9 - 0
client/widgets/TextControls.cpp

@@ -806,3 +806,12 @@ void CFocusable::moveFocus()
 		}
 	}
 }
+
+void CFocusable::removeFocus()
+{
+	focus = false;
+	focusListener->focusLost();
+	redraw();
+
+	inputWithFocus = nullptr;
+}

+ 1 - 0
client/widgets/TextControls.h

@@ -184,6 +184,7 @@ public:
 
 	void giveFocus(); //captures focus
 	void moveFocus(); //moves focus to next active control (may be used for tab switching)
+	void removeFocus(); //remove focus
 	bool hasFocus() const;
 
 	static std::list<CFocusable *> focusables; //all existing objs