diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index 320043cbd..ac02397bc 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -40,6 +40,7 @@ public: SimpleMenu(JGE*, int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7, bool centerHorizontal = true, bool centerVertical = true); virtual ~SimpleMenu(); virtual void Render(); + virtual bool CheckUserInput(JButton key); virtual void Update(float dt); virtual void Add(int id, const char * Text, string desc = "", bool forceFocus = false); int getmCurr(){return mCurr;} diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index e31ca1bed..d75947186 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -101,7 +101,6 @@ void SimpleMenu::drawVertPole(float x, float y, float height) { JRenderer* renderer = JRenderer::GetInstance(); - float xOffset = (spadeR->mWidth - kPoleWidth) / 2; float topYOffset = xOffset; float bottomYOffset = xOffset; @@ -213,12 +212,78 @@ void SimpleMenu::Render() mFont->SetScale(SCALE_NORMAL); } +bool SimpleMenu::CheckUserInput(JButton key) +{ + // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked + int x = -1, y = -1; + unsigned int distance2; + unsigned int minDistance2 = -1; + int n = mCurr; + + if ((key == JGE_BTN_NONE) && mEngine->GetLeftClickCoordinates(x, y)) + { + + // first scan the buttons on the screen and then process the other gui elements + for (size_t i = 0; i < mButtons.size(); i++) + { + if (mButtons[i]->ButtonPressed()) + { + mEngine->LeftClickedProcessed(); + return true; + } + } + + if (mObjects.size()) + { + float top, left; + + for (int i = 0; i < mCount; i++) + { + if (mObjects[i]->getTopLeft(top, left)) + { + distance2 = (top - y) * (top - y) + (left - x) * (left - x); + if ( (distance2 < minDistance2) ) + { + minDistance2 = distance2; + n = i; + } + else if (y > mHeight) // this will scroll downwards in a list. + { + n = mCurr + 1; + } + } + } + + if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN)) + { + mCurr = n; + mObjects[mCurr]->Entering(); + } + // if the same object was selected process click + else if (n == mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_OK)) + { + mObjects[mCurr]->Entering(); + } + mEngine->LeftClickedProcessed(); + mEngine->ResetInput(); + return true; + } + mEngine->LeftClickedProcessed(); + } + else + return JGuiController::CheckUserInput(key); + + return false; +} + + void SimpleMenu::Update(float dt) { JGuiController::Update(dt); if (mCurr > startId + maxItems - 1) startId = mCurr - maxItems + 1; else if (mCurr < startId) startId = mCurr; + stars->Update(dt); selectionT += 3 * dt; selectionY += (selectionTargetY - selectionY) * 8 * dt; diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index 21a18d2bd..c98ff90b1 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -1854,6 +1854,7 @@ void WGuiFilters::Render() bool WGuiFilters::CheckUserInput(JButton key) { if (subMenu && !subMenu->isClosed() && subMenu->CheckUserInput(key)) return true; + if (key == JGE_BTN_SEC) {//|| key == JGE_BTN_MENU){ //TODO Pop up a "Are you sure?" dialog.