diff --git a/projects/mtg/include/CardSelector.h b/projects/mtg/include/CardSelector.h index b49583228..d602517d9 100644 --- a/projects/mtg/include/CardSelector.h +++ b/projects/mtg/include/CardSelector.h @@ -59,6 +59,7 @@ class ObjectSelector : public GuiLayer void Add(T*); void Remove(T*); bool CheckUserInput(JButton key); + bool CheckUserInput(int x, int y); void Update(float dt); void Render(); void Push(); diff --git a/projects/mtg/include/MenuItem.h b/projects/mtg/include/MenuItem.h index c4c82290c..24f1a6565 100644 --- a/projects/mtg/include/MenuItem.h +++ b/projects/mtg/include/MenuItem.h @@ -39,6 +39,7 @@ class MenuItem: public JGuiObject virtual void Entering(); virtual bool Leaving(JButton key); virtual bool ButtonPressed(); + virtual bool getTopLeft(int& top, int& left) {top = mY; left = mX; return true;}; virtual ostream& toString(ostream& out) const; }; diff --git a/projects/mtg/include/SimpleMenuItem.h b/projects/mtg/include/SimpleMenuItem.h index 5a6ea93f8..abc9bda50 100644 --- a/projects/mtg/include/SimpleMenuItem.h +++ b/projects/mtg/include/SimpleMenuItem.h @@ -42,6 +42,7 @@ class SimpleMenuItem: public JGuiObject virtual bool Leaving(JButton key); virtual bool ButtonPressed(); virtual ostream& toString(ostream& out) const; + virtual bool getTopLeft(int& top, int& left) {top = mY; left = mX; return true;}; }; #endif diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index 1b4093e83..6c9c46027 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -167,6 +167,43 @@ bool CardSelector::CheckUserInput(JButton key) return true; } + +template<> +bool CardSelector::CheckUserInput(int x, int y) +{ + if (!active) { + for (vector::iterator it = cards.begin(); it != cards.end(); ++it) + if ((NULL == limitor) || (limitor->select(*it))) { + active = *it; + active->Entering(); + return true; + } + return true; + } + Target* oldactive = active; + active = closest(cards, limitor, x, y); + + 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 = fetchMemory(lasts[owner])) + if (old) active = old; + } + lasts[oldowner] = SelectorMemory(oldactive); + } + } + if (active != oldactive) { + { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0f; } + { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4f; } + if (oldactive) oldactive->Leaving(JGE_BTN_NONE); + if (active) active->Entering(); + } + return true; +} + template<> void CardSelector::Update(float dt) { float boundary = duel->RightBoundary(); diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index bd11e01ec..49cc0321a 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -58,16 +58,26 @@ void DuelLayers::init(){ void DuelLayers::CheckUserInput(int isAI){ JButton key; - while ((key = JGE::GetInstance()->ReadButton())){ + int x, y; + while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + { if ((!isAI) && (0 != key)) + { + if (stack->CheckUserInput(key)) break; + if (combat->CheckUserInput(key)) break; + if (avatars->CheckUserInput(key)) break; //avatars need to check their input before action (CTRL_CROSS) + if (action->CheckUserInput(key)) break; + if (hand->CheckUserInput(key)) break; + if (cs->CheckUserInput(key)) break; + } + else if((!isAI) && (x != -1 && y != -1)) + { + if (cs->CheckUserInput(x, y)) { - if (stack->CheckUserInput(key)) break; - if (combat->CheckUserInput(key)) break; - if (avatars->CheckUserInput(key)) break; //avatars need to check their input before action (CTRL_CROSS) - if (action->CheckUserInput(key)) break; - if (hand->CheckUserInput(key)) break; - if (cs->CheckUserInput(key)) break; + JGE::GetInstance()->LeftClickedProcessed(); + break; } + } } }