Refactor gamestatedeckviewer and add a grid view suited...

for bigger screens.
This commit is contained in:
Tobias Loose
2013-12-04 21:57:01 +01:00
parent e90f6fe224
commit 667b95f2b8
24 changed files with 845 additions and 447 deletions
+46
View File
@@ -0,0 +1,46 @@
#ifndef _CAROUSEL_DECK_VIEW_H_
#define _CAROUSEL_DECK_VIEW_H_
#include "DeckView.h"
class CarouselDeckView : public DeckView
{
private:
enum AnimationStage{
NONE = 0,
SLIDE_UP,
SLIDE_DOWN,
SCROLL_TO_SELECTED
};
static const float scroll_speed;
public:
CarouselDeckView();
virtual ~CarouselDeckView();
void Reset();
void UpdateViewState(float dt);
void UpdateCardPosition(CardRep &rep, int index);
void renderCard(int index)
{
int alpha = (int) (255 * (getCardRep(index).scale + 1.0 - max_scale));
DeckView::renderCard(index, alpha);
}
void Render();
MTGCard * Click(int x, int y);
bool Button(Buttons button);
MTGCard *getActiveCard();
//maintains the current rotation for fluid animations
private:
float mRotation; //[-1,1]. defines the current rotation of the cards
float mSlide; //[-1,1]. defines, the y-offset of the cards
int mScrollTarget; //0 <= mScrollTarget < mCards.size(). defines where to scroll to if the current animation is a scroll animation
AnimationStage mStage; // state machine state. for animation purposes
};
#endif //_CAROUSEL_DECK_VIEW_H_
+67
View File
@@ -0,0 +1,67 @@
#ifndef _DECK_VIEW_H_
#define _DECK_VIEW_H_
#include <vector>
#include "MTGCard.h"
#include "DeckDataWrapper.h"
#include "WFont.h"
#include "WResourceManager.h"
#include "Pos.h"
#define NO_USER_ACTIVITY_HELP_DELAY 10
#define NO_USER_ACTIVITY_SHOWCARD_DELAY 0.1
class DeckView
{
protected:
static const float max_scale;
static const float x_center;
static const float right_border;
public:
struct CardRep{
float x;
float y;
float scale;
MTGCard * card;
};
bool dirtyFilters;
bool dirtyCardPos;
DeckView(int numberOfCards);
virtual ~DeckView();
virtual void Reset();
//advances the view and card representations
void Update(float dt);
virtual void Render() = 0;
virtual MTGCard * Click(int x, int y) = 0;
virtual bool Button(Buttons button) = 0;
virtual MTGCard *getActiveCard() = 0;
virtual void SetDeck(DeckDataWrapper *toShow);
DeckDataWrapper *deck();
void SwitchFilter(int delta);
int filter();
void reloadIndexes();
int getPosition();
protected:
float last_user_activity;
int mFilter;
DeckDataWrapper *mCurrentDeck;
CardRep& getCardRep(unsigned int index);
void renderCard(int index, int alpha);
int getCardIndexNextTo(int x, int y);
vector<CardRep> mCards;
private:
virtual void UpdateViewState(float dt) = 0;
virtual void UpdateCardPosition(CardRep& rep, int index) = 0;
};
#endif // _DECK_VIEW_H_
+14 -46
View File
@@ -19,22 +19,7 @@
#include "WGui.h"
#include "InteractiveButton.h"
#define NO_USER_ACTIVITY_HELP_DELAY 10
#define NO_USER_ACTIVITY_SHOWCARD_DELAY 0.1
enum
{
STAGE_TRANSITION_RIGHT = 0,
STAGE_TRANSITION_LEFT = 1,
STAGE_WAITING = 2,
STAGE_TRANSITION_UP = 3,
STAGE_TRANSITION_DOWN = 4,
STAGE_ONSCREEN_MENU = 5,
STAGE_WELCOME = 6,
STAGE_MENU = 7,
STAGE_FILTERS = 8,
STAGE_TRANSITION_SELECTED = 9
};
class DeckView;
// TODO: need a better name for MENU_FIRST_MENU, this is reused for the 1st submenu of
// available options in the duel menu
@@ -44,7 +29,7 @@ enum
MENU_DECK_SELECTION = 10,
MENU_DECK_BUILDER = 11,
MENU_FIRST_DUEL_SUBMENU = 102,
MENU_LANGUAGE_SELECTION = 103,
MENU_LANGUAGE_SELECTION = 103
};
// enums for menu options
@@ -64,38 +49,28 @@ enum DECK_VIEWER_MENU_ITEMS
MENU_ITEM_NO = 21,
MENU_ITEM_FILTER_BY = 22,
MENUITEM_MORE_INFO = kInfoMenuID
};
#define ALL_COLORS -1
#define ROTATE_LEFT 1;
#define ROTATE_RIGHT 0;
#define HIGH_SPEED 15.0
#define MED_SPEED 5.0f
#define LOW_SPEED 1.5
#define MAX_SAVED_FILTERS Constants::NB_Colors + 1
#define CARDS_DISPLAYED 10
class GameStateDeckViewer: public GameState, public JGuiListener
{
private:
enum DeckViewerStages
{
STAGE_WAITING = 0,
STAGE_ONSCREEN_MENU,
STAGE_WELCOME,
STAGE_MENU,
STAGE_FILTERS
};
vector<JQuadPtr> mIcons;
JQuadPtr pspIcons[8];
JTexture * pspIconsTexture;
float last_user_activity;
float onScreenTransition;
float mRotation;
float mSlide;
int mAlpha;
int mStage;
int useFilter;
DeckViewerStages mStage;
JMusic * bgMusic;
int lastPos;
int lastTotal;
int mSelected;
InteractiveButton *toggleDeckButton, *sellCardButton, *statsPrevButton, *filterButton, *toggleViewButton;
@@ -108,10 +83,8 @@ private:
PriceList* pricelist;
PlayerData * playerdata;
int price;
DeckDataWrapper * displayed_deck;
DeckDataWrapper * myDeck;
DeckDataWrapper * myCollection;
MTGCard * cardIndex[CARDS_DISPLAYED];
StatsWrapper *stw;
int hudAlpha;
@@ -120,23 +93,20 @@ private:
bool mSwitching;
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();
void RenderButtons();
pair<float, float> cardsCoordinates[CARDS_DISPLAYED];
DeckView* mView;
public:
GameStateDeckViewer(GameApp* parent);
virtual ~GameStateDeckViewer();
void updateDecks();
void rotateCards(int direction);
void loadIndexes();
void updateFilters();
void rebuildFilters();
void switchDisplay();
void toggleCollection();
void Start();
virtual void End();
void addRemove(MTGCard * card);
@@ -145,8 +115,6 @@ public:
void renderSlideBar();
void renderDeckBackground();
void renderOnScreenMenu();
virtual void renderCard(int id, float rotation);
virtual void renderCard(int id);
virtual void Render();
int loadDeck(int deckid);
void LoadDeckStatistics(int deckId);
+225
View File
@@ -0,0 +1,225 @@
#ifndef _GRID_DECK_VIEW_H
#define _GRID_DECK_VIEW_H
#include "DeckView.h"
class GridDeckView : public DeckView
{
private:
enum AnimationStage{
NONE = 0,
SLIDE_UP,
SLIDE_DOWN,
SCROLL_TO_SELECTED
};
static const float scroll_speed = 5.0f;
static const float card_scale_small = 0.48f;
static const float card_scale_big = 0.6f;
public:
GridDeckView(): DeckView(16), mCols(8), mRows(2), mSlide(0), mScrollOffset(0), mCurrentSelection(0), mColsToScroll(0), mStage(NONE)
{}
virtual ~GridDeckView()
{}
void Reset()
{
mSlide = 0;
mScrollOffset = 0;
mCurrentSelection = 0;
mColsToScroll = 0;
mStage = NONE;
}
void UpdateViewState(float dt)
{
switch(mStage)
{
case SCROLL_TO_SELECTED:
if(mColsToScroll < 0){
mScrollOffset -= dt * scroll_speed;
if(mScrollOffset <= -1.0f)
{
mScrollOffset += 1.0f;
deck()->next();
deck()->next();
mCurrentSelection = (mCurrentSelection >= 6) ? mCurrentSelection - 2 : -1;
reloadIndexes();
mColsToScroll += 1;
}
}else if(mColsToScroll > 0){
mScrollOffset += dt * scroll_speed;
if(mScrollOffset >= 1.0f)
{
mScrollOffset -= 1.0f;
deck()->prev();
deck()->prev();
mCurrentSelection = (mCurrentSelection >= 0 && mCurrentSelection < 10) ? mCurrentSelection + 2 : -1;
reloadIndexes();
mColsToScroll -= 1;
}
}else if(mColsToScroll == 0){
mScrollOffset = 0;
mStage = NONE;
}
dirtyCardPos = true;
break;
case SLIDE_DOWN:
mSlide -= 0.05f;
if (mSlide < -1.0f)
{
dirtyFilters = true;
mSlide = 1;
}
else if (mSlide > 0 && mSlide < 0.05)
{
mStage = NONE;
mSlide = 0;
}
dirtyCardPos = true;
break;
case SLIDE_UP:
mSlide += 0.05f;
if (mSlide > 1.0f)
{
dirtyFilters = true;
mSlide = -1;
}
else if (mSlide < 0 && mSlide > -0.05)
{
mStage = NONE;
mSlide = 0;
}
dirtyCardPos = true;
break;
default:
mStage = NONE;
break;
}
}
void UpdateCardPosition(CardRep &rep, int index)
{
int col = index / mRows;
int row = index % mRows;
float colWidth = SCREEN_WIDTH_F / (mCols - 3);
float rowHeight = SCREEN_HEIGHT_F / mRows;
rep.x = (col + mScrollOffset) * colWidth - colWidth;
rep.y = row * rowHeight + mSlide*SCREEN_HEIGHT + rowHeight/2;
if(mCurrentSelection == index)
{
rep.scale = card_scale_big;
if(row == 0){
rep.y += rowHeight * (card_scale_big - card_scale_small);
}else{
rep.y -= rowHeight * (card_scale_big - card_scale_small);
}
}else{
rep.scale = card_scale_small;
}
}
void Render()
{
for(int i = 0; i < int(mCards.size()); ++i)
{
WResourceManager::Instance()->RetrieveCard(getCardRep(i).card);
if(mCurrentSelection != i)
{
renderCard(i, 255);
}
}
if(2 <= mCurrentSelection && mCurrentSelection < 12){
renderCard(mCurrentSelection, 255);
}
}
MTGCard * Click(int x, int y)
{
int n = getCardIndexNextTo(x, y);
DebugTrace("Clicked: " << n);
last_user_activity = 0;
//clicked active card, and no animation is running
if(n == mCurrentSelection && mStage == NONE)
{
return getActiveCard();
}
else if(n < 4 && mStage == NONE)
{
mColsToScroll = 1;
mStage = SCROLL_TO_SELECTED;
}
else if(n >= 12 && mStage == NONE)
{
mColsToScroll = -1;
mStage = SCROLL_TO_SELECTED;
}
else
{
mCurrentSelection = n;
dirtyCardPos = true;
}
return NULL;
}
bool Button(Buttons button)
{
switch(button)
{
case JGE_BTN_LEFT:
mColsToScroll -= 1;
mStage = SCROLL_TO_SELECTED;
last_user_activity = 0;
break;
case JGE_BTN_RIGHT:
mColsToScroll += 1;
mStage = SCROLL_TO_SELECTED;
last_user_activity = 0;
break;
case JGE_BTN_UP:
mStage = SLIDE_UP;
SwitchFilter(1);
last_user_activity = 0;
break;
case JGE_BTN_DOWN:
mStage = SLIDE_DOWN;
SwitchFilter(-1);
last_user_activity = 0;
break;
default:
return false;
}
return true;
}
MTGCard *getActiveCard()
{
if(mCurrentSelection >= 0 && mCurrentSelection < int(mCards.size()))
{
return mCards[mCurrentSelection].card;
}
else
{
return NULL;
}
}
//maintains the current rotation for fluid animations
private:
int mCols;
int mRows;
float mSlide; //[-1,1]. defines, the y-offset of the cards
float mScrollOffset;
int mCurrentSelection; //0 <= mCurrentSelection < mCards.size(). defines the current selected and thus upscaled card
int mColsToScroll; //the number of cols we need to scroll
AnimationStage mStage; // state machine state. for animation purposes
};
#endif //_GRID_DECK_VIEW_H
+2 -1
View File
@@ -6,8 +6,9 @@
#include <hge/hgeparticle.h>
#include "JGE.h"
#include "MTGDefinitions.h"
#include "GameApp.h"
#include "Pos.h"
#include "GuiLayers.h"
#include "WResource_Fwd.h"
class ManaIcon : public Pos
{
-1
View File
@@ -4,7 +4,6 @@
#define MTG_ERROR -1
#include "MTGDefinitions.h"
#include "GameApp.h"
#include "WResourceManager.h"
#include <dirent.h>
#include <Threading.h>
+2
View File
@@ -1,6 +1,8 @@
#ifndef OBJECTANALYTICS_H
#define OBJECTANALYTICS_H
#include <boost/cstdint.hpp>
#ifdef _DEBUG
#define TRACK_OBJECT_USAGE
#endif
-1
View File
@@ -7,7 +7,6 @@
#include <JGui.h>
#include <vector>
#include <string>
#include "GameApp.h"
#include "GameStateOptions.h"
#include "WFilter.h"
#include "WDataSrc.h"
+2
View File
@@ -3,6 +3,8 @@
#include <vector>
class GameObserver;
// Task type constant
#define TASK_BASIC 'B'
+2
View File
@@ -1,3 +1,5 @@
#include "MTGDeck.h"
#ifndef _WFILTER_H_
#define _WFILTER_H_
/**
+1
View File
@@ -8,6 +8,7 @@
class hgeDistortionMesh;
class GameStateOptions;
class SimpleMenu;
/**
@defgroup WGui Basic Gui