From b2c5df2cd3f39889dc2bd547c8f7c9956f38d760 Mon Sep 17 00:00:00 2001 From: Xawotihs Date: Mon, 5 Sep 2011 22:04:10 +0000 Subject: [PATCH] Modified the touch/mouse management in the editor to simply select the touched card. I also added a binding to switch between deck and collection with an horizontal swipe. --- projects/mtg/include/GameStateDeckViewer.h | 4 +- projects/mtg/src/GameStateDeckViewer.cpp | 86 +++++++++++++++------- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index fbf845bb9..4ca9c4a9d 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -31,7 +31,8 @@ enum STAGE_ONSCREEN_MENU = 5, STAGE_WELCOME = 6, STAGE_MENU = 7, - STAGE_FILTERS = 8 + STAGE_FILTERS = 8, + STAGE_TRANSITION_SELECTED = 9 }; // TODO: need a better name for MENU_FIRST_MENU, this is reused for the 1st submenu of @@ -93,6 +94,7 @@ private: JMusic * bgMusic; int lastPos; int lastTotal; + int mSelected; WGuiFilters * filterMenu; WSrcDeckViewer * source; diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index d431c666e..9ed3e6809 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -423,8 +423,30 @@ void GameStateDeckViewer::Update(float dt) } break; case JGE_BTN_OK: - last_user_activity = 0; - addRemove(cardIndex[2]); + if (mEngine->GetLeftClickCoordinates(x, y)) + { + for(int i=0; i < CARDS_DISPLAYED; i++) + { + distance2 = static_cast((cardsCoordinates[i].second - y) * (cardsCoordinates[i].second - y) + (cardsCoordinates[i].first - x) * (cardsCoordinates[i].first - x)); + if (distance2 < minDistance2) + { + minDistance2 = distance2; + n = i; + } + } + + if(n!=2) { + mSelected = n; + last_user_activity = 0; + mStage = STAGE_TRANSITION_SELECTED; + } + mEngine->LeftClickedProcessed(); + } + if(mStage != STAGE_TRANSITION_SELECTED) + { + last_user_activity = 0; + addRemove(cardIndex[2]); + } break; case JGE_BTN_SEC: last_user_activity = 0; @@ -474,32 +496,6 @@ void GameStateDeckViewer::Update(float dt) else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw->currentPage > stw->pageCount)) stw->currentPage = 0; break; default: // no keypress - if (mEngine->GetLeftClickCoordinates(x, y)) - { - for(int i=0; i < CARDS_DISPLAYED; i++) - { - distance2 = static_cast((cardsCoordinates[i].second - y) * (cardsCoordinates[i].second - y) + (cardsCoordinates[i].first - x) * (cardsCoordinates[i].first - x)); - if (distance2 < minDistance2) - { - minDistance2 = distance2; - n = i; - } - } - - if (n < ((CARDS_DISPLAYED/2) - 1)) - { - last_user_activity = 0; - mStage = STAGE_TRANSITION_RIGHT; - } - if (n > ((CARDS_DISPLAYED/2) + 1)) - { - last_user_activity = 0; - mStage = STAGE_TRANSITION_LEFT; - } - mEngine->LeftClickedProcessed(); - break; - } - if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY) { if (mStage != STAGE_ONSCREEN_MENU) @@ -520,6 +516,37 @@ void GameStateDeckViewer::Update(float dt) } } + if (mStage == STAGE_TRANSITION_SELECTED) + { + if (mSelected < 2) + { + mRotation -= dt * MED_SPEED; + if (mRotation < mSelected-2) + { + do + { + rotateCards(STAGE_TRANSITION_RIGHT); + mRotation += 1; + } while (mRotation < -1.0f); + mStage = STAGE_WAITING; + mRotation = 0; + } + } + else if (mSelected > 2) + { + mRotation += dt * MED_SPEED; + if (mRotation > mSelected - 2) + { + do + { + rotateCards(STAGE_TRANSITION_LEFT); + mRotation -= 1; + } while (mRotation > 1.0f); + mStage = STAGE_WAITING; + mRotation = 0; + } + } + } if (mStage == STAGE_TRANSITION_RIGHT || mStage == STAGE_TRANSITION_LEFT) { if (mStage == STAGE_TRANSITION_RIGHT) @@ -1675,5 +1702,8 @@ void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity) bool flickUpwards = (inYVelocity < 0); mEngine->HoldKey_NoRepeat(flickUpwards ? JGE_BTN_DOWN : JGE_BTN_UP); + } else if (abs(inXVelocity) > 300) + { + mEngine->HoldKey_NoRepeat(JGE_BTN_PRI); } }