Added basic input conflict reporting (conflicting bindings)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5399 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-05-07 01:06:03 +00:00
parent 92ae1673ab
commit e0ed3291e0
3 changed files with 116 additions and 0 deletions

View File

@@ -124,6 +124,9 @@ void ListWidget::renameItem(const int itemID, const irr::core::stringw newName,
m_items[itemID].m_label = newName;
list->setItem(itemID, newName.c_str(), icon);
list->setItemOverrideColor( itemID, EGUI_LBC_TEXT , video::SColor(255,0,0,0) );
list->setItemOverrideColor( itemID, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,255,255) );
}
// -----------------------------------------------------------------------------
@@ -197,3 +200,29 @@ void ListWidget::elementRemoved()
Widget::elementRemoved();
m_items.clear();
}
// -----------------------------------------------------------------------------
int ListWidget::getItemID(const std::string internalName) const
{
const int count = m_items.size();
for (int i=0; i<count; i++)
{
if (m_items[i].m_internal_name == internalName) return i;
}
return -1;
}
// -----------------------------------------------------------------------------
void ListWidget::markItemRed(const int id)
{
IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>();
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT, video::SColor(255,255,0,0) );
irritem->setItemOverrideColor( id, EGUI_LBC_TEXT_HIGHLIGHT, video::SColor(255,255,0,0) );
}
// -----------------------------------------------------------------------------

View File

@@ -107,6 +107,11 @@ namespace GUIEngine
irr::core::stringw getSelectionLabel() const;
/**
* \brief Finds the ID of the item that has a given internal name
*/
int getItemID(const std::string internalName) const;
/**
* \brief change the selected item
* \param index the index of the element to select within the list, or -1 to select nothing
@@ -114,8 +119,27 @@ namespace GUIEngine
*/
void setSelectionID(const int index);
/** \brief rename an item and/or change its icon based on its ID */
void renameItem(const int itemID, const irr::core::stringw newName, const int icon=-1);
/** \brief rename an item and/or change its icon based on its internal name */
void renameItem(const std::string internalName, const irr::core::stringw newName,
const int icon=-1)
{
const int id = getItemID(internalName);
assert(id != -1);
renameItem( id, newName, icon );
}
void markItemRed(const int id);
void markItemRed(const std::string internalName)
{
const int id = getItemID(internalName);
assert(id != -1);
markItemRed( id );
}
virtual void elementRemoved();
};
}

View File

@@ -172,6 +172,69 @@ void OptionsScreenInput2::updateInputButtons()
//I18N: Key binding name
actions->renameItem(16, makeLabel( _("Cancel/Back"), PA_MENU_CANCEL) );
// ---- 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;
action <= PA_LAST_GAME_ACTION;
action=PlayerAction(action+1))
{
const irr::core::stringw item = m_config->getBindingAsString(action);
if (currentlyUsedKeys.find(item) == currentlyUsedKeys.end())
{
currentlyUsedKeys.insert( item );
}
else
{
// binding conflict!
actions->markItemRed( KartActionStrings[action] );
// also mark others
for (PlayerAction others = PA_FIRST_GAME_ACTION;
others < action; others=PlayerAction(others+1))
{
const irr::core::stringw others_item = m_config->getBindingAsString(others);
if (others_item == item)
{
actions->markItemRed( KartActionStrings[others] );
}
}
//actions->renameItem( KartActionStrings[action], _("Binding Conflict!") );
}
}
// menu keys and game keys can overlap, no problem, so forget game keys before checking menu keys
currentlyUsedKeys.clear();
for (PlayerAction action = PA_FIRST_MENU_ACTION;
action <= PA_LAST_MENU_ACTION;
action=PlayerAction(action+1))
{
const irr::core::stringw item = m_config->getBindingAsString(action);
if (currentlyUsedKeys.find(item) == currentlyUsedKeys.end())
{
currentlyUsedKeys.insert( item );
}
else
{
// binding conflict!
actions->markItemRed( KartActionStrings[action] );
// also mark others
for (PlayerAction others = PA_FIRST_MENU_ACTION;
others < action; others=PlayerAction(others+1))
{
const irr::core::stringw others_item = m_config->getBindingAsString(others);
if (others_item == item)
{
actions->markItemRed( KartActionStrings[others] );
}
}
//actions->renameItem( KartActionStrings[action], _("Binding Conflict!") );
}
}
}
// -----------------------------------------------------------------------------