mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
API for custom events no longer requires SDL access
This commit is contained in:
parent
d4fba3787c
commit
e1bd0d2a04
@ -54,7 +54,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#ifdef VCMI_WINDOWS
|
#ifdef VCMI_WINDOWS
|
||||||
#include "SDL_syswm.h"
|
#include <SDL_syswm.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef VCMI_ANDROID
|
#ifdef VCMI_ANDROID
|
||||||
#include "lib/CAndroidVMHelper.h"
|
#include "lib/CAndroidVMHelper.h"
|
||||||
@ -949,7 +949,7 @@ static void handleEvent(SDL_Event & ev)
|
|||||||
}
|
}
|
||||||
else if(ev.type == SDL_USEREVENT)
|
else if(ev.type == SDL_USEREVENT)
|
||||||
{
|
{
|
||||||
switch(ev.user.code)
|
switch(static_cast<EUserEvent>(ev.user.code))
|
||||||
{
|
{
|
||||||
case EUserEvent::FORCE_QUIT:
|
case EUserEvent::FORCE_QUIT:
|
||||||
{
|
{
|
||||||
@ -1050,7 +1050,7 @@ static void handleEvent(SDL_Event & ev)
|
|||||||
static void mainLoop()
|
static void mainLoop()
|
||||||
{
|
{
|
||||||
SettingsListener resChanged = settings.listen["video"]["fullscreen"];
|
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));
|
inGuiThread.reset(new bool(true));
|
||||||
GH.mainFPSmng->init();
|
GH.mainFPSmng->init();
|
||||||
|
@ -2139,12 +2139,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won)
|
|||||||
if(won && cb->getStartInfo()->campState)
|
if(won && cb->getStartInfo()->campState)
|
||||||
CSH->startCampaignScenario(cb->getStartInfo()->campState);
|
CSH->startCampaignScenario(cb->getStartInfo()->campState);
|
||||||
else
|
else
|
||||||
sendCustomEvent(EUserEvent::RETURN_TO_MAIN_MENU);
|
GH.pushUserEvent(EUserEvent::RETURN_TO_MAIN_MENU);
|
||||||
}
|
|
||||||
|
|
||||||
void CPlayerInterface::sendCustomEvent( int code )
|
|
||||||
{
|
|
||||||
CGuiHandler::pushSDLEvent(SDL_USEREVENT, code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
|
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
|
||||||
@ -2268,7 +2263,7 @@ void CPlayerInterface::waitForAllDialogs(bool unlockPim)
|
|||||||
|
|
||||||
void CPlayerInterface::proposeLoadingGame()
|
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()
|
CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
|
||||||
|
@ -240,7 +240,6 @@ public:
|
|||||||
void tryDiggging(const CGHeroInstance *h);
|
void tryDiggging(const CGHeroInstance *h);
|
||||||
void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
|
void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
|
||||||
void requestReturningToMainMenu(bool won);
|
void requestReturningToMainMenu(bool won);
|
||||||
void sendCustomEvent(int code);
|
|
||||||
void proposeLoadingGame();
|
void proposeLoadingGame();
|
||||||
|
|
||||||
// Ambient sounds
|
// Ambient sounds
|
||||||
|
@ -657,7 +657,7 @@ void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
|
|||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = SDL_USEREVENT;
|
event.type = SDL_USEREVENT;
|
||||||
event.user.code = EUserEvent::CAMPAIGN_START_SCENARIO;
|
event.user.code = static_cast<int32_t>(EUserEvent::CAMPAIGN_START_SCENARIO);
|
||||||
if(cs)
|
if(cs)
|
||||||
event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
|
event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
|
||||||
else
|
else
|
||||||
@ -824,7 +824,7 @@ void CServerHandler::threadHandleConnection()
|
|||||||
if(client)
|
if(client)
|
||||||
{
|
{
|
||||||
state = EClientState::DISCONNECTING;
|
state = EClientState::DISCONNECTING;
|
||||||
CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU);
|
CGuiHandler::pushUserEvent(EUserEvent::RETURN_TO_MAIN_MENU);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -792,7 +792,7 @@ void CAdvMapInt::keyDown(const SDL_Keycode & key)
|
|||||||
if(isActive() && GH.isKeyboardCtrlDown())
|
if(isActive() && GH.isKeyboardCtrlDown())
|
||||||
{
|
{
|
||||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"),
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"),
|
||||||
[](){ LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME); }, nullptr);
|
[](){ GH.pushUserEvent(EUserEvent::RESTART_GAME); }, nullptr);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_SPACE: //space - try to revisit current object with selected hero
|
case SDLK_SPACE: //space - try to revisit current object with selected hero
|
||||||
|
@ -118,7 +118,7 @@ void CGuiHandler::popInt(std::shared_ptr<IShowActivatable> top)
|
|||||||
listInt.front()->activate();
|
listInt.front()->activate();
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
|
|
||||||
pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
|
pushUserEvent(EUserEvent::INTERFACE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGuiHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
|
void CGuiHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
|
||||||
@ -137,7 +137,7 @@ void CGuiHandler::pushInt(std::shared_ptr<IShowActivatable> newInt)
|
|||||||
objsToBlit.push_back(newInt);
|
objsToBlit.push_back(newInt);
|
||||||
totalRedraw();
|
totalRedraw();
|
||||||
|
|
||||||
pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
|
pushUserEvent(EUserEvent::INTERFACE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGuiHandler::popInts(int howMany)
|
void CGuiHandler::popInts(int howMany)
|
||||||
@ -160,7 +160,7 @@ void CGuiHandler::popInts(int howMany)
|
|||||||
}
|
}
|
||||||
fakeMouseMove();
|
fakeMouseMove();
|
||||||
|
|
||||||
pushSDLEvent(SDL_USEREVENT, EUserEvent::INTERFACE_CHANGED);
|
pushUserEvent(EUserEvent::INTERFACE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IShowActivatable> CGuiHandler::topInt()
|
std::shared_ptr<IShowActivatable> CGuiHandler::topInt()
|
||||||
@ -825,11 +825,11 @@ bool CGuiHandler::amIGuiThread()
|
|||||||
return inGuiThread.get() && *inGuiThread;
|
return inGuiThread.get() && *inGuiThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGuiHandler::pushSDLEvent(int type, int usercode)
|
void CGuiHandler::pushUserEvent(EUserEvent usercode)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = type;
|
event.type = SDL_USEREVENT;
|
||||||
event.user.code = usercode; // not necessarily used
|
event.user.code = static_cast<int32_t>(usercode);
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class IShowActivatable;
|
|||||||
class IShowable;
|
class IShowable;
|
||||||
|
|
||||||
// TODO: event handling need refactoring
|
// TODO: event handling need refactoring
|
||||||
enum EUserEvent
|
enum class EUserEvent
|
||||||
{
|
{
|
||||||
/*CHANGE_SCREEN_RESOLUTION = 1,*/
|
/*CHANGE_SCREEN_RESOLUTION = 1,*/
|
||||||
RETURN_TO_MAIN_MENU = 2,
|
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 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 isArrowKey(SDL_Keycode key);
|
||||||
static bool amIGuiThread();
|
static bool amIGuiThread();
|
||||||
static void pushSDLEvent(int type, int usercode = 0);
|
static void pushUserEvent(EUserEvent usercode);
|
||||||
|
|
||||||
CondSh<bool> * terminate_cond; // confirm termination
|
CondSh<bool> * terminate_cond; // confirm termination
|
||||||
};
|
};
|
||||||
|
@ -454,7 +454,7 @@ void CBonusSelection::restartMap()
|
|||||||
close();
|
close();
|
||||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]()
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]()
|
||||||
{
|
{
|
||||||
LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME);
|
GH.pushUserEvent(EUserEvent::RESTART_GAME);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
#include "../lib/NetPacksBase.h"
|
#include "../lib/NetPacksBase.h"
|
||||||
#include "../lib/StartInfo.h"
|
#include "../lib/StartInfo.h"
|
||||||
|
|
||||||
#include <SDL_events.h>
|
#include <SDL_video.h>
|
||||||
|
|
||||||
using namespace CSDL_Ext;
|
using namespace CSDL_Ext;
|
||||||
|
|
||||||
@ -610,7 +610,7 @@ void CSystemOptionsWindow::setGameRes(int index)
|
|||||||
|
|
||||||
void CSystemOptionsWindow::bquitf()
|
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()
|
void CSystemOptionsWindow::breturnf()
|
||||||
@ -620,7 +620,7 @@ void CSystemOptionsWindow::breturnf()
|
|||||||
|
|
||||||
void CSystemOptionsWindow::bmainmenuf()
|
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()
|
void CSystemOptionsWindow::bloadf()
|
||||||
@ -637,13 +637,13 @@ void CSystemOptionsWindow::bsavef()
|
|||||||
|
|
||||||
void CSystemOptionsWindow::brestartf()
|
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();
|
close();
|
||||||
GH.pushSDLEvent(eventType, code);
|
GH.pushUserEvent(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj)
|
CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj)
|
||||||
|
@ -43,6 +43,8 @@ class CTextBox;
|
|||||||
class CResDataBar;
|
class CResDataBar;
|
||||||
class CHeroWithMaybePickedArtifact;
|
class CHeroWithMaybePickedArtifact;
|
||||||
|
|
||||||
|
enum class EUserEvent;
|
||||||
|
|
||||||
/// Recruitment window where you can recruit creatures
|
/// Recruitment window where you can recruit creatures
|
||||||
class CRecruitmentWindow : public CStatusbarWindow
|
class CRecruitmentWindow : public CStatusbarWindow
|
||||||
{
|
{
|
||||||
@ -234,7 +236,7 @@ private:
|
|||||||
|
|
||||||
void selectGameRes();
|
void selectGameRes();
|
||||||
void setGameRes(int index);
|
void setGameRes(int index);
|
||||||
void closeAndPushEvent(int eventType, int code = 0);
|
void closeAndPushEvent(EUserEvent code);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSystemOptionsWindow();
|
CSystemOptionsWindow();
|
||||||
|
Loading…
Reference in New Issue
Block a user