From 70ef7966e135aadff8b9803ea087cc8346f714f6 Mon Sep 17 00:00:00 2001 From: yasin-ghannam Date: Mon, 14 Oct 2013 00:23:20 +0000 Subject: [PATCH] Modified Soccer Mode results screen. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14249 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/modes/soccer_world.cpp | 26 ++- src/modes/soccer_world.hpp | 21 ++- src/physics/physical_object.cpp | 5 + src/physics/physical_object.hpp | 2 + src/physics/physics.cpp | 7 + src/states_screens/race_result_gui.cpp | 217 ++++++++++++++++--------- src/states_screens/race_result_gui.hpp | 1 + 7 files changed, 200 insertions(+), 79 deletions(-) diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 72983a414..8febab091 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -54,6 +54,7 @@ void SoccerWorld::init() WorldWithRank::init(); m_display_rank = false; m_goal_timer = 0.f; + m_lastKartToHitBall = -1; // check for possible problems if AI karts were incorrectly added if(getNumKarts() > race_manager->getNumPlayers()) @@ -62,7 +63,6 @@ void SoccerWorld::init() exit(1); } m_goal_target = race_manager->getMaxGoal(); - printf("Max Goal: %d\n", m_goal_target); m_goal_sound = sfx_manager->createSoundSource("goal_scored"); } // init @@ -80,7 +80,11 @@ void SoccerWorld::reset() // Reset original positions for the soccer balls TrackObjectManager* tom = getTrack()->getTrackObjectManager(); assert(tom); - + m_redScorers.clear(); + m_redScoreTimes.clear(); + m_blueScorers.clear(); + m_blueScoreTimes.clear(); + m_lastKartToHitBall = -1; PtrVector& objects = tom->getObjects(); for(int i=0; isetPhase(WorldStatus::GOAL_PHASE); m_goal_sound->play(); + if(m_lastKartToHitBall != -1) + { + if(first_goal){ + m_redScorers.push_back(m_lastKartToHitBall); + m_redScoreTimes.push_back(world->getTime()); + } + else{ + m_blueScorers.push_back(m_lastKartToHitBall); + m_blueScoreTimes.push_back(world->getTime()); + } + } } //m_check_goals_enabled = false; // TODO: remove? @@ -178,6 +193,13 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal) // TODO: rescue the karts } // onCheckGoalTriggered +//----------------------------------------------------------------------------- +/** Sets the last kart that hit the ball, to be able to +* identify the scorer later. +*/ +void SoccerWorld::setLastKartTohitBall(unsigned int kartId){ + m_lastKartToHitBall = kartId; +} //----------------------------------------------------------------------------- /** The battle is over if only one kart is left, or no player kart. */ diff --git a/src/modes/soccer_world.hpp b/src/modes/soccer_world.hpp index b2d43be13..9da17e7ce 100644 --- a/src/modes/soccer_world.hpp +++ b/src/modes/soccer_world.hpp @@ -51,7 +51,11 @@ private: SFXBase *m_goal_sound; /** Timer for displaying goal text*/ float m_goal_timer; - + int m_lastKartToHitBall; + std::vector m_redScorers; + std::vector m_redScoreTimes; + std::vector m_blueScorers; + std::vector m_blueScoreTimes; public: SoccerWorld(); @@ -79,6 +83,21 @@ public: void onCheckGoalTriggered(bool first_goal); int getTeamLeader(unsigned int i); + void setLastKartTohitBall(unsigned int kartId); + std::vector getScorers(unsigned int team) + { + if(team == 0) + return m_redScorers; + else if(team == 1) + return m_blueScorers; + } + std::vector getScoreTimes(unsigned int team) + { + if(team == 0) + return m_redScoreTimes; + else if(team == 1) + return m_blueScoreTimes; + } private: void initKartList(); diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index ca0a8f6dc..0d75b9a82 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -528,6 +528,11 @@ void PhysicalObject::handleExplosion(const Vec3& pos, bool direct_hit) } // handleExplosion +// ---------------------------------------------------------------------------- +bool PhysicalObject::isSoccerBall() +{ + return m_object->isSoccerBall(); +} // ---------------------------------------------------------------------------- /* EOF */ diff --git a/src/physics/physical_object.hpp b/src/physics/physical_object.hpp index f8a699000..6f2deb4a0 100644 --- a/src/physics/physical_object.hpp +++ b/src/physics/physical_object.hpp @@ -27,6 +27,7 @@ #include "utils/vec3.hpp" #include "utils/leak_check.hpp" + class XMLNode; class TrackObject; @@ -138,6 +139,7 @@ public: virtual void handleExplosion(const Vec3& pos, bool directHit); void update (float dt); void init (); + bool isSoccerBall(); // ------------------------------------------------------------------------ /** Returns the rigid body of this physical object. */ diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 3b48e3763..8ac559baf 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -32,6 +32,7 @@ #include "physics/stk_dynamics_world.hpp" #include "physics/triangle_mesh.hpp" #include "tracks/track.hpp" +#include "modes/soccer_world.hpp" // ---------------------------------------------------------------------------- /** Initialise physics. @@ -188,6 +189,12 @@ void Physics::update(float dt) const KartProperties* kp = kart->getKartProperties(); kart->setSquash(kp->getSquashDuration(), kp->getSquashSlowdown()); } + else if(obj->isSoccerBall()) + { + int kartId = p->getUserPointer(1)->getPointerKart()->getWorldKartId(); + SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); + soccerWorld->setLastKartTohitBall(kartId); + } continue; } diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 44487a6f7..3daaee555 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -298,14 +298,6 @@ void RaceResultGUI::onConfirm() */ void RaceResultGUI::determineTableLayout() { - if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) - { - redTeamTexture = irr_driver->getTexture( - file_manager->getTextureFile("soccer_ball_red.png")); - blueTeamTexture = irr_driver->getTexture( - file_manager->getTextureFile("soccer_ball_blue.png")); - } - GUIEngine::Widget *table_area = getWidget("result-table"); m_font = GUIEngine::getFont(); @@ -520,7 +512,9 @@ void RaceResultGUI::onUpdate(float dt, irr::video::IVideoDriver*) */ void RaceResultGUI::renderGlobal(float dt) { - m_timer += dt; + bool isSoccerWorld = race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER; + + m_timer += dt; assert(World::getWorld()->getPhase()==WorldStatus::RESULT_DISPLAY_PHASE); unsigned int num_karts = m_all_row_infos.size(); @@ -666,7 +660,10 @@ void RaceResultGUI::renderGlobal(float dt) case RR_WAIT_TILL_END: break; } // switch - displayOneEntry((unsigned int)x, (unsigned int)y, i, true); + if(isSoccerWorld) + displaySoccerResults(); + else + displayOneEntry((unsigned int)x, (unsigned int)y, i, true); } // for i // Display highscores @@ -744,12 +741,6 @@ void RaceResultGUI::determineGPLayout() void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y, unsigned int n, bool display_points) { - SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); - bool isSoccerMode = race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER; - int m_team_goals[2] = {soccerWorld->getScore(0), soccerWorld->getScore(1)}; - - if (isSoccerMode && n > 0) return; - RowInfo *ri = &(m_all_row_infos[n]); video::SColor color = ri->m_is_player_kart ? video::SColor(255,255,0, 0 ) @@ -770,73 +761,29 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y, // First draw the icon // ------------------- - if (!isSoccerMode) + if(ri->m_kart_icon) { - if(ri->m_kart_icon) - { - core::recti source_rect(core::vector2di(0,0), - ri->m_kart_icon->getSize()); - core::recti dest_rect(current_x, y, - current_x+m_width_icon, y+m_width_icon); - irr_driver->getVideoDriver()->draw2DImage(ri->m_kart_icon, dest_rect, - source_rect, NULL, NULL, - true); - } - - current_x += m_width_icon + m_width_column_space; + core::recti source_rect(core::vector2di(0,0), + ri->m_kart_icon->getSize()); + core::recti dest_rect(current_x, y, + current_x+m_width_icon, y+m_width_icon); + irr_driver->getVideoDriver()->draw2DImage(ri->m_kart_icon, dest_rect, + source_rect, NULL, NULL, + true); } + + current_x += m_width_icon + m_width_column_space; // Draw the name // ------------- - if (!isSoccerMode) - { - core::recti pos_name(current_x, y, - UserConfigParams::m_width, y+m_distance_between_rows); - m_font->draw(ri->m_kart_name, pos_name, color, false, false, NULL, - true /* ignoreRTL */); - current_x += m_width_kart_name + m_width_column_space; - } - // Draw icon, name of team which won in soccer mode and score - // ---------------------------------------------------------- - if (isSoccerMode) - { - core::stringw text; - irr::video::ITexture *team_icon; - if (m_team_goals[0] > m_team_goals[1]) - { - text = core::stringw(_("Red team won")); - team_icon = redTeamTexture; - } - else if (m_team_goals[0] < m_team_goals[1]) - { - text = core::stringw(_("Blue team won")); - team_icon = blueTeamTexture; - } - else - text = core::stringw(_("Draw")); + core::recti pos_name(current_x, y, + UserConfigParams::m_width, y+m_distance_between_rows); + m_font->draw(ri->m_kart_name, pos_name, color, false, false, NULL, + true /* ignoreRTL */); + current_x += m_width_kart_name + m_width_column_space; - core::recti source_rect(core::vector2di(0,0), team_icon->getSize()); - core::recti dest_rect(current_x, y, current_x+m_width_icon, y+m_width_icon); - irr_driver->getVideoDriver()->draw2DImage(team_icon, dest_rect, - source_rect, NULL, NULL, - true); - - current_x += m_width_icon + m_width_column_space; - core::recti pos_name(current_x, y, - UserConfigParams::m_width, y+m_distance_between_rows); - - m_font->draw(text, pos_name, color, false, false, NULL, true /* ignoreRTL */); - core::dimension2du rect = m_font->getDimension(text.c_str()); - current_x += rect.Width + 2*m_width_column_space; - - text = core::stringw(m_team_goals[0]) + " : " + core::stringw(m_team_goals[1]); - dest_rect = core::recti(current_x, y, current_x+100, y+10); - m_font->draw(text, dest_rect, color, false, false, NULL, true /* ignoreRTL */); - rect = m_font->getDimension(text.c_str()); - current_x += rect.Width + 2*m_width_column_space; - } - + // Draw the time except in FTL mode // -------------------------------- if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER) @@ -882,6 +829,124 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y, } } // displayOneEntry +//----------------------------------------------------------------------------- +void RaceResultGUI::displaySoccerResults() +{ + + //Draw win text + core::stringw resultText; + static video::SColor color; + gui::IGUIFont* font = GUIEngine::getTitleFont(); + float currX = UserConfigParams::m_width/2; + RowInfo *ri = &(m_all_row_infos[0]); + float currY = ri->m_y_pos; + SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); + int teamScore[2] = {soccerWorld->getScore(0), soccerWorld->getScore(1)}; + + if(teamScore[0] > teamScore[1]) + { + resultText = _("Red Team Wins"); + color = video::SColor(255, 255, 0, 0); + } + else if(teamScore[1] > teamScore[0]) + { + resultText = _("Blue Team Wins"); + color = video::SColor(255,0,0,255); + } + else + { + resultText = _("It's a draw"); + color = video::SColor(255, 255, 255, 255); + } + + core::rect pos(currX, currY, currX, currY); + font->draw(resultText.c_str(), pos, color, true, true); + + //Draw team scores: + currY += 20; + currX /= 2; + irr::video::ITexture* redTeamIcon = irr_driver->getTexture( + file_manager->getTextureFile("soccer_ball_red.png")); + irr::video::ITexture* blueTeamIcon = irr_driver->getTexture( + file_manager->getTextureFile("soccer_ball_blue.png")); + + core::recti sourceRect(core::vector2di(0,0), redTeamIcon->getSize()); + core::recti destRect(currX, currY, currX+redTeamIcon->getSize().Width/2, + currY+redTeamIcon->getSize().Height/2); + irr_driver->getVideoDriver()->draw2DImage(redTeamIcon, destRect,sourceRect, + NULL,NULL, true); + currX += UserConfigParams::m_width/2 - redTeamIcon->getSize().Width/2; + destRect = core::recti(currX, currY, currX+redTeamIcon->getSize().Width/2, + currY+redTeamIcon->getSize().Height/2); + irr_driver->getVideoDriver()->draw2DImage(blueTeamIcon,destRect,sourceRect, + NULL, NULL, true); + + currX += redTeamIcon->getSize().Width/4; + currY += 10 + redTeamIcon->getSize().Height/2; + resultText = StringUtils::toWString(teamScore[1]); + pos = core::rect(currX, currY, currX, currY); + color = video::SColor(255,255,255,255); + font->draw(resultText.c_str(), pos, color, true, false); + + currX -= UserConfigParams::m_width/2 - redTeamIcon->getSize().Width/2; + resultText = StringUtils::toWString(teamScore[0]); + pos = core::rect(currX,currY,currX,currY); + font->draw(resultText.c_str(), pos, color, true, false); + + resultText = "-"; + float centerX = UserConfigParams::m_width/2; + pos = core::rect(centerX, currY, centerX, currY); + font->draw(resultText.c_str(), pos, color, true, false); + + //Draw goal scorers: + //The red scorers: + currY += 50; + font = GUIEngine::getSmallFont(); + std::vector scorers = soccerWorld->getScorers(0); + std::vector scoreTimes = soccerWorld->getScoreTimes(0); + irr::video::ITexture* scorerIcon; + + for(int i=0; igetKartIdent(scorers.at(i)).c_str(); + resultText = kartName.c_str(); + resultText.append(" "); + resultText.append(StringUtils::timeToString(scoreTimes.at(i)).c_str()); + pos = core::rect(currX,currY,currX,currY); + font->draw(resultText,pos, color, true, false); + std::string path = "../karts/" + kartName + "/" + kartName + "icon.png"; + scorerIcon = irr_driver->getTexture(file_manager->getTextureFile(path)); + sourceRect = core::recti(core::vector2di(0,0), scorerIcon->getSize()); + destRect = core::recti(currX-95, currY-5, currX - 65, currY+ 25); + irr_driver->getVideoDriver()->draw2DImage(scorerIcon, destRect, sourceRect, + NULL, NULL, true); + currY += 30; + } + + //The blue scorers: + currY -= 30*scorers.size(); + currX += UserConfigParams::m_width/2 - redTeamIcon->getSize().Width/2; + scorers = soccerWorld->getScorers(1); + scoreTimes = soccerWorld->getScoreTimes(1); + for(int i=0; igetKartIdent(scorers.at(i)).c_str(); + resultText = kartName.c_str(); + resultText.append(" "); + resultText.append(StringUtils::timeToString(scoreTimes.at(i)).c_str()); + pos = core::rect(currX,currY,currX,currY); + font->draw(resultText,pos, color, true, false); + + std::string path = "../karts/" + kartName + "/" + kartName + "icon.png"; + scorerIcon = irr_driver->getTexture(file_manager->getTextureFile(path)); + sourceRect = core::recti(core::vector2di(0,0), scorerIcon->getSize()); + destRect = core::recti(currX-95, currY-5, currX - 65, currY+ 25); + irr_driver->getVideoDriver()->draw2DImage(scorerIcon, destRect, sourceRect, + NULL, NULL, true); + currY += 30; + } +} + //----------------------------------------------------------------------------- void RaceResultGUI::clearHighscores() diff --git a/src/states_screens/race_result_gui.hpp b/src/states_screens/race_result_gui.hpp index cc0cc7476..0a89d8f1a 100644 --- a/src/states_screens/race_result_gui.hpp +++ b/src/states_screens/race_result_gui.hpp @@ -198,6 +198,7 @@ private: void displayGPProgress(); void cleanupGPProgress(); void displayHighScores(); + void displaySoccerResults(); public: RaceResultGUI();