diff --git a/projects/mtg/include/CardGui.h b/projects/mtg/include/CardGui.h index fe4cbdd57..0650d7e65 100644 --- a/projects/mtg/include/CardGui.h +++ b/projects/mtg/include/CardGui.h @@ -3,11 +3,12 @@ #ifndef _CARD_GUI_H_ #define _CARD_GUI_H_ +#include #include #include "Pos.h" #include "PlayGuiObject.h" #include "MTGCardInstance.h" -#include +#include "CardSelector.h" class MTGCardInstance; class PlayGuiObject; @@ -34,10 +35,11 @@ struct CardGui : public PlayGuiObject { class CardView : public CardGui { public: + const CardSelector::SelectorZone owner; MTGCardInstance* getCard(); // remove this when possible - CardView(MTGCardInstance* card, float x, float y); - CardView(MTGCardInstance* card, const Pos& ref); + CardView(const CardSelector::SelectorZone, MTGCardInstance* card, float x, float y); + CardView(const CardSelector::SelectorZone, MTGCardInstance* card, const Pos& ref); void Render(){CardGui::Render();}; void Render(JQuad* q){Pos::Render(q);}; virtual ostream& toString(ostream&) const; diff --git a/projects/mtg/include/CardSelector.h b/projects/mtg/include/CardSelector.h index 68e9b189a..1f8408172 100644 --- a/projects/mtg/include/CardSelector.h +++ b/projects/mtg/include/CardSelector.h @@ -22,6 +22,11 @@ struct LimitorFunctor template class ObjectSelector : public GuiLayer { + public: + typedef enum { + nullZone, handZone, playZone + } SelectorZone; + protected: vector cards; T* active; @@ -29,8 +34,7 @@ class ObjectSelector : public GuiLayer DuelLayers* duel; LimitorFunctor* limitor; Pos bigpos; - - T* handLast; T* playLast; + map lasts; public: ObjectSelector(DuelLayers*); diff --git a/projects/mtg/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index 233962f84..96a2d5ecd 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -22,7 +22,7 @@ CardDisplay::CardDisplay(int id, GameObserver* game, int _x, int _y, JGuiListene void CardDisplay::AddCard(MTGCardInstance * _card){ - CardGui * card = NEW CardView(_card, x + 5 + (mCount - start_item) * 30, y + 5); + CardGui * card = NEW CardView(CardSelector::nullZone, _card, x + 5 + (mCount - start_item) * 30, y + 5); Add(card); } diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 1c6f373fc..1eec0e5a8 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -16,7 +16,7 @@ const float CardGui::BigHeight = 285.0; CardGui::CardGui(MTGCardInstance* card, float x, float y) : PlayGuiObject(Height, x, y, false), card(card) {} CardGui::CardGui(MTGCardInstance* card, const Pos& ref) : PlayGuiObject(Height, ref, false), card(card) {} -CardView::CardView(MTGCardInstance* card, float x, float y) : CardGui(card, x, y) { +CardView::CardView(const CardSelector::SelectorZone owner, MTGCardInstance* card, float x, float y) : CardGui(card, x, y), owner(owner) { const Pos* ref = card->view; while (card) { @@ -25,7 +25,7 @@ CardView::CardView(MTGCardInstance* card, float x, float y) : CardGui(card, x, y } } -CardView::CardView(MTGCardInstance* card, const Pos& ref) : CardGui(card, ref) { +CardView::CardView(const CardSelector::SelectorZone owner, MTGCardInstance* card, const Pos& ref) : CardGui(card, ref), owner(owner) { const Pos* r = card->view; while (card) { diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index 47350f73b..32fb26ac2 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -94,7 +94,25 @@ bool CardSelector::CheckUserInput(u32 key) default: return false; } - if (active != oldactive) { oldactive->Leaving(key); active->Entering(); } + if (active != oldactive) + { + SelectorZone oldowner, owner; + if (CardView *q = dynamic_cast(oldactive)) oldowner = q->owner; else oldowner = nullZone; + if (CardView *q = dynamic_cast(active)) owner = q->owner; else owner = nullZone; + if (oldowner != owner) + { + if (nullZone != owner) + if (PlayGuiObject* old = lasts[owner]) active = old; + lasts[oldowner] = oldactive; + } + } + if (active != oldactive) + { + { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0; } + { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4; } + oldactive->Leaving(key); + active->Entering(); + } return true; } diff --git a/projects/mtg/src/Closest.cpp b/projects/mtg/src/Closest.cpp index 7403680bf..56f497b95 100644 --- a/projects/mtg/src/Closest.cpp +++ b/projects/mtg/src/Closest.cpp @@ -23,8 +23,6 @@ static inline Target* closest(vector& cards, Limitor* limitor, Target* else card = *it; } - { CardView* c = dynamic_cast(ref); if (c) c->zoom = 1.0; } - { CardView* c = dynamic_cast(card); if (c) c->zoom = 1.4; } return card; } diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index f6560f482..f325299a3 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -175,8 +175,20 @@ bool GuiCombat::CheckUserInput(u32 key) activeAtk = static_cast(active); cursor_pos = ATK; break; - case ATK : active = closest(attackers, NULL, static_cast(active)); activeAtk = static_cast(active); break; - case BLK : active = closest(activeAtk->blockers, NULL, static_cast(active)); break; + case ATK : + { + DamagerDamaged* old = active; + active = closest(attackers, NULL, static_cast(active)); activeAtk = static_cast(active); + if (old != active) { if (old) old->zoom = 1.0; if (active) active->zoom = 1.4; } + } + break; + case BLK : + { + DamagerDamaged* old = active; + active = closest(activeAtk->blockers, NULL, static_cast(active)); + if (old != active) { if (old) old->zoom = 1.0; if (active) active->zoom = 1.4; } + } + break; } break; case PSP_CTRL_RIGHT: @@ -184,10 +196,24 @@ bool GuiCombat::CheckUserInput(u32 key) { case NONE : case OK : break; - case BLK : active = closest(activeAtk->blockers, NULL, static_cast(active)); break; - case ATK : active = closest(attackers, NULL, static_cast(active)); - if (active == oldActive) { active = activeAtk = NULL; cursor_pos = OK; } - else activeAtk = static_cast(active); + case BLK : + { + DamagerDamaged* old = active; + active = closest(activeAtk->blockers, NULL, static_cast(active)); + if (old != active) { if (old) old->zoom = 1.0; if (active) active->zoom = 1.4; } + } + break; + case ATK : + { + DamagerDamaged* old = active; + active = closest(attackers, NULL, static_cast(active)); + if (active == oldActive) { active = activeAtk = NULL; cursor_pos = OK; } + else + { + if (old != active) { if (old) old->zoom = 1.0; if (active) active->zoom = 1.4; } + activeAtk = static_cast(active); + } + } break; } break; diff --git a/projects/mtg/src/GuiHand.cpp b/projects/mtg/src/GuiHand.cpp index 355f513f9..61f426bab 100644 --- a/projects/mtg/src/GuiHand.cpp +++ b/projects/mtg/src/GuiHand.cpp @@ -10,7 +10,6 @@ const float GuiHand::RightRowX = 460; const float GuiHand::OpenX = 394; const float GuiHand::ClosedX = 494; - bool HandLimitor::select(Target* t) { if (CardView* c = dynamic_cast(t)) @@ -149,9 +148,9 @@ int GuiHandSelf::receiveEventPlus(WEvent* e) { CardView* card; if (event->card->view) - card = NEW CardView(event->card, *(event->card->view)); + card = NEW CardView(CardSelector::handZone, event->card, *(event->card->view)); else - card = NEW CardView(event->card, ClosedRowX, 0); + card = NEW CardView(CardSelector::handZone, event->card, ClosedRowX, 0); card->t = 6*M_PI; cards.push_back(card); cs->Add(card); @@ -187,9 +186,9 @@ int GuiHandOpponent::receiveEventPlus(WEvent* e) { CardView* card; if (event->card->view) - card = NEW CardView(event->card, *(event->card->view)); + card = NEW CardView(CardSelector::handZone, event->card, *(event->card->view)); else - card = NEW CardView(event->card, ClosedRowX, 0); + card = NEW CardView(CardSelector::handZone, event->card, ClosedRowX, 0); card->t = -4*M_PI; card->alpha = 255; cards.push_back(card); return 1; diff --git a/projects/mtg/src/GuiPlay.cpp b/projects/mtg/src/GuiPlay.cpp index 8aef5f37c..3f2245bbb 100644 --- a/projects/mtg/src/GuiPlay.cpp +++ b/projects/mtg/src/GuiPlay.cpp @@ -176,9 +176,9 @@ int GuiPlay::receiveEventPlus(WEvent * e) { CardView * card; if (event->card->view) - card = NEW CardView(event->card, *(event->card->view)); + card = NEW CardView(CardSelector::playZone, event->card, *(event->card->view)); else - card = NEW CardView(event->card, 0, 0); + card = NEW CardView(CardSelector::playZone, event->card, 0, 0); cards.push_back(card); card->t = 0; card->alpha = 255; cs->Add(card); diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index b15de068a..7e7b48f0d 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -160,9 +160,9 @@ int GuiGraveyard::receiveEventPlus(WEvent* e) { CardView* t; if (event->card->view) - t = NEW CardView(event->card, *(event->card->view)); + t = NEW CardView(CardSelector::nullZone, event->card, *(event->card->view)); else - t = NEW CardView(event->card, x, y); + t = NEW CardView(CardSelector::nullZone, event->card, x, y); t->x = x + Width / 2; t->y = y + Height / 2; t->zoom = 0.6; t->alpha = 0; cards.push_back(t); return 1;