J :
* Display pictures for buttons on PSP in the keybinding screen. * Fix a bug where the New Binding... button would disappear when creating a new binding. * Fix a bug where the menu to choose the bound symbol was not modal.
This commit is contained in:
@@ -1,17 +1,11 @@
|
|||||||
#ifndef _TRANSLATEKEYS_H_
|
#ifndef _TRANSLATEKEYS_H_
|
||||||
#define _TRANSLATEKEYS_H_
|
#define _TRANSLATEKEYS_H_
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
|
|
||||||
struct KeyRep
|
typedef pair<string, JQuad*> KeyRep;
|
||||||
{
|
|
||||||
KeyRep(JQuad*, std::string);
|
|
||||||
JQuad* icon;
|
|
||||||
std::string text;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const KeyRep& translateKey(LocalKeySym);
|
const KeyRep& translateKey(LocalKeySym);
|
||||||
const KeyRep& translateKey(JButton);
|
const KeyRep& translateKey(JButton);
|
||||||
|
|
||||||
|
|||||||
@@ -493,6 +493,7 @@ class WGuiKeyBinder : public WGuiList {
|
|||||||
virtual bool isModal();
|
virtual bool isModal();
|
||||||
virtual bool CheckUserInput(JButton);
|
virtual bool CheckUserInput(JButton);
|
||||||
virtual void setData();
|
virtual void setData();
|
||||||
|
virtual void Update(float);
|
||||||
protected:
|
protected:
|
||||||
GameStateOptions* parent;
|
GameStateOptions* parent;
|
||||||
bool modal;
|
bool modal;
|
||||||
|
|||||||
@@ -446,15 +446,15 @@ void OptionKey::Render() {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const KeyRep& rep = translateKey(from);
|
const KeyRep& rep = translateKey(from);
|
||||||
if (rep.icon)
|
if (rep.second)
|
||||||
renderer->RenderQuad(rep.icon, x + 4, y + 2, 0, 0.5, 0.5);
|
renderer->RenderQuad(rep.second, x + 4, y + 2, 0, 16.0 / rep.second->mHeight, 16.0 / rep.second->mHeight);
|
||||||
else
|
else
|
||||||
mFont->DrawString(rep.text, x + 4, y + 2, JGETEXT_LEFT);
|
mFont->DrawString(rep.first, x + 4, y + 2, JGETEXT_LEFT);
|
||||||
const KeyRep& rep2 = translateKey(to);
|
const KeyRep& rep2 = translateKey(to);
|
||||||
if (rep2.icon)
|
if (rep2.second)
|
||||||
renderer->RenderQuad(rep2.icon, x + 4, y + 2, 0, 0.5, 0.5);
|
renderer->RenderQuad(rep2.second, x + 4, y + 2, 0, 16.0 / rep2.second->mHeight, 16.0 / rep2.second->mHeight);
|
||||||
else
|
else
|
||||||
mFont->DrawString(rep2.text, width - 4, y + 2, JGETEXT_RIGHT);
|
mFont->DrawString(rep2.first, width - 4, y + 2, JGETEXT_RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool OptionKey::CheckUserInput(JButton key) {
|
bool OptionKey::CheckUserInput(JButton key) {
|
||||||
@@ -479,13 +479,12 @@ void OptionKey::KeyPressed(LocalKeySym key) {
|
|||||||
grabbed = false;
|
grabbed = false;
|
||||||
|
|
||||||
btnMenu = NEW SimpleMenu(0, this, Constants::MENU_FONT, 80, 10);
|
btnMenu = NEW SimpleMenu(0, this, Constants::MENU_FONT, 80, 10);
|
||||||
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i)
|
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i) {
|
||||||
{
|
|
||||||
const KeyRep& rep = translateKey(btnList[i]);
|
const KeyRep& rep = translateKey(btnList[i]);
|
||||||
btnMenu->Add(i, rep.text.c_str());
|
btnMenu->Add(i, rep.first.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool OptionKey::isModal() { return grabbed; }
|
bool OptionKey::isModal() { return grabbed || btnMenu; }
|
||||||
void OptionKey::Overlay()
|
void OptionKey::Overlay()
|
||||||
{
|
{
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
@@ -500,8 +499,7 @@ void OptionKey::Overlay()
|
|||||||
else if (btnMenu)
|
else if (btnMenu)
|
||||||
btnMenu->Render();
|
btnMenu->Render();
|
||||||
}
|
}
|
||||||
void OptionKey::ButtonPressed(int controllerId, int controlId)
|
void OptionKey::ButtonPressed(int controllerId, int controlId) {
|
||||||
{
|
|
||||||
to = btnList[controlId];
|
to = btnList[controlId];
|
||||||
SAFE_DELETE(btnMenu);
|
SAFE_DELETE(btnMenu);
|
||||||
btnMenu = NULL;
|
btnMenu = NULL;
|
||||||
|
|||||||
@@ -6,17 +6,15 @@
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|
||||||
static map<const LocalKeySym, KeyRep const*> fattable;
|
static map<const LocalKeySym, KeyRep> fattable;
|
||||||
static map<const JButton, KeyRep const*> slimtable;
|
static map<const JButton, KeyRep> slimtable;
|
||||||
|
|
||||||
KeyRep::KeyRep(JQuad* icon, string text) : icon(icon), text(text) {}
|
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
const KeyRep& translateKey(LocalKeySym key) {
|
const KeyRep& translateKey(LocalKeySym key) {
|
||||||
{
|
{
|
||||||
map<const LocalKeySym, KeyRep const*>::iterator res;
|
map<const LocalKeySym, KeyRep>::iterator res;
|
||||||
if ((res = fattable.find(key)) != fattable.end())
|
if ((res = fattable.find(key)) != fattable.end())
|
||||||
return *(res->second);
|
return res->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* str = XKeysymToString(key);
|
char* str = XKeysymToString(key);
|
||||||
@@ -25,82 +23,121 @@ const KeyRep& translateKey(LocalKeySym key) {
|
|||||||
str = new char[11];
|
str = new char[11];
|
||||||
sprintf(str, "%lu", key);
|
sprintf(str, "%lu", key);
|
||||||
}
|
}
|
||||||
KeyRep* k = new KeyRep(NULL, str);
|
const KeyRep k = make_pair(str, static_cast<JQuad*>(NULL));
|
||||||
fattable[key] = k;
|
fattable[key] = k;
|
||||||
return *k;
|
return fattable[key];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
const KeyRep& translateKey(LocalKeySym key) {
|
const KeyRep& translateKey(LocalKeySym key) {
|
||||||
{
|
{
|
||||||
map<const LocalKeySym, KeyRep const*>::iterator res;
|
map<const LocalKeySym, KeyRep>::iterator res;
|
||||||
if ((res = fattable.find(key)) != fattable.end())
|
if ((res = fattable.find(key)) != fattable.end())
|
||||||
return *(res->second);
|
return *(res->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* I think the code should look like this ?
|
||||||
|
Documentation from : http://msdn.microsoft.com/en-us/library/ms171538.aspx
|
||||||
|
|
||||||
|
Keys keyCode = (Keys)((int)key) & Keys::KeyCode;
|
||||||
|
string s = keyCode.ToString();
|
||||||
|
KeyRep k;
|
||||||
|
if (0 == s.length()) {
|
||||||
|
char*str = new char[11];
|
||||||
|
sprintf(str, "%d", key);
|
||||||
|
k = make_pair(str, static_cast<JQuad*>(NULL));
|
||||||
|
}
|
||||||
|
else k = make_pair(s, static_cast<JQuad*>(NULL));
|
||||||
|
fattable[key] = k;
|
||||||
|
return fattable[key];
|
||||||
|
|
||||||
|
... Instead of the following :
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
char* str = new char[11];
|
char* str = new char[11];
|
||||||
sprintf(str, "%d", key);
|
sprintf(str, "%d", key);
|
||||||
KeyRep* k = new KeyRep(NULL, str);
|
const KeyRep k = make_pair(str, static_cast<JQuad*>(NULL));
|
||||||
fattable[key] = k;
|
fattable[key] = k;
|
||||||
return *k;
|
return fattable[key];
|
||||||
}
|
}
|
||||||
#else // PSP
|
#else // PSP
|
||||||
|
|
||||||
const KeyRep& translateKey(LocalKeySym key) {
|
|
||||||
map<const LocalKeySym, KeyRep const*>::iterator res;
|
|
||||||
if ((res = fattable.find(key)) != fattable.end())
|
|
||||||
return *(res->second);
|
|
||||||
|
|
||||||
if (fattable.end() == fattable.find(PSP_CTRL_SELECT))
|
const KeyRep& translateKey(LocalKeySym key) {
|
||||||
|
map<const LocalKeySym, KeyRep>::iterator res;
|
||||||
|
if ((res = fattable.find(key)) == fattable.end())
|
||||||
{
|
{
|
||||||
fattable[PSP_CTRL_SELECT] = new KeyRep(NULL, _("Select"));
|
if (fattable.end() == fattable.find(PSP_CTRL_SELECT))
|
||||||
fattable[PSP_CTRL_START] = new KeyRep(NULL, _("Start"));
|
{
|
||||||
fattable[PSP_CTRL_UP] = new KeyRep(NULL, _("Up"));
|
fattable[PSP_CTRL_SELECT] = make_pair(_("Select"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_RIGHT] = new KeyRep(NULL, _("Right"));
|
fattable[PSP_CTRL_START] = make_pair(_("Start"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_DOWN] = new KeyRep(NULL, _("Down"));
|
fattable[PSP_CTRL_UP] = make_pair(_("Up"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_LEFT] = new KeyRep(NULL, _("Left"));
|
fattable[PSP_CTRL_RIGHT] = make_pair(_("Right"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_LTRIGGER] = new KeyRep(NULL, _("Left trigger"));
|
fattable[PSP_CTRL_DOWN] = make_pair(_("Down"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_RTRIGGER] = new KeyRep(NULL, _("Right trigger"));
|
fattable[PSP_CTRL_LEFT] = make_pair(_("Left"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_TRIANGLE] = new KeyRep(NULL, _("Triangle"));
|
fattable[PSP_CTRL_LTRIGGER] = make_pair(_("Left trigger"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_CIRCLE] = new KeyRep(NULL, _("Circle"));
|
fattable[PSP_CTRL_RTRIGGER] = make_pair(_("Right trigger"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_CROSS] = new KeyRep(NULL, _("Cross"));
|
fattable[PSP_CTRL_TRIANGLE] = make_pair(_("Triangle"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_SQUARE] = new KeyRep(NULL, _("Square"));
|
fattable[PSP_CTRL_CIRCLE] = make_pair(_("Circle"), static_cast<JQuad*>(NULL));
|
||||||
fattable[PSP_CTRL_HOLD] = new KeyRep(NULL, _("Hold"));
|
fattable[PSP_CTRL_CROSS] = make_pair(_("Cross"), static_cast<JQuad*>(NULL));
|
||||||
|
fattable[PSP_CTRL_SQUARE] = make_pair(_("Square"), static_cast<JQuad*>(NULL));
|
||||||
|
fattable[PSP_CTRL_HOLD] = make_pair(_("Hold"), static_cast<JQuad*>(NULL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char* str = new char[11];
|
||||||
|
sprintf(str, "%d", key);
|
||||||
|
fattable[key] = make_pair(str, static_cast<JQuad*>(static_cast<JQuad*>(NULL)));
|
||||||
|
}
|
||||||
|
res = fattable.find(key);
|
||||||
}
|
}
|
||||||
if ((res = fattable.find(key)) != fattable.end())
|
KeyRep& k = res->second;
|
||||||
return *(res->second);
|
switch(key)
|
||||||
char* str = new char[11];
|
{
|
||||||
sprintf(str, "%d", key);
|
case PSP_CTRL_SELECT : k.second = resources.RetrieveQuad("iconspsp.png", (float)2*32, 32, 64, 32, "PSP_CTRL_SELECT", RETRIEVE_NORMAL); break;
|
||||||
KeyRep* k = new KeyRep(NULL, str);
|
case PSP_CTRL_START : k.second = resources.RetrieveQuad("iconspsp.png", (float)0*32, 32, 64, 32, "PSP_CTRL_START", RETRIEVE_NORMAL); break;
|
||||||
fattable[key] = k;
|
case PSP_CTRL_UP : k.second = resources.RetrieveQuad("iconspsp.png", (float)0*32, 0, 32, 32, "PSP_CTRL_UP", RETRIEVE_NORMAL); break;
|
||||||
return *k;
|
case PSP_CTRL_RIGHT : k.second = resources.RetrieveQuad("iconspsp.png", (float)3*32, 0, 32, 32, "PSP_CTRL_RIGHT", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_DOWN : k.second = resources.RetrieveQuad("iconspsp.png", (float)1*32, 0, 32, 32, "PSP_CTRL_DOWN", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_LEFT : k.second = resources.RetrieveQuad("iconspsp.png", (float)2*32, 0, 32, 32, "PSP_CTRL_LEFT", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_LTRIGGER : k.second = resources.RetrieveQuad("iconspsp.png", (float)6*32, 32, 64, 32, "PSP_CTRL_LTRIGGER", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_RTRIGGER : k.second = resources.RetrieveQuad("iconspsp.png", (float)8*32, 32, 64, 32, "PSP_CTRL_RTRIGGER", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_TRIANGLE : k.second = resources.RetrieveQuad("iconspsp.png", (float)5*32, 0, 32, 32, "PSP_CTRL_TRIANGLE", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_CIRCLE : k.second = resources.RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_CIRCLE", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_CROSS : k.second = resources.RetrieveQuad("iconspsp.png", (float)7*32, 0, 32, 32, "PSP_CTRL_CROSS", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_SQUARE : k.second = resources.RetrieveQuad("iconspsp.png", (float)6*32, 0, 32, 32, "PSP_CTRL_SQUARE", RETRIEVE_NORMAL); break;
|
||||||
|
case PSP_CTRL_HOLD : k.second = resources.RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32, "PSP_CTRL_HOLD", RETRIEVE_NORMAL); break;
|
||||||
|
default: /* Unknown key : no icon */ ;
|
||||||
|
}
|
||||||
|
return k;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const KeyRep& translateKey(JButton key) {
|
const KeyRep& translateKey(JButton key) {
|
||||||
{
|
{
|
||||||
map<const JButton, KeyRep const*>::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] = new KeyRep(NULL, _("None"));
|
slimtable[JGE_BTN_NONE] = make_pair(_("None"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_QUIT] = new KeyRep(NULL, _("Quit"));
|
slimtable[JGE_BTN_QUIT] = make_pair(_("Quit"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_MENU] = new KeyRep(NULL, _("Menu"));
|
slimtable[JGE_BTN_MENU] = make_pair(_("Menu"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_CTRL] = new KeyRep(NULL, _("Control"));
|
slimtable[JGE_BTN_CTRL] = make_pair(_("Control"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_POWER] = new KeyRep(NULL, _("Power"));
|
slimtable[JGE_BTN_POWER] = make_pair(_("Power"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_SOUND] = new KeyRep(NULL, _("Sound"));
|
slimtable[JGE_BTN_SOUND] = make_pair(_("Sound"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_RIGHT] = new KeyRep(NULL, _("Right"));
|
slimtable[JGE_BTN_RIGHT] = make_pair(_("Right"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_LEFT] = new KeyRep(NULL, _("Left"));
|
slimtable[JGE_BTN_LEFT] = make_pair(_("Left"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_UP] = new KeyRep(NULL, _("Up"));
|
slimtable[JGE_BTN_UP] = make_pair(_("Up"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_DOWN] = new KeyRep(NULL, _("Down"));
|
slimtable[JGE_BTN_DOWN] = make_pair(_("Down"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_OK] = new KeyRep(NULL, _("Ok"));
|
slimtable[JGE_BTN_OK] = make_pair(_("Ok"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_CANCEL] = new KeyRep(NULL, _("Cancel"));
|
slimtable[JGE_BTN_CANCEL] = make_pair(_("Cancel"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_PRI] = new KeyRep(NULL, _("Primary"));
|
slimtable[JGE_BTN_PRI] = make_pair(_("Primary"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_SEC] = new KeyRep(NULL, _("Secondary"));
|
slimtable[JGE_BTN_SEC] = make_pair(_("Secondary"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_PREV] = new KeyRep(NULL, _("Next phase/Previous item"));
|
slimtable[JGE_BTN_PREV] = make_pair(_("Next phase/Previous item"), static_cast<JQuad*>(NULL));
|
||||||
slimtable[JGE_BTN_NEXT] = new KeyRep(NULL, _("Open hand/Next item"));
|
slimtable[JGE_BTN_NEXT] = make_pair(_("Open hand/Next item"), static_cast<JQuad*>(NULL));
|
||||||
|
|
||||||
return *slimtable[key];
|
return slimtable[key];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1775,7 +1775,20 @@ WGuiKeyBinder::WGuiKeyBinder(string name, GameStateOptions* parent) : WGuiList(n
|
|||||||
for (JGE::keybindings_it it = start; it != end; ++it)
|
for (JGE::keybindings_it it = start; it != end; ++it)
|
||||||
Add(NEW OptionKey(parent, it->first, it->second));
|
Add(NEW OptionKey(parent, it->first, it->second));
|
||||||
}
|
}
|
||||||
bool WGuiKeyBinder::isModal() { return modal; }
|
void WGuiKeyBinder::Update(float dt) {
|
||||||
|
OptionKey* o = dynamic_cast<OptionKey*>(items[0]);
|
||||||
|
if (!o) return;
|
||||||
|
if (LOCAL_KEY_NONE != o->from) {
|
||||||
|
items.insert(items.begin(), NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE));
|
||||||
|
if (0 == currentItem) ++currentItem;
|
||||||
|
}
|
||||||
|
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it) (*it)->Update(dt);
|
||||||
|
}
|
||||||
|
bool WGuiKeyBinder::isModal() {
|
||||||
|
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it)
|
||||||
|
if ((*it)->isModal()) return true;
|
||||||
|
return modal;
|
||||||
|
}
|
||||||
bool WGuiKeyBinder::CheckUserInput(JButton key)
|
bool WGuiKeyBinder::CheckUserInput(JButton key)
|
||||||
{
|
{
|
||||||
if (!items[currentItem]->CheckUserInput(key))
|
if (!items[currentItem]->CheckUserInput(key))
|
||||||
@@ -1787,8 +1800,7 @@ bool WGuiKeyBinder::CheckUserInput(JButton key)
|
|||||||
void WGuiKeyBinder::setData(){
|
void WGuiKeyBinder::setData(){
|
||||||
JGE* j = JGE::GetInstance();
|
JGE* j = JGE::GetInstance();
|
||||||
j->ClearBindings();
|
j->ClearBindings();
|
||||||
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it)
|
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it) {
|
||||||
{
|
|
||||||
OptionKey* o = dynamic_cast<OptionKey*>(*it);
|
OptionKey* o = dynamic_cast<OptionKey*>(*it);
|
||||||
if (o && LOCAL_KEY_NONE != o->from && JGE_BTN_NONE != o->to)
|
if (o && LOCAL_KEY_NONE != o->from && JGE_BTN_NONE != o->to)
|
||||||
j->BindKey(o->from, o->to);
|
j->BindKey(o->from, o->to);
|
||||||
|
|||||||
Reference in New Issue
Block a user