mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Added right click pop-up for text inputs
This commit is contained in:
		| @@ -565,6 +565,8 @@ std::shared_ptr<CTextInput> InterfaceObjectConfigurable::buildTextInput(const Js | |||||||
| 		result->setText(readText(config["text"])); | 		result->setText(readText(config["text"])); | ||||||
| 	if(!config["callback"].isNull()) | 	if(!config["callback"].isNull()) | ||||||
| 		result->cb += callbacks_string.at(config["callback"].String()); | 		result->cb += callbacks_string.at(config["callback"].String()); | ||||||
|  | 	if(!config["help"].isNull()) | ||||||
|  | 		result->helpBox = readText(config["help"]); | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -61,7 +61,7 @@ OptionsTab::OptionsTab() : humanPlayers(0) | |||||||
| 	auto parseTimerString = [](const std::string & str){ | 	auto parseTimerString = [](const std::string & str){ | ||||||
| 		auto sc = str.find(":"); | 		auto sc = str.find(":"); | ||||||
| 		if(sc == std::string::npos) | 		if(sc == std::string::npos) | ||||||
| 			return std::stoi(str); | 			return str.empty() ? 0 : std::stoi(str); | ||||||
| 		 | 		 | ||||||
| 		auto l = str.substr(0, sc); | 		auto l = str.substr(0, sc); | ||||||
| 		auto r = str.substr(sc + 1, std::string::npos); | 		auto r = str.substr(sc + 1, std::string::npos); | ||||||
| @@ -75,6 +75,8 @@ OptionsTab::OptionsTab() : humanPlayers(0) | |||||||
| 			r.insert(r.begin(), l.back()); | 			r.insert(r.begin(), l.back()); | ||||||
| 			l.pop_back(); | 			l.pop_back(); | ||||||
| 		} | 		} | ||||||
|  | 		else if(r.empty()) | ||||||
|  | 			r = "0"; | ||||||
| 		 | 		 | ||||||
| 		int sec = std::stoi(r); | 		int sec = std::stoi(r); | ||||||
| 		if(sec >= 60) | 		if(sec >= 60) | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ | |||||||
| #include "../gui/CGuiHandler.h" | #include "../gui/CGuiHandler.h" | ||||||
| #include "../gui/Shortcut.h" | #include "../gui/Shortcut.h" | ||||||
| #include "../windows/CMessage.h" | #include "../windows/CMessage.h" | ||||||
|  | #include "../windows/InfoWindows.h" | ||||||
| #include "../adventureMap/CInGameConsole.h" | #include "../adventureMap/CInGameConsole.h" | ||||||
| #include "../renderSDL/SDL_Extensions.h" | #include "../renderSDL/SDL_Extensions.h" | ||||||
| #include "../render/Canvas.h" | #include "../render/Canvas.h" | ||||||
| @@ -495,7 +496,7 @@ CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(c | |||||||
| 	pos.h = Pos.h; | 	pos.h = Pos.h; | ||||||
| 	pos.w = Pos.w; | 	pos.w = Pos.w; | ||||||
| 	background.reset(); | 	background.reset(); | ||||||
| 	addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT); | 	addUsedEvents(LCLICK | SHOW_POPUP | KEYBOARD | TEXTINPUT); | ||||||
|  |  | ||||||
| #if !defined(VCMI_MOBILE) | #if !defined(VCMI_MOBILE) | ||||||
| 	giveFocus(); | 	giveFocus(); | ||||||
| @@ -511,7 +512,7 @@ CTextInput::CTextInput(const Rect & Pos, const Point & bgOffset, const std::stri | |||||||
|  |  | ||||||
| 	OBJ_CONSTRUCTION; | 	OBJ_CONSTRUCTION; | ||||||
| 	background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y); | 	background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y); | ||||||
| 	addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT); | 	addUsedEvents(LCLICK | SHOW_POPUP | KEYBOARD | TEXTINPUT); | ||||||
|  |  | ||||||
| #if !defined(VCMI_MOBILE) | #if !defined(VCMI_MOBILE) | ||||||
| 	giveFocus(); | 	giveFocus(); | ||||||
| @@ -604,6 +605,13 @@ void CTextInput::keyPressed(EShortcut key) | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void CTextInput::showPopupWindow(const Point & cursorPosition) | ||||||
|  | { | ||||||
|  | 	if(helpBox.size()) //there is no point to show window with nothing inside... | ||||||
|  | 		CRClickPopup::createAndPush(helpBox); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void CTextInput::setText(const std::string & nText) | void CTextInput::setText(const std::string & nText) | ||||||
| { | { | ||||||
| 	setText(nText, false); | 	setText(nText, false); | ||||||
|   | |||||||
| @@ -213,6 +213,8 @@ protected: | |||||||
| 	std::string visibleText() override; | 	std::string visibleText() override; | ||||||
|  |  | ||||||
| public: | public: | ||||||
|  | 	std::string helpBox; //for right-click help | ||||||
|  | 	 | ||||||
| 	CFunctionList<void(const std::string &)> cb; | 	CFunctionList<void(const std::string &)> cb; | ||||||
| 	CFunctionList<void(std::string &, const std::string &)> filters; | 	CFunctionList<void(std::string &, const std::string &)> filters; | ||||||
| 	void setText(const std::string & nText) override; | 	void setText(const std::string & nText) override; | ||||||
| @@ -224,6 +226,7 @@ public: | |||||||
|  |  | ||||||
| 	void clickPressed(const Point & cursorPosition) override; | 	void clickPressed(const Point & cursorPosition) override; | ||||||
| 	void keyPressed(EShortcut key) override; | 	void keyPressed(EShortcut key) override; | ||||||
|  | 	void showPopupWindow(const Point & cursorPosition) override; | ||||||
|  |  | ||||||
| 	//bool captureThisKey(EShortcut key) override; | 	//bool captureThisKey(EShortcut key) override; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user