This btw points out another circular dependancy between the texture and the JQuad - a texture owns a bunch of JQuads, yet the renderer uses JQuads and always assumes that the texture is valid. We're going to need to add more defensiveness to JGE to protect against this. Other changes in this check-in: WResourceManager doesn't derive from JResourceManager anymore. It actually didn't require anything from the base, so I killed the dependency. Also cleaned up the notion of a WTrackedQuad in the WCachedResource - it didn't need a separate class, just a better container. I've build this & tested against PSP, win, linux, QT (linux). I haven't tried against iOS and QT Win, or Maemo. If these other platforms are broken, I apologize in advance! - I'm hoping it should be fairly simple to put them back into play.
190 lines
7.0 KiB
C++
190 lines
7.0 KiB
C++
/*
|
|
* 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 <iomanip>
|
|
|
|
SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) :
|
|
JGuiController(id, listener), mFontId(fontId), mCollection(collection)
|
|
{
|
|
mX = 19;
|
|
mY = 66;
|
|
mWidth = 180.0f;
|
|
mTitle = _title;
|
|
mMaxLines = 12;
|
|
|
|
mTextFont = WResourceManager::Instance()->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());
|
|
|
|
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 ) );
|
|
|
|
// currently causes a crash on the PSP when drawing the corners.
|
|
// TODO: clean up the image ot make it loook cleaner. Find solution to load gfx to not crash PSP
|
|
#if 0
|
|
drawBoundingBox( mX, mY, mWidth, textHeight );
|
|
#endif
|
|
mTextFont->DrawString(detailedInformation.c_str(), mX + 9 , mY + 15);
|
|
|
|
}
|
|
|
|
// draws a bounding box around the popup.
|
|
void SimplePopup::drawBoundingBox( float x, float y, float width, float height )
|
|
{
|
|
|
|
//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;
|
|
|
|
// get the information from the cache, if it doesn't exist create an entry
|
|
mStatsWrapper = DeckManager::GetInstance()->getExtendedDeckStats( mDeckInformation, mCollection, (mDeckInformation->getFilename().find("baka") != string::npos) );
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
LOG(" Drawing a Corner! ");
|
|
JRenderer* r = JRenderer::GetInstance();
|
|
JQuadPtr horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
|
|
horizontalBarImage->SetHFlip(flipX);
|
|
horizontalBarImage->SetVFlip(flipY);
|
|
|
|
r->RenderQuad(horizontalBarImage.get(), x, y);
|
|
LOG(" Done Drawing a Corner! ");
|
|
}
|
|
|
|
void SimplePopup::drawHorzPole(string imageName, bool flipX = false, bool flipY = false, float x = 0, float y = 0, float width = SCREEN_WIDTH_F)
|
|
{
|
|
LOG(" Drawing a horizontal border! ");
|
|
JRenderer* r = JRenderer::GetInstance();
|
|
JQuadPtr horizontalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
|
|
if ( horizontalBarImage != NULL )
|
|
{
|
|
horizontalBarImage->SetHFlip(flipX);
|
|
horizontalBarImage->SetVFlip(flipY);
|
|
|
|
r->RenderQuad(horizontalBarImage.get(), x, y, 0, width);
|
|
}
|
|
else
|
|
{
|
|
LOG ( "ERROR: Error trying to render horizontal edge! ");
|
|
}
|
|
LOG(" Done Drawing a horizontal border! ");
|
|
}
|
|
|
|
void SimplePopup::drawVertPole(string imageName, bool flipX = false, bool flipY = false, float x = 0, float y = 0, float height = SCREEN_HEIGHT_F)
|
|
{
|
|
LOG(" Drawing a Vertical border! ");
|
|
JRenderer* r = JRenderer::GetInstance();
|
|
JQuadPtr verticalBarImage = WResourceManager::Instance()->RetrieveTempQuad( imageName, TEXTURE_SUB_5551);
|
|
if ( verticalBarImage != NULL )
|
|
{
|
|
verticalBarImage->SetHFlip(flipX);
|
|
verticalBarImage->SetVFlip(flipY);
|
|
|
|
r->RenderQuad(verticalBarImage.get(), x, y, 0, 1.0f, height);
|
|
}
|
|
else
|
|
{
|
|
LOG ( "ERROR: Error trying to render vertical edge! ");
|
|
}
|
|
LOG(" DONE Drawing a horizontal border! ");
|
|
}
|
|
|
|
|
|
void SimplePopup::Close()
|
|
{
|
|
mClosed = true;
|
|
mCount = 0;
|
|
}
|
|
|
|
SimplePopup::~SimplePopup(void)
|
|
{
|
|
mTextFont = NULL;
|
|
mDeckInformation = NULL;
|
|
}
|
|
|