From f18ead68201a0d23553ea17a6dcde41e257efbc7 Mon Sep 17 00:00:00 2001 From: auria Date: Thu, 25 Nov 2010 02:16:21 +0000 Subject: [PATCH] Show wanring dialog when trying to use shift as a key binding git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6721 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/Makefile.am | 4 +- .../Xcode/STK_XCode.xcodeproj/project.pbxproj | 12 ++--- src/input/input_manager.cpp | 8 +-- ...{confirm_dialog.cpp => message_dialog.cpp} | 53 +++++++++++++++---- ...{confirm_dialog.hpp => message_dialog.hpp} | 19 +++++-- .../dialogs/press_a_key_dialog.cpp | 2 +- src/states_screens/options_screen_input2.cpp | 41 +++++++------- src/states_screens/options_screen_input2.hpp | 6 +-- 8 files changed, 97 insertions(+), 48 deletions(-) rename src/states_screens/dialogs/{confirm_dialog.cpp => message_dialog.cpp} (60%) rename src/states_screens/dialogs/{confirm_dialog.hpp => message_dialog.hpp} (77%) diff --git a/src/Makefile.am b/src/Makefile.am index fd2fe728d..45f741ae0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -277,14 +277,14 @@ supertuxkart_SOURCES = \ states_screens/credits.hpp \ states_screens/dialogs/add_device_dialog.cpp \ states_screens/dialogs/add_device_dialog.hpp \ - states_screens/dialogs/confirm_dialog.cpp \ - states_screens/dialogs/confirm_dialog.hpp \ states_screens/dialogs/confirm_resolution_dialog.cpp \ states_screens/dialogs/confirm_resolution_dialog.hpp \ states_screens/dialogs/enter_player_name_dialog.cpp \ states_screens/dialogs/enter_player_name_dialog.hpp \ states_screens/dialogs/gp_info_dialog.cpp \ states_screens/dialogs/gp_info_dialog.hpp \ + states_screens/dialogs/message_dialog.cpp \ + states_screens/dialogs/message_dialog.hpp \ states_screens/dialogs/player_info_dialog.hpp \ states_screens/dialogs/player_info_dialog.cpp \ states_screens/dialogs/press_a_key_dialog.hpp \ diff --git a/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj b/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj index 12f95acdf..81bb69ad1 100644 --- a/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj +++ b/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj @@ -50,8 +50,8 @@ 952A1554103F68D000B1895D /* profile_world.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 952A1552103F68D000B1895D /* profile_world.cpp */; }; 953789730FC7829100DD1F8E /* graph_node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953789720FC7829100DD1F8E /* graph_node.cpp */; }; 953789820FC7831400DD1F8E /* quad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953789810FC7831400DD1F8E /* quad.cpp */; }; + 95395A77129DFE130079BCE7 /* message_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95395A75129DFE130079BCE7 /* message_dialog.cpp */; }; 953F8B2111F7C13C00205E66 /* scalable_font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953F8B1F11F7C13C00205E66 /* scalable_font.cpp */; }; - 954378D51238493C00F57707 /* confirm_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 954378D41238493C00F57707 /* confirm_dialog.cpp */; }; 95453ACA11808B8700A155B9 /* emergency_animation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95453AC811808B8700A155B9 /* emergency_animation.cpp */; }; 9545ABCA11E3E38300D3C37A /* progress_bar_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9545ABC811E3E38300D3C37A /* progress_bar_widget.cpp */; }; 954E486A11B19C4100B1DF63 /* fribidi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 954E486911B19C4100B1DF63 /* fribidi.framework */; }; @@ -411,6 +411,8 @@ 953789720FC7829100DD1F8E /* graph_node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = graph_node.cpp; path = ../../tracks/graph_node.cpp; sourceTree = SOURCE_ROOT; }; 953789800FC7831400DD1F8E /* quad.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = quad.hpp; path = ../../tracks/quad.hpp; sourceTree = SOURCE_ROOT; }; 953789810FC7831400DD1F8E /* quad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = quad.cpp; path = ../../tracks/quad.cpp; sourceTree = SOURCE_ROOT; }; + 95395A75129DFE130079BCE7 /* message_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = message_dialog.cpp; path = ../../states_screens/dialogs/message_dialog.cpp; sourceTree = SOURCE_ROOT; }; + 95395A76129DFE130079BCE7 /* message_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = message_dialog.hpp; path = ../../states_screens/dialogs/message_dialog.hpp; sourceTree = SOURCE_ROOT; }; 953EAAAD0F30A4220000D57D /* terrain_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = terrain_info.hpp; path = ../../tracks/terrain_info.hpp; sourceTree = SOURCE_ROOT; }; 953EAAAE0F30A4220000D57D /* terrain_info.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = terrain_info.cpp; path = ../../tracks/terrain_info.cpp; sourceTree = SOURCE_ROOT; }; 953EAAB00F30A4410000D57D /* triangle_mesh.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = triangle_mesh.hpp; path = ../../physics/triangle_mesh.hpp; sourceTree = SOURCE_ROOT; }; @@ -421,8 +423,6 @@ 953F8B2011F7C13C00205E66 /* scalable_font.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = scalable_font.hpp; path = ../../guiengine/scalable_font.hpp; sourceTree = SOURCE_ROOT; }; 9540E2560FD5F8FD002985B8 /* ptr_vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ptr_vector.hpp; path = ../../utils/ptr_vector.hpp; sourceTree = SOURCE_ROOT; }; 9540E2570FD5F8FD002985B8 /* no_copy.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = no_copy.hpp; path = ../../utils/no_copy.hpp; sourceTree = SOURCE_ROOT; }; - 954378D41238493C00F57707 /* confirm_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = confirm_dialog.cpp; path = ../../states_screens/dialogs/confirm_dialog.cpp; sourceTree = SOURCE_ROOT; }; - 954378E712384BEB00F57707 /* confirm_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = confirm_dialog.hpp; path = ../../states_screens/dialogs/confirm_dialog.hpp; sourceTree = SOURCE_ROOT; }; 95453AC811808B8700A155B9 /* emergency_animation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = emergency_animation.cpp; path = ../../karts/emergency_animation.cpp; sourceTree = SOURCE_ROOT; }; 95453AC911808B8700A155B9 /* emergency_animation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = emergency_animation.hpp; path = ../../karts/emergency_animation.hpp; sourceTree = SOURCE_ROOT; }; 9545ABC811E3E38300D3C37A /* progress_bar_widget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = progress_bar_widget.cpp; path = ../../guiengine/widgets/progress_bar_widget.cpp; sourceTree = SOURCE_ROOT; }; @@ -1401,14 +1401,14 @@ 956541E010DD628C00C83E99 /* add_device_dialog.hpp */, 95E6A0BE11DCF37800AE088A /* addons_loading.cpp */, 95E6A0BF11DCF37800AE088A /* addons_loading.hpp */, - 954378D41238493C00F57707 /* confirm_dialog.cpp */, - 954378E712384BEB00F57707 /* confirm_dialog.hpp */, 95E246BC111A2959000C965D /* confirm_resolution_dialog.cpp */, 95E246BD111A2959000C965D /* confirm_resolution_dialog.hpp */, 95833237101243ED00C5137E /* enter_player_name_dialog.cpp */, 95833238101243ED00C5137E /* enter_player_name_dialog.hpp */, 95634EF01126272C009C145D /* gp_info_dialog.cpp */, 95634EF11126272C009C145D /* gp_info_dialog.hpp */, + 95395A75129DFE130079BCE7 /* message_dialog.cpp */, + 95395A76129DFE130079BCE7 /* message_dialog.hpp */, 95833239101243ED00C5137E /* player_info_dialog.cpp */, 9583323A101243ED00C5137E /* player_info_dialog.hpp */, 9583323B101243ED00C5137E /* press_a_key_dialog.cpp */, @@ -2681,12 +2681,12 @@ 956039BA1218C09E00EB96C4 /* abstract_top_level_container.cpp in Sources */, 9552C1FB1231249000347B6C /* world_with_rank.cpp in Sources */, 956B0A9F1232D2E900767CCD /* bubble_widget.cpp in Sources */, - 954378D51238493C00F57707 /* confirm_dialog.cpp in Sources */, 95017B41124698C400C90D56 /* help_screen_4.cpp in Sources */, 95251F3D12554AB200505BA5 /* check_lap.cpp in Sources */, 9516B07E12629C4E005F9493 /* sfx_buffer.cpp in Sources */, 95BF1E68127513A100F78AE7 /* max_speed.cpp in Sources */, 9528CC241291E7A10078A5EF /* binding.cpp in Sources */, + 95395A77129DFE130079BCE7 /* message_dialog.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 3a9c76cd5..62b20cb70 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -244,7 +244,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID, if (m_sensed_input_high_kbd.find(m_sensed_input->m_button_id) != m_sensed_input_high_kbd.end()) { - OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input); + OptionsScreenInput2::getInstance()->gotSensedInput(*m_sensed_input); return; } } @@ -261,7 +261,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID, if (abs(value) > Input::MAX_VALUE/2.0f) { - OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input); + OptionsScreenInput2::getInstance()->gotSensedInput(*m_sensed_input); return; } } @@ -280,12 +280,12 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID, } else if ( abs(value) < Input::MAX_VALUE/8.0f && id_has_high_value ) { - OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input); + OptionsScreenInput2::getInstance()->gotSensedInput(*m_sensed_input); } else if ( abs(value) < Input::MAX_VALUE/8.0f && inverse_id_has_high_value ) { m_sensed_input->m_axis_direction= (axisDirection?0:-1); - OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input); + OptionsScreenInput2::getInstance()->gotSensedInput(*m_sensed_input); } } } diff --git a/src/states_screens/dialogs/confirm_dialog.cpp b/src/states_screens/dialogs/message_dialog.cpp similarity index 60% rename from src/states_screens/dialogs/confirm_dialog.cpp rename to src/states_screens/dialogs/message_dialog.cpp index e3d4af8aa..cb59f15c5 100644 --- a/src/states_screens/dialogs/confirm_dialog.cpp +++ b/src/states_screens/dialogs/message_dialog.cpp @@ -15,10 +15,11 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/dialogs/confirm_dialog.hpp" +#include "states_screens/dialogs/message_dialog.hpp" #include "guiengine/engine.hpp" #include "guiengine/screen.hpp" +#include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" #include "states_screens/state_manager.hpp" @@ -26,7 +27,7 @@ using namespace GUIEngine; // ------------------------------------------------------------------------------------------------------ -ConfirmDialog::ConfirmDialog(irr::core::stringw msg, IConfirmDialogListener* listener) : +MessageDialog::MessageDialog(irr::core::stringw msg, IConfirmDialogListener* listener) : ModalDialog(0.6f, 0.6f) { loadFromFile("confirm_dialog.stkgui"); @@ -39,24 +40,58 @@ ConfirmDialog::ConfirmDialog(irr::core::stringw msg, IConfirmDialogListener* lis // ------------------------------------------------------------------------------------------------------ -void ConfirmDialog::onEnterPressedInternal() +MessageDialog::MessageDialog(irr::core::stringw msg) : + ModalDialog(0.6f, 0.6f) +{ + loadFromFile("confirm_dialog.stkgui"); + + m_listener = NULL; + + LabelWidget* message = getWidget("title"); + message->setText( msg.c_str() ); + + ButtonWidget* yesbtn = getWidget("confirm"); + yesbtn->setVisible(false); + + ButtonWidget* cancelbtn = getWidget("cancel"); + cancelbtn->setText(_("OK")); + cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER); +} + +// ------------------------------------------------------------------------------------------------------ + +void MessageDialog::onEnterPressedInternal() { } // ------------------------------------------------------------------------------------------------------ -GUIEngine::EventPropagation ConfirmDialog::processEvent(const std::string& eventSource) +GUIEngine::EventPropagation MessageDialog::processEvent(const std::string& eventSource) { if (eventSource == "cancel") - { - m_listener->onCancel(); + { + if (m_listener == NULL) + { + ModalDialog::dismiss(); + } + else + { + m_listener->onCancel(); + } return GUIEngine::EVENT_BLOCK; } else if (eventSource == "confirm") - { - m_listener->onConfirm(); + { + if (m_listener == NULL) + { + ModalDialog::dismiss(); + } + else + { + m_listener->onConfirm(); + } return GUIEngine::EVENT_BLOCK; } @@ -66,7 +101,7 @@ GUIEngine::EventPropagation ConfirmDialog::processEvent(const std::string& event // ------------------------------------------------------------------------------------------------------ -void ConfirmDialog::IConfirmDialogListener::onCancel() +void MessageDialog::IConfirmDialogListener::onCancel() { ModalDialog::dismiss(); } diff --git a/src/states_screens/dialogs/confirm_dialog.hpp b/src/states_screens/dialogs/message_dialog.hpp similarity index 77% rename from src/states_screens/dialogs/confirm_dialog.hpp rename to src/states_screens/dialogs/message_dialog.hpp index 75171266c..5babc77ca 100644 --- a/src/states_screens/dialogs/confirm_dialog.hpp +++ b/src/states_screens/dialogs/message_dialog.hpp @@ -23,10 +23,10 @@ #include "guiengine/modaldialog.hpp" /** - * \brief Generic dialog to ask the user to confirm something. + * \brief Generic dialog to ask the user to confirm something, or to show a simple message box * \ingroup states_screens */ -class ConfirmDialog : public GUIEngine::ModalDialog +class MessageDialog : public GUIEngine::ModalDialog { public: @@ -61,11 +61,20 @@ public: /** * \param msg Message to display in the dialog - * \param listener A listener object to notify when the user made a choice + * \param listener A listener object to notify when the user made a choice. Note that + * MessageDialog does not take ownership of the listener and will not + * delete it. */ - ConfirmDialog(irr::core::stringw msg, IConfirmDialogListener* listener); + MessageDialog(irr::core::stringw msg, IConfirmDialogListener* listener); - ~ConfirmDialog() { m_listener = NULL; } + /** + * Variant of MessageDialog where cancelling is not possible (i.e. just shows a message box with OK) + * \param msg Message to display in the dialog + */ + MessageDialog(irr::core::stringw msg); + + + ~MessageDialog() { m_listener = NULL; } virtual void onEnterPressedInternal(); diff --git a/src/states_screens/dialogs/press_a_key_dialog.cpp b/src/states_screens/dialogs/press_a_key_dialog.cpp index 1ba911a04..44ab0e9e6 100644 --- a/src/states_screens/dialogs/press_a_key_dialog.cpp +++ b/src/states_screens/dialogs/press_a_key_dialog.cpp @@ -47,7 +47,7 @@ GUIEngine::EventPropagation PressAKeyDialog::processEvent(const std::string& eve else if (eventSource == "assignEsc") { Input simulatedInput(Input::IT_KEYBOARD, 0 /* deviceID */, KEY_ESCAPE); - OptionsScreenInput2::getInstance()->gotSensedInput(&simulatedInput); + OptionsScreenInput2::getInstance()->gotSensedInput(simulatedInput); return GUIEngine::EVENT_BLOCK; } diff --git a/src/states_screens/options_screen_input2.cpp b/src/states_screens/options_screen_input2.cpp index 640a88593..7f62ebc9e 100644 --- a/src/states_screens/options_screen_input2.cpp +++ b/src/states_screens/options_screen_input2.cpp @@ -263,27 +263,27 @@ void OptionsScreenInput2::updateInputButtons() static PlayerAction binding_to_set; static std::string binding_to_set_button; -void OptionsScreenInput2::gotSensedInput(Input* sensed_input) +void OptionsScreenInput2::gotSensedInput(Input sensed_input) { const bool keyboard = (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD && - sensed_input->m_type == Input::IT_KEYBOARD); - const bool gamepad = (sensed_input->m_type == Input::IT_STICKMOTION || - sensed_input->m_type == Input::IT_STICKBUTTON) && + sensed_input.m_type == Input::IT_KEYBOARD); + const bool gamepad = (sensed_input.m_type == Input::IT_STICKMOTION || + sensed_input.m_type == Input::IT_STICKBUTTON) && m_config->getType() == DEVICE_CONFIG_TYPE_GAMEPAD; - + if (keyboard) { if (UserConfigParams::m_verbosity>=5) { std::cout << "% Binding " << KartActionStrings[binding_to_set] - << " : setting to keyboard key " << sensed_input->m_button_id + << " : setting to keyboard key " << sensed_input.m_button_id << " \n\n"; } KeyboardConfig* keyboard = (KeyboardConfig*)m_config; keyboard->setBinding(binding_to_set, Input::IT_KEYBOARD, - sensed_input->m_button_id, Input::AD_NEUTRAL, - sensed_input->m_character); + sensed_input.m_button_id, Input::AD_NEUTRAL, + sensed_input.m_character); // refresh display updateInputButtons(); @@ -294,18 +294,18 @@ void OptionsScreenInput2::gotSensedInput(Input* sensed_input) { std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to gamepad #" - << sensed_input->m_device_id<< " : "; + << sensed_input.m_device_id<< " : "; - if (sensed_input->m_type == Input::IT_STICKMOTION) + if (sensed_input.m_type == Input::IT_STICKMOTION) { - std::cout << "axis " << sensed_input->m_button_id<< " direction " - << (sensed_input->m_axis_direction== Input::AD_NEGATIVE + std::cout << "axis " << sensed_input.m_button_id<< " direction " + << (sensed_input.m_axis_direction== Input::AD_NEGATIVE ? "-" : "+") << "\n\n"; } - else if (sensed_input->m_type == Input::IT_STICKBUTTON) + else if (sensed_input.m_type == Input::IT_STICKBUTTON) { - std::cout << "button " << sensed_input->m_button_id<< "\n\n"; + std::cout << "button " << sensed_input.m_button_id<< "\n\n"; } else { @@ -314,9 +314,9 @@ void OptionsScreenInput2::gotSensedInput(Input* sensed_input) } GamepadConfig* config = (GamepadConfig*)m_config; - config->setBinding(binding_to_set, sensed_input->m_type, - sensed_input->m_button_id, - (Input::AxisDirection)sensed_input->m_axis_direction); + config->setBinding(binding_to_set, sensed_input.m_type, + sensed_input.m_button_id, + (Input::AxisDirection)sensed_input.m_axis_direction); // refresh display updateInputButtons(); @@ -328,6 +328,11 @@ void OptionsScreenInput2::gotSensedInput(Input* sensed_input) ModalDialog::dismiss(); input_manager->setMode(InputManager::MENU); + + if (keyboard && sensed_input.m_button_id == irr::KEY_SHIFT) + { + new MessageDialog(_("Warning, 'Shift' is not a recommended key : when shift is pressed down, all keys that contain a character that is different in upper-case will stop working.")); + } // re-select the previous button (TODO!) //ButtonWidget* btn = this->getWidget(binding_to_set_button.c_str()); @@ -407,7 +412,7 @@ void OptionsScreenInput2::eventCallback(Widget* widget, const std::string& name, { // keyboard configs may be deleted //I18N: shown before deleting an input configuration - new ConfirmDialog( _("Are you sure you want to permanently delete this configuration?"), this ); + new MessageDialog( _("Are you sure you want to permanently delete this configuration?"), this ); } else { diff --git a/src/states_screens/options_screen_input2.hpp b/src/states_screens/options_screen_input2.hpp index 5192a2d89..cccf4928b 100644 --- a/src/states_screens/options_screen_input2.hpp +++ b/src/states_screens/options_screen_input2.hpp @@ -23,7 +23,7 @@ #include "irrlicht.h" #include "guiengine/screen.hpp" -#include "states_screens/dialogs/confirm_dialog.hpp" +#include "states_screens/dialogs/message_dialog.hpp" namespace GUIEngine { class Widget; } class DeviceConfig; @@ -39,7 +39,7 @@ struct Input; */ class OptionsScreenInput2 : public GUIEngine::Screen, public GUIEngine::ScreenSingleton, - public ConfirmDialog::IConfirmDialogListener + public MessageDialog::IConfirmDialogListener { OptionsScreenInput2(); @@ -73,7 +73,7 @@ public: * \brief invoke in "input sensing" mode, when input was sensed. * Updates the input bindings accordingly with the sensed input. */ - void gotSensedInput(Input* sensedInput); + void gotSensedInput(Input sensedInput); /** \brief Implement IConfirmDialogListener callback */ virtual void onConfirm();