From b816f94269e17bbc6dcbe1a47f98e0d2317865b2 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 3 Feb 2020 15:31:25 +0800 Subject: [PATCH] Add a continue button for multitouch device in kart selection --- data/gui/screens/karts.stkgui | 29 ++++++++------ data/gui/screens/online/network_karts.stkgui | 33 ++++++++------- src/states_screens/kart_selection.cpp | 40 ++++++++++++++++++- src/states_screens/kart_selection.hpp | 1 + .../online/network_kart_selection.cpp | 8 +++- .../online/network_kart_selection.hpp | 2 + 6 files changed, 85 insertions(+), 28 deletions(-) diff --git a/data/gui/screens/karts.stkgui b/data/gui/screens/karts.stkgui index d3645a567..6e3929deb 100644 --- a/data/gui/screens/karts.stkgui +++ b/data/gui/screens/karts.stkgui @@ -7,21 +7,26 @@ align="center" text_align="center" /> - + - - - - - - - - - - + +
+
+ + + + + + + +
+ + + +
diff --git a/data/gui/screens/online/network_karts.stkgui b/data/gui/screens/online/network_karts.stkgui index b89920d26..b061d8e8c 100644 --- a/data/gui/screens/online/network_karts.stkgui +++ b/data/gui/screens/online/network_karts.stkgui @@ -1,26 +1,31 @@ -
+
- + - - - - - - - - - - - + +
+
+ + + + + + + +
+ + + +
+ diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index d4229e325..59102fa24 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -268,6 +268,28 @@ void KartSelectionScreen::loadedFromFile() void KartSelectionScreen::beforeAddingWidget() { + if (useContinueButton()) + { + getWidget("kartlist")->m_properties[GUIEngine::PROP_WIDTH] = "90%"; + getWidget("continue")->setVisible(true); + } + else + { + getWidget("kartlist")->m_properties[GUIEngine::PROP_WIDTH] = "100%"; + getWidget("continue")->setVisible(false); + } + // Remove dispatcher from m_widgets before calculateLayout otherwise a + // dummy button is shown in kart screen + bool removed_dispatcher = false; + if (m_widgets.contains(m_dispatcher)) + { + m_widgets.remove(m_dispatcher); + removed_dispatcher = true; + } + calculateLayout(); + if (removed_dispatcher) + m_widgets.push_back(m_dispatcher); + // Dynamically add tabs RibbonWidget* tabs = getWidget("kartgroups"); assert( tabs != NULL ); @@ -1098,7 +1120,14 @@ void KartSelectionScreen::eventCallback(Widget* widget, } else if (name == "karts") { - if (m_kart_widgets.size() > unsigned(player_id)) + if (!useContinueButton() && + m_kart_widgets.size() > unsigned(player_id)) + playerConfirm(player_id); + } + else if (name == "continue") + { + if (useContinueButton() && + m_kart_widgets.size() > unsigned(player_id)) playerConfirm(player_id); } else if (name == "back") @@ -1551,6 +1580,15 @@ void KartSelectionScreen::setKartsFromCurrentGroup() } // ---------------------------------------------------------------------------- +bool KartSelectionScreen::useContinueButton() const +{ + if (m_multiplayer) + return false; + bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1; + return multitouch_enabled; +} // useContinueButton #if 0 #pragma mark - diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index c358a6d53..273f339a4 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -131,6 +131,7 @@ protected: private: PtrVector getUsableKarts( const std::string& selected_kart_group); + bool useContinueButton() const; public: /** Returns the current instance */ static KartSelectionScreen* getRunningInstance(); diff --git a/src/states_screens/online/network_kart_selection.cpp b/src/states_screens/online/network_kart_selection.cpp index 1b94dfc32..a2007a5e5 100644 --- a/src/states_screens/online/network_kart_selection.cpp +++ b/src/states_screens/online/network_kart_selection.cpp @@ -32,12 +32,18 @@ using namespace GUIEngine; +// ---------------------------------------------------------------------------- +void NetworkKartSelectionScreen::beforeAddingWidget() +{ + m_multiplayer = NetworkConfig::get()->getNetworkPlayers().size() != 1; + KartSelectionScreen::beforeAddingWidget(); +} // beforeAddingWidget + // ---------------------------------------------------------------------------- void NetworkKartSelectionScreen::init() { assert(!NetworkConfig::get()->isAddingNetworkPlayers()); m_all_players_done = false; - m_multiplayer = NetworkConfig::get()->getNetworkPlayers().size() != 1; KartSelectionScreen::init(); m_timer = getWidget("timer"); diff --git a/src/states_screens/online/network_kart_selection.hpp b/src/states_screens/online/network_kart_selection.hpp index d3fdb47e2..e71d53e10 100644 --- a/src/states_screens/online/network_kart_selection.hpp +++ b/src/states_screens/online/network_kart_selection.hpp @@ -64,6 +64,8 @@ private: { return m_available_karts.find(ident) == m_available_karts.end(); } // ------------------------------------------------------------------------ void updateProgressBarText(); + // ------------------------------------------------------------------------ + virtual void beforeAddingWidget() OVERRIDE; public: /** \brief Implement per-frame callback. */