diff --git a/JGE/include/JApp.h b/JGE/include/JApp.h index 47cc08803..29129fb1a 100644 --- a/JGE/include/JApp.h +++ b/JGE/include/JApp.h @@ -83,7 +83,7 @@ public: ////////////////////////////////////////////////////////////////////////// virtual void Resume() = 0; - virtual void OnScroll(int inXVelocity, int inYVelocity) = 0; + virtual void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0) = 0; }; diff --git a/JGE/include/JGE.h b/JGE/include/JGE.h index d723d350e..bf48c08dd 100644 --- a/JGE/include/JGE.h +++ b/JGE/include/JGE.h @@ -331,7 +331,7 @@ class JGE // Scroll events - currently triggered by SDL JOYBALL events - void Scroll(int inXVelocity, int inYVelocity); + void Scroll(int inXVelocity, int inYVelocity, int magnitude); ////////////////////////////////////////////////////////////////////////// /// Get if the system is ended/paused or not. diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index 62e13aced..8846a17df 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -577,11 +577,11 @@ void JGE::Assert(const char *filename, long lineNumber) mCriticalAssert = true; } -void JGE::Scroll(int inXVelocity, int inYVelocity) +void JGE::Scroll(int inXVelocity, int inYVelocity, int magnitude) { if (mApp != NULL) { - mApp->OnScroll(inXVelocity, inYVelocity); + mApp->OnScroll(inXVelocity, inYVelocity, magnitude); } } diff --git a/JGE/src/iOS/EAGLView.m b/JGE/src/iOS/EAGLView.m index 61640ba7b..30ec4e3d5 100755 --- a/JGE/src/iOS/EAGLView.m +++ b/JGE/src/iOS/EAGLView.m @@ -388,6 +388,15 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 g_engine->ResetInput(); } +- (int) distanceBetweenPointA: (CGPoint) cp1 andPointB: (CGPoint) cp2 +{ + int xDist = cp1.x - cp2.x; + int yDist = cp1.y - cp2.y; + int distance = (int) sqrt( (float) ((xDist * xDist) + (yDist + yDist))); + + return distance; +} + - (void)handlePanMotion: (UIPanGestureRecognizer *) panGesture { @@ -410,21 +419,14 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170 else { CGPoint v2 = [panGesture velocityInView: self]; - g_engine->Scroll( static_cast(v2.x), static_cast(v2.y)); - [self performSelector: @selector(resetInput) withObject: nil afterDelay: 0.1]; + int magnitude = [self distanceBetweenPointA: currentLocation andPointB: v2]; + g_engine->Scroll( 0 - static_cast(v2.x), 0 - static_cast(v2.y), static_cast(magnitude)); + [self performSelector: @selector(resetInput) withObject: nil afterDelay: 0.5]; + } } } -- (int) distanceBetweenPointA: (CGPoint) cp1 andPointB: (CGPoint) cp2 -{ - int xDist = cp1.x - cp2.x; - int yDist = cp1.y - cp2.y; - int distance = (int) sqrt( (float) ((xDist * xDist) + (yDist + yDist))); - - NSLog(@"distance between Point A: %@ and Point B: %@ is %i", NSStringFromCGPoint(cp1), NSStringFromCGPoint(cp2), distance); - return distance; -} - (void)handleSingleTap: (UITapGestureRecognizer *) recognizer { [[[recognizer view] layer] removeAllAnimations]; diff --git a/projects/mtg/include/GameApp.h b/projects/mtg/include/GameApp.h index 5d7ac82a2..3e98c0ba9 100644 --- a/projects/mtg/include/GameApp.h +++ b/projects/mtg/include/GameApp.h @@ -80,7 +80,7 @@ public: virtual void Pause(); virtual void Resume(); - virtual void OnScroll(int inXVelocity, int inYVelocity); + virtual void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0); void LoadGameStates(); void SetNextState(int state); diff --git a/projects/mtg/include/GameState.h b/projects/mtg/include/GameState.h index e080109ea..7f654c949 100644 --- a/projects/mtg/include/GameState.h +++ b/projects/mtg/include/GameState.h @@ -56,7 +56,7 @@ public: virtual void Start(){} virtual void End(){} - virtual void OnScroll(int inXVelocity, int inYVelocity) + virtual void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0) { } diff --git a/projects/mtg/include/GameStateAwards.h b/projects/mtg/include/GameStateAwards.h index cb614895c..777355cd2 100644 --- a/projects/mtg/include/GameStateAwards.h +++ b/projects/mtg/include/GameStateAwards.h @@ -35,7 +35,7 @@ public: virtual void Update(float dt); virtual void Render(); virtual void ButtonPressed(int controllerId, int controlId); - virtual void OnScroll(int inXVelocity, int inYVelocity); + virtual void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0); }; #endif diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 81be26bb4..af0bf2158 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -17,6 +17,7 @@ #include "DeckStats.h" #include "WDataSrc.h" #include "WGui.h" +#include "InteractiveButton.h" #define NO_USER_ACTIVITY_HELP_DELAY 10 #define NO_USER_ACTIVITY_SHOWCARD_DELAY 0.1 @@ -95,6 +96,8 @@ private: int lastPos; int lastTotal; int mSelected; + + InteractiveButton *toggleDeckButton, *sellCardButton; WGuiFilters * filterMenu; WSrcDeckViewer * source; @@ -118,6 +121,10 @@ private: void saveDeck(); //Saves the deck and additional necessary information void saveAsAIDeck(string deckName); // saves deck as an AI Deck int getCurrentPos(); + void sellCard(); + void setButtonState(bool state); + bool userPressedButton(); + pair cardsCoordinates[CARDS_DISPLAYED]; public: @@ -143,7 +150,7 @@ public: int loadDeck(int deckid); void LoadDeckStatistics(int deckId); - void OnScroll(int inXVelocity, int inYVelocity); + void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0); void buildEditorMenu(); virtual void ButtonPressed(int controllerId, int controlId); diff --git a/projects/mtg/include/GameStateDuel.h b/projects/mtg/include/GameStateDuel.h index 5526ac39a..913f35e16 100644 --- a/projects/mtg/include/GameStateDuel.h +++ b/projects/mtg/include/GameStateDuel.h @@ -80,7 +80,7 @@ public: virtual void Render(); void initRand(unsigned seed = 0); - void OnScroll(int inXVelocity, int inYVelocity); + void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0); enum ENUM_DUEL_STATE_MENU_ITEM { diff --git a/projects/mtg/include/GameStateShop.h b/projects/mtg/include/GameStateShop.h index e320ac388..db80bc091 100644 --- a/projects/mtg/include/GameStateShop.h +++ b/projects/mtg/include/GameStateShop.h @@ -115,7 +115,7 @@ public: virtual void Update(float dt); virtual void Render(); virtual void ButtonPressed(int controllerId, int controlId); - virtual void OnScroll(int inXVelocity, int inYVelocity); + virtual void OnScroll(int inXVelocity, int inYVelocity, int magnitude = 0); static float _x1[], _y1[], _x2[], _y2[], _x3[], _y3[], _x4[], _y4[]; }; diff --git a/projects/mtg/include/InteractiveButton.h b/projects/mtg/include/InteractiveButton.h index 4181836b1..0ffbb45f5 100644 --- a/projects/mtg/include/InteractiveButton.h +++ b/projects/mtg/include/InteractiveButton.h @@ -19,6 +19,10 @@ using std::string; #define SCALE_SELECTED 1.2f #define SCALE_NORMAL 1.0f +const int kDismissButtonId = 10000; +const int kToggleDeckActionId = 10001; +const int kSellCardActionId = 10002; + class InteractiveButton: public SimpleButton { private: diff --git a/projects/mtg/include/SimplePopup.h b/projects/mtg/include/SimplePopup.h index 21bd52c52..154710e92 100644 --- a/projects/mtg/include/SimplePopup.h +++ b/projects/mtg/include/SimplePopup.h @@ -35,7 +35,7 @@ private: public: bool autoTranslate; - SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL, int x = 364, int y = 235); + SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL, float x = 364, float y = 235); ~SimplePopup(void); void drawBoundingBox(float x, float y, float width, float height); bool isClosed() diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 232341d96..0ee750736 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -445,11 +445,11 @@ void GameApp::Render() } -void GameApp::OnScroll(int inXVelocity, int inYVelocity) +void GameApp::OnScroll(int inXVelocity, int inYVelocity, int magnitude) { if (mCurrentState != NULL) { - mCurrentState->OnScroll(inXVelocity, inYVelocity); + mCurrentState->OnScroll(inXVelocity, inYVelocity, magnitude); } } diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index b10f70a25..4a12461c4 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -389,7 +389,7 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId) } } -void GameStateAwards::OnScroll(int inXVelocity, int inYVelocity) +void GameStateAwards::OnScroll(int inXVelocity, int inYVelocity, int magnitude) { if (abs(inYVelocity) > 300) { diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index ba0b3c430..a7d0e3eb6 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -58,11 +58,17 @@ GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) : mAlpha = 255; menu = NULL; stw = NULL; + + toggleDeckButton = NEW InteractiveButton(NULL, kToggleDeckActionId, Fonts::MAIN_FONT, "View Deck", 10, 10, JGE_BTN_PRI); + sellCardButton = NEW InteractiveButton(NULL, kSellCardActionId, Fonts::MAIN_FONT, "Sell Card", (SCREEN_WIDTH_F/ 2) - 100, SCREEN_HEIGHT_F - 40, JGE_BTN_SEC); } GameStateDeckViewer::~GameStateDeckViewer() { SAFE_DELETE(bgMusic); + SAFE_DELETE(toggleDeckButton); + SAFE_DELETE(sellCardButton); + if (myDeck) { SAFE_DELETE(myDeck->parent); @@ -153,9 +159,11 @@ void GameStateDeckViewer::switchDisplay() if (displayed_deck == myCollection) { displayed_deck = myDeck; + toggleDeckButton->setText("View Collection"); } else { + toggleDeckButton->setText("View Deck"); displayed_deck = myCollection; } source->swapSrc(); @@ -334,6 +342,41 @@ void GameStateDeckViewer::saveAsAIDeck(string deckName) AIPlayer::invalidateTotalAIDecks(); //We added one AI deck, so we need to invalidate the count cache } +void GameStateDeckViewer::sellCard() +{ + last_user_activity = 0; + SAFE_DELETE(subMenu); + char buffer[4096]; + { + MTGCard * card = cardIndex[2]; + if (card && displayed_deck->count(card)) + { + price = pricelist->getSellPrice(card->getMTGId()); + sprintf(buffer, "%s : %i %s", _(card->data->getName()).c_str(), price, _("credits").c_str()); + const float menuXOffset = SCREEN_WIDTH_F - 300; + const float menuYOffset = SCREEN_HEIGHT_F / 2; + subMenu = NEW SimpleMenu(JGE::GetInstance(), MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer); + subMenu->Add(MENU_ITEM_YES, "Yes"); + subMenu->Add(MENU_ITEM_NO, "No", "", true); + } + } + stw->needUpdate = true; +} + +bool GameStateDeckViewer::userPressedButton() +{ + return ( + (toggleDeckButton->ButtonPressed()) + || (sellCardButton->ButtonPressed()) + ); + } + +void GameStateDeckViewer::setButtonState(bool state) +{ + toggleDeckButton->setIsSelectionValid(state); + sellCardButton->setIsSelectionValid(state); +} + void GameStateDeckViewer::Update(float dt) { @@ -341,7 +384,7 @@ void GameStateDeckViewer::Update(float dt) unsigned int distance2; unsigned int minDistance2 = -1; int n = 0; - + if (options.keypadActive()) { options.keypadUpdate(dt); @@ -418,47 +461,41 @@ void GameStateDeckViewer::Update(float dt) case JGE_BTN_OK: 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) + // verify that none of the buttons fired + if (userPressedButton()) { - minDistance2 = distance2; - n = i; + Update(dt); + break; } - } - if(n!=2) { - mSelected = n; - last_user_activity = 0; - mStage = STAGE_TRANSITION_SELECTED; - } - mEngine->LeftClickedProcessed(); + 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; - SAFE_DELETE(subMenu); - char buffer[4096]; - { - MTGCard * card = cardIndex[2]; - if (card && displayed_deck->count(card)) - { - price = pricelist->getSellPrice(card->getMTGId()); - sprintf(buffer, "%s : %i %s", _(card->data->getName()).c_str(), price, _("credits").c_str()); - const float menuXOffset = SCREEN_WIDTH_F - 300; - const float menuYOffset = SCREEN_HEIGHT_F / 2; - subMenu = NEW SimpleMenu(JGE::GetInstance(), MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer); - subMenu->Add(MENU_ITEM_YES, "Yes"); - subMenu->Add(MENU_ITEM_NO, "No", "", true); - } - } - stw->needUpdate = true; + sellCard(); break; case JGE_BTN_MENU: @@ -506,6 +543,8 @@ void GameStateDeckViewer::Update(float dt) } else last_user_activity += dt; + + break; } } @@ -747,7 +786,6 @@ void GameStateDeckViewer::renderDeckBackground() void GameStateDeckViewer::renderOnScreenMenu() { - WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); font->SetColor(ARGB(255,255,255,255)); JRenderer * r = JRenderer::GetInstance(); @@ -1416,9 +1454,8 @@ void GameStateDeckViewer::renderCard(int id) void GameStateDeckViewer::Render() { - - WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); - + setButtonState(false); + WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); if (displayed_deck == myDeck && mStage != STAGE_MENU) renderDeckBackground(); @@ -1475,19 +1512,28 @@ void GameStateDeckViewer::Render() } else { + setButtonState(true); renderOnScreenBasicInfo(); - } + if (mStage == STAGE_MENU) { + setButtonState(false); menu->Render(); } + if (subMenu) subMenu->Render(); - if (filterMenu && !filterMenu->isFinished()) filterMenu->Render(); - + if (filterMenu && !filterMenu->isFinished()) + { + setButtonState(false); + filterMenu->Render(); + } + if (options.keypadActive()) options.keypadRender(); + toggleDeckButton->Render(); + sellCardButton->Render(); } int GameStateDeckViewer::loadDeck(int deckid) @@ -1688,11 +1734,11 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) } } -void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity) +void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity, int magnitude) { bool flickHorizontal = (abs(inXVelocity) > abs(inYVelocity)); - bool flickUp = inYVelocity < 0 ? true : false; - bool flickRight = inXVelocity > 0 ? true : false; + bool flickUp = !flickHorizontal && (inYVelocity < 0) ? true : false; + bool flickRight = flickHorizontal && (inXVelocity > 0) ? true : false; if (mStage == STAGE_FILTERS) { @@ -1703,9 +1749,27 @@ void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity) } else { - if (flickHorizontal && (abs(inXVelocity) > 300)) - mEngine->HoldKey_NoRepeat(JGE_BTN_PRI); - else if (!flickHorizontal && (abs(inYVelocity) > 300)) + if (flickHorizontal) + { + //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. + 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; + + mEngine->LeftClickedProcessed(); + mEngine->LeftClicked(cardsCoordinates[offset].first, cardsCoordinates[offset].second); + mEngine->HoldKey_NoRepeat(JGE_BTN_OK); + } + else mEngine->HoldKey_NoRepeat(flickUp ? JGE_BTN_UP : JGE_BTN_DOWN); } } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 4a4920622..095e25e8a 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -931,8 +931,9 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) } } -void GameStateDuel::OnScroll(int inXVelocity, int inYVelocity) +void GameStateDuel::OnScroll(int inXVelocity, int inYVelocity, int magnitude) { + // ignore magnitude for now, since no action requires scrolling if (abs(inYVelocity) > 300) { bool flickUpwards = (inYVelocity < 0); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index c7f830071..8b4874f4f 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -808,8 +808,9 @@ void GameStateShop::ButtonPressed(int controllerId, int controlId) menu->Close(); } -void GameStateShop::OnScroll(int inXVelocity, int inYVelocity) +void GameStateShop::OnScroll(int inXVelocity, int inYVelocity, int magnitude) { + // we ignore magnitude since there isn't any scrolling in the shop if (abs(inXVelocity) > 200) { bool flickRight = (inXVelocity >= 0); diff --git a/projects/mtg/src/InteractiveButton.cpp b/projects/mtg/src/InteractiveButton.cpp index 426bf75dd..a2cb79833 100644 --- a/projects/mtg/src/InteractiveButton.cpp +++ b/projects/mtg/src/InteractiveButton.cpp @@ -15,6 +15,7 @@ #include "WResourceManager.h" #include "WFont.h" +const int kButtonHeight = 60; InteractiveButton::InteractiveButton(JGuiController* _parent, int id, int fontId, string text, float x, float y, JButton actionKey, bool hasFocus, bool autoTranslate) : SimpleButton( _parent, id, fontId, text, x, y, hasFocus, autoTranslate) @@ -35,7 +36,7 @@ void InteractiveButton::checkUserClick() setIsSelectionValid(false); int buttonImageWidth = static_cast(GetWidth()); int x2 = static_cast(getX()), y2 = static_cast(getY() + mYOffset); - int buttonHeight = 50; + int buttonHeight = kButtonHeight; if ( (x1 >= x2) && (x1 <= (x2 + buttonImageWidth)) && (y1 >= y2) && (y1 < (y2 + buttonHeight))) setIsSelectionValid( true ); } diff --git a/projects/mtg/src/SimplePopup.cpp b/projects/mtg/src/SimplePopup.cpp index 74d79b42c..7df50faa9 100644 --- a/projects/mtg/src/SimplePopup.cpp +++ b/projects/mtg/src/SimplePopup.cpp @@ -14,9 +14,7 @@ #include "DeckManager.h" #include -const int kDismissButtonId = 10000; - -SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection, int cancelX, int cancelY) : +SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection, float cancelX, float cancelY) : JGuiController(JGE::GetInstance(), id, listener), mFontId(fontId), mCollection(collection) { mX = 19; diff --git a/projects/mtg/wagic.xcodeproj/project.pbxproj b/projects/mtg/wagic.xcodeproj/project.pbxproj index aba647ea9..fa1745f69 100755 --- a/projects/mtg/wagic.xcodeproj/project.pbxproj +++ b/projects/mtg/wagic.xcodeproj/project.pbxproj @@ -2541,7 +2541,10 @@ FT2_BUILD_LIBRARY, ); "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNUSED_PARAMETER = NO; HEADER_SEARCH_PATHS = ( ../../JGE/include/, include/, @@ -2586,7 +2589,10 @@ IOS, ); "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNUSED_PARAMETER = NO; HEADER_SEARCH_PATHS = ( ../../JGE/include/, include/,