From ed865ce29abe71408b7058b72fe780c37bcb22aa Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 26 Sep 2010 08:41:25 +0000 Subject: [PATCH] Erwan - Fix for issue 371 (Deck Editor resets to letter "A") - Changed music behavior when switching menus. It shouldn't "restart" the music anymore. --- projects/mtg/include/GameApp.h | 1 + projects/mtg/include/GameStateDeckViewer.h | 3 ++ projects/mtg/src/GameApp.cpp | 5 ++ projects/mtg/src/GameStateDeckViewer.cpp | 53 +++++++++++++++++----- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/projects/mtg/include/GameApp.h b/projects/mtg/include/GameApp.h index 7d3310892..ed8ba42fc 100644 --- a/projects/mtg/include/GameApp.h +++ b/projects/mtg/include/GameApp.h @@ -87,6 +87,7 @@ class GameApp: public JApp static int HasMusic; static string systemError; static JMusic* music; + static string currentMusicFile; static void playMusic(string filename, bool loop = true); static MTGAllCards * collection; static int players[2]; diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index fcfdb6fa1..c0894afd7 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -138,6 +138,8 @@ private: int useFilter; JMusic * bgMusic; JQuad * backQuad; + int lastPos; + int lastTotal; WGuiFilters * filterMenu; WSrcDeckViewer * source; @@ -157,6 +159,7 @@ private: StatsWrapper stw; bool mSwitching; void saveDeck(); //Saves the deck and additional necessary information + int getCurrentPos(); public: GameStateDeckViewer(GameApp* parent); diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index be841f089..64750044d 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -30,6 +30,7 @@ MTGAllCards * GameApp::collection = NULL; int GameApp::players[] = {0,0}; int GameApp::HasMusic = 1; JMusic * GameApp::music = NULL; +string GameApp::currentMusicFile = ""; string GameApp::systemError = ""; JQuad* manaIcons[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; @@ -437,6 +438,9 @@ void GameApp::DoAnimation(int trans, float dur){ } void GameApp::playMusic(string filename, bool loop) { + if (filename.compare(currentMusicFile) == 0) + return; + if (music) { JSoundSystem::GetInstance()->StopMusic(music); SAFE_DELETE(music); @@ -445,5 +449,6 @@ void GameApp::playMusic(string filename, bool loop) { if (HasMusic && options[Options::MUSICVOLUME].number > 0){ music = resources.ssLoadMusic(filename.c_str()); if (music) JSoundSystem::GetInstance()->PlayMusic(music, loop); + currentMusicFile = filename; } } diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index ae1f659c1..c110a856f 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -72,6 +72,13 @@ void GameStateDeckViewer::rotateCards(int direction){ else displayed_deck->prev(); loadIndexes(); + + int total = displayed_deck->Size(); + if (total) { + lastPos = getCurrentPos(); + lastTotal = total; + } + int i = 0; } void GameStateDeckViewer::rebuildFilters(){ if(!filterMenu) filterMenu = NEW WGuiFilters("Filter by...",NULL); @@ -84,13 +91,29 @@ void GameStateDeckViewer::rebuildFilters(){ } void GameStateDeckViewer::updateFilters(){ if(!displayed_deck) return; + filterMenu->recolorFilter(useFilter-1); filterMenu->Finish(true); + int totalAfter = displayed_deck->Size(); + if (totalAfter && lastTotal) { + + //This part is a hack. I don't understand why in some cases "displayed_deck's" currentPos is not 0 at this stage + { + while (int currentPos = displayed_deck->getOffset()) { + if (currentPos > 0) displayed_deck->prev(); + else displayed_deck->next(); + } + } + + int pos = (totalAfter * lastPos) / lastTotal ; + for (int i = 0; i < pos - 3 ; ++i){ // "-3" because card "0" is displayed at position 3 initially + displayed_deck->next(); + } + } updateStats(); return; } void GameStateDeckViewer::loadIndexes(){ - int x=0; for (int i = 0; i < 7; i++){ cardIndex[i] = displayed_deck->getCard(i); } @@ -140,6 +163,8 @@ void GameStateDeckViewer::Start() last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; onScreenTransition = 0; useFilter = 0; + lastPos = 0; + lastTotal = 0; pricelist = NEW PriceList(RESPATH"/settings/prices.dat",mParent->collection); playerdata = NEW PlayerData(mParent->collection); @@ -462,30 +487,37 @@ void GameStateDeckViewer::renderOnScreenBasicInfo(){ JRenderer::GetInstance()->RenderQuad(mIcons[useFilter-1], SCREEN_WIDTH-10 , y + 10 , 0.0f,0.5,0.5); } +//returns position of the current card (cusor) in the currently viewed color/filter +int GameStateDeckViewer::getCurrentPos() { + int total = displayed_deck->Size(); + + int currentPos = displayed_deck->getOffset(); + currentPos+= 2; //we start by displaying card number 3 + currentPos = currentPos % total + 1; + if (currentPos <0) currentPos = (total + currentPos); + if (!currentPos) currentPos = total; + return currentPos; +} void GameStateDeckViewer::renderSlideBar(){ WFont * mFont = resources.GetWFont(Constants::MAIN_FONT); int total = displayed_deck->Size(); + if(total == 0) + return; + float filler = 15; float y = SCREEN_HEIGHT_F-25; float bar_size = SCREEN_WIDTH_F - 2*filler; JRenderer * r = JRenderer::GetInstance(); - int currentPos = displayed_deck->getOffset(); - if(total == 0) - return; + int currentPos = getCurrentPos(); - currentPos+= 2; //we start by displaying card number 3 - currentPos = currentPos % total + 1; - if (currentPos <0) currentPos = (total + currentPos); - if (!currentPos) currentPos = total; float cursor_pos = bar_size * currentPos / total; r->FillRoundRect(filler + 5,y+5,bar_size,0,3,ARGB(hudAlpha/2,0,0,0)); r->DrawLine(filler+cursor_pos + 5 ,y+5,filler+cursor_pos + 5,y+10,ARGB(hudAlpha/2,0,0,0)); r->FillRoundRect(filler,y,bar_size,0,3,ARGB(hudAlpha/2,128,128,128)); - //r->FillCircle(filler+cursor_pos + 3 ,SCREEN_HEIGHT - 15 + 3,6,ARGB(255,128,128,128)); r->DrawLine(filler+cursor_pos,y,filler+cursor_pos,y+5,ARGB(hudAlpha,255,255,255)); char buffer[256]; string deckname = _("Collection"); @@ -1337,7 +1369,6 @@ int GameStateDeckViewer::loadDeck(int deckid){ stw.pageCount = 9; stw.needUpdate = true; - //string profile = options[Options::ACTIVE_PROFILE].str; if(!playerdata) playerdata = NEW PlayerData(mParent->collection); SAFE_DELETE(myCollection); @@ -1345,8 +1376,6 @@ int GameStateDeckViewer::loadDeck(int deckid){ myCollection->Sort(WSrcCards::SORT_ALPHA); displayed_deck = myCollection; - //SAFE_DELETE(myCollection); - //myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection)); displayed_deck = myCollection; char deckname[256]; sprintf(deckname,"deck%i.txt",deckid);