added Reward and Expiration to task list

moved text scroller into DeckMenu class since it is specific to DeckMenu and not GameStateDuel
added new util function "wordWrap"
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-03 00:15:12 +00:00
parent 685626128a
commit 4a3d7faf0a
8 changed files with 133 additions and 71 deletions

View File

@@ -6,13 +6,16 @@
#include "JTypes.h"
#include "GameApp.h"
#include "Translate.h"
#include "TextScroller.h"
#include "Tasks.h"
#include <iomanip>
namespace
{
const unsigned int kPoleWidth = 7;
const unsigned int kVerticalMargin = 16;
const unsigned int kHorizontalMargin = 30;
const signed int kLineHeight = 20;
const signed int kDescriptionVerticalBoxPadding = 5;
const signed int kDescriptionHorizontalBoxPadding = 5;
}
WFont* DeckMenu::titleFont = NULL;
@@ -26,49 +29,64 @@ PIXEL_TYPE DeckMenu::jewelGraphics[9] = {0x3FFFFFFF,0x63645AEA,0x610D0D98,
//
// For the additional info window, maximum characters per line is roughly 30 characters across.
// TODO: figure a way to get incoming text to wrap.
//
//
// used fixed locations where the menu, title and descriptive text are located.
// * menu at (125, 60 )
// * descriptive information 125
// *** Need to make this configurable in a file somewhere to allow for class reuse
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const char * _title)
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title)
: JGuiController(id, listener),
fontId(fontId) {
background = NULL;
mX = 120;
mY = 55;
titleX = 125; // center point in title box
titleY = 28;
titleWidth = 180; // width of inner box of title
descX = 230 + kDescriptionVerticalBoxPadding;
descY = 65 + kDescriptionHorizontalBoxPadding;
descHeight = 145;
descWidth = 220;
statsX = 280;
statsY = 8;
statsHeight = 50;
statsWidth = 227;
avatarX = 230;
avatarY = 8;
int scrollerWidth = 80;
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40 , 230, scrollerWidth, 100, 1, 1);
autoTranslate = true;
maxItems = 7;
mHeight = 2 * kVerticalMargin + ( maxItems * kLineHeight );
mWidth = 0;
mX = 125;
mY = 60;
// where to place the title of the menu
titleX = mX;
titleY = mY - 30;
// we want to cap the deck titles to 15 characters to avoid overflowing deck names
title = _(_title);
// where stats information goes
statsX = 280;
statsY = 8 + kVerticalMargin;
statsHeight = 50;
statsWidth = SCREEN_WIDTH / 2 - 40; // 40 is the width of the right border
// where to place the descripiton information
descX = 229;
descY = 70;
startId = 0;
selectionT = 0;
timeOpen = 0;
closed = false;
++refCount;
selectionTargetY = selectionY = kVerticalMargin;
if (NULL == stars)
stars = NEW hgeParticleSystem(resources.RetrievePSI("stars.psi", resources.GetQuad("stars")));
stars->FireAt(mX, mY);
updateScroller();
}
// TODO: Make this configurable, perhaps by user as part of the theme options.
@@ -80,10 +98,11 @@ JQuad* getBackground()
}
void DeckMenu::Render() {
void DeckMenu::Render()
{
JRenderer * renderer = JRenderer::GetInstance();
WFont * titleFont = resources.GetWFont(Fonts::SMALLFACE_FONT);
WFont * titleFont = resources.GetWFont(Fonts::MAGIC_FONT);
WFont * mFont = resources.GetWFont(fontId);
// figure out where to place the stars initially
@@ -123,15 +142,15 @@ void DeckMenu::Render() {
for (int i = startId; i < startId + maxItems ; i++){
if (i > mCount-1) break;
if ( static_cast<DeckMenuItem*>(mObjects[i])->mY - kLineHeight * startId < mY + height - kLineHeight + 7) {
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*>(mObjects[i]);
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*>(mObjects[i]);
if ( currentMenuItem->mY - kLineHeight * startId < mY + height - kLineHeight + 7) {
if ( currentMenuItem->hasFocus()){
// display the avatar image
if ( currentMenuItem->imageFilename.size() > 0 )
{
JQuad * quad = resources.RetrieveTempQuad( currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR );
if (quad) {
renderer->RenderQuad(quad, 232, 10, 0, 0.9f, 0.9f);
renderer->RenderQuad(quad, avatarX, avatarY);
}
}
// fill in the description part of the screen
@@ -147,11 +166,8 @@ void DeckMenu::Render() {
oss << "Deck: " << currentMenuItem->meta->getName() << endl;
oss << currentMenuItem->meta->getStatsSummary();
mainFont->DrawString( oss.str(), statsX, statsY - kVerticalMargin );
mainFont->DrawString( oss.str(), statsX, statsY );
}
// fill in the bottom section of the screen.
// TODO: add text scroller of Tasks.
}
else {
mFont->SetColor(ARGB(150,255,255,255));
@@ -160,6 +176,10 @@ void DeckMenu::Render() {
}
if (!title.empty())
titleFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER);
scroller->Render();
renderer->RenderQuad(getBackground(), 0, 0 );
}
}
@@ -181,6 +201,8 @@ void DeckMenu::Update(float dt){
closed = false;
timeOpen += dt * 10;
}
scroller->Update(dt);
}
void DeckMenu::Add(int id, const char * text,string desc, bool forceFocus, DeckMetaData * deckMetaData) {
@@ -196,6 +218,22 @@ void DeckMenu::Add(int id, const char * text,string desc, bool forceFocus, DeckM
}
}
void DeckMenu::updateScroller()
{
// add all the items from the Tasks db.
TaskList *taskList = NEW TaskList();
scroller->Reset();
for (vector<Task*>::iterator it = taskList->tasks.begin(); it!=taskList->tasks.end(); it++)
{
ostringstream taskDescription;
taskDescription << "[ " << setw(4) << (*it)->getReward() << " / " << (*it)->getExpiration() << " ] " << (*it)->getDesc() << ". " << endl;
scroller->Add( taskDescription.str() );
}
SAFE_DELETE(taskList);
}
void DeckMenu::Close()
{
timeOpen = -1.0;
@@ -206,3 +244,8 @@ void DeckMenu::Close()
void DeckMenu::destroy(){
SAFE_DELETE(DeckMenu::stars);
}
DeckMenu::~DeckMenu()
{
SAFE_DELETE(scroller);
}