From 218db9d844792740daa5167a8886f3a13ddeff90 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Fri, 23 Mar 2012 13:17:13 +0000 Subject: [PATCH] improved scrolling of simple menus. Now you can scroll up as well as down by activating the area above/below the menu items removed the buttons when displaying the filter menus. --- JGE/src/JGui.cpp | 2 ++ projects/mtg/src/GameStateShop.cpp | 4 +++- projects/mtg/src/SimpleMenu.cpp | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/JGE/src/JGui.cpp b/JGE/src/JGui.cpp index c3db3e991..11c6cf38f 100644 --- a/JGE/src/JGui.cpp +++ b/JGE/src/JGui.cpp @@ -181,6 +181,8 @@ bool JGuiController::CheckUserInput(JButton key) minDistance2 = distance2; n = i; } + else + break; } } diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index 356afec53..730e17b5e 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -723,6 +723,7 @@ void GameStateShop::Render() if (shopMenu) shopMenu->Render(); + if (filterMenu && !filterMenu->isFinished()) filterMenu->Render(); else @@ -790,7 +791,8 @@ void GameStateShop::Render() if (menu) menu->Render(); - renderButtons(); + if (filterMenu && filterMenu->isFinished()) + renderButtons(); } void GameStateShop::ButtonPressed(int controllerId, int controlId) diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 1c37e2ab6..6e923b0a2 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -240,25 +240,35 @@ bool SimpleMenu::CheckUserInput(JButton key) if (mObjects.size()) { float top, left; + SimpleMenuItem * currentItem = static_cast(mObjects[mCurr]); + float fontHeight = WResourceManager::Instance()->GetWFont(currentItem->getFontId())->GetHeight(); + float menuTopEdge = fontHeight + mY + spadeR->mHeight; + float menuBottomEdge = menuTopEdge + (maxItems * fontHeight); for (int i = 0; i < mCount; i++) { if (mObjects[i]->getTopLeft(top, left)) { distance2 = (unsigned int)((top - y) * (top - y) + (left - x) * (left - x)); - if ( (distance2 < minDistance2) ) + if ( (distance2 <= minDistance2) ) { minDistance2 = distance2; - n = i; - } - else if (y > mHeight) // this will scroll downwards in a list. - { - if (mCurr < mCount-1) - n = mCurr + 1; + if (y < menuTopEdge) + { + n = (mCurr - 1) > 0 ? mCurr - 1 : 0; + break; + } + else if (y > menuBottomEdge) + { + n = (mCurr + 1) < mCount ? mCurr + 1 : mCount - 1; + break; + } + else + n = i; } } } - + // check to see if the user clicked if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN)) { mCurr = n;