iOS: pause game/status text from external code (#50)
* external game pausing * external status text * fix compilation on other platforms
This commit is contained in:
parent
158aa77fc9
commit
ed85506dbe
57
src/game.cpp
57
src/game.cpp
|
@ -1495,6 +1495,10 @@ public:
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
#ifdef __IOS__
|
||||||
|
void pauseGame();
|
||||||
|
void customStatustext(const std::wstring &text, float time);
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -1699,6 +1703,9 @@ private:
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
bool m_android_chat_open;
|
bool m_android_chat_open;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __IOS__
|
||||||
|
GameRunData* runData_ptr;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
Game::Game() :
|
Game::Game() :
|
||||||
|
@ -1722,6 +1729,9 @@ Game::Game() :
|
||||||
sky(NULL),
|
sky(NULL),
|
||||||
local_inventory(NULL),
|
local_inventory(NULL),
|
||||||
hud(NULL),
|
hud(NULL),
|
||||||
|
#ifdef __IOS__
|
||||||
|
runData_ptr(NULL),
|
||||||
|
#endif
|
||||||
mapper(NULL)
|
mapper(NULL)
|
||||||
{
|
{
|
||||||
g_settings->registerChangedCallback("doubletap_jump",
|
g_settings->registerChangedCallback("doubletap_jump",
|
||||||
|
@ -1841,6 +1851,9 @@ void Game::run()
|
||||||
runData.time_from_last_punch = 10.0;
|
runData.time_from_last_punch = 10.0;
|
||||||
runData.profiler_max_page = 3;
|
runData.profiler_max_page = 3;
|
||||||
runData.update_wielded_item_trigger = true;
|
runData.update_wielded_item_trigger = true;
|
||||||
|
#ifdef __IOS__
|
||||||
|
runData_ptr = &runData;
|
||||||
|
#endif
|
||||||
|
|
||||||
flags.show_chat = true;
|
flags.show_chat = true;
|
||||||
flags.show_hud = true;
|
flags.show_hud = true;
|
||||||
|
@ -4526,6 +4539,28 @@ void Game::readSettings()
|
||||||
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
|
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __IOS__
|
||||||
|
void Game::pauseGame()
|
||||||
|
{
|
||||||
|
g_touchscreengui->handleReleaseAll();
|
||||||
|
if (g_menumgr.pausesGame())
|
||||||
|
return;
|
||||||
|
show_pause_menu(¤t_formspec, client, gamedef,
|
||||||
|
texture_src, device, simple_singleplayer_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::customStatustext(const std::wstring &text, float time)
|
||||||
|
{
|
||||||
|
if (!runData_ptr)
|
||||||
|
return;
|
||||||
|
statustext = text;
|
||||||
|
if(statustext == L"")
|
||||||
|
runData_ptr->statustext_time = 0;
|
||||||
|
else
|
||||||
|
runData_ptr->statustext_time = time;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Shutdown / cleanup
|
Shutdown / cleanup
|
||||||
|
@ -4560,6 +4595,8 @@ void Game::extendedResourceCleanup()
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
|
static Game *g_game = NULL;
|
||||||
|
|
||||||
void the_game(bool *kill,
|
void the_game(bool *kill,
|
||||||
bool random_input,
|
bool random_input,
|
||||||
InputHandler *input,
|
InputHandler *input,
|
||||||
|
@ -4578,6 +4615,7 @@ void the_game(bool *kill,
|
||||||
bool simple_singleplayer_mode)
|
bool simple_singleplayer_mode)
|
||||||
{
|
{
|
||||||
Game game;
|
Game game;
|
||||||
|
g_game = &game;
|
||||||
|
|
||||||
/* Make a copy of the server address because if a local singleplayer server
|
/* Make a copy of the server address because if a local singleplayer server
|
||||||
* is created then this is updated and we don't want to change the value
|
* is created then this is updated and we don't want to change the value
|
||||||
|
@ -4607,4 +4645,23 @@ void the_game(bool *kill,
|
||||||
error_message = e.what() + strgettext("\nCheck debug.txt for details.");
|
error_message = e.what() + strgettext("\nCheck debug.txt for details.");
|
||||||
errorstream << "ModError: " << error_message << std::endl;
|
errorstream << "ModError: " << error_message << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_game = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __IOS__
|
||||||
|
void external_pause_game()
|
||||||
|
{
|
||||||
|
if (!g_game)
|
||||||
|
return;
|
||||||
|
g_game->pauseGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void external_statustext(const char *text, float duration)
|
||||||
|
{
|
||||||
|
if (!g_game)
|
||||||
|
return;
|
||||||
|
std::wstring s = narrow_to_wide(std::string(text));
|
||||||
|
g_game->customStatustext(s, duration);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -609,6 +609,17 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __IOS__
|
||||||
|
void TouchScreenGUI::handleReleaseAll()
|
||||||
|
{
|
||||||
|
m_known_ids.clear();
|
||||||
|
if(m_move_id != -1)
|
||||||
|
handleReleaseEvent(m_move_id);
|
||||||
|
for(int i = 0; i < after_last_element_id; i++)
|
||||||
|
m_buttons[i].ids.clear();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void TouchScreenGUI::translateEvent(const SEvent &event)
|
void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
{
|
{
|
||||||
if (!m_visible) {
|
if (!m_visible) {
|
||||||
|
|
|
@ -91,8 +91,9 @@ public:
|
||||||
void hide();
|
void hide();
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
void storePointerPos(size_t ID, v2s32 pos);
|
#ifdef __IOS__
|
||||||
v2s32 loadPointerPos(size_t ID);
|
void handleReleaseAll();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IrrlichtDevice* m_device;
|
IrrlichtDevice* m_device;
|
||||||
|
@ -185,6 +186,9 @@ private:
|
||||||
|
|
||||||
/* array for doubletap detection */
|
/* array for doubletap detection */
|
||||||
key_event m_key_events[2];
|
key_event m_key_events[2];
|
||||||
|
|
||||||
|
void storePointerPos(size_t ID, v2s32 pos);
|
||||||
|
v2s32 loadPointerPos(size_t ID);
|
||||||
};
|
};
|
||||||
extern TouchScreenGUI *g_touchscreengui;
|
extern TouchScreenGUI *g_touchscreengui;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue