Rename TouchScreenGUI -> TouchControls

to avoid confusion between touchscreen-related settings that affect GUIs
(formspecs) and touchscreen-related settings that affect the touch controls
(TouchControls / formerly TouchScreenGUI)
This commit is contained in:
Gregor Parzefall 2024-05-15 21:11:16 +02:00
parent 9a7c260701
commit 28d8a00173
9 changed files with 77 additions and 77 deletions

View File

@ -19,7 +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 "gui/touchcontrols.h"
#include "server.h"
#include "filesys.h"
#include "gui/guiMainMenu.h"
@ -225,9 +225,9 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
m_rendering_engine->get_scene_manager()->clear();
if (g_touchscreengui) {
delete g_touchscreengui;
g_touchscreengui = NULL;
if (g_touchcontrols) {
delete g_touchcontrols;
g_touchcontrols = NULL;
}
/* Save the settings when leaving the game.

View File

@ -40,7 +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 "gui/touchcontrols.h"
#include "itemdef.h"
#include "log.h"
#include "filesys.h"
@ -1242,8 +1242,8 @@ void Game::shutdown()
// Clear text when exiting.
m_game_ui->clearText();
if (g_touchscreengui)
g_touchscreengui->hide();
if (g_touchcontrols)
g_touchcontrols->hide();
showOverlayMessage(N_("Shutting down..."), 0, 0, false);
@ -1505,8 +1505,8 @@ bool Game::createClient(const GameStartData &start_data)
client->getScript()->on_camera_ready(camera);
client->setCamera(camera);
if (g_touchscreengui) {
g_touchscreengui->setUseCrosshair(!isTouchCrosshairDisabled());
if (g_touchcontrols) {
g_touchcontrols->setUseCrosshair(!isTouchCrosshairDisabled());
}
/* Clouds
@ -1574,7 +1574,7 @@ bool Game::initGui()
-1, chat_backend, client, &g_menumgr);
if (g_settings->getBool("enable_touch"))
g_touchscreengui = new TouchScreenGUI(device, texture_src);
g_touchcontrols = new TouchControls(device, texture_src);
return true;
}
@ -2013,15 +2013,15 @@ void Game::processUserInput(f32 dtime)
input->clear();
}
if (g_touchscreengui)
g_touchscreengui->hide();
if (g_touchcontrols)
g_touchcontrols->hide();
} else {
if (g_touchscreengui) {
/* on touchscreengui step may generate own input events which ain't
if (g_touchcontrols) {
/* on touchcontrols step may generate own input events which ain't
* what we want in case we just did clear them */
g_touchscreengui->show();
g_touchscreengui->step(dtime);
g_touchcontrols->show();
g_touchcontrols->step(dtime);
}
m_game_focused = true;
@ -2214,8 +2214,8 @@ void Game::processItemSelection(u16 *new_playeritem)
}
}
if (g_touchscreengui) {
std::optional<u16> selection = g_touchscreengui->getHotbarSelection();
if (g_touchcontrols) {
std::optional<u16> selection = g_touchcontrols->getHotbarSelection();
if (selection)
*new_playeritem = *selection;
}
@ -2623,7 +2623,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
this results in duplicated input. To avoid that, we don't enable relative
mouse mode if we're in touchscreen mode. */
if (cur_control)
cur_control->setRelativeMode(!g_touchscreengui && !isMenuActive());
cur_control->setRelativeMode(!g_touchcontrols && !isMenuActive());
if ((device->isWindowActive() && device->isWindowFocused()
&& !isMenuActive()) || input->isRandom()) {
@ -2666,9 +2666,9 @@ f32 Game::getSensitivityScaleFactor() const
void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
{
if (g_touchscreengui) {
cam->camera_yaw += g_touchscreengui->getYawChange();
cam->camera_pitch += g_touchscreengui->getPitchChange();
if (g_touchcontrols) {
cam->camera_yaw += g_touchcontrols->getYawChange();
cam->camera_pitch += g_touchcontrols->getPitchChange();
} else {
v2s32 center(driver->getScreenSize().Width / 2, driver->getScreenSize().Height / 2);
v2s32 dist = input->getMousePos() - center;
@ -2733,7 +2733,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
* touch then its meaning is inverted (i.e. holding aux1 means walk and
* not fast)
*/
if (g_touchscreengui && m_touch_simulate_aux1) {
if (g_touchcontrols && m_touch_simulate_aux1) {
control.aux1 = control.aux1 ^ true;
}
@ -3222,8 +3222,8 @@ void Game::updateCamera(f32 dtime)
camera->toggleCameraMode();
if (g_touchscreengui)
g_touchscreengui->setUseCrosshair(!isTouchCrosshairDisabled());
if (g_touchcontrols)
g_touchcontrols->setUseCrosshair(!isTouchCrosshairDisabled());
// Make the player visible depending on camera mode.
playercao->updateMeshCulling();
@ -3324,8 +3324,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
}
shootline.end = shootline.start + camera_direction * BS * d;
if (g_touchscreengui && isTouchCrosshairDisabled()) {
shootline = g_touchscreengui->getShootline();
if (g_touchcontrols && isTouchCrosshairDisabled()) {
shootline = g_touchcontrols->getShootline();
// Scale shootline to the acual distance the player can reach
shootline.end = shootline.start +
shootline.getVector().normalize() * BS * d;
@ -3342,9 +3342,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
if (pointed != runData.pointed_old)
infostream << "Pointing at " << pointed.dump() << std::endl;
if (g_touchscreengui) {
if (g_touchcontrols) {
auto mode = selected_def.touch_interaction.getMode(pointed.type);
g_touchscreengui->applyContextControls(mode);
g_touchcontrols->applyContextControls(mode);
}
// Note that updating the selection mesh every frame is not particularly efficient,
@ -4331,7 +4331,7 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
(this->camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
if (g_touchscreengui && isTouchCrosshairDisabled())
if (g_touchcontrols && isTouchCrosshairDisabled())
draw_crosshair = false;
this->m_rendering_engine->draw_scene(sky_color, this->m_game_ui->m_flags.show_hud,
@ -4442,7 +4442,7 @@ void Game::showPauseMenu()
{
std::string control_text;
if (g_touchscreengui) {
if (g_touchcontrols) {
control_text = strgettext("Controls:\n"
"No menu open:\n"
"- slide finger: look around\n"

View File

@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "wieldmesh.h"
#include "client/renderingengine.h"
#include "client/minimap.h"
#include "gui/touchscreengui.h"
#include "gui/touchcontrols.h"
#include "util/enriched_string.h"
#include "irrlicht_changes/CGUITTFont.h"
@ -305,8 +305,8 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
drawItem(mainlist->getItem(i), item_rect, (i + 1) == selectitem);
if (is_hotbar && g_touchscreengui)
g_touchscreengui->registerHotbarRect(i, item_rect);
if (is_hotbar && g_touchcontrols)
g_touchcontrols->registerHotbarRect(i, item_rect);
}
}
@ -770,8 +770,8 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
void Hud::drawHotbar(u16 playeritem)
{
if (g_touchscreengui)
g_touchscreengui->resetHotbarRects();
if (g_touchcontrols)
g_touchcontrols->resetHotbarRects();
InventoryList *mainlist = inventory->getList("main");
if (mainlist == NULL) {

View File

@ -21,7 +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 "gui/touchcontrols.h"
#include "hud.h"
void KeyCache::populate_nonchanging()
@ -115,8 +115,8 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
// Let the menu handle events, if one is active.
if (isMenuActive()) {
if (g_touchscreengui)
g_touchscreengui->setVisible(false);
if (g_touchcontrols)
g_touchcontrols->setVisible(false);
return g_menumgr.preprocessEvent(event);
}
@ -140,9 +140,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
return true;
}
} else if (g_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
// In case of touchscreengui, we have to handle different events
g_touchscreengui->translateEvent(event);
} else if (g_touchcontrols && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
// In case of touchcontrols, we have to handle different events
g_touchcontrols->translateEvent(event);
return true;
} else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
// joystick may be nullptr if game is launched with '--random-input' parameter
@ -209,8 +209,8 @@ float RealInputHandler::getMovementSpeed()
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();
if (g_touchcontrols && g_touchcontrols->getMovementSpeed())
return g_touchcontrols->getMovementSpeed();
return joystick.getMovementSpeed();
}
@ -232,8 +232,8 @@ float RealInputHandler::getMovementDirection()
return std::atan2(x, z);
// `getMovementDirection() == 0` means forward, so we cannot use
// `getMovementDirection()` as a condition.
else if (g_touchscreengui && g_touchscreengui->getMovementSpeed())
return g_touchscreengui->getMovementDirection();
else if (g_touchcontrols && g_touchcontrols->getMovementSpeed())
return g_touchcontrols->getMovementDirection();
return joystick.getMovementDirection();
}

View File

@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "client/renderingengine.h"
#include "gui/touchscreengui.h"
#include "gui/touchcontrols.h"
ClientDynamicInfo ClientDynamicInfo::getCurrent()
{
@ -33,7 +33,7 @@ ClientDynamicInfo ClientDynamicInfo::getCurrent()
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;
bool touch_controls = g_touchcontrols;
return {
screen_size, real_gui_scaling, real_hud_scaling,

View File

@ -25,6 +25,6 @@ set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modalMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/profilergraph.cpp
${CMAKE_CURRENT_SOURCE_DIR}/touchscreengui.cpp
${CMAKE_CURRENT_SOURCE_DIR}/touchcontrols.cpp
PARENT_SCOPE
)

View File

@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gui/guiInventoryList.h"
#include "porting.h"
#include "settings.h"
#include "touchscreengui.h"
#include "touchcontrols.h"
PointerAction PointerAction::fromEvent(const SEvent &event) {
switch (event.EventType) {
@ -117,8 +117,8 @@ void GUIModalMenu::quitMenu()
Environment->removeFocus(this);
m_menumgr->deletingMenu(this);
this->remove();
if (g_touchscreengui)
g_touchscreengui->show();
if (g_touchcontrols)
g_touchcontrols->show();
}
static bool isChild(gui::IGUIElement *tocheck, gui::IGUIElement *parent)

View File

@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "touchscreengui.h"
#include "touchcontrols.h"
#include "gettime.h"
#include "irr_v2d.h"
@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include <algorithm>
TouchScreenGUI *g_touchscreengui;
TouchControls *g_touchcontrols;
static const char *button_image_names[] = {
"jump_btn.png",
@ -237,7 +237,7 @@ static EKEY_CODE id_to_keycode(touch_gui_button_id id)
code = keyname_to_keycode(resolved.c_str());
} catch (UnknownKeycode &e) {
code = KEY_UNKNOWN;
warningstream << "TouchScreenGUI: Unknown key '" << resolved
warningstream << "TouchControls: Unknown key '" << resolved
<< "' for '" << key << "', hiding button." << std::endl;
}
return code;
@ -403,7 +403,7 @@ void AutoHideButtonBar::hide()
updateVisibility();
}
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsrc):
TouchControls::TouchControls(IrrlichtDevice *device, ISimpleTextureSource *tsrc):
m_device(device),
m_guienv(device->getGUIEnvironment()),
m_receiver(device->getEventReceiver()),
@ -515,7 +515,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsr
}
}
void TouchScreenGUI::addButton(touch_gui_button_id id, const std::string &image, const recti &rect)
void TouchControls::addButton(touch_gui_button_id id, const std::string &image, const recti &rect)
{
IGUIImage *btn_gui_button = m_guienv->addImage(rect, nullptr, id);
load_button_texture(btn_gui_button, image, rect,
@ -526,7 +526,7 @@ void TouchScreenGUI::addButton(touch_gui_button_id id, const std::string &image,
btn.gui_button = grab_gui_element<IGUIImage>(btn_gui_button);
}
IGUIImage *TouchScreenGUI::makeJoystickButton(touch_gui_button_id id,
IGUIImage *TouchControls::makeJoystickButton(touch_gui_button_id id,
const recti &button_rect, bool visible)
{
IGUIImage *btn_gui_button = m_guienv->addImage(button_rect, nullptr, id);
@ -537,7 +537,7 @@ IGUIImage *TouchScreenGUI::makeJoystickButton(touch_gui_button_id id,
return btn_gui_button;
}
bool TouchScreenGUI::isHotbarButton(const SEvent &event)
bool TouchControls::isHotbarButton(const SEvent &event)
{
const v2s32 touch_pos = v2s32(event.TouchInput.X, event.TouchInput.Y);
// check if hotbar item is pressed
@ -552,14 +552,14 @@ bool TouchScreenGUI::isHotbarButton(const SEvent &event)
return false;
}
std::optional<u16> TouchScreenGUI::getHotbarSelection()
std::optional<u16> TouchControls::getHotbarSelection()
{
auto selection = m_hotbar_selection;
m_hotbar_selection = std::nullopt;
return selection;
}
void TouchScreenGUI::handleReleaseEvent(size_t pointer_id)
void TouchControls::handleReleaseEvent(size_t pointer_id)
{
// By the way: Android reuses pointer IDs, so m_pointer_pos[pointer_id]
// will be overwritten soon anyway.
@ -605,15 +605,15 @@ void TouchScreenGUI::handleReleaseEvent(size_t pointer_id)
m_joystick_btn_bg->setVisible(false);
m_joystick_btn_center->setVisible(false);
} else {
infostream << "TouchScreenGUI::translateEvent released unknown button: "
infostream << "TouchControls::translateEvent released unknown button: "
<< pointer_id << std::endl;
}
}
void TouchScreenGUI::translateEvent(const SEvent &event)
void TouchControls::translateEvent(const SEvent &event)
{
if (!m_visible) {
infostream << "TouchScreenGUI::translateEvent got event but is not visible!"
infostream << "TouchControls::translateEvent got event but is not visible!"
<< std::endl;
return;
}
@ -780,7 +780,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
}
}
void TouchScreenGUI::applyJoystickStatus()
void TouchControls::applyJoystickStatus()
{
if (m_joystick_triggers_aux1) {
SEvent translated{};
@ -796,7 +796,7 @@ void TouchScreenGUI::applyJoystickStatus()
}
}
void TouchScreenGUI::step(float dtime)
void TouchControls::step(float dtime)
{
// simulate keyboard repeats
buttons_step(m_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource);
@ -832,17 +832,17 @@ void TouchScreenGUI::step(float dtime)
m_had_move_id = false;
}
void TouchScreenGUI::resetHotbarRects()
void TouchControls::resetHotbarRects()
{
m_hotbar_rects.clear();
}
void TouchScreenGUI::registerHotbarRect(u16 index, const recti &rect)
void TouchControls::registerHotbarRect(u16 index, const recti &rect)
{
m_hotbar_rects[index] = rect;
}
void TouchScreenGUI::setVisible(bool visible)
void TouchControls::setVisible(bool visible)
{
m_visible = visible;
for (auto &button : m_buttons) {
@ -867,7 +867,7 @@ void TouchScreenGUI::setVisible(bool visible)
}
}
void TouchScreenGUI::hide()
void TouchControls::hide()
{
if (!m_visible)
return;
@ -875,7 +875,7 @@ void TouchScreenGUI::hide()
setVisible(false);
}
void TouchScreenGUI::show()
void TouchControls::show()
{
if (m_visible)
return;
@ -883,7 +883,7 @@ void TouchScreenGUI::show()
setVisible(true);
}
v2s32 TouchScreenGUI::getPointerPos()
v2s32 TouchControls::getPointerPos()
{
if (m_draw_crosshair)
return v2s32(m_screensize.X / 2, m_screensize.Y / 2);
@ -892,7 +892,7 @@ v2s32 TouchScreenGUI::getPointerPos()
return m_move_pos;
}
void TouchScreenGUI::emitMouseEvent(EMOUSE_INPUT_EVENT type)
void TouchControls::emitMouseEvent(EMOUSE_INPUT_EVENT type)
{
v2s32 pointer_pos = getPointerPos();
@ -907,7 +907,7 @@ void TouchScreenGUI::emitMouseEvent(EMOUSE_INPUT_EVENT type)
m_receiver->OnEvent(event);
}
void TouchScreenGUI::applyContextControls(const TouchInteractionMode &mode)
void TouchControls::applyContextControls(const TouchInteractionMode &mode)
{
// Since the pointed thing has already been determined when this function
// is called, we cannot use this function to update the shootline.

View File

@ -183,10 +183,10 @@ private:
void updateVisibility();
};
class TouchScreenGUI
class TouchControls
{
public:
TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsrc);
TouchControls(IrrlichtDevice *device, ISimpleTextureSource *tsrc);
void translateEvent(const SEvent &event);
void applyContextControls(const TouchInteractionMode &mode);
@ -314,4 +314,4 @@ private:
u64 m_place_pressed_until = 0;
};
extern TouchScreenGUI *g_touchscreengui;
extern TouchControls *g_touchcontrols;