work towards encapsulation of race results display
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2344 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
e92747fe56
commit
35c1c3eb32
@ -40,10 +40,7 @@ RaceResultsGUI::RaceResultsGUI()
|
|||||||
network_manager->beginRaceResultBarrier();
|
network_manager->beginRaceResultBarrier();
|
||||||
Widget *bottom_of_list;
|
Widget *bottom_of_list;
|
||||||
|
|
||||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
|
bottom_of_list = displayRaceResults();
|
||||||
bottom_of_list = displayLeaderResults();
|
|
||||||
else
|
|
||||||
bottom_of_list = displayRaceResults();
|
|
||||||
|
|
||||||
// If it's a server, the user can only select 'ok', since the
|
// If it's a server, the user can only select 'ok', since the
|
||||||
// server does all the game mode selection etc.
|
// server does all the game mode selection etc.
|
||||||
@ -89,6 +86,7 @@ RaceResultsGUI::RaceResultsGUI()
|
|||||||
} // RaceResultsGUI
|
} // RaceResultsGUI
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
#if 0
|
||||||
Widget *RaceResultsGUI::displayLeaderResults()
|
Widget *RaceResultsGUI::displayLeaderResults()
|
||||||
{
|
{
|
||||||
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
@ -138,6 +136,7 @@ Widget *RaceResultsGUI::displayLeaderResults()
|
|||||||
delete []race_time;
|
delete []race_time;
|
||||||
return w_prev;
|
return w_prev;
|
||||||
} // displayLeaderResults
|
} // displayLeaderResults
|
||||||
|
#endif
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
Widget *RaceResultsGUI::displayRaceResults()
|
Widget *RaceResultsGUI::displayRaceResults()
|
||||||
@ -145,25 +144,25 @@ Widget *RaceResultsGUI::displayRaceResults()
|
|||||||
Widget *w_prev=widget_manager->addTextWgt( WTOK_RESULTS, 5, 7, _("Race results") );
|
Widget *w_prev=widget_manager->addTextWgt( WTOK_RESULTS, 5, 7, _("Race results") );
|
||||||
widget_manager->hideWgtRect(WTOK_RESULTS);
|
widget_manager->hideWgtRect(WTOK_RESULTS);
|
||||||
w_prev->setPosition(WGT_DIR_FROM_LEFT, 0.1f, NULL, WGT_DIR_FROM_TOP, 0.1f, NULL);
|
w_prev->setPosition(WGT_DIR_FROM_LEFT, 0.1f, NULL, WGT_DIR_FROM_TOP, 0.1f, NULL);
|
||||||
|
|
||||||
const unsigned int MAX_STR_LEN = 60;
|
const unsigned int MAX_STR_LEN = 60;
|
||||||
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
|
|
||||||
int* order = new int [NUM_KARTS];
|
int* order = new int [NUM_KARTS];
|
||||||
|
RaceManager::getWorld()->raceResultOrder( order );
|
||||||
|
|
||||||
unsigned int max_name_len = 1;
|
unsigned int max_name_len = 1;
|
||||||
|
|
||||||
for(unsigned int i=0; i < NUM_KARTS; i++)
|
for(unsigned int i=0; i < NUM_KARTS; i++)
|
||||||
{
|
{
|
||||||
Kart *k = RaceManager::getKart(i); // Display even for eliminated karts!
|
Kart *k = RaceManager::getKart(i); // Display even for eliminated karts!
|
||||||
order[k->getPosition()-1] = i;
|
|
||||||
const std::string& s = k->getName();
|
const std::string& s = k->getName();
|
||||||
unsigned int l = (unsigned int)s.size();
|
unsigned int l = (unsigned int)s.size();
|
||||||
if(l>max_name_len) max_name_len = l;
|
if(l>max_name_len) max_name_len = l;
|
||||||
} // for i
|
} // for i
|
||||||
|
|
||||||
// save bottom of result list for later
|
// save bottom of result list for later
|
||||||
Widget *bottom_of_list=displayKartList(0, NUM_KARTS-1, w_prev,
|
Widget *bottom_of_list=displayKartList(w_prev, order, 0.1f);
|
||||||
order, /*displayTime*/ true, 0.1f);
|
|
||||||
|
|
||||||
delete[] order;
|
delete[] order;
|
||||||
|
|
||||||
@ -203,14 +202,18 @@ Widget *RaceResultsGUI::displayRaceResults()
|
|||||||
} // displayRaceResults
|
} // displayRaceResults
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
Widget *RaceResultsGUI::displayKartList(unsigned int from, unsigned int to,
|
Widget *RaceResultsGUI::displayKartList(Widget *w_prev, int *order, float horizontal)
|
||||||
Widget *w_prev, int *order,
|
|
||||||
bool display_time, float horizontal)
|
|
||||||
{
|
{
|
||||||
|
const bool display_time = RaceManager::getWorld()->getClockMode() == CHRONO;
|
||||||
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
|
|
||||||
const int MAX_STR_LEN=60;
|
const int MAX_STR_LEN=60;
|
||||||
char *score = new char[(to-from+1) * MAX_STR_LEN];
|
char *score = new char[NUM_KARTS * MAX_STR_LEN];
|
||||||
for(unsigned int i = from; i <= to; ++i)
|
int kart_id = 0; // 'i' below is not reliable because some karts (e.g. leader) will be skipped
|
||||||
|
for(unsigned int i = 0; i < NUM_KARTS; ++i)
|
||||||
{
|
{
|
||||||
|
if(order[i] == -1) continue;
|
||||||
|
|
||||||
const Kart *KART = RaceManager::getKart(order[i]);
|
const Kart *KART = RaceManager::getKart(order[i]);
|
||||||
const std::string& KART_NAME = KART->getName();
|
const std::string& KART_NAME = KART->getName();
|
||||||
char sTime[20];sTime[0]=0;
|
char sTime[20];sTime[0]=0;
|
||||||
@ -232,19 +235,21 @@ Widget *RaceResultsGUI::displayKartList(unsigned int from, unsigned int to,
|
|||||||
KART->getPosition(), KART_NAME.c_str(), sTime);
|
KART->getPosition(), KART_NAME.c_str(), sTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *image=widget_manager->addImgButtonWgt(WTOK_FIRST_IMAGE + i, 7, 7,
|
Widget *image=widget_manager->addImgButtonWgt(WTOK_FIRST_IMAGE + kart_id, 7, 7,
|
||||||
KART->getKartProperties()->getIconFile() );
|
KART->getKartProperties()->getIconFile() );
|
||||||
widget_manager->deactivateWgt(WTOK_FIRST_IMAGE+i);
|
widget_manager->deactivateWgt(WTOK_FIRST_IMAGE+kart_id);
|
||||||
|
|
||||||
image->setPosition(WGT_DIR_FROM_LEFT, horizontal, NULL,
|
image->setPosition(WGT_DIR_FROM_LEFT, horizontal, NULL,
|
||||||
WGT_DIR_UNDER_WIDGET, 0.0f, w_prev);
|
WGT_DIR_UNDER_WIDGET, 0.0f, w_prev);
|
||||||
Widget *w=widget_manager->addTextWgt(WTOK_FIRST_RESULT + i, 5, 7,
|
Widget *w=widget_manager->addTextWgt(WTOK_FIRST_RESULT + kart_id, 5, 7,
|
||||||
(char*)(score + MAX_STR_LEN * i) );
|
(char*)(score + MAX_STR_LEN * i) );
|
||||||
w->setPosition(WGT_DIR_RIGHT_WIDGET, 0.1f, image,
|
w->setPosition(WGT_DIR_RIGHT_WIDGET, 0.1f, image,
|
||||||
WGT_DIR_UNDER_WIDGET, 0.0f, w_prev);
|
WGT_DIR_UNDER_WIDGET, 0.0f, w_prev);
|
||||||
w_prev=w;
|
w_prev=w;
|
||||||
|
|
||||||
|
kart_id++;
|
||||||
}
|
}
|
||||||
widget_manager->sameWidth(WTOK_FIRST_RESULT+from, WTOK_FIRST_RESULT+to);
|
widget_manager->sameWidth(WTOK_FIRST_RESULT, WTOK_FIRST_RESULT+kart_id-1);
|
||||||
return w_prev;
|
return w_prev;
|
||||||
} // displayKartList
|
} // displayKartList
|
||||||
|
|
||||||
|
@ -49,11 +49,8 @@ private:
|
|||||||
/** The widget selected by the user, so that the right action can be done
|
/** The widget selected by the user, so that the right action can be done
|
||||||
* once clients and server are synchronised. */
|
* once clients and server are synchronised. */
|
||||||
WidgetTokens m_selected_widget;
|
WidgetTokens m_selected_widget;
|
||||||
Widget *displayLeaderResults();
|
|
||||||
Widget *displayRaceResults();
|
Widget *displayRaceResults();
|
||||||
Widget *displayKartList(unsigned int from, unsigned int to,
|
Widget *displayKartList(Widget *w_prev, int *order, float horizontal);
|
||||||
Widget *w_prev, int *order, bool display_time,
|
|
||||||
float horizontal);
|
|
||||||
public:
|
public:
|
||||||
RaceResultsGUI();
|
RaceResultsGUI();
|
||||||
~RaceResultsGUI();
|
~RaceResultsGUI();
|
||||||
|
@ -106,6 +106,7 @@ void FollowTheLeaderRace::terminateRace()
|
|||||||
LinearWorld::terminateRace();
|
LinearWorld::terminateRace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark overridden from World
|
#pragma mark overridden from World
|
||||||
@ -134,3 +135,45 @@ KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo(const RaceGUI* cal
|
|||||||
m_kart_display_info[0].special_title = _("Leader");
|
m_kart_display_info[0].special_title = _("Leader");
|
||||||
return m_kart_display_info;
|
return m_kart_display_info;
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void FollowTheLeaderRace::raceResultOrder( int* order )
|
||||||
|
{
|
||||||
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
|
|
||||||
|
int *scores = new int[NUM_KARTS];
|
||||||
|
double *race_time = new double[NUM_KARTS];
|
||||||
|
|
||||||
|
// Ignore kart 0, since it was the leader
|
||||||
|
order[0] = -1;
|
||||||
|
for( unsigned int kart_id = 1; kart_id < NUM_KARTS; ++kart_id )
|
||||||
|
{
|
||||||
|
order[kart_id] = kart_id;
|
||||||
|
scores[kart_id] = race_manager->getKartScore(kart_id);
|
||||||
|
race_time[kart_id] = race_manager->getOverallTime(kart_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Bubblesort
|
||||||
|
bool sorted;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
sorted = true;
|
||||||
|
for( unsigned int i = 1; i < NUM_KARTS - 1; ++i )
|
||||||
|
{
|
||||||
|
if( scores[order[i]] < scores[order[i+1]] ||
|
||||||
|
(scores[order[i]] == scores[order[i+1]]
|
||||||
|
&& race_time[order[i]] > race_time[order[i+1]]) )
|
||||||
|
{
|
||||||
|
int tmp = order[i];
|
||||||
|
order[i] = order[i+1];
|
||||||
|
order[i+1] = tmp;
|
||||||
|
sorted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(!sorted);
|
||||||
|
for(unsigned int i=1; i<NUM_KARTS; i++)
|
||||||
|
RaceManager::getKart(order[i])->setPosition(i);
|
||||||
|
|
||||||
|
delete []scores;
|
||||||
|
delete []race_time;
|
||||||
|
}
|
||||||
|
@ -40,6 +40,10 @@ public:
|
|||||||
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
|
virtual KartIconDisplayInfo* getKartsDisplayInfo(const RaceGUI* caller);
|
||||||
|
|
||||||
virtual bool raceHasLaps(){ return false; }
|
virtual bool raceHasLaps(){ return false; }
|
||||||
|
|
||||||
|
/** Called by the race result GUI at the end of the race to know the final order
|
||||||
|
(fill in the 'order' array) */
|
||||||
|
virtual void raceResultOrder( int* order );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -425,6 +425,14 @@ void LinearWorld::terminateRace()
|
|||||||
} // if !hasFinishedRace
|
} // if !hasFinishedRace
|
||||||
} // for i
|
} // for i
|
||||||
}
|
}
|
||||||
|
void LinearWorld::raceResultOrder( int* order )
|
||||||
|
{
|
||||||
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
|
for(unsigned int i=0; i < NUM_KARTS; i++)
|
||||||
|
{
|
||||||
|
order[RaceManager::getKart(i)->getPosition()-1] = i; // even for eliminated karts
|
||||||
|
}
|
||||||
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
float LinearWorld::estimateFinishTimeForKart (Kart* kart, KartInfo& kart_info)
|
float LinearWorld::estimateFinishTimeForKart (Kart* kart, KartInfo& kart_info)
|
||||||
{
|
{
|
||||||
|
@ -85,8 +85,11 @@ public:
|
|||||||
virtual void terminateRace();
|
virtual void terminateRace();
|
||||||
virtual void restartRace();
|
virtual void restartRace();
|
||||||
|
|
||||||
|
|
||||||
virtual bool raceHasLaps(){ return true; }
|
virtual bool raceHasLaps(){ return true; }
|
||||||
|
|
||||||
|
/** Called by the race result GUI at the end of the race to know the final order
|
||||||
|
(fill in the 'order' array) */
|
||||||
|
virtual void raceResultOrder( int* order );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
ThreeStrikesBattle::ThreeStrikesBattle() : World()
|
ThreeStrikesBattle::ThreeStrikesBattle() : World()
|
||||||
{
|
{
|
||||||
TimedRace::setClockMode(CHRONO);
|
TimedRace::setClockMode(CHRONO);
|
||||||
@ -46,13 +47,12 @@ ThreeStrikesBattle::ThreeStrikesBattle() : World()
|
|||||||
m_kart[n]->setPosition(-1);
|
m_kart[n]->setPosition(-1);
|
||||||
}// next kart
|
}// next kart
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
ThreeStrikesBattle::~ThreeStrikesBattle()
|
ThreeStrikesBattle::~ThreeStrikesBattle()
|
||||||
{
|
{
|
||||||
delete[] m_kart_display_info;
|
delete[] m_kart_display_info;
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ThreeStrikesBattle::onGo()
|
void ThreeStrikesBattle::onGo()
|
||||||
{
|
{
|
||||||
// Reset the brakes now that the prestart
|
// Reset the brakes now that the prestart
|
||||||
@ -63,11 +63,12 @@ void ThreeStrikesBattle::onGo()
|
|||||||
m_kart[i]->resetBrakes();
|
m_kart[i]->resetBrakes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void ThreeStrikesBattle::terminateRace()
|
void ThreeStrikesBattle::terminateRace()
|
||||||
{
|
{
|
||||||
World::terminateRace();
|
World::terminateRace();
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void ThreeStrikesBattle::kartHit(const int kart_id)
|
void ThreeStrikesBattle::kartHit(const int kart_id)
|
||||||
{
|
{
|
||||||
assert(kart_id >= 0);
|
assert(kart_id >= 0);
|
||||||
@ -84,10 +85,12 @@ void ThreeStrikesBattle::kartHit(const int kart_id)
|
|||||||
if(getCurrentNumKarts()==2)
|
if(getCurrentNumKarts()==2)
|
||||||
sound_manager->switchToFastMusic();
|
sound_manager->switchToFastMusic();
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
std::string ThreeStrikesBattle::getInternalCode() const
|
std::string ThreeStrikesBattle::getInternalCode() const
|
||||||
{
|
{
|
||||||
return "BATTLE_3_STRIKES";
|
return "BATTLE_3_STRIKES";
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void ThreeStrikesBattle::update(float delta)
|
void ThreeStrikesBattle::update(float delta)
|
||||||
{
|
{
|
||||||
World::update(delta);
|
World::update(delta);
|
||||||
@ -104,6 +107,7 @@ void ThreeStrikesBattle::update(float delta)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void ThreeStrikesBattle::restartRace()
|
void ThreeStrikesBattle::restartRace()
|
||||||
{
|
{
|
||||||
World::restartRace();
|
World::restartRace();
|
||||||
@ -116,7 +120,7 @@ void ThreeStrikesBattle::restartRace()
|
|||||||
}// next kart
|
}// next kart
|
||||||
}
|
}
|
||||||
//void ThreeStrikesBattle::getDefaultCollectibles(int& collectible_type, int& amount)
|
//void ThreeStrikesBattle::getDefaultCollectibles(int& collectible_type, int& amount)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo(const RaceGUI* caller)
|
KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo(const RaceGUI* caller)
|
||||||
{
|
{
|
||||||
const unsigned int kart_amount = race_manager->getNumKarts();
|
const unsigned int kart_amount = race_manager->getNumKarts();
|
||||||
@ -159,7 +163,7 @@ KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo(const RaceGUI* call
|
|||||||
|
|
||||||
return m_kart_display_info;
|
return m_kart_display_info;
|
||||||
}
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
||||||
{
|
{
|
||||||
// find closest point to drop kart on
|
// find closest point to drop kart on
|
||||||
@ -202,4 +206,15 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body)
|
|||||||
|
|
||||||
body->setCenterOfMassTransform(pos);
|
body->setCenterOfMassTransform(pos);
|
||||||
|
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void ThreeStrikesBattle::raceResultOrder( int* order )
|
||||||
|
{
|
||||||
|
// FIXME - implement properly
|
||||||
|
const unsigned int NUM_KARTS = race_manager->getNumKarts();
|
||||||
|
|
||||||
|
for( unsigned int kart_id = 0; kart_id < NUM_KARTS; ++kart_id )
|
||||||
|
{
|
||||||
|
order[kart_id] = kart_id;
|
||||||
|
}
|
||||||
}
|
}
|
@ -59,6 +59,10 @@ public:
|
|||||||
virtual std::string getInternalCode() const;
|
virtual std::string getInternalCode() const;
|
||||||
|
|
||||||
virtual void kartHit(const int kart_id);
|
virtual void kartHit(const int kart_id);
|
||||||
|
|
||||||
|
/** Called by the race result GUI at the end of the race to know the final order
|
||||||
|
(fill in the 'order' array) */
|
||||||
|
virtual void raceResultOrder( int* order );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,6 +192,10 @@ public:
|
|||||||
/** Called when a kart was hit by a projectile
|
/** Called when a kart was hit by a projectile
|
||||||
*/
|
*/
|
||||||
virtual void kartHit(const int kart_id) {};
|
virtual void kartHit(const int kart_id) {};
|
||||||
|
|
||||||
|
/** Called by the race result GUI at the end of the race to know the final order
|
||||||
|
(fill in the 'order' array) */
|
||||||
|
virtual void raceResultOrder( int* order ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user