Updated new race result gui (which by default is not shown atm).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5699 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
8e48d227b8
commit
7557d4be8b
@ -28,15 +28,19 @@
|
|||||||
*/
|
*/
|
||||||
RaceResultGUI::RaceResultGUI()
|
RaceResultGUI::RaceResultGUI()
|
||||||
{
|
{
|
||||||
|
#undef USE_NEW_RACE_RESULT
|
||||||
|
|
||||||
|
#ifndef USE_NEW_RACE_RESULT
|
||||||
// FIXME: for now disable the new race result display
|
// FIXME: for now disable the new race result display
|
||||||
// by just firing up the old display (which will make sure
|
// by just firing up the old display (which will make sure
|
||||||
// that the rendering for this object is not called anymore).
|
// that the rendering for this object is not called anymore).
|
||||||
new RaceOverDialog(0.6f, 0.9f);
|
new RaceOverDialog(0.6f, 0.9f);
|
||||||
return;
|
return;
|
||||||
|
#else
|
||||||
|
|
||||||
determineLayout();
|
determineLayout();
|
||||||
m_timer = 0;
|
m_timer = 0;
|
||||||
|
m_animation_state = RR_BEGIN_FIRST_TABLE;
|
||||||
|
#endif
|
||||||
} // RaceResultGUI
|
} // RaceResultGUI
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -63,65 +67,86 @@ void RaceResultGUI::nextPhase()
|
|||||||
*/
|
*/
|
||||||
void RaceResultGUI::determineLayout()
|
void RaceResultGUI::determineLayout()
|
||||||
{
|
{
|
||||||
|
m_font = dynamic_cast<gui::ScalableFont*>(GUIEngine::getFont());
|
||||||
|
assert(m_font);
|
||||||
|
World *world = World::getWorld();
|
||||||
|
world->raceResultOrder(&m_order);
|
||||||
|
|
||||||
|
// Determine the kart to display in the right order, and the maximum
|
||||||
|
// width for the kart name column
|
||||||
|
m_max_kart_name_width = 0;
|
||||||
|
float max_finish_time = 0;
|
||||||
|
for(unsigned int i=0; i<m_order.size(); i++)
|
||||||
|
{
|
||||||
|
if(m_order[i]==-1) continue;
|
||||||
|
Kart *kart = world->getKart(m_order[i]);
|
||||||
|
m_kart_names.push_back(kart->getName());
|
||||||
|
|
||||||
|
video::ITexture *icon =
|
||||||
|
kart->getKartProperties()->getIconMaterial()->getTexture();
|
||||||
|
m_kart_icons.push_back(icon);
|
||||||
|
|
||||||
|
const float time = kart->getFinishTime();
|
||||||
|
if(time > max_finish_time) max_finish_time = time;
|
||||||
|
std::string time_string = StringUtils::timeToString(time);
|
||||||
|
m_time_strings.push_back(time_string.c_str());
|
||||||
|
|
||||||
|
core::dimension2d<u32> rect = m_font->getDimension(kart->getName().c_str());
|
||||||
|
if(rect.Width > m_max_kart_name_width)
|
||||||
|
m_max_kart_name_width = rect.Width;
|
||||||
|
m_new_points.push_back(race_manager->getPositionScore(i+1));
|
||||||
|
m_old_overall_points.push_back(race_manager->getKartPrevScore(m_order[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string max_time = StringUtils::timeToString(max_finish_time);
|
||||||
|
core::stringw string_max_time(max_time.c_str());
|
||||||
|
core::dimension2du r_time = m_font->getDimension(string_max_time.c_str());
|
||||||
|
m_time_width = r_time.Width;
|
||||||
|
|
||||||
|
// Use only the karts that are supposed to be displayed (and
|
||||||
|
// ignore e.g. the leader in a FTL race).
|
||||||
|
unsigned int num_karts = m_time_strings.size();
|
||||||
|
|
||||||
// Top pixel where to display text
|
// Top pixel where to display text
|
||||||
unsigned int top = (int)(0.15f*UserConfigParams::m_height);
|
unsigned int top = (int)(0.15f*UserConfigParams::m_height);
|
||||||
|
|
||||||
// Height of the result display
|
// Height of the result display
|
||||||
unsigned int height = (int)(0.7f *UserConfigParams::m_height);
|
unsigned int height = (int)(0.7f *UserConfigParams::m_height);
|
||||||
|
|
||||||
|
// Setup different timing information for the different phases
|
||||||
|
// -----------------------------------------------------------
|
||||||
// How much time between consecutive rows
|
// How much time between consecutive rows
|
||||||
m_time_between_rows = 0.5f;
|
m_time_between_rows = 0.5f;
|
||||||
|
|
||||||
World *world = World::getWorld();
|
// How long it takes for one line to scroll from right to left
|
||||||
unsigned int num_karts = world->getNumKarts();
|
m_time_single_scroll = 0.5f;
|
||||||
|
|
||||||
|
// The time the first phase is being displayed: add the start time
|
||||||
|
// of the last kart to the duration of the scroll plus some time
|
||||||
|
// of rest before the next phase starts
|
||||||
|
m_time_overall_scroll = (num_karts-1)*m_time_between_rows
|
||||||
|
+ m_time_single_scroll + 2.0f;
|
||||||
|
|
||||||
// Determine text height
|
// Determine text height
|
||||||
m_font = GUIEngine::getFont();
|
core::dimension2du text_size = m_font->getDimension(L"Y");
|
||||||
core::dimension2du text_size = m_font->getDimension(L"a");
|
|
||||||
m_distance_between_rows = (int)(1.5f*text_size.Height);
|
m_distance_between_rows = (int)(1.5f*text_size.Height);
|
||||||
|
|
||||||
// If there are too many karts, reduce size between rows
|
// If there are too many karts, reduce size between rows
|
||||||
if(m_distance_between_rows * num_karts > height)
|
if(m_distance_between_rows * num_karts > height)
|
||||||
m_distance_between_rows = height / num_karts;
|
m_distance_between_rows = height / num_karts;
|
||||||
|
|
||||||
world->raceResultOrder(&m_order);
|
|
||||||
|
|
||||||
m_start_at.clear();
|
m_start_at.clear();
|
||||||
for(unsigned int i=0; i<num_karts; i++)
|
for(unsigned int i=0; i<num_karts; i++)
|
||||||
{
|
{
|
||||||
if(m_order[i]==-1) continue;
|
|
||||||
m_start_at.push_back(m_time_between_rows * i);
|
m_start_at.push_back(m_time_between_rows * i);
|
||||||
m_x_pos.push_back((float)UserConfigParams::m_width);
|
m_x_pos.push_back((float)UserConfigParams::m_width);
|
||||||
m_y_pos.push_back(m_distance_between_rows+i*m_distance_between_rows);
|
m_y_pos.push_back(top+i*m_distance_between_rows);
|
||||||
Kart *kart = world->getKart(m_order[i]);
|
|
||||||
const core::stringw& kart_name = kart->getName();
|
|
||||||
|
|
||||||
const float time = kart->getFinishTime();
|
|
||||||
std::string time_string = StringUtils::timeToString(time);
|
|
||||||
core::stringw kart_results_line = StringUtils::insertValues( L"%i. %s %s",
|
|
||||||
kart->getPosition(),
|
|
||||||
kart_name.c_str(),
|
|
||||||
time_string.c_str());
|
|
||||||
|
|
||||||
m_entry.push_back(core::stringw(kart_results_line.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_icon_width = UserConfigParams::m_height<600
|
m_icon_width = UserConfigParams::m_height<600
|
||||||
? 27
|
? 27
|
||||||
: (int)(40*(UserConfigParams::m_width/800.0f));
|
: (int)(40*(UserConfigParams::m_width/800.0f));
|
||||||
|
|
||||||
// Determine the maximum width for the kart name column
|
|
||||||
unsigned int max_name_width = 0;
|
|
||||||
float max_finish_time = 0;
|
|
||||||
for(unsigned int i=0; i<num_karts; i++)
|
|
||||||
{
|
|
||||||
const Kart *kart = world->getKart(i);
|
|
||||||
core::dimension2d<u32> rect = m_font->getDimension(kart->getName().c_str());
|
|
||||||
if(rect.Width > max_name_width) max_name_width = rect.Width;
|
|
||||||
if(kart->getFinishTime() > max_finish_time)
|
|
||||||
max_finish_time = kart->getFinishTime();
|
|
||||||
} // for i<num_karts
|
|
||||||
|
|
||||||
// Not all digits have the same width. So to properly align the times
|
// Not all digits have the same width. So to properly align the times
|
||||||
// and points, we have to do the layout one digit at a time, and we
|
// and points, we have to do the layout one digit at a time, and we
|
||||||
// need the maximum size of one digit for that:
|
// need the maximum size of one digit for that:
|
||||||
@ -133,6 +158,9 @@ void RaceResultGUI::determineLayout()
|
|||||||
core::dimension2du r = m_font->getDimension(s);
|
core::dimension2du r = m_font->getDimension(s);
|
||||||
if(r.Width > m_max_digit_width) m_max_digit_width = r.Width;
|
if(r.Width > m_max_digit_width) m_max_digit_width = r.Width;
|
||||||
}
|
}
|
||||||
|
core::dimension2du r = m_font->getDimension(L":");
|
||||||
|
m_colon_width = r.Width;
|
||||||
|
|
||||||
m_column_space_size = 20;
|
m_column_space_size = 20;
|
||||||
} // determineLayout
|
} // determineLayout
|
||||||
|
|
||||||
@ -143,28 +171,43 @@ void RaceResultGUI::determineLayout()
|
|||||||
*/
|
*/
|
||||||
void RaceResultGUI::renderGlobal(float dt)
|
void RaceResultGUI::renderGlobal(float dt)
|
||||||
{
|
{
|
||||||
|
m_timer += dt;
|
||||||
|
switch(m_animation_state)
|
||||||
|
{
|
||||||
|
case RR_BEGIN_FIRST_TABLE:
|
||||||
|
if(m_timer > m_time_overall_scroll)
|
||||||
|
{
|
||||||
|
m_animation_state = RR_INCREASE_POINTS;
|
||||||
|
m_timer = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RR_INCREASE_POINTS:
|
||||||
|
if(m_timer > 5)
|
||||||
|
{
|
||||||
|
m_animation_state = RR_RESORT_TABLE;
|
||||||
|
m_timer = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RR_RESORT_TABLE:
|
||||||
|
break;
|
||||||
|
case RR_WAIT_TILL_END:
|
||||||
|
break;
|
||||||
|
} // switch
|
||||||
World *world = World::getWorld();
|
World *world = World::getWorld();
|
||||||
assert(world->getPhase()==WorldStatus::RESULT_DISPLAY_PHASE);
|
assert(world->getPhase()==WorldStatus::RESULT_DISPLAY_PHASE);
|
||||||
|
|
||||||
m_timer += dt;
|
|
||||||
|
|
||||||
unsigned int num_karts = world->getNumKarts();
|
unsigned int num_karts = world->getNumKarts();
|
||||||
|
|
||||||
// How long it takes for one line to scroll from right to left
|
float v = 0.9f*UserConfigParams::m_width/m_time_single_scroll;
|
||||||
float scroll_duration = 0.5f;
|
for(unsigned int i=0; i<m_kart_names.size(); i++)
|
||||||
|
|
||||||
float v = 0.9f*UserConfigParams::m_width/scroll_duration;
|
|
||||||
for(unsigned int i=0; i<num_karts; i++)
|
|
||||||
{
|
{
|
||||||
if(m_order[i]==-1) continue;
|
|
||||||
if(m_start_at[i]>m_timer) continue;
|
if(m_start_at[i]>m_timer) continue;
|
||||||
m_x_pos[i] -= dt*v;
|
m_x_pos[i] -= dt*v;
|
||||||
if(m_x_pos[i]<0.1f*UserConfigParams::m_width)
|
if(m_x_pos[i]<0.1f*UserConfigParams::m_width)
|
||||||
m_x_pos[i] = 0.1f*UserConfigParams::m_width;
|
m_x_pos[i] = 0.1f*UserConfigParams::m_width;
|
||||||
printf("%d: %f %d\n", i, m_x_pos[i], m_y_pos[i]);
|
|
||||||
displayOneEntry((unsigned int)(m_x_pos[i]), m_y_pos[i],
|
displayOneEntry((unsigned int)(m_x_pos[i]), m_y_pos[i],
|
||||||
m_order[i], true);
|
i, true);
|
||||||
}
|
}
|
||||||
} // renderGlobal
|
} // renderGlobal
|
||||||
|
|
||||||
@ -187,15 +230,53 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y,
|
|||||||
|
|
||||||
// First draw the icon
|
// First draw the icon
|
||||||
// -------------------
|
// -------------------
|
||||||
video::ITexture *t = kart->getKartProperties()->getIconMaterial()->getTexture();
|
core::recti source_rect(core::vector2di(0,0), m_kart_icons[n]->getSize());
|
||||||
core::recti source_rect(core::vector2di(0,0), t->getSize());
|
|
||||||
core::recti dest_rect(x, y, x+m_icon_width, y+m_icon_width);
|
core::recti dest_rect(x, y, x+m_icon_width, y+m_icon_width);
|
||||||
irr_driver->getVideoDriver()->draw2DImage(t, dest_rect, source_rect,
|
irr_driver->getVideoDriver()->draw2DImage(m_kart_icons[n], dest_rect,
|
||||||
NULL, NULL, true);
|
source_rect, NULL, NULL, true);
|
||||||
// Draw the name
|
// Draw the name
|
||||||
// -------------
|
// -------------
|
||||||
core::recti pos(x+m_icon_width+m_column_space_size, y,
|
core::recti pos_name(x+m_icon_width+m_column_space_size, y,
|
||||||
UserConfigParams::m_width, y+m_distance_between_rows);
|
UserConfigParams::m_width, y+m_distance_between_rows);
|
||||||
|
|
||||||
m_font->draw(m_entry[n], pos, color);
|
m_font->draw(m_kart_names[n], pos_name, color);
|
||||||
|
|
||||||
|
// Draw the time
|
||||||
|
// -------------
|
||||||
|
unsigned int x_time = x + m_icon_width + m_column_space_size
|
||||||
|
+ m_max_kart_name_width + m_column_space_size;
|
||||||
|
|
||||||
|
bool mono = m_font->getMonospaceDigits();
|
||||||
|
//m_font->setMonospaceDigits(true);
|
||||||
|
dest_rect = core::recti(x_time, y, x_time+100, y+10);
|
||||||
|
m_font->draw(m_time_strings[n], dest_rect, color);
|
||||||
|
m_font->setMonospaceDigits(mono);
|
||||||
|
|
||||||
|
// Draw the new points
|
||||||
|
// -------------------
|
||||||
|
unsigned int x_point = x + m_icon_width + m_column_space_size
|
||||||
|
+ m_max_kart_name_width + m_column_space_size
|
||||||
|
+ m_time_width + m_column_space_size;
|
||||||
|
dest_rect = core::recti(x_point, y, x_point+100, y+10);
|
||||||
|
core::stringw point_string = core::stringw("+")+core::stringw(m_new_points[n]);
|
||||||
|
while(point_string.size()<3)
|
||||||
|
point_string = core::stringw(" ")+point_string;
|
||||||
|
m_font->draw(point_string, dest_rect, color);
|
||||||
|
|
||||||
} // displayOneEntry
|
} // displayOneEntry
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void RaceResultGUI::drawNumber(const core::stringw &number_string,
|
||||||
|
unsigned int *x, unsigned int y,
|
||||||
|
const video::SColor &color)
|
||||||
|
{
|
||||||
|
for(unsigned int i=0; i<number_string.size(); i++)
|
||||||
|
{
|
||||||
|
core::recti p(*x, y, *x+m_max_digit_width, y+10);
|
||||||
|
m_font->draw(number_string.subString(i,1), p, color);
|
||||||
|
if(number_string[i]==':')
|
||||||
|
*x+=m_colon_width;
|
||||||
|
else
|
||||||
|
*x+=m_max_digit_width;
|
||||||
|
} // for i<number_string.size
|
||||||
|
} // drawNumber
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "states_screens/race_gui_base.hpp"
|
#include "states_screens/race_gui_base.hpp"
|
||||||
|
#include "guiengine/CGUIFont.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Displays the results (while the end animation is shown).
|
* \brief Displays the results (while the end animation is shown).
|
||||||
@ -32,15 +33,65 @@
|
|||||||
class RaceResultGUI : public RaceGUIBase
|
class RaceResultGUI : public RaceGUIBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
/** Timer variable for animations. */
|
||||||
float m_timer;
|
float m_timer;
|
||||||
|
|
||||||
|
/** Finite state machine for the animations:
|
||||||
|
BEGIN_FIRST_TABLE: The rows scroll into place.
|
||||||
|
INCREASE_POINTS: The overall points are added up
|
||||||
|
RESORT_TABLE: Resort the table so that it is now sorted by
|
||||||
|
GP points.
|
||||||
|
WAIT_TILL_END Some delay to wait for end, after a period it
|
||||||
|
wii automatically end. */
|
||||||
|
enum {RR_BEGIN_FIRST_TABLE,
|
||||||
|
RR_INCREASE_POINTS,
|
||||||
|
RR_RESORT_TABLE,
|
||||||
|
RR_WAIT_TILL_END}
|
||||||
|
m_animation_state;
|
||||||
|
|
||||||
|
/** Start time for each line of the animation. */
|
||||||
std::vector<float> m_start_at;
|
std::vector<float> m_start_at;
|
||||||
|
|
||||||
|
/** Currenct X position. */
|
||||||
std::vector<float> m_x_pos;
|
std::vector<float> m_x_pos;
|
||||||
|
|
||||||
|
/** Currenct Y position. */
|
||||||
std::vector<int> m_y_pos;
|
std::vector<int> m_y_pos;
|
||||||
std::vector<core::stringw> m_entry;
|
|
||||||
|
/** The order in which to display the karts. */
|
||||||
|
std::vector<int> m_order;
|
||||||
|
|
||||||
|
/** The names of all karts in the right order. */
|
||||||
|
std::vector<core::stringw> m_kart_names;
|
||||||
|
|
||||||
|
/** Points earned in this race. */
|
||||||
|
std::vector<int> m_new_points;
|
||||||
|
|
||||||
|
/** When updating the number of points in the display, this is the
|
||||||
|
currently displayed number of points, so
|
||||||
|
m_old_overall_points <= m_current_displayed_points<=
|
||||||
|
m_old_overall_points+m_new_points. */
|
||||||
|
std::vector<int> m_current_displayed_points;
|
||||||
|
|
||||||
|
/** Overall points before this race. */
|
||||||
|
std::vector<int> m_old_overall_points;
|
||||||
|
|
||||||
|
/** The kart icons. */
|
||||||
|
std::vector<video::ITexture*> m_kart_icons;
|
||||||
|
|
||||||
|
/** The times of all karts in the right order. */
|
||||||
|
std::vector<core::stringw> m_time_strings;
|
||||||
|
|
||||||
/** Time to wait till the next row starts to be animated. */
|
/** Time to wait till the next row starts to be animated. */
|
||||||
float m_time_between_rows;
|
float m_time_between_rows;
|
||||||
|
|
||||||
|
/** The time a single line scrolls into place. */
|
||||||
|
float m_time_single_scroll;
|
||||||
|
|
||||||
|
/** The overall time the first phase (scrolling) is displayed.
|
||||||
|
This includes a small waiting time at the end. */
|
||||||
|
float m_time_overall_scroll;
|
||||||
|
|
||||||
/** Distance between each row of the race results */
|
/** Distance between each row of the race results */
|
||||||
unsigned int m_distance_between_rows;
|
unsigned int m_distance_between_rows;
|
||||||
|
|
||||||
@ -50,26 +101,31 @@ private:
|
|||||||
/** The width of the time column. */
|
/** The width of the time column. */
|
||||||
unsigned int m_time_width;
|
unsigned int m_time_width;
|
||||||
|
|
||||||
|
/** Width of the kart name column. */
|
||||||
|
unsigned int m_max_kart_name_width;
|
||||||
|
|
||||||
/** The width of the point column. */
|
/** The width of the point column. */
|
||||||
unsigned int m_column_width;
|
unsigned int m_column_width;
|
||||||
|
|
||||||
/** The order in which to display the karts. */
|
|
||||||
std::vector<int> m_order;
|
|
||||||
|
|
||||||
/** The width of the largest digit (not all digits
|
/** The width of the largest digit (not all digits
|
||||||
* have the same font size) */
|
* have the same font size) */
|
||||||
unsigned int m_max_digit_width ;
|
unsigned int m_max_digit_width ;
|
||||||
|
|
||||||
|
/** The width of a ":" (used in time display mm:ss:hh). */
|
||||||
|
unsigned int m_colon_width;
|
||||||
|
|
||||||
/** Size of space between columns. */
|
/** Size of space between columns. */
|
||||||
unsigned int m_column_space_size;
|
unsigned int m_column_space_size;
|
||||||
|
|
||||||
/** The font to use. */
|
/** The font to use. */
|
||||||
gui::IGUIFont* m_font;
|
gui::ScalableFont* m_font;
|
||||||
|
|
||||||
void displayOneEntry(unsigned int x, unsigned int y,
|
void displayOneEntry(unsigned int x, unsigned int y,
|
||||||
unsigned int n, bool display_points);
|
unsigned int n, bool display_points);
|
||||||
void determineLayout();
|
void determineLayout();
|
||||||
|
void drawNumber(const core::stringw &number_string,
|
||||||
|
unsigned int *x, unsigned int y,
|
||||||
|
const video::SColor &color);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RaceResultGUI();
|
RaceResultGUI();
|
||||||
|
Loading…
Reference in New Issue
Block a user