mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Remove excessive touchscreengui.h includes (#14466)
This commit is contained in:
parent
61a5733692
commit
c8b615acc9
8 changed files with 115 additions and 86 deletions
|
@ -368,6 +368,7 @@ set(common_SRCS
|
||||||
${server_SRCS}
|
${server_SRCS}
|
||||||
${content_SRCS}
|
${content_SRCS}
|
||||||
chat.cpp
|
chat.cpp
|
||||||
|
clientdynamicinfo.cpp
|
||||||
collision.cpp
|
collision.cpp
|
||||||
content_mapnode.cpp
|
content_mapnode.cpp
|
||||||
content_nodemeta.cpp
|
content_nodemeta.cpp
|
||||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
#include "gui/mainmenumanager.h"
|
#include "gui/mainmenumanager.h"
|
||||||
#include "clouds.h"
|
#include "clouds.h"
|
||||||
|
#include "gui/touchscreengui.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
#include "gui/guiMainMenu.h"
|
#include "gui/guiMainMenu.h"
|
||||||
|
@ -210,8 +211,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (g_settings->getBool("enable_touch")) {
|
if (g_settings->getBool("enable_touch")) {
|
||||||
receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
|
g_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver);
|
||||||
g_touchscreengui = receiver->m_touchscreengui;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
the_game(
|
the_game(
|
||||||
|
@ -246,7 +246,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
|
||||||
if (g_touchscreengui) {
|
if (g_touchscreengui) {
|
||||||
delete g_touchscreengui;
|
delete g_touchscreengui;
|
||||||
g_touchscreengui = NULL;
|
g_touchscreengui = NULL;
|
||||||
receiver->m_touchscreengui = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the settings when leaving the game.
|
/* Save the settings when leaving the game.
|
||||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
#include "content_cso.h"
|
#include "content_cso.h"
|
||||||
#include <IBillboardSceneNode.h>
|
#include <IBillboardSceneNode.h>
|
||||||
|
#include "client/texturesource.h"
|
||||||
#include "clientenvironment.h"
|
#include "clientenvironment.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
|
@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "content/subgames.h"
|
#include "content/subgames.h"
|
||||||
#include "client/event_manager.h"
|
#include "client/event_manager.h"
|
||||||
#include "fontengine.h"
|
#include "fontengine.h"
|
||||||
|
#include "gui/touchscreengui.h"
|
||||||
#include "itemdef.h"
|
#include "itemdef.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
|
|
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
#include "inputhandler.h"
|
#include "inputhandler.h"
|
||||||
#include "gui/mainmenumanager.h"
|
#include "gui/mainmenumanager.h"
|
||||||
|
#include "gui/touchscreengui.h"
|
||||||
#include "hud.h"
|
#include "hud.h"
|
||||||
|
|
||||||
void KeyCache::populate_nonchanging()
|
void KeyCache::populate_nonchanging()
|
||||||
|
@ -102,8 +103,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
||||||
React to nothing here if a menu is active
|
React to nothing here if a menu is active
|
||||||
*/
|
*/
|
||||||
if (isMenuActive()) {
|
if (isMenuActive()) {
|
||||||
if (m_touchscreengui) {
|
if (g_touchscreengui) {
|
||||||
m_touchscreengui->setVisible(false);
|
g_touchscreengui->setVisible(false);
|
||||||
}
|
}
|
||||||
return g_menumgr.preprocessEvent(event);
|
return g_menumgr.preprocessEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -128,9 +129,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
||||||
return true;
|
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
|
// In case of touchscreengui, we have to handle different events
|
||||||
m_touchscreengui->translateEvent(event);
|
g_touchscreengui->translateEvent(event);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
|
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
|
||||||
|
@ -195,6 +196,52 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
||||||
return false;
|
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
|
* RandomInputHandler
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
#include "renderingengine.h"
|
#include "renderingengine.h"
|
||||||
#include "gui/touchscreengui.h"
|
|
||||||
|
|
||||||
class InputHandler;
|
class InputHandler;
|
||||||
|
|
||||||
|
@ -198,15 +197,8 @@ public:
|
||||||
keyWasReleased.clear();
|
keyWasReleased.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyEventReceiver()
|
|
||||||
{
|
|
||||||
m_touchscreengui = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
JoystickController *joystick = nullptr;
|
JoystickController *joystick = nullptr;
|
||||||
|
|
||||||
TouchScreenGUI *m_touchscreengui;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
s32 mouse_wheel = 0;
|
s32 mouse_wheel = 0;
|
||||||
|
|
||||||
|
@ -308,48 +300,9 @@ public:
|
||||||
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
|
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float getMovementSpeed()
|
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 getMovementDirection()
|
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 bool cancelPressed()
|
virtual bool cancelPressed()
|
||||||
{
|
{
|
||||||
|
|
55
src/clientdynamicinfo.cpp
Normal file
55
src/clientdynamicinfo.cpp
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2022-3 rubenwardy <rw@rubenwardy.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SERVER
|
||||||
|
|
||||||
|
#include "clientdynamicinfo.h"
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
#include "client/renderingengine.h"
|
||||||
|
#include "gui/touchscreengui.h"
|
||||||
|
|
||||||
|
ClientDynamicInfo ClientDynamicInfo::getCurrent()
|
||||||
|
{
|
||||||
|
v2u32 screen_size = RenderingEngine::getWindowSize();
|
||||||
|
f32 density = RenderingEngine::getDisplayDensity();
|
||||||
|
f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
|
||||||
|
f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
|
||||||
|
f32 real_gui_scaling = gui_scaling * density;
|
||||||
|
f32 real_hud_scaling = hud_scaling * density;
|
||||||
|
bool touch_controls = g_touchscreengui;
|
||||||
|
|
||||||
|
return {
|
||||||
|
screen_size, real_gui_scaling, real_hud_scaling,
|
||||||
|
ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling),
|
||||||
|
touch_controls
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling)
|
||||||
|
{
|
||||||
|
f32 factor = (g_settings->getBool("enable_touch") ? 10 : 15) / gui_scaling;
|
||||||
|
f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y;
|
||||||
|
if (ratio < 1)
|
||||||
|
return { factor, factor / ratio };
|
||||||
|
else
|
||||||
|
return { factor * ratio, factor };
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -20,11 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#ifndef SERVER
|
|
||||||
#include "settings.h"
|
|
||||||
#include "client/renderingengine.h"
|
|
||||||
#include "gui/touchscreengui.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct ClientDynamicInfo
|
struct ClientDynamicInfo
|
||||||
|
@ -44,32 +39,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
static ClientDynamicInfo getCurrent() {
|
static ClientDynamicInfo getCurrent();
|
||||||
v2u32 screen_size = RenderingEngine::getWindowSize();
|
|
||||||
f32 density = RenderingEngine::getDisplayDensity();
|
|
||||||
f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
|
|
||||||
f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
|
|
||||||
f32 real_gui_scaling = gui_scaling * density;
|
|
||||||
f32 real_hud_scaling = hud_scaling * density;
|
|
||||||
bool touch_controls = g_touchscreengui;
|
|
||||||
|
|
||||||
return {
|
|
||||||
screen_size, real_gui_scaling, real_hud_scaling,
|
|
||||||
ClientDynamicInfo::calculateMaxFSSize(screen_size, gui_scaling),
|
|
||||||
touch_controls
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef SERVER
|
static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling);
|
||||||
static v2f32 calculateMaxFSSize(v2u32 render_target_size, f32 gui_scaling) {
|
|
||||||
f32 factor = (g_settings->getBool("enable_touch") ? 10 : 15) / gui_scaling;
|
|
||||||
f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y;
|
|
||||||
if (ratio < 1)
|
|
||||||
return { factor, factor / ratio };
|
|
||||||
else
|
|
||||||
return { factor * ratio, factor };
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue