mark conflicts between configuration in blue for #39 (commit with Auria's blessing)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9656 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
red-skull 2011-08-29 02:21:50 +00:00
parent c4d06b5c1e
commit c4a24ad6b6
7 changed files with 99 additions and 11 deletions

View File

@ -22,16 +22,23 @@
<spacer height="16" width="10"/>
<!-- List of key bindings -->
<list id="actions" proportion="5" width="75%" align="center"/>
<list id="actions" proportion="8" width="75%" align="center"/>
<!-- Bottom buttons -->
<spacer width="50" height="20" />
<div proportion="2" width="100%" layout="horizontal-row">
<div height="100%" width="fit" layout="vertical-row">
<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" />
</div>
<spacer width="20" height="10" />
<label id="conflict" proportion="1" text="" word_wrap="true" align="center"/>
</div>
</box>
</div>

View File

@ -371,3 +371,14 @@ bool DeviceConfig::hasBindingFor(const int button_id) const
}
return false;
}
//------------------------------------------------------------------------------
bool DeviceConfig::hasBindingFor(const int button_id, PlayerAction from, PlayerAction to) const
{
for (int n=from; n<=to; n++)
{
if (m_bindings[n].getId() == button_id) return true;
}
return false;
}

View File

@ -125,6 +125,7 @@ public:
Binding& getBinding (int i) {return m_bindings[i];}
bool hasBindingFor(const int buttonID) const;
bool hasBindingFor(const int buttonID, PlayerAction from, PlayerAction to) const;
/** At this time only relevant for gamepads, keyboards are always enabled */
bool isEnabled() const { return m_enabled; }

View File

@ -338,6 +338,27 @@ void ListWidget::markItemRed(const int id, bool red)
// -----------------------------------------------------------------------------
void ListWidget::markItemBlue(const int id, bool blue)
{
// May only be called AFTER this widget has been add()ed
assert(m_element != NULL);
IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>();
if (blue)
{
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,0,0,255) );
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,0,0,255) );
}
else
{
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,0,0,0) );
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,255,255) );
}
}
// -----------------------------------------------------------------------------
EventPropagation ListWidget::transmitEvent(Widget* w, std::string& originator, const int playerID)
{
if (originator.find(m_properties[PROP_ID] + "_column_") != std::string::npos)

View File

@ -183,6 +183,7 @@ namespace GUIEngine
* \pre may only be called after the widget has been added to the screen with add()
*/
void markItemRed(const int id, bool red=true);
void markItemBlue(const int id, bool blue=true);
/**
* \brief Make an item red to mark an error, for instance
@ -195,6 +196,13 @@ namespace GUIEngine
markItemRed( id, red );
}
void markItemBlue(const std::string internalName, bool blue=true)
{
const int id = getItemID(internalName);
assert(id != -1);
markItemBlue( id, blue );
}
/** Override callback from Widget */
virtual EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID);

View File

@ -223,6 +223,8 @@ void OptionsScreenInput2::updateInputButtons()
actions->renameItem(i++, makeLabel( _("Cancel/Back"), PA_MENU_CANCEL) );
bool conflicts = false;
// ---- make sure there are no binding conflicts (same key used for two actions)
std::set<irr::core::stringw> currentlyUsedKeys;
for (PlayerAction action = PA_FIRST_GAME_ACTION;
@ -233,6 +235,12 @@ void OptionsScreenInput2::updateInputButtons()
if (currentlyUsedKeys.find(item) == currentlyUsedKeys.end())
{
currentlyUsedKeys.insert( item );
if (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD
&& conflictsBetweenKbdConfig(action, PA_FIRST_GAME_ACTION, PA_LAST_GAME_ACTION))
{
conflicts = true;
actions->markItemBlue (KartActionStrings[action]);
}
}
else
{
@ -264,6 +272,12 @@ void OptionsScreenInput2::updateInputButtons()
if (currentlyUsedKeys.find(item) == currentlyUsedKeys.end())
{
currentlyUsedKeys.insert( item );
if (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD
&& conflictsBetweenKbdConfig(action, PA_FIRST_MENU_ACTION, PA_LAST_MENU_ACTION))
{
conflicts = true;
actions->markItemBlue (KartActionStrings[action]);
}
}
else
{
@ -284,6 +298,13 @@ void OptionsScreenInput2::updateInputButtons()
//actions->renameItem( KartActionStrings[action], _("Binding Conflict!") );
}
}
GUIEngine::Widget* conflict_label = this->getWidget<GUIEngine::LabelWidget>("conflict");
if (conflicts)
conflict_label->setText( _("* A blue item means a conflict with another configuration") );
else
conflict_label->setText("");
} // updateInputButtons
// -----------------------------------------------------------------------------
@ -491,3 +512,20 @@ void OptionsScreenInput2::onConfirm()
}
// -----------------------------------------------------------------------------
bool OptionsScreenInput2::conflictsBetweenKbdConfig(PlayerAction action,
PlayerAction from, PlayerAction to)
{
KeyboardConfig* other_kbd_config;
int id = m_config->getBinding(action).getId();
for (int i=0; i < input_manager->getDeviceList()->getKeyboardAmount(); i++) {
other_kbd_config = input_manager->getDeviceList()->getKeyboardConfig(i);
if (m_config != other_kbd_config && other_kbd_config->hasBindingFor(id, from, to)
&& (other_kbd_config->getBinding(action).getId() != id || action == PA_FIRE)) {
return true;
}
}
return false;
}

View File

@ -45,6 +45,8 @@ class OptionsScreenInput2 : public GUIEngine::Screen,
void updateInputButtons();
bool conflictsBetweenKbdConfig(PlayerAction action, PlayerAction from, PlayerAction to);
DeviceConfig* m_config;
irr::core::stringw makeLabel(const irr::core::stringw translatedName, PlayerAction action) const;