* 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
+25 -18
View File
@@ -1,6 +1,6 @@
#include "PrecompiledHeader.h"
#include <iomanip>
#include "DeckEditorMenu.h"
#include "PrecompiledHeader.h"
#include <iomanip>
#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;
+35 -21
View File
@@ -9,6 +9,7 @@
#include "TextScroller.h"
#include "Tasks.h"
#include <iomanip>
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;
+11 -4
View File
@@ -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());
}
+2 -2
View File
@@ -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<DeckMetaData *> 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.");