From 8a4797a06a55fc2d4faee938ed8af2ed7a9904f3 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sat, 13 Mar 2010 07:25:07 +0000 Subject: [PATCH] Erwan - quick patch for i379 --- projects/mtg/include/GameStateDuel.h | 2 +- projects/mtg/include/GameStateMenu.h | 1 + projects/mtg/src/GameStateDuel.cpp | 28 +++++++++++-------- projects/mtg/src/GameStateMenu.cpp | 41 +++++++++++++++++----------- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/projects/mtg/include/GameStateDuel.h b/projects/mtg/include/GameStateDuel.h index 3a5c7ccaa..32bae5e39 100644 --- a/projects/mtg/include/GameStateDuel.h +++ b/projects/mtg/include/GameStateDuel.h @@ -38,7 +38,7 @@ class GameStateDuel: public GameState, public JGuiListener bool MusicExist(string FileName); void loadPlayer(int playerId, int decknb = 0, int isAI = 0); - + void ensureOpponentMenu(); //loads the opponentMenu if it doesn't exist public: GameStateDuel(GameApp* parent); diff --git a/projects/mtg/include/GameStateMenu.h b/projects/mtg/include/GameStateMenu.h index 2291cc150..28a6d0d11 100644 --- a/projects/mtg/include/GameStateMenu.h +++ b/projects/mtg/include/GameStateMenu.h @@ -49,6 +49,7 @@ class GameStateMenu: public GameState, public JGuiListener void runTest(); //!! void listPrimitives(); void genNbCardsStr(); //computes the contents of nbCardsStr + void ensureMGuiController(); //creates the MGuiController if it doesn't exist public: GameStateMenu(GameApp* parent); virtual ~GameStateMenu(); diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 8a2ce4976..dd8bc0452 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -213,6 +213,16 @@ bool GameStateDuel::MusicExist(string FileName){ return false; } +void GameStateDuel::ensureOpponentMenu(){ + if (!opponentMenu){ + opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Constants::MENU_FONT, 35, 25, "Choose Opponent"); + opponentMenu->Add(0,"Random"); + if (options[Options::EVILTWIN_MODE_UNLOCKED].number) + opponentMenu->Add(-1,"Evil Twin", "Can you play against yourself?"); + fillDeckMenu(opponentMenu,RESPATH"/ai/baka", "ai_baka", mPlayers[0]); + } +} + void GameStateDuel::Update(float dt) { switch (mGamePhase) @@ -270,13 +280,7 @@ void GameStateDuel::Update(float dt) deckmenu->Update(dt); else{ if (mParent->players[0] == PLAYER_TYPE_HUMAN){ - if (!opponentMenu){ - opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Constants::MENU_FONT, 35, 25, "Choose Opponent"); - opponentMenu->Add(0,"Random"); - if (options[Options::EVILTWIN_MODE_UNLOCKED].number) - opponentMenu->Add(-1,"Evil Twin", "Can you play against yourself?"); - fillDeckMenu(opponentMenu,RESPATH"/ai/baka", "ai_baka", mPlayers[0]); - } + ensureOpponentMenu(); opponentMenu->Update(dt); }else{ loadPlayer(1); @@ -286,14 +290,14 @@ void GameStateDuel::Update(float dt) break; case DUEL_STATE_CHOOSE_DECK2_TO_PLAY: if (mParent->players[1] == PLAYER_TYPE_HUMAN){ - if (deckmenu->closed) mGamePhase = DUEL_STATE_PLAY; - else deckmenu->Update(dt); + if (deckmenu->closed) mGamePhase = DUEL_STATE_PLAY; + else deckmenu->Update(dt); } - else - { + else{ + ensureOpponentMenu(); if (opponentMenu->closed) mGamePhase = DUEL_STATE_PLAY; else opponentMenu->Update(dt); - } + } break; case DUEL_STATE_PLAY: if (!game){ diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index d45010d4f..127a0402f 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -10,7 +10,7 @@ #include "../include/PlayerData.h" #include "../include/utils.h" -static const char* GAME_VERSION = "WTH?! 0.11.0 - by wololo"; +static const char* GAME_VERSION = "WTH?! 0.11.1 - by wololo"; #define DEFAULT_ANGLE_MULTIPLIER 0.4 #define MAX_ANGLE_MULTIPLIER (3*M_PI) @@ -100,7 +100,7 @@ void GameStateMenu::Create() } } - currentState = MENU_STATE_MAJOR_LOADING_CARDS | MENU_STATE_MINOR_NONE; + currentState = MENU_STATE_MAJOR_LOADING_CARDS; bool langChosen = false; string lang = options[Options::LANG].str; if (lang.size()){ @@ -340,6 +340,20 @@ void GameStateMenu::listPrimitives(){ primitivesLoadCounter = 0; } +void GameStateMenu::ensureMGuiController(){ + if (!mGuiController) { + mGuiController = NEW JGuiController(100, this); + if (mGuiController) { + JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT); + mFont->SetColor(ARGB(255,255,255,255)); + mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"particle1.psi",resources.GetQuad("particles"), true)); + mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"particle2.psi",resources.GetQuad("particles"))); + mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"particle3.psi",resources.GetQuad("particles"))); + mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"particle4.psi",resources.GetQuad("particles"))); + mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"particle5.psi",resources.GetQuad("particles"))); + } + } +} void GameStateMenu::Update(float dt) { @@ -414,25 +428,16 @@ void GameStateMenu::Update(float dt) break; case MENU_STATE_MAJOR_MAINMENU : if (!scrollerSet) fillScroller(); - if (!mGuiController) { - mGuiController = NEW JGuiController(100, this); - if (mGuiController) { - JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT); - mFont->SetColor(ARGB(255,255,255,255)); - mGuiController->Add(NEW MenuItem(MENUITEM_PLAY, mFont, "Play", 80, 50 + SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"particle1.psi",resources.GetQuad("particles"), true)); - mGuiController->Add(NEW MenuItem(MENUITEM_DECKEDITOR, mFont, "Deck Editor", 160, 50 + SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"particle2.psi",resources.GetQuad("particles"))); - mGuiController->Add(NEW MenuItem(MENUITEM_SHOP, mFont, "Shop", 240, 50 + SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"particle3.psi",resources.GetQuad("particles"))); - mGuiController->Add(NEW MenuItem(MENUITEM_OPTIONS, mFont, "Options", 320, 50 + SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"particle4.psi",resources.GetQuad("particles"))); - mGuiController->Add(NEW MenuItem(MENUITEM_EXIT, mFont, "Exit", 400, 50 + SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"particle5.psi",resources.GetQuad("particles"))); - } - } + ensureMGuiController(); if (mGuiController) mGuiController->Update(dt); if(mEngine->GetButtonState(JGE_BTN_NEXT)) //Hook for GameStateAward state mParent->DoTransition(TRANSITION_FADE,GAME_STATE_AWARDS); //TODO: A slide transition would be nice. break; case MENU_STATE_MAJOR_SUBMENU : - subMenuController->Update(dt); + if (subMenuController) + subMenuController->Update(dt); + ensureMGuiController(); mGuiController->Update(dt); break; case MENU_STATE_MAJOR_DUEL : @@ -464,6 +469,10 @@ void GameStateMenu::Update(float dt) switch (MENU_STATE_MINOR & currentState){ case MENU_STATE_MINOR_SUBMENU_CLOSING : + if (!subMenuController){ //http://code.google.com/p/wagic/issues/detail?id=379 + currentState &= ~MENU_STATE_MINOR_SUBMENU_CLOSING; + break; + } if (subMenuController->closed) { SAFE_DELETE(subMenuController); currentState &= ~MENU_STATE_MINOR_SUBMENU_CLOSING; @@ -540,7 +549,7 @@ void GameStateMenu::Render() }; renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors); - if (mGuiController!=NULL) + if (mGuiController) mGuiController->Render(); mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);