Add a buttonMode to grid view to enable it on pointerless devices.

This commit is contained in:
Tobias Loose
2013-12-08 09:11:44 +01:00
parent bdd0e6c042
commit 12c5f31562
7 changed files with 156 additions and 44 deletions

View File

@@ -27,7 +27,9 @@ public:
void Render(); void Render();
bool ButtonPressed(Buttons button);
MTGCard * Click(int x, int y); MTGCard * Click(int x, int y);
MTGCard * Click();
void changePosition(int offset); void changePosition(int offset);
void changeFilter(int offset); void changeFilter(int offset);

View File

@@ -42,7 +42,8 @@ public:
virtual void Render() = 0; virtual void Render() = 0;
virtual MTGCard * Click(int x, int y) = 0; virtual MTGCard * Click(int x, int y) = 0;
bool ButtonPressed(Buttons button); virtual MTGCard * Click() = 0;
virtual bool ButtonPressed(Buttons button) = 0;
virtual MTGCard *getActiveCard() = 0; virtual MTGCard *getActiveCard() = 0;
virtual void changePosition(int offset) = 0; virtual void changePosition(int offset) = 0;
virtual void changeFilter(int offset) = 0; virtual void changeFilter(int offset) = 0;

View File

@@ -20,7 +20,9 @@ public:
void UpdateCardPosition(CardRep &rep, int index); void UpdateCardPosition(CardRep &rep, int index);
void Render(); void Render();
bool ButtonPressed(Buttons button);
MTGCard * Click(int x, int y); MTGCard * Click(int x, int y);
MTGCard * Click();
void changePosition(int offset); void changePosition(int offset);
void changeFilter(int offset); void changeFilter(int offset);
@@ -33,6 +35,9 @@ private:
InOutQuadEasing mScrollEasing; InOutQuadEasing mScrollEasing;
InOutQuadEasing mSlideEasing; InOutQuadEasing mSlideEasing;
int mCurrentSelection; int mCurrentSelection;
bool mButtonMode;
void moveSelection(int offset, bool alignIfOutOfBounds);
}; };
#endif //_GRID_DECK_VIEW_H #endif //_GRID_DECK_VIEW_H

View File

@@ -118,6 +118,31 @@ void CarouselDeckView::Render()
} }
} }
bool CarouselDeckView::ButtonPressed(Buttons button)
{
switch(button)
{
case JGE_BTN_LEFT:
changePosition(-1);
last_user_activity = 0;
break;
case JGE_BTN_RIGHT:
changePosition(1);
last_user_activity = 0;
break;
case JGE_BTN_UP:
changeFilter(1);
last_user_activity = 0;
break;
case JGE_BTN_DOWN:
changeFilter(-1);
last_user_activity = 0;
break;
default:
return false;
}
return true;
}
MTGCard * CarouselDeckView::Click(int x, int y) MTGCard * CarouselDeckView::Click(int x, int y)
{ {
int n = getCardIndexNextTo(x, y); int n = getCardIndexNextTo(x, y);
@@ -139,6 +164,18 @@ MTGCard * CarouselDeckView::Click(int x, int y)
return NULL; return NULL;
} }
MTGCard *CarouselDeckView::Click()
{
if(mSlideEasing.finished() && mScrollEasing.finished())
{
return getActiveCard();
}
else
{
return NULL;
}
}
void CarouselDeckView::changePosition(int offset) void CarouselDeckView::changePosition(int offset)
{ {
mScrollEasing.start((float)offset, (float)(0.3f*abs(offset))); mScrollEasing.start((float)offset, (float)(0.3f*abs(offset)));

View File

@@ -41,32 +41,6 @@ void DeckView::Update(float dt)
} }
} }
bool DeckView::ButtonPressed(Buttons button)
{
switch(button)
{
case JGE_BTN_LEFT:
changePosition(-1);
last_user_activity = 0;
break;
case JGE_BTN_RIGHT:
changePosition(1);
last_user_activity = 0;
break;
case JGE_BTN_UP:
changeFilter(1);
last_user_activity = 0;
break;
case JGE_BTN_DOWN:
changeFilter(-1);
last_user_activity = 0;
break;
default:
return false;
}
return true;
}
void DeckView::SetDeck(DeckDataWrapper *toShow) void DeckView::SetDeck(DeckDataWrapper *toShow)
{ {
mCurrentDeck = toShow; mCurrentDeck = toShow;

View File

@@ -443,19 +443,21 @@ void GameStateDeckViewer::Update(float dt)
int x, y; int x, y;
if (mEngine->GetLeftClickCoordinates(x, y)) if (mEngine->GetLeftClickCoordinates(x, y))
{ {
last_user_activity = 0;
mEngine->LeftClickedProcessed(); mEngine->LeftClickedProcessed();
if(mView->Click(x, y) == mView->getActiveCard()) if(mView->Click(x, y) != NULL)
{ {
addRemove(mView->getActiveCard()); addRemove(mView->getActiveCard());
} }
} }
else else
{ {
last_user_activity = 0; if(mView->Click() != NULL)
{
addRemove(mView->getActiveCard()); addRemove(mView->getActiveCard());
} }
}
last_user_activity = 0;
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
break; break;
} }
@@ -468,6 +470,8 @@ void GameStateDeckViewer::Update(float dt)
buildEditorMenu(); buildEditorMenu();
break; break;
case JGE_BTN_CTRL: case JGE_BTN_CTRL:
if(!mView->ButtonPressed(JGE_BTN_CTRL))
{
mStage = STAGE_FILTERS; mStage = STAGE_FILTERS;
if (!filterMenu) if (!filterMenu)
{ {
@@ -479,6 +483,7 @@ void GameStateDeckViewer::Update(float dt)
if (mView->deck() != myDeck) source->swapSrc(); if (mView->deck() != myDeck) source->swapSrc();
} }
filterMenu->Entering(JGE_BTN_NONE); filterMenu->Entering(JGE_BTN_NONE);
}
break; break;
case JGE_BTN_PREV: case JGE_BTN_PREV:
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY) if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)

View File

@@ -7,7 +7,8 @@ const float GridDeckView::card_scale_big = 0.7f;
GridDeckView::GridDeckView() GridDeckView::GridDeckView()
: DeckView(16), mCols(8), mRows(2), mScrollOffset(0), mSlideOffset(0), : DeckView(16), mCols(8), mRows(2), mScrollOffset(0), mSlideOffset(0),
mScrollEasing(mScrollOffset), mSlideEasing(mSlideOffset), mCurrentSelection(-1) mScrollEasing(mScrollOffset), mSlideEasing(mSlideOffset), mCurrentSelection(-1),
mButtonMode(false)
{ {
} }
@@ -23,6 +24,7 @@ void GridDeckView::Reset()
mScrollEasing.finish(); mScrollEasing.finish();
mCurrentSelection = 0; mCurrentSelection = 0;
mButtonMode = false;
DeckView::Reset(); DeckView::Reset();
} }
@@ -36,14 +38,14 @@ void GridDeckView::UpdateViewState(float dt)
if(mScrollOffset <= -1.0f) if(mScrollOffset <= -1.0f)
{ {
SwitchPosition(2); SwitchPosition(2);
moveSelection(-2, false);
mScrollEasing.translate(1.0f); mScrollEasing.translate(1.0f);
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
} }
else if(mScrollOffset >= 1.0f) else if(mScrollOffset >= 1.0f)
{ {
SwitchPosition(-2); SwitchPosition(-2);
moveSelection(2, false);
mScrollEasing.translate(-1.0f); mScrollEasing.translate(-1.0f);
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
} }
dirtyCardPos = true; dirtyCardPos = true;
@@ -138,10 +140,50 @@ void GridDeckView::Render()
} }
} }
bool GridDeckView::ButtonPressed(Buttons button)
{
switch(button)
{
case JGE_BTN_LEFT:
if(mButtonMode) moveSelection(-2, true);
else changePosition(-1);
last_user_activity = 0;
break;
case JGE_BTN_RIGHT:
if(mButtonMode) moveSelection(2, true);
else changePosition(1);
last_user_activity = 0;
break;
case JGE_BTN_UP:
if(mButtonMode) moveSelection(-1, true);
else changeFilter(1);
last_user_activity = 0;
break;
case JGE_BTN_DOWN:
if(mButtonMode) moveSelection(1, true);
else changeFilter(-1);
last_user_activity = 0;
break;
case JGE_BTN_CTRL:
if(mButtonMode)
{
mButtonMode = false;
dirtyCardPos = true;
mCurrentSelection = -1;
}
else return false;
break;
default:
return false;
}
return true;
}
MTGCard * GridDeckView::Click(int x, int y) MTGCard * GridDeckView::Click(int x, int y)
{ {
int n = getCardIndexNextTo(x, y); int n = getCardIndexNextTo(x, y);
last_user_activity = 0; last_user_activity = 0;
mButtonMode = false;
if(mScrollEasing.finished() && mSlideEasing.finished()) if(mScrollEasing.finished() && mSlideEasing.finished())
{ //clicked and no animations running { //clicked and no animations running
@@ -167,6 +209,26 @@ MTGCard * GridDeckView::Click(int x, int y)
return NULL; return NULL;
} }
MTGCard * GridDeckView::Click()
{
if(mScrollEasing.finished() && mSlideEasing.finished())
{
MTGCard *active = getActiveCard();
if(active != NULL)
{
return active;
}
else
{
mButtonMode = true;
dirtyCardPos = true;
mCurrentSelection = 4;
}
}
return NULL;
}
void GridDeckView::changePosition(int offset) void GridDeckView::changePosition(int offset)
{ {
mScrollEasing.start(-1.0f * offset, scroll_animation_duration * abs(offset)); mScrollEasing.start(-1.0f * offset, scroll_animation_duration * abs(offset));
@@ -188,7 +250,7 @@ void GridDeckView::changeFilter(int offset)
MTGCard* GridDeckView::getActiveCard() MTGCard* GridDeckView::getActiveCard()
{ {
if(mCurrentSelection >= 0 && mCurrentSelection < int(mCards.size())) if(mCurrentSelection >= 4 && mCurrentSelection < int(mCards.size())-4)
{ {
return mCards[mCurrentSelection].card; return mCards[mCurrentSelection].card;
} }
@@ -197,3 +259,29 @@ MTGCard* GridDeckView::getActiveCard()
return NULL; return NULL;
} }
} }
void GridDeckView::moveSelection(int offset, bool alignIfOutOfBounds)
{
mCurrentSelection += offset;
if(alignIfOutOfBounds)
{
if(mCurrentSelection < 4)
{
changePosition(-1);
}
else if(mCurrentSelection >= 12)
{
changePosition(1);
}
}
else
{
if(mCurrentSelection < 4 || mCurrentSelection >= 12)
{
mCurrentSelection = -1;
}
}
dirtyCardPos = true;
}