* 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.
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-08 11:15:16 +00:00
parent eec0c5b717
commit 8ba33c9b58
6 changed files with 81 additions and 49 deletions
+7 -3
View File
@@ -24,12 +24,16 @@ class DeckMenu:public JGuiController{
string backgroundName; string backgroundName;
int fontId; int fontId;
std::string title; string title;
string displayTitle;
WFont * mFont;
float mTitleFontScale;
int maxItems, startId; int maxItems, startId;
float selectionT, selectionY; float selectionT, selectionY;
float timeOpen; float timeOpen;
WFont* titleFont;
static hgeParticleSystem* stars; static hgeParticleSystem* stars;
void initMenuItems(); void initMenuItems();
@@ -39,7 +43,6 @@ class DeckMenu:public JGuiController{
public: public:
TextScroller * scroller; TextScroller * scroller;
bool autoTranslate; bool autoTranslate;
JQuad * getBackground();
DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = ""); DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = "");
~DeckMenu(); ~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 Add(int id, const char * Text, string desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL);
void Close(); void Close();
void updateScroller(); void updateScroller();
JQuad * getBackground();
float selectionTargetY; float selectionTargetY;
bool closed; bool closed;
+1 -1
View File
@@ -27,7 +27,7 @@ class DeckMenuItem: public JGuiObject
string desc; string desc;
DeckMetaData *meta; 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(); ~DeckMenuItem();
float mX; float mX;
float mY; float mY;
+25 -18
View File
@@ -1,6 +1,6 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include <iomanip> #include <iomanip>
#include "DeckEditorMenu.h" #include "DeckEditorMenu.h"
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "DeckEditorMenu.h" #include "DeckEditorMenu.h"
#include "DeckDataWrapper.h" #include "DeckDataWrapper.h"
@@ -16,11 +16,12 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const
deckTitle = selectedDeck ? selectedDeck->parent->meta_name : ""; deckTitle = selectedDeck ? selectedDeck->parent->meta_name : "";
mX = 120; mX = 123;
mY = 70; mY = 70;
starsOffsetX = 50; starsOffsetX = 50;
titleX = 110; // center point in title box titleX = 110; // center point in title box
titleY = 34; titleY = 25;
titleWidth = 180; // width of inner box of title titleWidth = 180; // width of inner box of title
descX = 275; descX = 275;
@@ -28,11 +29,11 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const
descHeight = 154; descHeight = 154;
descWidth = 175; descWidth = 175;
statsX = 290; statsHeight = 50;
statsY = 15; statsWidth = 185;
statsHeight = 40; statsX = 280;
statsWidth = 180; statsY = 12;
avatarX = 222; avatarX = 222;
avatarY = 8; avatarY = 8;
@@ -48,14 +49,20 @@ void DeckEditorMenu::Render()
r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0)); r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0));
DeckMenu::Render(); DeckMenu::Render();
WFont *mainFont = resources.GetWFont( Fonts::MAIN_FONT ); if ( deckTitle.size() > 0 )
mainFont->DrawString( deckTitle.c_str(), statsX, statsY ); {
WFont *mainFont = resources.GetWFont( Fonts::OPTION_FONT );
if ( stw && selectedDeck ) DWORD currentColor = mainFont->GetColor();
drawDeckStatistics(); 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() void DeckEditorMenu::drawDeckStatistics()
{ {
ostringstream deckStatsString; ostringstream deckStatsString;
+35 -21
View File
@@ -9,6 +9,7 @@
#include "TextScroller.h" #include "TextScroller.h"
#include "Tasks.h" #include "Tasks.h"
#include <iomanip> #include <iomanip>
namespace namespace
{ {
const float kVerticalMargin = 16; const float kVerticalMargin = 16;
@@ -17,7 +18,6 @@ namespace
const float kDescriptionVerticalBoxPadding = 5; const float kDescriptionVerticalBoxPadding = 5;
const float kDescriptionHorizontalBoxPadding = 5; const float kDescriptionHorizontalBoxPadding = 5;
} }
#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
hgeParticleSystem* DeckMenu::stars = NULL; hgeParticleSystem* DeckMenu::stars = NULL;
@@ -38,9 +38,9 @@ fontId(fontId) {
mY = 55; mY = 55;
mWidth = 176; mWidth = 176;
mX = 122; mX = 125;
titleX = 125; // center point in title box titleX = 130; // center point in title box
titleY = 28; titleY = 28;
titleWidth = 180; // width of inner box of title titleWidth = 180; // width of inner box of title
@@ -56,24 +56,31 @@ fontId(fontId) {
statsHeight = 50; statsHeight = 50;
statsWidth = 227; statsWidth = 227;
menuInitialized = false;
avatarX = 230; avatarX = 230;
avatarY = 8; avatarY = 8;
float scrollerWidth = 80;
menuInitialized = false;
float scrollerWidth = 80;
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1); scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1);
autoTranslate = true; autoTranslate = true;
maxItems = 7; maxItems = 7;
mHeight = 2 * kVerticalMargin + ( maxItems * kLineHeight ); mHeight = 2 * kVerticalMargin + ( maxItems * kLineHeight );
// we want to cap the deck titles to 15 characters to avoid overflowing deck names // we want to cap the deck titles to 15 characters to avoid overflowing deck names
title = _(_title); title = _(_title);
displayTitle = title;
titleFont = resources.GetWFont(Fonts::OPTION_FONT); 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; startId = 0;
selectionT = 0; selectionT = 0;
timeOpen = 0; timeOpen = 0;
@@ -88,7 +95,7 @@ fontId(fontId) {
updateScroller(); updateScroller();
} }
// TODO: Make this configurable, perhaps by user as part of the theme options.
JQuad* DeckMenu::getBackground() JQuad* DeckMenu::getBackground()
{ {
ostringstream bgFilename; ostringstream bgFilename;
@@ -113,7 +120,6 @@ void DeckMenu::initMenuItems()
void DeckMenu::Render() void DeckMenu::Render()
{ {
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
WFont * mFont = resources.GetWFont(fontId);
float height = mHeight; float height = mHeight;
if (!menuInitialized) if (!menuInitialized)
@@ -170,12 +176,11 @@ void DeckMenu::Render()
if (!title.empty()) if (!title.empty())
{ {
titleFont->SetColor(ARGB(100,255,255,255)); float currentFontScale = mFont->GetScale();
titleFont->SetScale(.8f); mFont->SetScale( mTitleFontScale );
titleFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER); mFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER);
titleFont->SetScale(1.0f); mFont->SetScale( currentFontScale );
} }
scroller->Render(); scroller->Render();
} }
} }
@@ -193,10 +198,18 @@ void DeckMenu::Update(float dt){
float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin)*(1+cos(selectionT))/2); float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin)*(1+cos(selectionT))/2);
float starsY = selectionY + 5 * cos(selectionT*2.35f) + kLineHeight / 2 - kLineHeight * startId; float starsY = selectionY + 5 * cos(selectionT*2.35f) + kLineHeight / 2 - kLineHeight * startId;
stars->MoveTo( starsX, starsY); stars->MoveTo( starsX, starsY);
if (timeOpen < 0) { if (timeOpen < 0)
{
timeOpen += dt * 10; timeOpen += dt * 10;
if (timeOpen >= 0) { timeOpen = 0; closed = true; stars->FireAt(mX, mY); } if (timeOpen >= 0)
} else { {
timeOpen = 0;
closed = true;
stars->FireAt(mX, mY);
}
}
else
{
closed = false; closed = false;
timeOpen += dt * 10; 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) { 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; menuItem->desc = deckMetaData ? deckMetaData->getDescription() : desc;
JGuiController::Add(menuItem); JGuiController::Add(menuItem);
if (mCount <= maxItems) mHeight += kLineHeight; if (mCount <= maxItems)
mHeight += kLineHeight;
if (forceFocus){ if (forceFocus){
mObjects[mCurr]->Leaving(JGE_BTN_DOWN); mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
mCurr = mCount-1; mCurr = mCount-1;
+11 -4
View File
@@ -4,7 +4,13 @@
#include "Translate.h" #include "Translate.h"
#include "WResourceManager.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) if (autoTranslate)
mText = _(text); mText = _(text);
@@ -14,7 +20,6 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
mScale = 1.0f; mScale = 1.0f;
mTargetScale = 1.0f; mTargetScale = 1.0f;
if (hasFocus) if (hasFocus)
Entering(); Entering();
@@ -30,7 +35,10 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
void DeckMenuItem::RenderWithOffset(float yOffset) void DeckMenuItem::RenderWithOffset(float yOffset)
{ {
WFont * mFont = resources.GetWFont(fontId); 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() void DeckMenuItem::Render()
@@ -83,7 +91,6 @@ void DeckMenuItem::Relocate(float x, float y)
float DeckMenuItem::GetWidth() float DeckMenuItem::GetWidth()
{ {
WFont * mFont = resources.GetWFont(fontId); WFont * mFont = resources.GetWFont(fontId);
mFont->SetScale(1.0);
return mFont->GetStringWidth(mText.c_str()); return mFont->GetStringWidth(mText.c_str());
} }
+2 -2
View File
@@ -138,7 +138,7 @@ void GameStateDeckViewer::switchDisplay(){
void GameStateDeckViewer::updateDecks(){ void GameStateDeckViewer::updateDecks(){
SAFE_DELETE(welcome_menu); 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(); DeckManager * deckManager = DeckManager::GetInstance();
vector<DeckMetaData *> playerDeckList = fillDeckMenu( welcome_menu,options.profileFile()); vector<DeckMetaData *> playerDeckList = fillDeckMenu( welcome_menu,options.profileFile());
@@ -166,7 +166,7 @@ void GameStateDeckViewer::buildEditorMenu()
SAFE_DELETE( menu ); SAFE_DELETE( menu );
//Build menu. //Build menu.
JRenderer::GetInstance()->FillRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 100, ARGB(0, 0, 0, 0) ); 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_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."); menu->Add( MENU_ITEM_SWITCH_DECKS_NO_SAVE, "Switch Decks", "Do not make any changes.\nView another deck.");