diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 5365d70f9..5826508f6 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -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" @@ -230,9 +230,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. diff --git a/src/client/game.cpp b/src/client/game.cpp index 1267b32a9..648155d83 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -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" @@ -1245,8 +1245,8 @@ void Game::shutdown() // Clear text when exiting. m_game_ui->clearText(); - if (g_touchscreengui) - g_touchscreengui->hide(); + if (g_touchcontrols) + g_touchcontrols->hide(); // only if the shutdown progress bar isn't shown yet if (m_shutdown_progress == 0.0f) @@ -1510,8 +1510,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 @@ -1579,7 +1579,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; } @@ -2027,15 +2027,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; @@ -2230,8 +2230,8 @@ void Game::processItemSelection(u16 *new_playeritem) } } - if (g_touchscreengui) { - std::optional selection = g_touchscreengui->getHotbarSelection(); + if (g_touchcontrols) { + std::optional selection = g_touchcontrols->getHotbarSelection(); if (selection) *new_playeritem = *selection; } @@ -2636,7 +2636,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()) { @@ -2679,9 +2679,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; @@ -2746,7 +2746,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; } @@ -3235,8 +3235,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(); @@ -3337,8 +3337,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; @@ -3355,9 +3355,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, @@ -4348,7 +4348,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, @@ -4459,7 +4459,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" diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 3f9672f3d..e2d1ee455 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -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" @@ -322,8 +322,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); } } @@ -787,8 +787,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) { diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index 4233916c2..39c212d2f 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -22,7 +22,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() @@ -143,8 +143,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); } @@ -168,9 +168,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 @@ -237,8 +237,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(); } @@ -260,8 +260,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(); } diff --git a/src/clientdynamicinfo.cpp b/src/clientdynamicinfo.cpp index a9b2a6ef3..2e75a6adc 100644 --- a/src/clientdynamicinfo.cpp +++ b/src/clientdynamicinfo.cpp @@ -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, diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 66d6a9ee8..73bbecb02 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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 ) diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index 7e6c486e0..97e1ae8e0 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -377,7 +377,7 @@ void GUIKeyChangeMenu::add_key(int id, std::wstring button_name, const std::stri key_settings.push_back(k); } -// compare with button_titles in touchscreengui.cpp +// compare with button_titles in touchcontrols.cpp void GUIKeyChangeMenu::init_keys() { this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wstrgettext("Forward"), "keymap_forward"); diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp index 83d5036f9..fd60d08c2 100644 --- a/src/gui/modalMenu.cpp +++ b/src/gui/modalMenu.cpp @@ -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) { @@ -111,8 +111,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) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchcontrols.cpp similarity index 94% rename from src/gui/touchscreengui.cpp rename to src/gui/touchcontrols.cpp index c428ef52e..b96ced1bf 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchcontrols.cpp @@ -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" @@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -TouchScreenGUI *g_touchscreengui; +TouchControls *g_touchcontrols; static const char *button_image_names[] = { "jump_btn.png", @@ -266,14 +266,14 @@ 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; } -TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsrc): +TouchControls::TouchControls(IrrlichtDevice *device, ISimpleTextureSource *tsrc): m_device(device), m_guienv(device->getGUIEnvironment()), m_receiver(device->getEventReceiver()), @@ -413,7 +413,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsr } } -void TouchScreenGUI::addButton(std::vector &buttons, touch_gui_button_id id, +void TouchControls::addButton(std::vector &buttons, touch_gui_button_id id, const std::string &image, const recti &rect, bool visible) { IGUIImage *btn_gui_button = m_guienv->addImage(rect, nullptr, id); @@ -426,7 +426,7 @@ void TouchScreenGUI::addButton(std::vector &buttons, touch_gui_butt btn.gui_button = grab_gui_element(btn_gui_button); } -void TouchScreenGUI::addToggleButton(std::vector &buttons, touch_gui_button_id id, +void TouchControls::addToggleButton(std::vector &buttons, touch_gui_button_id id, const std::string &image_1, const std::string &image_2, const recti &rect, bool visible) { addButton(buttons, id, image_1, rect, visible); @@ -436,7 +436,7 @@ void TouchScreenGUI::addToggleButton(std::vector &buttons, touch_gu btn.toggle_textures[1] = image_2; } -IGUIImage *TouchScreenGUI::makeButtonDirect(touch_gui_button_id id, +IGUIImage *TouchControls::makeButtonDirect(touch_gui_button_id id, const recti &rect, bool visible) { IGUIImage *btn_gui_button = m_guienv->addImage(rect, nullptr, id); @@ -447,7 +447,7 @@ IGUIImage *TouchScreenGUI::makeButtonDirect(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 @@ -462,14 +462,14 @@ bool TouchScreenGUI::isHotbarButton(const SEvent &event) return false; } -std::optional TouchScreenGUI::getHotbarSelection() +std::optional 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. @@ -516,15 +516,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; } @@ -702,7 +702,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) } } -void TouchScreenGUI::applyJoystickStatus() +void TouchControls::applyJoystickStatus() { if (m_joystick_triggers_aux1) { SEvent translated{}; @@ -718,7 +718,7 @@ void TouchScreenGUI::applyJoystickStatus() } } -void TouchScreenGUI::step(float dtime) +void TouchControls::step(float dtime) { if (m_overflow_open) { buttons_step(m_overflow_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource); @@ -757,17 +757,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) { if (m_visible == visible) return; @@ -781,14 +781,14 @@ void TouchScreenGUI::setVisible(bool visible) updateVisibility(); } -void TouchScreenGUI::toggleOverflowMenu() +void TouchControls::toggleOverflowMenu() { releaseAll(); // must be done first m_overflow_open = !m_overflow_open; updateVisibility(); } -void TouchScreenGUI::updateVisibility() +void TouchControls::updateVisibility() { bool regular_visible = m_visible && !m_overflow_open; for (auto &button : m_buttons) @@ -804,7 +804,7 @@ void TouchScreenGUI::updateVisibility() text->setVisible(overflow_visible); } -void TouchScreenGUI::releaseAll() +void TouchControls::releaseAll() { while (!m_pointer_pos.empty()) handleReleaseEvent(m_pointer_pos.begin()->first); @@ -821,17 +821,17 @@ void TouchScreenGUI::releaseAll() } } -void TouchScreenGUI::hide() +void TouchControls::hide() { setVisible(false); } -void TouchScreenGUI::show() +void TouchControls::show() { setVisible(true); } -v2s32 TouchScreenGUI::getPointerPos() +v2s32 TouchControls::getPointerPos() { if (m_draw_crosshair) return v2s32(m_screensize.X / 2, m_screensize.Y / 2); @@ -840,7 +840,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(); @@ -855,7 +855,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. diff --git a/src/gui/touchscreengui.h b/src/gui/touchcontrols.h similarity index 97% rename from src/gui/touchscreengui.h rename to src/gui/touchcontrols.h index 2da9d8151..ebc251bb6 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchcontrols.h @@ -128,10 +128,10 @@ struct button_info }; -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); @@ -182,7 +182,7 @@ private: s32 m_button_size; double m_touchscreen_threshold; u16 m_long_tap_delay; - bool m_visible = true; // is the whole touch screen gui visible + bool m_visible = true; std::unordered_map m_hotbar_rects; std::optional m_hotbar_selection = std::nullopt; @@ -273,4 +273,4 @@ private: u64 m_place_pressed_until = 0; }; -extern TouchScreenGUI *g_touchscreengui; +extern TouchControls *g_touchcontrols;