Extended Scroll() and OnScroll() to also take in magnitude as one of its parameters. magnitude is currently used in the deck editor to figure out how many cards to rotate around per swipe as function of velocity and the number of cards displayed on the screen.

fixed a compiler warning in SimplePopup in the constructor declaration
===DECK Editor changes ===
Added two touch buttons , one for "Sell Card", the other to switch between Deck and Collection.
changed swipe Left/Right to rotate card collection; removing the previous action which was to swap between deck/collection viewing

Note: GameStateDeckViewer isn't a JGuiController so can't leverage off the mButtons vector.  Thus, the buttons have to be handled by this class separately. (setButtonState, userPressedButton)
This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-26 13:53:03 +00:00
parent dda048c616
commit a2179017d4
20 changed files with 159 additions and 75 deletions

View File

@@ -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;
};

View File

@@ -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.

View File

@@ -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);
}
}

View File

@@ -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<int>(v2.x), static_cast<int>(v2.y));
[self performSelector: @selector(resetInput) withObject: nil afterDelay: 0.1];
int magnitude = [self distanceBetweenPointA: currentLocation andPointB: v2];
g_engine->Scroll( 0 - static_cast<int>(v2.x), 0 - static_cast<int>(v2.y), static_cast<int>(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];

View File

@@ -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);

View File

@@ -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)
{
}

View File

@@ -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

View File

@@ -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<float, float> 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);

View File

@@ -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
{

View File

@@ -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[];
};

View File

@@ -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:

View File

@@ -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()

View File

@@ -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);
}
}

View File

@@ -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)
{

View File

@@ -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<unsigned int>((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<unsigned int>((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);
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<int>(GetWidth());
int x2 = static_cast<int>(getX()), y2 = static_cast<int>(getY() + mYOffset);
int buttonHeight = 50;
int buttonHeight = kButtonHeight;
if ( (x1 >= x2) && (x1 <= (x2 + buttonImageWidth)) && (y1 >= y2) && (y1 < (y2 + buttonHeight)))
setIsSelectionValid( true );
}

View File

@@ -14,9 +14,7 @@
#include "DeckManager.h"
#include <iomanip>
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;

View File

@@ -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/,