diff --git a/projects/mtg/include/CardDisplay.h b/projects/mtg/include/CardDisplay.h index 30fa21c57..ac294ee9e 100644 --- a/projects/mtg/include/CardDisplay.h +++ b/projects/mtg/include/CardDisplay.h @@ -23,7 +23,6 @@ public: 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 52a2bdee6..d5f6ff29b 100644 --- a/projects/mtg/include/GuiAvatars.h +++ b/projects/mtg/include/GuiAvatars.h @@ -29,7 +29,6 @@ public: 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 a28f84cf2..9fb352a7a 100644 --- a/projects/mtg/include/GuiStatic.h +++ b/projects/mtg/include/GuiStatic.h @@ -52,7 +52,6 @@ public: 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/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index 29a8548dc..34f9e8896 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -95,59 +95,6 @@ void CardDisplay::Update(float dt) if (update) init(zone); } -bool CardDisplay::CheckUserInput(int x, int y) -{ - bool result = false; - unsigned int distance2; - unsigned int minDistance2 = -1; - int n = mCurr; - JButton key; - if (JGE::GetInstance()->GetLeftClickCoordinates(x, y)) - { - for (size_t i = 0; i < mObjects.size(); i++) - { - float top, left; - if (mObjects[i]->getTopLeft(top, left)) - { - distance2 = static_cast((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 < start_item) - { - rotateLeft(); - } - else if (n >= (int)(mObjects.size()) && mObjects.size()) - { - n = mObjects.size() - 1; - } - if (n >= start_item + nb_displayed_items) - { - rotateRight(); - } - - if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key)) - { - mCurr = n; - mObjects[mCurr]->Entering(); - result = true; - } - JGE::GetInstance()->LeftClickedProcessed(); - } - - return result; -} - bool CardDisplay::CheckUserInput(JButton key) { if (JGE_BTN_SEC == key || JGE_BTN_PRI == key || JGE_BTN_UP == key || JGE_BTN_DOWN == key) @@ -220,11 +167,62 @@ bool CardDisplay::CheckUserInput(JButton key) mCurr = n; mObjects[mCurr]->Entering(); } - } return true; - default: - ; } + default: + { + bool result = false; + unsigned int distance2; + unsigned int minDistance2 = -1; + int n = mCurr; + int x1,y1; + JButton key; + if (JGE::GetInstance()->GetLeftClickCoordinates(x1, y1)) + { + for (size_t i = 0; i < mObjects.size(); i++) + { + float top, left; + if (mObjects[i]->getTopLeft(top, left)) + { + distance2 = static_cast((top - y1) * (top - y1) + (left - x1) * (left - x1)); + if (distance2 < minDistance2) + { + minDistance2 = distance2; + n = i; + } + } + } + + if (n < mCurr) + key = JGE_BTN_LEFT; + else + key = JGE_BTN_RIGHT; + + if (n < start_item) + { + rotateLeft(); + } + else if (n >= (int)(mObjects.size()) && mObjects.size()) + { + n = mObjects.size() - 1; + } + if (n >= start_item + nb_displayed_items) + { + rotateRight(); + } + + if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key)) + { + mCurr = n; + mObjects[mCurr]->Entering(); + result = true; + } + JGE::GetInstance()->LeftClickedProcessed(); + } + return result; + } + } + return false; } diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index 5284a13c5..1fa3cc2d0 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -214,7 +214,17 @@ bool CardSelector::CheckUserInput(JButton key) options[Options::DISABLECARDS].number = 0; return true; default: - return false; + { + int x,y; + if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + { + active = closest (cards, limitor, static_cast (x), static_cast (y)); + } + else + { + return false; + } + } } if (active != oldactive) { diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 72bd97e18..974117cd6 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -66,34 +66,36 @@ void DuelLayers::CheckUserInput(int isAI) { JButton key; int x, y; - while ((key = JGE::GetInstance()->ReadButton())) + while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x, y)) { - if ((!isAI) && (0 != key)) + if ((!isAI) && ((0 != key) || JGE::GetInstance()->GetLeftClickCoordinates(x, y))) { - if (stack->CheckUserInput(key)) + if (stack->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; - if (combat->CheckUserInput(key)) + } + if (combat->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; - if (avatars->CheckUserInput(key)) + } + if (avatars->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; //avatars need to check their input before action (CTRL_CROSS) - if (action->CheckUserInput(key)) + } + if (action->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; - if (hand->CheckUserInput(key)) + } + if (hand->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; - if (CardSelectorSingleton::Instance()->CheckUserInput(key)) + } + if (CardSelectorSingleton::Instance()->CheckUserInput(key)) { + JGE::GetInstance()->LeftClickedProcessed(); break; + } } - } - if ((!isAI) && JGE::GetInstance()->GetLeftClickCoordinates(x, y)) - { - if (avatars->CheckUserInput(x, y)) - { - JGE::GetInstance()->LeftClickedProcessed(); - } - else if (CardSelectorSingleton::Instance()->CheckUserInput(x, y)) - { - JGE::GetInstance()->LeftClickedProcessed(); - } + JGE::GetInstance()->LeftClickedProcessed(); } } diff --git a/projects/mtg/src/GuiAvatars.cpp b/projects/mtg/src/GuiAvatars.cpp index ab672de56..a2911a004 100644 --- a/projects/mtg/src/GuiAvatars.cpp +++ b/projects/mtg/src/GuiAvatars.cpp @@ -115,23 +115,6 @@ 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 0fda6ed12..64824cf39 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -199,13 +199,6 @@ 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)