From c55c9c25071af5e8a0d62d664b915e7edf1b9491 Mon Sep 17 00:00:00 2001 From: Vittorio Alfieri Date: Sun, 14 Nov 2021 14:24:27 +0100 Subject: [PATCH] Fixed primitives, improved background images management for game settings, deck selection, deck editor background, post-match credits, deck editor selection and trophies room (now it's possibile to randomly use up to 3 background images and if the chosen image is not available, it will be rendered the default one). --- CHANGELOG.md | 7 +++- projects/mtg/bin/Res/sets/primitives/mtg.txt | 6 ++-- projects/mtg/src/Credits.cpp | 26 +++++++++++++-- projects/mtg/src/DeckEditorMenu.cpp | 14 ++++++++ projects/mtg/src/DeckMenu.cpp | 2 +- projects/mtg/src/GameStateAwards.cpp | 19 +++++++++-- projects/mtg/src/GameStateDeckViewer.cpp | 35 ++++++++++++++++---- projects/mtg/src/GameStateDuel.cpp | 26 +++++++++++++-- projects/mtg/src/GameStateOptions.cpp | 28 ++++++++++++++-- 9 files changed, 144 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4785bb463..d95a6d077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,13 @@ ## [master] (https://github.com/WagicProject/wagic/tree/master) +### 14/11/21 +- *Committed:* Fixed primitives, improved background images management for game settings, deck selection, deck editor background, post-match credits, deck editor selection and trophies room (now it's possibile to randomly use up to 3 background images and if the chosen image is not available, it will be rendered the default one). ([Vitty85](https://github.com/Vitty85)) + +- *Committed:* Fixed primitives, several bugs and crashes. https://github.com/WagicProject/wagic/commit/96f7072a77f566718fc49c2bfe3b0b192452faf6 ([EduardoMunozGomez](https://github.com/EduardoMunozGomez)) + ### 13/11/21 -- *Committed:* Fixed VOW set, added new AI deck, improved Android downloader for VOC and VOW sets. ([Vitty85](https://github.com/Vitty85)) +- *Committed:* Fixed VOW set, added new AI deck, improved Android downloader for VOC and VOW sets. https://github.com/WagicProject/wagic/commit/9957719e0c3e2467fd12039c213d54f151664fdd ([Vitty85](https://github.com/Vitty85)) ### 11/11/21 - *Committed:* Fixed VOW and VOC sets, improved Android downloader for VOC and VOW sets. https://github.com/WagicProject/wagic/commit/8b91048d124be38bbb845c47c00857ce5a32cdac ([Vitty85](https://github.com/Vitty85)) diff --git a/projects/mtg/bin/Res/sets/primitives/mtg.txt b/projects/mtg/bin/Res/sets/primitives/mtg.txt index 5f06a31e0..c4fd2cdc5 100644 --- a/projects/mtg/bin/Res/sets/primitives/mtg.txt +++ b/projects/mtg/bin/Res/sets/primitives/mtg.txt @@ -53740,8 +53740,8 @@ toughness=0 [card] name=Helix Pinnacle abilities=shroud -auto={X}:thisforeach(X) all(this) counter(0/0,1,Tower) -auto=@each my upkeep restriction{{type(helix pinnacle[counter{0/0.100.Tower}]|myBattlefield)~morethan~0}}:winGame +auto={X}:name(Put X counters) thisforeach(X) all(this) counter(0/0,1,Tower) +auto=@each my upkeep restriction{compare(hascnttower)~morethan~99}:name(You win the game) winGame controller text=Shroud -- {X}: Put X tower counters on Helix Pinnacle. -- At the beginning of your upkeep, if there are 100 or more tower counters on Helix Pinnacle, you win the game. mana={G} type=Enchantment @@ -125390,7 +125390,7 @@ toughness=6 [card] name=Ulrich's Kindred abilities=trample -auto={3}{G}:target(*[wolf;werewolf;attacking]) indestructible ueot +auto={3}{G}:name(Gains indestructible) target(*[wolf;werewolf;attacking]) indestructible ueot text=Trample -- {3}{G}: Target attacking Wolf or Werewolf gains indestructible until end of turn. mana={2}{R} type=Creature diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index 19d7c1153..7ceedcc48 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -142,6 +142,8 @@ void CreditBonus::Render(float x, float y, WFont * font) font->DrawString(buffer, x, y); } +static std::string kBgFile = ""; + Credits::Credits() { unlocked = -1; @@ -163,6 +165,7 @@ Credits::~Credits() if (bonus[i]) delete bonus[i]; bonus.clear(); + kBgFile = ""; //Reset the chosen backgorund. } void Credits::compute(GameObserver* g, GameApp * _app) @@ -514,10 +517,29 @@ void Credits::Render() return; JRenderer * r = JRenderer::GetInstance(); #if !defined (PSP) - JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture("bgdeckeditor.jpg"); + //Now it's possibile to randomly use up to 3 background images for post-match credits (if random index is 0, it will be rendered the default "bgdeckeditor.jpg" image). + JTexture * wpTex = NULL; + if(kBgFile == ""){ + char temp[4096]; + sprintf(temp, "bgdeckeditor%i.jpg", std::rand() % 3); + kBgFile.assign(temp); + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); + if (wpTex) { + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); + if (wpQuad.get()) + r->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); + else { + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for post-match credits. + wpTex = NULL; + } + } else + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for post-match credits. + } + if(!wpTex) + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); if (wpTex) { - JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad("bgdeckeditor.jpg"); + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); r->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); } #else diff --git a/projects/mtg/src/DeckEditorMenu.cpp b/projects/mtg/src/DeckEditorMenu.cpp index 790f6476d..08858d668 100644 --- a/projects/mtg/src/DeckEditorMenu.cpp +++ b/projects/mtg/src/DeckEditorMenu.cpp @@ -10,7 +10,21 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const string& _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats) : DeckMenu(id, listener, fontId, _title), selectedDeck(_selectedDeck), stw(stats) { +#if !defined (PSP) + //Now it's possibile to randomly use up to 3 background images for deck editor selection (if random index is 0, it will be rendered the default "menubgdeckeditor.jpg" image). + ostringstream bgFilename; + char temp[4096]; + sprintf(temp, "menubgdeckeditor%i", std::rand() % 3); + backgroundName.assign(temp); + bgFilename << backgroundName << ".jpg"; + JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad(bgFilename.str(), TEXTURE_SUB_5551); + if (!background.get()){ + backgroundName = "menubgdeckeditor"; //Fallback to default background image for deck editor selection. + } +#else backgroundName = "menubgdeckeditor"; +#endif + mShowDetailsScreen = false; deckTitle = selectedDeck ? selectedDeck->parent->meta_name : ""; diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index f598a43a4..510e182e0 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -151,7 +151,7 @@ void DeckMenu::RenderBackground() { ostringstream bgFilename; #if !defined (PSP) - if(backgroundName == "menubgdeckeditor") + if(backgroundName.find("menubgdeckeditor") != string::npos) //Now it's possibile to randomly use up to 3 background images for deck editor selection. bgFilename << backgroundName << ".jpg"; else bgFilename << backgroundName << ".png"; diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index 21e43e263..6b2839af5 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -27,6 +27,8 @@ namespace GameStateAwardsConst const int kBackToMainMenuID = 1; } +static std::string kAwardFile = ""; + GameStateAwards::GameStateAwards(GameApp* parent) : GameState(parent, "trophies") { @@ -35,7 +37,7 @@ GameStateAwards::GameStateAwards(GameApp* parent) : GameStateAwards::~GameStateAwards() { - + kAwardFile = ""; //Reset the chosen backgorund. } void GameStateAwards::End() @@ -47,6 +49,8 @@ void GameStateAwards::End() if (saveMe) options.save(); + + kAwardFile = ""; //Reset the chosen backgorund. } void GameStateAwards::Start() { @@ -168,7 +172,18 @@ void GameStateAwards::Render() #if defined (PSP) JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad("pspawardback.jpg", TEXTURE_SUB_5551); #else - JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad("awardback.jpg", TEXTURE_SUB_5551); + //Now it's possibile to randomly use up to 3 background images for trophies room (if random index is 0, it will be rendered the default "awardback.jpg" image). + JQuadPtr background; + if(kAwardFile == ""){ + char temp[4096]; + sprintf(temp, "awardback%i.jpg", std::rand() % 3); + kAwardFile.assign(temp); + JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad(kAwardFile); + if (!background.get()) + kAwardFile = "awardback.jpg"; //Fallback to default background image for trophies room. + } + background = WResourceManager::Instance()->RetrieveTempQuad(kAwardFile, TEXTURE_SUB_5551); + //JQuadPtr background = WResourceManager::Instance()->RetrieveTempQuad("awardback.jpg", TEXTURE_SUB_5551); #endif if (background.get()) diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 27439125c..18c747235 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -28,6 +28,8 @@ #define NO_USER_ACTIVITY_HELP_DELAY 10 +static std::string kBgFile = ""; + GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) : GameState(parent, "deckeditor"), mView(NULL), mCurrentView(CAROUSEL_VIEW) { @@ -102,6 +104,7 @@ GameStateDeckViewer::~GameStateDeckViewer() SAFE_DELETE(myCollection); } SAFE_DELETE(filterMenu); + kBgFile = ""; //Reset the chosen backgorund. } void GameStateDeckViewer::rebuildFilters() @@ -303,6 +306,7 @@ void GameStateDeckViewer::End() SAFE_DELETE(playerdata); SAFE_DELETE(filterMenu); SAFE_DELETE(source); + kBgFile = ""; //Reset the chosen backgorund. } void GameStateDeckViewer::addRemove(MTGCard * card) @@ -1570,13 +1574,32 @@ void GameStateDeckViewer::Render() WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); #if !defined (PSP) - JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture("bgdeckeditor.jpg"); + //Now it's possibile to randomly use up to 3 background images for deck editor background (if random index is 0, it will be rendered the default "bgdeckeditor.jpg" image). + JTexture * wpTex = NULL; + if(kBgFile == ""){ + char temp[4096]; + sprintf(temp, "bgdeckeditor%i.jpg", std::rand() % 3); + kBgFile.assign(temp); + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); + if (wpTex) { + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); + if (wpQuad.get()) + JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); + else { + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for deck editor background. + wpTex = NULL; + } + } else + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for deck editor background. + } + if(!wpTex) + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); if (wpTex) { - JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad("bgdeckeditor.jpg"); + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); - }/* - if (mView->deck() == myDeck && mStage != STAGE_MENU) + } + /*if (mView->deck() == myDeck && mStage != STAGE_MENU) renderDeckBackground();*/ #else JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture("pspbgdeckeditor.jpg"); @@ -1584,8 +1607,8 @@ void GameStateDeckViewer::Render() { JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad("pspbgdeckeditor.jpg"); JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); - }/* - if (mView->deck() == myDeck && mStage != STAGE_MENU) + } + /*if (mView->deck() == myDeck && mStage != STAGE_MENU) renderDeckBackground();*/ #endif mView->Render(); diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 9c6e1be7e..74cff64f5 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -133,6 +133,7 @@ enum ENUM_OPERATION_LEVELS int GameStateDuel::selectedPlayerDeckId = 0; int GameStateDuel::selectedAIDeckId = 0; +static std::string kBgFile = ""; GameStateDuel::GameStateDuel(GameApp* parent) : GameState(parent, "duel") @@ -181,6 +182,7 @@ GameStateDuel::~GameStateDuel() { End(); SAFE_DELETE(tournament); + kBgFile = ""; //Reset the chosen backgorund. } void GameStateDuel::Start() @@ -370,6 +372,7 @@ void GameStateDuel::End() #endif MTGAbility::deletedpointers.clear(); // Clear the list of deallocated pointer. + kBgFile = ""; //Reset the chosen backgorund. } //TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that? @@ -1084,10 +1087,29 @@ void GameStateDuel::Render() JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); } #else - JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture("bgdeckeditor.jpg"); + //Now it's possibile to randomly use up to 3 background images for deck selection (if random index is 0, it will be rendered the default "bgdeckeditor.jpg" image). + JTexture * wpTex = NULL; + if(kBgFile == ""){ + char temp[4096]; + sprintf(temp, "bgdeckeditor%i.jpg", std::rand() % 3); + kBgFile.assign(temp); + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); + if (wpTex) { + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); + if (wpQuad.get()) + JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); + else { + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for deck selection. + wpTex = NULL; + } + } else + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for deck selection. + } + if(!wpTex) + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); if (wpTex) { - JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad("bgdeckeditor.jpg"); + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); } #endif diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 47788bad1..8722ad448 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -16,12 +16,16 @@ namespace GameStateOptionsConst const int kReloadID = 5; } +static std::string kBgFile = ""; + GameStateOptions::GameStateOptions(GameApp* parent) : GameState(parent, "options"), mReload(false), grabber(NULL), optionsMenu(NULL), optionsTabs(NULL) { } + GameStateOptions::~GameStateOptions() { + kBgFile = ""; //Reset the chosen backgorund. } void GameStateOptions::Start() @@ -153,6 +157,7 @@ void GameStateOptions::End() JRenderer::GetInstance()->EnableVSync(false); SAFE_DELETE(optionsTabs); SAFE_DELETE(optionsMenu); + kBgFile = ""; //Reset the chosen backgorund. } void GameStateOptions::Update(float dt) @@ -237,10 +242,29 @@ void GameStateOptions::Render() //Erase JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); #if !defined (PSP) - JTexture * wpTex = WResourceManager::Instance()->RetrieveTexture("bgdeckeditor.jpg"); + //Now it's possibile to randomly use up to 3 background images for game settings (if random index is 0, it will be rendered the default "bgdeckeditor.jpg" image). + JTexture * wpTex = NULL; + if(kBgFile == ""){ + char temp[4096]; + sprintf(temp, "bgdeckeditor%i.jpg", std::rand() % 3); + kBgFile.assign(temp); + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); + if (wpTex) { + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); + if (wpQuad.get()) + JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); + else { + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for game settings. + wpTex = NULL; + } + } else + kBgFile = "bgdeckeditor.jpg"; //Fallback to default background image for game settings. + } + if(!wpTex) + wpTex = WResourceManager::Instance()->RetrieveTexture(kBgFile); if (wpTex) { - JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad("bgdeckeditor.jpg"); + JQuadPtr wpQuad = WResourceManager::Instance()->RetrieveTempQuad(kBgFile); JRenderer::GetInstance()->RenderQuad(wpQuad.get(), 0, 0, 0, SCREEN_WIDTH_F / wpQuad->mWidth, SCREEN_HEIGHT_F / wpQuad->mHeight); } #else