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:
hikerstk 2010-07-20 23:01:47 +00:00
parent 8e48d227b8
commit 7557d4be8b
2 changed files with 199 additions and 62 deletions

View File

@ -28,15 +28,19 @@
*/
RaceResultGUI::RaceResultGUI()
{
// FIXME: for now disable the new race result display
// by just firing up the old display (which will make sure
// that the rendering for this object is not called anymore).
new RaceOverDialog(0.6f, 0.9f);
return;
#undef USE_NEW_RACE_RESULT
#ifndef USE_NEW_RACE_RESULT
// FIXME: for now disable the new race result display
// by just firing up the old display (which will make sure
// that the rendering for this object is not called anymore).
new RaceOverDialog(0.6f, 0.9f);
return;
#else
determineLayout();
m_timer = 0;
m_animation_state = RR_BEGIN_FIRST_TABLE;
#endif
} // RaceResultGUI
//-----------------------------------------------------------------------------
@ -63,65 +67,86 @@ void RaceResultGUI::nextPhase()
*/
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
unsigned int top = (int)(0.15f*UserConfigParams::m_height);
// Height of the result display
unsigned int height = (int)(0.7f *UserConfigParams::m_height);
// Setup different timing information for the different phases
// -----------------------------------------------------------
// How much time between consecutive rows
m_time_between_rows = 0.5f;
World *world = World::getWorld();
unsigned int num_karts = world->getNumKarts();
// How long it takes for one line to scroll from right to left
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
m_font = GUIEngine::getFont();
core::dimension2du text_size = m_font->getDimension(L"a");
core::dimension2du text_size = m_font->getDimension(L"Y");
m_distance_between_rows = (int)(1.5f*text_size.Height);
// If there are too many karts, reduce size between rows
if(m_distance_between_rows * num_karts > height)
m_distance_between_rows = height / num_karts;
world->raceResultOrder(&m_order);
m_start_at.clear();
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_x_pos.push_back((float)UserConfigParams::m_width);
m_y_pos.push_back(m_distance_between_rows+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_y_pos.push_back(top+i*m_distance_between_rows);
}
m_icon_width = UserConfigParams::m_height<600
? 27
: (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
// and points, we have to do the layout one digit at a time, and we
// need the maximum size of one digit for that:
@ -133,7 +158,10 @@ void RaceResultGUI::determineLayout()
core::dimension2du r = m_font->getDimension(s);
if(r.Width > m_max_digit_width) m_max_digit_width = r.Width;
}
m_column_space_size = 20;
core::dimension2du r = m_font->getDimension(L":");
m_colon_width = r.Width;
m_column_space_size = 20;
} // determineLayout
//-----------------------------------------------------------------------------
@ -143,28 +171,43 @@ void RaceResultGUI::determineLayout()
*/
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();
assert(world->getPhase()==WorldStatus::RESULT_DISPLAY_PHASE);
m_timer += dt;
unsigned int num_karts = world->getNumKarts();
// How long it takes for one line to scroll from right to left
float scroll_duration = 0.5f;
float v = 0.9f*UserConfigParams::m_width/scroll_duration;
for(unsigned int i=0; i<num_karts; i++)
float v = 0.9f*UserConfigParams::m_width/m_time_single_scroll;
for(unsigned int i=0; i<m_kart_names.size(); i++)
{
if(m_order[i]==-1) continue;
if(m_start_at[i]>m_timer) continue;
m_x_pos[i] -= dt*v;
if(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],
m_order[i], true);
i, true);
}
} // renderGlobal
@ -187,15 +230,53 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y,
// First draw the icon
// -------------------
video::ITexture *t = kart->getKartProperties()->getIconMaterial()->getTexture();
core::recti source_rect(core::vector2di(0,0), t->getSize());
core::recti source_rect(core::vector2di(0,0), m_kart_icons[n]->getSize());
core::recti dest_rect(x, y, x+m_icon_width, y+m_icon_width);
irr_driver->getVideoDriver()->draw2DImage(t, dest_rect, source_rect,
NULL, NULL, true);
irr_driver->getVideoDriver()->draw2DImage(m_kart_icons[n], dest_rect,
source_rect, NULL, NULL, true);
// Draw the name
// -------------
core::recti pos(x+m_icon_width+m_column_space_size, y,
UserConfigParams::m_width, y+m_distance_between_rows);
core::recti pos_name(x+m_icon_width+m_column_space_size, y,
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
//-----------------------------------------------------------------------------
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

View File

@ -24,6 +24,7 @@
#include <vector>
#include "states_screens/race_gui_base.hpp"
#include "guiengine/CGUIFont.h"
/**
* \brief Displays the results (while the end animation is shown).
@ -32,15 +33,65 @@
class RaceResultGUI : public RaceGUIBase
{
private:
/** Timer variable for animations. */
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;
/** Currenct X position. */
std::vector<float> m_x_pos;
/** Currenct Y position. */
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. */
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 */
unsigned int m_distance_between_rows;
@ -50,26 +101,31 @@ private:
/** The width of the time column. */
unsigned int m_time_width;
/** Width of the kart name column. */
unsigned int m_max_kart_name_width;
/** The width of the point column. */
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
* 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. */
unsigned int m_column_space_size;
/** The font to use. */
gui::IGUIFont* m_font;
gui::ScalableFont* m_font;
void displayOneEntry(unsigned int x, unsigned int y,
unsigned int n, bool display_points);
void determineLayout();
void drawNumber(const core::stringw &number_string,
unsigned int *x, unsigned int y,
const video::SColor &color);
public:
RaceResultGUI();