J :
* This finalizes the functionality for key bindings. * Key bindings are saved in the user's configuration file and read back the next time. * Still got to do : display, instead of a number, an icon on PSP and a string on windows (linux/mac already done).
This commit is contained in:
@@ -133,6 +133,7 @@ private:
|
|||||||
|
|
||||||
class GameOptionKeyBindings : public GameOption {
|
class GameOptionKeyBindings : public GameOption {
|
||||||
virtual bool read(string input);
|
virtual bool read(string input);
|
||||||
|
virtual bool write(std::ofstream*, string);
|
||||||
};
|
};
|
||||||
|
|
||||||
class OptionVolume: public EnumDefinition{
|
class OptionVolume: public EnumDefinition{
|
||||||
|
|||||||
@@ -139,12 +139,17 @@ class OptionKey : public WGuiItem, public KeybGrabber {
|
|||||||
LocalKeySym from;
|
LocalKeySym from;
|
||||||
JButton to;
|
JButton to;
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
virtual void Update(float);
|
||||||
virtual void Overlay();
|
virtual void Overlay();
|
||||||
virtual bool CheckUserInput(JButton key);
|
virtual bool CheckUserInput(JButton key);
|
||||||
virtual void KeyPressed(LocalKeySym key);
|
virtual void KeyPressed(LocalKeySym key);
|
||||||
virtual bool isModal();
|
virtual bool isModal();
|
||||||
|
virtual void ButtonPressed(int controllerId, int controlId);
|
||||||
|
virtual bool Visible();
|
||||||
|
virtual bool Selectable();
|
||||||
protected:
|
protected:
|
||||||
bool grabbed;
|
bool grabbed;
|
||||||
GameStateOptions* g;
|
GameStateOptions* g;
|
||||||
|
SimpleMenu* btnMenu;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -490,6 +490,7 @@ class WGuiKeyBinder : public WGuiList {
|
|||||||
WGuiKeyBinder(string name, GameStateOptions* parent);
|
WGuiKeyBinder(string name, GameStateOptions* parent);
|
||||||
virtual bool isModal();
|
virtual bool isModal();
|
||||||
virtual bool CheckUserInput(JButton);
|
virtual bool CheckUserInput(JButton);
|
||||||
|
virtual void setData();
|
||||||
protected:
|
protected:
|
||||||
GameStateOptions* parent;
|
GameStateOptions* parent;
|
||||||
bool modal;
|
bool modal;
|
||||||
|
|||||||
@@ -912,3 +912,14 @@ bool GameOptionKeyBindings::read(string input){
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GameOptionKeyBindings::write(std::ofstream* file, string name) {
|
||||||
|
JGE* j = JGE::GetInstance();
|
||||||
|
*file << name << "=";
|
||||||
|
JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
|
||||||
|
if (start != end) { *file << start->first << ":" << start->second; ++start; }
|
||||||
|
for (JGE::keybindings_it it = start; it != end; ++it)
|
||||||
|
*file << "," << it->first << ":" << it->second;
|
||||||
|
*file << endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ void GameStateOptions::Update(float dt)
|
|||||||
JButton key;
|
JButton key;
|
||||||
if (grabber) {
|
if (grabber) {
|
||||||
LocalKeySym sym;
|
LocalKeySym sym;
|
||||||
if (LOCAL_NO_KEY != (sym = j->ReadLocalKey()))
|
if (LOCAL_KEY_NONE != (sym = j->ReadLocalKey()))
|
||||||
grabber->KeyPressed(sym);
|
grabber->KeyPressed(sym);
|
||||||
}
|
}
|
||||||
else while ((key = JGE::GetInstance()->ReadButton())){
|
else while ((key = JGE::GetInstance()->ReadButton())){
|
||||||
|
|||||||
@@ -430,37 +430,60 @@ void OptionTheme::confirmChange(bool confirmed){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionKey::OptionKey(GameStateOptions* g, LocalKeySym from, JButton to) : WGuiItem(""), from(from), to(to), grabbed(false), g(g) {}
|
OptionKey::OptionKey(GameStateOptions* g, LocalKeySym from, JButton to) : WGuiItem(""), from(from), to(to), grabbed(false), g(g), btnMenu(NULL) {}
|
||||||
|
|
||||||
|
void OptionKey::Update(float dt) { if (btnMenu) btnMenu->Update(dt); }
|
||||||
void OptionKey::Render() {
|
void OptionKey::Render() {
|
||||||
JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT);
|
JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT);
|
||||||
mFont->SetColor(getColor(WGuiColor::TEXT));
|
mFont->SetColor(getColor(WGuiColor::TEXT));
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
const KeyRep& rep = translateKey(from);
|
if (LOCAL_KEY_NONE == from)
|
||||||
if (rep.icon)
|
{
|
||||||
renderer->RenderQuad(rep.icon, x + 2, y + 2);
|
string msg = _("New binding...");
|
||||||
|
mFont->DrawString(msg, (SCREEN_WIDTH - mFont->GetStringWidth(msg.c_str())) / 2, y + 2);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mFont->DrawString(rep.text, x + 4, y + 2, JGETEXT_LEFT);
|
{
|
||||||
const KeyRep& rep2 = translateKey(to);
|
const KeyRep& rep = translateKey(from);
|
||||||
if (rep2.icon)
|
if (rep.icon)
|
||||||
renderer->RenderQuad(rep2.icon, x + 2, y + 2);
|
renderer->RenderQuad(rep.icon, x + 2, y + 2);
|
||||||
else
|
else
|
||||||
mFont->DrawString(rep2.text, width - 4, y + 2, JGETEXT_RIGHT);
|
mFont->DrawString(rep.text, x + 4, y + 2, JGETEXT_LEFT);
|
||||||
|
const KeyRep& rep2 = translateKey(to);
|
||||||
|
if (rep2.icon)
|
||||||
|
renderer->RenderQuad(rep2.icon, x + 2, y + 2);
|
||||||
|
else
|
||||||
|
mFont->DrawString(rep2.text, width - 4, y + 2, JGETEXT_RIGHT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bool OptionKey::CheckUserInput(JButton key) {
|
bool OptionKey::CheckUserInput(JButton key) {
|
||||||
if (JGE_BTN_OK == key)
|
if (btnMenu)
|
||||||
{
|
return btnMenu->CheckUserInput(key);
|
||||||
|
if (JGE_BTN_OK == key) {
|
||||||
grabbed = true;
|
grabbed = true;
|
||||||
g->GrabKeyboard(this);
|
g->GrabKeyboard(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JButton btnList[] = {JGE_BTN_MENU, JGE_BTN_CTRL, JGE_BTN_RIGHT,
|
||||||
|
JGE_BTN_LEFT, JGE_BTN_UP, JGE_BTN_DOWN,
|
||||||
|
JGE_BTN_OK, JGE_BTN_CANCEL, JGE_BTN_PRI,
|
||||||
|
JGE_BTN_SEC, JGE_BTN_PREV, JGE_BTN_NEXT,
|
||||||
|
JGE_BTN_NONE};
|
||||||
void OptionKey::KeyPressed(LocalKeySym key) {
|
void OptionKey::KeyPressed(LocalKeySym key) {
|
||||||
cout << "KEY : " << key << endl;
|
from = key;
|
||||||
g->UngrabKeyboard(this);
|
g->UngrabKeyboard(this);
|
||||||
grabbed = false;
|
grabbed = false;
|
||||||
|
|
||||||
|
btnMenu = NEW SimpleMenu(0, this, Constants::MENU_FONT, 80, 10);
|
||||||
|
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
const KeyRep& rep = translateKey(btnList[i]);
|
||||||
|
btnMenu->Add(i, rep.text.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bool OptionKey::isModal() { return grabbed; }
|
bool OptionKey::isModal() { return grabbed; }
|
||||||
void OptionKey::Overlay()
|
void OptionKey::Overlay()
|
||||||
@@ -468,11 +491,20 @@ void OptionKey::Overlay()
|
|||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT);
|
JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT);
|
||||||
mFont->SetColor(ARGB(255, 0, 0, 0));
|
mFont->SetColor(ARGB(255, 0, 0, 0));
|
||||||
if (grabbed)
|
if (grabbed) {
|
||||||
{
|
static const int x = 30, y = 45;
|
||||||
// static const int x = 30, y = 45;
|
renderer->FillRoundRect(x, y, SCREEN_WIDTH - 2*x, 50, 2, ARGB(200, 200, 200, 255));
|
||||||
renderer->FillRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 2, ARGB(255, 255, 255, 255));
|
string msg = _("Press a key to associate.");
|
||||||
string msg = _("Press a key to associate.");
|
mFont->DrawString(msg, (SCREEN_WIDTH - mFont->GetStringWidth(msg.c_str())) / 2, y + 20);
|
||||||
mFont->DrawString(msg, (SCREEN_WIDTH - mFont->GetStringWidth(msg.c_str())) / 2, y + 2);
|
}
|
||||||
}
|
else if (btnMenu)
|
||||||
|
btnMenu->Render();
|
||||||
}
|
}
|
||||||
|
void OptionKey::ButtonPressed(int controllerId, int controlId)
|
||||||
|
{
|
||||||
|
to = btnList[controlId];
|
||||||
|
SAFE_DELETE(btnMenu);
|
||||||
|
btnMenu = NULL;
|
||||||
|
}
|
||||||
|
bool OptionKey::Visible() { return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL; }
|
||||||
|
bool OptionKey::Selectable() { return JGE_BTN_NONE != to || LOCAL_KEY_NONE == from || btnMenu != NULL; }
|
||||||
|
|||||||
@@ -1746,17 +1746,26 @@ WGuiKeyBinder::WGuiKeyBinder(string name, GameStateOptions* parent) : WGuiList(n
|
|||||||
JGE* j = JGE::GetInstance();
|
JGE* j = JGE::GetInstance();
|
||||||
JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
|
JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
|
||||||
|
|
||||||
u32 y = 40;
|
Add(NEW OptionKey(parent, LOCAL_KEY_NONE, JGE_BTN_NONE));
|
||||||
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; }
|
bool WGuiKeyBinder::isModal() { return modal; }
|
||||||
bool WGuiKeyBinder::CheckUserInput(JButton key)
|
bool WGuiKeyBinder::CheckUserInput(JButton key)
|
||||||
{
|
{
|
||||||
switch (key) {
|
if (!items[currentItem]->CheckUserInput(key))
|
||||||
case JGE_BTN_OK: items[currentItem]->CheckUserInput(key); break;
|
return WGuiList::CheckUserInput(key);
|
||||||
default:
|
if (!items[currentItem]->Selectable())
|
||||||
return WGuiList::CheckUserInput(key);
|
nextItem();
|
||||||
}
|
return true;
|
||||||
return false;
|
}
|
||||||
|
void WGuiKeyBinder::setData(){
|
||||||
|
JGE* j = JGE::GetInstance();
|
||||||
|
j->ClearBindings();
|
||||||
|
for (vector<WGuiBase*>::iterator it = items.begin(); it != items.end(); ++it)
|
||||||
|
{
|
||||||
|
OptionKey* o = dynamic_cast<OptionKey*>(*it);
|
||||||
|
if (o && LOCAL_KEY_NONE != o->from && JGE_BTN_NONE != o->to)
|
||||||
|
j->BindKey(o->from, o->to);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user