1) Added general messages (fastest lap etc) and plunger-in-face

2) Removed unused plib font objects - hooray :)


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3754 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-07-16 03:24:17 +00:00
parent 9920c72415
commit 9563b78500
11 changed files with 52 additions and 404 deletions

View File

@@ -76,8 +76,6 @@ supertuxkart_SOURCES = \
gui/credits.hpp \
gui/engine.cpp \
gui/engine.hpp \
gui/font.cpp \
gui/font.hpp \
gui/kart_selection.cpp \
gui/kart_selection.hpp \
gui/modaldialog.cpp \

View File

@@ -30,7 +30,6 @@
#include "config/user_config.hpp"
#include "graphics/material_manager.hpp"
#include "gui/engine.hpp"
#include "gui/font.hpp"
#include "gui/state_manager.hpp"
#include "io/file_manager.hpp"
#include "items/item_manager.hpp"
@@ -179,16 +178,10 @@ void IrrDriver::changeResolution()
projectile_manager -> loadData();
attachment_manager -> loadModels();
//FIXME: the font reinit funcs should be inside the font class
//Reinit fonts
delete_fonts();
init_fonts();
StateManager::initGUI();
GUIEngine::reshowCurrentScreen();
// startScreen -> installMaterial();
} // changeResolution
}
// ----------------------------------------------------------------------------
/** Loads an animated mesh and returns a pointer to it.
* \param filename File to load.
@@ -279,7 +272,16 @@ scene::ISceneNode *IrrDriver::addMesh(scene::IMesh *mesh)
} // addMesh
// ----------------------------------------------------------------------------
void IrrDriver::renderToTexture(ptr_vector<scene::IMesh, REF>& mesh, std::vector<Vec3>& mesh_location, ITexture* target, float angle)
/** Renders a given vector of meshes onto a texture. Parameters:
* \param mesh Vector of meshes to render.
* \param mesh_location For each mesh the location where it should be
* positioned.
* \param target The texture to render the meshes to.
* \param angle Heading for all meshes.
*/
void IrrDriver::renderToTexture(ptr_vector<scene::IMesh, REF>& mesh,
std::vector<Vec3>& mesh_location,
ITexture* target, float angle)
{
scene::ISceneNode* main_node = NULL;

View File

@@ -1,239 +0,0 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "gui/font.hpp"
#include <vector>
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "utils/string_utils.hpp"
Font* font_gui;
Font* font_race;
int init_fonts()
{
font_gui = new Font("DomesticMannersLatin1.txf");
font_race = new Font("DomesticMannersLatin1.txf");
return ( font_gui && font_race );
} // init_fonts
// =============================================================================
int delete_fonts()
{
delete font_gui;
delete font_race;
return 0;
} // delete_fonts
// =============================================================================
Font::Font(const char *fontname)
{
#ifndef HAVE_IRRLICHT
m_fnt = new fntTexFont(file_manager->getFontFile(fontname).c_str(),
GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
m_text_out = new fntRenderer();
m_text_out->setFont(m_fnt);
#endif
} // Font
// -----------------------------------------------------------------------------
Font::~Font()
{
#ifdef HAVE_IRRLICHT
#else
delete m_text_out;
delete m_fnt;
#endif
} // ~Font
// -----------------------------------------------------------------------------
void Font::Print(const char *text, int size,
int x, int y,
const float* color,
float scale_x, float scale_y,
int left, int right, int top, int bottom, bool doShadow)
{
#ifdef HAVE_IRRLICHT
#else
// Only scale for lower resolution
float fontScaling = UserConfigParams::m_width<800 ? ((float)UserConfigParams::m_width/800.0f)
: 1.0f;
int sz = (int)(size*std::max(scale_x,scale_y)*fontScaling);
float l,r,t,b;
m_fnt->getBBox(text, (float)sz, 0, &l, &r, &b, &t);
const int W = (int)((r-l+0.99));
const int H = (int)((t-b+0.99));
if(x==CENTER_OF_SCREEN)
{
if(left ==-1) left = 0;
if(right==-1) right = UserConfigParams::m_width-1;
int width = right-left+1;
x = (width - W)/2 + left;
}
if(y==CENTER_OF_SCREEN)
{
if(top == -1) top = UserConfigParams::m_height-1;
if(bottom == -1) bottom = 0;
int height = top-bottom+1;
y = (height - H)/2 + bottom;
}
m_text_out->begin();
m_text_out->setPointSize((float)sz);
if(doShadow)
{
m_text_out->start2f((float)x-2, (float)y-2);
glColor4ub(0, 0, 0, 100);
m_text_out->puts(text);
}
m_text_out->start2f((float)x, (float)y);
if( color == NULL )
{
glColor4f(1.0f,1.0f,1.0f,1.0f);
}
else
{
glColor4fv(color);
}
m_text_out->puts(text);
m_text_out->end();
#endif
} // Print
// -----------------------------------------------------------------------------
void Font::PrintBold(const std::string &text, int size, int x, int y,
const float* color, float scale_x, float scale_y,
int left, int right, int top, int bottom )
{
// Only scale for lower resolution
float fontScaling = UserConfigParams::m_width<800 ? ((float)UserConfigParams::m_width/800.0f)
: 1.0f;
int sz = (int)(size*std::max(scale_x,scale_y)*fontScaling);
float l,r,t,b;
getBBoxMultiLine(text, sz, 0, &l, &r, &b, &t);
const int W = (int)((r-l+0.99));
const int H = (int)((t-b+0.99));
if(x==CENTER_OF_SCREEN)
{
if(left ==-1) left = 0;
if(right==-1) right = UserConfigParams::m_width-1;
int width = right-left+1;
x = (width - W)/2 + left;
}
if(y==CENTER_OF_SCREEN)
{
if(top == -1) top = UserConfigParams::m_height-1;
if(bottom == -1) bottom = 0;
int height = top-bottom+1;
y = (height - H)/2 + bottom;
}
#ifndef HAVE_IRRLICHT
m_text_out->begin();
m_text_out->setPointSize((float)sz);
// print shadow
// ------------
glColor4f(0.0f,0.0f,0.0f,1.0f);
float xf=(float)x+2;
float yf=(float)y-2;
for(float r=-1; r<=0; r+=0.5)
{
m_text_out->start2f(xf-r, yf-r);
m_text_out->puts(text.c_str());
}
if( color == NULL )
{
glColor4f(1.0f,1.0f,1.0f,1.0f);
}
else
{
glColor4fv(color);
}
xf=(float)x;
yf=(float)y;
for(float r=-1.0f; r<=0.0f; r+=0.5f)
{
// This kind of simulates an outline, but it's not too good
//if(r==-1.0f || r==0.0f)
// glColor4f(0.0f,0.0f,0.0f,1.0f);
//else
// glColor4f(1.0f,1.0f,1.0f,1.0f);
m_text_out->start2f((float)x+r, (float)y+r);
m_text_out->puts(text.c_str());
}
m_text_out->end();
#endif
} // PrintBold
// ----------------------------------------------------------------------------
void Font::getBBox(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top)
{
#ifndef HAVE_IRRLICHT
m_fnt->getBBox(text.c_str(), (float)size, italic, left, right, bot, top);
if(UserConfigParams::m_width<800) {
float fract=(float)UserConfigParams::m_width/800.0f;
*left *= fract;
*right *= fract;
if(bot) *bot *= fract;
if(top) *top *= fract;
}
#endif
}
// ----------------------------------------------------------------------------
void Font::getBBoxMultiLine(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top)
{
// Plib does not handle multi-lines strings as expected. So as a work
// around we split strings into lines, and compute the size for each
// line, and take the maximum size at the end.
#ifndef HAVE_IRRLICHT
std::vector<std::string> s=StringUtils::split(text,'\n');
m_fnt->getBBox(s[0].c_str(), (float)size, italic, left, right, bot, top);
for(unsigned int i=1; i<s.size(); i++)
{
float l,r,b,t;
m_fnt->getBBox(s[i].c_str(), (float)size, italic, &l, &r, &b, &t);
if(left) *left = std::min(*left, l);
if(bot ) *bot = std::min(*bot, b);
if(right)*right = std::max(*right, r);
if(top) *top = std::max(*top, t);
}
if(UserConfigParams::m_width<800) {
float fract=(float)UserConfigParams::m_width/800.0f;
*left *= fract;
*right *= fract;
if(bot) *bot *= fract;
if(top) *top *= fract;
}
#endif
}

View File

@@ -1,83 +0,0 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_FONT_HPP
#define HEADER_FONT_HPP
#include <string>
class Font
{
public:
//CENTER_OF_SCREEN has to be bigger or smaller than Widget::MAX_SCROLL
const static int CENTER_OF_SCREEN=-1000001;
enum FontSize {SMALL=18, MEDIUM=24, LARGE=30 };
Font(const char* fontname);
Font(const std::string &fontname) { Font(fontname.c_str()); }
~Font();
void getBBox(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top);
void getBBoxMultiLine(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top);
// The actual main function which does everything
// ----------------------------------------------
void Print( const char *text, int size,
int x, int y,
const float* color = NULL,
float scale_x=1.0f, float scale_y=1.0f,
int left=-1, int right=-1, int top=-1, int bottom=-1,
bool doShadow=false);
void Print( std::string const &text, int size,
int x, int y,
const float* color = NULL,
float scale_x=1.0f, float scale_y=1.0f,
int left=-1, int right=-1, int top=-1, int bottom=-1,
bool doShadow=false)
{
Print(text.c_str(), size, x, y,
color, scale_x, scale_y, left, right, top, bottom,
doShadow);
}
void PrintShadow(const char *text, int size,
int x, int y,
const float* color = NULL,
float scale_x=1.0f, float scale_y=1.0f,
int left=-1, int right=-1, int top=-1, int bottom=-1)
{
Print(text, size, x, y,
color, scale_x, scale_y,
left, right, top, bottom, true);
}
void PrintBold( std::string const &text, int size,
int x, int y,
const float* color = NULL,
float scale_x=1.0f, float scale_y=1.0f,
int left=-1, int right=-1, int top=-1, int bottom=-1);
};
int init_fonts();
int delete_fonts();
extern Font* font_gui;
extern Font* font_race;
#endif

View File

@@ -24,7 +24,6 @@
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "gui/font.hpp"
#include "input/input.hpp"
#include "input/input_manager.hpp"
#include "race/race_manager.hpp"
@@ -456,7 +455,7 @@ void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y,
int y;
// First line of text somewhat under the top of the screen. For now
// start just under the timer display
y = (int)(ratio_y*(UserConfigParams::m_height -164)+offset_y);
y = (int)(ratio_y*164+offset_y);
// The message are displayed in reverse order, so that a multi-line
// message (addMessage("1", ...); addMessage("2",...) is displayed
// in the right order: "1" on top of "2"
@@ -467,17 +466,11 @@ void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y,
// Display only messages for all karts, or messages for this kart
if( msg.m_kart && msg.m_kart!=player_kart) continue;
//FIXME: instead of the next line, in msg there should be a GLfloat that acts as the colors.
GLfloat const COLORS[] = {msg.m_red/255.0f, msg.m_green/255.0f, msg.m_blue/255.0f, 255.0f};
font_race->Print( msg.m_message.c_str(), msg.m_font_size,
Font::CENTER_OF_SCREEN, y,
COLORS,
ratio_x, ratio_y,
offset_x, offset_x+(int)(UserConfigParams::m_width*ratio_x));
// Add 20% of font size as space between the lines
y-=msg.m_font_size*12/10;
core::rect<s32> pos(UserConfigParams::m_width>>1, y,
UserConfigParams::m_width>>1, y);
irr_driver->getRaceFont()->draw(core::stringw(msg.m_message.c_str()).c_str(),
pos, msg.m_color, true, true);
y+=40;
} // for i in all messages
} // drawAllMessages
@@ -487,9 +480,9 @@ void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y,
* once).
**/
void RaceGUI::addMessage(const std::string &msg, const Kart *kart, float time,
int font_size, int red, int green, int blue)
int font_size, const video::SColor &color)
{
m_messages.push_back(TimedMessage(msg, kart, time, font_size, red, green, blue));
m_messages.push_back(TimedMessage(msg, kart, time, font_size, color));
} // addMessage
//-----------------------------------------------------------------------------
@@ -504,8 +497,8 @@ void RaceGUI::drawMusicDescription()
gui::IGUIFont* font = irr_driver->getRaceFont();
if(mi->getComposer()!="")
{
core::rect<s32> pos_by(UserConfigParams::m_width>>1, y,
UserConfigParams::m_width>>1, y);
core::rect<s32> pos_by(UserConfigParams::m_width>>1, y,
UserConfigParams::m_width>>1, y);
std::string s="by "+mi->getComposer();
font->draw(core::stringw(s.c_str()).c_str(), pos_by, white, true, true);
y-=40;
@@ -646,8 +639,8 @@ void RaceGUI::drawStatusText()
// split_screen_ratio_x, split_screen_ratio_y );
drawLap (info, player_kart, offset_x, offset_y,
split_screen_ratio_x, split_screen_ratio_y );
// drawAllMessages (player_kart, offset_x, offset_y,
// split_screen_ratio_x, split_screen_ratio_y );
drawAllMessages (player_kart, offset_x, offset_y,
split_screen_ratio_x, split_screen_ratio_y );
if(player_kart->hasViewBlockedByPlunger())
{
@@ -658,15 +651,12 @@ void RaceGUI::drawStatusText()
if (num_players == 3 && pla > 1)
plunger_x = offset_x + UserConfigParams::m_width/2 - plunger_size/2;
#ifndef HAVE_IRRLICHT
m_plunger_face->getState()->force();
#endif
glBegin ( GL_QUADS ) ;
glTexCoord2f(1, 0); glVertex2i(plunger_x+plunger_size, offset_y);
glTexCoord2f(0, 0); glVertex2i(plunger_x, offset_y);
glTexCoord2f(0, 1); glVertex2i(plunger_x, offset_y+plunger_size);
glTexCoord2f(1, 1); glVertex2i(plunger_x+plunger_size, offset_y+plunger_size);
glEnd () ;
video::ITexture *t=m_plunger_face->getTexture();
core::rect<s32> dest(plunger_x, offset_y,
plunger_x+plunger_size, offset_y+plunger_size);
const core::rect<s32> source(core::position2d<s32>(0,0), t->getOriginalSize());
irr_driver->getVideoDriver()->draw2DImage(t, dest, source);
}
} // next player

View File

@@ -58,27 +58,23 @@ private:
class TimedMessage
{
public:
std::string m_message; // message to display
float m_remaining_time; // time remaining before removing this message from screen
int m_red,m_blue,m_green; // colour
int m_font_size; // size
const Kart *m_kart;
std::string m_message; // message to display
float m_remaining_time; // time remaining before removing this message from screen
video::SColor m_color; // color of message
int m_font_size; // size
const Kart *m_kart;
// std::vector needs standard copy-ctor and std-assignment op.
// let compiler create defaults .. they'll do the job, no
// deep copies here ..
TimedMessage(const std::string &message,
const Kart *kart, float time, int size,
int red, int green, int blue)
const video::SColor &color)
{
m_message = message;
m_font_size = size;
m_kart = kart;
if( time < 0.0f ) m_remaining_time = -1.0f;
else
{
m_remaining_time = time;
}
m_red=red; m_blue=blue; m_green=green;
m_message = message;
m_font_size = size;
m_kart = kart;
m_remaining_time = ( time < 0.0f ) ? -1.0f : time;
m_color = color;
}
// in follow leader the clock counts backwards
bool done(const float dt)
@@ -124,8 +120,8 @@ public:
void render();
void update(float dt);
void addMessage(const std::string &m, const Kart *kart, float time,
int fonst_size, int red=255, int green=0, int blue=255);
int fonst_size,
const video::SColor &color=video::SColor(255, 255, 0, 255));
};
#endif

View File

@@ -212,10 +212,6 @@
RelativePath="..\..\gui\engine.cpp"
>
</File>
<File
RelativePath="..\..\gui\font.cpp"
>
</File>
<File
RelativePath="..\..\gui\kart_selection.cpp"
>
@@ -762,10 +758,6 @@
RelativePath="..\..\gui\credits.hpp"
>
</File>
<File
RelativePath="..\..\gui\font.hpp"
>
</File>
<File
RelativePath="..\..\gui\kart_selection.hpp"
>

View File

@@ -324,14 +324,14 @@ void PlayerKart::raceFinished(float time)
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER)
m_camera->setMode(Camera::CM_FINAL);
// TODO : race ending menu
/*
RaceGUI* m=(RaceGUI*)menu_manager->getRaceMenu();
RaceGUI* m=RaceManager::getWorld()->getRaceGUI();
if(m)
{
m->addMessage(getPosition()==1 ? _("You won the race!") : _("You finished the race!") ,
m->addMessage(getPosition()==1 ? _("You won the race!")
: _("You finished the race!") ,
this, 2.0f, 60);
}
*/
} // raceFinished
//-----------------------------------------------------------------------------

View File

@@ -49,7 +49,6 @@
#include "graphics/material_manager.hpp"
#include "graphics/scene.hpp"
#include "gui/engine.hpp"
#include "gui/font.hpp"
#include "gui/state_manager.hpp"
#include "io/file_manager.hpp"
#include "input/input_manager.hpp"
@@ -503,11 +502,10 @@ void initRest()
}
//=============================================================================
void CleanTuxKart()
void cleanTuxKart()
{
//delete in reverse order of what they were created in.
//see InitTuxkart()
//if(menu_manager) delete menu_manager;
if(race_manager) delete race_manager;
if(network_manager) delete network_manager;
if(grand_prix_manager) delete grand_prix_manager;
@@ -587,11 +585,6 @@ int main(int argc, char *argv[] )
attachment_manager -> loadModels ();
stk_scene = new Scene();
//For some reason, calling this before the material loading screws
//the background picture.
//fntInit();
init_fonts();
// prepare main menu
StateManager::initGUI();
@@ -675,9 +668,7 @@ int main(int argc, char *argv[] )
fclose(stdout);
}
delete_fonts();
CleanTuxKart();
cleanTuxKart();
return 0 ;
}

View File

@@ -248,13 +248,13 @@ void LinearWorld::newLap(unsigned int kart_index)
{
setFastestLap(kart, time_per_lap);
m_race_gui->addMessage(_("New fastest lap"), NULL,
2.0f, 40, 100, 210, 100);
2.0f, 40, video::SColor(255, 100, 210, 100));
std::string s = StringUtils::timeToString(time_per_lap);
std::ostringstream m_fastest_lap_message;
m_fastest_lap_message << s << ": " << kart->getName();
m_race_gui->addMessage(m_fastest_lap_message.str(), NULL,
2.0f, 40, 100, 210, 100);
2.0f, 40, video::SColor(255, 100, 210, 100));
} // end if new fastest lap
}
kart_info.m_lap_start_time = getTime();

View File

@@ -132,7 +132,8 @@ public:
virtual void render();
virtual void restartRace();
void disableRace(); // Put race into limbo phase
/** Returns a pointer to the race gui. */
RaceGUI *getRaceGUI() const { return m_race_gui; }
PlayerKart *getPlayerKart(int player) const { return m_player_karts[player]; }
unsigned int getCurrentNumLocalPlayers() const { return m_local_player_karts.size(); }
PlayerKart *getLocalPlayerKart(int n) const { return m_local_player_karts[n]; }