diff --git a/projects/mtg/Makefile b/projects/mtg/Makefile index a3387bdd6..407cf7b79 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/GameStateStory.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/StoryFlow.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.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 objs/WFont.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/GameStateStory.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/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.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 objs/WFont.o DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) diff --git a/projects/mtg/bin/Res/themes/Gemstones/backdrop_black.jpg b/projects/mtg/bin/Res/themes/Gemstones/backdrop_black.jpg new file mode 100644 index 000000000..35d77fa27 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/backdrop_black.jpg differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/backdrop_blue.jpg b/projects/mtg/bin/Res/themes/Gemstones/backdrop_blue.jpg new file mode 100644 index 000000000..4ca776b0d Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/backdrop_blue.jpg differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/backdrop_green.jpg b/projects/mtg/bin/Res/themes/Gemstones/backdrop_green.jpg new file mode 100644 index 000000000..f4ae6edca Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/backdrop_green.jpg differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/backdrop_red.jpg b/projects/mtg/bin/Res/themes/Gemstones/backdrop_red.jpg new file mode 100644 index 000000000..f79bd5bc9 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/backdrop_red.jpg differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/backdrop_white.jpg b/projects/mtg/bin/Res/themes/Gemstones/backdrop_white.jpg new file mode 100644 index 000000000..04c5588ea Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/backdrop_white.jpg differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/gold.png b/projects/mtg/bin/Res/themes/Gemstones/gold.png new file mode 100644 index 000000000..f85513203 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/gold.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/goldglow.png b/projects/mtg/bin/Res/themes/Gemstones/goldglow.png new file mode 100644 index 000000000..f85513203 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/goldglow.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/handback.png b/projects/mtg/bin/Res/themes/Gemstones/handback.png new file mode 100644 index 000000000..26656e32d Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/handback.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/handback_white.png b/projects/mtg/bin/Res/themes/Gemstones/handback_white.png new file mode 100644 index 000000000..090eec174 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/handback_white.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle.png new file mode 100644 index 000000000..6a41edf5d Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle_black.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle_black.png new file mode 100644 index 000000000..93679c885 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle_black.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle_blue.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle_blue.png new file mode 100644 index 000000000..b7b155131 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle_blue.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle_green.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle_green.png new file mode 100644 index 000000000..7d3abdc44 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle_green.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle_red.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle_red.png new file mode 100644 index 000000000..03459fae8 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle_red.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/menutitle_white.png b/projects/mtg/bin/Res/themes/Gemstones/menutitle_white.png new file mode 100644 index 000000000..8c40a23a7 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/menutitle_white.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/phasebar_black.png b/projects/mtg/bin/Res/themes/Gemstones/phasebar_black.png new file mode 100644 index 000000000..37d8beb7c Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/phasebar_black.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/phasebar_blue.png b/projects/mtg/bin/Res/themes/Gemstones/phasebar_blue.png new file mode 100644 index 000000000..dfb19afa6 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/phasebar_blue.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/phasebar_green.png b/projects/mtg/bin/Res/themes/Gemstones/phasebar_green.png new file mode 100644 index 000000000..fc7a9eb22 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/phasebar_green.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/phasebar_red.png b/projects/mtg/bin/Res/themes/Gemstones/phasebar_red.png new file mode 100644 index 000000000..bbe189b81 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/phasebar_red.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/phasebar_white.png b/projects/mtg/bin/Res/themes/Gemstones/phasebar_white.png new file mode 100644 index 000000000..812f8277e Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/phasebar_white.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/preview.png b/projects/mtg/bin/Res/themes/Gemstones/preview.png new file mode 100644 index 000000000..8a9984c81 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/preview.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/style.txt b/projects/mtg/bin/Res/themes/Gemstones/style.txt new file mode 100644 index 000000000..38db22cc7 --- /dev/null +++ b/projects/mtg/bin/Res/themes/Gemstones/style.txt @@ -0,0 +1,43 @@ + + Jade + Jasper + Lapis + Jet + Moonstone + + + + + + + + + + + \ No newline at end of file diff --git a/projects/mtg/bin/Res/themes/Gemstones/themeinfo.txt b/projects/mtg/bin/Res/themes/Gemstones/themeinfo.txt new file mode 100644 index 000000000..27d5dbec8 --- /dev/null +++ b/projects/mtg/bin/Res/themes/Gemstones/themeinfo.txt @@ -0,0 +1,5 @@ +Jeck + +This is Gemstones, a theme based on semi-precious gemstones. It demonstrates the use of backdrop.txt to script backdrop selection. + +See the forum at http://wololo.net/forum/ for more themes! \ No newline at end of file diff --git a/projects/mtg/bin/Res/themes/Gemstones/wood_black.png b/projects/mtg/bin/Res/themes/Gemstones/wood_black.png new file mode 100644 index 000000000..edf5f1126 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/wood_black.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/wood_blue.png b/projects/mtg/bin/Res/themes/Gemstones/wood_blue.png new file mode 100644 index 000000000..f053623b4 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/wood_blue.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/wood_green.png b/projects/mtg/bin/Res/themes/Gemstones/wood_green.png new file mode 100644 index 000000000..a209fbd51 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/wood_green.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/wood_red.png b/projects/mtg/bin/Res/themes/Gemstones/wood_red.png new file mode 100644 index 000000000..40621b5b6 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/wood_red.png differ diff --git a/projects/mtg/bin/Res/themes/Gemstones/wood_white.png b/projects/mtg/bin/Res/themes/Gemstones/wood_white.png new file mode 100644 index 000000000..30afeb638 Binary files /dev/null and b/projects/mtg/bin/Res/themes/Gemstones/wood_white.png differ diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 7c40f80b9..047a69bf5 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -19,6 +19,10 @@ using std::string; #define INVALID_OPTION -1 +class WStyle; +class StyleManager; +class Player; + class Options { public: friend class GameSettings; @@ -44,6 +48,7 @@ public: MAX_GRADE, ECON_DIFFICULTY, TRANSITIONS, + GUI_STYLE, INTERRUPT_SECONDS, KEY_BINDINGS, //My interrupts @@ -144,6 +149,8 @@ private: OptionVolume(); static OptionVolume mDef; }; + + class OptionClosedHand: public EnumDefinition { public: enum { INVISIBLE = 0, VISIBLE = 1 }; @@ -183,7 +190,6 @@ private: OptionEconDifficulty(); static OptionEconDifficulty mDef; }; - class OptionDifficulty: public EnumDefinition { public: enum { NORMAL = 0, HARD = 1, HARDER = 2, EVIL = 3}; @@ -243,9 +249,14 @@ public: static GameOption invalid_option; + WStyle * getStyle(); + StyleManager * getStyleMan(); + void automaticStyle(Player * p1, Player * p2); + private: GameApp * theGame; SimplePad * keypad; + StyleManager * styleMan; }; extern GameSettings options; diff --git a/projects/mtg/include/GameStateShop.h b/projects/mtg/include/GameStateShop.h index 9df4c840a..27f0695de 100644 --- a/projects/mtg/include/GameStateShop.h +++ b/projects/mtg/include/GameStateShop.h @@ -39,6 +39,9 @@ public: int maxInventory(); void addToDeck(MTGDeck * d, WSrcCards * srcCards); string getSort(); +#ifdef TESTSUITE + bool unitTest(); +#endif private: void randomCustom(MTGPacks * packlist); void randomStandard(); diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index ac57bb8cf..584b8cb51 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -84,7 +84,13 @@ protected: vector actual_data; }; - +class OptionThemeStyle: public OptionSelect{ + public: + virtual bool Visible(); + virtual void Reload(); + virtual void confirmChange(bool confirmed); + OptionThemeStyle(string _displayValue); +}; class OptionDirectory:public OptionSelect{ public: virtual void Reload(); @@ -98,7 +104,7 @@ class OptionTheme:public OptionDirectory{ private: static const string DIRTESTER; public: - OptionTheme(); + OptionTheme(OptionThemeStyle * style = NULL); JQuad * getImage(); virtual void updateValue(); virtual float getHeight(); @@ -107,6 +113,7 @@ class OptionTheme:public OptionDirectory{ virtual bool Visible(); protected: + OptionThemeStyle * ts; string author; bool bChecked; }; diff --git a/projects/mtg/include/StyleManager.h b/projects/mtg/include/StyleManager.h new file mode 100644 index 000000000..7a7260c53 --- /dev/null +++ b/projects/mtg/include/StyleManager.h @@ -0,0 +1,32 @@ +class WStyle{ +public: + friend class StyleManager; + string stylized(string filename); +protected: + map mapping; +}; + +class WStyleRule{ +public: + string filter; //The condition + string style; //The style to use. +}; +class MTGDeck; +class StyleManager{ +public: + friend class OptionThemeStyle; + friend class OptionTheme; + StyleManager(); + ~StyleManager(); + void determineActive(MTGDeck * p1, MTGDeck * p2); + WStyle * get(); +protected: + int topRule; int topSize; + int playerSrc; + + void loadRules(); + void killRules(); + vector rules; + string activeStyle; + map styles; +}; \ No newline at end of file diff --git a/projects/mtg/include/TestSuiteAI.h b/projects/mtg/include/TestSuiteAI.h index 30897e025..7b7b154b7 100644 --- a/projects/mtg/include/TestSuiteAI.h +++ b/projects/mtg/include/TestSuiteAI.h @@ -47,6 +47,12 @@ class TestSuiteState{ void cleanup(); }; + +class TestSuitePregame{ + public: + virtual void performTest() = 0; +}; + class TestSuite{ public: MTGAllCards* collection; @@ -67,13 +73,14 @@ class TestSuite{ int load(const char * filename); TestSuite(const char * filename,MTGAllCards* _collection); void initGame(); + void pregameTests(); int assertGame(); MTGPlayerCards * buildDeck(int playerId); string getNextAction(); Interruptible * getActionByMTGId(int mtgid); int loadNext(); void cleanup(); - int Log(const char * text); + static int Log(const char * text); }; @@ -85,7 +92,6 @@ class TestSuiteAI:public AIPlayerBaka{ TestSuiteAI(TestSuite * suite, int playerId); virtual int Act(float dt); virtual int displayStack(); - }; diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 501af55af..51622df9f 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -193,6 +193,8 @@ void GameObserver::startGame(Rules * rules){ if (rules) rules->initPlayers(); + options.automaticStyle(players[0],players[1]); + mLayers = NEW DuelLayers(); mLayers->init(); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index e4ff8bc07..5fc51793d 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -4,6 +4,7 @@ #include "../include/GameOptions.h" #include "../include/Translate.h" #include "../include/OptionItem.h" +#include "../include/StyleManager.h" #include #include #include @@ -31,6 +32,7 @@ const string Options::optionNames[] = { "maxGrade", "economic_difficulty", "transitions", + "bgStyle", "interruptSeconds", #if defined(WIN32) "keybindings_win", @@ -409,16 +411,46 @@ GameSettings options; GameSettings::GameSettings() { + styleMan = NULL; globalOptions = NULL; theGame = NULL; profileOptions = NULL; //reloadProfile should be before using options. } +WStyle * GameSettings::getStyle() { + if(!styleMan) styleMan = new StyleManager(); + return styleMan->get(); +} + +StyleManager * GameSettings::getStyleMan() { + if(!styleMan) styleMan = new StyleManager(); + return styleMan; +} + +void GameSettings::automaticStyle(Player * p1, Player * p2){ + if(!styleMan) styleMan = new StyleManager(); + MTGDeck * decks[2]; + for(int i=0;i<2;i++){ + decks[i] = new MTGDeck(GameApp::collection); + Player * p; if(i == 0) p = p1; else p = p2; + map::iterator it; + for(it = p->game->library->cardsMap.begin();it != p->game->library->cardsMap.end();it++){ + decks[i]->add(it->first); + } + } + styleMan->determineActive(decks[0],decks[1]); + for(int i=0;i<2;i++){ + SAFE_DELETE(decks[i]); + } +} + + GameSettings::~GameSettings(){ SAFE_DELETE(globalOptions); SAFE_DELETE(profileOptions); SAFE_DELETE(keypad); + SAFE_DELETE(styleMan); } bool GameSettings::newAward(){ @@ -591,6 +623,7 @@ void GameSettings::checkProfile(){ //Give the player their first deck createUsersFirstDeck(setId); } + getStyleMan()->determineActive(NULL,NULL); } void GameSettings::createUsersFirstDeck(int setId){ @@ -766,6 +799,7 @@ OptionEconDifficulty::OptionEconDifficulty(){ mDef.values.push_back(EnumDefinition::assoc(Constants::ECON_LUCK, "Luck")); mDef.values.push_back(EnumDefinition::assoc(Constants::ECON_EASY, "Easy")); }; + //GameOptionAward GameOptionAward::GameOptionAward(){ achieved = time(NULL); diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 1d9faade3..ecd622574 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -242,6 +242,7 @@ void GameStateDuel::Update(float dt) rules = NEW Rules("testsuite.txt"); loadTestSuitePlayers(); mGamePhase = DUEL_STATE_PLAY; + testSuite->pregameTests(); testSuite->initGame(); }else{ if (!game){ diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 362f43c03..ebdd4c724 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -51,12 +51,18 @@ void GameStateOptions::Start() optionsList->Add(NEW WGuiHeader("User Options")); WDecoConfirm * cPrf = NEW WDecoConfirm(this,NEW OptionProfile(mParent,this)); cPrf->confirm = "Use this Profile"; - OptionDirectory * od = NEW OptionTheme(); + OptionThemeStyle * ots = NEW OptionThemeStyle("Theme Style"); + OptionDirectory * od = NEW OptionTheme(ots); WDecoConfirm * cThm = NEW WDecoConfirm(this,od); cThm->confirm = "Use this Theme"; + WDecoConfirm * cStyle = NEW WDecoConfirm(this,ots); + cStyle->confirm = "Use this Style"; + optionsList->Add(NEW WGuiSplit(cPrf,cThm)); + optionsList->Add(cStyle); optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"),-102,4,this)); + optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode"))); optionsTabs->Add(optionsList); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index 8f842f61d..05e54cc1c 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -9,6 +9,8 @@ #include "../include/MTGPack.h" #include "../include/Translate.h" #include "../include/GameOptions.h" +#include "../include/TestSuiteAI.h" + #include float GameStateShop::_x1[] = { 79, 19, 27,103,154,187,102,144,198,133,183}; @@ -787,3 +789,47 @@ void ShopBooster::addToDeck(MTGDeck * d, WSrcCards * srcCards){ else pack->assemblePack(d); } + + +#ifdef TESTSUITE +bool ShopBooster::unitTest(){ + //this tests the default random pack creation. + MTGDeck * d = NEW MTGDeck(GameApp::collection); + char result[1024]; + + randomStandard(); + MTGPack * mP = MTGPacks::getDefault(); + if(!altSet && mainSet->mPack) mP = mainSet->mPack; + char buf[512]; + if(!altSet) sprintf(buf,"set:%s;",mainSet->id.c_str()); + else sprintf(buf,"set:%s;|set:%s;",mainSet->id.c_str(),altSet->id.c_str()); + mP->pool = buf; + mP->assemblePack(d); //Use the primary packfile. assemblePack deletes pool. + DeckDataWrapper* ddw = NEW DeckDataWrapper(d); + + int u = 0, r = 0; + int card = 0; + for(int i=0;iSize(true);i++){ + MTGCard * c = ddw->getCard(i); + if(!c) break; + if(c->getRarity() == Constants::RARITY_R || c->getRarity() == Constants::RARITY_M) + r+=ddw->count(c); + else if(c->getRarity() == Constants::RARITY_U) + u+=ddw->count(c); + card++; + } + if(r != 1 || u != 3 ){ + sprintf(result, "==Unexpected rarity count==
"); + TestSuite::Log(result); + return false; + } + if(ddw->getCount() < 14) { + sprintf(result, "==Unexpected card count==
"); + TestSuite::Log(result); + return false; + } + sprintf(result, "==Test Succesful !==
"); + TestSuite::Log(result); + return true; +} + #endif \ No newline at end of file diff --git a/projects/mtg/src/GuiHand.cpp b/projects/mtg/src/GuiHand.cpp index a5df402d3..3fd8b92e1 100644 --- a/projects/mtg/src/GuiHand.cpp +++ b/projects/mtg/src/GuiHand.cpp @@ -27,22 +27,13 @@ HandLimitor::HandLimitor(GuiHand* hand) : hand(hand) {} GuiHand::GuiHand(CardSelector* cs, MTGHand* hand) : GuiLayer(), hand(hand), cs(cs) { - JTexture* texture = resources.GetTexture("handback.png"); - if (texture) - { - back = NEW JQuad(texture, 0, 0, 101, 250); - back->SetTextureRect(1, 0, 100, 250); - } - else - { - back = NULL; - GameApp::systemError = "Error loading hand texture : " __FILE__; - } + back = resources.RetrieveTempQuad("handback.png"); + if(back) back->SetTextureRect(1, 0, 100, 250); + else GameApp::systemError = "Error loading hand texture : " __FILE__; } GuiHand::~GuiHand() { - delete(back); for (vector::iterator it = cards.begin(); it != cards.end(); ++it) delete(*it); } diff --git a/projects/mtg/src/GuiPhaseBar.cpp b/projects/mtg/src/GuiPhaseBar.cpp index 09cffa343..144b489a1 100644 --- a/projects/mtg/src/GuiPhaseBar.cpp +++ b/projects/mtg/src/GuiPhaseBar.cpp @@ -24,15 +24,12 @@ static int colors[] = GuiPhaseBar::GuiPhaseBar() : phase(NULL), angle(0.0f) { - JQuad * quad; + JQuad * quad = NULL; if ((quad = resources.GetQuad("phasebar")) != NULL){ quad->mHeight = Height; quad->mWidth = Width; } - else - { - GameApp::systemError = "Error loading phasebar texture : " __FILE__; - } + else GameApp::systemError = "Error loading phasebar texture : " __FILE__; } GuiPhaseBar::~GuiPhaseBar() diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index aba577302..1ec848358 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -5,6 +5,7 @@ #include "../include/Translate.h" #include "../include/Subtypes.h" #include "../include/TranslateKeys.h" +#include "../include/StyleManager.h" #include #include #include @@ -216,6 +217,27 @@ void OptionProfile::confirmChange(bool confirmed){ } return; } +//OptionThemeStyle +OptionThemeStyle::OptionThemeStyle(string _displayValue) : OptionSelect(Options::GUI_STYLE,_displayValue) +{ + Reload(); + initSelections(); +}; +bool OptionThemeStyle::Visible() { + return (selections.size() > 1); +}; +void OptionThemeStyle::confirmChange(bool confirmed){ + options.getStyleMan()->determineActive(NULL,NULL); +} +void OptionThemeStyle::Reload(){ + selections.clear(); + addSelection("Dynamic"); + map::iterator it; + + StyleManager * sm = options.getStyleMan(); + for(it=sm->styles.begin();it!=sm->styles.end();it++) + addSelection(it->first); +} //OptionLanguage OptionLanguage::OptionLanguage(string _displayValue) : OptionSelect(Options::LANG,_displayValue) { @@ -348,12 +370,13 @@ OptionDirectory::OptionDirectory(string root, int id, string displayValue, strin } const string OptionTheme::DIRTESTER = "preview.png"; -OptionTheme::OptionTheme() : OptionDirectory(RESPATH"/themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ +OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(RESPATH"/themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ addSelection("Default"); sort(selections.begin(),selections.end()); initSelections(); mFocus=false; bChecked = false; + ts = style; } JQuad * OptionTheme::getImage(){ char buf[512]; @@ -429,6 +452,9 @@ void OptionTheme::confirmChange(bool confirmed){ value = prior_value; else{ setData(); + options.getStyleMan()->loadRules(); + if(ts) ts->Reload(); + resources.Refresh(); //Update images prior_value = value; } diff --git a/projects/mtg/src/StyleManager.cpp b/projects/mtg/src/StyleManager.cpp new file mode 100644 index 000000000..3ca68619d --- /dev/null +++ b/projects/mtg/src/StyleManager.cpp @@ -0,0 +1,146 @@ +#include "../include/config.h" +#include "../include/GameApp.h" +#include "../include/GuiBackground.h" +#include "../include/GameObserver.h" +#include "../include/Rules.h" +#include "../include/DeckDataWrapper.h" +#include "../include/WFilter.h" +#include "../include/StyleManager.h" +#include "../../../JGE/src/tinyxml/tinyxml.h" + +void StyleManager::killRules(){ + activeStyle = ""; + vector::iterator i; + for(i=rules.begin();i!=rules.end();i++) + SAFE_DELETE(*i); + rules.clear(); + + map::iterator mi; + for(mi=styles.begin();mi!=styles.end();mi++){ + SAFE_DELETE(mi->second); + } + styles.clear(); +} + +StyleManager::StyleManager(){ + loadRules(); +} + +StyleManager::~StyleManager(){ + killRules(); +} + + +string WStyle::stylized(string filename){ + if(mapping.find(filename) != mapping.end()) + return mapping[filename]; + return filename; +} +void StyleManager::loadRules(){ + killRules(); + //TODO Placeholder until XML format available. + string filename = RESPATH"/" + resources.graphicsFile("style.txt"); + TiXmlDocument xmlfile(filename.c_str()); + if(!xmlfile.LoadFile()) + return; + TiXmlHandle hDoc(&xmlfile); + TiXmlElement * pRule; + for(pRule = hDoc.FirstChildElement().Element();pRule!=NULL;pRule=pRule->NextSiblingElement()){ + //root should be "pack" + string tag = pRule->Value(); + std::transform(tag.begin(),tag.end(),tag.begin(),::tolower); + if(tag == "activebg"){ + //After validating, handle actual loading. + TiXmlElement * pSlot; + const char * holder = NULL; + holder = pRule->Attribute("source"); + if(holder) playerSrc = atoi(holder); else playerSrc = -1; + + for (pSlot=pRule->FirstChildElement();pSlot!=NULL;pSlot=pSlot->NextSiblingElement()){ + //Load slot. + tag = pSlot->Value(); + std::transform(tag.begin(),tag.end(),tag.begin(),::tolower); + if(tag != "case") continue; + + WStyleRule * r = NEW WStyleRule(); + rules.push_back(r); + + holder = pSlot->Attribute("rule"); + if(holder) r->filter = holder; + r->style = pSlot->GetText(); + } + } else if(tag == "style"){ + TiXmlElement * pSlot; + const char * holder = NULL; + holder = pRule->Attribute("name"); + if(!holder) continue; + string sname = holder; + WStyle * s = NEW WStyle(); + + for (pSlot=pRule->FirstChildElement();pSlot!=NULL;pSlot=pSlot->NextSiblingElement()){ + + tag = pSlot->Value(); + std::transform(tag.begin(),tag.end(),tag.begin(),::tolower); + if(tag.size() && pSlot->GetText()) + s->mapping[tag] = pSlot->GetText(); + } + if(styles[sname]) SAFE_DELETE(styles[sname]); + styles[sname] = s; + + + } + } + + determineActive(NULL,NULL); + return; +} + +WStyle * StyleManager::get() { + if(styles.find(activeStyle) != styles.end()) + return styles[activeStyle]; + return NULL; +}; +void StyleManager::determineActive(MTGDeck * p1, MTGDeck * p2) +{ + string check = options[Options::GUI_STYLE].str; + if(check.size() && styles.find(check) != styles.end()){ + string prior = activeStyle; + activeStyle = check; + if(prior != activeStyle) + resources.Refresh(); + return; + } + topRule = -1; topSize = 0; + + MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection); + if(p1 && playerSrc != 2) tempDeck->add(p1); + if(p2 && playerSrc != 1) tempDeck->add(p2); + WCFilterFactory * ff = WCFilterFactory::GetInstance(); + + if(tempDeck){ + DeckDataWrapper * ddw = NEW DeckDataWrapper(tempDeck); + for(int r=0;r<(int)rules.size();r++){ + ddw->clearFilters(); + ddw->addFilter(ff->Construct(rules[r]->filter)); + ddw->validate(); + int ct = ddw->getCount(WSrcDeck::FILTERED_COPIES); + if(ct > topSize) { + topRule = r; + topSize = ct; + } + } + delete tempDeck; + delete ddw; + } + + string prior = activeStyle; + activeStyle = ""; + if(topRule >= 0){ + map::iterator mi = styles.find(rules[topRule]->style); + if(mi != styles.end()) + activeStyle = mi->first; + } + if(prior != activeStyle) + resources.Refresh(); + +} \ No newline at end of file diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 7c4cb0448..c04c490eb 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -6,6 +6,7 @@ #include "../include/GuiCombat.h" #include "../include/Rules.h" #include "../include/GameObserver.h" +#include "../include/GameStateShop.h" #include using std::string; @@ -297,7 +298,6 @@ void TestSuite::initGame(){ } OutputDebugString("TESTUITE Init Game Done !\n"); } - int TestSuite::Log(const char * text){ ofstream file (RESPATH"/test/results.html",ios_base::app); if (file){ @@ -582,3 +582,17 @@ int TestSuite::load(const char * _filename){ return 1; } + +void TestSuite::pregameTests(){ + //Test Booster Generation + srand(1024); + char result[1024]; + ShopBooster sb; + for(int i=0;i<5;i++){ + nbTests++; + sprintf(result, "

pregame/BoosterTest#%i

", i); + Log(result); + if(!sb.unitTest()) + nbFailed++; + } +} \ No newline at end of file diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index e3851df6c..5eb739b21 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -9,6 +9,7 @@ #include #include #include "../include/WResourceManager.h" +#include "../include/StyleManager.h" #if defined (WIN32) #include #include @@ -515,6 +516,16 @@ string WResourceManager::graphicsFile(const string filename){ //Check the theme folder. string theme = options[Options::ACTIVE_THEME].str; + //Check for a theme style renaming: + if(filename != "style.txt"){ + WStyle * ws = options.getStyle(); + if(ws){ + sprintf(buf,"themes/%s/%s",theme.c_str(),ws->stylized(filename).c_str()); + if(fileOK(buf,true)) + return buf; + } + } + if(theme != "" && theme != "Default"){ sprintf(buf,"themes/%s/%s",theme.c_str(),filename.c_str()); if(fileOK(buf,true)) diff --git a/projects/mtg/template.vcproj b/projects/mtg/template.vcproj index e3ef4f331..d90ca00bd 100644 --- a/projects/mtg/template.vcproj +++ b/projects/mtg/template.vcproj @@ -768,6 +768,10 @@ RelativePath=".\src\StoryFlow.cpp" > + + @@ -1165,6 +1169,10 @@ RelativePath=".\include\StoryFlow.h" > + +