Moving towards adding support for multiple keyboard configs through the GUI

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4325 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-12-19 19:48:41 +00:00
parent 7703fa76ae
commit 631ac7de5d
6 changed files with 163 additions and 2 deletions

View File

@@ -103,6 +103,7 @@
<spacer width="50" height="10" />
<button id="add_device" proportion="1" width="25%" I18N="In the input configuration screen" text="Add a device"/>
</box>
<spacer width="50" height="40" />

View File

@@ -254,6 +254,8 @@ supertuxkart_SOURCES = \
states_screens/challenges.hpp \
states_screens/credits.cpp \
states_screens/credits.hpp \
states_screens/dialogs/add_device_dialog.cpp \
states_screens/dialogs/add_device_dialog.hpp \
states_screens/dialogs/enter_player_name_dialog.cpp \
states_screens/dialogs/enter_player_name_dialog.hpp \
states_screens/dialogs/player_info_dialog.hpp \

View File

@@ -246,6 +246,7 @@
955DE88310042701006A4F3C /* check_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955DE88110042701006A4F3C /* check_manager.cpp */; };
955DE88C1004273B006A4F3C /* check_structure.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955DE8871004273B006A4F3C /* check_structure.cpp */; };
956541BB10DD5F0A00C83E99 /* arenas_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956541B910DD5F0A00C83E99 /* arenas_screen.cpp */; };
956541E110DD628C00C83E99 /* add_device_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956541DF10DD628C00C83E99 /* add_device_dialog.cpp */; };
956D36A710095035007FCB95 /* player.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956D36A610095035007FCB95 /* player.cpp */; };
958330CC10122B4A00C5137E /* engine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330B210122B4A00C5137E /* engine.cpp */; };
958330CD10122B4A00C5137E /* event_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330B410122B4A00C5137E /* event_handler.cpp */; };
@@ -435,6 +436,8 @@
955DE8881004273B006A4F3C /* check_structure.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = check_structure.hpp; path = ../../tracks/check_structure.hpp; sourceTree = SOURCE_ROOT; };
956541B910DD5F0A00C83E99 /* arenas_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = arenas_screen.cpp; path = games/supertuxkart/src/states_screens/arenas_screen.cpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
956541BA10DD5F0A00C83E99 /* arenas_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = arenas_screen.hpp; path = games/supertuxkart/src/states_screens/arenas_screen.hpp; sourceTree = SYSTEM_DEVELOPER_DIR; };
956541DF10DD628C00C83E99 /* add_device_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = add_device_dialog.cpp; path = ../../states_screens/dialogs/add_device_dialog.cpp; sourceTree = SOURCE_ROOT; };
956541E010DD628C00C83E99 /* add_device_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = add_device_dialog.hpp; path = ../../states_screens/dialogs/add_device_dialog.hpp; sourceTree = SOURCE_ROOT; };
956D36A610095035007FCB95 /* player.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = player.cpp; path = ../../config/player.cpp; sourceTree = SOURCE_ROOT; };
958330B210122B4A00C5137E /* engine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = engine.cpp; path = ../../guiengine/engine.cpp; sourceTree = SOURCE_ROOT; };
958330B310122B4A00C5137E /* engine.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = engine.hpp; path = ../../guiengine/engine.hpp; sourceTree = SOURCE_ROOT; };
@@ -1304,6 +1307,8 @@
95833236101243ED00C5137E /* dialogs */ = {
isa = PBXGroup;
children = (
956541DF10DD628C00C83E99 /* add_device_dialog.cpp */,
956541E010DD628C00C83E99 /* add_device_dialog.hpp */,
95833237101243ED00C5137E /* enter_player_name_dialog.cpp */,
95833238101243ED00C5137E /* enter_player_name_dialog.hpp */,
95833239101243ED00C5137E /* player_info_dialog.cpp */,
@@ -2570,6 +2575,7 @@
95FB16DB10A7796800645974 /* new_ai.cpp in Sources */,
953C3CCA10CAF3EE0025F78A /* CGUIFont.cpp in Sources */,
956541BB10DD5F0A00C83E99 /* arenas_screen.cpp in Sources */,
956541E110DD628C00C83E99 /* add_device_dialog.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,109 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/dialogs/add_device_dialog.hpp"
#include "states_screens/options_screen_players.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
using namespace irr::gui;
using namespace irr::core;
AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f)
{
IGUIFont* font = GUIEngine::getFont();
const int textHeight = font->getDimension(L"X").Height;
const int buttonHeight = textHeight + 10;
const int y_bottom = m_area.getHeight() - 2*(buttonHeight + 10) - 20;
core::rect<s32> text_area( 15, 15, m_area.getWidth()-15, y_bottom-15 );
IGUIStaticText* b = GUIEngine::getGUIEnv()->addStaticText( _("To add a new Gamepad/Joystick device, simply start SuperTuxKart with it connected and it will appear in the list.\n\nTo add a keyboard config, you can use the button below, HOWEVER please note that most keyboards only support a limited amount of simultaneous keypresses and are thus inappropriate for multiplayer gameplay."),
text_area, false , true , // border, word warp
m_irrlicht_window);
b->setTabStop(false);
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "addkeyboard";
//I18N: In the 'add new input device' dialog
widget->m_text = _("Add Keyboard Configuration");
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y_bottom;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_properties[PROP_ID] = "cancel";
widget->m_text = _("Cancel");
const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y_bottom + buttonHeight + 20;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
widget->setFocusForPlayer( GUI_PLAYER_ID );
}
}
// ------------------------------------------------------------------------------------------------------
void AddDeviceDialog::onEnterPressedInternal()
{
}
// ------------------------------------------------------------------------------------------------------
GUIEngine::EventPropagation AddDeviceDialog::processEvent(std::string& eventSource)
{
if (eventSource == "cancel")
{
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
//GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
//GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "addkeyboard")
{
// TODO
}
return GUIEngine::EVENT_LET;
}

View File

@@ -0,0 +1,38 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_ADD_DEVICE_DIALOG_HPP
#define HEADER_ADD_DEVICE_DIALOG_HPP
#include "config/player.hpp"
#include "guiengine/modaldialog.hpp"
class AddDeviceDialog : public GUIEngine::ModalDialog
{
public:
/**
* Creates a modal dialog with given percentage of screen width and height
*/
AddDeviceDialog();
void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(std::string& eventSource);
};
#endif

View File

@@ -24,6 +24,7 @@
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/add_device_dialog.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/string_utils.hpp"
@@ -238,7 +239,7 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
{
//const std::string& screen_name = this->getName();
if(name == "options_choice")
if (name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(GUI_PLAYER_ID).c_str();
@@ -246,7 +247,11 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
else if (selection == "players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance());
else if (selection == "controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}
else if(name == "back")
else if (name == "add_device")
{
new AddDeviceDialog();
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}