diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6f9bda0de..9b3f89b21 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -733,7 +733,7 @@ class AManaProducer: public MTGAbility{ } - if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0 && currentlyTapping < 3){ + if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0 && currentlyTapping < 3){ JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/mana.wav"); if (sample) JSoundSystem::GetInstance()->PlaySample(sample); } diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 7d73626c2..31f56b142 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -1,25 +1,42 @@ #ifndef _GAME_OPTIONS_H_ #define _GAME_OPTIONS_H_ +#include +#include +using std::map; +using std::string; + +#define OPTIONS_MUSICVOLUME "musicVolume" +#define OPTIONS_SFXVOLUME "sfxVolume" -#define MAX_OPTIONS 50 -#define OPTIONS_MUSICVOLUME 0 -#define OPTIONS_SFXVOLUME 1 -#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 2 #define OPTIONS_SAVEFILE RESPATH"/settings/options.txt" + +class GameOption { +public: + int value; + string svalue; + int getIntValue(); + GameOption(int _value = 0); +}; + + class GameOptions { public: - int values[MAX_OPTIONS]; + map values; static GameOptions * GetInstance(); static void Destroy(); int save(); int load(); + static const char * phaseInterrupts[]; private: GameOptions(); ~GameOptions(); static GameOptions* mInstance; + static map optionsTypes; + + }; #endif diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 70c9726aa..0fe8e912d 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -200,7 +200,7 @@ class GameStateDeckViewer: public GameState, public JGuiListener } welcome_menu->Add(10, "Cancel"); - if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){ + if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() > 0){ if (GameApp::music){ JSoundSystem::GetInstance()->StopMusic(GameApp::music); SAFE_DELETE(GameApp::music); diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 9acec7d53..2ed4a20de 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -8,12 +8,12 @@ using std::string; class OptionItem:public JGuiObject{ public: - string displayValue; - int id, value; + string displayValue, id; + int value; int hasFocus; int maxValue, increment; float x, y; - OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1); + OptionItem(string _id, string _displayValue, int _maxValue = 1, int _increment = 1); ~OptionItem(); virtual void Render(); diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index abdae48e6..5ccedfbe9 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -89,7 +89,7 @@ int Spell::resolve(){ source->controller()->game->putInPlay(source); //Play SFX - if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){ + if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0){ JSample * sample = source->getSample(); if (sample){ JSoundSystem::GetInstance()->PlaySample(sample); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 4651869c4..74e493834 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -135,7 +135,7 @@ void GameObserver::userRequestNextGamePhase(){ if (getCurrentTargetChooser()) return; if (mLayers->combatLayer()->remainingDamageSteps) return; //TODO CHECK POSSIBILITY - if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){ + if (opponent()->isAI() || GameOptions::GetInstance()->values[GameOptions::phaseInterrupts[currentGamePhase]].getIntValue()){ mLayers->stackLayer()->AddNextGamePhase(); }else{ nextGamePhase(); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index ab4bcff28..0a9a87260 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -4,6 +4,32 @@ #include #include #include +#include + +const char* GameOptions::phaseInterrupts[] = { + "interrupt ---", + "interrupt Untap", + "interrupt Upkeep", + "interrupt Draw", + "interrupt Main phase 1", + "interrupt Combat begins", + "interrupt Attackers", + "interrupt Blockers", + "interrupt Combat damage", + "interrupt Combat ends", + "interrupt Main phase 2", + "interrupt End of turn", + "interrupt Cleanup", + "interrupt ---" +}; + +GameOption::GameOption(int _value){ + value = _value; +} + +int GameOption::getIntValue(){ + return value; +} GameOptions* GameOptions::mInstance = NULL; @@ -14,9 +40,6 @@ GameOptions * GameOptions::GetInstance(){ } GameOptions::GameOptions(){ - for(int i = 0; i < MAX_OPTIONS; i++){ - values[i] = 0; - } load(); } @@ -24,12 +47,10 @@ int GameOptions::load(){ std::ifstream file(OPTIONS_SAVEFILE); std::string s; if(file){ - for (int i = 0; i < MAX_OPTIONS; i++){ - if(std::getline(file,s)){ - values[i] = atoi(s.c_str()); - }else{ - //TODO error management - } + while(std::getline(file,s)){ + int found =s.find("="); + string name = s.substr(0,found); + values[name] = GameOption(atoi(s.substr(found+1).c_str())); } file.close(); } @@ -38,10 +59,11 @@ int GameOptions::load(){ int GameOptions::save(){ std::ofstream file(OPTIONS_SAVEFILE); - char writer[10]; + char writer[1024]; if (file){ - for (int i = 0; i < MAX_OPTIONS; i++){ - sprintf(writer,"%i\n", values[i]); + map::iterator it; + for ( it=values.begin() ; it != values.end(); it++ ){ + sprintf(writer,"%s=%d\n", it->first.c_str(), it->second.getIntValue()); file<EnableVSync(true); subMenuController = NULL; - if (GameApp::HasMusic && !GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){ + if (GameApp::HasMusic && !GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() > 0){ GameApp::music = JSoundSystem::GetInstance()->LoadMusic("sound/Track0.mp3"); JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true); } - if (GameApp::HasMusic && GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] == 0){ + if (GameApp::HasMusic && GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() == 0){ JSoundSystem::GetInstance()->StopMusic(GameApp::music); SAFE_DELETE(GameApp::music); } diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index bcd78c1ab..915667eeb 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -67,9 +67,9 @@ void GameStateOptions::Render() const char * const CreditsText[] = { "Wagic, The Homebrew ?! by WilLoW", - "This is a work in progress and it contains bugs, deal with it", + "This is a work in progress and it contains bugs", "updates on http://www.wololo.net/wagic", - "Many thanks to Abrasax and J for their help in this release", + "Many thanks to J for his help in this release, and to all card creators", "", "Developped with the JGE++ Library (http://jge.khors.com)", "", diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 279001f06..4ed0bff49 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -90,7 +90,7 @@ void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){ void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){ if (from->removeCard(card)){ - if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){ + if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0){ if (to == graveyard){ if (card->isACreature()){ JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/graveyard.wav"); diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 4252ce442..e122e94c6 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -4,12 +4,12 @@ #include "../include/GameOptions.h" -OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){ +OptionItem::OptionItem(string _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){ id = _id; maxValue = _maxValue; increment = _increment; displayValue = _displayValue; - value = GameOptions::GetInstance()->values[id]; + value = GameOptions::GetInstance()->values[id].getIntValue(); hasFocus = 0; x = 0; y = 0; @@ -20,7 +20,10 @@ OptionItem::~OptionItem(){ } void OptionItem::setData(){ - GameOptions::GetInstance()->values[id] = value; + GameOptions::GetInstance()->values[id] = GameOption(value); + char buf[4096]; + sprintf(buf, "Option: %s => %i\n", id.c_str(), GameOptions::GetInstance()->values[id].getIntValue()); + OutputDebugString(buf); } void OptionItem::Render(){