/** Shows the current soccer result. */ void RaceGUI::drawScores() { SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); int offsetY = 5; int offsetX = 5; gui::ScalableFont* font = GUIEngine::getFont(); static video::SColor color = video::SColor(255,255,255,255); //Draw kart icons above score(denoting teams) irr::video::ITexture *red_team = irr_driver->getTexture(FileManager::GUI, "soccer_ball_red.png"); irr::video::ITexture *blue_team = irr_driver->getTexture(FileManager::GUI, "soccer_ball_blue.png"); irr::video::ITexture *team_icon; int numLeader = 1; for(unsigned int i=0; i<soccerWorld->getNumKarts(); i++) { int j = soccerWorld->getTeamLeader(i); if(j < 0) break; AbstractKart* kart = soccerWorld->getKart(i); video::ITexture* icon = kart->getKartProperties()->getMinimapIcon(); core::rect<s32> source(core::position2di(0, 0), icon->getSize()); core::recti position(offsetX, offsetY, offsetX + 2*m_minimap_player_size, offsetY + 2*m_minimap_player_size); draw2DImage(icon, position, source, NULL, NULL, true); core::stringw score = StringUtils::toWString(soccerWorld->getScore(i)); int string_height = GUIEngine::getFont()->getDimension(score.c_str()).Height; core::recti pos(position.UpperLeftCorner.X + 5, position.LowerRightCorner.Y + offsetY, position.LowerRightCorner.X, position.LowerRightCorner.Y + string_height); font->draw(score.c_str(),pos,color); switch(numLeader) { case 1: team_icon = red_team; break; case 2: team_icon = blue_team; break; default: break; } core::rect<s32> indicatorPos(offsetX, offsetY, offsetX + (int)(m_minimap_player_size/1.25f), offsetY + (int)(m_minimap_player_size/1.25f)); core::rect<s32> sourceRect(core::position2d<s32>(0,0), team_icon->getOriginalSize()); draw2DImage(team_icon,indicatorPos,sourceRect, NULL,NULL,true); numLeader++; offsetX += position.LowerRightCorner.X; } } // drawScores
//----------------------------------------------------------------------------- void RaceResultGUI::displaySoccerResults() { //Draw win text core::stringw resultText; static video::SColor color = video::SColor(255, 255, 255, 255); gui::IGUIFont* font = GUIEngine::getTitleFont(); int currX = UserConfigParams::m_width/2; RowInfo *ri = &(m_all_row_infos[0]); int currY = (int)ri->m_y_pos; SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); int teamScore[2] = {soccerWorld->getScore(0), soccerWorld->getScore(1)}; GUIEngine::Widget *table_area = getWidget("result-table"); int height = table_area->m_h + table_area->m_y; if(teamScore[0] > teamScore[1]) { resultText = _("Red Team Wins"); } else if(teamScore[1] > teamScore[0]) { resultText = _("Blue Team Wins"); } else { //Cannot really happen now. Only in time limited matches. resultText = _("It's a draw"); } core::rect<s32> pos(currX, currY, currX, currY); font->draw(resultText.c_str(), pos, color, true, true); core::dimension2du rect = m_font->getDimension(resultText.c_str()); //Draw team scores: currY += rect.Height; currX /= 2; irr::video::ITexture* redTeamIcon = irr_driver->getTexture(FileManager::GUI, "soccer_ball_red.png"); irr::video::ITexture* blueTeamIcon = irr_driver->getTexture(FileManager::GUI, "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); 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); draw2DImage(blueTeamIcon,destRect,sourceRect, NULL, NULL, true); resultText = StringUtils::toWString(teamScore[1]); rect = m_font->getDimension(resultText.c_str()); currX += redTeamIcon->getSize().Width/4; currY += redTeamIcon->getSize().Height/2 + rect.Height/4; pos = core::rect<s32>(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<s32>(currX,currY,currX,currY); font->draw(resultText.c_str(), pos, color, true, false); int centerX = UserConfigParams::m_width/2; pos = core::rect<s32>(centerX, currY, centerX, currY); font->draw("-", pos, color, true, false); //Draw goal scorers: //The red scorers: currY += rect.Height/2 + rect.Height/4; font = GUIEngine::getSmallFont(); std::vector<int> scorers = soccerWorld->getScorers(0); std::vector<float> scoreTimes = soccerWorld->getScoreTimes(0); irr::video::ITexture* scorerIcon; int prevY = currY; for(unsigned int i=0; i<scorers.size(); i++) { resultText = soccerWorld->getKart(scorers.at(i))-> getKartProperties()->getName(); resultText.append(" "); resultText.append(StringUtils::timeToString(scoreTimes.at(i)).c_str()); rect = m_font->getDimension(resultText.c_str()); if(height-prevY < ((short)scorers.size()+1)*(short)rect.Height) currY += (height-prevY)/((short)scorers.size()+1); else currY += rect.Height; if(currY > height) break; pos = core::rect<s32>(currX,currY,currX,currY); font->draw(resultText,pos, color, true, false); scorerIcon = soccerWorld->getKart(scorers.at(i)) ->getKartProperties()->getIconMaterial()->getTexture(); sourceRect = core::recti(core::vector2di(0,0), scorerIcon->getSize()); irr::u32 offsetX = GUIEngine::getFont()->getDimension(resultText.c_str()).Width/2; destRect = core::recti(currX-offsetX-30, currY, currX-offsetX, currY+ 30); draw2DImage(scorerIcon, destRect, sourceRect, NULL, NULL, true); } //The blue scorers: currY = prevY; currX += UserConfigParams::m_width/2 - redTeamIcon->getSize().Width/2; scorers = soccerWorld->getScorers(1); scoreTimes = soccerWorld->getScoreTimes(1); for(unsigned int i=0; i<scorers.size(); i++) { resultText = soccerWorld->getKart(scorers.at(i))-> getKartProperties()->getName(); resultText.append(" "); resultText.append(StringUtils::timeToString(scoreTimes.at(i)).c_str()); rect = m_font->getDimension(resultText.c_str()); if(height-prevY < ((short)scorers.size()+1)*(short)rect.Height) currY += (height-prevY)/((short)scorers.size()+1); else currY += rect.Height; if(currY > height) break; pos = core::rect<s32>(currX,currY,currX,currY); font->draw(resultText,pos, color, true, false); scorerIcon = soccerWorld->getKart(scorers.at(i))-> getKartProperties()->getIconMaterial()->getTexture(); sourceRect = core::recti(core::vector2di(0,0), scorerIcon->getSize()); irr::u32 offsetX = GUIEngine::getFont()->getDimension(resultText.c_str()).Width/2; destRect = core::recti(currX-offsetX-30, currY, currX-offsetX, currY+ 30); draw2DImage(scorerIcon, destRect, sourceRect, NULL, NULL, true); } }