Make deck views toggleable

This commit is contained in:
Tobias Loose
2013-12-05 16:41:54 +01:00
parent 55e0366f19
commit 0c72bfd4c4
3 changed files with 66 additions and 14 deletions

View File

@@ -91,14 +91,22 @@ private:
string newDeckname;
bool isAIDeckSave;
bool mSwitching;
enum AvailableView{
CAROUSEL_VIEW,
GRID_VIEW
};
DeckView* mView;
AvailableView mCurrentView;
void saveDeck(); //Saves the deck and additional necessary information
void saveAsAIDeck(string deckName); // saves deck as an AI Deck
void sellCard();
void setButtonState(bool state);
bool userPressedButton();
void RenderButtons();
DeckView* mView;
void setupView(AvailableView view);
void toggleView();
public:
GameStateDeckViewer(GameApp* parent);
virtual ~GameStateDeckViewer();

View File

@@ -28,7 +28,7 @@
GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) :
GameState(parent, "deckeditor"), mView(NEW GridDeckView())
GameState(parent, "deckeditor"), mView(NULL), mCurrentView(CAROUSEL_VIEW)
{
bgMusic = NULL;
isAIDeckSave = false;
@@ -48,7 +48,8 @@ GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) :
toggleDeckButton = NEW InteractiveButton(NULL, kToggleDeckActionId, Fonts::MAIN_FONT, "View Deck", 10, SCREEN_HEIGHT_F - 20, JGE_BTN_PRI);
sellCardButton = NEW InteractiveButton(NULL, kSellCardActionId, Fonts::MAIN_FONT, "Sell Card", (SCREEN_WIDTH_F/ 2) - 100, SCREEN_HEIGHT_F - 20, JGE_BTN_SEC);
filterButton = NEW InteractiveButton(NULL, kFilterButtonId, Fonts::MAIN_FONT, "filter", (SCREEN_WIDTH_F - 110), SCREEN_HEIGHT_F - 20, JGE_BTN_CTRL);
toggleViewButton = NEW InteractiveButton(NULL, kSwitchViewButton, Fonts::MAIN_FONT, "Grid", (SCREEN_WIDTH_F/ 2) - 130, SCREEN_HEIGHT_F - 20, JGE_BTN_NONE);
//TODO: Check if that button is available:
toggleViewButton = NEW InteractiveButton(NULL, kSwitchViewButton, Fonts::MAIN_FONT, "Grid", (SCREEN_WIDTH_F/ 2) + 50, SCREEN_HEIGHT_F - 20, JGE_BTN_MAX);
}
GameStateDeckViewer::~GameStateDeckViewer()
@@ -103,8 +104,8 @@ void GameStateDeckViewer::toggleCollection()
{
if (mView->deck() == myCollection)
{
mView->SetDeck(myDeck);
toggleDeckButton->setText("View Collection");
mView->SetDeck(myDeck);
}
else
{
@@ -162,18 +163,17 @@ void GameStateDeckViewer::Start()
subMenu = NULL;
myDeck = NULL;
mStage = STAGE_WELCOME;
mView->Reset();
mAlpha = 255;
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
onScreenTransition = 0;
//lastPos = 0;
//lastTotal = 0;
pricelist = NEW PriceList("settings/prices.dat", MTGCollection());
playerdata = NEW PlayerData(MTGCollection());
myCollection = NEW DeckDataWrapper(playerdata->collection);
myCollection->Sort(WSrcCards::SORT_ALPHA);
mView->SetDeck(myCollection);
setupView(mCurrentView);
//Icons
mIcons = manaIcons;
@@ -338,6 +338,40 @@ void GameStateDeckViewer::RenderButtons()
toggleViewButton->Render();
}
void GameStateDeckViewer::setupView(GameStateDeckViewer::AvailableView view)
{
DeckDataWrapper *wrapper = myCollection;
if(mView)
{
wrapper = mView->deck();
}
SAFE_DELETE(mView);
if(view == CAROUSEL_VIEW) mView = NEW CarouselDeckView();
else if(view == GRID_VIEW) mView = NEW GridDeckView();
mView->SetDeck(wrapper);
updateFilters();
}
void GameStateDeckViewer::toggleView()
{
if(mCurrentView == CAROUSEL_VIEW)
{
mCurrentView = GRID_VIEW;
toggleViewButton->setText("Carousel");
}
else
{
mCurrentView = CAROUSEL_VIEW;
toggleViewButton->setText("Grid");
}
setupView(mCurrentView);
}
void GameStateDeckViewer::Update(float dt)
{
if (options.keypadActive())
@@ -388,9 +422,12 @@ void GameStateDeckViewer::Update(float dt)
case JGE_BTN_RIGHT:
case JGE_BTN_UP:
case JGE_BTN_DOWN:
mView->Button(button);
last_user_activity = 0;
mStage = STAGE_WAITING;
if(last_user_activity > 0.2)
{
mView->Button(button);
last_user_activity = 0;
mStage = STAGE_WAITING;
}
break;
case JGE_BTN_CANCEL:
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
@@ -402,6 +439,13 @@ void GameStateDeckViewer::Update(float dt)
toggleCollection();
}
break;
case JGE_BTN_MAX:
if (last_user_activity > 0.2)
{
last_user_activity = 0;
toggleView();
}
break;
case JGE_BTN_OK:
{
// verify that none of the buttons fired

View File

@@ -2,10 +2,10 @@
const float GridDeckView::scroll_speed = 5.0f;
const float GridDeckView::card_scale_small = 0.48f;
const float GridDeckView::card_scale_big = 0.6f;
const float GridDeckView::card_scale_big = 0.7f;
GridDeckView::GridDeckView()
: DeckView(16), mCols(8), mRows(2), mSlide(0), mScrollOffset(0), mCurrentSelection(0), mColsToScroll(0), mStage(NONE)
: DeckView(16), mCols(8), mRows(2), mSlide(0), mScrollOffset(0), mCurrentSelection(-1), mColsToScroll(0), mStage(NONE)
{
}