diff --git a/projects/mtg/include/GuiPlay.h b/projects/mtg/include/GuiPlay.h index 657e20f14..73e81c508 100644 --- a/projects/mtg/include/GuiPlay.h +++ b/projects/mtg/include/GuiPlay.h @@ -38,6 +38,7 @@ class GuiPlay : public GuiLayer float maxHeight; public: VertStack(float height = VERTHEIGHT); + void Render(CardView*, iterator begin, iterator end); void Enstack(CardView*); inline float nextX(); }; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 32c569274..ca6f88f17 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -63,10 +63,18 @@ class MTGCardInstance: public MTGCard, public Damageable { int typeAsTarget(){return TARGET_CARD;} const string getDisplayName() const; MTGCardInstance * target; - void addType(int type); - bool blocked; //Blocked this turn or not? + + + //types + void addType(char * type_text); + virtual void addType(int id); + void setType(const char * type_text); + void setSubtype( string value); + int removeType(string value, int removeAll = 0); + int removeType(int value, int removeAll = 0); //Combat + bool blocked; //Blocked this turn or not? MTGCardInstance * defenser; listblockers; int attacker; diff --git a/projects/mtg/include/WEvent.h b/projects/mtg/include/WEvent.h index d4916b58d..3fc988de5 100644 --- a/projects/mtg/include/WEvent.h +++ b/projects/mtg/include/WEvent.h @@ -54,6 +54,14 @@ struct WEventCardUpdate : public WEvent { WEventCardUpdate(MTGCardInstance * card); }; +//Event when a card gains/looses types +struct WEventCardChangeType : public WEventCardUpdate { + int type; + bool before; + bool after; + WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after); +}; + //Event when a card is tapped/untapped struct WEventCardTap : public WEventCardUpdate { bool before; diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index 045152f05..b9315957b 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -59,6 +59,12 @@ void GuiPlay::VertStack::Enstack(CardView* card) y += 8; } +void GuiPlay::VertStack::Render(CardView* card, iterator begin, iterator end) +{ + RenderSpell(card->card, begin, end, card->x + 5, card->y - 10); + card->Render(); +} + inline float GuiPlay::VertStack::nextX() { return x + CARD_WIDTH; } GuiPlay::BattleField::BattleField(float width) : HorzStack(width), attackers(0), blockers(0), height(0.0), red(0), colorFlow(0) {} @@ -152,20 +158,25 @@ void GuiPlay::Replace() void GuiPlay::Render() { battleField.Render(); - for (iterator it = cards.begin(); it != end_spells; ++it) - if (!(*it)->card->target) - (*it)->Render(); - for (iterator it = end_spells; it != cards.end(); ++it) - if ((*it)->card->isCreature()) + + for (iterator it = cards.begin(); it != cards.end(); ++it) + if ((*it)->card->isLand()) { - if (game->players[0] == (*it)->card->controller()) selfCreatures.Render(*it, cards.begin(), end_spells); - else opponentCreatures.Render(*it, cards.begin(), end_spells); + if (game->players[0] == (*it)->card->controller()) selfLands.Render(*it, cards.begin(), end_spells); + else opponentLands.Render(*it, cards.begin(), end_spells); } - else if ((*it)->card->isLand()) + else if ((*it)->card->isCreature()) { - if (game->players[0] == (*it)->card->controller()) selfLands.Render(*it, cards.begin(), end_spells); - else opponentLands.Render(*it, cards.begin(), end_spells); + if (game->players[0] == (*it)->card->controller()) selfCreatures.Render(*it, cards.begin(), end_spells); + else opponentCreatures.Render(*it, cards.begin(), end_spells); } + else{ + if (!(*it)->card->target) { + if (game->players[0] == (*it)->card->controller()) selfSpells.Render(*it, cards.begin(), end_spells); + else opponentSpells.Render(*it, cards.begin(), end_spells); + } + } + } void GuiPlay::Update(float dt) { @@ -214,9 +225,13 @@ int GuiPlay::receiveEventPlus(WEvent * e) return 1; } else if (WEventPhaseChange *event = dynamic_cast(e)) - { - if (Constants::MTG_PHASE_COMBATEND == event->to->id) battleField.colorFlow = -1; - } + { + if (Constants::MTG_PHASE_COMBATEND == event->to->id) battleField.colorFlow = -1; + } + else if (dynamic_cast(e)) + { + Replace(); + } return 0; } int GuiPlay::receiveEventMinus(WEvent * e) diff --git a/projects/mtg/src/MTGCard.cpp b/projects/mtg/src/MTGCard.cpp index 113f1993a..f3ca94cc8 100644 --- a/projects/mtg/src/MTGCard.cpp +++ b/projects/mtg/src/MTGCard.cpp @@ -217,7 +217,6 @@ void MTGCard::addType(char * _type_text){ } void MTGCard::setSubtype( string value){ - int id = Subtypes::subtypesList->Add(value); addType(id); } @@ -228,6 +227,7 @@ void MTGCard::addType(int id){ } +//TODO Definitely move some of these functions to MTGCardInstance. There is no reason to remove a type from an MTGCard since they represent the Database //Removes a type from the types of a given card //If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence int MTGCard::removeType(string value, int removeAll){ diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 33ab622ec..5a23ccaa9 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -114,8 +114,36 @@ const string MTGCardInstance::getDisplayName() const { } void MTGCardInstance::addType(int type){ - types[nb_types] = type; - nb_types++; + bool before = hasType(type); + MTGCard::addType(type); + WEvent * e = NEW WEventCardChangeType(this,type,before,true); + GameObserver::GetInstance()->receiveEvent(e); +} + +void MTGCardInstance::addType(char * type_text){ + setSubtype(type_text); +} + +void MTGCardInstance::setType(const char * type_text){ + setSubtype(type_text); +} + +void MTGCardInstance::setSubtype(string value){ + int id = Subtypes::subtypesList->Add(value); + addType(id); +} +int MTGCardInstance::removeType(string value,int removeAll){ + int id = Subtypes::subtypesList->Add(value); + return removeType(id,removeAll); +} + +int MTGCardInstance::removeType(int id, int removeAll){ + bool before = hasType(id); + int result = MTGCard::removeType(id,removeAll); + bool after = hasType(id); + WEvent * e = NEW WEventCardChangeType(this,id,before,after); + GameObserver::GetInstance()->receiveEvent(e); + return result; } UntapBlockers * MTGCardInstance::getUntapBlockers(){ diff --git a/projects/mtg/src/WEvent.cpp b/projects/mtg/src/WEvent.cpp index 835ab904d..46ba3a3fb 100644 --- a/projects/mtg/src/WEvent.cpp +++ b/projects/mtg/src/WEvent.cpp @@ -16,6 +16,8 @@ WEventPhaseChange::WEventPhaseChange(Phase * from, Phase * to) : WEvent(CHANGE_P WEventCardTap::WEventCardTap(MTGCardInstance * card, bool before, bool after) : WEventCardUpdate(card), before(before), after(after){} +WEventCardChangeType::WEventCardChangeType(MTGCardInstance * card, int type, bool before, bool after) : WEventCardUpdate(card), type(type), before(before), after(after){} + WEventCreatureAttacker::WEventCreatureAttacker(MTGCardInstance * card, Targetable * before, Targetable * after) : WEventCardUpdate(card), before(before), after(after){} WEventCreatureBlocker::WEventCreatureBlocker(MTGCardInstance * card, MTGCardInstance * from,MTGCardInstance * to) : WEventCardUpdate(card), before(from), after(to){}