Fixed trophy card selection and scrolling with mouse and touch.

This commit is contained in:
Xawotihs
2011-09-06 21:08:25 +00:00
parent 98709e661e
commit c3d2b60a67
4 changed files with 61 additions and 4 deletions

View File

@@ -35,6 +35,7 @@ public:
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(); virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
virtual void OnScroll(int inXVelocity, int inYVelocity);
}; };
#endif #endif

View File

@@ -857,8 +857,11 @@ public:
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
virtual void setData(); virtual void setData();
WGuiBase * operator[](int); WGuiBase * operator[](int);
virtual bool CheckUserInput(JButton key);
protected: protected:
bool mFocus; bool mFocus;
int startWindow;
int endWindow;
}; };
/** /**

View File

@@ -177,7 +177,7 @@ void GameStateAwards::Update(float dt)
{ {
JButton key = JGE_BTN_NONE; JButton key = JGE_BTN_NONE;
int x, y; int x, y;
while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x,y)) while ((key = JGE::GetInstance()->ReadButton()))
{ {
switch (key) 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;
}
}
}

View File

@@ -360,10 +360,11 @@ void WGuiList::Render()
//Render items. //Render items.
if (start >= 0) if (start >= 0)
{ {
int pos;
//Render current underlay. //Render current underlay.
if (currentItem >= 0 && currentItem < nbitems && items[currentItem]->Visible()) items[currentItem]->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; if (!items[pos]->Visible()) continue;
@@ -386,6 +387,9 @@ void WGuiList::Render()
break; break;
} }
startWindow = start;
endWindow = pos;
//Draw scrollbar //Draw scrollbar
if (listHeight > SCREEN_HEIGHT && listSelectable > 1) if (listHeight > SCREEN_HEIGHT && listSelectable > 1)
{ {
@@ -418,6 +422,41 @@ void WGuiList::ButtonPressed(int controllerId, int controlId)
it->ButtonPressed(controllerId, 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<unsigned int>((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) string WDecoEnum::lookupVal(int value)
{ {
@@ -927,12 +966,12 @@ bool WGuiMenu::CheckUserInput(JButton key)
if (!mEngine->GetButtonState(held)) //Key isn't held down. if (!mEngine->GetButtonState(held)) //Key isn't held down.
held = JGE_BTN_NONE; 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 { // a dude clicked somwhere, we're gonna select the closest object from where he clicked
int n = currentItem; int n = currentItem;
unsigned int distance2; unsigned int distance2;
unsigned int minDistance2 = -1; 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]; WGuiItem* pItem = (WGuiItem*)items[k];
distance2 = static_cast<unsigned int>((pItem->getY() - j) * (pItem->getY() - j) + (pItem->getX() - i) * (pItem->getX() - i)); distance2 = static_cast<unsigned int>((pItem->getY() - j) * (pItem->getY() - j) + (pItem->getX() - i) * (pItem->getX() - i));