2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
|
|
|
|
// Copyright (C) 2006 Joerg Henrichs, SuperTuxKart-Team, Steve Baker
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// 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.
|
|
|
|
|
2009-07-18 13:48:36 -04:00
|
|
|
#include "states_screens/race_gui.hpp"
|
2007-11-26 09:28:15 -05:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
#include "irrlicht.h"
|
|
|
|
using namespace irr;
|
|
|
|
|
2010-04-21 13:24:02 -04:00
|
|
|
#include "audio/music_manager.hpp"
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "config/user_config.hpp"
|
2009-08-20 20:32:24 -04:00
|
|
|
#include "graphics/camera.hpp"
|
2009-03-11 01:10:56 -04:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2009-06-02 08:37:29 -04:00
|
|
|
#include "graphics/material_manager.hpp"
|
2010-01-24 18:57:50 -05:00
|
|
|
#include "guiengine/engine.hpp"
|
2009-12-06 13:35:58 -05:00
|
|
|
#include "guiengine/modaldialog.hpp"
|
2009-08-16 18:52:41 -04:00
|
|
|
#include "io/file_manager.hpp"
|
2009-06-02 08:37:29 -04:00
|
|
|
#include "input/input.hpp"
|
|
|
|
#include "input/input_manager.hpp"
|
2009-07-27 07:56:09 -04:00
|
|
|
#include "karts/kart_properties_manager.hpp"
|
2009-08-20 20:32:24 -04:00
|
|
|
#include "modes/world.hpp"
|
2009-06-02 21:36:48 -04:00
|
|
|
#include "race/race_manager.hpp"
|
2009-01-22 17:27:13 -05:00
|
|
|
#include "tracks/track.hpp"
|
|
|
|
#include "utils/constants.hpp"
|
2009-07-08 08:34:39 -04:00
|
|
|
#include "utils/string_utils.hpp"
|
2009-01-23 00:23:22 -05:00
|
|
|
#include "utils/translation.hpp"
|
2008-01-12 20:26:30 -05:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
/** The constructor is called before anything is attached to the scene node.
|
|
|
|
* So rendering to a texture can be done here. But world is not yet fully
|
|
|
|
* created, so only the race manager can be accessed safely.
|
|
|
|
*/
|
2008-02-10 18:17:25 -05:00
|
|
|
RaceGUI::RaceGUI()
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-04-28 14:26:23 -04:00
|
|
|
m_map_right_side_x = 0;
|
|
|
|
|
2010-04-27 17:44:01 -04:00
|
|
|
// Originally m_map_height was 100, and we take 480 as minimum res
|
2010-04-28 09:17:02 -04:00
|
|
|
const float scaling = irr_driver->getFrameSize().Height / 480.0f;
|
2010-04-27 17:44:01 -04:00
|
|
|
// Marker texture has to be power-of-two for (old) OpenGL compliance
|
|
|
|
m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling)));
|
2010-04-28 09:17:02 -04:00
|
|
|
m_marker_ai_size = (int)( 14.0f * scaling);
|
|
|
|
m_marker_player_size = (int)( 16.0f * scaling);
|
|
|
|
m_map_width = (int)(100.0f * scaling);
|
|
|
|
m_map_height = (int)(100.0f * scaling);
|
|
|
|
m_map_left = (int)( 10.0f * scaling);
|
|
|
|
m_map_bottom = (int)( 10.0f * scaling);
|
2010-04-28 14:26:23 -04:00
|
|
|
m_minimap_on_left = true;
|
|
|
|
|
2010-04-27 17:44:01 -04:00
|
|
|
// Minimap is also rendered bigger via OpenGL, so find power-of-two again
|
|
|
|
const int map_texture = 2 << ((int) ceil(1.0 + log(128.0 * scaling)));
|
|
|
|
m_map_rendered_width = map_texture;
|
|
|
|
m_map_rendered_height = map_texture;
|
|
|
|
|
2010-03-06 21:03:39 -05:00
|
|
|
m_max_font_height = GUIEngine::getFontHeight() + 10;
|
|
|
|
m_small_font_max_height = GUIEngine::getSmallFontHeight() + 5;
|
|
|
|
|
2009-12-06 13:35:58 -05:00
|
|
|
// special case : when 3 players play, use available 4th space for such things
|
|
|
|
if (race_manager->getNumLocalPlayers() == 3)
|
|
|
|
{
|
|
|
|
m_map_left = UserConfigParams::m_width - m_map_width;
|
2010-04-28 14:26:23 -04:00
|
|
|
m_minimap_on_left = false;
|
2009-12-06 13:35:58 -05:00
|
|
|
}
|
2010-04-27 17:44:01 -04:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
m_speed_meter_icon = material_manager->getMaterial("speedback.png");
|
2010-04-27 17:44:01 -04:00
|
|
|
m_speed_bar_icon = material_manager->getMaterial("speedfore.png");
|
2009-07-27 07:56:09 -04:00
|
|
|
m_plunger_face = material_manager->getMaterial("plungerface.png");
|
2009-08-16 18:52:41 -04:00
|
|
|
m_music_icon = material_manager->getMaterial("notes.png");
|
2009-07-27 07:56:09 -04:00
|
|
|
createMarkerTexture();
|
2010-01-11 17:08:33 -05:00
|
|
|
|
|
|
|
// Translate strings only one in constructor to avoid calling
|
|
|
|
// gettext in each frame.
|
|
|
|
//I18N: Shown at the end of a race
|
|
|
|
m_string_finished = _("Finished");
|
|
|
|
m_string_lap = _("Lap");
|
|
|
|
//I18N: as in "ready, set, go", shown at the beginning of the race
|
|
|
|
m_string_ready = _("Ready!");
|
|
|
|
m_string_set = _("Set!");
|
|
|
|
m_string_go = _("Go!");
|
2007-05-27 12:01:53 -04:00
|
|
|
} // RaceGUI
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
RaceGUI::~RaceGUI()
|
|
|
|
{
|
2009-07-27 07:56:09 -04:00
|
|
|
irr_driver->removeTexture(m_marker);
|
2007-05-27 12:01:53 -04:00
|
|
|
} // ~Racegui
|
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Creates a texture with the markers for all karts in the current race
|
|
|
|
* on it. This assumes that nothing is attached to the scene node at
|
|
|
|
* this stage.
|
|
|
|
*/
|
|
|
|
void RaceGUI::createMarkerTexture()
|
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
unsigned int num_karts = race_manager->getNumberOfKarts();
|
|
|
|
unsigned int npower2 = 1;
|
2009-07-27 07:56:09 -04:00
|
|
|
// Textures must be power of 2, so
|
2010-02-10 06:40:33 -05:00
|
|
|
while(npower2<num_karts) npower2*=2;
|
2009-07-27 07:56:09 -04:00
|
|
|
|
2009-07-29 22:40:30 -04:00
|
|
|
int radius = (m_marker_rendered_size>>1)-1;
|
2009-08-29 13:09:03 -04:00
|
|
|
IrrDriver::RTTProvider rttProvider(core::dimension2du(m_marker_rendered_size * npower2,
|
2009-09-08 08:50:52 -04:00
|
|
|
m_marker_rendered_size),
|
2009-08-05 08:45:11 -04:00
|
|
|
"RaceGUI::markers");
|
2009-11-23 00:20:05 -05:00
|
|
|
scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode();
|
2009-08-18 05:41:53 -04:00
|
|
|
core::matrix4 projection;
|
|
|
|
projection.buildProjectionMatrixOrthoLH((float)(m_marker_rendered_size*npower2),
|
|
|
|
(float)(m_marker_rendered_size), -1.0f, 1.0f);
|
|
|
|
camera->setProjectionMatrix(projection, true);
|
|
|
|
core::vector3df center( (float)(m_marker_rendered_size*npower2>>1),
|
|
|
|
(float)(m_marker_rendered_size>>1), 0.0f);
|
|
|
|
camera->setPosition(center);
|
|
|
|
camera->setUpVector(core::vector3df(0,1,0));
|
|
|
|
camera->setTarget(center + core::vector3df(0,0,4));
|
|
|
|
// The call to render sets the projection matrix etc. So we have to call
|
|
|
|
// this now before doing the direct OpenGL calls.
|
|
|
|
// FIXME: perhaps we should use three calls to irr_driver: begin(),
|
|
|
|
// render(), end() - so we could do the rendering by calling to
|
|
|
|
// draw2DPolygon() between render() and end(), avoiding the
|
|
|
|
// call to camera->render()
|
|
|
|
camera->render();
|
2009-12-03 04:10:57 -05:00
|
|
|
// We have to reset the material here, since otherwise the last
|
|
|
|
// set material (i.e from the kart selection screen) will be used
|
|
|
|
// when rednering to the texture.
|
|
|
|
video::SMaterial m;
|
|
|
|
m.setTexture(0, NULL);
|
|
|
|
irr_driver->getVideoDriver()->setMaterial(m);
|
2010-02-10 06:40:33 -05:00
|
|
|
for(unsigned int i=0; i<num_karts; i++)
|
2009-07-27 07:56:09 -04:00
|
|
|
{
|
2009-08-13 00:53:51 -04:00
|
|
|
const std::string& kart_ident = race_manager->getKartIdent(i);
|
2010-02-27 19:52:41 -05:00
|
|
|
assert(kart_ident.size() > 0);
|
|
|
|
|
2009-08-13 00:53:51 -04:00
|
|
|
const KartProperties *kp = kart_properties_manager->getKart(kart_ident);
|
2010-02-27 19:52:41 -05:00
|
|
|
assert(kp != NULL);
|
|
|
|
|
2009-07-29 22:40:30 -04:00
|
|
|
core::vector2df center((float)((m_marker_rendered_size>>1)+i*m_marker_rendered_size),
|
|
|
|
(float)(m_marker_rendered_size>>1) );
|
2009-07-27 07:56:09 -04:00
|
|
|
int count = kp->getShape();
|
2009-10-15 19:51:41 -04:00
|
|
|
//core::array<core::vector2df> vertices;
|
|
|
|
video::S3DVertex *vertices = new video::S3DVertex[count+1];
|
2009-12-03 04:10:57 -05:00
|
|
|
unsigned short int *index = new unsigned short int[count+1];
|
2010-04-22 22:18:45 -04:00
|
|
|
video::ITexture *t = kp->getMinimapIcon();
|
|
|
|
if(t)
|
|
|
|
{
|
|
|
|
video::ITexture *t = kp->getIconMaterial()->getTexture();
|
|
|
|
core::recti dest_rect(i*m_marker_rendered_size,
|
|
|
|
0,
|
|
|
|
(i+1)*m_marker_rendered_size,
|
|
|
|
m_marker_rendered_size);
|
|
|
|
core::recti source_rect(core::vector2di(0,0), t->getSize());
|
|
|
|
irr_driver->getVideoDriver()->draw2DImage(t, dest_rect,
|
|
|
|
source_rect,
|
|
|
|
/*clipRect*/0,
|
|
|
|
/*color*/ 0,
|
|
|
|
/*useAlpha*/true);
|
|
|
|
}
|
|
|
|
else // no special minimap icon defined
|
|
|
|
{
|
|
|
|
video::SColor color = kp->getColor();
|
|
|
|
createRegularPolygon(count, (float)radius, center, color,
|
|
|
|
vertices, index);
|
|
|
|
irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count,
|
|
|
|
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
|
|
|
|
delete vertices;
|
|
|
|
delete index;
|
|
|
|
} // if special minimap icon defined
|
2009-07-27 07:56:09 -04:00
|
|
|
}
|
2009-08-18 05:41:53 -04:00
|
|
|
|
2009-09-08 08:50:52 -04:00
|
|
|
m_marker = rttProvider.renderToTexture(-1, /*is_2d_render*/true);
|
2009-11-23 00:20:05 -05:00
|
|
|
irr_driver->removeCameraSceneNode(camera);
|
2009-07-27 07:56:09 -04:00
|
|
|
} // createMarkerTexture
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Creates the 2D vertices for a regular polygon. Adopted from Irrlicht.
|
|
|
|
* \param n Number of vertices to use.
|
|
|
|
* \param radius Radius of the polygon.
|
|
|
|
* \param center The center point of the polygon.
|
|
|
|
* \param v Pointer to the array of vertices.
|
|
|
|
*/
|
|
|
|
void RaceGUI::createRegularPolygon(unsigned int n, float radius,
|
|
|
|
const core::vector2df ¢er,
|
2009-10-15 19:51:41 -04:00
|
|
|
const video::SColor &color,
|
|
|
|
video::S3DVertex *v, unsigned short int *index)
|
2009-07-27 07:56:09 -04:00
|
|
|
{
|
|
|
|
float f = 2*M_PI/(float)n;
|
|
|
|
for (unsigned int i=0; i<n; i++)
|
|
|
|
{
|
|
|
|
float p = i*f;
|
|
|
|
core::vector2df X = center + core::vector2df(sin(p)*radius, -cos(p)*radius);
|
2009-10-15 19:51:41 -04:00
|
|
|
v[i].Pos.X = X.X;
|
|
|
|
v[i].Pos.Y = X.Y;
|
|
|
|
v[i].Color = color;
|
|
|
|
index[i] = i;
|
2009-07-27 07:56:09 -04:00
|
|
|
}
|
|
|
|
} // createRegularPolygon
|
|
|
|
|
2009-08-20 20:32:24 -04:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2009-11-23 00:20:05 -05:00
|
|
|
/** Render all global parts of the race gui, i.e. things that are only
|
|
|
|
* displayed once even in splitscreen.
|
|
|
|
* \param dt Timestep sized.
|
2009-07-12 07:54:21 -04:00
|
|
|
*/
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::renderGlobal(float dt)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-10-04 14:50:45 -04:00
|
|
|
cleanupMessages(dt);
|
2009-11-23 00:20:05 -05:00
|
|
|
|
2009-12-06 13:35:58 -05:00
|
|
|
// Special case : when 3 players play, use 4th window to display such stuff (but we must clear it)
|
|
|
|
if (race_manager->getNumLocalPlayers() == 3 && !GUIEngine::ModalDialog::isADialogActive())
|
|
|
|
{
|
|
|
|
static video::SColor black = video::SColor(255,0,0,0);
|
|
|
|
irr_driver->getVideoDriver()->draw2DRectangle(black,
|
|
|
|
core::rect<s32>(UserConfigParams::m_width/2, UserConfigParams::m_height/2,
|
|
|
|
UserConfigParams::m_width, UserConfigParams::m_height));
|
|
|
|
}
|
|
|
|
|
2010-02-11 02:11:52 -05:00
|
|
|
World *world = World::getWorld();
|
|
|
|
assert(world != NULL);
|
|
|
|
if(world->getPhase() >= WorldStatus::READY_PHASE &&
|
|
|
|
world->getPhase() <= WorldStatus::GO_PHASE )
|
2009-11-23 00:20:05 -05:00
|
|
|
{
|
|
|
|
drawGlobalReadySetGo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Timer etc. are not displayed unless the game is actually started.
|
2010-02-11 02:11:52 -05:00
|
|
|
if(!world->isRacePhase()) return;
|
2009-11-23 00:20:05 -05:00
|
|
|
|
|
|
|
drawGlobalTimer();
|
2010-02-11 02:11:52 -05:00
|
|
|
if(world->getPhase() == WorldStatus::GO_PHASE ||
|
|
|
|
world->getPhase() == WorldStatus::MUSIC_PHASE)
|
2009-11-23 00:20:05 -05:00
|
|
|
{
|
|
|
|
drawGlobalMusicDescription();
|
|
|
|
}
|
|
|
|
|
|
|
|
drawGlobalMiniMap();
|
2010-02-11 02:11:52 -05:00
|
|
|
RaceGUI::KartIconDisplayInfo* info = world->getKartsDisplayInfo();
|
2009-11-23 00:20:05 -05:00
|
|
|
drawGlobalPlayerIcons(info);
|
|
|
|
} // renderGlobal
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-11-23 00:20:05 -05:00
|
|
|
/** Render the details for a single player, i.e. speed, energy,
|
|
|
|
* collectibles, ...
|
2010-02-10 06:40:33 -05:00
|
|
|
* \param kart Pointer to the kart for which to render the view.
|
2009-07-12 07:54:21 -04:00
|
|
|
*/
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::renderPlayerView(const Kart *kart)
|
2009-07-12 07:54:21 -04:00
|
|
|
{
|
2010-02-14 19:54:28 -05:00
|
|
|
const core::recti &viewport = kart->getCamera()->getViewport();
|
|
|
|
const core::vector2df &scaling = kart->getCamera()->getScaling();
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2010-02-20 15:16:26 -05:00
|
|
|
if (kart->hasViewBlockedByPlunger())
|
2009-11-23 00:20:05 -05:00
|
|
|
{
|
|
|
|
int offset_y = viewport.UpperLeftCorner.Y;
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2010-02-20 15:16:26 -05:00
|
|
|
const int screen_width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X;
|
|
|
|
const int plunger_size = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y;
|
2009-11-23 00:20:05 -05:00
|
|
|
int plunger_x = viewport.UpperLeftCorner.X + screen_width/2 - plunger_size/2;
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
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());
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2010-02-20 15:16:26 -05:00
|
|
|
//static const video::SColor white = video::SColor(255, 255, 255, 255);
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2010-02-20 15:16:26 -05:00
|
|
|
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, NULL /* clip */,
|
|
|
|
NULL /* color */, true /* alpha */);
|
2009-11-23 00:20:05 -05:00
|
|
|
}
|
2010-02-26 14:30:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
drawAllMessages (kart, viewport, scaling);
|
|
|
|
if(!World::getWorld()->isRacePhase()) return;
|
|
|
|
|
|
|
|
RaceGUI::KartIconDisplayInfo* info = World::getWorld()->getKartsDisplayInfo();
|
|
|
|
|
|
|
|
drawPowerupIcons (kart, viewport, scaling);
|
|
|
|
drawEnergyMeter (kart, viewport, scaling);
|
|
|
|
drawSpeed (kart, viewport, scaling);
|
2010-04-27 20:07:48 -04:00
|
|
|
drawLap (info, kart, viewport);
|
2010-02-26 14:30:53 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
} // renderPlayerView
|
2009-07-12 07:54:21 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Displays the racing time on the screen.s
|
2009-03-11 01:10:56 -04:00
|
|
|
*/
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::drawGlobalTimer()
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-11 02:11:52 -05:00
|
|
|
assert(World::getWorld() != NULL);
|
2008-09-21 12:07:56 -04:00
|
|
|
|
2010-02-11 02:11:52 -05:00
|
|
|
if(!World::getWorld()->shouldDrawTimer()) return;
|
|
|
|
std::string s = StringUtils::timeToString(World::getWorld()->getTime());
|
2009-07-12 07:54:21 -04:00
|
|
|
core::stringw sw(s.c_str());
|
|
|
|
|
|
|
|
static video::SColor time_color = video::SColor(255, 255, 255, 255);
|
|
|
|
core::rect<s32> pos(UserConfigParams::m_width-120, 10,
|
|
|
|
UserConfigParams::m_width, 50);
|
2009-12-06 13:35:58 -05:00
|
|
|
|
|
|
|
// special case : when 3 players play, use available 4th space for such things
|
|
|
|
if (race_manager->getNumLocalPlayers() == 3)
|
|
|
|
{
|
|
|
|
pos += core::vector2d<s32>(0, UserConfigParams::m_height/2);
|
|
|
|
}
|
|
|
|
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getFont();
|
2009-07-12 07:54:21 -04:00
|
|
|
font->draw(sw.c_str(), pos, time_color);
|
2009-11-23 00:20:05 -05:00
|
|
|
} // DRAWGLOBALTimer
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-07-29 22:40:30 -04:00
|
|
|
/** Draws the mini map and the position of all karts on it.
|
|
|
|
*/
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::drawGlobalMiniMap()
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-11 02:11:52 -05:00
|
|
|
World *world = World::getWorld();
|
2008-10-14 16:20:54 -04:00
|
|
|
// arenas currently don't have a map.
|
2010-02-11 02:11:52 -05:00
|
|
|
if(world->getTrack()->isArena()) return;
|
2009-07-29 22:40:30 -04:00
|
|
|
|
2010-02-11 02:11:52 -05:00
|
|
|
const video::ITexture *mini_map=world->getTrack()->getMiniMap();
|
2008-10-14 16:20:54 -04:00
|
|
|
|
2009-07-29 22:40:30 -04:00
|
|
|
int upper_y = UserConfigParams::m_height-m_map_bottom-m_map_height;
|
|
|
|
int lower_y = UserConfigParams::m_height-m_map_bottom;
|
2009-12-06 13:35:58 -05:00
|
|
|
|
2009-07-29 22:40:30 -04:00
|
|
|
core::rect<s32> dest(m_map_left, upper_y,
|
|
|
|
m_map_left + m_map_width, lower_y);
|
2009-07-27 07:56:09 -04:00
|
|
|
core::rect<s32> source(core::position2di(0, 0), mini_map->getOriginalSize());
|
2009-07-29 22:40:30 -04:00
|
|
|
irr_driver->getVideoDriver()->draw2DImage(mini_map, dest, source, 0, 0, true);
|
2010-04-28 14:26:23 -04:00
|
|
|
m_map_right_side_x = dest.LowerRightCorner.X;
|
|
|
|
|
2010-02-10 06:40:33 -05:00
|
|
|
for(unsigned int i=0; i<world->getNumKarts(); i++)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
const Kart *kart = world->getKart(i);
|
2008-04-15 09:57:18 -04:00
|
|
|
if(kart->isEliminated()) continue; // don't draw eliminated kart
|
2009-12-17 19:36:35 -05:00
|
|
|
const Vec3& xyz = kart->getXYZ();
|
2009-07-29 22:40:30 -04:00
|
|
|
Vec3 draw_at;
|
2010-02-11 02:11:52 -05:00
|
|
|
world->getTrack()->mapPoint2MiniMap(xyz, &draw_at);
|
2009-08-26 11:18:14 -04:00
|
|
|
// int marker_height = m_marker->getOriginalSize().Height;
|
2009-07-29 22:40:30 -04:00
|
|
|
core::rect<s32> source(i *m_marker_rendered_size, 0,
|
|
|
|
(i+1)*m_marker_rendered_size, m_marker_rendered_size);
|
2010-02-14 19:54:28 -05:00
|
|
|
int marker_half_size = (kart->getController()->isPlayerController()
|
|
|
|
? m_marker_player_size
|
|
|
|
: m_marker_ai_size )>>1;
|
2009-07-29 22:40:30 -04:00
|
|
|
core::rect<s32> position(m_map_left+(int)(draw_at.getX()-marker_half_size),
|
|
|
|
lower_y -(int)(draw_at.getY()+marker_half_size),
|
|
|
|
m_map_left+(int)(draw_at.getX()+marker_half_size),
|
|
|
|
lower_y -(int)(draw_at.getY()-marker_half_size));
|
|
|
|
irr_driver->getVideoDriver()->draw2DImage(m_marker, position, source, NULL, NULL, true);
|
|
|
|
} // for i<getNumKarts
|
2009-11-23 00:20:05 -05:00
|
|
|
} // drawGlobalMiniMap
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-07-13 08:25:38 -04:00
|
|
|
// Draw players icons and their times (if defined in the current mode).
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::drawGlobalPlayerIcons(const KartIconDisplayInfo* info)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
int x = 5;
|
2009-12-06 13:35:58 -05:00
|
|
|
int y_base = 20;
|
|
|
|
|
|
|
|
// Special case : when 3 players play, use 4th window to display such stuff
|
|
|
|
if (race_manager->getNumLocalPlayers() == 3)
|
|
|
|
{
|
|
|
|
x = UserConfigParams::m_width/2 + 5;
|
|
|
|
y_base = UserConfigParams::m_height/2 + 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
int y;
|
2009-01-06 08:29:48 -05:00
|
|
|
int ICON_WIDTH=40;
|
|
|
|
int ICON_PLAYER_WIDTH=50;
|
2009-06-20 21:10:43 -04:00
|
|
|
if(UserConfigParams::m_height<600)
|
2009-01-06 08:29:48 -05:00
|
|
|
{
|
|
|
|
ICON_WIDTH = 27;
|
|
|
|
ICON_PLAYER_WIDTH = 35;
|
|
|
|
}
|
2008-09-30 20:46:00 -04:00
|
|
|
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getFont();
|
2010-02-11 02:11:52 -05:00
|
|
|
World *world = World::getWorld();
|
2010-02-10 06:40:33 -05:00
|
|
|
const unsigned int kart_amount = world->getNumKarts();
|
2008-09-27 15:43:57 -04:00
|
|
|
for(unsigned int i = 0; i < kart_amount ; i++)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
Kart* kart = world->getKart(i);
|
2008-04-15 09:57:18 -04:00
|
|
|
if(kart->isEliminated()) continue;
|
2008-10-14 16:20:54 -04:00
|
|
|
const int position = kart->getPosition();
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-12-06 13:35:58 -05:00
|
|
|
y = y_base + ( (position == -1 ? i : position-1)*(ICON_PLAYER_WIDTH+2));
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2010-03-31 19:49:42 -04:00
|
|
|
if (info[i].m_text.size() > 0)
|
2008-04-16 20:20:06 -04:00
|
|
|
{
|
2010-02-23 21:11:33 -05:00
|
|
|
video::SColor color = video::SColor(255, (int)(255*info[i].r),
|
|
|
|
(int)(255*info[i].g),
|
|
|
|
(int)(255*info[i].b) );
|
2009-07-13 08:25:38 -04:00
|
|
|
core::rect<s32> pos(x+ICON_PLAYER_WIDTH, y+5, x+ICON_PLAYER_WIDTH, y+5);
|
2010-03-31 19:49:42 -04:00
|
|
|
core::stringw s=info[i].m_text.c_str();
|
2009-07-13 08:25:38 -04:00
|
|
|
font->draw(s.c_str(), pos, color);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
2008-09-27 15:43:57 -04:00
|
|
|
|
2009-08-30 14:21:59 -04:00
|
|
|
if (info[i].special_title.size() > 0)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2009-07-13 08:25:38 -04:00
|
|
|
static video::SColor color = video::SColor(255, 255, 0, 0);
|
|
|
|
core::rect<s32> pos(x+ICON_PLAYER_WIDTH, y+5, x+ICON_PLAYER_WIDTH, y+5);
|
|
|
|
core::stringw s(info[i].special_title.c_str());
|
|
|
|
font->draw(s.c_str(), pos, color);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
|
2009-07-13 08:25:38 -04:00
|
|
|
// draw icon
|
2010-02-14 19:54:28 -05:00
|
|
|
video::ITexture *icon =
|
|
|
|
kart->getKartProperties()->getIconMaterial()->getTexture();
|
|
|
|
int w = kart->getController()->isPlayerController() ? ICON_PLAYER_WIDTH
|
|
|
|
: ICON_WIDTH;
|
2009-07-13 08:25:38 -04:00
|
|
|
const core::rect<s32> pos(x, y, x+w, y+w);
|
2009-08-13 18:53:24 -04:00
|
|
|
|
|
|
|
// Fixes crash bug, why are certain icons not showing up?
|
|
|
|
if (icon != NULL)
|
|
|
|
{
|
|
|
|
const core::rect<s32> rect(core::position2d<s32>(0,0), icon->getOriginalSize());
|
|
|
|
irr_driver->getVideoDriver()->draw2DImage(icon, pos, rect, NULL, NULL, true);
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-09-30 20:46:00 -04:00
|
|
|
} // next kart
|
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
} // drawGlobalPlayerIcons
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::drawPowerupIcons(const Kart* kart,
|
2009-11-23 00:20:05 -05:00
|
|
|
const core::recti &viewport,
|
|
|
|
const core::vector2df &scaling)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2007-06-08 05:19:27 -04:00
|
|
|
// If player doesn't have anything, do nothing.
|
2010-02-10 06:40:33 -05:00
|
|
|
const Powerup* powerup = kart->getPowerup();
|
2010-04-28 09:17:02 -04:00
|
|
|
if(powerup->getType() == PowerupManager::POWERUP_NOTHING) return;
|
2010-02-10 06:40:33 -05:00
|
|
|
int n = kart->getNumPowerup() ;
|
2009-07-13 20:26:18 -04:00
|
|
|
if(n<1) return; // shouldn't happen, but just in case
|
|
|
|
if(n>5) n=5; // Display at most 5 items
|
2007-06-08 05:19:27 -04:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
int nSize=(int)(64.0f*std::min(scaling.X, scaling.Y));
|
2010-03-06 20:35:57 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
int x1 = (int)((UserConfigParams::m_width/2-32) * scaling.X)
|
|
|
|
+ viewport.UpperLeftCorner.X;
|
2009-11-29 08:04:57 -05:00
|
|
|
//int y1 = UserConfigParams::m_height - viewport.LowerRightCorner.Y
|
|
|
|
// + (int)(20 * scaling.Y)+nSize;
|
|
|
|
int y1 = viewport.UpperLeftCorner.Y
|
|
|
|
+ (int)(20 * scaling.Y);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2010-05-07 11:28:05 -04:00
|
|
|
assert(powerup != NULL);
|
|
|
|
assert(powerup->getIcon() != NULL);
|
2009-07-13 20:26:18 -04:00
|
|
|
video::ITexture *t=powerup->getIcon()->getTexture();
|
2010-05-07 11:28:05 -04:00
|
|
|
assert(t != NULL);
|
2009-07-13 20:26:18 -04:00
|
|
|
core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize());
|
2010-03-06 20:35:57 -05:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
for ( int i = 0 ; i < n ; i++ )
|
|
|
|
{
|
2009-11-29 08:04:57 -05:00
|
|
|
int x2=(int)(x1+i*std::min(scaling.X, scaling.Y)*30);
|
|
|
|
core::rect<s32> pos(x2, y1, x2+nSize, y1+nSize);
|
2009-07-30 06:20:11 -04:00
|
|
|
irr_driver->getVideoDriver()->draw2DImage(t, pos, rect, NULL,
|
|
|
|
NULL, true);
|
2007-05-27 12:01:53 -04:00
|
|
|
} // for i
|
2008-10-29 22:02:56 -04:00
|
|
|
} // drawPowerupIcons
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/* Energy meter that gets filled with coins */
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::drawEnergyMeter (const Kart *kart,
|
2009-11-23 00:20:05 -05:00
|
|
|
const core::recti &viewport,
|
|
|
|
const core::vector2df &scaling)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
float state = (float)(kart->getEnergy()) / MAX_ITEMS_COLLECTED;
|
2009-11-23 00:20:05 -05:00
|
|
|
int x = (int)((UserConfigParams::m_width-24) * scaling.X) + viewport.UpperLeftCorner.X;
|
|
|
|
//int y = (int)(250 * scaling.Y) + viewport.UpperLeftCorner.Y;
|
2009-11-29 08:04:57 -05:00
|
|
|
int y = viewport.LowerRightCorner.Y - (int)(250 * scaling.Y);
|
2009-11-23 00:20:05 -05:00
|
|
|
int w = (int)(16 * scaling.X);
|
|
|
|
int h = (int)(UserConfigParams::m_height/4 * scaling.Y);
|
2008-05-11 13:32:41 -04:00
|
|
|
float coin_target = (float)race_manager->getCoinTarget();
|
2008-10-29 11:55:54 -04:00
|
|
|
int th = (int)(h*(coin_target/MAX_ITEMS_COLLECTED));
|
2009-07-14 08:57:04 -04:00
|
|
|
|
|
|
|
video::SColor black_border(255, 0, 0, 0);
|
|
|
|
video::SColor white_border(255, 255, 255, 255);
|
|
|
|
video::IVideoDriver *video = irr_driver->getVideoDriver();
|
|
|
|
#define LINE(x0,y0,x1,y1, color) video->draw2DLine(core::position2di(x0,y0), \
|
|
|
|
core::position2di(x1,y1), color)
|
|
|
|
|
|
|
|
// Left side:
|
|
|
|
LINE(x-1, y+1, x-1, y-h-1, black_border);
|
|
|
|
LINE(x, y, x, y-h-2, white_border);
|
2009-07-27 07:56:09 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
// Right side:
|
|
|
|
LINE(x+w, y+1, x+w, y-h-1, black_border);
|
|
|
|
LINE(x+w+1, y, x+w+1, y-h-2, white_border);
|
2009-07-27 07:56:09 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
// Bottom
|
|
|
|
LINE(x, y+1, x+w, y+1, black_border);
|
|
|
|
LINE(x+1, y, x+w+1, y, white_border);
|
2009-07-27 07:56:09 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
// Top
|
|
|
|
LINE(x, y-h, x+w, y-h, black_border);
|
|
|
|
LINE(x, y-h-1, x+w, y-h-1, white_border);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
const int GRADS = (int)(MAX_ITEMS_COLLECTED/5); // each graduation equals 5 items
|
|
|
|
int gh = (int)(h/GRADS); //graduation height
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
// 'Meter marks;
|
2008-05-10 09:30:55 -04:00
|
|
|
int gh_incr = gh;
|
|
|
|
for (int i=0; i<GRADS-1; i++)
|
|
|
|
{
|
2009-07-14 08:57:04 -04:00
|
|
|
LINE(x+1, y-1-gh, x+1+w, y-1-gh, white_border);
|
2008-05-10 09:30:55 -04:00
|
|
|
gh+=gh_incr;
|
|
|
|
}
|
2009-07-14 08:57:04 -04:00
|
|
|
|
2008-05-11 13:32:41 -04:00
|
|
|
//Target line
|
|
|
|
if (coin_target > 0)
|
|
|
|
{
|
2009-07-14 08:57:04 -04:00
|
|
|
LINE(x+1, y-1-th, x+1+w, y-1-th, video::SColor(255, 255, 0, 0));
|
2008-05-11 13:32:41 -04:00
|
|
|
}
|
2009-07-14 08:57:04 -04:00
|
|
|
#undef LINE
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-07-14 08:57:04 -04:00
|
|
|
// The actual energy meter
|
|
|
|
core::rect<s32> energy(x+1, y-1-(int)(state*h), x+1+w, y-1);
|
|
|
|
video::SColor bottom(255, 240, 0, 0);
|
|
|
|
video::SColor top (160, 240, 200, 0);
|
|
|
|
video->draw2DRectangle(energy, top, top, bottom, bottom);
|
2007-05-27 12:01:53 -04:00
|
|
|
} // drawEnergyMeter
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::drawSpeed(const Kart* kart, const core::recti &viewport,
|
2009-11-23 00:20:05 -05:00
|
|
|
const core::vector2df &scaling)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
float minRatio = std::min(scaling.X, scaling.Y);
|
|
|
|
const int SPEEDWIDTH = 128;
|
|
|
|
int meter_width = (int)(SPEEDWIDTH*minRatio);
|
|
|
|
int meter_height = (int)(SPEEDWIDTH*minRatio);
|
|
|
|
core::vector2di offset = viewport.UpperLeftCorner;
|
|
|
|
offset.X += (int)((UserConfigParams::m_width-10)*scaling.X) - meter_width;
|
2009-11-29 08:04:57 -05:00
|
|
|
offset.Y = viewport.LowerRightCorner.Y-(int)(10*scaling.Y);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
// First draw the meter (i.e. the background which contains the numbers etc.
|
|
|
|
// -------------------------------------------------------------------------
|
2009-07-15 09:40:22 -04:00
|
|
|
video::IVideoDriver *video = irr_driver->getVideoDriver();
|
2009-11-23 00:20:05 -05:00
|
|
|
const core::rect<s32> meter_pos(offset.X,
|
2009-11-29 08:04:57 -05:00
|
|
|
offset.Y-meter_height,
|
2009-11-23 00:20:05 -05:00
|
|
|
offset.X+meter_width,
|
2009-11-29 08:04:57 -05:00
|
|
|
offset.Y);
|
2009-07-27 07:56:09 -04:00
|
|
|
video::ITexture *meter_texture = m_speed_meter_icon->getTexture();
|
|
|
|
const core::rect<s32> meter_texture_coords(core::position2d<s32>(0,0),
|
|
|
|
meter_texture->getOriginalSize());
|
|
|
|
video->draw2DImage(meter_texture, meter_pos, meter_texture_coords, NULL, NULL, true);
|
|
|
|
|
2009-07-15 09:40:22 -04:00
|
|
|
const float speed = kart->getSpeed();
|
2009-07-27 07:56:09 -04:00
|
|
|
if(speed <=0) return; // Nothing to do if speed is negative.
|
|
|
|
|
|
|
|
// Draw the actual speed bar (if the speed is >0)
|
|
|
|
// ----------------------------------------------
|
|
|
|
float speed_ratio = speed/KILOMETERS_PER_HOUR/110.0f;
|
2010-04-27 18:51:07 -04:00
|
|
|
if(speed_ratio>1 || !kart->isOnGround()) speed_ratio = 1;
|
2009-07-27 07:56:09 -04:00
|
|
|
|
|
|
|
video::ITexture *bar_texture = m_speed_bar_icon->getTexture();
|
2009-08-05 08:45:11 -04:00
|
|
|
core::dimension2du bar_size = bar_texture->getOriginalSize();
|
2009-10-15 19:51:41 -04:00
|
|
|
video::S3DVertex vertices[4];
|
|
|
|
|
|
|
|
vertices[0].TCoords = core::vector2df(1.0f, 1.0f);
|
|
|
|
vertices[0].Pos = core::vector3df((float)meter_pos.LowerRightCorner.X,
|
|
|
|
(float)meter_pos.LowerRightCorner.Y,
|
|
|
|
0);
|
|
|
|
vertices[1].TCoords = core::vector2df(0, 1.0f);
|
|
|
|
vertices[1].Pos = core::vector3df((float)meter_pos.UpperLeftCorner.X,
|
|
|
|
(float)meter_pos.LowerRightCorner.Y, 0);
|
|
|
|
unsigned int count;
|
2009-07-27 07:56:09 -04:00
|
|
|
if(speed_ratio<=0.5f)
|
2009-07-15 09:40:22 -04:00
|
|
|
{
|
2009-10-15 19:51:41 -04:00
|
|
|
count = 3;
|
|
|
|
vertices[2].TCoords = core::vector2df(0, 1-2*speed_ratio);
|
|
|
|
vertices[2].Pos = core::vector3df((float)meter_pos.UpperLeftCorner.X,
|
|
|
|
(float)meter_pos.LowerRightCorner.Y-speed_ratio*2*meter_height,
|
|
|
|
0);
|
2009-07-27 07:56:09 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-15 19:51:41 -04:00
|
|
|
count = 4;
|
|
|
|
vertices[2].TCoords = core::vector2df(0,0);
|
2009-11-23 00:20:05 -05:00
|
|
|
vertices[2].Pos = core::vector3df((float)offset.X,
|
2009-11-29 08:04:57 -05:00
|
|
|
(float)(offset.Y-meter_height),
|
2009-11-23 00:20:05 -05:00
|
|
|
0);
|
2009-10-15 19:51:41 -04:00
|
|
|
vertices[3].TCoords = core::vector2df(2*speed_ratio-1.0f, 0);
|
2009-11-23 00:20:05 -05:00
|
|
|
vertices[3].Pos = core::vector3df(offset.X+2*(speed_ratio-0.5f)*meter_width,
|
2009-11-29 08:04:57 -05:00
|
|
|
(float)(offset.Y-meter_height),
|
2009-11-23 00:20:05 -05:00
|
|
|
0);
|
2009-10-15 19:51:41 -04:00
|
|
|
}
|
|
|
|
short int index[4];
|
|
|
|
for(unsigned int i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
index[i]=i;
|
|
|
|
vertices[i].Color = video::SColor(255, 255, 255, 255);
|
2009-07-27 07:56:09 -04:00
|
|
|
}
|
2009-10-15 19:51:41 -04:00
|
|
|
video::SMaterial m;
|
|
|
|
m.setTexture(0, m_speed_bar_icon->getTexture());
|
2010-01-05 06:31:10 -05:00
|
|
|
m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
2009-10-15 19:51:41 -04:00
|
|
|
irr_driver->getVideoDriver()->setMaterial(m);
|
|
|
|
irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count,
|
|
|
|
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
|
2007-05-27 12:01:53 -04:00
|
|
|
} // drawSpeed
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::drawLap(const KartIconDisplayInfo* info, const Kart* kart,
|
2010-04-27 20:07:48 -04:00
|
|
|
const core::recti &viewport)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
// Don't display laps in follow the leader mode
|
2010-02-11 02:11:52 -05:00
|
|
|
if(!World::getWorld()->raceHasLaps()) return;
|
2008-09-27 15:43:57 -04:00
|
|
|
|
|
|
|
const int lap = info[kart->getWorldKartId()].lap;
|
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
if(lap<0) return; // don't display 'lap 0/...'
|
2010-01-10 18:12:29 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
core::recti pos;
|
2009-11-29 08:04:57 -05:00
|
|
|
pos.UpperLeftCorner.Y = viewport.LowerRightCorner.Y;
|
2010-04-28 14:26:23 -04:00
|
|
|
|
|
|
|
// place lap count somewhere on the left of the screen
|
|
|
|
if (m_minimap_on_left)
|
|
|
|
{
|
|
|
|
// check if mini-map is within Y coords of this player.
|
|
|
|
// if the mini-map is not even in the viewport of this player, don't bother placing
|
|
|
|
// the lap text at the right of the minimap.
|
|
|
|
if (UserConfigParams::m_height - m_map_bottom - m_map_height > viewport.LowerRightCorner.Y)
|
|
|
|
{
|
|
|
|
pos.UpperLeftCorner.X = viewport.UpperLeftCorner.X + (int)(0.1f*UserConfigParams::m_width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// place lap text at the right of the mini-map
|
|
|
|
const int calculated_x = viewport.UpperLeftCorner.X + (int)(0.05f*UserConfigParams::m_width);
|
|
|
|
pos.UpperLeftCorner.X = std::max(calculated_x, m_map_right_side_x + 15); // don't overlap minimap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// mini-map is on the right, and lap text on right, so no overlap possible
|
|
|
|
pos.UpperLeftCorner.X = viewport.UpperLeftCorner.X + (int)(0.05f*UserConfigParams::m_width);
|
|
|
|
}
|
|
|
|
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getFont();
|
2010-04-25 14:11:36 -04:00
|
|
|
|
2010-04-27 20:07:48 -04:00
|
|
|
int font_height = (int)(font->getDimension(L"X").Height);
|
2010-04-25 14:11:36 -04:00
|
|
|
|
2010-01-24 18:57:50 -05:00
|
|
|
if (kart->hasFinishedRace())
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2009-07-13 20:26:18 -04:00
|
|
|
static video::SColor color = video::SColor(255, 255, 255, 255);
|
2009-11-29 08:04:57 -05:00
|
|
|
pos.UpperLeftCorner.Y -= 2*font_height;
|
|
|
|
pos.LowerRightCorner = pos.UpperLeftCorner;
|
2010-01-11 17:08:33 -05:00
|
|
|
font->draw(m_string_finished.c_str(), pos, color);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-13 20:26:18 -04:00
|
|
|
static video::SColor color = video::SColor(255, 255, 255, 255);
|
2009-11-29 08:04:57 -05:00
|
|
|
pos.UpperLeftCorner.Y -= 3*font_height;
|
|
|
|
pos.LowerRightCorner = pos.UpperLeftCorner;
|
2010-01-11 17:08:33 -05:00
|
|
|
font->draw(m_string_lap.c_str(), pos, color);
|
2009-07-13 20:26:18 -04:00
|
|
|
|
|
|
|
char str[256];
|
|
|
|
sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps());
|
2009-11-29 08:04:57 -05:00
|
|
|
pos.UpperLeftCorner.Y += font_height;
|
|
|
|
pos.LowerRightCorner.Y += font_height;
|
2009-07-13 20:26:18 -04:00
|
|
|
font->draw(core::stringw(str).c_str(), pos, color);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
} // drawLap
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Removes messages which have been displayed long enough. This function
|
2008-10-04 14:50:45 -04:00
|
|
|
* must be called after drawAllMessages, otherwise messages which are only
|
2007-05-27 12:01:53 -04:00
|
|
|
* displayed once will not be drawn!
|
|
|
|
**/
|
|
|
|
|
2008-10-04 14:50:45 -04:00
|
|
|
void RaceGUI::cleanupMessages(const float dt)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
AllMessageType::iterator p =m_messages.begin();
|
|
|
|
while(p!=m_messages.end())
|
|
|
|
{
|
2008-10-04 14:50:45 -04:00
|
|
|
if((*p).done(dt))
|
2007-09-10 10:11:08 -04:00
|
|
|
{
|
|
|
|
p = m_messages.erase(p);
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
else
|
2007-09-10 10:11:08 -04:00
|
|
|
{
|
|
|
|
++p;
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
} // cleanupMessages
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Displays all messages in the message queue
|
|
|
|
**/
|
2010-02-10 06:40:33 -05:00
|
|
|
void RaceGUI::drawAllMessages(const Kart* kart,
|
2009-11-23 00:20:05 -05:00
|
|
|
const core::recti &viewport,
|
|
|
|
const core::vector2df &scaling)
|
2010-03-04 20:58:27 -05:00
|
|
|
{
|
2010-03-06 21:03:39 -05:00
|
|
|
int y = viewport.LowerRightCorner.Y - m_small_font_max_height - 10;
|
2010-03-06 20:35:57 -05:00
|
|
|
|
2010-02-18 19:53:08 -05:00
|
|
|
const int x = (viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X)/2;
|
|
|
|
const int w = (viewport.LowerRightCorner.X + viewport.UpperLeftCorner.X)/2;
|
2010-03-06 20:35:57 -05:00
|
|
|
|
|
|
|
// draw less important first, at the very top of the screen
|
|
|
|
for (AllMessageType::const_iterator i = m_messages.begin(); i != m_messages.end(); ++i)
|
|
|
|
{
|
|
|
|
TimedMessage const &msg = *i;
|
|
|
|
if (!msg.m_important)
|
|
|
|
{
|
|
|
|
// Display only messages for all karts, or messages for this kart
|
|
|
|
if (msg.m_kart && msg.m_kart!=kart) continue;
|
|
|
|
|
|
|
|
core::rect<s32> pos(x - w/2, y, x + w/2, y + m_max_font_height);
|
2010-03-06 21:03:39 -05:00
|
|
|
GUIEngine::getSmallFont()->draw(core::stringw(msg.m_message.c_str()).c_str(),
|
|
|
|
pos, msg.m_color, true /* hcenter */, true /* vcenter */);
|
|
|
|
y -= m_small_font_max_height;
|
2010-03-06 20:35:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// First line of text somewhat under the top of the viewport.
|
|
|
|
y = (int)(viewport.UpperLeftCorner.Y + 164*scaling.Y);
|
2010-02-18 19:53:08 -05:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
// 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"
|
2010-02-18 19:53:08 -05:00
|
|
|
for (AllMessageType::const_iterator i = m_messages.begin(); i != m_messages.end(); ++i)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2007-09-10 10:11:08 -04:00
|
|
|
TimedMessage const &msg = *i;
|
|
|
|
|
2010-03-06 20:35:57 -05:00
|
|
|
if (!msg.m_important) continue; // less important messages were already displayed
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
// Display only messages for all karts, or messages for this kart
|
2010-02-18 19:53:08 -05:00
|
|
|
if (msg.m_kart && msg.m_kart!=kart) continue;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2010-03-04 20:58:27 -05:00
|
|
|
core::rect<s32> pos(x - w/2, y, x + w/2, y + m_max_font_height);
|
2010-01-24 18:57:50 -05:00
|
|
|
GUIEngine::getFont()->draw(core::stringw(msg.m_message.c_str()).c_str(),
|
2010-02-18 19:53:08 -05:00
|
|
|
pos, msg.m_color, true /* hcenter */, true /* vcenter */);
|
2010-03-04 20:58:27 -05:00
|
|
|
y += m_max_font_height;
|
2007-05-27 12:01:53 -04:00
|
|
|
} // for i in all messages
|
|
|
|
} // drawAllMessages
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Adds a message to the message queue. The message is displayed for a
|
|
|
|
* certain amount of time (unless time<0, then the message is displayed
|
|
|
|
* once).
|
|
|
|
**/
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::addMessage(const core::stringw &msg, const Kart *kart, float time,
|
2010-03-06 20:35:57 -05:00
|
|
|
int font_size, const video::SColor &color, bool important)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-03-06 20:35:57 -05:00
|
|
|
m_messages.push_back(TimedMessage(msg, kart, time, font_size, color, important));
|
2007-05-27 12:01:53 -04:00
|
|
|
} // addMessage
|
|
|
|
|
2008-02-10 18:17:25 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Displays the description given for the music currently being played -
|
|
|
|
// usually the title and composer.
|
2009-11-23 00:20:05 -05:00
|
|
|
void RaceGUI::drawGlobalMusicDescription()
|
2008-02-10 18:17:25 -05:00
|
|
|
{
|
2009-08-16 16:55:06 -04:00
|
|
|
if (!UserConfigParams::m_music) return; // show no music description when it's off
|
|
|
|
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getFont();
|
2010-01-04 13:05:56 -05:00
|
|
|
|
2010-05-10 19:53:32 -04:00
|
|
|
float race_time = World::getWorld()->getTime();
|
2010-01-04 13:05:56 -05:00
|
|
|
// ---- Manage pulsing effect
|
2009-08-16 18:52:41 -04:00
|
|
|
// 3.0 is the duration of ready/set (TODO: don't hardcode)
|
2010-05-10 19:53:32 -04:00
|
|
|
float timeProgression = (float)(race_time) /
|
2010-01-04 13:05:56 -05:00
|
|
|
(float)(stk_config->m_music_credit_time - 2.0f);
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-05-10 19:53:32 -04:00
|
|
|
const int x_pulse = (int)(sin(race_time*9.0f)*10.0f);
|
|
|
|
const int y_pulse = (int)(cos(race_time*9.0f)*10.0f);
|
2009-08-16 18:52:41 -04:00
|
|
|
|
|
|
|
float resize = 1.0f;
|
|
|
|
if (timeProgression < 0.1)
|
|
|
|
{
|
|
|
|
resize = timeProgression/0.1f;
|
|
|
|
}
|
|
|
|
else if (timeProgression > 0.9)
|
|
|
|
{
|
|
|
|
resize = 1.0f - (timeProgression - 0.9f)/0.1f;
|
|
|
|
}
|
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
const float resize3 = resize*resize*resize;
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
// ---- Get song name, and calculate its size, allowing us to position stuff
|
2010-04-21 13:24:02 -04:00
|
|
|
const MusicInformation* mi = music_manager->getCurrentMusic();
|
2010-01-04 13:05:56 -05:00
|
|
|
if (!mi) return;
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
std::string s="\""+mi->getTitle()+"\"";
|
|
|
|
core::stringw thetext(s.c_str());
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
core::dimension2d< u32 > textSize = font->getDimension(thetext.c_str());
|
|
|
|
int textWidth = textSize.Width;
|
|
|
|
|
|
|
|
int textWidth2 = 0;
|
|
|
|
core::stringw thetext_composer;
|
|
|
|
if (mi->getComposer()!="")
|
|
|
|
{
|
|
|
|
std::string s = "by "+mi->getComposer();
|
|
|
|
thetext_composer = s.c_str();
|
|
|
|
textWidth2 = font->getDimension(thetext_composer.c_str()).Width;
|
|
|
|
}
|
|
|
|
const int max_text_size = (int)(UserConfigParams::m_width*2.0f/3.0f);
|
|
|
|
if (textWidth > max_text_size) textWidth = max_text_size;
|
|
|
|
if (textWidth2 > max_text_size) textWidth2 = max_text_size;
|
|
|
|
|
|
|
|
const int ICON_SIZE = 64;
|
|
|
|
const int y = UserConfigParams::m_height - 80;
|
|
|
|
// the 20 is an arbitrary space left between the note icon and the text
|
|
|
|
const int noteX = (UserConfigParams::m_width / 2) - std::max(textWidth, textWidth2)/2 - ICON_SIZE/2 - 20;
|
|
|
|
const int noteY = y;
|
|
|
|
// the 20 is an arbitrary space left between the note icon and the text
|
|
|
|
const int textXFrom = (UserConfigParams::m_width / 2) - std::max(textWidth, textWidth2)/2 + 20;
|
|
|
|
const int textXTo = (UserConfigParams::m_width / 2) + std::max(textWidth, textWidth2)/2 + 20;
|
|
|
|
|
|
|
|
// ---- Draw "by" text
|
2009-08-16 20:19:55 -04:00
|
|
|
const int text_y = (int)(UserConfigParams::m_height - 80*(resize3) + 40*(1-resize));
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
static const video::SColor white = video::SColor(255, 255, 255, 255);
|
2008-03-14 05:49:17 -04:00
|
|
|
if(mi->getComposer()!="")
|
2008-02-10 18:17:25 -05:00
|
|
|
{
|
2010-01-04 13:05:56 -05:00
|
|
|
core::rect<s32> pos_by(textXFrom, text_y+40,
|
|
|
|
textXTo, text_y+40);
|
2008-03-14 05:49:17 -04:00
|
|
|
std::string s="by "+mi->getComposer();
|
2009-07-15 09:40:22 -04:00
|
|
|
font->draw(core::stringw(s.c_str()).c_str(), pos_by, white, true, true);
|
2008-03-14 05:49:17 -04:00
|
|
|
}
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
// ---- Draw "song name" text
|
|
|
|
core::rect<s32> pos(textXFrom, text_y,
|
|
|
|
textXTo, text_y);
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2010-01-04 13:05:56 -05:00
|
|
|
font->draw(thetext.c_str(), pos, white, true /* hcenter */, true /* vcenter */);
|
|
|
|
|
2009-08-16 18:52:41 -04:00
|
|
|
// Draw music icon
|
2010-01-04 13:05:56 -05:00
|
|
|
int iconSizeX = (int)(ICON_SIZE*resize + x_pulse*resize*resize);
|
|
|
|
int iconSizeY = (int)(ICON_SIZE*resize + y_pulse*resize*resize);
|
|
|
|
|
2009-08-16 18:52:41 -04:00
|
|
|
video::ITexture *t = m_music_icon->getTexture();
|
2010-01-04 13:05:56 -05:00
|
|
|
core::rect<s32> dest(noteX-iconSizeX/2+20, noteY-iconSizeY/2+ICON_SIZE/2,
|
|
|
|
noteX+iconSizeX/2+20, noteY+iconSizeY/2+ICON_SIZE/2);
|
2009-08-16 18:52:41 -04:00
|
|
|
const core::rect<s32> source(core::position2d<s32>(0,0), t->getOriginalSize());
|
|
|
|
|
|
|
|
irr_driver->getVideoDriver()->draw2DImage(t, dest, source, NULL, NULL, true);
|
2010-01-04 13:05:56 -05:00
|
|
|
|
2009-08-16 18:52:41 -04:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
} // drawGlobalMusicDescription
|
2008-02-10 18:17:25 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Draws the ready-set-go message on the screen.
|
|
|
|
*/
|
|
|
|
void RaceGUI::drawGlobalReadySetGo()
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-11 02:11:52 -05:00
|
|
|
switch (World::getWorld()->getPhase())
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2010-02-09 04:24:45 -05:00
|
|
|
case WorldStatus::READY_PHASE:
|
2008-04-24 03:06:09 -04:00
|
|
|
{
|
2010-01-24 18:57:50 -05:00
|
|
|
//static video::SColor color = video::SColor(255, 230, 168, 158);
|
|
|
|
static video::SColor color = video::SColor(255, 255, 255, 255);
|
2009-07-12 07:54:21 -04:00
|
|
|
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
|
|
|
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getTitleFont();
|
2010-01-11 17:08:33 -05:00
|
|
|
font->draw(m_string_ready.c_str(), pos, color, true, true);
|
2008-04-24 03:06:09 -04:00
|
|
|
}
|
|
|
|
break;
|
2010-02-09 04:24:45 -05:00
|
|
|
case WorldStatus::SET_PHASE:
|
2008-04-24 03:06:09 -04:00
|
|
|
{
|
2010-01-24 18:57:50 -05:00
|
|
|
//static video::SColor color = video::SColor(255, 230, 230, 158);
|
|
|
|
static video::SColor color = video::SColor(255, 255, 255, 255);
|
2009-07-12 07:54:21 -04:00
|
|
|
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
|
|
|
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
2010-01-24 18:57:50 -05:00
|
|
|
gui::IGUIFont* font = GUIEngine::getTitleFont();
|
2008-09-01 20:35:28 -04:00
|
|
|
//I18N: as in "ready, set, go", shown at the beginning of the race
|
2010-01-11 17:08:33 -05:00
|
|
|
font->draw(m_string_set.c_str(), pos, color, true, true);
|
2008-04-24 03:06:09 -04:00
|
|
|
}
|
|
|
|
break;
|
2010-02-09 04:24:45 -05:00
|
|
|
case WorldStatus::GO_PHASE:
|
2008-04-24 03:06:09 -04:00
|
|
|
{
|
2010-01-24 18:57:50 -05:00
|
|
|
//static video::SColor color = video::SColor(255, 100, 209, 100);
|
|
|
|
static video::SColor color = video::SColor(255, 255, 255, 255);
|
2009-07-12 07:54:21 -04:00
|
|
|
core::rect<s32> pos(UserConfigParams::m_width>>1, UserConfigParams::m_height>>1,
|
|
|
|
UserConfigParams::m_width>>1, UserConfigParams::m_height>>1);
|
2010-01-24 18:57:50 -05:00
|
|
|
//gui::IGUIFont* font = irr_driver->getRaceFont();
|
|
|
|
gui::IGUIFont* font = GUIEngine::getTitleFont();
|
2008-09-01 20:35:28 -04:00
|
|
|
//I18N: as in "ready, set, go", shown at the beginning of the race
|
2010-01-11 17:08:33 -05:00
|
|
|
font->draw(m_string_go.c_str(), pos, color, true, true);
|
2008-04-24 03:06:09 -04:00
|
|
|
}
|
|
|
|
break;
|
2008-02-12 20:02:02 -05:00
|
|
|
default:
|
|
|
|
break;
|
2007-05-27 12:01:53 -04:00
|
|
|
} // switch
|
2009-11-23 00:20:05 -05:00
|
|
|
} // drawGlobalReadySetGo
|