diff --git a/client/CMT.cpp b/client/CMT.cpp index e11c76b17..f85fd029c 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -54,7 +54,7 @@ #include #ifdef VCMI_WINDOWS -#include "SDL_syswm.h" +#include #endif #ifdef VCMI_ANDROID #include "lib/CAndroidVMHelper.h" @@ -949,7 +949,7 @@ static void handleEvent(SDL_Event & ev) } else if(ev.type == SDL_USEREVENT) { - switch(ev.user.code) + switch(static_cast(ev.user.code)) { case EUserEvent::FORCE_QUIT: { @@ -1050,7 +1050,7 @@ static void handleEvent(SDL_Event & ev) static void mainLoop() { SettingsListener resChanged = settings.listen["video"]["fullscreen"]; - resChanged([](const JsonNode &newState){ CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::FULLSCREEN_TOGGLED); }); + resChanged([](const JsonNode &newState){ CGuiHandler::pushUserEvent(EUserEvent::FULLSCREEN_TOGGLED); }); inGuiThread.reset(new bool(true)); GH.mainFPSmng->init(); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index ac10fb62a..246681a95 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -2139,12 +2139,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won) if(won && cb->getStartInfo()->campState) CSH->startCampaignScenario(cb->getStartInfo()->campState); else - sendCustomEvent(EUserEvent::RETURN_TO_MAIN_MENU); -} - -void CPlayerInterface::sendCustomEvent( int code ) -{ - CGuiHandler::pushSDLEvent(SDL_USEREVENT, code); + GH.pushUserEvent(EUserEvent::RETURN_TO_MAIN_MENU); } void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al) @@ -2268,7 +2263,7 @@ void CPlayerInterface::waitForAllDialogs(bool unlockPim) void CPlayerInterface::proposeLoadingGame() { - showYesNoDialog(CGI->generaltexth->allTexts[68], [this](){ sendCustomEvent(EUserEvent::RETURN_TO_MENU_LOAD); }, nullptr); + showYesNoDialog(CGI->generaltexth->allTexts[68], [this](){ GH.pushUserEvent(EUserEvent::RETURN_TO_MENU_LOAD); }, nullptr); } CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting() diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 65c769032..febf9748f 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -240,7 +240,6 @@ public: void tryDiggging(const CGHeroInstance *h); void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard; void requestReturningToMainMenu(bool won); - void sendCustomEvent(int code); void proposeLoadingGame(); // Ambient sounds diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 1f1836119..a34fd9204 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -657,7 +657,7 @@ void CServerHandler::startCampaignScenario(std::shared_ptr cs) { SDL_Event event; event.type = SDL_USEREVENT; - event.user.code = EUserEvent::CAMPAIGN_START_SCENARIO; + event.user.code = static_cast(EUserEvent::CAMPAIGN_START_SCENARIO); if(cs) event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release(); else @@ -824,7 +824,7 @@ void CServerHandler::threadHandleConnection() if(client) { state = EClientState::DISCONNECTING; - CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU); + CGuiHandler::pushUserEvent(EUserEvent::RETURN_TO_MAIN_MENU); } else { diff --git a/client/adventureMap/CAdvMapInt.cpp b/client/adventureMap/CAdvMapInt.cpp index 9bea0cf0a..db776f95e 100644 --- a/client/adventureMap/CAdvMapInt.cpp +++ b/client/adventureMap/CAdvMapInt.cpp @@ -792,7 +792,7 @@ void CAdvMapInt::keyDown(const SDL_Keycode & key) if(isActive() && GH.isKeyboardCtrlDown()) { LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"), - [](){ LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME); }, nullptr); + [](){ GH.pushUserEvent(EUserEvent::RESTART_GAME); }, nullptr); } return; case SDLK_SPACE: //space - try to revisit current object with selected hero diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index 6c9ca0c21..e98ebab85 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -118,7 +118,7 @@ void CGuiHandler::popInt(std::shared_ptr top) listInt.front()->activate(); totalRedraw(); - pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED); + pushUserEvent(EUserEvent::INTERFACE_CHANGED); } void CGuiHandler::pushInt(std::shared_ptr newInt) @@ -137,7 +137,7 @@ void CGuiHandler::pushInt(std::shared_ptr newInt) objsToBlit.push_back(newInt); totalRedraw(); - pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED); + pushUserEvent(EUserEvent::INTERFACE_CHANGED); } void CGuiHandler::popInts(int howMany) @@ -160,7 +160,7 @@ void CGuiHandler::popInts(int howMany) } fakeMouseMove(); - pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED); + pushUserEvent(EUserEvent::INTERFACE_CHANGED); } std::shared_ptr CGuiHandler::topInt() @@ -825,11 +825,11 @@ bool CGuiHandler::amIGuiThread() return inGuiThread.get() && *inGuiThread; } -void CGuiHandler::pushSDLEvent(int type, int usercode) +void CGuiHandler::pushUserEvent(EUserEvent usercode) { SDL_Event event; - event.type = type; - event.user.code = usercode; // not necessarily used + event.type = SDL_USEREVENT; + event.user.code = static_cast(usercode); SDL_PushEvent(&event); } diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index 84905d2a6..d71d44e2a 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -32,7 +32,7 @@ class IShowActivatable; class IShowable; // TODO: event handling need refactoring -enum EUserEvent +enum class EUserEvent { /*CHANGE_SCREEN_RESOLUTION = 1,*/ RETURN_TO_MAIN_MENU = 2, @@ -176,7 +176,7 @@ public: static bool isNumKey(SDL_Keycode key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) static bool isArrowKey(SDL_Keycode key); static bool amIGuiThread(); - static void pushSDLEvent(int type, int usercode = 0); + static void pushUserEvent(EUserEvent usercode); CondSh * terminate_cond; // confirm termination }; diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index 9bcf406ae..099e66feb 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -454,7 +454,7 @@ void CBonusSelection::restartMap() close(); LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]() { - LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME); + GH.pushUserEvent(EUserEvent::RESTART_GAME); }, 0); } diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 4caefc5b2..a21464559 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -63,7 +63,7 @@ #include "../lib/NetPacksBase.h" #include "../lib/StartInfo.h" -#include +#include using namespace CSDL_Ext; @@ -610,7 +610,7 @@ void CSystemOptionsWindow::setGameRes(int index) void CSystemOptionsWindow::bquitf() { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::FORCE_QUIT); }, 0); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::FORCE_QUIT); }, 0); } void CSystemOptionsWindow::breturnf() @@ -620,7 +620,7 @@ void CSystemOptionsWindow::breturnf() void CSystemOptionsWindow::bmainmenuf() { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU); }, 0); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this](){ closeAndPushEvent(EUserEvent::RETURN_TO_MAIN_MENU); }, 0); } void CSystemOptionsWindow::bloadf() @@ -637,13 +637,13 @@ void CSystemOptionsWindow::bsavef() void CSystemOptionsWindow::brestartf() { - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(SDL_USEREVENT, EUserEvent::RESTART_GAME); }, 0); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [this](){ closeAndPushEvent(EUserEvent::RESTART_GAME); }, 0); } -void CSystemOptionsWindow::closeAndPushEvent(int eventType, int code) +void CSystemOptionsWindow::closeAndPushEvent(EUserEvent code) { close(); - GH.pushSDLEvent(eventType, code); + GH.pushUserEvent(code); } CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj) diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index 62252fb14..17ed2542d 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -43,6 +43,8 @@ class CTextBox; class CResDataBar; class CHeroWithMaybePickedArtifact; +enum class EUserEvent; + /// Recruitment window where you can recruit creatures class CRecruitmentWindow : public CStatusbarWindow { @@ -234,7 +236,7 @@ private: void selectGameRes(); void setGameRes(int index); - void closeAndPushEvent(int eventType, int code = 0); + void closeAndPushEvent(EUserEvent code); public: CSystemOptionsWindow();