From 91a9387e333fbf24e8b738825b54ef3023444428 Mon Sep 17 00:00:00 2001 From: "wagic.jeck" Date: Wed, 9 Sep 2009 11:11:17 +0000 Subject: [PATCH] Jeck - Profile loading fix, minor options menu improvements, minor cleanup. --- projects/mtg/include/GameOptions.h | 3 +- projects/mtg/include/OptionItem.h | 408 ++++--- projects/mtg/src/GameApp.cpp | 14 +- projects/mtg/src/GameOptions.cpp | 65 +- projects/mtg/src/GameStateMenu.cpp | 14 +- projects/mtg/src/GameStateOptions.cpp | 406 +++---- projects/mtg/src/OptionItem.cpp | 1611 +++++++++++++------------ projects/mtg/src/WResourceManager.cpp | 4 - 8 files changed, 1277 insertions(+), 1248 deletions(-) diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index f26105e4a..4c856702c 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -117,7 +117,8 @@ public: //The sanity=false option returns the adjusted path even if the file doesn't exist. string profileFile(string filename="", string fallback="", bool sanity=true,bool relative=false); - void checkProfile(); + void reloadProfile(bool images = true); //Reloads profile using current options[ACTIVE_PROFILE] + void checkProfile(); //Confirms that a profile is loaded and contains a collection. void createUsersFirstDeck(int setId); GameOption& operator[](string); diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 33f5b937a..dce912f55 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -1,199 +1,209 @@ -#ifndef _OPTION_ITEM_H_ -#define _OPTION_ITEM_H_ - -#include -#include -#include -#include "../include/GameApp.h" - -using std::string; - -#define MAX_OPTION_TABS 5 -#define MAX_OPTION_ITEMS 20 -#define MAX_ONSCREEN_OPTIONS 8 -#define OPTION_CENTER 4 - -#define OPTIONS_SUBMODE_NORMAL 0 -#define OPTIONS_SUBMODE_RELOAD 1 -#define OPTIONS_SUBMODE_PROFILE 2 -#define OPTIONS_SUBMODE_MODE 3 -#define OPTIONS_SUBMODE_THEME 4 - -class OptionItem { -public: - string displayValue, id; - int hasFocus; - bool canSelect; - bool bHidden; - float x, y; - float width, height; - virtual ostream& toString(ostream& out)const; - - OptionItem( string _id, string _displayValue); - virtual ~OptionItem() {}; - - virtual bool Selectable() {return (canSelect && !bHidden);}; - virtual void Entering(); - virtual bool Leaving(); - virtual void Update(float dt); - virtual void updateValue()=0; - virtual void Reload(){}; - virtual void Render()=0; - virtual void setData()=0; - virtual int Submode() {return OPTIONS_SUBMODE_NORMAL;}; - virtual void cancelSubmode() {}; - virtual void acceptSubmode() {}; -}; - -class OptionInteger:public OptionItem{ - public: - int value; - int maxValue, increment; - - OptionInteger(string _id, string _displayValue, int _maxValue = 1, int _increment = 1); - - virtual void Reload() {if(id != "") value = options[id].number;}; - virtual void Render(); - virtual void setData(); - virtual void updateValue(){value+=increment; if (value>maxValue) value=0;}; - virtual ostream& toString(ostream& out) const; -}; - -class OptionString:public OptionItem{ - public: - string value; - OptionString(string _id, string _displayValue); - - virtual void Render(); - virtual void setData(); - virtual void updateValue(); - virtual void Reload() {if(id != "") value = options[id].str;}; - virtual ostream& toString(ostream& out) const; - bool bShowValue; -}; - -class OptionNewProfile:public OptionString{ - public: - OptionNewProfile(string _id, string _displayValue) : OptionString(_id, _displayValue) {bShowValue=false;}; - virtual void updateValue(); - virtual void Update(float dt); - virtual int Submode(); - bool bChanged; -}; - -class OptionHeader:public OptionItem{ - public: - OptionHeader(string _displayValue): OptionItem("", _displayValue) { canSelect=false;}; - virtual void Render(); - virtual void setData() {}; - virtual void updateValue() {}; -}; - -class OptionText:public OptionItem{ - public: - OptionText(string _displayValue): OptionItem("", _displayValue) { canSelect=false;}; - virtual void Render(); - virtual void setData() {}; - virtual void updateValue() {}; -}; - -class OptionSelect:public OptionItem{ - public: - size_t value; - vector selections; - - virtual void addSelection(string s); - OptionSelect(string _id, string _displayValue): OptionItem(_id, _displayValue) {value = 0;}; - virtual void Reload() {initSelections();}; - virtual void Render(); - virtual void setData(); - virtual void initSelections(); - virtual void updateValue(){value++; if (value > selections.size() - 1) value=0;}; - virtual ostream& toString(ostream& out) const; -}; - - -class OptionDirectory:public OptionSelect{ - public: - virtual void Reload(); - OptionDirectory(string _root, string _id, string _displayValue); -private: - string root; -}; - -class OptionTheme:public OptionDirectory{ - public: - OptionTheme(); -}; - -class OptionProfile:public OptionDirectory{ - public: - OptionProfile(GameApp * _app); - ~OptionProfile(); - virtual void addSelection(string s); - virtual bool Leaving(); - virtual void Entering(); - virtual void Render(); - virtual void Update(float dt); - virtual void updateValue(); - virtual int Submode(); - virtual void cancelSubmode(); - virtual void acceptSubmode(); - void populate(); -private: - bool bCheck; - JQuad * mAvatar; - JTexture * mAvatarTex; - GameApp * app; - string preview; - size_t initialValue; -}; - -class OptionsList{ - public: - string sectionName; - string failMsg; - int nbitems; - int current; - OptionsList(string name); - ~OptionsList(); - bool Leaving(); - void Entering(); - void Render(); - void reloadValues(); - void Update(float dt); - void Add(OptionItem * item); - void save(); - int Submode(); - void acceptSubmode(); - void cancelSubmode(); - - OptionItem * operator[](int); -private: - OptionItem * listItems[MAX_OPTION_ITEMS]; -}; - -class OptionsMenu -{ - public: - JLBFont * mFont; - OptionsList * tabs[MAX_OPTION_TABS]; - int nbitems; - int current; - - OptionsMenu(); - ~OptionsMenu(); - - bool isTab(string name); - int Submode(); - void acceptSubmode(); - void cancelSubmode(); - void Render(); - void reloadValues(); - void Update(float dt); - void Add(OptionsList * tab); - void save(); - -}; - -#endif +#ifndef _OPTION_ITEM_H_ +#define _OPTION_ITEM_H_ + +#include +#include +#include +#include "../include/GameApp.h" + +using std::string; + +#define MAX_OPTION_TABS 5 +#define MAX_OPTION_ITEMS 20 +#define MAX_ONSCREEN_OPTIONS 8 +#define OPTION_CENTER 4 + +#define OPTIONS_SUBMODE_NORMAL 0 +#define OPTIONS_SUBMODE_RELOAD 1 +#define OPTIONS_SUBMODE_PROFILE 2 +#define OPTIONS_SUBMODE_MODE 3 +#define OPTIONS_SUBMODE_THEME 4 + +class OptionItem { +public: + string displayValue, id; + int hasFocus; + bool canSelect; + bool bHidden; + float x, y; + float width, height; + virtual ostream& toString(ostream& out)const; + + OptionItem( string _id, string _displayValue); + virtual ~OptionItem() {}; + + virtual bool Selectable() {return (canSelect && !bHidden);}; + virtual void Entering(); + virtual bool Leaving(); + virtual void Update(float dt); + virtual void updateValue()=0; + virtual void Reload(){}; + virtual void Render()=0; + virtual void setData()=0; + virtual int Submode() {return OPTIONS_SUBMODE_NORMAL;}; + virtual void cancelSubmode() {}; + virtual void acceptSubmode() {}; +}; + +class OptionInteger:public OptionItem{ + public: + int value; //Current value. + int defValue; //Default value. + string strDefault; //What to call the default value. + int maxValue, increment; + + OptionInteger(string _id, string _displayValue, int _maxValue = 1, int _increment = 1, int _defV = 0, string _sDef = ""); + + virtual void Reload() {if(id != "") value = options[id].number;}; + virtual void Render(); + virtual void setData(); + virtual void updateValue(){value+=increment; if (value>maxValue) value=0;}; + virtual ostream& toString(ostream& out) const; +}; + +class OptionString:public OptionItem{ + public: + string value; + OptionString(string _id, string _displayValue); + + virtual void Render(); + virtual void setData(); + virtual void updateValue(); + virtual void Reload() {if(id != "") value = options[id].str;}; + virtual ostream& toString(ostream& out) const; + bool bShowValue; +}; + +class OptionNewProfile:public OptionString{ + public: + OptionNewProfile(string _id, string _displayValue) : OptionString(_id, _displayValue) {bShowValue=false;}; + virtual void updateValue(); + virtual void Update(float dt); + virtual int Submode(); + bool bChanged; +}; + +class OptionHeader:public OptionItem{ + public: + OptionHeader(string _displayValue): OptionItem("", _displayValue) { canSelect=false;}; + virtual void Render(); + virtual void setData() {}; + virtual void updateValue() {}; +}; + +class OptionText:public OptionItem{ + public: + OptionText(string _displayValue): OptionItem("", _displayValue) { canSelect=false;}; + virtual void Render(); + virtual void setData() {}; + virtual void updateValue() {}; +}; + +class OptionSelect:public OptionItem{ + public: + size_t value; + vector selections; + + virtual void addSelection(string s); + OptionSelect(string _id, string _displayValue): OptionItem(_id, _displayValue) {value = 0;}; + virtual void Reload() {initSelections();}; + virtual void Render(); + virtual void setData(); + virtual void initSelections(); + virtual void updateValue(){value++; if (value > selections.size() - 1) value=0;}; + virtual ostream& toString(ostream& out) const; +}; + + +class OptionDirectory:public OptionSelect{ + public: + virtual void Reload(); + OptionDirectory(string _root, string _id, string _displayValue); +private: + string root; +}; + +class OptionTheme:public OptionDirectory{ + public: + OptionTheme(); +}; + +class OptionVolume: public OptionInteger{ + public: + OptionVolume(string _id, string _displayName, bool _bMusic = false); + virtual void updateValue(); +private: + bool bMusic; +}; + +class OptionProfile:public OptionDirectory{ + public: + OptionProfile(GameApp * _app); + ~OptionProfile(); + virtual void addSelection(string s); + virtual bool Leaving(); + virtual void Entering(); + virtual void Render(); + virtual void Update(float dt); + virtual void updateValue(); + virtual int Submode(); + virtual void cancelSubmode(); + virtual void acceptSubmode(); + void populate(); +private: + bool bCheck; + JQuad * mAvatar; + JTexture * mAvatarTex; + GameApp * app; + string preview; + size_t initialValue; +}; + +class OptionsList{ + public: + string sectionName; + string failMsg; + int nbitems; + int current; + OptionsList(string name); + ~OptionsList(); + bool Leaving(); + void Entering(); + void Render(); + void reloadValues(); + void Update(float dt); + void Add(OptionItem * item); + void save(); + int Submode(); + void acceptSubmode(); + void cancelSubmode(); + + OptionItem * operator[](int); +private: + OptionItem * listItems[MAX_OPTION_ITEMS]; +}; + +class OptionsMenu +{ + public: + JLBFont * mFont; + OptionsList * tabs[MAX_OPTION_TABS]; + int nbitems; + int current; + + OptionsMenu(); + ~OptionsMenu(); + + bool isTab(string name); + int Submode(); + void acceptSubmode(); + void cancelSubmode(); + void Render(); + void reloadValues(); + void Update(float dt); + void Add(OptionsList * tab); + void save(); + +}; + +#endif diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 66ab5cc7c..35301fb4b 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -43,6 +43,15 @@ GameApp::GameApp(): JApp() players[1] = 0; gameType = GAME_TYPE_CLASSIC; + + mCurrentState = NULL; + mNextState = NULL; + collection = NULL; + + for(int i=0;i<6;i++) + Particles[i] = NULL; + + music = NULL; } @@ -64,6 +73,9 @@ void GameApp::Create() //Link this to our settings manager. options.theGame = this; + //Ensure that options are properly loaded before loading files. + options.reloadProfile(); + //Test for Music files presence string filepath = RESPATH; filepath = filepath + "/" + resources.musicFile("Track0.mp3"); @@ -200,7 +212,7 @@ void GameApp::Destroy() SimpleMenu::destroy(); - + options.theGame = NULL; LOG("==Destroying GameApp Successful=="); } diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index 1619b3b03..e953475bc 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -187,10 +187,10 @@ GameSettings::GameSettings() //Load global options globalOptions = NEW GameOptions(GLOBAL_SETTINGS); + //reloadProfile should be called for the rest. + theGame = NULL; profileOptions = NULL; themeOptions = NULL; - - checkProfile(); } GameSettings::~GameSettings(){ @@ -220,8 +220,17 @@ int GameSettings::save(){ if(globalOptions) globalOptions->save(); - if(profileOptions) + if(profileOptions){ + //Force our directories to exist. + MAKEDIR(RESPATH"/profiles"); + string temp = profileFile("","",false,false); + MAKEDIR(temp.c_str()); + temp+="/stats"; + MAKEDIR(temp.c_str()); + temp = profileFile(PLAYER_SETTINGS,"",false); + profileOptions->save(); + } checkProfile(); @@ -267,39 +276,31 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b return buf; } +void GameSettings::reloadProfile(bool images){ + SAFE_DELETE(profileOptions); + SAFE_DELETE(themeOptions); + checkProfile(); + if(images) + resources.Refresh(); //Update images +} + void GameSettings::checkProfile(){ - //Load current profile's options. Doesn't save prior set. char buf[512]; - //Force our directories to exist. - MAKEDIR(RESPATH"/profiles"); - string temp = profileFile("","",false,false); - MAKEDIR(temp.c_str()); - temp+="/stats"; - MAKEDIR(temp.c_str()); - temp = profileFile(PLAYER_SETTINGS,"",false); + //If it doesn't exist, load current profile. + if(!profileOptions) + profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS,"",false)); - SAFE_DELETE(profileOptions); - profileOptions = NEW GameOptions(temp); - - //Force a profile. - if((*profileOptions)[Options::ACTIVE_THEME].isDefault()){ - temp = "Default"; - (*profileOptions)[Options::ACTIVE_THEME].str = "Default"; - }else{ - temp = (*profileOptions)[Options::ACTIVE_THEME].str; - } - //Load theme options - if(temp == "Default") - sprintf(buf,RESPATH"/graphics/metrics.txt"); - else{ - sprintf(buf,RESPATH"/themes/%s/metrics.txt",temp.c_str()); + if(!themeOptions){ + if(!profileOptions || (*profileOptions)[Options::ACTIVE_THEME].isDefault()) + sprintf(buf,RESPATH"/graphics/metrics.txt"); + else + sprintf(buf,RESPATH"/themes/%s/metrics.txt",(*profileOptions)[Options::ACTIVE_THEME].str.c_str()); + + themeOptions = NEW GameOptions(buf); } - SAFE_DELETE(themeOptions); - themeOptions = NEW GameOptions(buf); - //Validation of collection, etc, only happens if the game is up. if(theGame == NULL || theGame->collection == NULL) return; @@ -309,7 +310,7 @@ void GameSettings::checkProfile(){ { //If we had any default settings, we'd set them here. - //Give the player cards from the set for which we have the most variety + //Find the set for which we have the most variety int setId = 0; int maxcards = 0; for (int i=0; i< MtgSets::SetsList->nb_items; i++){ @@ -319,15 +320,17 @@ void GameSettings::checkProfile(){ setId = i; } } + //Save this set as "unlocked" char buffer[4096]; string s = MtgSets::SetsList->values[setId]; sprintf(buffer,"unlocked_%s", s.c_str()); (*profileOptions)[buffer]=1; profileOptions->save(); + + //Give the player their first deck createUsersFirstDeck(setId); } - } void GameSettings::createUsersFirstDeck(int setId){ diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index e2b831a97..da2f0959a 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -290,6 +290,7 @@ void GameStateMenu::Update(float dt) mReadConf = 1; } if (!nextDirectory(RESPATH"/sets/","_cards.dat")){ + //Force default, if necessary. if(options[Options::ACTIVE_PROFILE].str == "") options[Options::ACTIVE_PROFILE].str = "Default"; @@ -300,15 +301,8 @@ void GameStateMenu::Update(float dt) file.close(); currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE; }else{ - //check for first time player! - file.open(options.profileFile(PLAYER_COLLECTION,"",false).c_str()); - if(file){ - file.close(); - currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE; - }else{ - currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE; - } - } + currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE; + } //List active profile and database size. PlayerData * playerdata = NEW PlayerData(mParent->collection); @@ -321,8 +315,8 @@ void GameStateMenu::Update(float dt) } break; case MENU_STATE_MAJOR_FIRST_TIME : - options.checkProfile(); currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE; + options.checkProfile(); //Handles building a new deck, if needed. break; case MENU_STATE_MAJOR_MAINMENU : if (!scrollerSet) fillScroller(); diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index aa6a387ea..725ba38f5 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -1,203 +1,203 @@ -#include "../include/config.h" -#include "../include/GameStateOptions.h" -#include "../include/GameApp.h" -#include "../include/OptionItem.h" -#include "../include/SimpleMenu.h" -#include "../include/SimplePad.h" -#include "../include/GameOptions.h" -#include "../include/Translate.h" - -GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) { - optionsTabs = NULL; - optionsMenu = NULL; - confirmMenu = NULL; -} - - -GameStateOptions::~GameStateOptions() { - -} - -void GameStateOptions::Start() -{ - - timer = 0; - mState = SHOW_OPTIONS; - JRenderer::GetInstance()->ResetPrivateVRAM(); - JRenderer::GetInstance()->EnableVSync(true); - - OptionsList * optionsList; - - optionsList = NEW OptionsList("Settings"); - optionsList->Add(NEW OptionHeader("General Options")); - if (GameApp::HasMusic) optionsList->Add(NEW OptionInteger(Options::MUSICVOLUME, "Music volume", 100, 10)); - optionsList->Add(NEW OptionInteger(Options::SFXVOLUME, "SFX volume", 100, 10)); - optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information")); - if (options[Options::DIFFICULTY_MODE_UNLOCKED].number) - optionsList->Add(NEW OptionInteger(Options::DIFFICULTY, "Difficulty", 3, 1)); - optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1)); - optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells")); - optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities")); - optionsList->Add(NEW OptionInteger(Options::CACHESIZE, "Image Cache Size", 60, 5)); - optionsTabs = NEW OptionsMenu(); - optionsTabs->Add(optionsList); - - optionsList = NEW OptionsList("Profiles"); - OptionNewProfile * key = NEW OptionNewProfile("","New Profile"); - key->bShowValue = false; - optionsList->Add(key); - OptionProfile * pickProf = NEW OptionProfile(mParent); - optionsList->Add(pickProf); - OptionTheme * theme = NEW OptionTheme(); - optionsList->Add(theme); - - optionsTabs->Add(optionsList); - optionsList = NEW OptionsList("Credits"); - optionsList->failMsg = ""; - optionsTabs->Add(optionsList); - - JLBFont * mFont = resources.GetJLBFont("f3"); - optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170); - optionsMenu->Add(1, "Save & Back to Main Menu"); - optionsMenu->Add(2, "Back to Main Menu"); - optionsMenu->Add(3, "Cancel"); - - confirmMenu = NEW SimpleMenu(103, this,mFont, 50,170); - confirmMenu->Add(1, "Use this profile"); - confirmMenu->Add(2, "Cancel"); -} - - -void GameStateOptions::End() -{ - JRenderer::GetInstance()->EnableVSync(false); - SAFE_DELETE(optionsTabs); - SAFE_DELETE(optionsMenu); - SAFE_DELETE(confirmMenu); -} - - -void GameStateOptions::Update(float dt) -{ - timer += dt; - - if(options.keypadActive()){ - options.keypadUpdate(dt); - } - else if (mState == SHOW_OPTIONS){ - - switch(optionsTabs->Submode()){ - case OPTIONS_SUBMODE_RELOAD: - optionsTabs->acceptSubmode(); - optionsTabs->reloadValues(); - mState = SHOW_OPTIONS; - break; - case OPTIONS_SUBMODE_PROFILE: - mState = SHOW_OPTIONS_PROFILE; - break; - default: - if (PSP_CTRL_START == mEngine->ReadButton() ) - mState = SHOW_OPTIONS_MENU; - - optionsTabs->Update(dt); - break; - } - - }else if(mState == SHOW_OPTIONS_MENU){ - optionsMenu->Update(dt); - }else if(mState == SHOW_OPTIONS_PROFILE){ - confirmMenu->Update(dt); - } -} - -void GameStateOptions::Render() -{ - //Erase - JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); - - const char * const CreditsText[] = { - "Wagic, The Homebrew?! by WilLoW", - "", - "updates, new cards, and more on http://wololo.net/wagic", - "Many thanks to the devs and card creators who help this project", - "", - "Developped with the JGE++ Library (http://jge.khors.com)", - "Player's avatar from http://mathieuchoinet.blogspot.com, under CC License", - "Background picture and some art from the KDE project, www.kde.org", - "SFX From www.soundsnap.com", - "", - "Music by Celestial Aeon Project, http://www.jamendo.com", - "", - "", - "This work is not related to or endorsed by Wizards of the Coast, Inc", - "", - "Please support this project with donations at http://wololo.net/wagic", - }; - - JLBFont * mFont = resources.GetJLBFont("magic"); - mFont->SetColor(ARGB(255,200,200,200)); - mFont->SetScale(1.0); - float startpos = 272 - timer * 10; - float pos = startpos; - int size = sizeof(CreditsText) / sizeof(CreditsText[0]); - - for (int i = 0; i < size; i++){ - pos = startpos +20*i; - if (pos > -20){ - mFont->DrawString(_(CreditsText[i]).c_str(),SCREEN_WIDTH/2,pos ,JGETEXT_CENTER); - } - } - - if (pos < -20) - timer = 0; - - mFont->SetScale(1.f); - - optionsTabs->Render(); - - switch(mState){ - case SHOW_OPTIONS_MENU: - optionsMenu->Render(); - break; - case SHOW_OPTIONS_PROFILE: - confirmMenu->Render(); - break; - } - - if(options.keypadActive()) - options.keypadRender(); -} - - -void GameStateOptions::ButtonPressed(int controllerId, int controlId) -{ - //Exit menu? - if(controllerId == 102) - switch (controlId){ - case 1: - optionsTabs->save(); - case 2: - mParent->SetNextState(GAME_STATE_MENU); - break; - case 3: - mState = SHOW_OPTIONS; - break; - } - //Profile confirmation? - else if(controllerId == 103) - switch (controlId){ - case 1: - //Load the New profile. - optionsTabs->acceptSubmode(); - optionsTabs->reloadValues(); - //Reset the current settings to those of the profile... - mState = SHOW_OPTIONS; - break; - case 2: - optionsTabs->cancelSubmode(); - mState = SHOW_OPTIONS; - break; - } -}; - - +#include "../include/config.h" +#include "../include/GameStateOptions.h" +#include "../include/GameApp.h" +#include "../include/OptionItem.h" +#include "../include/SimpleMenu.h" +#include "../include/SimplePad.h" +#include "../include/GameOptions.h" +#include "../include/Translate.h" + +GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) { + optionsTabs = NULL; + optionsMenu = NULL; + confirmMenu = NULL; +} + + +GameStateOptions::~GameStateOptions() { + +} + +void GameStateOptions::Start() +{ + timer = 0; + mState = SHOW_OPTIONS; + JRenderer::GetInstance()->ResetPrivateVRAM(); + JRenderer::GetInstance()->EnableVSync(true); + + OptionsList * optionsList; + + optionsList = NEW OptionsList("Settings"); + + optionsList->Add(NEW OptionHeader("General Options")); + if (GameApp::HasMusic) optionsList->Add(NEW OptionVolume(Options::MUSICVOLUME, "Music volume", true)); + optionsList->Add(NEW OptionVolume(Options::SFXVOLUME, "SFX volume")); + optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information")); + if (options[Options::DIFFICULTY_MODE_UNLOCKED].number) + optionsList->Add(NEW OptionInteger(Options::DIFFICULTY, "Difficulty", 3, 1)); + optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1)); + optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells")); + optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities")); + optionsList->Add(NEW OptionInteger(Options::CACHESIZE, "Image Cache Size", 60, 5,0,"Default")); + optionsTabs = NEW OptionsMenu(); + optionsTabs->Add(optionsList); + + optionsList = NEW OptionsList("Profiles"); + OptionNewProfile * key = NEW OptionNewProfile("","New Profile"); + key->bShowValue = false; + optionsList->Add(key); + OptionProfile * pickProf = NEW OptionProfile(mParent); + optionsList->Add(pickProf); + OptionTheme * theme = NEW OptionTheme(); + optionsList->Add(theme); + + optionsTabs->Add(optionsList); + optionsList = NEW OptionsList("Credits"); + optionsList->failMsg = ""; + optionsTabs->Add(optionsList); + + JLBFont * mFont = resources.GetJLBFont("f3"); + optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170); + optionsMenu->Add(1, "Save & Back to Main Menu"); + optionsMenu->Add(2, "Back to Main Menu"); + optionsMenu->Add(3, "Cancel"); + + confirmMenu = NEW SimpleMenu(103, this,mFont, 50,170); + confirmMenu->Add(1, "Use this profile"); + confirmMenu->Add(2, "Cancel"); +} + + +void GameStateOptions::End() +{ + JRenderer::GetInstance()->EnableVSync(false); + SAFE_DELETE(optionsTabs); + SAFE_DELETE(optionsMenu); + SAFE_DELETE(confirmMenu); +} + + +void GameStateOptions::Update(float dt) +{ + timer += dt; + + if(options.keypadActive()){ + options.keypadUpdate(dt); + } + else if (mState == SHOW_OPTIONS){ + + switch(optionsTabs->Submode()){ + case OPTIONS_SUBMODE_RELOAD: + optionsTabs->acceptSubmode(); + optionsTabs->reloadValues(); + mState = SHOW_OPTIONS; + break; + case OPTIONS_SUBMODE_PROFILE: + mState = SHOW_OPTIONS_PROFILE; + break; + default: + if (PSP_CTRL_START == mEngine->ReadButton() ) + mState = SHOW_OPTIONS_MENU; + + optionsTabs->Update(dt); + break; + } + + }else if(mState == SHOW_OPTIONS_MENU){ + optionsMenu->Update(dt); + }else if(mState == SHOW_OPTIONS_PROFILE){ + confirmMenu->Update(dt); + } +} + +void GameStateOptions::Render() +{ + //Erase + JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); + + const char * const CreditsText[] = { + "Wagic, The Homebrew?! by WilLoW", + "", + "updates, new cards, and more on http://wololo.net/wagic", + "Many thanks to the devs and card creators who help this project", + "", + "Developped with the JGE++ Library (http://jge.khors.com)", + "Player's avatar from http://mathieuchoinet.blogspot.com, under CC License", + "Background picture and some art from the KDE project, www.kde.org", + "SFX From www.soundsnap.com", + "", + "Music by Celestial Aeon Project, http://www.jamendo.com", + "", + "", + "This work is not related to or endorsed by Wizards of the Coast, Inc", + "", + "Please support this project with donations at http://wololo.net/wagic", + }; + + JLBFont * mFont = resources.GetJLBFont("magic"); + mFont->SetColor(ARGB(255,200,200,200)); + mFont->SetScale(1.0); + float startpos = 272 - timer * 10; + float pos = startpos; + int size = sizeof(CreditsText) / sizeof(CreditsText[0]); + + for (int i = 0; i < size; i++){ + pos = startpos +20*i; + if (pos > -20){ + mFont->DrawString(_(CreditsText[i]).c_str(),SCREEN_WIDTH/2,pos ,JGETEXT_CENTER); + } + } + + if (pos < -20) + timer = 0; + + mFont->SetScale(1.f); + + optionsTabs->Render(); + + switch(mState){ + case SHOW_OPTIONS_MENU: + optionsMenu->Render(); + break; + case SHOW_OPTIONS_PROFILE: + confirmMenu->Render(); + break; + } + + if(options.keypadActive()) + options.keypadRender(); +} + + +void GameStateOptions::ButtonPressed(int controllerId, int controlId) +{ + //Exit menu? + if(controllerId == 102) + switch (controlId){ + case 1: + optionsTabs->save(); + case 2: + mParent->SetNextState(GAME_STATE_MENU); + break; + case 3: + mState = SHOW_OPTIONS; + break; + } + //Profile confirmation? + else if(controllerId == 103) + switch (controlId){ + case 1: + //Load the New profile. + optionsTabs->acceptSubmode(); + optionsTabs->reloadValues(); + //Reset the current settings to those of the profile... + mState = SHOW_OPTIONS; + break; + case 2: + optionsTabs->cancelSubmode(); + mState = SHOW_OPTIONS; + break; + } +}; + + diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 1fb614466..afdf46964 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -1,800 +1,813 @@ -#include "../include/config.h" -#include "../include/OptionItem.h" -#include "../include/GameApp.h" -#include -#include "../include/GameOptions.h" -#include "../include/PlayerData.h" -#include "../include/Translate.h" -#include -#include -#include - -//Option Item - -void OptionItem::Update(float dt){ - JGE * mEngine = JGE::GetInstance(); - if (hasFocus){ - if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue(); - } -} - -void OptionItem::Entering(){ - hasFocus = true; -} - -bool OptionItem::Leaving(){ - hasFocus = false; - return true; -} - -ostream& OptionItem::toString(ostream& out) const{ -return out << "OptionItem ::: displayValue : " << displayValue - << " ; id : " << id - << " ; hasFocus : " << hasFocus - << " ; x,y : " << x << "," << y; -} - -OptionItem::OptionItem( string _id, string _displayValue) { - id = _id; - displayValue = _(_displayValue); - canSelect=true; - hasFocus=false; - bHidden=false; - width = SCREEN_WIDTH; - height = 20; -} - -//Option Integer - -void OptionInteger::Render(){ - JLBFont * mFont = resources.GetJLBFont("f3"); - if (hasFocus){ - mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); - }else{ - mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); - } - JRenderer * renderer = JRenderer::GetInstance(); - renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); - mFont->DrawString(displayValue.c_str(),x,y); - char buf[512]; - if (maxValue == 1){ - if (value){ - sprintf(buf, _("Yes").c_str()); - }else{ - sprintf(buf,_("No").c_str()); - } - }else{ - sprintf(buf, "%i", value); - } - mFont->DrawString(buf,width -10 ,y,JGETEXT_RIGHT); -} - -OptionInteger::OptionInteger(string _id, string _displayValue, int _maxValue, int _increment): OptionItem(_id, _displayValue){ - - maxValue = _maxValue; - increment = _increment; - value = ::options[id].number; - hasFocus = false; - x = 0; - y = 0; -} - -void OptionInteger::setData(){ - if(id != "") - options[id] = GameOption(value); -} - - -ostream& OptionInteger::toString(ostream& out) const{ - return out << "OptionItem ::: displayValue : " << displayValue - << " ; id : " << id - << " ; value : " << value - << " ; hasFocus : " << hasFocus - << " ; maxValue : " << maxValue - << " ; increment : " << increment - << " ; x,y : " << x << "," << y; -} - -//Option Select - -void OptionSelect::initSelections(){ - //Find currently active bit in the list. - for(size_t i=0;iSetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); - }else{ - mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); - } - - JRenderer * renderer = JRenderer::GetInstance(); - renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); - mFont->DrawString(displayValue.c_str(),x,y); - - if (value < selections.size()) - mFont->DrawString(selections[value].c_str(),width-10,y,JGETEXT_RIGHT); - else - mFont->DrawString("Unset",width-10,y,JGETEXT_RIGHT); -} - -void OptionSelect::setData() -{ - if(id == "") return; - if (value < selections.size()) - options[id] = GameOption(selections[value]); -} - -void OptionSelect::addSelection(string s) -{ - selections.push_back(s); -} - - -ostream& OptionSelect::toString(ostream& out) const -{ - return out << "OptionItem ::: displayValue : " << displayValue - << " ; id : " << id - << " ; value : " << value - << " ; hasFocus : " << hasFocus - << " ; x,y : " << x << "," << y; -} - -//OptionHeader - -void OptionHeader::Render(){ - JLBFont * mFont = resources.GetJLBFont("f3"); - mFont->SetColor(options[Metrics::OPTION_HEADER_TC].asColor()); - - JRenderer * renderer = JRenderer::GetInstance(); - renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); - mFont->DrawString(displayValue.c_str(),width/2,y,JGETEXT_CENTER); -} - -void OptionText::Render(){ - JLBFont * mFont = resources.GetJLBFont("f3"); - mFont->SetScale(.8); - mFont->SetColor(options[Metrics::OPTION_TEXT_TC].asColor()); - - JRenderer * renderer = JRenderer::GetInstance(); - renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_TEXT_FC].asColor(ARGB(150,80,80,80))); - mFont->DrawString(displayValue.c_str(),x,y,JGETEXT_LEFT); - mFont->SetScale(1); -} - -//OptionProfile - -OptionProfile::~OptionProfile(){ - SAFE_DELETE(mAvatarTex); - SAFE_DELETE(mAvatar); -} - -int OptionProfile::Submode(){ - if(value != initialValue && bCheck){ - bCheck=false; //Just about to check it! - return OPTIONS_SUBMODE_PROFILE; - } - return OPTIONS_SUBMODE_NORMAL; -} - -void OptionProfile::addSelection(string s){ - OptionDirectory::addSelection(s); - - //Check how many options... if 1, we're not selectable. - if(selections.size() > 1) - canSelect = true; - else - canSelect = false; -} - -OptionProfile::OptionProfile(GameApp * _app): OptionDirectory(RESPATH"/profiles",Options::ACTIVE_PROFILE, "Profile"){ - app = _app; - height=100; - addSelection("Default"); - sort(selections.begin(),selections.end()); - initSelections(); - mAvatarTex=NULL; - mAvatar=NULL; - hasFocus=false; - populate(); - bCheck=false; -}; - -void OptionProfile::updateValue(){ - value++; - if (value > selections.size() - 1) - value=0; - - populate(); -} - -void OptionProfile::populate(){ - JRenderer * renderer = JRenderer::GetInstance(); - string temp = options[Options::ACTIVE_PROFILE].str; - if (value >= selections.size()){ //TODO fail gracefully. - return; - } - - options[Options::ACTIVE_PROFILE].str = selections[value]; - - SAFE_DELETE(mAvatar); - SAFE_DELETE(mAvatarTex); - mAvatarTex = JRenderer::GetInstance()->LoadTexture(options.profileFile("avatar.jpg","",true,true).c_str(), false); - if (mAvatarTex){ - mAvatar = NEW JQuad(mAvatarTex, 0, 0, 35, 50); - renderer->BindTexture(mAvatarTex); - } - - options.checkProfile(); - PlayerData * pdata = NEW PlayerData(app->collection); - - options[Options::ACTIVE_PROFILE] = temp; - - char buf[512]; - sprintf(buf,"Credits: %i\nCards: %i",pdata->credits,pdata->collection->totalCards()); - preview = buf; - - - SAFE_DELETE(pdata); -} - -void OptionProfile::Render(){ - JRenderer * renderer = JRenderer::GetInstance(); - JLBFont * mFont = resources.GetJLBFont("f3"); - mFont->SetScale(1); - int spacing = 2+(int)mFont->GetHeight(); - - //Draw faux option. Not highlighted if we've only one. - if (hasFocus && selections.size() > 1){ - mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); - renderer->FillRoundRect(x-5,y-2,width-x-5,20,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); - mFont->DrawString("Change Profile",SCREEN_WIDTH/2,y,JGETEXT_CENTER); - }else{ - mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); - renderer->FillRoundRect(x-5,y-2,width-x-5,20,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); - mFont->DrawString("Profile",SCREEN_WIDTH/2,y,JGETEXT_CENTER); - } - - - //Draw preview box. - renderer->FillRoundRect(x-5,y-2+25,width-x-5,height-25,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); - - int pX, pY; - pX = x; - pY = y+30; - if(mAvatar){ - renderer->RenderQuad(mAvatar,x,pY); - pX += 40; - } - - mFont->SetColor(options[Metrics::OPTION_TEXT_TC].asColor()); - mFont->DrawString(selections[value].c_str(),pX,pY,JGETEXT_LEFT); - mFont->SetScale(.8); - mFont->DrawString(preview.c_str(),pX,pY+spacing,JGETEXT_LEFT); - mFont->SetScale(1); -} -void OptionProfile::Update(float dt){ - JGE * mEngine = JGE::GetInstance(); - if (hasFocus){ - if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue(); - } -} - -void OptionProfile::Entering(){ - hasFocus = true; - bCheck = false; - initialValue = value; -} -bool OptionProfile::Leaving(){ - - //Choice must be confirmed. - if(value != initialValue){ - bCheck = true; - return false; - } - hasFocus = false; - return true; -} - -void OptionProfile::cancelSubmode() -{ - if (initialValue >= selections.size()) - return; - - options[Options::ACTIVE_PROFILE] = selections[initialValue]; - value = initialValue; - populate(); - bCheck = false; -} -void OptionProfile::acceptSubmode() -{ - if (value >= selections.size()) - return; - - options[Options::ACTIVE_PROFILE] = selections[value]; - initialValue = value; - populate(); - resources.Refresh(); //Update images, in case we've changed profiles, etc. - bCheck = false; -} - -//OptionDirectory -void OptionDirectory::Reload(){ - DIR *mDip; - struct dirent *mDit; - char buf[4096]; - mDip = opendir(root.c_str()); - - if(!mDip) - return; - - while ((mDit = readdir(mDip))){ - if(mDit->d_name[0] != '.'){ - sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); - std::ifstream file(buf); - if(file){ - file.close(); - continue; - } - if(find(selections.begin(),selections.end(),mDit->d_name) == selections.end()) - addSelection(mDit->d_name); - } - } - - closedir(mDip); - mDip = NULL; - initSelections(); -} - -OptionDirectory::OptionDirectory(string _root, string _id, string _displayValue): OptionSelect(_id, _displayValue){ - DIR *mDip; - struct dirent *mDit; - char buf[4096]; - root = _root; - mDip = opendir(root.c_str()); - - if(!mDip) - return; - - while ((mDit = readdir(mDip))){ - if(mDit->d_name[0] != '.'){ - sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); - std::ifstream file(buf); - if(file){ - file.close(); - continue; - } - addSelection(mDit->d_name); - } - } - - closedir(mDip); - mDip = NULL; - initSelections(); -} - -OptionsList::OptionsList(string name){ - sectionName = name; - failMsg = "NO OPTIONS AVAILABLE"; - nbitems = 0; - current = -1; -} -OptionsList::~OptionsList(){ - for (int i = 0 ; i < nbitems; i++){ - SAFE_DELETE(listItems[i]); - } -} - -void OptionsList::Add(OptionItem * item){ - if (nbitems < MAX_OPTION_ITEMS){ - listItems[nbitems] = item; - nbitems++; - } -} -bool OptionsList::Leaving(){ - if(current >= 0 && current < nbitems) - return listItems[current]->Leaving(); - - return true; -} -void OptionsList::Entering(){ - //Try to force a selectable option. - if(current == -1){ - for (int i = 0 ; i < nbitems; i++){ - if(listItems[i]->Selectable()) { - current = i; - listItems[current]->Entering(); - break; - } - } - } - - if(current >= 0 && current < nbitems) - listItems[current]->Entering(); - - return; -} -void OptionsList::Render(){ - JRenderer * renderer = JRenderer::GetInstance(); - - int width = SCREEN_WIDTH; - int listHeight=40; - int listSelectable=0; - int adjustedCurrent=0; - int start = 0, nowPos = 0, vHeight=0; - - - //List is empty. - if (!nbitems && failMsg != ""){ - JLBFont * mFont = resources.GetJLBFont("f3"); - mFont->SetColor(options[Metrics::MSG_FAIL_TC].asColor(ARGB(255,155,155,155))); - mFont->DrawString(failMsg.c_str(),SCREEN_WIDTH/2, 40, JGETEXT_RIGHT); - return; - } - - //Force a selectable option. - if(current == -1){ - for (int i = 0 ; i < nbitems; i++){ - if(listItems[i]->Selectable()) { - current = i; - listItems[current]->Entering(); - break; - } - } - } - //Find out how large our list is. - for (int pos=0;pos < nbitems; pos++){ - listHeight+=listItems[pos]->height+5; - if(listItems[pos]->Selectable()){ - listSelectable++; - if(pos < current) adjustedCurrent++; - } - } - - //Always fill screen - if(listHeight > SCREEN_HEIGHT) - { - width -= 10; - for (start=current;start > 0; start--){ - if(listItems[start]->bHidden) - continue; - - vHeight += listItems[start]->height+5; - if(vHeight >= (SCREEN_HEIGHT-60)/2) - break; - } - vHeight = 0; - for (nowPos=nbitems;nowPos > 1; nowPos--){ - if(listItems[start]->bHidden) - continue; - vHeight += listItems[nowPos-1]->height+5; - } - - if(vHeight <= SCREEN_HEIGHT-40 && nowPos < start) - start = nowPos; - - } - - vHeight = 0; - nowPos = 40; - - //Render items. - if(start >= 0) - { - for (int pos=0;pos < nbitems; pos++){ - if(listItems[pos]->bHidden) - continue; - - if(pos < start){ - vHeight += listItems[pos]->height + 5; - continue; - } - listItems[pos]->x = 10; - listItems[pos]->y = nowPos; - listItems[pos]->width = width; - nowPos += listItems[pos]->height + 5; - listItems[pos]->Render(); - if(nowPos > SCREEN_HEIGHT) - break; - } - - //Draw scrollbar - if(listHeight > SCREEN_HEIGHT && listSelectable > 1){ - int barPosition = 35+((float)adjustedCurrent/listSelectable)*(SCREEN_HEIGHT-40); - int barLength = (SCREEN_HEIGHT-40) / listSelectable; - if(barLength < 4) barLength = 4; - width = (SCREEN_WIDTH-(width-5))/2; //Find center of blank space by options. - renderer->FillRect(SCREEN_WIDTH-width-1,39,2,SCREEN_HEIGHT-42, - options[Metrics::OPTION_SCROLLBAR_FC].asColor(ARGB(150,150,150,150))); - renderer->FillRoundRect(SCREEN_WIDTH-width-4,barPosition,5,barLength,2, - options[Metrics::OPTION_SCROLLBAR_FCH].asColor(ARGB(255,255,255,255))); - } - } -} - -void OptionsList::save(){ - for (int i = 0; i < nbitems; i++){ - listItems[i]->setData(); - } - ::options.save(); -} - -void OptionsList::Update(float dt){ - JGE * mEngine = JGE::GetInstance(); - int potential = current; - - if (mEngine->GetButtonClick(PSP_CTRL_UP)) - { - if (potential > 0){ - potential--; - while(potential > 0 && listItems[potential]->Selectable() == false) - potential--; - if(potential < 0 || !listItems[potential]->Selectable()) - potential = -1; - else if(listItems[current]->Leaving()){ - current = potential; - listItems[current]->Entering(); - } - } - } - else if (mEngine->GetButtonClick(PSP_CTRL_DOWN)) - { - if (potential < nbitems-1){ - potential++; - while(potential < nbitems-1 && listItems[potential]->Selectable() == false) - potential++; - if(potential == nbitems || !listItems[potential]->Selectable()) - potential = -1; - else if(potential != current && listItems[current]->Leaving()){ - current = potential; - listItems[current]->Entering(); - } - } - } - for (int i = 0 ; i < nbitems; i++){ - listItems[i]->Update(dt); - } -} - - -void OptionsMenu::Add(OptionsList * tab){ - if (nbitems < MAX_OPTION_TABS){ - tabs[nbitems] = tab; - nbitems++; - if (current < 0){ - current = 0; - } - - } -} - -void OptionsMenu::Render(){ - if (nbitems == 0){ - mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT); - return; - } - - JRenderer * renderer = JRenderer::GetInstance(); - - int offset = 0; - for(int i=0;iGetStringWidth(tabs[i]->sectionName.c_str()); - if(i == current){ - mFont->SetColor(options[Metrics::OPTION_TAB_TCH].asColor()); - renderer->FillRoundRect(offset+5,5,w + 5,25,2,options[Metrics::OPTION_TAB_FCH].asColor(ARGB(150,150,150,150))); - } - else{ - mFont->SetColor(options[Metrics::OPTION_TAB_TC].asColor(ARGB(255,155,155,155))); - renderer->FillRoundRect(offset+5,5,w + 5,25,2,options[Metrics::OPTION_TAB_FC].asColor(ARGB(150,50,50,50))); - } - mFont->DrawString(tabs[i]->sectionName.c_str(),offset+10,10); - offset += w + 10 + 2; - } - - if(current > -1 && current < nbitems && tabs[current]) - tabs[current]->Render(); -} - -void OptionsMenu::Update(float dt){ - JGE * mEngine = JGE::GetInstance(); - if(current < 0 || current >= nbitems) - return; - - //We use the shoulder buttons to switch tabs, if we've got them. - if (mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)) - { - if (current > 0) - { - if(tabs[current]->Leaving()){ - current--; - tabs[current]->Entering(); - } - } - } - else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)) - { - if (current < nbitems -1) - { - if(tabs[current]->Leaving()){ - current++; - tabs[current]->Entering(); - } - } - } - - tabs[current]->Update(dt); -} - -OptionsMenu::OptionsMenu(){ - nbitems=0; - current=0; - mFont = resources.GetJLBFont("f3"); - for(int x=0;xsave(); -} - -bool OptionsMenu::isTab(string name){ - if(current <0 || current >= nbitems) - return false; - else if(tabs[current]->sectionName == name) - return true; - - return false; -} - -int OptionsMenu::Submode() -{ - if(current <0 || current >= nbitems) - return OPTIONS_SUBMODE_NORMAL; - - return tabs[current]->Submode(); -} - -void OptionsMenu::acceptSubmode() -{ - if(current > -1 && current < nbitems) - tabs[current]->acceptSubmode(); -} -void OptionsMenu::reloadValues() -{ - for(int i=0;ireloadValues(); -} - -void OptionsMenu::cancelSubmode() -{ - if(current > -1 && current < nbitems) - tabs[current]->cancelSubmode(); -} - - -int OptionsList::Submode() -{ - if(current <0 || current >= nbitems) - return OPTIONS_SUBMODE_NORMAL; - - return listItems[current]->Submode(); -} - -void OptionsList::reloadValues() -{ - for(int i=0;iReload(); - } -} -void OptionsList::acceptSubmode() -{ - if(current > -1 && current < nbitems) - listItems[current]->acceptSubmode(); -} - -void OptionsList::cancelSubmode() -{ - if(current > -1 && current < nbitems) - listItems[current]->cancelSubmode(); -} - -//OptionString - -void OptionString::Render(){ - - JLBFont * mFont = resources.GetJLBFont("f3"); - if (hasFocus){ - mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); - }else{ - mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); - } - JRenderer * renderer = JRenderer::GetInstance(); - renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); - - if(!bShowValue){ - mFont->DrawString(displayValue.c_str(),(x+width)/2,y,JGETEXT_CENTER); - } - else{ - mFont->DrawString(displayValue.c_str(),x,y); - int w = mFont->GetStringWidth(value.c_str()-10); - mFont->DrawString(value.c_str(),width - w,y,JGETEXT_RIGHT); - } -} - -void OptionString::setData(){ - if(id != "") - options[id] = GameOption(value); -} -void OptionString::updateValue(){ - options.keypadStart(value,&value); - options.keypadTitle(displayValue); -} - -void OptionNewProfile::updateValue(){ - options.keypadStart("",&value); - options.keypadTitle(displayValue); -} - -void OptionNewProfile::Update(float dt){ - if(value != ""){ - string temp; - temp = options[Options::ACTIVE_PROFILE].str; - value = options.keypadFinish(); - if(value == "") - return; - - if(temp != value){ - options[Options::ACTIVE_PROFILE] = value; - options.checkProfile(); - } - value = ""; - bChanged = true; - } - OptionItem::Update(dt); -} - -int OptionNewProfile::Submode(){ - if(bChanged){ - bChanged=false; //Just about to check it! - return OPTIONS_SUBMODE_RELOAD; - } - return OPTIONS_SUBMODE_NORMAL; -} - -OptionString::OptionString(string _id, string _displayValue): OptionItem(_id, _displayValue) -{ - bShowValue=true; - if(_id != "") - value=options[_id].str; -} - -ostream& OptionString::toString(ostream& out) const{ -return out << "OptionString ::: displayValue : " << displayValue - << " ; id : " << id - << " ; value : " << value - << " ; hasFocus : " << hasFocus - << " ; x,y : " << x << "," << y; -} - -OptionTheme::OptionTheme(): OptionDirectory(RESPATH"/themes",Options::ACTIVE_THEME, "Current Theme"){ - addSelection("Default"); - sort(selections.begin(),selections.end()); - initSelections(); - hasFocus=false; - if(selections.size() == 1) - bHidden = true; +#include "../include/config.h" +#include "../include/OptionItem.h" +#include "../include/GameApp.h" +#include +#include "../include/GameOptions.h" +#include "../include/PlayerData.h" +#include "../include/Translate.h" +#include +#include +#include + +//Option Item + +void OptionItem::Update(float dt){ + JGE * mEngine = JGE::GetInstance(); + if (hasFocus){ + if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue(); + } +} + +void OptionItem::Entering(){ + hasFocus = true; +} + +bool OptionItem::Leaving(){ + hasFocus = false; + return true; +} + +ostream& OptionItem::toString(ostream& out) const{ +return out << "OptionItem ::: displayValue : " << displayValue + << " ; id : " << id + << " ; hasFocus : " << hasFocus + << " ; x,y : " << x << "," << y; +} + +OptionItem::OptionItem( string _id, string _displayValue) { + id = _id; + displayValue = _(_displayValue); + canSelect=true; + hasFocus=false; + bHidden=false; + width = SCREEN_WIDTH; + height = 20; +} + +//Option Integer + +void OptionInteger::Render(){ + JLBFont * mFont = resources.GetJLBFont("f3"); + if (hasFocus){ + mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); + }else{ + mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); + } + JRenderer * renderer = JRenderer::GetInstance(); + renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); + mFont->DrawString(displayValue.c_str(),x,y); + char buf[512]; + if (maxValue == 1){ + if (value){ + sprintf(buf, _("Yes").c_str()); + }else{ + sprintf(buf,_("No").c_str()); + } + }else{ + if(value == defValue && strDefault.size()) + sprintf(buf, "%s", strDefault.c_str()); + else + sprintf(buf, "%i", value); + } + mFont->DrawString(buf,width -10 ,y,JGETEXT_RIGHT); +} + +OptionInteger::OptionInteger(string _id, string _displayValue, int _maxValue, int _increment, int _defV, string _sDef): OptionItem(_id, _displayValue){ + defValue = _defV; + strDefault = _sDef; + maxValue = _maxValue; + increment = _increment; + value = ::options[id].number; + hasFocus = false; + x = 0; + y = 0; +} + +void OptionInteger::setData(){ + if(id != "") + options[id] = GameOption(value); +} + + +ostream& OptionInteger::toString(ostream& out) const{ + return out << "OptionItem ::: displayValue : " << displayValue + << " ; id : " << id + << " ; value : " << value + << " ; hasFocus : " << hasFocus + << " ; maxValue : " << maxValue + << " ; increment : " << increment + << " ; x,y : " << x << "," << y; +} + +//Option Select + +void OptionSelect::initSelections(){ + //Find currently active bit in the list. + for(size_t i=0;iSetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); + }else{ + mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); + } + + JRenderer * renderer = JRenderer::GetInstance(); + renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); + mFont->DrawString(displayValue.c_str(),x,y); + + if (value < selections.size()) + mFont->DrawString(selections[value].c_str(),width-10,y,JGETEXT_RIGHT); + else + mFont->DrawString("Unset",width-10,y,JGETEXT_RIGHT); +} + +void OptionSelect::setData() +{ + if(id == "") return; + if (value < selections.size()) + options[id] = GameOption(selections[value]); +} + +void OptionSelect::addSelection(string s) +{ + selections.push_back(s); +} + + +ostream& OptionSelect::toString(ostream& out) const +{ + return out << "OptionItem ::: displayValue : " << displayValue + << " ; id : " << id + << " ; value : " << value + << " ; hasFocus : " << hasFocus + << " ; x,y : " << x << "," << y; +} + +//OptionHeader + +void OptionHeader::Render(){ + JLBFont * mFont = resources.GetJLBFont("f3"); + mFont->SetColor(options[Metrics::OPTION_HEADER_TC].asColor()); + + JRenderer * renderer = JRenderer::GetInstance(); + renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); + mFont->DrawString(displayValue.c_str(),width/2,y,JGETEXT_CENTER); +} + +void OptionText::Render(){ + JLBFont * mFont = resources.GetJLBFont("f3"); + mFont->SetScale(.8); + mFont->SetColor(options[Metrics::OPTION_TEXT_TC].asColor()); + + JRenderer * renderer = JRenderer::GetInstance(); + renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_TEXT_FC].asColor(ARGB(150,80,80,80))); + mFont->DrawString(displayValue.c_str(),x,y,JGETEXT_LEFT); + mFont->SetScale(1); +} + +//OptionProfile + +OptionProfile::~OptionProfile(){ + SAFE_DELETE(mAvatarTex); + SAFE_DELETE(mAvatar); +} + +int OptionProfile::Submode(){ + if(value != initialValue && bCheck){ + bCheck=false; //Just about to check it! + return OPTIONS_SUBMODE_PROFILE; + } + return OPTIONS_SUBMODE_NORMAL; +} + +void OptionProfile::addSelection(string s){ + OptionDirectory::addSelection(s); + + //Check how many options... if 1, we're not selectable. + if(selections.size() > 1) + canSelect = true; + else + canSelect = false; +} + +OptionProfile::OptionProfile(GameApp * _app): OptionDirectory(RESPATH"/profiles",Options::ACTIVE_PROFILE, "Profile"){ + app = _app; + height=100; + addSelection("Default"); + sort(selections.begin(),selections.end()); + initSelections(); + mAvatarTex=NULL; + mAvatar=NULL; + hasFocus=false; + populate(); + bCheck=false; +}; + +void OptionProfile::updateValue(){ + value++; + if (value > selections.size() - 1) + value=0; + + populate(); +} + +void OptionProfile::populate(){ + JRenderer * renderer = JRenderer::GetInstance(); + string temp = options[Options::ACTIVE_PROFILE].str; + if (value >= selections.size()){ //TODO fail gracefully. + return; + } + + options[Options::ACTIVE_PROFILE].str = selections[value]; + + SAFE_DELETE(mAvatar); + SAFE_DELETE(mAvatarTex); + mAvatarTex = JRenderer::GetInstance()->LoadTexture(options.profileFile("avatar.jpg","",true,true).c_str(), false); + if (mAvatarTex){ + mAvatar = NEW JQuad(mAvatarTex, 0, 0, 35, 50); + renderer->BindTexture(mAvatarTex); + } + + options.reloadProfile(); + PlayerData * pdata = NEW PlayerData(app->collection); + + options[Options::ACTIVE_PROFILE] = temp; + + char buf[512]; + sprintf(buf,"Credits: %i\nCards: %i",pdata->credits,pdata->collection->totalCards()); + preview = buf; + + + SAFE_DELETE(pdata); +} + +void OptionProfile::Render(){ + JRenderer * renderer = JRenderer::GetInstance(); + JLBFont * mFont = resources.GetJLBFont("f3"); + mFont->SetScale(1); + int spacing = 2+(int)mFont->GetHeight(); + + //Draw faux option. Not highlighted if we've only one. + if (hasFocus && selections.size() > 1){ + mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); + renderer->FillRoundRect(x-5,y-2,width-x-5,20,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); + mFont->DrawString("Change Profile",SCREEN_WIDTH/2,y,JGETEXT_CENTER); + }else{ + mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); + renderer->FillRoundRect(x-5,y-2,width-x-5,20,2,options[Metrics::OPTION_HEADER_FC].asColor(ARGB(150,80,80,80))); + mFont->DrawString("Profile",SCREEN_WIDTH/2,y,JGETEXT_CENTER); + } + + + //Draw preview box. + renderer->FillRoundRect(x-5,y-2+25,width-x-5,height-25,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); + + int pX, pY; + pX = x; + pY = y+30; + if(mAvatar){ + renderer->RenderQuad(mAvatar,x,pY); + pX += 40; + } + + mFont->SetColor(options[Metrics::OPTION_TEXT_TC].asColor()); + mFont->DrawString(selections[value].c_str(),pX,pY,JGETEXT_LEFT); + mFont->SetScale(.8); + mFont->DrawString(preview.c_str(),pX,pY+spacing,JGETEXT_LEFT); + mFont->SetScale(1); +} +void OptionProfile::Update(float dt){ + JGE * mEngine = JGE::GetInstance(); + if (hasFocus){ + if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue(); + } +} + +void OptionProfile::Entering(){ + hasFocus = true; + bCheck = false; + initialValue = value; +} +bool OptionProfile::Leaving(){ + + //Choice must be confirmed. + if(value != initialValue){ + bCheck = true; + return false; + } + hasFocus = false; + return true; +} + +void OptionProfile::cancelSubmode() +{ + if (initialValue >= selections.size()) + return; + + options[Options::ACTIVE_PROFILE] = selections[initialValue]; + value = initialValue; + populate(); + bCheck = false; +} +void OptionProfile::acceptSubmode() +{ + if (value >= selections.size()) + return; + + options[Options::ACTIVE_PROFILE] = selections[value]; + initialValue = value; + populate(); + bCheck = false; +} + +//OptionDirectory +void OptionDirectory::Reload(){ + DIR *mDip; + struct dirent *mDit; + char buf[4096]; + mDip = opendir(root.c_str()); + + if(!mDip) + return; + + while ((mDit = readdir(mDip))){ + if(mDit->d_name[0] != '.'){ + sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); + std::ifstream file(buf); + if(file){ + file.close(); + continue; + } + if(find(selections.begin(),selections.end(),mDit->d_name) == selections.end()) + addSelection(mDit->d_name); + } + } + + closedir(mDip); + mDip = NULL; + initSelections(); +} + +OptionDirectory::OptionDirectory(string _root, string _id, string _displayValue): OptionSelect(_id, _displayValue){ + DIR *mDip; + struct dirent *mDit; + char buf[4096]; + root = _root; + mDip = opendir(root.c_str()); + + if(!mDip) + return; + + while ((mDit = readdir(mDip))){ + if(mDit->d_name[0] != '.'){ + sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); + std::ifstream file(buf); + if(file){ + file.close(); + continue; + } + addSelection(mDit->d_name); + } + } + + closedir(mDip); + mDip = NULL; + initSelections(); +} + +OptionsList::OptionsList(string name){ + sectionName = name; + failMsg = "NO OPTIONS AVAILABLE"; + nbitems = 0; + current = -1; +} +OptionsList::~OptionsList(){ + for (int i = 0 ; i < nbitems; i++){ + SAFE_DELETE(listItems[i]); + } +} + +void OptionsList::Add(OptionItem * item){ + if (nbitems < MAX_OPTION_ITEMS){ + listItems[nbitems] = item; + nbitems++; + } +} +bool OptionsList::Leaving(){ + if(current >= 0 && current < nbitems) + return listItems[current]->Leaving(); + + return true; +} +void OptionsList::Entering(){ + //Try to force a selectable option. + if(current == -1){ + for (int i = 0 ; i < nbitems; i++){ + if(listItems[i]->Selectable()) { + current = i; + listItems[current]->Entering(); + break; + } + } + } + + if(current >= 0 && current < nbitems) + listItems[current]->Entering(); + + return; +} +void OptionsList::Render(){ + JRenderer * renderer = JRenderer::GetInstance(); + + int width = SCREEN_WIDTH; + int listHeight=40; + int listSelectable=0; + int adjustedCurrent=0; + int start = 0, nowPos = 0, vHeight=0; + + + //List is empty. + if (!nbitems && failMsg != ""){ + JLBFont * mFont = resources.GetJLBFont("f3"); + mFont->SetColor(options[Metrics::MSG_FAIL_TC].asColor(ARGB(255,155,155,155))); + mFont->DrawString(failMsg.c_str(),SCREEN_WIDTH/2, 40, JGETEXT_RIGHT); + return; + } + + //Force a selectable option. + if(current == -1){ + for (int i = 0 ; i < nbitems; i++){ + if(listItems[i]->Selectable()) { + current = i; + listItems[current]->Entering(); + break; + } + } + } + //Find out how large our list is. + for (int pos=0;pos < nbitems; pos++){ + listHeight+=listItems[pos]->height+5; + if(listItems[pos]->Selectable()){ + listSelectable++; + if(pos < current) adjustedCurrent++; + } + } + + //Always fill screen + if(listHeight > SCREEN_HEIGHT) + { + width -= 10; + for (start=current;start > 0; start--){ + if(listItems[start]->bHidden) + continue; + + vHeight += listItems[start]->height+5; + if(vHeight >= (SCREEN_HEIGHT-60)/2) + break; + } + vHeight = 0; + for (nowPos=nbitems;nowPos > 1; nowPos--){ + if(listItems[start]->bHidden) + continue; + vHeight += listItems[nowPos-1]->height+5; + } + + if(vHeight <= SCREEN_HEIGHT-40 && nowPos < start) + start = nowPos; + + } + + vHeight = 0; + nowPos = 40; + + //Render items. + if(start >= 0) + { + for (int pos=0;pos < nbitems; pos++){ + if(listItems[pos]->bHidden) + continue; + + if(pos < start){ + vHeight += listItems[pos]->height + 5; + continue; + } + listItems[pos]->x = 10; + listItems[pos]->y = nowPos; + listItems[pos]->width = width; + nowPos += listItems[pos]->height + 5; + listItems[pos]->Render(); + if(nowPos > SCREEN_HEIGHT) + break; + } + + //Draw scrollbar + if(listHeight > SCREEN_HEIGHT && listSelectable > 1){ + int barPosition = 35+((float)adjustedCurrent/listSelectable)*(SCREEN_HEIGHT-40); + int barLength = (SCREEN_HEIGHT-40) / listSelectable; + if(barLength < 4) barLength = 4; + width = (SCREEN_WIDTH-(width-5))/2; //Find center of blank space by options. + renderer->FillRect(SCREEN_WIDTH-width-1,39,2,SCREEN_HEIGHT-42, + options[Metrics::OPTION_SCROLLBAR_FC].asColor(ARGB(150,150,150,150))); + renderer->FillRoundRect(SCREEN_WIDTH-width-4,barPosition,5,barLength,2, + options[Metrics::OPTION_SCROLLBAR_FCH].asColor(ARGB(255,255,255,255))); + } + } +} + +void OptionsList::save(){ + for (int i = 0; i < nbitems; i++){ + listItems[i]->setData(); + } + ::options.save(); +} + +void OptionsList::Update(float dt){ + JGE * mEngine = JGE::GetInstance(); + int potential = current; + + if (mEngine->GetButtonClick(PSP_CTRL_UP)) + { + if (potential > 0){ + potential--; + while(potential > 0 && listItems[potential]->Selectable() == false) + potential--; + if(potential < 0 || !listItems[potential]->Selectable()) + potential = -1; + else if(listItems[current]->Leaving()){ + current = potential; + listItems[current]->Entering(); + } + } + } + else if (mEngine->GetButtonClick(PSP_CTRL_DOWN)) + { + if (potential < nbitems-1){ + potential++; + while(potential < nbitems-1 && listItems[potential]->Selectable() == false) + potential++; + if(potential == nbitems || !listItems[potential]->Selectable()) + potential = -1; + else if(potential != current && listItems[current]->Leaving()){ + current = potential; + listItems[current]->Entering(); + } + } + } + for (int i = 0 ; i < nbitems; i++){ + listItems[i]->Update(dt); + } +} + + +void OptionsMenu::Add(OptionsList * tab){ + if (nbitems < MAX_OPTION_TABS){ + tabs[nbitems] = tab; + nbitems++; + if (current < 0){ + current = 0; + } + + } +} + +void OptionsMenu::Render(){ + if (nbitems == 0){ + mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT); + return; + } + + JRenderer * renderer = JRenderer::GetInstance(); + + int offset = 0; + for(int i=0;iGetStringWidth(tabs[i]->sectionName.c_str()); + if(i == current){ + mFont->SetColor(options[Metrics::OPTION_TAB_TCH].asColor()); + renderer->FillRoundRect(offset+5,5,w + 5,25,2,options[Metrics::OPTION_TAB_FCH].asColor(ARGB(150,150,150,150))); + } + else{ + mFont->SetColor(options[Metrics::OPTION_TAB_TC].asColor(ARGB(255,155,155,155))); + renderer->FillRoundRect(offset+5,5,w + 5,25,2,options[Metrics::OPTION_TAB_FC].asColor(ARGB(150,50,50,50))); + } + mFont->DrawString(tabs[i]->sectionName.c_str(),offset+10,10); + offset += w + 10 + 2; + } + + if(current > -1 && current < nbitems && tabs[current]) + tabs[current]->Render(); +} + +void OptionsMenu::Update(float dt){ + JGE * mEngine = JGE::GetInstance(); + if(current < 0 || current >= nbitems) + return; + + //We use the shoulder buttons to switch tabs, if we've got them. + if (mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)) + { + if (current > 0) + { + if(tabs[current]->Leaving()){ + current--; + tabs[current]->Entering(); + } + } + } + else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)) + { + if (current < nbitems -1) + { + if(tabs[current]->Leaving()){ + current++; + tabs[current]->Entering(); + } + } + } + + tabs[current]->Update(dt); +} + +OptionsMenu::OptionsMenu(){ + nbitems=0; + current=0; + mFont = resources.GetJLBFont("f3"); + for(int x=0;xsave(); +} + +bool OptionsMenu::isTab(string name){ + if(current <0 || current >= nbitems) + return false; + else if(tabs[current]->sectionName == name) + return true; + + return false; +} + +int OptionsMenu::Submode() +{ + if(current <0 || current >= nbitems) + return OPTIONS_SUBMODE_NORMAL; + + return tabs[current]->Submode(); +} + +void OptionsMenu::acceptSubmode() +{ + if(current > -1 && current < nbitems) + tabs[current]->acceptSubmode(); +} +void OptionsMenu::reloadValues() +{ + for(int i=0;ireloadValues(); +} + +void OptionsMenu::cancelSubmode() +{ + if(current > -1 && current < nbitems) + tabs[current]->cancelSubmode(); +} + + +int OptionsList::Submode() +{ + if(current <0 || current >= nbitems) + return OPTIONS_SUBMODE_NORMAL; + + return listItems[current]->Submode(); +} + +void OptionsList::reloadValues() +{ + for(int i=0;iReload(); + } +} +void OptionsList::acceptSubmode() +{ + if(current > -1 && current < nbitems) + listItems[current]->acceptSubmode(); +} + +void OptionsList::cancelSubmode() +{ + if(current > -1 && current < nbitems) + listItems[current]->cancelSubmode(); +} + +//OptionString + +void OptionString::Render(){ + + JLBFont * mFont = resources.GetJLBFont("f3"); + if (hasFocus){ + mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0))); + }else{ + mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor()); + } + JRenderer * renderer = JRenderer::GetInstance(); + renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50))); + + if(!bShowValue){ + mFont->DrawString(displayValue.c_str(),(x+width)/2,y,JGETEXT_CENTER); + } + else{ + mFont->DrawString(displayValue.c_str(),x,y); + int w = mFont->GetStringWidth(value.c_str()-10); + mFont->DrawString(value.c_str(),width - w,y,JGETEXT_RIGHT); + } +} + +void OptionString::setData(){ + if(id != "") + options[id] = GameOption(value); +} +void OptionString::updateValue(){ + options.keypadStart(value,&value); + options.keypadTitle(displayValue); +} + +void OptionNewProfile::updateValue(){ + options.keypadStart("",&value); + options.keypadTitle(displayValue); +} + +void OptionNewProfile::Update(float dt){ + if(value != ""){ + string temp; + temp = options[Options::ACTIVE_PROFILE].str; + value = options.keypadFinish(); + if(value == "") + return; + + if(temp != value){ + options[Options::ACTIVE_PROFILE] = value; + options.reloadProfile(); + } + value = ""; + bChanged = true; + } + OptionItem::Update(dt); +} + +int OptionNewProfile::Submode(){ + if(bChanged){ + bChanged=false; //Just about to check it! + return OPTIONS_SUBMODE_RELOAD; + } + return OPTIONS_SUBMODE_NORMAL; +} + +OptionString::OptionString(string _id, string _displayValue): OptionItem(_id, _displayValue) +{ + bShowValue=true; + if(_id != "") + value=options[_id].str; +} + +ostream& OptionString::toString(ostream& out) const{ +return out << "OptionString ::: displayValue : " << displayValue + << " ; id : " << id + << " ; value : " << value + << " ; hasFocus : " << hasFocus + << " ; x,y : " << x << "," << y; +} + +OptionTheme::OptionTheme(): OptionDirectory(RESPATH"/themes",Options::ACTIVE_THEME, "Current Theme"){ + addSelection("Default"); + sort(selections.begin(),selections.end()); + initSelections(); + hasFocus=false; + if(selections.size() == 1) + bHidden = true; +} + +void OptionVolume::updateValue(){ + value+=increment; + if (value>maxValue) + value=0; +} + +OptionVolume::OptionVolume(string _id, string _displayName, bool _bMusic): OptionInteger(_id, _displayName, 100, 10,0,"Muted") { + bMusic = _bMusic; } \ No newline at end of file diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index 7b5db0ada..3ea515b40 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -935,10 +935,6 @@ int WResourceManager::CreateTexture(const string &textureName) { mTextureList.push_back(tex); mTextureMap[textureName] = id; } - else - { - - } return id; }