From 8ba33c9b5869f2cf5394e98b796c97c408be9f14 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Mon, 8 Nov 2010 11:15:16 +0000 Subject: [PATCH] * updated title font size for deck selection screen to ensure it will always fit * added deck name max pixel size to ensure no deck name overflows into borders of menu. --- projects/mtg/include/DeckMenu.h | 10 +++-- projects/mtg/include/DeckMenuItem.h | 2 +- projects/mtg/src/DeckEditorMenu.cpp | 43 ++++++++++-------- projects/mtg/src/DeckMenu.cpp | 56 +++++++++++++++--------- projects/mtg/src/DeckMenuItem.cpp | 15 +++++-- projects/mtg/src/GameStateDeckViewer.cpp | 4 +- 6 files changed, 81 insertions(+), 49 deletions(-) diff --git a/projects/mtg/include/DeckMenu.h b/projects/mtg/include/DeckMenu.h index 54dd4399f..07d1c9ff2 100644 --- a/projects/mtg/include/DeckMenu.h +++ b/projects/mtg/include/DeckMenu.h @@ -24,12 +24,16 @@ class DeckMenu:public JGuiController{ string backgroundName; int fontId; - std::string title; + string title; + string displayTitle; + WFont * mFont; + float mTitleFontScale; + int maxItems, startId; + float selectionT, selectionY; float timeOpen; - WFont* titleFont; static hgeParticleSystem* stars; void initMenuItems(); @@ -39,7 +43,6 @@ class DeckMenu:public JGuiController{ public: TextScroller * scroller; bool autoTranslate; - JQuad * getBackground(); DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = ""); ~DeckMenu(); @@ -48,6 +51,7 @@ class DeckMenu:public JGuiController{ void Add(int id, const char * Text, string desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL); void Close(); void updateScroller(); + JQuad * getBackground(); float selectionTargetY; bool closed; diff --git a/projects/mtg/include/DeckMenuItem.h b/projects/mtg/include/DeckMenuItem.h index c4d2ab2df..9b33aa7f0 100644 --- a/projects/mtg/include/DeckMenuItem.h +++ b/projects/mtg/include/DeckMenuItem.h @@ -27,7 +27,7 @@ class DeckMenuItem: public JGuiObject string desc; DeckMetaData *meta; - DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL); + DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL, const float &scaleFactor = 1.0f); ~DeckMenuItem(); float mX; float mY; diff --git a/projects/mtg/src/DeckEditorMenu.cpp b/projects/mtg/src/DeckEditorMenu.cpp index d229cc477..db998a39b 100644 --- a/projects/mtg/src/DeckEditorMenu.cpp +++ b/projects/mtg/src/DeckEditorMenu.cpp @@ -1,6 +1,6 @@ -#include "PrecompiledHeader.h" -#include -#include "DeckEditorMenu.h" +#include "PrecompiledHeader.h" +#include +#include "DeckEditorMenu.h" #include "PrecompiledHeader.h" #include "DeckEditorMenu.h" #include "DeckDataWrapper.h" @@ -16,11 +16,12 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const deckTitle = selectedDeck ? selectedDeck->parent->meta_name : ""; - mX = 120; + mX = 123; mY = 70; starsOffsetX = 50; + titleX = 110; // center point in title box - titleY = 34; + titleY = 25; titleWidth = 180; // width of inner box of title descX = 275; @@ -28,11 +29,11 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const descHeight = 154; descWidth = 175; - statsX = 290; - statsY = 15; - statsHeight = 40; - statsWidth = 180; - + statsHeight = 50; + statsWidth = 185; + statsX = 280; + statsY = 12; + avatarX = 222; avatarY = 8; @@ -48,14 +49,20 @@ void DeckEditorMenu::Render() r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0)); DeckMenu::Render(); - WFont *mainFont = resources.GetWFont( Fonts::MAIN_FONT ); - mainFont->DrawString( deckTitle.c_str(), statsX, statsY ); - - if ( stw && selectedDeck ) - drawDeckStatistics(); - -} - + if ( deckTitle.size() > 0 ) + { + WFont *mainFont = resources.GetWFont( Fonts::OPTION_FONT ); + DWORD currentColor = mainFont->GetColor(); + mainFont->SetColor( ARGB(255,255,255,255) ); + mainFont->DrawString( deckTitle.c_str(), statsX + (statsWidth / 2), statsHeight / 2 , JGETEXT_CENTER); + mainFont->SetColor( currentColor ); + } + + if ( stw && selectedDeck ) + drawDeckStatistics(); + +} + void DeckEditorMenu::drawDeckStatistics() { ostringstream deckStatsString; diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index a7700fc3e..e08b1c082 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -9,6 +9,7 @@ #include "TextScroller.h" #include "Tasks.h" #include + namespace { const float kVerticalMargin = 16; @@ -17,7 +18,6 @@ namespace const float kDescriptionVerticalBoxPadding = 5; const float kDescriptionHorizontalBoxPadding = 5; } - #define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) hgeParticleSystem* DeckMenu::stars = NULL; @@ -38,9 +38,9 @@ fontId(fontId) { mY = 55; mWidth = 176; - mX = 122; + mX = 125; - titleX = 125; // center point in title box + titleX = 130; // center point in title box titleY = 28; titleWidth = 180; // width of inner box of title @@ -56,24 +56,31 @@ fontId(fontId) { statsHeight = 50; statsWidth = 227; - menuInitialized = false; - avatarX = 230; avatarY = 8; - float scrollerWidth = 80; + menuInitialized = false; + + float scrollerWidth = 80; scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1); autoTranslate = true; maxItems = 7; - mHeight = 2 * kVerticalMargin + ( maxItems * kLineHeight ); // we want to cap the deck titles to 15 characters to avoid overflowing deck names title = _(_title); - - titleFont = resources.GetWFont(Fonts::OPTION_FONT); + displayTitle = title; + mFont = resources.GetWFont(fontId); + mTitleFontScale = 1.0f; + // determine if scaling is needed to fit the menu title. + while ( mFont->GetStringWidth( displayTitle.c_str() ) > titleWidth ) + { + mTitleFontScale -= 0.05f; + mFont->SetScale( mTitleFontScale ); + } + startId = 0; selectionT = 0; timeOpen = 0; @@ -88,7 +95,7 @@ fontId(fontId) { updateScroller(); } -// TODO: Make this configurable, perhaps by user as part of the theme options. + JQuad* DeckMenu::getBackground() { ostringstream bgFilename; @@ -113,7 +120,6 @@ void DeckMenu::initMenuItems() void DeckMenu::Render() { JRenderer * renderer = JRenderer::GetInstance(); - WFont * mFont = resources.GetWFont(fontId); float height = mHeight; if (!menuInitialized) @@ -170,12 +176,11 @@ void DeckMenu::Render() if (!title.empty()) { - titleFont->SetColor(ARGB(100,255,255,255)); - titleFont->SetScale(.8f); - titleFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER); - titleFont->SetScale(1.0f); + float currentFontScale = mFont->GetScale(); + mFont->SetScale( mTitleFontScale ); + mFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER); + mFont->SetScale( currentFontScale ); } - scroller->Render(); } } @@ -193,10 +198,18 @@ void DeckMenu::Update(float dt){ float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin)*(1+cos(selectionT))/2); float starsY = selectionY + 5 * cos(selectionT*2.35f) + kLineHeight / 2 - kLineHeight * startId; stars->MoveTo( starsX, starsY); - if (timeOpen < 0) { + if (timeOpen < 0) + { timeOpen += dt * 10; - if (timeOpen >= 0) { timeOpen = 0; closed = true; stars->FireAt(mX, mY); } - } else { + if (timeOpen >= 0) + { + timeOpen = 0; + closed = true; + stars->FireAt(mX, mY); + } + } + else + { closed = false; timeOpen += dt * 10; } @@ -205,11 +218,12 @@ void DeckMenu::Update(float dt){ } void DeckMenu::Add(int id, const char * text,string desc, bool forceFocus, DeckMetaData * deckMetaData) { - DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount*kLineHeight, (mCount == 0), autoTranslate, deckMetaData); + DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount*kLineHeight, (mCount == 0), autoTranslate, deckMetaData, 0.8f); menuItem->desc = deckMetaData ? deckMetaData->getDescription() : desc; JGuiController::Add(menuItem); - if (mCount <= maxItems) mHeight += kLineHeight; + if (mCount <= maxItems) + mHeight += kLineHeight; if (forceFocus){ mObjects[mCurr]->Leaving(JGE_BTN_DOWN); mCurr = mCount-1; diff --git a/projects/mtg/src/DeckMenuItem.cpp b/projects/mtg/src/DeckMenuItem.cpp index 675c88287..7a85222d5 100644 --- a/projects/mtg/src/DeckMenuItem.cpp +++ b/projects/mtg/src/DeckMenuItem.cpp @@ -4,7 +4,13 @@ #include "Translate.h" #include "WResourceManager.h" -DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData): JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y) +namespace +{ + const float kMaxDeckNameWidth = 180; // pixel width +} + +DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData, const float &scaleFactor) +: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y), mScale(scaleFactor) { if (autoTranslate) mText = _(text); @@ -14,7 +20,6 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f mScale = 1.0f; mTargetScale = 1.0f; - if (hasFocus) Entering(); @@ -30,7 +35,10 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f void DeckMenuItem::RenderWithOffset(float yOffset) { WFont * mFont = resources.GetWFont(fontId); - mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER); + string displayName = mText; + while ( mFont->GetStringWidth( displayName.c_str() ) > kMaxDeckNameWidth ) + displayName = displayName.substr(0, displayName.size() - 1 ); + mFont->DrawString(displayName.c_str(), mX, mY + yOffset, JGETEXT_CENTER); } void DeckMenuItem::Render() @@ -83,7 +91,6 @@ void DeckMenuItem::Relocate(float x, float y) float DeckMenuItem::GetWidth() { WFont * mFont = resources.GetWFont(fontId); - mFont->SetScale(1.0); return mFont->GetStringWidth(mText.c_str()); } diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 2e6534e50..dd51f7c0e 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -138,7 +138,7 @@ void GameStateDeckViewer::switchDisplay(){ void GameStateDeckViewer::updateDecks(){ SAFE_DELETE(welcome_menu); - welcome_menu = NEW DeckEditorMenu( MENU_DECK_SELECTION, this, Fonts::MAGIC_FONT, "Choose Deck To Edit"); + welcome_menu = NEW DeckEditorMenu( MENU_DECK_SELECTION, this, Fonts::OPTION_FONT, "Choose Deck To Edit"); DeckManager * deckManager = DeckManager::GetInstance(); vector playerDeckList = fillDeckMenu( welcome_menu,options.profileFile()); @@ -166,7 +166,7 @@ void GameStateDeckViewer::buildEditorMenu() SAFE_DELETE( menu ); //Build menu. JRenderer::GetInstance()->FillRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 100, ARGB(0, 0, 0, 0) ); - menu = NEW DeckEditorMenu( MENU_DECK_BUILDER, this, Fonts::MAGIC_FONT, "Deck Editor", myDeck, stw ); + menu = NEW DeckEditorMenu( MENU_DECK_BUILDER, this, Fonts::OPTION_FONT, "Deck Editor", myDeck, stw ); menu->Add( MENU_ITEM_FILTER_BY, "Filter By...", "Narrow down the list of cards. "); menu->Add( MENU_ITEM_SWITCH_DECKS_NO_SAVE, "Switch Decks", "Do not make any changes.\nView another deck.");