diff --git a/projects/mtg/include/CarouselDeckView.h b/projects/mtg/include/CarouselDeckView.h new file mode 100644 index 000000000..f911ba09b --- /dev/null +++ b/projects/mtg/include/CarouselDeckView.h @@ -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_ diff --git a/projects/mtg/include/DeckView.h b/projects/mtg/include/DeckView.h new file mode 100644 index 000000000..4a77a0f67 --- /dev/null +++ b/projects/mtg/include/DeckView.h @@ -0,0 +1,67 @@ +#ifndef _DECK_VIEW_H_ +#define _DECK_VIEW_H_ + +#include + +#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 mCards; +private: + virtual void UpdateViewState(float dt) = 0; + virtual void UpdateCardPosition(CardRep& rep, int index) = 0; +}; + +#endif // _DECK_VIEW_H_ diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 4c0248de8..cd820036b 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -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 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 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); diff --git a/projects/mtg/include/GridDeckView.h b/projects/mtg/include/GridDeckView.h new file mode 100644 index 000000000..6eb2ec104 --- /dev/null +++ b/projects/mtg/include/GridDeckView.h @@ -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 diff --git a/projects/mtg/include/GuiMana.h b/projects/mtg/include/GuiMana.h index d18655bc9..de9f68641 100644 --- a/projects/mtg/include/GuiMana.h +++ b/projects/mtg/include/GuiMana.h @@ -6,8 +6,9 @@ #include #include "JGE.h" #include "MTGDefinitions.h" -#include "GameApp.h" +#include "Pos.h" #include "GuiLayers.h" +#include "WResource_Fwd.h" class ManaIcon : public Pos { diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index c17e83189..fcba1b192 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -4,7 +4,6 @@ #define MTG_ERROR -1 #include "MTGDefinitions.h" -#include "GameApp.h" #include "WResourceManager.h" #include #include diff --git a/projects/mtg/include/ObjectAnalytics.h b/projects/mtg/include/ObjectAnalytics.h index db610a54c..43306f801 100644 --- a/projects/mtg/include/ObjectAnalytics.h +++ b/projects/mtg/include/ObjectAnalytics.h @@ -1,6 +1,8 @@ #ifndef OBJECTANALYTICS_H #define OBJECTANALYTICS_H +#include + #ifdef _DEBUG #define TRACK_OBJECT_USAGE #endif diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 7664e82d8..998d9cb67 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -7,7 +7,6 @@ #include #include #include -#include "GameApp.h" #include "GameStateOptions.h" #include "WFilter.h" #include "WDataSrc.h" diff --git a/projects/mtg/include/Tasks.h b/projects/mtg/include/Tasks.h index 2eb8b7340..b257752a6 100644 --- a/projects/mtg/include/Tasks.h +++ b/projects/mtg/include/Tasks.h @@ -3,6 +3,8 @@ #include +class GameObserver; + // Task type constant #define TASK_BASIC 'B' diff --git a/projects/mtg/include/WFilter.h b/projects/mtg/include/WFilter.h index 2ec34538a..16d30c59d 100644 --- a/projects/mtg/include/WFilter.h +++ b/projects/mtg/include/WFilter.h @@ -1,3 +1,5 @@ +#include "MTGDeck.h" + #ifndef _WFILTER_H_ #define _WFILTER_H_ /** diff --git a/projects/mtg/include/WGui.h b/projects/mtg/include/WGui.h index 60dab9a7b..008d29658 100644 --- a/projects/mtg/include/WGui.h +++ b/projects/mtg/include/WGui.h @@ -8,6 +8,7 @@ class hgeDistortionMesh; class GameStateOptions; +class SimpleMenu; /** @defgroup WGui Basic Gui diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 0c414ae94..490e35488 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -17,6 +17,7 @@ #include "Counters.h" #include "ModRules.h" #include "CardDescriptor.h" +#include "GameApp.h" const float CardGui::Width = 28.0; const float CardGui::Height = 40.0; diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index b399bfb07..462457492 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -6,6 +6,7 @@ #include "MTGDeck.h" #include "Subtypes.h" #include "Translate.h" +#include "GameApp.h" using std::string; diff --git a/projects/mtg/src/CarouselDeckView.cpp b/projects/mtg/src/CarouselDeckView.cpp new file mode 100644 index 000000000..4fbeda9a1 --- /dev/null +++ b/projects/mtg/src/CarouselDeckView.cpp @@ -0,0 +1,184 @@ +#include "CarouselDeckView.h" + +const float CarouselDeckView::scroll_speed = 5.0f; + +CarouselDeckView::CarouselDeckView() : + DeckView(10), mRotation(0), mSlide(0), mScrollTarget(2), mStage(NONE) +{ +} + +CarouselDeckView::~CarouselDeckView() +{} + +void CarouselDeckView::UpdateViewState(float dt) +{ + switch(mStage) + { + case SCROLL_TO_SELECTED: + if(mScrollTarget < 2){ //scroll left + mRotation -= dt * scroll_speed; + if(mRotation <= -1.0f) + { + mRotation += 1.0f; + deck()->prev(); + reloadIndexes(); + mScrollTarget += 1; + } + }else if(mScrollTarget > 2){ + mRotation += dt * scroll_speed; + if(mRotation >= 1.0f) + { + mRotation -= 1.0f; + deck()->next(); + reloadIndexes(); + mScrollTarget -= 1; + } + }else if(mScrollTarget == 2){ + mRotation = 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 CarouselDeckView::UpdateCardPosition(CardRep &rep, int index) +{ + float rotation = mRotation + 8 - index; + + rep.x = x_center + cos((rotation) * M_PI / 12) * (right_border - x_center); + rep.scale = max_scale / 1.12f * cos((rep.x - x_center) * 1.5f / (right_border - x_center)) + 0.2f * max_scale * cos( + cos((rep.x - x_center) * 0.15f / (right_border - x_center))); + rep.y = (SCREEN_HEIGHT_F) / 2.0f + SCREEN_HEIGHT_F * mSlide * (rep.scale + 0.2f); +} + +void CarouselDeckView::Reset() +{ + mRotation = 0; + mSlide = 0; + mScrollTarget = 2; + mStage = NONE; + DeckView::Reset(); +} + +void CarouselDeckView::Render() +{ + // even though we want to draw the cards in a particular z order for layering, we want to prefetch them + // in a different order, ie the center card should appear first, then the adjacent ones + if (WResourceManager::Instance()->IsThreaded()) + { + WResourceManager::Instance()->RetrieveCard(getCardRep(0).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(3).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(4).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(2).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(5).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(1).card); + WResourceManager::Instance()->RetrieveCard(getCardRep(6).card); + } + + renderCard(6); + renderCard(5); + renderCard(4); + renderCard(0); + + if (mRotation < 0.5 && mRotation > -0.5) + { + renderCard(1); + renderCard(3); + renderCard(2); + } + else if (mRotation < -0.5) + { + renderCard(3); + renderCard(2); + renderCard(1); + } +} + +MTGCard * CarouselDeckView::Click(int x, int y) +{ + int n = getCardIndexNextTo(x, y); + last_user_activity = 0; + + //clicked active card, and no animation is running + if(n == 2 && mStage == NONE) + { + return getActiveCard(); + } + + //clicked not the active card, start animation:s + if(n != 2 && mStage == NONE) + { + mScrollTarget = n; + mStage = SCROLL_TO_SELECTED; + } + + return NULL; +} + +bool CarouselDeckView::Button(Buttons button) +{ + switch(button) + { + case JGE_BTN_LEFT: + mScrollTarget -= 1; + mStage = SCROLL_TO_SELECTED; + last_user_activity = 0; + break; + case JGE_BTN_RIGHT: + mScrollTarget += 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 *CarouselDeckView::getActiveCard() +{ + return getCardRep(2).card; +} + diff --git a/projects/mtg/src/DeckView.cpp b/projects/mtg/src/DeckView.cpp new file mode 100644 index 000000000..c76c03ca6 --- /dev/null +++ b/projects/mtg/src/DeckView.cpp @@ -0,0 +1,194 @@ +#include "DeckView.h" + +#include "GameOptions.h" +#include "CardGui.h" + +const float DeckView::max_scale = 0.96f; +const float DeckView::x_center = 180; +const float DeckView::right_border = SCREEN_WIDTH + 180; + +DeckView::DeckView(int numberOfCards) + : dirtyFilters(true), dirtyCardPos(true), last_user_activity(0.0f), mFilter(0), mCurrentDeck(NULL) +{ + mCards.resize(numberOfCards); +} + +DeckView::~DeckView() +{ + +} + +void DeckView::Reset() +{ + dirtyFilters = true; + dirtyCardPos = true; + last_user_activity = 0; + mFilter = 0; + mCurrentDeck = NULL; +} + +void DeckView::Update(float dt) +{ + last_user_activity += dt; + + UpdateViewState(dt); + + if(dirtyCardPos){ + for(unsigned int i = 0; i < mCards.size(); ++i) + { + UpdateCardPosition(mCards[i], i); + } + dirtyCardPos = false; + } +} + +void DeckView::SetDeck(DeckDataWrapper *toShow) +{ + mCurrentDeck = toShow; + reloadIndexes(); +} + +DeckDataWrapper* DeckView::deck() +{ + return mCurrentDeck; +} + +void DeckView::SwitchFilter(int delta) +{ + unsigned int FilterCount = Constants::NB_Colors + 1; + mFilter = (FilterCount + mFilter + delta) % FilterCount; +} + +int DeckView::filter(){ + return mFilter; +} + +void DeckView::reloadIndexes() //fixme: feels ugly. check if we can remove this +{ + for (unsigned int i = 0; i < mCards.size(); i++) + { + mCards[i].card = deck()->getCard(i); + } +} + +DeckView::CardRep& DeckView::getCardRep(unsigned int index) +{ + return mCards[index]; +} + +void DeckView::renderCard(int index, int alpha) +{ + WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); + + const CardRep& cardPosition = getCardRep(index); + + if (!cardPosition.card) return; + + if (!WResourceManager::Instance()->IsThreaded()) + { + JQuadPtr backQuad = WResourceManager::Instance()->GetQuad(kGenericCardID); + JQuadPtr quad; + + int cacheError = CACHE_ERROR_NONE; + + if (!options[Options::DISABLECARDS].number) + { + quad = WResourceManager::Instance()->RetrieveCard(cardPosition.card, RETRIEVE_EXISTING); + cacheError = WResourceManager::Instance()->RetrieveError(); + if (!quad.get() && cacheError != CACHE_ERROR_404) + { + if (last_user_activity > (abs(2 - index) + 1) * NO_USER_ACTIVITY_SHOWCARD_DELAY) + quad = WResourceManager::Instance()->RetrieveCard(cardPosition.card); + else + { + quad = backQuad; + } + } + } + + if (quad.get()) + { + if (quad == backQuad) + { + quad->SetColor(ARGB(255,255,255,255)); + float _scale = cardPosition.scale * (285 / quad->mHeight); + JRenderer::GetInstance()->RenderQuad(quad.get(), cardPosition.x, cardPosition.y, 0.0f, _scale, _scale); + } + else + { + Pos pos = Pos(cardPosition.x, cardPosition.y, cardPosition.scale * 285 / 250, 0.0, 255); + CardGui::DrawCard(cardPosition.card, pos); + } + } + else + { + Pos pos = Pos(cardPosition.x, cardPosition.y, cardPosition.scale * 285 / 250, 0.0, 255); + CardGui::DrawCard(cardPosition.card, pos, DrawMode::kText); + } + } + else + { + int mode = !options[Options::DISABLECARDS].number ? DrawMode::kNormal : DrawMode::kText; + + Pos pos = Pos(cardPosition.x, cardPosition.y, cardPosition.scale * 285 / 250, 0.0, 255); + CardGui::DrawCard(cardPosition.card, pos, mode); + } + + int quadAlpha = alpha; + if (!deck()->count(cardPosition.card)) quadAlpha /= 2; + quadAlpha = 255 - quadAlpha; + if (quadAlpha > 0) + { + JRenderer::GetInstance()->FillRect(cardPosition.x - cardPosition.scale * 100.0f, cardPosition.y - cardPosition.scale * 142.5f, cardPosition.scale * 200.0f, cardPosition.scale * 285.0f, + ARGB(quadAlpha,0,0,0)); + } + if (last_user_activity < 3) + { + int fontAlpha = alpha; + float qtY = cardPosition.y - 135 * cardPosition.scale; + float qtX = cardPosition.x + 40 * cardPosition.scale; + char buffer[4096]; + sprintf(buffer, "x%i", deck()->count(cardPosition.card)); + WFont * font = mFont; + font->SetColor(ARGB(fontAlpha/2,0,0,0)); + JRenderer::GetInstance()->FillRect(qtX, qtY, font->GetStringWidth(buffer) + 6, 16, ARGB(fontAlpha/2,0,0,0)); + font->DrawString(buffer, qtX + 4, qtY + 4); + font->SetColor(ARGB(fontAlpha,255,255,255)); + font->DrawString(buffer, qtX + 2, qtY + 2); + font->SetColor(ARGB(255,255,255,255)); + } +} + +int DeckView::getCardIndexNextTo(int x, int y) +{ + int bestCardIndex = -1; + float bestDistance = 0; + + for(unsigned int i = 0; i < mCards.size(); i++) + { + const CardRep& cardPosition = getCardRep(i); + + float dx = (x - cardPosition.x); + float dy = (y - cardPosition.y); + float dist = dx*dx + dy*dy; + + if(dist < bestDistance || bestCardIndex == -1) + { + bestDistance = dist; + bestCardIndex = i; + } + } + + return bestCardIndex; +} + +int DeckView::getPosition() +{ + if(!mCurrentDeck){ return 0; } + + int total = mCurrentDeck->Size(); + int currentPos = (mCurrentDeck->getOffset() + 3) % total; + + while (currentPos <= 0) currentPos += total; + return currentPos; +} diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 1ce06c2ca..7e2c3bb98 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -21,13 +21,16 @@ #include "SimpleMenu.h" #include "utils.h" #include "AIPlayer.h" +#include "GameApp.h" + +#include "CarouselDeckView.h" +#include "GridDeckView.h" GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) : - GameState(parent, "deckeditor") + GameState(parent, "deckeditor"), mView(NEW GridDeckView()) { bgMusic = NULL; - useFilter = 0; isAIDeckSave = false; mSwitching = false; welcome_menu = NULL; @@ -37,8 +40,6 @@ GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) : source = NULL; hudAlpha = 0; subMenu = NULL; - mRotation = 0; - mSlide = 0; mAlpha = 255; menu = NULL; stw = NULL; @@ -58,6 +59,7 @@ GameStateDeckViewer::~GameStateDeckViewer() SAFE_DELETE(statsPrevButton); SAFE_DELETE(filterButton); SAFE_DELETE(toggleViewButton); + SAFE_DELETE(mView); if (myDeck) { @@ -72,24 +74,6 @@ GameStateDeckViewer::~GameStateDeckViewer() SAFE_DELETE(filterMenu); } -void GameStateDeckViewer::rotateCards(int direction) -{ - int left = direction; - if (left) - displayed_deck->next(); - else - displayed_deck->prev(); - loadIndexes(); - - int total = displayed_deck->Size(); - if (total) - { - lastPos = getCurrentPos(); - lastTotal = total; - } - -} - void GameStateDeckViewer::rebuildFilters() { if (!filterMenu) filterMenu = NEW WGuiFilters("Filter by...", NULL); @@ -97,7 +81,7 @@ void GameStateDeckViewer::rebuildFilters() SAFE_DELETE(source); source = NEW WSrcDeckViewer(myDeck, myCollection); filterMenu->setSrc(source); - if (displayed_deck != myDeck) source->swapSrc(); + if (mView->deck() != myDeck) source->swapSrc(); filterMenu->Finish(true); // no stats need updating if there isn't a deck to update @@ -107,58 +91,28 @@ void GameStateDeckViewer::rebuildFilters() void GameStateDeckViewer::updateFilters() { - if (!displayed_deck) return; + if (!mView->deck() || !filterMenu) return; - filterMenu->recolorFilter(useFilter - 1); + filterMenu->recolorFilter(mView->filter() - 1); filterMenu->Finish(true); - int totalAfter = displayed_deck->Size(); - if (totalAfter && lastTotal) - { - - //This part is a hack. I don't understand why in some cases "displayed_deck's" currentPos is not 0 at this stage - { - while (int currentPos = displayed_deck->getOffset()) - { - if (currentPos > 0) - displayed_deck->prev(); - else - displayed_deck->next(); - } - } - - int pos = (totalAfter * lastPos) / lastTotal; - for (int i = 0; i < pos - 3; ++i) - { // "-3" because card "0" is displayed at position 3 initially - displayed_deck->next(); - } - } stw->updateStats( myDeck );; return; } -void GameStateDeckViewer::loadIndexes() +void GameStateDeckViewer::toggleCollection() { - for (int i = 0; i < 7; i++) + if (mView->deck() == myCollection) { - cardIndex[i] = displayed_deck->getCard(i); - } -} - -void GameStateDeckViewer::switchDisplay() -{ - if (displayed_deck == myCollection) - { - displayed_deck = myDeck; + mView->SetDeck(myDeck); toggleDeckButton->setText("View Collection"); } else { toggleDeckButton->setText("View Deck"); - displayed_deck = myCollection; + mView->SetDeck(myCollection); } source->swapSrc(); updateFilters(); - loadIndexes(); } void GameStateDeckViewer::updateDecks() @@ -208,20 +162,18 @@ void GameStateDeckViewer::Start() subMenu = NULL; myDeck = NULL; mStage = STAGE_WELCOME; - mRotation = 0; - mSlide = 0; + mView->Reset(); mAlpha = 255; last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; onScreenTransition = 0; - useFilter = 0; - lastPos = 0; - lastTotal = 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); - displayed_deck = myCollection; + mView->SetDeck(myCollection); //Icons mIcons = manaIcons; @@ -250,7 +202,7 @@ void GameStateDeckViewer::Start() GameApp::playMusic("Track1.mp3"); - loadIndexes(); + mView->reloadIndexes(); mEngine->ResetInput(); JRenderer::GetInstance()->EnableVSync(true); } @@ -282,9 +234,9 @@ void GameStateDeckViewer::End() void GameStateDeckViewer::addRemove(MTGCard * card) { if (!card) return; - if (displayed_deck->Remove(card, 1, (displayed_deck == myDeck))) + if (mView->deck()->Remove(card, 1, (mView->deck() == myDeck))) { - if (displayed_deck == myCollection) + if (mView->deck() == myCollection) { myDeck->Add(card); myDeck->Sort(WSrcCards::SORT_ALPHA); @@ -297,7 +249,7 @@ void GameStateDeckViewer::addRemove(MTGCard * card) myCollection->validate(); myDeck->validate(); stw->needUpdate = true; - loadIndexes(); + mView->reloadIndexes(); } void GameStateDeckViewer::saveDeck() @@ -342,8 +294,8 @@ void GameStateDeckViewer::sellCard() SAFE_DELETE(subMenu); char buffer[4096]; { - MTGCard * card = cardIndex[2]; - if (card && displayed_deck->count(card)) + MTGCard * card = mView->getActiveCard(); + if (card && mView->deck()->count(card)) { price = pricelist->getSellPrice(card->getMTGId()); sprintf(buffer, "%s : %i %s", _(card->data->getName()).c_str(), price, _("credits").c_str()); @@ -387,13 +339,7 @@ void GameStateDeckViewer::RenderButtons() } void GameStateDeckViewer::Update(float dt) -{ - - int x, y; - unsigned int distance2; - unsigned int minDistance2 = -1; - int n = 0; - +{ if (options.keypadActive()) { options.keypadUpdate(dt); @@ -435,27 +381,16 @@ void GameStateDeckViewer::Update(float dt) } if (mStage == STAGE_WAITING || mStage == STAGE_ONSCREEN_MENU) { - switch (mEngine->ReadButton()) + JButton button = mEngine->ReadButton(); + switch (button) { case JGE_BTN_LEFT: - last_user_activity = 0; - mStage = STAGE_TRANSITION_LEFT; - break; case JGE_BTN_RIGHT: - last_user_activity = 0; - mStage = STAGE_TRANSITION_RIGHT; - break; case JGE_BTN_UP: - last_user_activity = 0; - mStage = STAGE_TRANSITION_UP; - useFilter++; - if (useFilter >= MAX_SAVED_FILTERS) useFilter = 0; - break; case JGE_BTN_DOWN: + mView->Button(button); last_user_activity = 0; - mStage = STAGE_TRANSITION_DOWN; - useFilter--; - if (useFilter < 0) useFilter = MAX_SAVED_FILTERS - 1; + mStage = STAGE_WAITING; break; case JGE_BTN_CANCEL: options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number; @@ -464,45 +399,35 @@ void GameStateDeckViewer::Update(float dt) if (last_user_activity > 0.2) { last_user_activity = 0; - switchDisplay(); + toggleCollection(); } break; case JGE_BTN_OK: + { + // verify that none of the buttons fired + if (userPressedButton()) + { + Update(dt); + break; + } + + int x, y; if (mEngine->GetLeftClickCoordinates(x, y)) - { - // verify that none of the buttons fired - if (userPressedButton()) - { - Update(dt); - break; - } - - 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 > .05) { last_user_activity = 0; - addRemove(cardIndex[2]); + mEngine->LeftClickedProcessed(); + if(mView->Click(x, y) == mView->getActiveCard()) + { + addRemove(mView->getActiveCard()); + } + }else{ + last_user_activity = 0; + addRemove(mView->getActiveCard()); } + mStage = STAGE_WAITING; break; + } case JGE_BTN_SEC: sellCard(); break; @@ -520,7 +445,7 @@ void GameStateDeckViewer::Update(float dt) SAFE_DELETE(source); source = NEW WSrcDeckViewer(myDeck, myCollection); filterMenu->setSrc(source); - if (displayed_deck != myDeck) source->swapSrc(); + if (mView->deck() != myDeck) source->swapSrc(); } filterMenu->Entering(JGE_BTN_NONE); break; @@ -557,103 +482,15 @@ 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) - { - mRotation -= dt * MED_SPEED; - if (mRotation < -1.0f) - { - do - { - rotateCards(mStage); - mRotation += 1; - } while (mRotation < -1.0f); - mStage = STAGE_WAITING; - mRotation = 0; - } - } - else if (mStage == STAGE_TRANSITION_LEFT) - { - mRotation += dt * MED_SPEED; - if (mRotation > 1.0f) - { - do - { - rotateCards(mStage); - mRotation -= 1; - } while (mRotation > 1.0f); - mStage = STAGE_WAITING; - mRotation = 0; - } - } - } - if (mStage == STAGE_TRANSITION_DOWN || mStage == STAGE_TRANSITION_UP) - { - if (mStage == STAGE_TRANSITION_DOWN) - { - mSlide -= 0.05f; - if (mSlide < -1.0f) - { - updateFilters(); - loadIndexes(); - mSlide = 1; - } - else if (mSlide > 0 && mSlide < 0.05) - { - mStage = STAGE_WAITING; - mSlide = 0; - } - } - if (mStage == STAGE_TRANSITION_UP) - { - mSlide += 0.05f; - if (mSlide > 1.0f) - { - updateFilters(); - loadIndexes(); - mSlide = -1; - } - else if (mSlide < 0 && mSlide > -0.05) - { - mStage = STAGE_WAITING; - mSlide = 0; - } - } + mView->Update(dt); + if(mView->dirtyFilters){ + updateFilters(); + mView->reloadIndexes(); + mView->dirtyFilters = false; } - else if (mStage == STAGE_WELCOME) + + if (mStage == STAGE_WELCOME) welcome_menu->Update(dt); else if (mStage == STAGE_MENU) menu->Update(dt); @@ -667,19 +504,20 @@ void GameStateDeckViewer::Update(float dt) //useFilter = 0; filterMenu->Finish(true); filterMenu->Update(dt); - loadIndexes(); + mView->reloadIndexes(); return; } if (!filterMenu->isFinished()) { filterMenu->CheckUserInput(key); filterMenu->Update(dt); + mView->reloadIndexes(); } else { mStage = STAGE_WAITING; updateFilters(); - loadIndexes(); + mView->reloadIndexes(); } } } @@ -693,16 +531,16 @@ void GameStateDeckViewer::renderOnScreenBasicInfo() float y = 0; int allCopies, nowCopies; - nowCopies = displayed_deck->getCount(WSrcDeck::FILTERED_COPIES); - allCopies = displayed_deck->getCount(WSrcDeck::UNFILTERED_COPIES); - WCardFilter * wc = displayed_deck->getFiltersRoot(); + nowCopies = mView->deck()->getCount(WSrcDeck::FILTERED_COPIES); + allCopies = mView->deck()->getCount(WSrcDeck::UNFILTERED_COPIES); + WCardFilter * wc = mView->deck()->getFiltersRoot(); if (wc) - sprintf(buffer, "%s %i of %i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ", nowCopies, allCopies, - displayed_deck->getCount(WSrcDeck::FILTERED_UNIQUE)); + sprintf(buffer, "%s %i of %i cards (%i unique)", (mView->deck() == myDeck) ? "DECK: " : " ", nowCopies, allCopies, + mView->deck()->getCount(WSrcDeck::FILTERED_UNIQUE)); else - sprintf(buffer, "%s%i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ", allCopies, displayed_deck->getCount( - WSrcDeck::UNFILTERED_UNIQUE)); + sprintf(buffer, "%s%i cards (%i unique)", (mView->deck() == myDeck) ? "DECK: " : " ", allCopies, + mView->deck()->getCount(WSrcDeck::UNFILTERED_UNIQUE)); float w = mFont->GetStringWidth(buffer); PIXEL_TYPE backupColor = mFont->GetColor(); @@ -712,34 +550,21 @@ void GameStateDeckViewer::renderOnScreenBasicInfo() mFont->DrawString(buffer, SCREEN_WIDTH - 22, y + 15, JGETEXT_RIGHT); mFont->SetColor(backupColor); - if (useFilter != 0) renderer->RenderQuad(mIcons[useFilter - 1].get(), SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5); -} - -//returns position of the current card (cusor) in the currently viewed color/filter -int GameStateDeckViewer::getCurrentPos() -{ - int total = displayed_deck->Size(); - - int currentPos = displayed_deck->getOffset(); - currentPos += 2; //we start by displaying card number 3 - currentPos = currentPos % total + 1; - if (currentPos < 0) currentPos = (total + currentPos); - if (!currentPos) currentPos = total; - return currentPos; + if (mView->filter() != 0) renderer->RenderQuad(mIcons[mView->filter() - 1].get(), SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5); } void GameStateDeckViewer::renderSlideBar() { WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); - int total = displayed_deck->Size(); + int total = mView->deck()->Size(); if (total == 0) return; float filler = 15; float y = SCREEN_HEIGHT_F - 25; float bar_size = SCREEN_WIDTH_F - 2 * filler; JRenderer * r = JRenderer::GetInstance(); - int currentPos = getCurrentPos(); + int currentPos = mView->getPosition(); float cursor_pos = bar_size * currentPos / total; @@ -750,7 +575,7 @@ void GameStateDeckViewer::renderSlideBar() r->DrawLine(filler + cursor_pos, y, filler + cursor_pos, y + 5, ARGB(hudAlpha,255,255,255)); char buffer[256]; string deckname = _("Collection"); - if (displayed_deck == myDeck) + if (mView->deck() == myDeck) { deckname = _("Deck"); } @@ -849,7 +674,7 @@ void GameStateDeckViewer::renderOnScreenMenu() font->DrawString(_("Toggle Images"), rightPspX - 35, rightPspY - 40); - if (displayed_deck == myCollection) + if (mView->deck() == myCollection) { font->DrawString(_("Add card"), rightPspX + 20, rightPspY - 15); font->DrawString(_("View Deck"), rightPspX - 20, rightPspY - 15, JGETEXT_RIGHT); @@ -864,7 +689,7 @@ void GameStateDeckViewer::renderOnScreenMenu() font->DrawString(_("menu"), SCREEN_WIDTH - 35 + rightTransition, SCREEN_HEIGHT - 15); font->DrawString(_("filter"), SCREEN_WIDTH - 95 + rightTransition, SCREEN_HEIGHT - 15); - if (displayed_deck == myCollection) + if (mView->deck() == myCollection) { font->DrawString(_("in: collection"), 5 - leftTransition, 5); font->DrawString(_("Use SQUARE to view your deck,"), SCREEN_WIDTH - 200 + rightTransition, 5); @@ -883,7 +708,7 @@ void GameStateDeckViewer::renderOnScreenMenu() // print stuff here about the editor commands float textYOffset = SCREEN_HEIGHT_F/2; font->DrawString(_("Click on the card image"), SCREEN_WIDTH - 200 + rightTransition, textYOffset - (2 * fH)); - if (displayed_deck == myCollection) + if (mView->deck() == myCollection) font->DrawString(_("to add card to deck."), SCREEN_WIDTH - 200 + rightTransition, textYOffset - fH); else font->DrawString(_("to remove card from deck."), SCREEN_WIDTH - 200 + rightTransition, textYOffset - fH); @@ -1399,152 +1224,17 @@ void GameStateDeckViewer::renderOnScreenMenu() } } - -void GameStateDeckViewer::renderCard(int id, float rotation) -{ - WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); - MTGCard * card = cardIndex[id]; - - float max_scale = 0.96f; - float x_center_0 = 180; - float right_border = SCREEN_WIDTH + 180; - - float x_center = x_center_0 + cos((rotation + 8 - id) * M_PI / 12) * (right_border - x_center_0); - float scale = max_scale / 1.12f * cos((x_center - x_center_0) * 1.5f / (right_border - x_center_0)) + 0.2f * max_scale * cos( - cos((x_center - x_center_0) * 0.15f / (right_border - x_center_0))); - float x = x_center; // ; - - float y = (SCREEN_HEIGHT_F) / 2.0f + SCREEN_HEIGHT_F * mSlide * (scale + 0.2f); - - cardsCoordinates[id] = pair(x, y); - - int alpha = (int) (255 * (scale + 1.0 - max_scale)); - - if (!card) return; - - if (!WResourceManager::Instance()->IsThreaded()) - { - JQuadPtr backQuad = WResourceManager::Instance()->GetQuad(kGenericCardID); - JQuadPtr quad; - - int cacheError = CACHE_ERROR_NONE; - - if (!options[Options::DISABLECARDS].number) - { - quad = WResourceManager::Instance()->RetrieveCard(card, RETRIEVE_EXISTING); - cacheError = WResourceManager::Instance()->RetrieveError(); - if (!quad.get() && cacheError != CACHE_ERROR_404) - { - if (last_user_activity > (abs(2 - id) + 1) * NO_USER_ACTIVITY_SHOWCARD_DELAY) - quad = WResourceManager::Instance()->RetrieveCard(card); - else - { - quad = backQuad; - } - } - } - - if (quad.get()) - { - if (quad == backQuad) - { - quad->SetColor(ARGB(255,255,255,255)); - float _scale = scale * (285 / quad->mHeight); - JRenderer::GetInstance()->RenderQuad(quad.get(), x, y, 0.0f, _scale, _scale); - } - else - { - Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255); - CardGui::DrawCard(card, pos); - } - } - else - { - Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255); - CardGui::DrawCard(card, pos, DrawMode::kText); - } - } - else - { - int mode = !options[Options::DISABLECARDS].number ? DrawMode::kNormal : DrawMode::kText; - - Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255); - CardGui::DrawCard(card, pos, mode); - } - - int quadAlpha = alpha; - if (!displayed_deck->count(card)) quadAlpha /= 2; - quadAlpha = 255 - quadAlpha; - if (quadAlpha > 0) - { - JRenderer::GetInstance()->FillRect(x - scale * 100.0f, y - scale * 142.5f, scale * 200.0f, scale * 285.0f, - ARGB(quadAlpha,0,0,0)); - } - if (last_user_activity < 3) - { - int fontAlpha = alpha; - float qtY = y - 135 * scale; - float qtX = x + 40 * scale; - char buffer[4096]; - sprintf(buffer, "x%i", displayed_deck->count(card)); - WFont * font = mFont; - font->SetColor(ARGB(fontAlpha/2,0,0,0)); - JRenderer::GetInstance()->FillRect(qtX, qtY, font->GetStringWidth(buffer) + 6, 16, ARGB(fontAlpha/2,0,0,0)); - font->DrawString(buffer, qtX + 4, qtY + 4); - font->SetColor(ARGB(fontAlpha,255,255,255)); - font->DrawString(buffer, qtX + 2, qtY + 2); - font->SetColor(ARGB(255,255,255,255)); - } -} - -void GameStateDeckViewer::renderCard(int id) -{ - renderCard(id, 0); -} - void GameStateDeckViewer::Render() { 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) + if (mView->deck() == myDeck && mStage != STAGE_MENU) renderDeckBackground(); - int order[3] = { 1, 2, 3 }; - if (mRotation < 0.5 && mRotation > -0.5) - { - order[1] = 3; - order[2] = 2; - } - else if (mRotation < -0.5) - { - order[0] = 3; - order[2] = 1; - } - // even though we want to draw the cards in a particular z order for layering, we want to prefetch them - // in a different order, ie the center card should appear first, then the adjacent ones - if (WResourceManager::Instance()->IsThreaded()) - { - WResourceManager::Instance()->RetrieveCard(cardIndex[0]); - WResourceManager::Instance()->RetrieveCard(cardIndex[3]); - WResourceManager::Instance()->RetrieveCard(cardIndex[4]); - WResourceManager::Instance()->RetrieveCard(cardIndex[2]); - WResourceManager::Instance()->RetrieveCard(cardIndex[5]); - WResourceManager::Instance()->RetrieveCard(cardIndex[1]); - WResourceManager::Instance()->RetrieveCard(cardIndex[6]); - } + mView->Render(); - renderCard(6, mRotation); - renderCard(5, mRotation); - renderCard(4, mRotation); - renderCard(0, mRotation); - - for (int i = 0; i < 3; i++) - { - renderCard(order[i], mRotation); - } - - if (displayed_deck->Size() > 0) + if (mView->deck()->Size() > 0) { setButtonState(true); renderSlideBar(); @@ -1604,7 +1294,7 @@ int GameStateDeckViewer::loadDeck(int deckid) SAFE_DELETE(myCollection); myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection->Sort(WSrcCards::SORT_ALPHA); - displayed_deck = myCollection; + mView->SetDeck(myCollection); char deckname[256]; sprintf(deckname, "deck%i.txt", deckid); @@ -1648,7 +1338,7 @@ int GameStateDeckViewer::loadDeck(int deckid) myDeck->Sort(WSrcCards::SORT_ALPHA); SAFE_DELETE(filterMenu); rebuildFilters(); - loadIndexes(); + mView->reloadIndexes(); return 1; } @@ -1689,9 +1379,9 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) SAFE_DELETE(myCollection); myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection->Sort(WSrcCards::SORT_ALPHA); - displayed_deck = myCollection; + mView->SetDeck(myCollection); rebuildFilters(); - loadIndexes(); + mView->reloadIndexes(); mStage = STAGE_WELCOME; break; } @@ -1764,7 +1454,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) { case MENU_ITEM_YES: { - MTGCard * card = cardIndex[2]; + MTGCard * card = mView->getActiveCard(); if (card) { int rnd = (rand() % 25); @@ -1772,10 +1462,10 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) price = price - (rnd * price) / 100; pricelist->setPrice(card->getMTGId(), price); playerdata->collection->remove(card->getMTGId()); - displayed_deck->Remove(card, 1); - displayed_deck->validate(); + mView->deck()->Remove(card, 1); + mView->deck()->validate(); stw->needUpdate = true; - loadIndexes(); + mView->reloadIndexes(); } } case MENU_ITEM_NO: @@ -1816,9 +1506,10 @@ void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity) else offset = 2 + numCards; - mEngine->LeftClickedProcessed(); - mEngine->LeftClicked(static_cast(cardsCoordinates[offset].first), static_cast(cardsCoordinates[offset].second)); - mEngine->HoldKey_NoRepeat(JGE_BTN_OK); + //TODO: FIXME + //mEngine->LeftClickedProcessed(); + //mEngine->LeftClicked(static_cast(cardsCoordinates[offset].first), static_cast(cardsCoordinates[offset].second)); + //mEngine->HoldKey_NoRepeat(JGE_BTN_OK); } } else diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index c2b4174da..878415184 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -14,6 +14,7 @@ #include "Translate.h" #include "Rules.h" #include "ModRules.h" +#include "GameApp.h" #ifdef TESTSUITE #include "TestSuiteAI.h" diff --git a/projects/mtg/src/GridDeckView.cpp b/projects/mtg/src/GridDeckView.cpp new file mode 100644 index 000000000..cb81a0065 --- /dev/null +++ b/projects/mtg/src/GridDeckView.cpp @@ -0,0 +1 @@ +#include "GridDeckView.h" diff --git a/projects/mtg/src/GuiMana.cpp b/projects/mtg/src/GuiMana.cpp index 63d72936d..c4ca3d257 100644 --- a/projects/mtg/src/GuiMana.cpp +++ b/projects/mtg/src/GuiMana.cpp @@ -3,6 +3,7 @@ #include "GuiMana.h" #include "OptionItem.h" #include "Player.h" +#include "GameApp.h" //using std::cout; using std::endl; diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index df9edceab..4fee0a0ea 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -7,6 +7,7 @@ #include "TranslateKeys.h" #include "StyleManager.h" #include +#include "SimpleMenu.h" //OptionItem OptionItem::OptionItem(int _id, string _displayValue) : diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index 9d7ed8ae9..b6e5e4d56 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -6,6 +6,7 @@ #include "Player.h" #include "AIMomirPlayer.h" +#include "GameApp.h" #include "MTGGameZones.h" #include "MTGAbility.h" #include "AllAbilities.h" diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index 98eacc5d7..8a6daed56 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -13,6 +13,7 @@ #include "PlayerData.h" #include "MTGDeck.h" #include "WFont.h" +#include "GameApp.h" #include #define LINE_SPACE 2 diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index 234b2c5a2..4a1308f1b 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -6,6 +6,9 @@ #include "Subtypes.h" #include "TranslateKeys.h" #include +#include "SimpleMenu.h" +#include "Pos.h" +#include "CardGui.h" /** Provides an interface to retrieve some standardized colors. The idea here is that a child of WGuiBase diff --git a/projects/mtg/wagic-qt.pro b/projects/mtg/wagic-qt.pro index 3084f5f32..248635a43 100644 --- a/projects/mtg/wagic-qt.pro +++ b/projects/mtg/wagic-qt.pro @@ -106,6 +106,9 @@ SOURCES += \ src/DeckMenuItem.cpp\ src/DeckMetaData.cpp\ src/DeckStats.cpp\ + src/DeckView.cpp\ + src/CarouselDeckView.cpp\ + src/GridDeckView.cpp\ src/DuelLayers.cpp\ src/Effects.cpp\ src/ExtraCost.cpp\ @@ -301,7 +304,10 @@ HEADERS += \ include/SimpleMenu.h\ include/SimpleButton.h\ include/InteractiveButton.h\ - include/ObjectAnalytics.h + include/ObjectAnalytics.h\ + include/DeckView.h\ + include/CarouselDeckView.h\ + include/GridDeckView.h # JGE, could probably be moved outside SOURCES += \