diff --git a/projects/mtg/Makefile b/projects/mtg/Makefile index e9a7dd3f9..c7c89b5f5 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/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardSelector.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.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/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.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/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/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/SimplePad.o objs/Token.o objs/Translate.o objs/utils.o objs/WEvent.o objs/WResourceManager.o +OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardSelector.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.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/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.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/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/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/SimplePad.o objs/Token.o objs/Translate.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) diff --git a/projects/mtg/include/Trash.h b/projects/mtg/include/Trash.h new file mode 100644 index 000000000..53193b157 --- /dev/null +++ b/projects/mtg/include/Trash.h @@ -0,0 +1,21 @@ +#ifndef _TRASH_H_ +#define _TRASH_H_ + +#include +#include "Pos.h" +#include "WEvent.h" + +void trash(Pos*); + +class Trash +{ + std::vector bin; + void put_out(); + int receiveEvent(WEvent* e); + friend void trash(Pos*); + + public: + static void cleanup(); +}; + +#endif // _TRASH_H_ diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 61bb4a49b..ce96a335c 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -51,17 +51,18 @@ void CardGui::Render() if (game) tc = game->getCurrentTargetChooser(); JQuad * quad = resources.RetrieveCard(card,CACHE_THUMB); + JQuad* shadow = resources.GetQuad("shadow"); if (quad) { const float scale = actZ * 40 / quad->mHeight; - renderer->RenderQuad(resources.GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale); + renderer->RenderQuad(shadow, actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale); quad->SetColor(ARGB(static_cast(actA),255,255,255)); renderer->RenderQuad(quad, actX, actY, actT, scale, scale); } else { const float scale = actZ; - renderer->RenderQuad(resources.GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale); - + shadow->SetColor(ARGB(static_cast(actA),255,255,255)); + renderer->RenderQuad(shadow, actX + scale*2, actY + scale*2, actT, 28*scale, 40*scale); mFont->SetColor(ARGB(static_cast(actA), 0, 0, 0)); JQuad * icon = NULL; @@ -86,7 +87,11 @@ void CardGui::Render() mFont->SetScale(DEFAULT_MAIN_FONT_SCALE * 0.5 * actZ); mFont->DrawString(card->getName().c_str(), actX - actZ * Width / 2 + 1, actY - actZ * Height / 2 + 1); if (icon) { icon->SetColor(ARGB(static_cast(actA),255,255,255)); renderer->RenderQuad(icon, actX, actY, 0); } - if (tc && !tc->canTarget(card)) renderer->FillRect(actX - actZ*Width/2, actY - actZ*Height/2, actZ*Width, actZ*Height, ARGB((static_cast(actA*0.75)),0,0,0)); + if (tc && !tc->canTarget(card)) + { + shadow->SetColor(ARGB(static_cast(actA),128,92,92)); + renderer->RenderQuad(shadow, actX, actY, actT, 28*scale, 40*scale); + } mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 7e013176b..06a67bd61 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -1,5 +1,4 @@ #include "../include/config.h" -#include "../include/DuelLayers.h" #include "../include/MTGRules.h" #include "../include/GuiCombat.h" #include "../include/GuiBackground.h" @@ -9,6 +8,8 @@ #include "../include/GuiHand.h" #include "../include/GuiPlay.h" #include "../include/GuiMana.h" +#include "../include/Trash.h" +#include "../include/DuelLayers.h" void DuelLayers::init(){ @@ -78,9 +79,9 @@ DuelLayers::DuelLayers() : nbitems(0) {} DuelLayers::~DuelLayers(){ for (int i = 0; i < nbitems; ++i) delete objects[i]; - for (size_t i = 0; i < waiters.size(); ++i){ + for (size_t i = 0; i < waiters.size(); ++i) delete(waiters[i]); - } + Trash::cleanup(); } int DuelLayers::unstoppableRenderInProgress(){ @@ -150,6 +151,11 @@ int DuelLayers::receiveEvent(WEvent * e){ } for (int i = 0; i < nbitems; ++i) objects[i]->receiveEventMinus(e); + + if (WEventPhaseChange *event = dynamic_cast(e)) + if (Constants::MTG_PHASE_BEFORE_BEGIN == event->to->id) + Trash::cleanup(); + return 1; } diff --git a/projects/mtg/src/GuiHand.cpp b/projects/mtg/src/GuiHand.cpp index 4a58cf261..8d38beba0 100644 --- a/projects/mtg/src/GuiHand.cpp +++ b/projects/mtg/src/GuiHand.cpp @@ -1,5 +1,6 @@ #include "../include/config.h" #include "../include/GameApp.h" +#include "../include/Trash.h" #include "../include/GuiHand.h" const float GuiHand::ClosedRowX = 459; @@ -164,7 +165,7 @@ int GuiHandSelf::receiveEventMinus(WEvent* e) cs->Remove(cv); Repos(); cards.erase(it); - delete cv; + trash(cv); return 1; } return 1; @@ -198,7 +199,7 @@ int GuiHandOpponent::receiveEventMinus(WEvent* e) { CardView* cv = *it; cards.erase(it); - delete cv; + trash(cv); return 1; } return 0; diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index 65566d002..8aef5f37c 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -1,6 +1,7 @@ #include "../include/config.h" #include "../include/GameApp.h" #include "../include/GuiPlay.h" +#include "../include/Trash.h" #define CARD_WIDTH (31) @@ -219,8 +220,7 @@ int GuiPlay::receiveEventMinus(WEvent * e) CardView* cv = *it; cs->Remove(cv); cards.erase(it); - cv->card->view = NULL; - delete cv; + trash(cv); Replace(); return 1; } diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index 76b3282bb..b15de068a 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -1,4 +1,5 @@ #include "../include/config.h" +#include "../include/Trash.h" #include "../include/GuiStatic.h" GuiStatic::GuiStatic(float desiredHeight, float x, float y, bool hasFocus, GuiAvatars* parent) : PlayGuiObject(desiredHeight, x, y, hasFocus), parent(parent) {} @@ -162,7 +163,7 @@ int GuiGraveyard::receiveEventPlus(WEvent* e) t = NEW CardView(event->card, *(event->card->view)); else t = NEW CardView(event->card, x, y); - t->x = x + Width / 2; t->y = y + Height / 2; t->zoom = 0.3; t->alpha = 0; + t->x = x + Width / 2; t->y = y + Height / 2; t->zoom = 0.6; t->alpha = 0; cards.push_back(t); return 1; } @@ -178,7 +179,7 @@ int GuiGraveyard::receiveEventMinus(WEvent* e) { CardView* cv = *it; cards.erase(it); - delete cv; + trash(cv); return 1; } return 0; diff --git a/projects/mtg/src/Trash.cpp b/projects/mtg/src/Trash.cpp new file mode 100644 index 000000000..16ab46538 --- /dev/null +++ b/projects/mtg/src/Trash.cpp @@ -0,0 +1,30 @@ +#include +#include "../include/MTGDefinitions.h" +#include "../include/Pos.h" +#include "../include/CardGui.h" +#include "../include/Trash.h" + +void Trash::put_out() +{ + for (std::vector::iterator it = bin.begin(); it != bin.end(); ++it) + { + std::cout << "DELETE " << *it << std::endl; + if (CardView *c = dynamic_cast(*it)) + SAFE_DELETE(c); + else + SAFE_DELETE(*it); + } + bin.clear(); +} + +static Trash PosTrash; + +void Trash::cleanup() +{ + PosTrash.put_out(); +} + +void trash(Pos* garbage) +{ + PosTrash.bin.push_back(garbage); +}