mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Auto-toggle TouchControls in-game when receiving touch/mouse input
This commit is contained in:
parent
3c5f05b284
commit
4952f17df4
15 changed files with 152 additions and 89 deletions
|
@ -723,6 +723,7 @@ protected:
|
|||
void processUserInput(f32 dtime);
|
||||
void processKeyInput();
|
||||
void processItemSelection(u16 *new_playeritem);
|
||||
bool shouldShowTouchControls();
|
||||
|
||||
void dropSelectedItem(bool single_item = false);
|
||||
void openInventory();
|
||||
|
@ -1565,6 +1566,14 @@ bool Game::createClient(const GameStartData &start_data)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Game::shouldShowTouchControls()
|
||||
{
|
||||
const std::string &touch_controls = g_settings->get("touch_controls");
|
||||
if (touch_controls == "auto")
|
||||
return RenderingEngine::getLastPointerType() == PointerType::Touch;
|
||||
return is_yes(touch_controls);
|
||||
}
|
||||
|
||||
bool Game::initGui()
|
||||
{
|
||||
m_game_ui->init();
|
||||
|
@ -1579,7 +1588,7 @@ bool Game::initGui()
|
|||
gui_chat_console = make_irr<GUIChatConsole>(guienv, guienv->getRootGUIElement(),
|
||||
-1, chat_backend, client, &g_menumgr);
|
||||
|
||||
if (g_settings->getBool("touch_controls")) {
|
||||
if (shouldShowTouchControls()) {
|
||||
g_touchcontrols = new TouchControls(device, texture_src);
|
||||
g_touchcontrols->setUseCrosshair(!isTouchCrosshairDisabled());
|
||||
}
|
||||
|
@ -2031,6 +2040,15 @@ void Game::updateStats(RunStats *stats, const FpsControl &draw_times,
|
|||
|
||||
void Game::processUserInput(f32 dtime)
|
||||
{
|
||||
bool desired = shouldShowTouchControls();
|
||||
if (desired && !g_touchcontrols) {
|
||||
g_touchcontrols = new TouchControls(device, texture_src);
|
||||
|
||||
} else if (!desired && g_touchcontrols) {
|
||||
delete g_touchcontrols;
|
||||
g_touchcontrols = nullptr;
|
||||
}
|
||||
|
||||
// Reset input if window not active or some menu is active
|
||||
if (!device->isWindowActive() || isMenuActive() || guienv->hasFocus(gui_chat_console.get())) {
|
||||
if (m_game_focused) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue