diff --git a/projects/mtg/bin/Res/graphics/DeckMenuBackdrop.png b/projects/mtg/bin/Res/graphics/DeckMenuBackdrop.png index 8d8ddb8b0..eaad689ab 100644 Binary files a/projects/mtg/bin/Res/graphics/DeckMenuBackdrop.png and b/projects/mtg/bin/Res/graphics/DeckMenuBackdrop.png differ diff --git a/projects/mtg/include/DeckMetaData.h b/projects/mtg/include/DeckMetaData.h index 2c2b58551..487e6be6a 100644 --- a/projects/mtg/include/DeckMetaData.h +++ b/projects/mtg/include/DeckMetaData.h @@ -32,7 +32,7 @@ public: DeckMetaData(); DeckMetaData(string filename, Player * statsPlayer); void load(string filename); - void loadStatsForPlayer( Player * statsPlayer, string opponentDeckName = "" ); + void loadStatsForPlayer( Player * statsPlayer, string deckStatsFileName = "" ); // Accessors string getFilename(); @@ -52,6 +52,9 @@ public: }; class DeckMetaDataList { +private: + mapvalues; + public: void invalidate(string filename); DeckMetaData * get(string filename, Player * statsPlayer = NULL); @@ -59,8 +62,6 @@ public: static DeckMetaDataList * decksMetaData; -private: - mapvalues; }; #endif diff --git a/projects/mtg/include/SimplePopup.h b/projects/mtg/include/SimplePopup.h index bc33350c6..6cd49a0f1 100644 --- a/projects/mtg/include/SimplePopup.h +++ b/projects/mtg/include/SimplePopup.h @@ -18,7 +18,7 @@ class SimplePopup: public JGuiController { private: - float mHeight, mWidth, mX, mY; + float mWidth, mX, mY; int mMaxLines; int mFontId; DeckMetaData * mDeckInformation; @@ -28,8 +28,9 @@ private: bool mClosed; MTGAllCards * mCollection; - void drawHorzPole(float x, float y, float width); - void drawVertPole(float x, float y, float height); + void drawHorzPole(string imageName, bool flipX, bool flipY, float x, float y, float width); + void drawCorner(string imageName, bool flipX, bool flipY, float x, float y); + void drawVertPole(string imageName, bool flipX, bool flipY, float x, float y, float height); public: bool autoTranslate; @@ -37,7 +38,7 @@ public: SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL); ~SimplePopup(void); - + void drawBoundingBox( float x, float y, float width, float height ); bool isClosed() { return mClosed; } MTGAllCards* getCollection() { return mCollection; } void Render(); diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index 8f5ba12ab..44c329365 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -15,9 +15,12 @@ namespace const float kVerticalMargin = 16; const float kHorizontalMargin = 20; const float kLineHeight = 20; - const float kDescriptionVerticalBoxPadding = 5; + const float kDescriptionVerticalBoxPadding = 5; const float kDescriptionHorizontalBoxPadding = 5; - const float kMenuFontScale = 1.0f; + + const float kDescriptiveTextFontScale = 0.85f; + const float kDefaultFontScale = 1.0f; + const int DETAILED_INFO_THRESHOLD = 20; } @@ -39,16 +42,16 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve backgroundName = "DeckMenuBackdrop"; mAlwaysShowDetailsButton = false; mSelectedDeck = NULL; - mY = 55; + mY = 50; mWidth = 176; - mX = 125; + mX = 110; - titleX = 130; // center point in title box - titleY = 28; + titleX = 110; // center point in title box + titleY = 15; titleWidth = 180; // width of inner box of title - descX = 230 + kDescriptionVerticalBoxPadding; - descY = 65 + kDescriptionHorizontalBoxPadding; + descX = 260 + kDescriptionVerticalBoxPadding; + descY = 100 + kDescriptionHorizontalBoxPadding; descHeight = 145; descWidth = 220; @@ -56,20 +59,20 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve detailedInfoBoxY = 235; starsOffsetX = 50; - statsX = 280; - statsY = 8; + statsX = 300; + statsY = 15; statsHeight = 50; statsWidth = 227; mSelectedDeckId = startIndex; - avatarX = 230; - avatarY = 8; + avatarX = 232; + avatarY = 11; menuInitialized = false; - float scrollerWidth = 80; - mScroller = NEW TextScroller(Fonts::MAIN_FONT, 40, 230, scrollerWidth, 100, 1, 1); + float scrollerWidth = 60; + mScroller = NEW TextScroller(Fonts::MAIN_FONT, 20, 235, scrollerWidth, 100, 1, 1); mAutoTranslate = true; maxItems = 7; @@ -189,7 +192,6 @@ void DeckMenu::Render() mSelectedDeck = currentMenuItem->meta; WFont *mainFont = resources.GetWFont(Fonts::MAIN_FONT); - // display the "more info" button if special condition is met if (showDetailsScreen()) { @@ -212,6 +214,7 @@ void DeckMenu::Render() } // fill in the description part of the screen string text = currentMenuItem->desc; + mainFont->SetScale(kDescriptiveTextFontScale); mainFont->DrawString(text.c_str(), descX, descY); mFont->SetColor(ARGB(255,255,255,255)); @@ -229,22 +232,22 @@ void DeckMenu::Render() { mFont->SetColor(ARGB(150,255,255,255)); } - mFont->SetScale(kMenuFontScale); + mFont->SetScale(kDefaultFontScale); currentMenuItem->RenderWithOffset(-kLineHeight * startId); } } RenderBackground(); - if (!title.empty()) + mFont->SetScale(kDescriptiveTextFontScale); + mScroller->Render(); + mFont->SetScale(kDefaultFontScale); + + if (!title.empty()) { mFont->SetColor(ARGB(255,255,255,255)); - mFont->SetScale(titleFontScale); mFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER); } - mFont->SetScale(1.0f); - mScroller->Render(); - } void DeckMenu::Update(float dt) diff --git a/projects/mtg/src/GameState.cpp b/projects/mtg/src/GameState.cpp index d1ff35d07..01d717d21 100644 --- a/projects/mtg/src/GameState.cpp +++ b/projects/mtg/src/GameState.cpp @@ -50,31 +50,31 @@ vector GameState::getValidDeckMetaData(const string& path, const std::ostringstream filename; filename << path << "/deck" << nbDecks << ".txt"; DeckMetaData * meta = metas->get(filename.str(), statsPlayer); + string deckStatsFileName; if (meta) { found = 1; if (statsPlayer) { - std::ostringstream smallDeckName; - smallDeckName << smallDeckPrefix << "_deck" << nbDecks; - meta->loadStatsForPlayer(statsPlayer, smallDeckName.str()); + std::ostringstream aiStatsDeckName; + aiStatsDeckName << smallDeckPrefix << "_deck" << nbDecks; + deckStatsFileName = aiStatsDeckName.str(); } else { std::ostringstream playerStatsDeckName; playerStatsDeckName << "stats/player_deck" << nbDecks << ".txt"; - string deckstats = options.profileFile(playerStatsDeckName.str()); - meta->loadStatsForPlayer(NULL, deckstats); + deckStatsFileName = options.profileFile(playerStatsDeckName.str()); } + meta->loadStatsForPlayer(statsPlayer, deckStatsFileName); retList.push_back(meta); nbDecks++; } meta = NULL; } - std::sort(retList.begin(), retList.end(), sortByName); - + std::sort(retList.begin(), retList.end(), sortByName); return retList; } @@ -101,7 +101,6 @@ void GameState::renderDeckMenu(DeckMenu * _menu, const vector& d DeckMetaData * deckMetaData = *i; string deckName = deckMetaData -> getName(); string deckDescription = deckMetaData -> getDescription(); - //int deckId = deckMetaData -> getDeckId(); //do we need this? _menu->Add(deckNumber++, deckName.c_str(), deckDescription.c_str(), false, deckMetaData); } } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 5fbac124f..83a727893 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -127,7 +127,6 @@ void GameStateDuel::Start() deckManager->updateMetaDataList(&playerDeckList, false); playerDeckList.clear(); - DebugTrace("INFO: Player Deck menu has a size of " << sizeof( deckmenu ) ); break; } } @@ -278,7 +277,7 @@ void GameStateDuel::ensureOpponentMenu() { if (opponentMenu == NULL) { - opponentMenu = NEW DeckMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Fonts::OPTION_FONT, "Choose Your Opponent", + opponentMenu = NEW DeckMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Fonts::OPTION_FONT, "Choose Opponent", GameStateDuel::selectedAIDeckId, true); opponentMenu->Add(MENUITEM_RANDOM_AI, "Random"); if (options[Options::EVILTWIN_MODE_UNLOCKED].number) opponentMenu->Add(MENUITEM_EVIL_TWIN, "Evil Twin", _( @@ -690,7 +689,7 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) break; } else if (controlId != MENUITEM_EVIL_TWIN && aiDeckSize > 0) // evil twin - deckNumber = deckManager->getAIDeckOrderList()->at(controlId - 1)->getDeckId(); + deckNumber = deckManager->getAIDeckOrderList()->at(controlId - 1)->getDeckId(); loadPlayer(1, deckNumber, 1); OpponentsDeckid = deckNumber; opponentMenu->Close(); @@ -746,7 +745,8 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) if (mGamePhase == DUEL_STATE_CHOOSE_DECK1) { vector * playerDeck = deckManager->getPlayerDeckOrderList(); - if (!premadeDeck && controlId > 0) deckNumber = playerDeck->at(controlId - 1)->getDeckId(); + if (!premadeDeck && controlId > 0) + deckNumber = playerDeck->at(controlId - 1)->getDeckId(); loadPlayer(0, deckNumber); deckmenu->Close(); mGamePhase = DUEL_STATE_CHOOSE_DECK1_TO_2; diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index ac41db119..952de33d4 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -259,7 +259,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi } else { - primitive->setType(val); + primitive->setType(val); break; } } diff --git a/projects/mtg/src/SimplePopup.cpp b/projects/mtg/src/SimplePopup.cpp index c4f6ec01d..07b09aa7a 100644 --- a/projects/mtg/src/SimplePopup.cpp +++ b/projects/mtg/src/SimplePopup.cpp @@ -1,115 +1,167 @@ -/* - * SimplePopup.cpp - * - * Created on: Nov 18, 2010 - * Author: Michael - */ - -#include "PrecompiledHeader.h" -#include "SimplePopup.h" -#include "JTypes.h" -#include "GameApp.h" -#include "DeckStats.h" -#include "DeckManager.h" -#include - -SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) : - JGuiController(id, listener), mFontId(fontId), mCollection(collection) -{ - mX = 35; - mY = 50; - mTitle = _title; - mMaxLines = 10; - mTextFont = resources.GetWFont(fontId); - this->mCount = 1; - mStatsWrapper = NULL; - Update(deckMetaData); -} - -void SimplePopup::Render() -{ - mClosed = false; - - JRenderer *r = JRenderer::GetInstance(); - string detailedInformation = getDetailedInformation(mDeckInformation->getFilename()); - - mTextFont->SetScale(0.85f); - const float textWidth = 183.0f; - const float textHeight = mTextFont->GetHeight() * 10; - r->DrawRoundRect(mX, mY, textWidth, textHeight, 2.0f, ARGB( 255, 125, 255, 0) ); - r->FillRoundRect(mX, mY, textWidth, textHeight, 2.0f, ARGB( 255, 0, 0, 0 ) ); - - mTextFont->DrawString(detailedInformation.c_str(), mX + 20 , mY + 10); - -} -void SimplePopup::Update(DeckMetaData* selectedDeck) -{ - mDeckInformation = selectedDeck; - SAFE_DELETE(mStatsWrapper); - mStatsWrapper = NEW StatsWrapper(mDeckInformation->getDeckId()); - mStatsWrapper->updateStats(mDeckInformation->getFilename(), mCollection); -} - - -string SimplePopup::getDetailedInformation(string filename) -{ - ostringstream oss; - oss - << "------- Deck Summary -----" << endl - << "Cards: "<< mStatsWrapper->cardCount << endl - << "Creatures: "<< setw(2) << mStatsWrapper->countCreatures - << " Enchantments: " << mStatsWrapper->countEnchantments << endl - << "Instants: " << setw(4) << mStatsWrapper->countInstants - << " Sorceries: " << setw(2) << mStatsWrapper->countSorceries << endl - << "Lands: " - << "A: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] << " " - << "G: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] + mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] << " " - << "R: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_RED ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_RED ] << " " - << "U: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_BLUE ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_BLUE ] << " " - << "B: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_BLACK ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_BLACK ] << " " - << "W: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_WHITE ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_WHITE ] << endl - << " --- Mana Curve --- " << endl; - - for ( int costIdx = 0; costIdx < Constants::STATS_MAX_MANA_COST+1; ++costIdx ) - if ( mStatsWrapper->countCardsPerCost[ costIdx ] > 0 ) - oss << costIdx << ": " << setw(2) << left << mStatsWrapper->countCardsPerCost[ costIdx ] << " "; - - oss << endl; - - oss - << " --- Average Cost --- " << endl - << "Creature: "<< setprecision(2) << mStatsWrapper->avgCreatureCost << endl - << "Mana: " << setprecision(2) << mStatsWrapper->avgManaCost << " " - << "Spell: " << setprecision(2) << mStatsWrapper->avgSpellCost << endl; - - return oss.str(); -} - - void SimplePopup::Update(float dt) -{ - JButton key = mEngine->ReadButton(); - CheckUserInput(key); -} - -void SimplePopup::Close() -{ - mClosed = true; - mCount = 0; -} - -SimplePopup::~SimplePopup(void) -{ - mTextFont = NULL; - mDeckInformation = NULL; - SAFE_DELETE(mStatsWrapper); -} - -void SimplePopup::drawHorzPole(float x, float y, float width) -{ - -} - -void SimplePopup::drawVertPole(float x, float y, float height) -{ - -} +/* + * SimplePopup.cpp + * + * Created on: Nov 18, 2010 + * Author: Michael + */ + +#include "PrecompiledHeader.h" +#include "SimplePopup.h" +#include "JTypes.h" +#include "GameApp.h" +#include "DeckStats.h" +#include "DeckManager.h" +#include + +SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) : + JGuiController(id, listener), mFontId(fontId), mCollection(collection) +{ + mX = 18; + mY = 66; + mWidth = 180.0f; + mTitle = _title; + mMaxLines = 11; + + mTextFont = resources.GetWFont(fontId); + this->mCount = 1; // a hack to ensure the menus do book keeping correctly. Since we aren't adding items to the menu, this is required + mStatsWrapper = NULL; + Update(deckMetaData); +} + +void SimplePopup::Render() +{ + mClosed = false; + + JRenderer *r = JRenderer::GetInstance(); + string detailedInformation = getDetailedInformation(mDeckInformation->getFilename()); + + mTextFont->SetScale(0.85f); + const float textHeight = mTextFont->GetHeight() * mMaxLines; + r->DrawRoundRect(mX, mY, mWidth, textHeight, 2.0f, ARGB( 255, 125, 255, 0) ); + r->FillRoundRect(mX, mY, mWidth, textHeight, 2.0f, ARGB( 255, 0, 0, 0 ) ); + + drawBoundingBox( mX, mY, mWidth, textHeight ); + + mTextFont->DrawString(detailedInformation.c_str(), mX + 20 , mY + 15); + +} + +void SimplePopup::drawBoundingBox( float x, float y, float width, float height ) +{ + JRenderer *r = JRenderer::GetInstance(); + + //draw the corners + string topCornerImageName = "top_corner.png"; + string bottomCornerImageName = "bottom_corner.png"; + string verticalBarImageName = "vert_bar.png"; + string horizontalBarImageName = "top_bar.png"; + + const float boxWidth = ( width + 15 ) / 3.0f; + const float boxHeight = ( height + 15 ) / 3.0f; + + drawHorzPole( horizontalBarImageName, false, false, x, y, boxWidth ); + drawHorzPole( horizontalBarImageName, false, true, x, y + height, boxWidth ); + + drawVertPole( verticalBarImageName, false, false, x, y, boxHeight ); + drawVertPole( verticalBarImageName, true, false, x + width, y, boxHeight ); + + drawCorner( topCornerImageName, false, false, x, y ); + drawCorner( topCornerImageName, true, false, x + width, y ); + drawCorner( bottomCornerImageName, false, false, x, y + height ); + drawCorner( bottomCornerImageName, true, false, x + width, y + height ); +} + +void SimplePopup::Update(DeckMetaData* selectedDeck) +{ + mDeckInformation = selectedDeck; + SAFE_DELETE(mStatsWrapper); + mStatsWrapper = NEW StatsWrapper(mDeckInformation->getDeckId()); + mStatsWrapper->updateStats(mDeckInformation->getFilename(), mCollection); +} + + +string SimplePopup::getDetailedInformation(string filename) +{ + ostringstream oss; + oss + << "------- Deck Summary -----" << endl + << "Cards: "<< mStatsWrapper->cardCount << endl + << "Creatures: "<< setw(2) << mStatsWrapper->countCreatures + << " Enchantments: " << mStatsWrapper->countEnchantments << endl + << "Instants: " << setw(4) << mStatsWrapper->countInstants + << " Sorceries: " << setw(2) << mStatsWrapper->countSorceries << endl + << "Lands: " + << "A: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] << " " + << "G: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] + mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] << " " + << "R: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_RED ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_RED ] << " " + << "U: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_BLUE ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_BLUE ] << " " + << "B: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_BLACK ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_BLACK ] << " " + << "W: " << setw(2) << left << mStatsWrapper->countLandsPerColor[ Constants::MTG_COLOR_WHITE ] + mStatsWrapper->countBasicLandsPerColor[ Constants::MTG_COLOR_WHITE ] << endl + << " --- Mana Curve --- " << endl; + + for ( int costIdx = 0; costIdx < Constants::STATS_MAX_MANA_COST+1; ++costIdx ) + if ( mStatsWrapper->countCardsPerCost[ costIdx ] > 0 ) + oss << costIdx << ": " << setw(2) << left << mStatsWrapper->countCardsPerCost[ costIdx ] << " "; + + oss << endl; + + oss + << " --- Average Cost --- " << endl + << "Creature: "<< setprecision(2) << mStatsWrapper->avgCreatureCost << endl + << "Mana: " << setprecision(2) << mStatsWrapper->avgManaCost << " " + << "Spell: " << setprecision(2) << mStatsWrapper->avgSpellCost << endl; + + return oss.str(); +} + + void SimplePopup::Update(float dt) +{ + JButton key = mEngine->ReadButton(); + CheckUserInput(key); +} + +// drawing routines +void SimplePopup::drawCorner(string imageName, bool flipX, bool flipY, float x, float y) +{ + JRenderer* r = JRenderer::GetInstance(); + JQuad *horizontalBarImage = resources.RetrieveTempQuad( imageName, TEXTURE_SUB_5551); + horizontalBarImage->SetHFlip(flipX); + horizontalBarImage->SetVFlip(flipY); + + r->RenderQuad( horizontalBarImage, x, y); +} + +void SimplePopup::drawHorzPole(string imageName, bool flipX = false, bool flipY = false, float x = 0, float y = 0, float width = SCREEN_WIDTH_F) +{ + JRenderer* r = JRenderer::GetInstance(); + JQuad *horizontalBarImage = resources.RetrieveTempQuad( imageName, TEXTURE_SUB_5551); + horizontalBarImage->SetHFlip(flipX); + horizontalBarImage->SetVFlip(flipY); + + r->RenderQuad( horizontalBarImage, x, y, 0, width ); +} + +void SimplePopup::drawVertPole(string imageName, bool flipX = false, bool flipY = false, float x = 0, float y = 0, float height = SCREEN_HEIGHT_F) +{ + JRenderer* r = JRenderer::GetInstance(); + JQuad *verticalBarImage = resources.RetrieveTempQuad( imageName, TEXTURE_SUB_5551); + verticalBarImage->SetHFlip(flipX); + verticalBarImage->SetVFlip(flipY); + + r->RenderQuad( verticalBarImage, x, y, 0, 1.0f, height); +} + + +void SimplePopup::Close() +{ + mClosed = true; + mCount = 0; +} + +SimplePopup::~SimplePopup(void) +{ + mTextFont = NULL; + mDeckInformation = NULL; + SAFE_DELETE(mStatsWrapper); +} +