diff --git a/projects/mtg/include/GameStateAwards.h b/projects/mtg/include/GameStateAwards.h index 0649ba1b2..cb614895c 100644 --- a/projects/mtg/include/GameStateAwards.h +++ b/projects/mtg/include/GameStateAwards.h @@ -35,6 +35,7 @@ public: virtual void Update(float dt); virtual void Render(); virtual void ButtonPressed(int controllerId, int controlId); + virtual void OnScroll(int inXVelocity, int inYVelocity); }; #endif diff --git a/projects/mtg/include/WGui.h b/projects/mtg/include/WGui.h index cf7d64b77..2e89a85af 100644 --- a/projects/mtg/include/WGui.h +++ b/projects/mtg/include/WGui.h @@ -857,8 +857,11 @@ public: virtual void ButtonPressed(int controllerId, int controlId); virtual void setData(); WGuiBase * operator[](int); + virtual bool CheckUserInput(JButton key); protected: bool mFocus; + int startWindow; + int endWindow; }; /** diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index 31df962bd..7a17230eb 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -177,7 +177,7 @@ void GameStateAwards::Update(float dt) { JButton key = JGE_BTN_NONE; int x, y; - while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x,y)) + while ((key = JGE::GetInstance()->ReadButton())) { switch (key) { @@ -388,3 +388,17 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId) } } } + +void GameStateAwards::OnScroll(int inXVelocity, int inYVelocity) +{ + if (abs(inYVelocity) > 300) + { + bool flickUpwards = (inYVelocity < 0); + int velocity = (inYVelocity < 0) ? (-1 * inYVelocity) : inYVelocity; + while(velocity > 0) + { + mEngine->HoldKey_NoRepeat(flickUpwards ? JGE_BTN_DOWN : JGE_BTN_UP); + velocity -= 100; + } + } +} diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index 04a2e5bcd..f1b5c6226 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -360,10 +360,11 @@ void WGuiList::Render() //Render items. if (start >= 0) { + int pos; //Render current underlay. if (currentItem >= 0 && currentItem < nbitems && items[currentItem]->Visible()) items[currentItem]->Underlay(); - for (int pos = 0; pos < nbitems; pos++) + for (pos = 0; pos < nbitems; pos++) { if (!items[pos]->Visible()) continue; @@ -386,6 +387,9 @@ void WGuiList::Render() break; } + startWindow = start; + endWindow = pos; + //Draw scrollbar if (listHeight > SCREEN_HEIGHT && listSelectable > 1) { @@ -418,6 +422,41 @@ void WGuiList::ButtonPressed(int controllerId, int controlId) it->ButtonPressed(controllerId, controlId); } +bool WGuiList::CheckUserInput(JButton key) +{ + JGE * mEngine = JGE::GetInstance(); + int i, j; + + if ((key == JGE_BTN_OK) && mEngine->GetLeftClickCoordinates(i, j)) + { // a dude clicked somwhere, we're gonna select the closest object from where he clicked + int n = currentItem; + unsigned int distance2; + unsigned int minDistance2 = -1; + for(int k = startWindow; k < endWindow; k++) + { + WGuiItem* pItem = (WGuiItem*)items[k]; + distance2 = static_cast((pItem->getY() - j) * (pItem->getY() - j) + (pItem->getX() - i) * (pItem->getX() - i)); + if (distance2 < minDistance2 && pItem->Selectable()) + { + minDistance2 = distance2; + n = k; + } + } + + if (n != currentItem && items[n]->Selectable()) + { + setSelected(n); + mEngine->LeftClickedProcessed(); + if (sync) syncMove(); + return true; + } + } + + mEngine->LeftClickedProcessed(); + return WGuiMenu::CheckUserInput(key); +} + + string WDecoEnum::lookupVal(int value) { @@ -927,12 +966,12 @@ bool WGuiMenu::CheckUserInput(JButton key) if (!mEngine->GetButtonState(held)) //Key isn't held down. held = JGE_BTN_NONE; - if (mEngine->GetLeftClickCoordinates(i, j)) + if ((key == JGE_BTN_OK) && mEngine->GetLeftClickCoordinates(i, j)) { // a dude clicked somwhere, we're gonna select the closest object from where he clicked int n = currentItem; unsigned int distance2; unsigned int minDistance2 = -1; - for(size_t k = 0; k < items.size(); k++) + for(int k = 0; k >= items.size(); k++) { WGuiItem* pItem = (WGuiItem*)items[k]; distance2 = static_cast((pItem->getY() - j) * (pItem->getY() - j) + (pItem->getX() - i) * (pItem->getX() - i));