Added support for deleting added keyboard configurations

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5929 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-09-08 22:40:54 +00:00
parent 559c7bf0b2
commit 244b40bfbf
5 changed files with 78 additions and 8 deletions

View File

@ -18,14 +18,19 @@
<box proportion="1" width="100%" layout="vertical-row">
<!-- Configuration name -->
<spacer height="6" width="10"/>
<label id="title" width="100%" text_align="center" text="[none]" />
<label id="title" width="100%" text_align="center" />
<spacer height="16" width="10"/>
<!-- List of key bindings -->
<list id="actions" proportion="5" width="75%" align="center"/>
<!-- Bottom buttons -->
<spacer width="50" height="20" />
<button id="delete"
I18N="To delete a keyboard configuration" text="Delete Configuration"/>
<spacer width="50" height="10" />
<button id="back_to_device_list" I18N="In the input configuration screen" text="Back to device list"/>
<spacer width="50" height="10" />

View File

@ -191,10 +191,46 @@ void DeviceManager::addEmptyKeyboard()
}
// -----------------------------------------------------------------------------
void DeviceManager::addGamepad(GamePadDevice* d)
{
m_gamepads.push_back(d);
}
// -----------------------------------------------------------------------------
bool DeviceManager::deleteConfig(DeviceConfig* config)
{
for (int n=0; n<m_keyboards.size(); n++)
{
if (m_keyboards[n].getConfiguration() == config)
{
m_keyboards.erase(n);
n--;
}
}
for (int n=0; n<m_gamepads.size(); n++)
{
if (m_gamepads[n].getConfiguration() == config)
{
m_gamepads.erase(n);
n--;
}
}
if (m_keyboard_configs.erase(config))
{
return true;
}
if (m_gamepad_configs.erase(config))
{
return true;
}
return false;
}
// -----------------------------------------------------------------------------
InputDevice* DeviceManager::mapKeyboardInput( int btnID, InputManager::InputDriverMode mode,

View File

@ -102,7 +102,10 @@ public:
KeyboardDevice* getKeyboardFromBtnID(const int btnID);
/**
* \brief Delete the given config and removes DeviceManager references to it.
*/
bool deleteConfig(DeviceConfig* config);
/** 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.

View File

@ -65,6 +65,21 @@ void OptionsScreenInput2::init()
RibbonWidget* tabBar = this->getWidget<RibbonWidget>("options_choice");
if (tabBar != NULL) tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
ButtonWidget* deleteBtn = this->getWidget<ButtonWidget>("delete");
if (m_config->getType() != DEVICE_CONFIG_TYPE_KEYBOARD)
{
deleteBtn->setDeactivated();
}
else if (input_manager->getDeviceList()->getKeyboardAmount() < 2)
{
// don't allow deleting the last config
deleteBtn->setDeactivated();
}
else
{
deleteBtn->setActivated();
}
LabelWidget* label = this->getWidget<LabelWidget>("title");
label->setText( m_config->getName().c_str() );
@ -373,6 +388,16 @@ void OptionsScreenInput2::eventCallback(Widget* widget, const std::string& name,
}
}
}
else if (name == "delete")
{
// TODO: ask for confirmation before deleting
const bool success = input_manager->getDeviceList()->deleteConfig(m_config);
assert(success);
m_config = NULL;
input_manager->getDeviceList()->serialize();
StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}
} // eventCallback
// -----------------------------------------------------------------------------

View File

@ -179,21 +179,22 @@ void remove(TYPE* obj)
}
/**
* Removes and deletes
* \brief Removes and deletes the given object.
* \return whether this object was found in the vector and deleted
*/
void erase(TYPE* obj)
bool erase(void* obj)
{
for(unsigned int n=0; n<contentsVector.size(); n++)
{
TYPE * pointer = contentsVector[n];
if(pointer == obj)
if((void*)pointer == obj)
{
contentsVector.erase(contentsVector.begin()+n);
delete pointer;
return;
return true;
}
}
return false;
}
};