From 1194463349f8e08d88b3997c6b64026725368495 Mon Sep 17 00:00:00 2001 From: Tobias Loose Date: Thu, 5 Dec 2013 22:10:33 +0100 Subject: [PATCH] Let the deck view base class handle buttons --- projects/mtg/include/CarouselDeckView.h | 4 ++- projects/mtg/include/DeckView.h | 4 ++- projects/mtg/include/GridDeckView.h | 5 +++- projects/mtg/src/CarouselDeckView.cpp | 36 +++++++++++------------- projects/mtg/src/DeckView.cpp | 26 +++++++++++++++++ projects/mtg/src/GameStateDeckViewer.cpp | 23 ++++----------- projects/mtg/src/GridDeckView.cpp | 36 ++++++++++-------------- 7 files changed, 72 insertions(+), 62 deletions(-) diff --git a/projects/mtg/include/CarouselDeckView.h b/projects/mtg/include/CarouselDeckView.h index f911ba09b..1ef2a4472 100644 --- a/projects/mtg/include/CarouselDeckView.h +++ b/projects/mtg/include/CarouselDeckView.h @@ -31,7 +31,9 @@ public: void Render(); MTGCard * Click(int x, int y); - bool Button(Buttons button); + + void changePosition(int offset); + void changeFilter(int offset); MTGCard *getActiveCard(); diff --git a/projects/mtg/include/DeckView.h b/projects/mtg/include/DeckView.h index 4a77a0f67..d5d7dca5b 100644 --- a/projects/mtg/include/DeckView.h +++ b/projects/mtg/include/DeckView.h @@ -39,8 +39,10 @@ public: virtual void Render() = 0; virtual MTGCard * Click(int x, int y) = 0; - virtual bool Button(Buttons button) = 0; + bool Button(Buttons button); virtual MTGCard *getActiveCard() = 0; + virtual void changePosition(int offset) = 0; + virtual void changeFilter(int offset) = 0; virtual void SetDeck(DeckDataWrapper *toShow); DeckDataWrapper *deck(); diff --git a/projects/mtg/include/GridDeckView.h b/projects/mtg/include/GridDeckView.h index 7bcc363b7..8aeb51814 100644 --- a/projects/mtg/include/GridDeckView.h +++ b/projects/mtg/include/GridDeckView.h @@ -20,7 +20,10 @@ public: void Render(); MTGCard * Click(int x, int y); - bool Button(Buttons button); + + void changePosition(int offset); + void changeFilter(int offset); + MTGCard *getActiveCard(); private: int mCols; diff --git a/projects/mtg/src/CarouselDeckView.cpp b/projects/mtg/src/CarouselDeckView.cpp index 4fbeda9a1..9a37b8fde 100644 --- a/projects/mtg/src/CarouselDeckView.cpp +++ b/projects/mtg/src/CarouselDeckView.cpp @@ -147,34 +147,30 @@ MTGCard * CarouselDeckView::Click(int x, int y) return NULL; } -bool CarouselDeckView::Button(Buttons button) +void CarouselDeckView::changePosition(int offset) { - switch(button) - { - case JGE_BTN_LEFT: - mScrollTarget -= 1; - mStage = SCROLL_TO_SELECTED; - last_user_activity = 0; - break; - case JGE_BTN_RIGHT: + if(offset > 0){ mScrollTarget += 1; mStage = SCROLL_TO_SELECTED; - last_user_activity = 0; - break; - case JGE_BTN_UP: + }else if(offset < 0){ + mScrollTarget -= 1; + mStage = SCROLL_TO_SELECTED; + } + + last_user_activity = 0; +} + +void CarouselDeckView::changeFilter(int offset) +{ + if(offset > 0){ mStage = SLIDE_UP; SwitchFilter(1); - last_user_activity = 0; - break; - case JGE_BTN_DOWN: + } else if(offset < 0){ mStage = SLIDE_DOWN; SwitchFilter(-1); - last_user_activity = 0; - break; - default: - return false; } - return true; + + last_user_activity = 0; } MTGCard *CarouselDeckView::getActiveCard() diff --git a/projects/mtg/src/DeckView.cpp b/projects/mtg/src/DeckView.cpp index 3e3c674ef..6c1e8e277 100644 --- a/projects/mtg/src/DeckView.cpp +++ b/projects/mtg/src/DeckView.cpp @@ -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) { mCurrentDeck = toShow; diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 9a31b7e2f..d358eed84 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -1536,26 +1536,13 @@ void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity) { if(abs(inXVelocity) > 300) { - //determine how many cards to move, the faster the velocity the more cards to move. - // 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. + //FIXME: this 500 is a bit arbitrary int numCards = (magnitude / 500) % 8; - int offset = 0; - 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(cardsCoordinates[offset].first), static_cast(cardsCoordinates[offset].second)); - //mEngine->HoldKey_NoRepeat(JGE_BTN_OK); + mView->changePosition(flickRight ? numCards : - numCards); } } else - mEngine->HoldKey_NoRepeat(flickUp ? JGE_BTN_UP : JGE_BTN_DOWN); + mView->changeFilter(flickUp ? 1 : -1); + + last_user_activity = 0; } diff --git a/projects/mtg/src/GridDeckView.cpp b/projects/mtg/src/GridDeckView.cpp index 7d918acb7..0de06ee53 100644 --- a/projects/mtg/src/GridDeckView.cpp +++ b/projects/mtg/src/GridDeckView.cpp @@ -141,30 +141,24 @@ MTGCard * GridDeckView::Click(int x, int y) return NULL; } -bool GridDeckView::Button(Buttons button) +void GridDeckView::changePosition(int offset) { - switch(button) - { - case JGE_BTN_RIGHT: - mScrollOffset.start(-1.0f, 0.3f); - last_user_activity = 0; - break; - case JGE_BTN_LEFT: + if(offset < 0){ mScrollOffset.start( 1.0f, 0.3f); - last_user_activity = 0; - break; - 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; + }else if(offset > 0){ + mScrollOffset.start(-1.0f, 0.3f); } - 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()