diff --git a/projects/mtg/include/CardDisplay.h b/projects/mtg/include/CardDisplay.h index d224bc22a..ff9108b78 100644 --- a/projects/mtg/include/CardDisplay.h +++ b/projects/mtg/include/CardDisplay.h @@ -21,6 +21,7 @@ class CardDisplay:public PlayGuiObjectController{ void rotateLeft(); void rotateRight(); bool CheckUserInput(JButton key); + bool CheckUserInput(int x, int y); virtual void Update(float dt); void Render(); void init(MTGGameZone * zone); diff --git a/projects/mtg/include/GuiAvatars.h b/projects/mtg/include/GuiAvatars.h index 6798ee967..f94a2203f 100644 --- a/projects/mtg/include/GuiAvatars.h +++ b/projects/mtg/include/GuiAvatars.h @@ -30,6 +30,7 @@ class GuiAvatars : public GuiLayer int receiveEventPlus(WEvent*); int receiveEventMinus(WEvent*); bool CheckUserInput(JButton key); + bool CheckUserInput(int x, int y); float LeftBoundarySelf(); }; diff --git a/projects/mtg/include/GuiStatic.h b/projects/mtg/include/GuiStatic.h index 24defead6..ed211373d 100644 --- a/projects/mtg/include/GuiStatic.h +++ b/projects/mtg/include/GuiStatic.h @@ -44,6 +44,7 @@ struct GuiGameZone : public GuiStatic{ int showCards; virtual void Render(); virtual bool CheckUserInput(JButton key); + virtual bool CheckUserInput(int x, int y); virtual void Update(float dt); GuiGameZone(float x, float y, bool hasFocus, MTGGameZone * zone, GuiAvatars* parent); ~GuiGameZone(); diff --git a/projects/mtg/include/PlayGuiObject.h b/projects/mtg/include/PlayGuiObject.h index 469d97f32..eb073fc4c 100644 --- a/projects/mtg/include/PlayGuiObject.h +++ b/projects/mtg/include/PlayGuiObject.h @@ -34,6 +34,7 @@ class PlayGuiObject: public JGuiObject, public JGuiListener, public Pos{ PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus); PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus); virtual void ButtonPressed(int controllerId, int controlId){}; + virtual bool getTopLeft(int& top, int& left) {top = actY; left = actX; return true;}; virtual ~PlayGuiObject(){}; vector effects; }; diff --git a/projects/mtg/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index 85993d638..09e646ee6 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -77,68 +77,121 @@ void CardDisplay::Update(float dt){ if (update) init(zone); } -bool CardDisplay::CheckUserInput(JButton key){ - if (JGE_BTN_SEC == key || JGE_BTN_PRI == key) +bool CardDisplay::CheckUserInput(int x, int y) { + unsigned int distance2; + unsigned int minDistance2 = -1; + int n = mCurr; + JButton key; + if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + { + for(int i = 0; i < mCount; i++) { - if (listener){ - listener->ButtonPressed(mId, 0); - return true; + int top, left; + if(mObjects[i]->getTopLeft(top, left)) + { + distance2 = (top-y)*(top-y) + (left-x)*(left-x); + if(distance2 < minDistance2) + { + minDistance2 = distance2; + n = i; + } } } + if(n < mCurr) + key = JGE_BTN_LEFT; + else + key = JGE_BTN_RIGHT; + + if (n= mCount) { + n = mCount-1; + } + if (n>= start_item + nb_displayed_items) { + rotateRight(); + } + + if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key)) + { + mCurr = n; + mObjects[mCurr]->Entering(); + } + JGE::GetInstance()->LeftClickedProcessed(); + return true; + } + + return false; +} + + +bool CardDisplay::CheckUserInput(JButton key){ + if (JGE_BTN_SEC == key || JGE_BTN_PRI == key) + { + if (listener){ + listener->ButtonPressed(mId, 0); + return true; + } + } + if (!mCount) return false; if (mActionButton == key) - { - if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){ - CardGui * cardg = (CardGui *)mObjects[mCurr]; - if (tc) - { - tc->toggleTarget(cardg->card); - return true; - }else{ - if (game) game->ButtonPressed(cardg); - return true; - } + { + if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){ + CardGui * cardg = (CardGui *)mObjects[mCurr]; + if (tc) { + tc->toggleTarget(cardg->card); + return true; + } else { + if (game) game->ButtonPressed(cardg); + return true; } - return true; } + return true; + } switch(key) - { - case JGE_BTN_LEFT : - { - int n = mCurr; - n--; - if (nLeaving(JGE_BTN_LEFT)){ - mCurr = n; - mObjects[mCurr]->Entering(); - } - return true; + { + case JGE_BTN_LEFT : + { + int n = mCurr; + n--; + if (n= mCount){n = mCount-1;} - if (n>= start_item + nb_displayed_items){ - rotateRight(); - } - if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){ - mCurr = n; - mObjects[mCurr]->Entering(); - } - } - return true; - default: - ; } + if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){ + mCurr = n; + mObjects[mCurr]->Entering(); + } + return true; + } + case JGE_BTN_RIGHT : + { + int n = mCurr; + n++; + if (n>= mCount) { + n = mCount-1; + } + if (n>= start_item + nb_displayed_items) { + rotateRight(); + } + if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){ + mCurr = n; + mObjects[mCurr]->Entering(); + } + } + return true; + default: + ; + } + return false; } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index a99e6351d..d2d10216e 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -73,7 +73,11 @@ void DuelLayers::CheckUserInput(int isAI){ } if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) { - if (cs->CheckUserInput(x, y)) + if (avatars->CheckUserInput(x, y)) + { + JGE::GetInstance()->LeftClickedProcessed(); + } + else if (cs->CheckUserInput(x, y)) { JGE::GetInstance()->LeftClickedProcessed(); } diff --git a/projects/mtg/src/GuiAvatars.cpp b/projects/mtg/src/GuiAvatars.cpp index 5594266a5..9af776f0e 100644 --- a/projects/mtg/src/GuiAvatars.cpp +++ b/projects/mtg/src/GuiAvatars.cpp @@ -80,6 +80,17 @@ bool GuiAvatars::CheckUserInput(JButton key){ return false; } +bool GuiAvatars::CheckUserInput(int x, int y){ +// if (self->CheckUserInput(key)) return true; +// if (opponent->CheckUserInput(key)) return true; + if (selfGraveyard->CheckUserInput(x, y)) return true; + if (opponentGraveyard->CheckUserInput(x, y)) return true; + if (opponentHand->CheckUserInput(x, y)) return true; + if (selfLibrary->CheckUserInput(x, y)) return true; + if (opponentLibrary->CheckUserInput(x, y)) return true; + return false; +} + void GuiAvatars::Update(float dt) { self->Update(dt); diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index 5dbd0117c..5cfbb8298 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -180,6 +180,11 @@ bool GuiGameZone::CheckUserInput(JButton key){ return false; } +bool GuiGameZone::CheckUserInput(int x, int y){ + if (showCards) return cd->CheckUserInput(x, y); + return false; +} + void GuiGameZone::Update(float dt){ if (showCards) cd->Update(dt); PlayGuiObject::Update(dt);