1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Remove excessive touchscreengui.h includes (#14466)

This commit is contained in:
grorp 2024-03-17 14:59:50 +01:00 committed by GitHub
parent 61a5733692
commit c8b615acc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 115 additions and 86 deletions

View file

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gui/mainmenumanager.h"
#include "clouds.h"
#include "gui/touchscreengui.h"
#include "server.h"
#include "filesys.h"
#include "gui/guiMainMenu.h"
@ -210,8 +211,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
break;
if (g_settings->getBool("enable_touch")) {
receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
g_touchscreengui = receiver->m_touchscreengui;
g_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
}
the_game(
@ -246,7 +246,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
if (g_touchscreengui) {
delete g_touchscreengui;
g_touchscreengui = NULL;
receiver->m_touchscreengui = NULL;
}
/* Save the settings when leaving the game.

View file

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_cso.h"
#include <IBillboardSceneNode.h>
#include "client/texturesource.h"
#include "clientenvironment.h"
#include "client.h"
#include "map.h"

View file

@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content/subgames.h"
#include "client/event_manager.h"
#include "fontengine.h"
#include "gui/touchscreengui.h"
#include "itemdef.h"
#include "log.h"
#include "filesys.h"

View file

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"
#include "inputhandler.h"
#include "gui/mainmenumanager.h"
#include "gui/touchscreengui.h"
#include "hud.h"
void KeyCache::populate_nonchanging()
@ -102,8 +103,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
React to nothing here if a menu is active
*/
if (isMenuActive()) {
if (m_touchscreengui) {
m_touchscreengui->setVisible(false);
if (g_touchscreengui) {
g_touchscreengui->setVisible(false);
}
return g_menumgr.preprocessEvent(event);
}
@ -128,9 +129,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
return true;
}
} else if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
} else if (g_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
// In case of touchscreengui, we have to handle different events
m_touchscreengui->translateEvent(event);
g_touchscreengui->translateEvent(event);
return true;
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
@ -195,6 +196,52 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
return false;
}
/*
* RealInputHandler
*/
float RealInputHandler::getMovementSpeed()
{
bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]),
b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]),
l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]),
r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]);
if (f || b || l || r)
{
// if contradictory keys pressed, stay still
if (f && b && l && r)
return 0.0f;
else if (f && b && !l && !r)
return 0.0f;
else if (!f && !b && l && r)
return 0.0f;
return 1.0f; // If there is a keyboard event, assume maximum speed
}
if (g_touchscreengui && g_touchscreengui->getMovementSpeed())
return g_touchscreengui->getMovementSpeed();
return joystick.getMovementSpeed();
}
float RealInputHandler::getMovementDirection()
{
float x = 0, z = 0;
/* Check keyboard for input */
if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]))
z += 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]))
z -= 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]))
x += 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]))
x -= 1;
if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */
return std::atan2(x, z);
else if (g_touchscreengui && g_touchscreengui->getMovementDirection())
return g_touchscreengui->getMovementDirection();
return joystick.getMovementDirection();
}
/*
* RandomInputHandler
*/

View file

@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <list>
#include "keycode.h"
#include "renderingengine.h"
#include "gui/touchscreengui.h"
class InputHandler;
@ -198,15 +197,8 @@ public:
keyWasReleased.clear();
}
MyEventReceiver()
{
m_touchscreengui = NULL;
}
JoystickController *joystick = nullptr;
TouchScreenGUI *m_touchscreengui;
private:
s32 mouse_wheel = 0;
@ -308,48 +300,9 @@ public:
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
}
virtual float getMovementSpeed()
{
bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]),
b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]),
l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]),
r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]);
if (f || b || l || r)
{
// if contradictory keys pressed, stay still
if (f && b && l && r)
return 0.0f;
else if (f && b && !l && !r)
return 0.0f;
else if (!f && !b && l && r)
return 0.0f;
return 1.0f; // If there is a keyboard event, assume maximum speed
}
if (m_receiver->m_touchscreengui && m_receiver->m_touchscreengui->getMovementSpeed())
return m_receiver->m_touchscreengui->getMovementSpeed();
return joystick.getMovementSpeed();
}
virtual float getMovementSpeed();
virtual float getMovementDirection()
{
float x = 0, z = 0;
/* Check keyboard for input */
if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]))
z += 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]))
z -= 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]))
x += 1;
if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]))
x -= 1;
if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */
return atan2(x, z);
else if (m_receiver->m_touchscreengui && m_receiver->m_touchscreengui->getMovementDirection())
return m_receiver->m_touchscreengui->getMovementDirection();
return joystick.getMovementDirection();
}
virtual float getMovementDirection();
virtual bool cancelPressed()
{