cleaned up options menu code

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3535 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-05-24 00:52:31 +00:00
parent 2a7052de02
commit 7e45011c6e
12 changed files with 820 additions and 276 deletions

View File

@@ -135,6 +135,7 @@ supertuxkart_SOURCES = \
input/device_manager.cpp \
input/device_manager.hpp \
input/input.hpp \
input/input.hpp \
input/input_device.cpp \
input/input_device.hpp \
input/input_manager.cpp \
@@ -188,6 +189,8 @@ supertuxkart_SOURCES = \
gui/engine.hpp \
gui/my_button.cpp \
gui/my_button.hpp \
gui/options_screen.cpp \
gui/options_screen.hpp \
gui/screen.cpp \
gui/screen.hpp \
gui/screen_loader.cpp \

268
src/gui/options_screen.cpp Normal file
View File

@@ -0,0 +1,268 @@
#include "gui/options_screen.hpp"
#include "gui/engine.hpp"
#include "gui/widget.hpp"
#include "gui/screen.hpp"
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "gui/state_manager.hpp"
using namespace GUIEngine;
/**
* Callback handling events from the options menus
*/
namespace StateManager
{
// -----------------------------------------------------------------------------
void initAudioVideo(Widget* widget, std::string& name)
{
// ---- sfx volume
SpinnerWidget* gauge = getCurrentScreen()->getWidget<SpinnerWidget>("sfx_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sfx_manager->getMasterSFXVolume()*10.0f) );
gauge = getCurrentScreen()->getWidget<SpinnerWidget>("music_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sound_manager->getMasterMusicVolume()*10.f) );
// ---- music volume
CheckBoxWidget* sfx = getCurrentScreen()->getWidget<CheckBoxWidget>("sfx_enabled");
CheckBoxWidget* music = getCurrentScreen()->getWidget<CheckBoxWidget>("music_enabled");
// ---- audio enables/disables
sfx->setState( user_config->doSFX() );
music->setState( user_config->doMusic() );
// ---- video modes
{
RibbonGridWidget* res = getCurrentScreen()->getWidget<RibbonGridWidget>("resolutions");
assert( res != NULL );
CheckBoxWidget* full = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert( full != NULL );
full->setState( user_config->m_fullscreen );
// --- get resolution list from irrlicht the first time
if(!getCurrentScreen()->m_inited)
{
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
const float ratio = (float)w / h;
char name[32];
sprintf( name, "%ix%i", w, h );
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
res->addItem(name,name,"gui/screen54.png");
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
res->addItem(name,name,"gui/screen43.png");
else if( ABOUT_EQUAL( ratio, (16.0f/10.0f) ) )
res->addItem(name,name,"gui/screen1610.png");
else if( ABOUT_EQUAL( ratio, (5.0f/3.0f) ) )
res->addItem(name,name,"gui/screen53.png");
else if( ABOUT_EQUAL( ratio, (3.0f/2.0f) ) )
res->addItem(name,name,"gui/screen32.png");
else
{
std::cout << "Unknown screen size ratio : " << ratio << std::endl;
// FIXME - do something better than showing a random icon
res->addItem(name,name,"gui/screen1610.png");
}
#undef ABOUT_EQUAL
} // next resolution
} // end if not inited
res->updateItemDisplay();
// ---- select curernt resolution every time
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
char name[32];
sprintf( name, "%ix%i", w, h );
if(w == user_config->m_width && h == user_config->m_height)
{
//std::cout << "************* Detected right resolution!!! " << n << "\n";
// that's the current one
res->setSelection(n);
break;
}
} // end for
}
}
// -----------------------------------------------------------------------------
void eventAudioVideo(Widget* widget, std::string& name)
{
if(name == "music_volume")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
sound_manager->setMasterMusicVolume( w->getValue()/10.0f );
}
else if(name == "sfx_volume")
{
static SFXBase* sample_sound = NULL;
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
if(sample_sound == NULL)
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
sample_sound->volume(1);
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
user_config->m_sfx_volume = w->getValue()/10.0f;
// play a sample sound to show the user what this volume is like
sample_sound->position ( Vec3(0,0,0) );
if(sample_sound->getStatus() != SFXManager::SFX_PLAYING)
{
sample_sound->play();
}
}
else if(name == "music_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
user_config->setMusic(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
if(w->getState() == false)
sound_manager->stopMusic();
else
sound_manager->startMusic(sound_manager->getCurrentMusic());
}
else if(name == "sfx_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
user_config->setSFX(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
}
else if(name == "apply_resolution")
{
using namespace GUIEngine;
user_config->m_prev_width = user_config->m_width;
user_config->m_prev_height = user_config->m_height;
RibbonGridWidget* w1 = getCurrentScreen()->getWidget<RibbonGridWidget>("resolutions");
assert(w1 != NULL);
const std::string& res = w1->getSelectionName();
int w = -1, h = -1;
if( sscanf(res.c_str(), "%ix%i", &w, &h) != 2 || w == -1 || h == -1 )
{
std::cerr << "Failed to decode resolution : " << res.c_str() << std::endl;
return;
}
CheckBoxWidget* w2 = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert(w2 != NULL);
user_config->m_width = w;
user_config->m_height = h;
user_config->m_fullscreen = w2->getState();
irr_driver->changeResolution();
}
}
// -----------------------------------------------------------------------------
void initInput(Widget* widget, std::string& name)
{
{
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
assert( devices != NULL );
if(!getCurrentScreen()->m_inited)
{
devices->addItem("Keyboard","keyboard","gui/keyboard.png");
const int gamepad_count = input_manager->getDeviceList()->getGamePadAmount();
for(int i=0; i<gamepad_count; i++)
{
std::string name = input_manager->getDeviceList()->getGamePad(i)->m_name;
char internal_name[32];
sprintf(internal_name, "gamepad%i", i);
devices->addItem(name,internal_name,"gui/gamepad.png");
}
}
devices->updateItemDisplay();
}
}
// -----------------------------------------------------------------------------
void eventInput(Widget* widget, std::string& name)
{
}
// -----------------------------------------------------------------------------
// main call (from StateManager); dispatches the call to a specialissed function as needed
void menuEventOptions(Widget* widget, std::string& name)
{
const std::string& screen_name = getCurrentScreen()->getName();
if(name == "init")
{
const std::string& screen_name = getCurrentScreen()->getName();
RibbonWidget* ribbon = getCurrentScreen()->getWidget<RibbonWidget>("options_choice");
if(ribbon != NULL)
{
if(screen_name == "options_av.stkgui") ribbon->select( "audio_video" );
else if(screen_name == "options_players.stkgui") ribbon->select( "players" );
else if(screen_name == "options_input.stkgui") ribbon->select( "controls" );
}
if(screen_name == "options_av.stkgui") initAudioVideo(widget, name);
else if(screen_name == "options_input.stkgui") initInput(widget, name);
//getCurrentScreen()->m_inited;
}
else if(name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionName().c_str();
if(selection == "audio_video") StateManager::replaceTopMostMenu("options_av.stkgui");
else if(selection == "players") StateManager::replaceTopMostMenu("options_players.stkgui");
else if(selection == "controls") StateManager::replaceTopMostMenu("options_input.stkgui");
}
else if(name == "back")
{
StateManager::escapePressed();
}
else
{
if(screen_name == "options_av.stkgui") eventAudioVideo(widget, name);
else if(screen_name == "options_input.stkgui") eventInput(widget, name);
}
}
}

View File

@@ -0,0 +1,18 @@
#ifndef __HEADER_OPTIONS_SCREEN_HPP__
#define __HEADER_OPTIONS_SCREEN_HPP__
#include <string>
namespace GUIEngine
{
class Widget;
}
namespace StateManager
{
void menuEventOptions(GUIEngine::Widget* widget, std::string& name);
}
#endif

View File

@@ -1,12 +1,10 @@
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "gui/state_manager.hpp"
#include "gui/engine.hpp"
#include "gui/widget.hpp"
#include "gui/screen.hpp"
#include "gui/credits.hpp"
#include "gui/options_screen.hpp"
#include "input/input_manager.hpp"
#include "input/device_manager.hpp"
#include "graphics/irr_driver.hpp"
@@ -270,234 +268,6 @@ namespace StateManager
}
// -------------------------------------------------------------------------
/**
* Callback handling events from the options menus
*/
void menuEventOptions(Widget* widget, std::string& name)
{
// -- init
if(name == "init")
{
const std::string& screen_name = getCurrentScreen()->getName();
RibbonWidget* ribbon = getCurrentScreen()->getWidget<RibbonWidget>("options_choice");
if(ribbon != NULL)
{
if(screen_name == "options_av.stkgui") ribbon->select( "audio_video" );
else if(screen_name == "options_players.stkgui") ribbon->select( "players" );
else if(screen_name == "options_input.stkgui") ribbon->select( "controls" );
}
// ---- init audio-video sub-screen
if(screen_name == "options_av.stkgui")
{
// ---- sfx volume
SpinnerWidget* gauge = getCurrentScreen()->getWidget<SpinnerWidget>("sfx_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sfx_manager->getMasterSFXVolume()*10.0f) );
gauge = getCurrentScreen()->getWidget<SpinnerWidget>("music_volume");
assert(gauge != NULL);
gauge->setValue( (int)(sound_manager->getMasterMusicVolume()*10.f) );
// ---- music volume
CheckBoxWidget* sfx = getCurrentScreen()->getWidget<CheckBoxWidget>("sfx_enabled");
CheckBoxWidget* music = getCurrentScreen()->getWidget<CheckBoxWidget>("music_enabled");
// ---- audio enables/disables
sfx->setState( user_config->doSFX() );
music->setState( user_config->doMusic() );
// ---- video modes
{
RibbonGridWidget* res = getCurrentScreen()->getWidget<RibbonGridWidget>("resolutions");
assert( res != NULL );
CheckBoxWidget* full = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert( full != NULL );
full->setState( user_config->m_fullscreen );
// --- get resolution list from irrlicht the first time
if(!getCurrentScreen()->m_inited)
{
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
const float ratio = (float)w / h;
char name[32];
sprintf( name, "%ix%i", w, h );
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
res->addItem(name,name,"gui/screen54.png");
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
res->addItem(name,name,"gui/screen43.png");
else if( ABOUT_EQUAL( ratio, (16.0f/10.0f) ) )
res->addItem(name,name,"gui/screen1610.png");
else if( ABOUT_EQUAL( ratio, (5.0f/3.0f) ) )
res->addItem(name,name,"gui/screen53.png");
else if( ABOUT_EQUAL( ratio, (3.0f/2.0f) ) )
res->addItem(name,name,"gui/screen32.png");
else
{
std::cout << "Unknown screen size ratio : " << ratio << std::endl;
// FIXME - do something better than showing a random icon
res->addItem(name,name,"gui/screen1610.png");
}
#undef ABOUT_EQUAL
} // next resolution
} // end if not inited
res->updateItemDisplay();
// ---- select curernt resolution every time
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
char name[32];
sprintf( name, "%ix%i", w, h );
if(w == user_config->m_width && h == user_config->m_height)
{
//std::cout << "************* Detected right resolution!!! " << n << "\n";
// that's the current one
res->setSelection(n);
break;
}
} // end for
}
}
// ---- init input options screen
else if(screen_name == "options_input.stkgui")
{
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
assert( devices != NULL );
if(!getCurrentScreen()->m_inited)
{
devices->addItem("Keyboard","keyboard","gui/keyboard.png");
const int gamepad_count = input_manager->getDeviceList()->getGamePadAmount();
for(int i=0; i<gamepad_count; i++)
{
std::string name = input_manager->getDeviceList()->getGamePad(i)->m_name;
char internal_name[32];
sprintf(internal_name, "gamepad%i", i);
devices->addItem(name,internal_name,"gui/gamepad.png");
}
}
devices->updateItemDisplay();
}
getCurrentScreen()->m_inited;
} // end init
// -- options
else if(name == "options_choice")
{
std::string selection = ((RibbonWidget*)widget)->getSelectionName().c_str();
if(selection == "audio_video") replaceTopMostMenu("options_av.stkgui");
else if(selection == "players") replaceTopMostMenu("options_players.stkgui");
else if(selection == "controls") replaceTopMostMenu("options_input.stkgui");
}
else if(name == "music_volume")
{
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
sound_manager->setMasterMusicVolume( w->getValue()/10.0f );
}
else if(name == "sfx_volume")
{
static SFXBase* sample_sound = NULL;
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);
if(sample_sound == NULL)
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
sample_sound->volume(1);
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
user_config->m_sfx_volume = w->getValue()/10.0f;
// play a sample sound to show the user what this volume is like
sample_sound->position ( Vec3(0,0,0) );
if(sample_sound->getStatus() != SFXManager::SFX_PLAYING)
{
sample_sound->play();
}
}
else if(name == "music_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
user_config->setMusic(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
if(w->getState() == false)
sound_manager->stopMusic();
else
sound_manager->startMusic(sound_manager->getCurrentMusic());
}
else if(name == "sfx_enabled")
{
CheckBoxWidget* w = dynamic_cast<CheckBoxWidget*>(widget);
user_config->setSFX(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
}
else if(name == "apply_resolution")
{
using namespace GUIEngine;
user_config->m_prev_width = user_config->m_width;
user_config->m_prev_height = user_config->m_height;
RibbonGridWidget* w1 = getCurrentScreen()->getWidget<RibbonGridWidget>("resolutions");
assert(w1 != NULL);
const std::string& res = w1->getSelectionName();
int w = -1, h = -1;
if( sscanf(res.c_str(), "%ix%i", &w, &h) != 2 || w == -1 || h == -1 )
{
std::cerr << "Failed to decode resolution : " << res.c_str() << std::endl;
return;
}
CheckBoxWidget* w2 = getCurrentScreen()->getWidget<CheckBoxWidget>("fullscreen");
assert(w2 != NULL);
user_config->m_width = w;
user_config->m_height = h;
user_config->m_fullscreen = w2->getState();
irr_driver->changeResolution();
}
else if(name == "back")
{
StateManager::escapePressed();
}
}
// -----------------------------------------------------------------------------
/**

View File

@@ -238,6 +238,8 @@
9551CBD60FC1BB7600DB481B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95F4231E0E26E44800692113 /* Cocoa.framework */; };
9551CBD70FC1BB7600DB481B /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95F423120E26E3DC00692113 /* OpenGL.framework */; };
9551CBDA0FC1BB9200DB481B /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9551CBD90FC1BB9200DB481B /* AGL.framework */; };
95D1F5F70FC8C3E300FF6968 /* input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D1F5F60FC8C3E300FF6968 /* input.cpp */; };
95D1F6190FC8CDBB00FF6968 /* options_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D1F6180FC8CDBB00FF6968 /* options_screen.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -765,6 +767,9 @@
95C65DA10F532FD400BE7BA7 /* nitro.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = nitro.cpp; path = ../../graphics/nitro.cpp; sourceTree = SOURCE_ROOT; };
95CA59F60F82FCB7003323DB /* physical_object.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = physical_object.hpp; path = ../../physics/physical_object.hpp; sourceTree = SOURCE_ROOT; };
95CA59F70F82FCB7003323DB /* physical_object.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = physical_object.cpp; path = ../../physics/physical_object.cpp; sourceTree = SOURCE_ROOT; };
95D1F5F60FC8C3E300FF6968 /* input.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = input.cpp; path = ../../input/input.cpp; sourceTree = SOURCE_ROOT; };
95D1F6170FC8CDBB00FF6968 /* options_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = options_screen.hpp; path = ../../gui/options_screen.hpp; sourceTree = SOURCE_ROOT; };
95D1F6180FC8CDBB00FF6968 /* options_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = options_screen.cpp; path = ../../gui/options_screen.cpp; sourceTree = SOURCE_ROOT; };
95D464880FA37B1B00F50CA2 /* libIrrlicht.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libIrrlicht.a; path = /usr/local/lib/libIrrlicht.a; sourceTree = "<absolute>"; };
95D538840F69D61C00B4062E /* aabbox3d.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = aabbox3d.h; path = /usr/local/include/irrlicht/aabbox3d.h; sourceTree = "<absolute>"; };
95D538850F69D61C00B4062E /* CDynamicMeshBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDynamicMeshBuffer.h; path = /usr/local/include/irrlicht/CDynamicMeshBuffer.h; sourceTree = "<absolute>"; };
@@ -993,6 +998,8 @@
9505577D0F696A900056E88C /* my_button.hpp */,
95C1E3FF0F699427005D33E6 /* font.cpp */,
95C1E4020F69943D005D33E6 /* font.hpp */,
95D1F6180FC8CDBB00FF6968 /* options_screen.cpp */,
95D1F6170FC8CDBB00FF6968 /* options_screen.hpp */,
95C1E3F10F699079005D33E6 /* race_gui.cpp */,
95C1E3EB0F698F23005D33E6 /* race_gui.hpp */,
9505577F0F696A900056E88C /* screen.cpp */,
@@ -1060,6 +1067,7 @@
95A118280F77EA3100B18B3D /* input */ = {
isa = PBXGroup;
children = (
95D1F5F60FC8C3E300FF6968 /* input.cpp */,
95A118290F77EA3100B18B3D /* input.hpp */,
95A1182A0F77EA3100B18B3D /* input_manager.cpp */,
95A1182B0F77EA3100B18B3D /* input_manager.hpp */,
@@ -2250,6 +2258,8 @@
9507E9700FC1C8C200BD2B92 /* RenderTexture.cpp in Sources */,
953789730FC7829100DD1F8E /* graph_node.cpp in Sources */,
953789820FC7831400DD1F8E /* quad.cpp in Sources */,
95D1F5F70FC8C3E300FF6968 /* input.cpp in Sources */,
95D1F6190FC8CDBB00FF6968 /* options_screen.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -23,6 +23,9 @@ public:
int getGamePadAmount() const{ return m_gamepad_amount; }
GamePadDevice* getGamePad(const int i) { return m_gamepads.get(i); }
int getKeyboardAmount() const{ return m_keyboard_amount; }
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
/** Given some input, finds to which device it belongs and, using the corresponding device object,
maps this input to the corresponding player and game action. returns false if player/action could not be set */
bool mapInputToPlayerAndAction( Input::InputType type, int id0, int id1, int id2, int value,

502
src/input/input.cpp Normal file
View File

@@ -0,0 +1,502 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2007-2008 Robert Schuster <robertschuster@fsfe.org>
//
// 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 "input/input.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include <irrlicht.h>
using namespace irr;
// -----------------------------------------------------------------------------
std::string Input::getInputAsString(const Input::InputType type, const int id, const Input::AxisDirection dir)
{
std::string s;
switch (type)
{
case Input::IT_NONE:
s = _("not set");
break;
case Input::IT_KEYBOARD:
// TODO - implement with non-SDL code
// s = SDL_GetKeyName((SDLKey) input.id0);
s = "some key";
switch(id)
{
case KEY_LBUTTON :
s = "left mouse button";
break;
case KEY_RBUTTON :
s = "right mouse button";
break;
case KEY_CANCEL :
s = "cancel";
break;
case KEY_MBUTTON :
s = "middle mouse button";
break;
case KEY_XBUTTON1 :
s = "X1 mouse button";
break;
case KEY_XBUTTON2 :
s = "X2 mouse button";
break;
case KEY_BACK :
s = "backspace";
break;
case KEY_TAB :
s = "tab";
break;
case KEY_CLEAR :
s = "clear";
break;
case KEY_RETURN :
s = "return";
break;
case KEY_SHIFT :
s = "shift";
break;
case KEY_CONTROL :
s = "control";
break;
case KEY_MENU :
s = "alt/menu";
break;
case KEY_PAUSE :
s = "pause";
break;
case KEY_CAPITAL :
s = "caps lock";
break;
case KEY_KANA :
s = "kana";
break;
//case KEY_HANGUEL :
//case KEY_HANGUL :
// s = "hangul";
break;
case KEY_JUNJA :
s = "junja";
break;
case KEY_FINAL :
s = "final";
break;
//case KEY_HANJA :
// s = "hanja";
// break;
//case KEY_KANJI :
// s = "kanji";
// break;
case KEY_ESCAPE :
s = "escape";
break;
case KEY_CONVERT :
s = "convert";
break;
case KEY_NONCONVERT :
s = "nonconvert";
break;
case KEY_ACCEPT :
s = "accept";
break;
case KEY_MODECHANGE :
s = "modechange";
break;
case KEY_SPACE :
s = "space";
break;
case KEY_PRIOR :
s = "page up";
break;
case KEY_NEXT :
s = "page down";
break;
case KEY_END :
s = "end";
break;
case KEY_HOME :
s = "home";
break;
case KEY_LEFT :
s = "left";
break;
case KEY_UP :
s = "up";
break;
case KEY_RIGHT :
s = "right";
break;
case KEY_DOWN :
s = "down";
break;
case KEY_SELECT :
s = "select";
break;
case KEY_PRINT :
s = "print";
break;
case KEY_EXECUT :
s = "exec";
break;
case KEY_SNAPSHOT :
s = "print screen";
break;
case KEY_INSERT :
s = "insert";
break;
case KEY_DELETE :
s = "delete";
break;
case KEY_HELP :
s = "help";
break;
case KEY_KEY_0 :
s = "0";
break;
case KEY_KEY_1 :
s = "1";
break;
case KEY_KEY_2 :
s = "2";
break;
case KEY_KEY_3 :
s = "3";
break;
case KEY_KEY_4 :
s = "4";
break;
case KEY_KEY_5 :
s = "5";
break;
case KEY_KEY_6 :
s = "6";
break;
case KEY_KEY_7 :
s = "7";
break;
case KEY_KEY_8 :
s = "8";
break;
case KEY_KEY_9 :
s = "9";
break;
case KEY_KEY_A :
s = "A";
break;
case KEY_KEY_B :
s = "B";
break;
case KEY_KEY_C :
s = "C";
break;
case KEY_KEY_D :
s = "D";
break;
case KEY_KEY_E :
s = "E";
break;
case KEY_KEY_F :
s = "F";
break;
case KEY_KEY_G :
s = "G";
break;
case KEY_KEY_H :
s = "H";
break;
case KEY_KEY_I :
s = "I";
break;
case KEY_KEY_J :
s = "J";
break;
case KEY_KEY_K :
s = "K";
break;
case KEY_KEY_L :
s = "L";
break;
case KEY_KEY_M :
s = "M";
break;
case KEY_KEY_N :
s = "N";
break;
case KEY_KEY_O :
s = "O";
break;
case KEY_KEY_P :
s = "P";
break;
case KEY_KEY_Q :
s = "Q";
break;
case KEY_KEY_R :
s = "R";
break;
case KEY_KEY_S :
s = "S";
break;
case KEY_KEY_T :
s = "T";
break;
case KEY_KEY_U :
s = "U";
break;
case KEY_KEY_V :
s = "V";
break;
case KEY_KEY_W :
s = "W";
break;
case KEY_KEY_X :
s = "X";
break;
case KEY_KEY_Y :
s = "Y";
break;
case KEY_KEY_Z :
s = "Z";
break;
case KEY_LWIN :
s = "Left Logo";
break;
case KEY_RWIN :
s = "Right Logo";
break;
case KEY_APPS :
s = "apps";
break;
case KEY_SLEEP :
s = "sleep";
break;
case KEY_NUMPAD0 :
s = "numpad 0";
break;
case KEY_NUMPAD1 :
s = "numpad 1";
break;
case KEY_NUMPAD2 :
s = "numpad 2";
break;
case KEY_NUMPAD3 :
s = "numpad 3";
break;
case KEY_NUMPAD4 :
s = "numpad 4";
break;
case KEY_NUMPAD5 :
s = "numpad 5";
break;
case KEY_NUMPAD6 :
s = "numpad 6";
break;
case KEY_NUMPAD7 :
s = "numpad 7";
break;
case KEY_NUMPAD8 :
s = "numpad 8";
break;
case KEY_NUMPAD9 :
s = "numpad 9";
break;
case KEY_MULTIPLY :
s = "*";
break;
case KEY_ADD :
s = "+";
break;
case KEY_SEPARATOR :
s = "separator";
break;
case KEY_SUBTRACT :
s = "- (subtract)";
break;
case KEY_DECIMAL :
s = "decimal";
break;
case KEY_DIVIDE :
s = "/ (divide)";
break;
case KEY_F1 :
s = "F1";
break;
case KEY_F2 :
s = "F2";
break;
case KEY_F3 :
s = "F3";
break;
case KEY_F4 :
s = "F4";
break;
case KEY_F5 :
s = "F5";
break;
case KEY_F6 :
s = "F6";
break;
case KEY_F7 :
s = "F7";
break;
case KEY_F8 :
s = "F8";
break;
case KEY_F9 :
s = "F9";
break;
case KEY_F10 :
s = "F10";
break;
case KEY_F11 :
s = "F11";
break;
case KEY_F12 :
s = "F12";
break;
case KEY_F13 :
s = "F13";
break;
case KEY_F14 :
s = "F14";
break;
case KEY_F15 :
s = "F15";
break;
case KEY_F16 :
s = "F16";
break;
case KEY_F17 :
s = "F17";
break;
case KEY_F18 :
s = "F18";
break;
case KEY_F19 :
s = "F19";
break;
case KEY_F20 :
s = "F20";
break;
case KEY_F21 :
s = "F21";
break;
case KEY_F22 :
s = "F22";
break;
case KEY_F23 :
s = "F23";
break;
case KEY_F24 :
s = "F24";
break;
case KEY_NUMLOCK :
s = "num lock";
break;
case KEY_SCROLL :
s = "scroll lock";
break;
case KEY_LSHIFT :
s = "left shift";
break;
case KEY_RSHIFT :
s = "right shift";
break;
case KEY_LCONTROL :
s = "left control";
break;
case KEY_RCONTROL :
s = "right control";
break;
case KEY_LMENU :
s = "left menu";
break;
case KEY_RMENU :
s = "right menu";
break;
case KEY_PLUS :
s = "+";
break;
case KEY_COMMA :
s = ",";
break;
case KEY_MINUS :
s = "-";
break;
case KEY_PERIOD :
s = ".";
break;
case KEY_ATTN :
s = "attn";
break;
case KEY_CRSEL :
s = "crsel";
break;
case KEY_EXSEL :
s = "exsel";
break;
case KEY_EREOF :
s = "ereof";
break;
case KEY_PLAY :
s = "play";
break;
case KEY_ZOOM :
s = "zoom";
break;
case KEY_PA1 :
s = "pa1";
break;
case KEY_OEM_CLEAR:
s = "oem clear";
break;
}
break;
case Input::IT_STICKMOTION:
//I18N : to appear in input configuration screen, for gamepad axes
s = StringUtils::insert_values( _("Axis %d %s"), id, (dir == Input::AD_NEGATIVE) ? '-' : '+');
break;
case Input::IT_STICKBUTTON:
//I18N : to appear in input configuration screen, for gamepad buttons
s = StringUtils::insert_values( _("Gamepad button %d"), id);
break;
case Input::IT_STICKHAT:
//I18N : to appear in input configuration screen, for gamepad hats
s = StringUtils::insert_values( _("Gamepad hat %d"), id);
break;
case Input::IT_MOUSEBUTTON:
//I18N : to appear in input configuration screen, for mouse (might not be used at all)
s = StringUtils::insert_values( _("Mouse button %d"), id);
break;
case Input::IT_MOUSEMOTION: // FIXME : I don't reckon this is used at all
//I18N : to appear in input configuration screen, for mouse (might not be used at all)
s = StringUtils::insert_values( _("Mouse axis %d %s"),
id,
(dir == Input::AD_NEGATIVE)
? '-': '+' );
break;
default:
s = _("Invalid");
}
return s;
} // GetKeyAsString

View File

@@ -88,6 +88,9 @@ struct Input
{
// Nothing to do.
}
static std::string getInputAsString(const Input::InputType type, const int id, const Input::AxisDirection dir);
};
enum PlayerAction

View File

@@ -86,6 +86,11 @@ bool InputDevice::deserializeAction(irr::io::IrrXMLReader* xml)
return true;
}
// -----------------------------------------------------------------------------
std::string InputDevice::getBindingAsString(const PlayerAction action) const
{
return Input::getInputAsString(m_bindings[action].type, m_bindings[action].id, m_bindings[action].dir);
}
#if 0
#pragma mark -

View File

@@ -38,6 +38,11 @@ public:
DeviceType getType() const { return m_type; };
/**
* returns a human-readable string for the key binded with the given action
*/
std::string getBindingAsString(const PlayerAction action) const;
void serialize(std::ofstream& stream);
bool deserializeAction(irr::io::IrrXMLReader* xml);
};

View File

@@ -617,50 +617,7 @@ void UserConfig::writeStickConfigs(lisp::Writer *writer)
writer->endList("stick-configs");
} // writeStickConfigs
*/
// -----------------------------------------------------------------------------
std::string UserConfig::getInputAsString(const Input &input)
{
std::string s;
switch (input.type)
{
case Input::IT_NONE:
s = _("not set");
break;
case Input::IT_KEYBOARD:
// TODO - implement with non-SDL code
// s = SDL_GetKeyName((SDLKey) input.id0);
s = "some key";
break;
case Input::IT_STICKMOTION:
s = StringUtils::insert_values( _("joy %d axis %d %s"), input.id0,
input.id1,
(input.id2 == Input::AD_NEGATIVE)
? '-' : '+' );
break;
case Input::IT_STICKBUTTON:
s = StringUtils::insert_values( _("joy %d btn %d"),
input.id0, input.id1);
break;
case Input::IT_STICKHAT:
s = StringUtils::insert_values( _("joy %d hat %d"),
input.id0, input.id1);
break;
case Input::IT_MOUSEBUTTON:
s = StringUtils::insert_values( _("mouse btn %d"), input.id0);
break;
case Input::IT_MOUSEMOTION:
s = StringUtils::insert_values( _("mouse axis %d %s"),
input.id0,
(input.id1 == Input::AD_NEGATIVE)
? '-': '+' );
break;
default:
s = _("Invalid");
}
return s;
} // GetKeyAsString
// -----------------------------------------------------------------------------
#if 0
@@ -752,7 +709,7 @@ void UserConfig::setStaticAction(StaticAction ga, const Input &i0, const Input &
* something else).
* \param player_index Player index 0, ..., max
*/
#if 0 // TODO
#if 0
std::string UserConfig::getInputDeviceName(int player_index) const
{
std::string config_name;

View File

@@ -147,7 +147,7 @@ private:
/** Creates an GameAction->Input mapping with four Inputs */
//void setStaticAction(StaticAction, const Input &, const Input &, const Input &, const Input &);
std::string getInputAsString(const Input &);
//std::string getInputAsString(const Input &);
/** Creates an ActionMap for the GameAction values of the specified
* range.