options screen will now show current binding

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3537 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-05-24 01:22:13 +00:00
parent e9a136b556
commit cc2c62e024
5 changed files with 125 additions and 42 deletions

View File

@ -14,67 +14,67 @@
<scrollable_ribbon id="devices" proportion="3" text="all" width="100%" square_items="false" align="center" child_width="256" child_height="128" /> <scrollable_ribbon id="devices" proportion="3" text="all" width="100%" square_items="false" align="center" child_width="256" child_height="128" />
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Accelerate"/> <label proportion="2" height="100%" text="Accelerate" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_up" proportion="1" height="100%" text="[none]"/> <button id="binding_up" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Brake"/> <label proportion="2" height="100%" text="Brake" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_down" proportion="1" height="100%" text="[none]"/> <button id="binding_down" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Left"/> <label proportion="2" height="100%" text="Left" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_left" proportion="1" height="100%" text="[none]"/> <button id="binding_left" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Right"/> <label proportion="2" height="100%" text="Right" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_right" proportion="1" height="100%" text="[none]"/> <button id="binding_right" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Fire"/> <label proportion="2" height="100%" text="Fire" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_fire" proportion="1" height="100%" text="[none]"/> <button id="binding_fire" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center" >
<label proportion="2" height="100%" text="Nitro"/> <label proportion="2" height="100%" text="Nitro" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_nitro" proportion="1" height="100%" text="[none]"/> <button id="binding_nitro" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Sharp Turn"/> <label proportion="2" height="100%" text="Sharp Turn" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_drift" proportion="1" height="100%" text="[none]"/> <button id="binding_drift" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Rescue"/> <label proportion="2" height="100%" text="Rescue" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_rescue" proportion="1" height="100%" text="[none]"/> <button id="binding_rescue" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer height="5" width="10"/> <spacer height="5" width="10"/>
<div width="75%" proportion="1" layout="horizontal-row" > <div width="85%" proportion="1" layout="horizontal-row" align="center">
<label proportion="2" height="100%" text="Look Back"/> <label proportion="2" height="100%" text="Look Back" text_align="right"/>
<spacer width="20" height="100%" /> <spacer proportion="1" height="100%" />
<button id="binding_look_back" proportion="1" height="100%" text="[none]"/> <button id="binding_look_back" proportion="2" height="100%" text="[none]"/>
</div> </div>
<spacer width="50" height="10" /> <spacer width="50" height="10" />

View File

@ -9,6 +9,7 @@
#include "input/device_manager.hpp" #include "input/device_manager.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "gui/state_manager.hpp" #include "gui/state_manager.hpp"
#include <iostream>
using namespace GUIEngine; using namespace GUIEngine;
@ -17,8 +18,11 @@ using namespace GUIEngine;
*/ */
namespace StateManager namespace StateManager
{ {
void eventInput(Widget* widget, const std::string& name);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void initAudioVideo(Widget* widget, std::string& name) void initAudioVideo(Widget* widget, const std::string& name)
{ {
// ---- sfx volume // ---- sfx volume
SpinnerWidget* gauge = getCurrentScreen()->getWidget<SpinnerWidget>("sfx_volume"); SpinnerWidget* gauge = getCurrentScreen()->getWidget<SpinnerWidget>("sfx_volume");
@ -113,7 +117,7 @@ namespace StateManager
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void eventAudioVideo(Widget* widget, std::string& name) void eventAudioVideo(Widget* widget, const std::string& name)
{ {
if(name == "music_volume") if(name == "music_volume")
{ {
@ -193,7 +197,50 @@ namespace StateManager
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void initInput(Widget* widget, std::string& name) void updateInputButtons(const InputDevice* device)
{
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_up");
btn->setLabel( device->getBindingAsString(PA_ACCEL).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_down");
btn->setLabel( device->getBindingAsString(PA_BRAKE).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_left");
btn->setLabel( device->getBindingAsString(PA_LEFT).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_right");
btn->setLabel( device->getBindingAsString(PA_RIGHT).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_fire");
btn->setLabel( device->getBindingAsString(PA_FIRE).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_nitro");
btn->setLabel( device->getBindingAsString(PA_NITRO).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_drift");
btn->setLabel( device->getBindingAsString(PA_DRIFT).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_rescue");
btn->setLabel( device->getBindingAsString(PA_RESCUE).c_str() );
}
{
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>("binding_look_back");
btn->setLabel( device->getBindingAsString(PA_LOOK_BACK).c_str() );
}
}
// -----------------------------------------------------------------------------
void initInput(Widget* widget, const std::string& name)
{ {
{ {
RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices"); RibbonGridWidget* devices = getCurrentScreen()->getWidget<RibbonGridWidget>("devices");
@ -215,17 +262,48 @@ namespace StateManager
} }
devices->updateItemDisplay(); devices->updateItemDisplay();
// trigger displaying bindings for default selected device
const std::string name("devices");
eventInput(devices, name);
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void eventInput(Widget* widget, std::string& name) void eventInput(Widget* widget, const std::string& name)
{ {
if(name == "devices")
{
RibbonGridWidget* devices = dynamic_cast<RibbonGridWidget*>(widget);
const std::string& selection = devices->getSelectionName();
if( selection.find("gamepad") != std::string::npos )
{
int i = -1, read = 0;
read = sscanf( selection.c_str(), "gamepad%i", &i );
if(read == 1 && i != -1)
{
updateInputButtons( input_manager->getDeviceList()->getGamePad(i) );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(selection == "keyboard")
{
updateInputButtons( input_manager->getDeviceList()->getKeyboard(0) );
}
else
{
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// main call (from StateManager); dispatches the call to a specialissed function as needed // main call (from StateManager); dispatches the call to a specialissed function as needed
void menuEventOptions(Widget* widget, std::string& name) void menuEventOptions(Widget* widget, const std::string& name)
{ {
const std::string& screen_name = getCurrentScreen()->getName(); const std::string& screen_name = getCurrentScreen()->getName();

View File

@ -11,7 +11,7 @@ namespace GUIEngine
namespace StateManager namespace StateManager
{ {
void menuEventOptions(GUIEngine::Widget* widget, std::string& name); void menuEventOptions(GUIEngine::Widget* widget, const std::string& name);
} }

View File

@ -228,6 +228,10 @@ void ButtonWidget::add()
m_element->setTabOrder(id); m_element->setTabOrder(id);
m_element->setTabGroup(false); m_element->setTabGroup(false);
} }
void ButtonWidget::setLabel(const char* label)
{
m_element->setText( stringw(label).c_str() );
}
#if 0 #if 0
#pragma mark - #pragma mark -

View File

@ -152,6 +152,7 @@ namespace GUIEngine
void add(); void add();
public: public:
virtual ~ButtonWidget() {} virtual ~ButtonWidget() {}
void setLabel(const char* label);
}; };
class LabelWidget : public Widget class LabelWidget : public Widget