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();
bool ButtonPressed(Buttons button);
MTGCard * Click(int x, int y);
MTGCard * Click();
void changePosition(int offset);
void changeFilter(int offset);

View File

@@ -42,7 +42,8 @@ public:
virtual void Render() = 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 void changePosition(int offset) = 0;
virtual void changeFilter(int offset) = 0;

View File

@@ -20,7 +20,9 @@ public:
void UpdateCardPosition(CardRep &rep, int index);
void Render();
bool ButtonPressed(Buttons button);
MTGCard * Click(int x, int y);
MTGCard * Click();
void changePosition(int offset);
void changeFilter(int offset);
@@ -33,6 +35,9 @@ private:
InOutQuadEasing mScrollEasing;
InOutQuadEasing mSlideEasing;
int mCurrentSelection;
bool mButtonMode;
void moveSelection(int offset, bool alignIfOutOfBounds);
};
#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)
{
int n = getCardIndexNextTo(x, y);
@@ -139,6 +164,18 @@ MTGCard * CarouselDeckView::Click(int x, int y)
return NULL;
}
MTGCard *CarouselDeckView::Click()
{
if(mSlideEasing.finished() && mScrollEasing.finished())
{
return getActiveCard();
}
else
{
return NULL;
}
}
void CarouselDeckView::changePosition(int 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)
{
mCurrentDeck = toShow;

View File

@@ -443,19 +443,21 @@ void GameStateDeckViewer::Update(float dt)
int x, y;
if (mEngine->GetLeftClickCoordinates(x, y))
{
last_user_activity = 0;
mEngine->LeftClickedProcessed();
if(mView->Click(x, y) == mView->getActiveCard())
if(mView->Click(x, y) != NULL)
{
addRemove(mView->getActiveCard());
}
}
else
{
last_user_activity = 0;
if(mView->Click() != NULL)
{
addRemove(mView->getActiveCard());
}
}
last_user_activity = 0;
mStage = STAGE_WAITING;
break;
}
@@ -468,6 +470,8 @@ void GameStateDeckViewer::Update(float dt)
buildEditorMenu();
break;
case JGE_BTN_CTRL:
if(!mView->ButtonPressed(JGE_BTN_CTRL))
{
mStage = STAGE_FILTERS;
if (!filterMenu)
{
@@ -479,6 +483,7 @@ void GameStateDeckViewer::Update(float dt)
if (mView->deck() != myDeck) source->swapSrc();
}
filterMenu->Entering(JGE_BTN_NONE);
}
break;
case JGE_BTN_PREV:
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()
: 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();
mCurrentSelection = 0;
mButtonMode = false;
DeckView::Reset();
}
@@ -36,14 +38,14 @@ void GridDeckView::UpdateViewState(float dt)
if(mScrollOffset <= -1.0f)
{
SwitchPosition(2);
moveSelection(-2, false);
mScrollEasing.translate(1.0f);
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
}
else if(mScrollOffset >= 1.0f)
{
SwitchPosition(-2);
moveSelection(2, false);
mScrollEasing.translate(-1.0f);
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
}
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)
{
int n = getCardIndexNextTo(x, y);
last_user_activity = 0;
mButtonMode = false;
if(mScrollEasing.finished() && mSlideEasing.finished())
{ //clicked and no animations running
@@ -167,6 +209,26 @@ MTGCard * GridDeckView::Click(int x, int y)
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)
{
mScrollEasing.start(-1.0f * offset, scroll_animation_duration * abs(offset));
@@ -188,7 +250,7 @@ void GridDeckView::changeFilter(int offset)
MTGCard* GridDeckView::getActiveCard()
{
if(mCurrentSelection >= 0 && mCurrentSelection < int(mCards.size()))
if(mCurrentSelection >= 4 && mCurrentSelection < int(mCards.size())-4)
{
return mCards[mCurrentSelection].card;
}
@@ -197,3 +259,29 @@ MTGCard* GridDeckView::getActiveCard()
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;
}