Use big digit font to display the kart rank inside of the speedometer.

This commit is contained in:
hiker 2014-06-09 22:38:19 +10:00
parent 508431b030
commit 02b0cfd069
4 changed files with 46 additions and 57 deletions

View File

@ -687,11 +687,11 @@ namespace GUIEngine
{ {
IGUIEnvironment* g_env; IGUIEnvironment* g_env;
Skin* g_skin = NULL; Skin* g_skin = NULL;
ScalableFont* g_font; ScalableFont *g_font;
ScalableFont* g_large_font; ScalableFont *g_large_font;
ScalableFont* g_title_font; ScalableFont *g_title_font;
ScalableFont* g_small_font; ScalableFont *g_small_font;
ScalableFont* g_digit_font; ScalableFont *g_digit_font;
IrrlichtDevice* g_device; IrrlichtDevice* g_device;
IVideoDriver* g_driver; IVideoDriver* g_driver;
@ -1062,7 +1062,7 @@ namespace GUIEngine
ScalableFont* sfont = ScalableFont* sfont =
new ScalableFont(g_env, new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT, file_manager->getAssetChecked(FileManager::FONT,
"StkFont.xml",true).c_str() ); "StkFont.xml",true) );
sfont->setScale(normal_text_scale); sfont->setScale(normal_text_scale);
sfont->setKerningHeight(-5); sfont->setKerningHeight(-5);
g_font = sfont; g_font = sfont;
@ -1070,13 +1070,12 @@ namespace GUIEngine
ScalableFont* digit_font = ScalableFont* digit_font =
new ScalableFont(g_env, new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT, file_manager->getAssetChecked(FileManager::FONT,
"BigDigitFont.xml",true).c_str()); "BigDigitFont.xml",true));
digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one
g_digit_font = digit_font; g_digit_font = digit_font;
Private::font_height = g_font->getDimension( L"X" ).Height; Private::font_height = g_font->getDimension( L"X" ).Height;
ScalableFont* sfont_larger = sfont->getHollowCopy(); ScalableFont* sfont_larger = sfont->getHollowCopy();
sfont_larger->setScale(normal_text_scale*1.4f); sfont_larger->setScale(normal_text_scale*1.4f);
sfont_larger->setKerningHeight(-5); sfont_larger->setKerningHeight(-5);
@ -1097,7 +1096,7 @@ namespace GUIEngine
new ScalableFont(g_env, new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT, file_manager->getAssetChecked(FileManager::FONT,
"title_font.xml", "title_font.xml",
true).c_str() ); true) );
sfont2->m_fallback_font = sfont; sfont2->m_fallback_font = sfont;
// Because the fallback font is much smaller than the title font: // Because the fallback font is much smaller than the title font:
sfont2->m_fallback_font_scale = 4.0f; sfont2->m_fallback_font_scale = 4.0f;

View File

@ -21,9 +21,9 @@ namespace gui
{ {
//! constructor //! constructor
ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename) ScalableFont::ScalableFont(IGUIEnvironment *env, const std::string &filename)
: Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0),
MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("ScalableFont"); setDebugName("ScalableFont");
@ -44,7 +44,7 @@ ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename)
// don't grab environment, to avoid circular references // don't grab environment, to avoid circular references
Driver = Environment->getVideoDriver(); Driver = Environment->getVideoDriver();
SpriteBank = Environment->addEmptySpriteBank(filename); SpriteBank = Environment->addEmptySpriteBank(io::path(filename.c_str()));
if (SpriteBank) if (SpriteBank)
SpriteBank->grab(); SpriteBank->grab();
} }
@ -676,7 +676,6 @@ void ScalableFont::draw(const core::stringw& text,
source, source,
clip, clip,
color, true); color, true);
#ifdef FONT_DEBUG #ifdef FONT_DEBUG
driver->draw2DLine(core::position2d<s32>(dest.UpperLeftCorner.X, dest.UpperLeftCorner.Y), driver->draw2DLine(core::position2d<s32>(dest.UpperLeftCorner.X, dest.UpperLeftCorner.Y),
core::position2d<s32>(dest.UpperLeftCorner.X, dest.LowerRightCorner.Y), core::position2d<s32>(dest.UpperLeftCorner.X, dest.LowerRightCorner.Y),

View File

@ -72,7 +72,7 @@ public:
int m_fallback_kerning_width; int m_fallback_kerning_width;
//! constructor //! constructor
ScalableFont(IGUIEnvironment* env, const io::path& filename); ScalableFont(IGUIEnvironment* env, const std::string &filename);
/** Creates a hollow copy of this font; i.e. the underlying font data is the *same* for /** Creates a hollow copy of this font; i.e. the underlying font data is the *same* for
* both fonts. The advantage of doing this is that you can change "view" parameters * both fonts. The advantage of doing this is that you can change "view" parameters

View File

@ -219,6 +219,8 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
} // renderPlayerView } // renderPlayerView
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Shows the current soccer result.
*/
void RaceGUI::drawScores() void RaceGUI::drawScores()
{ {
SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
@ -271,7 +273,8 @@ void RaceGUI::drawScores()
numLeader++; numLeader++;
offsetX += position.LowerRightCorner.X; offsetX += position.LowerRightCorner.X;
} }
} } // drawScores
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Displays the racing time on the screen.s /** Displays the racing time on the screen.s
*/ */
@ -388,10 +391,10 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart,
const core::recti &viewport, const core::recti &viewport,
const core::vector2df &scaling) const core::vector2df &scaling)
{ {
float minRatio = std::min(scaling.X, scaling.Y); float min_ratio = std::min(scaling.X, scaling.Y);
const int GAUGEWIDTH = 78; const int GAUGEWIDTH = 78;
int gauge_width = (int)(GAUGEWIDTH*minRatio); int gauge_width = (int)(GAUGEWIDTH*min_ratio);
int gauge_height = (int)(GAUGEWIDTH*minRatio); int gauge_height = (int)(GAUGEWIDTH*min_ratio);
float state = (float)(kart->getEnergy()) float state = (float)(kart->getEnergy())
/ kart->getKartProperties()->getNitroMax(); / kart->getKartProperties()->getNitroMax();
@ -581,10 +584,8 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart,
irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count, irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count,
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
} }
} // drawEnergyMeter } // drawEnergyMeter
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -593,10 +594,10 @@ void RaceGUI::drawSpeedAndEnergy(const AbstractKart* kart,
const core::recti &viewport, const core::recti &viewport,
const core::vector2df &scaling) const core::vector2df &scaling)
{ {
float minRatio = std::min(scaling.X, scaling.Y); float min_ratio = std::min(scaling.X, scaling.Y);
const int SPEEDWIDTH = 128; const int SPEEDWIDTH = 128;
int meter_width = (int)(SPEEDWIDTH*minRatio); int meter_width = (int)(SPEEDWIDTH*min_ratio);
int meter_height = (int)(SPEEDWIDTH*minRatio); int meter_height = (int)(SPEEDWIDTH*min_ratio);
drawEnergyMeter(viewport.LowerRightCorner.X , drawEnergyMeter(viewport.LowerRightCorner.X ,
(int)(viewport.LowerRightCorner.Y), (int)(viewport.LowerRightCorner.Y),
@ -699,30 +700,35 @@ void RaceGUI::drawSpeedAndEnergy(const AbstractKart* kart,
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
// Draw Speed in Numbers // Draw rank
WorldWithRank *world = dynamic_cast<WorldWithRank*>(World::getWorld());
core::recti pos; if (world && world->displayRank())
pos.UpperLeftCorner.X=(int)(offset.X + 0.5f*meter_width); {
pos.UpperLeftCorner.Y=(int)(offset.Y - 0.62f*meter_height); core::recti pos;
pos.LowerRightCorner.X=(int)(offset.X + 0.8f*meter_width); pos.UpperLeftCorner.X = (int)(offset.X + 0.5f*meter_width);
pos.LowerRightCorner.Y=(int)(offset.X - 0.5f*meter_height); pos.UpperLeftCorner.Y = (int)(offset.Y - 0.62f*meter_height);
pos.LowerRightCorner.X = (int)(offset.X + 0.8f*meter_width);
pos.LowerRightCorner.Y = (int)(offset.X - 0.5f*meter_height);
gui::ScalableFont* font; gui::ScalableFont* font;
if (pos.getWidth() > 55) font = GUIEngine::getHighresDigitFont();
font = GUIEngine::getLargeFont(); font->setScale(min_ratio * 0.7f);
else if (pos.getWidth() > 40) font->setShadow(video::SColor(255, 128, 0, 0));
font = GUIEngine::getFont(); static video::SColor color = video::SColor(255, 255, 255, 255);
else std::ostringstream oss;
font = GUIEngine::getSmallFont(); oss << kart->getPosition(); // the current font has no . :( << ".";
static video::SColor color = video::SColor(255, 255, 255, 255); pos.LowerRightCorner = core::vector2di(offset.X+int(0.6f*meter_width),
std::ostringstream oss; offset.Y-0.5f*meter_height);
oss << (int)(speed*10); pos.UpperLeftCorner = core::vector2di(offset.X+int(0.6f*meter_width),
offset.Y-0.5f*meter_height);
font->draw(oss.str().c_str(), pos, color); font->draw(oss.str().c_str(), pos, color, true, true);
}
} } // drawSpeedAndEnergy
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Displays the rank and the lap of the kart. /** Displays the rank and the lap of the kart.
@ -755,21 +761,6 @@ void RaceGUI::drawRankLap(const AbstractKart* kart,
static video::SColor color = video::SColor(255, 255, 255, 255); static video::SColor color = video::SColor(255, 255, 255, 255);
WorldWithRank *world = (WorldWithRank*)(World::getWorld()); WorldWithRank *world = (WorldWithRank*)(World::getWorld());
if (world->displayRank())
{
const int rank = kart->getPosition();
font->draw(m_string_rank.c_str(), pos, color);
pos.UpperLeftCorner.Y += font_height;
pos.LowerRightCorner.Y += font_height;
char str[256];
const unsigned int kart_amount = world->getCurrentNumKarts();
sprintf(str, "%d/%d", rank, kart_amount);
font->draw(core::stringw(str).c_str(), pos, color);
pos.UpperLeftCorner.Y += font_height;
pos.LowerRightCorner.Y += font_height;
}
// Don't display laps in follow the leader mode // Don't display laps in follow the leader mode
if(world->raceHasLaps()) if(world->raceHasLaps())