Let the deck view base class handle buttons

This commit is contained in:
Tobias Loose
2013-12-05 22:10:33 +01:00
parent 8de50532f2
commit 1194463349
7 changed files with 72 additions and 62 deletions
+3 -1
View File
@@ -31,7 +31,9 @@ public:
void Render(); void Render();
MTGCard * Click(int x, int y); MTGCard * Click(int x, int y);
bool Button(Buttons button);
void changePosition(int offset);
void changeFilter(int offset);
MTGCard *getActiveCard(); MTGCard *getActiveCard();
+3 -1
View File
@@ -39,8 +39,10 @@ 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;
virtual bool Button(Buttons button) = 0; bool Button(Buttons button);
virtual MTGCard *getActiveCard() = 0; virtual MTGCard *getActiveCard() = 0;
virtual void changePosition(int offset) = 0;
virtual void changeFilter(int offset) = 0;
virtual void SetDeck(DeckDataWrapper *toShow); virtual void SetDeck(DeckDataWrapper *toShow);
DeckDataWrapper *deck(); DeckDataWrapper *deck();
+4 -1
View File
@@ -20,7 +20,10 @@ public:
void Render(); void Render();
MTGCard * Click(int x, int y); MTGCard * Click(int x, int y);
bool Button(Buttons button);
void changePosition(int offset);
void changeFilter(int offset);
MTGCard *getActiveCard(); MTGCard *getActiveCard();
private: private:
int mCols; int mCols;
+16 -20
View File
@@ -147,34 +147,30 @@ MTGCard * CarouselDeckView::Click(int x, int y)
return NULL; return NULL;
} }
bool CarouselDeckView::Button(Buttons button) void CarouselDeckView::changePosition(int offset)
{ {
switch(button) if(offset > 0){
{
case JGE_BTN_LEFT:
mScrollTarget -= 1;
mStage = SCROLL_TO_SELECTED;
last_user_activity = 0;
break;
case JGE_BTN_RIGHT:
mScrollTarget += 1; mScrollTarget += 1;
mStage = SCROLL_TO_SELECTED; mStage = SCROLL_TO_SELECTED;
last_user_activity = 0; }else if(offset < 0){
break; mScrollTarget -= 1;
case JGE_BTN_UP: mStage = SCROLL_TO_SELECTED;
}
last_user_activity = 0;
}
void CarouselDeckView::changeFilter(int offset)
{
if(offset > 0){
mStage = SLIDE_UP; mStage = SLIDE_UP;
SwitchFilter(1); SwitchFilter(1);
last_user_activity = 0; } else if(offset < 0){
break;
case JGE_BTN_DOWN:
mStage = SLIDE_DOWN; mStage = SLIDE_DOWN;
SwitchFilter(-1); SwitchFilter(-1);
last_user_activity = 0;
break;
default:
return false;
} }
return true;
last_user_activity = 0;
} }
MTGCard *CarouselDeckView::getActiveCard() MTGCard *CarouselDeckView::getActiveCard()
+26
View File
@@ -42,6 +42,32 @@ void DeckView::Update(float dt)
} }
} }
bool DeckView::Button(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;
+5 -18
View File
@@ -1536,26 +1536,13 @@ void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity)
{ {
if(abs(inXVelocity) > 300) if(abs(inXVelocity) > 300)
{ {
//determine how many cards to move, the faster the velocity the more cards to move. //FIXME: this 500 is a bit arbitrary
// the display is setup so that there is a max of 2 cards to the left and 7 cards to the right
// of the current card.
int numCards = (magnitude / 500) % 8; int numCards = (magnitude / 500) % 8;
int offset = 0; mView->changePosition(flickRight ? numCards : - numCards);
if ( (numCards == 0) && magnitude) numCards = 7;
if ( !flickRight)
{
if (numCards > 1)
offset = 0;
}
else
offset = 2 + numCards;
//TODO: FIXME
//mEngine->LeftClickedProcessed();
//mEngine->LeftClicked(static_cast<int>(cardsCoordinates[offset].first), static_cast<int>(cardsCoordinates[offset].second));
//mEngine->HoldKey_NoRepeat(JGE_BTN_OK);
} }
} }
else else
mEngine->HoldKey_NoRepeat(flickUp ? JGE_BTN_UP : JGE_BTN_DOWN); mView->changeFilter(flickUp ? 1 : -1);
last_user_activity = 0;
} }
+15 -21
View File
@@ -141,30 +141,24 @@ MTGCard * GridDeckView::Click(int x, int y)
return NULL; return NULL;
} }
bool GridDeckView::Button(Buttons button) void GridDeckView::changePosition(int offset)
{ {
switch(button) if(offset < 0){
{
case JGE_BTN_RIGHT:
mScrollOffset.start(-1.0f, 0.3f);
last_user_activity = 0;
break;
case JGE_BTN_LEFT:
mScrollOffset.start( 1.0f, 0.3f); mScrollOffset.start( 1.0f, 0.3f);
last_user_activity = 0; }else if(offset > 0){
break; mScrollOffset.start(-1.0f, 0.3f);
case JGE_BTN_UP:
mSlide.start(2.0f, 0.3f);
last_user_activity = 0;
break;
case JGE_BTN_DOWN:
mSlide.start(-2.0f, 0.3f);
last_user_activity = 0;
break;
default:
return false;
} }
return true; last_user_activity = 0;
}
void GridDeckView::changeFilter(int offset)
{
if(offset < 0){
mSlide.start(-2.0f, 0.3f);
}else if(offset > 0){
mSlide.start(2.0f, 0.3f);
}
last_user_activity = 0;
} }
MTGCard* GridDeckView::getActiveCard() MTGCard* GridDeckView::getActiveCard()