mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	code review
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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(); | ||||
| 	}; | ||||
| }; | ||||
|   | ||||
| @@ -806,3 +806,12 @@ void CFocusable::moveFocus() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CFocusable::removeFocus() | ||||
| { | ||||
| 	focus = false; | ||||
| 	focusListener->focusLost(); | ||||
| 	redraw(); | ||||
|  | ||||
| 	inputWithFocus = nullptr; | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user