- added ability to reload default key bindings

- reverted keybindings display back to action names instead of PSP key equivalent (see commit commit 168154b52d)
This commit is contained in:
Rolzad73
2017-02-01 22:53:01 -05:00
parent fb91726c35
commit 1d0237f15d
4 changed files with 58 additions and 34 deletions

View File

@@ -998,6 +998,8 @@ protected:
set<LocalKeySym> confirmedKeys; set<LocalKeySym> confirmedKeys;
set<JButton> confirmedButtons; set<JButton> confirmedButtons;
string confirmationString; string confirmationString;
private:
void populateKeyBindingList();
}; };
/**@} This comment used by Doxyyen. */ /**@} This comment used by Doxyyen. */

View File

@@ -135,14 +135,14 @@ const KeyRep& translateKey(LocalKeySym key)
#endif #endif
const KeyRep& translateKey(JButton key) { const KeyRep& translateKey(JButton key) {
/*
{ {
map<const JButton, KeyRep>::iterator res; map<const JButton, KeyRep>::iterator res;
if ((res = slimtable.find(key)) != slimtable.end()) if ((res = slimtable.find(key)) != slimtable.end())
return res->second; return res->second;
} }
slimtable[JGE_BTN_NONE] = make_pair(_("None"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_NONE] = make_pair(_("Delete this binding"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_QUIT] = make_pair(_("Quit"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_QUIT] = make_pair(_("Quit"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_MENU] = make_pair(_("Menu"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_MENU] = make_pair(_("Menu"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_CTRL] = make_pair(_("Control"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_CTRL] = make_pair(_("Control"), static_cast<JQuad*>(NULL));
@@ -158,10 +158,11 @@ const KeyRep& translateKey(JButton key) {
slimtable[JGE_BTN_SEC] = make_pair(_("Secondary"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_SEC] = make_pair(_("Secondary"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_PREV] = make_pair(_("Next phase/Previous item"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_PREV] = make_pair(_("Next phase/Previous item"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_NEXT] = make_pair(_("Open hand/Next item"), static_cast<JQuad*>(NULL)); slimtable[JGE_BTN_NEXT] = make_pair(_("Open hand/Next item"), static_cast<JQuad*>(NULL));
slimtable[JGE_BTN_FULLSCREEN] = make_pair(_("Fullscreen"), static_cast<JQuad*>(NULL));
return slimtable[key]; return slimtable[key];
*/
/*
map<const JButton, KeyRep>::iterator res; map<const JButton, KeyRep>::iterator res;
if ((res = slimtable.find(key)) == slimtable.end()) if ((res = slimtable.find(key)) == slimtable.end())
{ {
@@ -205,7 +206,8 @@ const KeyRep& translateKey(JButton key) {
case JGE_BTN_OK : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL).get(); break; case JGE_BTN_OK : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_SEC : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL).get(); break; case JGE_BTN_SEC : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL).get(); break;
case JGE_BTN_PRI : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL).get(); break; case JGE_BTN_PRI : k.second = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL).get(); break;
default: /* Unknown key : no icon */ ; default: ; // Unknown key : no icon
} }
return k; return k;
*/
} }

View File

@@ -2276,22 +2276,17 @@ WGuiKeyBinder::WGuiKeyBinder(string name, GameStateOptions* parent) :
WGuiList(name), parent(parent), confirmMenu(NULL), modal(false), confirmed(CONFIRM_NEED), confirmingKey(LOCAL_KEY_NONE), WGuiList(name), parent(parent), confirmMenu(NULL), modal(false), confirmed(CONFIRM_NEED), confirmingKey(LOCAL_KEY_NONE),
confirmingButton(JGE_BTN_NONE), confirmationString("") confirmingButton(JGE_BTN_NONE), confirmationString("")
{ {
JGE* j = JGE::GetInstance(); populateKeyBindingList();
JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
Add(NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE));
for (JGE::keybindings_it it = start; it != end; ++it)
Add(NEW OptionKey(parent, it->first, it->second));
} }
void WGuiKeyBinder::Update(float dt) void WGuiKeyBinder::Update(float dt)
{ {
OptionKey* o = dynamic_cast<OptionKey*> (items[0]); OptionKey* o = dynamic_cast<OptionKey*> (items[1]);
if (!o) return; if (!o) return;
if (LOCAL_KEY_NONE != o->from) if (LOCAL_KEY_NONE != o->from)
{ {
items.insert(items.begin(), NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE)); items.insert(items.begin() + 1, NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE));
if (0 == currentItem) ++currentItem; if (1 == currentItem) ++currentItem;
} }
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it) for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it)
(*it)->Update(dt); (*it)->Update(dt);
@@ -2416,7 +2411,11 @@ WGuiBase::CONFIRM_TYPE WGuiKeyBinder::needsConfirm()
void WGuiKeyBinder::ButtonPressed(int controllerId, int controlId) void WGuiKeyBinder::ButtonPressed(int controllerId, int controlId)
{ {
if (2 == controlId) if (1 == controlId)
{
confirmed = CONFIRM_CANCEL;
}
else if (2 == controlId) {
switch (controllerId) switch (controllerId)
{ {
case 0: case 0:
@@ -2426,8 +2425,16 @@ void WGuiKeyBinder::ButtonPressed(int controllerId, int controlId)
confirmedButtons.insert(confirmingButton); confirmedButtons.insert(confirmingButton);
break; break;
} }
else }
confirmed = CONFIRM_CANCEL; else if (3 == controlId) {
switch (controllerId)
{
case -102:
JGE::GetInstance()->ResetBindings();
populateKeyBindingList();
break;
}
}
SAFE_DELETE(confirmMenu); SAFE_DELETE(confirmMenu);
confirmMenu = NULL; confirmMenu = NULL;
} }
@@ -2460,3 +2467,16 @@ bool WGuiKeyBinder::yieldFocus()
{ {
return true; return true;
} }
void WGuiKeyBinder::populateKeyBindingList()
{
items.clear();
DebugTrace(items.empty());
Add(NEW WGuiButton(NEW WGuiItem("Load Defaults..."), -102, 3, this));
Add(NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE));
JGE* j = JGE::GetInstance();
JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
for (JGE::keybindings_it it = start; it != end; ++it)
Add(NEW OptionKey(parent, it->first, it->second));
}