From 6db3c5bc7e7786fd9962a7a13caa7a6501f1511c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 11 Mar 2012 16:29:01 +0000 Subject: [PATCH] * VCAI: can't request actions from action handling thread * Save game screen and returning to main menu will work if game was started with --start option * GUI controls can selectively capture keyboard events. CTextInput won't capture Enter. Fixes #654. --- AI/VCAI/VCAI.cpp | 4 +++- client/CMT.cpp | 1 + client/CPreGame.cpp | 10 +++++++++- client/CPreGame.h | 2 ++ client/UIFramework/CGuiHandler.cpp | 4 ++-- client/UIFramework/CIntObject.cpp | 5 +++++ client/UIFramework/CIntObject.h | 1 + client/UIFramework/CIntObjectClasses.cpp | 8 ++++++++ client/UIFramework/CIntObjectClasses.h | 8 +++++--- 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 47feef9a5..7f31e6bb9 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -788,7 +788,9 @@ void VCAI::showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *do NET_EVENT_HANDLER; LOG_ENTRY; status.addQuery(); - pickBestCreatures (down, up); + + //you can't request action from action-response thread + //pickBestCreatures (down, up); onEnd(); } diff --git a/client/CMT.cpp b/client/CMT.cpp index f765e685a..6e3aaee9e 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -716,6 +716,7 @@ static void listenForEvents() const_cast(CGI)->dobjinfo = new CDefObjInfoHandler; const_cast(CGI)->dobjinfo->load(); + CGPreGame::createIfNotPresent(); GH.curInt = CGP; GH.defActionsDef = 63; break; diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index d00001e56..5c2b0866e 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -401,10 +401,12 @@ CGPreGame::CGPreGame(): GH.defActionsDef = 63; CGP = this; menu = new CMenuScreen((*pregameConfig)["window"]); + loadGraphics(); } CGPreGame::~CGPreGame() { + disposeGraphics(); } void CGPreGame::openSel(CMenuScreen::EState screenType, CMenuScreen::EMultiMode multi /*= CMenuScreen::SINGLE_PLAYER*/) @@ -475,10 +477,17 @@ void CGPreGame::openCampaignScreen(std::string name) tlog1<<"Unknown campaign set: "< *Names /*= NULL*/) : ISelectionScreenInfo(Names), serverHandlingThread(NULL), mx(new boost::recursive_mutex), serv(NULL), ongoingClosing(false), myNameID(255) { + CGPreGame::createIfNotPresent(); //we depend on its graphics screenType = Type; multiPlayer = MultiPlayer; @@ -514,7 +523,6 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti bg = new CPicture(BitmapHandler::loadBitmap(rand()%2 ? "ZPIC1000.bmp" : "ZPIC1001.bmp"), -3, -6, true); } - CGP->loadGraphics(); sInfo.difficulty = 1; current = NULL; diff --git a/client/CPreGame.h b/client/CPreGame.h index b40d850ff..2cf12f0df 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -501,6 +501,8 @@ public: void disposeGraphics(); void openCampaignScreen(std::string name); + + static void createIfNotPresent(); }; extern ISelectionScreenInfo *SEL; diff --git a/client/UIFramework/CGuiHandler.cpp b/client/UIFramework/CGuiHandler.cpp index 965260063..c4aaad6e1 100644 --- a/client/UIFramework/CGuiHandler.cpp +++ b/client/UIFramework/CGuiHandler.cpp @@ -168,7 +168,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) bool keysCaptured = false; for(std::list::iterator i=keyinterested.begin(); i != keyinterested.end() && current; i++) { - if((*i)->captureAllKeys) + if((*i)->captureThisEvent(key)) { keysCaptured = true; break; @@ -177,7 +177,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) std::list miCopy = keyinterested; for(std::list::iterator i=miCopy.begin(); i != miCopy.end() && current; i++) - if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys)) + if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureThisEvent(key))) (**i).keyPressed(key); } else if(sEvent->type==SDL_MOUSEMOTION) diff --git a/client/UIFramework/CIntObject.cpp b/client/UIFramework/CIntObject.cpp index f9ecf7df4..a6ec1090e 100644 --- a/client/UIFramework/CIntObject.cpp +++ b/client/UIFramework/CIntObject.cpp @@ -442,6 +442,11 @@ const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/) return pos; } +bool CIntObject::captureThisEvent(const SDL_KeyboardEvent & key) +{ + return captureAllKeys; +} + void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key) { if(vstd::contains(assignedKeys,key.keysym.sym)) diff --git a/client/UIFramework/CIntObject.h b/client/UIFramework/CIntObject.h index 670be2281..06f37a010 100644 --- a/client/UIFramework/CIntObject.h +++ b/client/UIFramework/CIntObject.h @@ -104,6 +104,7 @@ public: void activateKeys(); void deactivateKeys(); virtual void keyPressed(const SDL_KeyboardEvent & key); + virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER) //mouse movement handling bool strongInterest; //if true - report all mouse movements, if not - only when hovered diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp index 3b8558b87..b5f109eb9 100644 --- a/client/UIFramework/CIntObjectClasses.cpp +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -1470,6 +1470,14 @@ CTextInput::~CTextInput() { } +bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key) +{ + if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER) + return false; + + return true; +} + CFocusable::CFocusable() { focusables.push_back(this); diff --git a/client/UIFramework/CIntObjectClasses.h b/client/UIFramework/CIntObjectClasses.h index 260e36bc6..c9646b216 100644 --- a/client/UIFramework/CIntObjectClasses.h +++ b/client/UIFramework/CIntObjectClasses.h @@ -405,9 +405,11 @@ public: CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList &CB); CTextInput(const Rect &Pos, SDL_Surface *srf = NULL); ~CTextInput(); - void showAll(SDL_Surface * to); - void clickLeft(tribool down, bool previousState); - void keyPressed(const SDL_KeyboardEvent & key); + + void showAll(SDL_Surface * to) OVERRIDE; + void clickLeft(tribool down, bool previousState) OVERRIDE; + void keyPressed(const SDL_KeyboardEvent & key) OVERRIDE; + bool captureThisEvent(const SDL_KeyboardEvent & key) OVERRIDE; }; /// Listbox UI Element