diff --git a/projects/mtg/Makefile b/projects/mtg/Makefile index 8484d1874..00292e82b 100644 --- a/projects/mtg/Makefile +++ b/projects/mtg/Makefile @@ -1,4 +1,4 @@ -OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/Token.o objs/Translate.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o +OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 7d52eaf91..4362309c3 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -131,4 +131,12 @@ private: string preview; size_t initialValue; }; + +class OptionKey : public WGuiItem { + public: + OptionKey(LocalKeySym, JButton); + LocalKeySym from; + JButton to; + virtual void Render(); +}; #endif diff --git a/projects/mtg/include/TranslateKeys.h b/projects/mtg/include/TranslateKeys.h new file mode 100644 index 000000000..e174a47ac --- /dev/null +++ b/projects/mtg/include/TranslateKeys.h @@ -0,0 +1,18 @@ +#ifndef _TRANSLATEKEYS_H_ +#define _TRANSLATEKEYS_H_ + +#include +#include "JGE.h" + +struct KeyRep +{ + KeyRep(JQuad*, std::string); + JQuad* icon; + std::string text; +}; + + +const KeyRep& translateKey(LocalKeySym); +const KeyRep& translateKey(JButton); + +#endif diff --git a/projects/mtg/include/WGui.h b/projects/mtg/include/WGui.h index 131707282..826737bbb 100644 --- a/projects/mtg/include/WGui.h +++ b/projects/mtg/include/WGui.h @@ -484,10 +484,9 @@ struct WLFiltersSort{ bool operator()(const WGuiBase*l, const WGuiBase*r); }; -class WGuiKeyBinder : public WGuiItem { +class WGuiKeyBinder : public WGuiList { public: - WGuiKeyBinder(); - virtual void Render(); + WGuiKeyBinder(string name); }; #endif diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 04618de50..b6f9d5cfc 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -80,8 +80,7 @@ void GameStateOptions::Start() optionsList->Add(oGra); optionsTabs->Add(optionsList); - optionsList = NEW WGuiList("Key Bindings"); - optionsList->Add(NEW WGuiKeyBinder()); + optionsList = NEW WGuiKeyBinder("Key Bindings"); optionsTabs->Add(optionsList); optionsList = NEW WGuiList("Credits"); diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 81ab135af..15210b4ee 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -4,6 +4,7 @@ #include "../include/PlayerData.h" #include "../include/Translate.h" #include "../include/Subtypes.h" +#include "../include/TranslateKeys.h" #include #include #include @@ -428,3 +429,18 @@ void OptionTheme::confirmChange(bool confirmed){ prior_value = value; } } + +OptionKey::OptionKey(LocalKeySym from, JButton to) : WGuiItem(""), from(from), to(to){} + +void OptionKey::Render(){ + JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT); + mFont->SetColor(getColor(WGuiColor::TEXT)); + JRenderer * renderer = JRenderer::GetInstance(); + + const KeyRep& rep = translateKey(from); + if (NULL == rep.icon) + mFont->DrawString(rep.text, x + 4, y + 2, JGETEXT_LEFT); + const KeyRep& rep2 = translateKey(to); + if (NULL == rep2.icon) + mFont->DrawString(rep2.text, width - 4, y + 2, JGETEXT_RIGHT); +} diff --git a/projects/mtg/src/TranslateKeys.cpp b/projects/mtg/src/TranslateKeys.cpp new file mode 100644 index 000000000..242aac1be --- /dev/null +++ b/projects/mtg/src/TranslateKeys.cpp @@ -0,0 +1,70 @@ +#include +#include "../include/Translate.h" +#include "../include/TranslateKeys.h" + +using std::string; +using std::map; + +static map fattable; +static map slimtable; + +KeyRep::KeyRep(JQuad* icon, string text) : icon(icon), text(text) {} + +#ifdef LINUX +const KeyRep& translateKey(LocalKeySym key) { + { + map::iterator res; + if ((res = fattable.find(key)) != fattable.end()) + return *(res->second); + } + char* str = XKeysymToString(key); + if (!str) + { + str = new char[11]; + sprintf(str, "%lu", key); + } + KeyRep* k = new KeyRep(NULL, str); + fattable[key] = k; + return *k; +} +#else +const KeyRep& translateKey(LocalKeySym key) { + { + map::iterator res; + if ((res = fattable.find(key)) != fattable.end()) + return *(res->second); + } + char* str = new char[11]; + sprintf(str, "%d", key); + KeyRep* k = new KeyRep(NULL, str); + fattable[key] = k; + return *k; +} +#endif + +const KeyRep& translateKey(JButton key) { + { + map::iterator res; + if ((res = slimtable.find(key)) != slimtable.end()) + return *(res->second); + } + + slimtable[JGE_BTN_NONE] = new KeyRep(NULL, _("None")); + slimtable[JGE_BTN_QUIT] = new KeyRep(NULL, _("Quit")); + slimtable[JGE_BTN_MENU] = new KeyRep(NULL, _("Menu")); + slimtable[JGE_BTN_CTRL] = new KeyRep(NULL, _("Control")); + slimtable[JGE_BTN_POWER] = new KeyRep(NULL, _("Power")); + slimtable[JGE_BTN_SOUND] = new KeyRep(NULL, _("Sound")); + slimtable[JGE_BTN_RIGHT] = new KeyRep(NULL, _("Right")); + slimtable[JGE_BTN_LEFT] = new KeyRep(NULL, _("Left")); + slimtable[JGE_BTN_UP] = new KeyRep(NULL, _("Up")); + slimtable[JGE_BTN_DOWN] = new KeyRep(NULL, _("Down")); + slimtable[JGE_BTN_OK] = new KeyRep(NULL, _("Ok")); + slimtable[JGE_BTN_CANCEL] = new KeyRep(NULL, _("Cancel")); + slimtable[JGE_BTN_PRI] = new KeyRep(NULL, _("Primary")); + slimtable[JGE_BTN_SEC] = new KeyRep(NULL, _("Secondary")); + slimtable[JGE_BTN_PREV] = new KeyRep(NULL, _("Previous")); + slimtable[JGE_BTN_NEXT] = new KeyRep(NULL, _("Next")); + + return *slimtable[key]; +} diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index 42e12f5d4..6b5081194 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -1732,26 +1732,14 @@ string WGuiFilterItem::getCode(){ return mCode; } -WGuiKeyBinder::WGuiKeyBinder() : WGuiItem("KB", 0) {} -void WGuiKeyBinder::Render() +WGuiKeyBinder::WGuiKeyBinder(string name) : WGuiList(name) { - JRenderer* renderer = JRenderer::GetInstance(); JGE* j = JGE::GetInstance(); JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end(); - JLBFont * font = resources.GetJLBFont(Constants::OPTION_FONT); - font->SetColor(getColor(WGuiColor::TEXT_BODY)); u32 y = 40; for (JGE::keybindings_it it = start; it != end; ++it) { - // renderer->FillRoundRect(2, y, SCREEN_WIDTH - 4, 23, 2, getColor(WGuiColor::BACK)); - char tmp[11]; - sprintf(tmp, "%lu", it->first); - font->DrawString(tmp, 4, y+2, JGETEXT_LEFT); - sprintf(tmp, "%i", it->second); - font->DrawString(tmp, SCREEN_WIDTH - 4, y+2, JGETEXT_RIGHT); - - y += 25; - // cout << it->first << " > " << it->second << endl; + Add(NEW OptionKey(it->first, it->second)); } }