/** Draws the rank of a player. * \param kart The kart of the player. * \param offset Offset of top left corner for this display (for splitscreen). * \param min_ratio Scaling of the screen (for splitscreen). * \param meter_width Width of the meter (inside which the rank is shown). * \param meter_height Height of the meter (inside which the rank is shown). * \param dt Time step size. */ void RaceGUI::drawRank(const AbstractKart *kart, const core::vector2df &offset, float min_ratio, int meter_width, int meter_height, float dt) { // Draw rank WorldWithRank *world = dynamic_cast<WorldWithRank*>(World::getWorld()); if (!world || !world->displayRank()) return; int id = kart->getWorldKartId(); if (m_animation_states[id] == AS_NONE) { if (m_last_ranks[id] != kart->getPosition()) { m_rank_animation_duration[id] = 0.0f; m_animation_states[id] = AS_SMALLER; } } else { m_rank_animation_duration[id] += dt; } float scale = 1.0f; int rank = kart->getPosition(); const float DURATION = 0.4f; const float MIN_SHRINK = 0.3f; if (m_animation_states[id] == AS_SMALLER) { scale = 1.0f - m_rank_animation_duration[id]/ DURATION; rank = m_last_ranks[id]; if (scale < MIN_SHRINK) { m_animation_states[id] = AS_BIGGER; m_rank_animation_duration[id] = 0.0f; // Store the new rank m_last_ranks[id] = kart->getPosition(); scale = MIN_SHRINK; } } else if (m_animation_states[id] == AS_BIGGER) { scale = m_rank_animation_duration[id] / DURATION + MIN_SHRINK; rank = m_last_ranks[id]; if (scale > 1.0f) { m_animation_states[id] = AS_NONE; scale = 1.0f; } } else { m_last_ranks[id] = kart->getPosition(); } gui::ScalableFont* font = GUIEngine::getHighresDigitFont(); font->setScale(min_ratio * scale); font->setShadow(video::SColor(255, 128, 0, 0)); std::ostringstream oss; oss << rank; // the current font has no . :( << "."; core::recti pos; pos.LowerRightCorner = core::vector2di(int(offset.X + 0.65f*meter_width), int(offset.Y - 0.55f*meter_height)); pos.UpperLeftCorner = core::vector2di(int(offset.X + 0.65f*meter_width), int(offset.Y - 0.55f*meter_height)); static video::SColor color = video::SColor(255, 255, 255, 255); font->draw(oss.str().c_str(), pos, color, true, true); font->setScale(1.0f); } // drawRank
/** Displays the rank and the lap of the kart. * \param info Info object c */ void RaceGUI::drawRankLap(const KartIconDisplayInfo* info, const AbstractKart* kart, const core::recti &viewport) { // Don't display laps or ranks if the kart has already finished the race. if (kart->hasFinishedRace()) return; core::recti pos; pos.UpperLeftCorner.Y = viewport.UpperLeftCorner.Y; // If the time display in the top right is in this viewport, // move the lap/rank display down a little bit so that it is // displayed under the time. if(viewport.UpperLeftCorner.Y==0 && viewport.LowerRightCorner.X==UserConfigParams::m_width && race_manager->getNumPlayers()!=3) pos.UpperLeftCorner.Y += 40; pos.LowerRightCorner.Y = viewport.LowerRightCorner.Y; pos.UpperLeftCorner.X = viewport.LowerRightCorner.X - m_rank_lap_width - 10; pos.LowerRightCorner.X = viewport.LowerRightCorner.X; gui::ScalableFont* font = (race_manager->getNumLocalPlayers() > 2 ? GUIEngine::getSmallFont() : GUIEngine::getFont()); int font_height = (int)(font->getDimension(L"X").Height); static video::SColor color = video::SColor(255, 255, 255, 255); WorldWithRank *world = (WorldWithRank*)(World::getWorld()); if (world->displayRank()) { const int rank = kart->getPosition(); font->draw(m_string_rank.c_str(), pos, color); pos.UpperLeftCorner.Y += font_height; pos.LowerRightCorner.Y += font_height; char str[256]; const unsigned int kart_amount = world->getCurrentNumKarts(); sprintf(str, "%d/%d", rank, kart_amount); font->draw(core::stringw(str).c_str(), pos, color); pos.UpperLeftCorner.Y += font_height; pos.LowerRightCorner.Y += font_height; } // Don't display laps in follow the leader mode if(world->raceHasLaps()) { const int lap = info[kart->getWorldKartId()].lap; // don't display 'lap 0/...' if(lap>=0) { font->draw(m_string_lap.c_str(), pos, color); char str[256]; sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps()); pos.UpperLeftCorner.Y += font_height; pos.LowerRightCorner.Y += font_height; font->draw(core::stringw(str).c_str(), pos, color); pos.UpperLeftCorner.Y += font_height; pos.LowerRightCorner.Y += font_height; } } } // drawRankLap
/** Displays the rank and the lap of the kart. * \param info Info object c */ void MinimalRaceGUI::drawRankLap(const KartIconDisplayInfo* info, const AbstractKart* kart, const core::recti &viewport) { // Don't display laps or ranks if the kart has already finished the race. if (kart->hasFinishedRace()) return; core::recti pos; gui::ScalableFont* font = (race_manager->getNumLocalPlayers() > 2 ? GUIEngine::getSmallFont() : GUIEngine::getFont()); float scale = font->getScale(); font->setScale(m_font_scale); // Add a black shadow to make the text better readable on // 'white' tracks (e.g. with snow and ice). font->setShadow(video::SColor(255, 0, 0, 0)); static video::SColor color = video::SColor(255, 255, 255, 255); WorldWithRank *world = (WorldWithRank*)(World::getWorld()); if (world->displayRank()) { pos.UpperLeftCorner.Y = viewport.UpperLeftCorner.Y; pos.LowerRightCorner.Y = viewport.UpperLeftCorner.Y+50; // Split screen 3 or 4 players, left side: if(viewport.LowerRightCorner.X < UserConfigParams::m_width) { pos.UpperLeftCorner.X = 10; pos.LowerRightCorner.X = viewport.LowerRightCorner.X; } else { pos.UpperLeftCorner.X = viewport.LowerRightCorner.X - m_rank_width-10; pos.LowerRightCorner.X = viewport.LowerRightCorner.X; } char str[256]; sprintf(str, "%d/%d", kart->getPosition(), world->getCurrentNumKarts()); font->draw(str, pos, color); } // Don't display laps in follow the leader mode if(world->raceHasLaps()) { const int lap = info[kart->getWorldKartId()].lap; // don't display 'lap 0/...' if(lap>=0) { pos.LowerRightCorner.Y = viewport.LowerRightCorner.Y; pos.UpperLeftCorner.Y = viewport.LowerRightCorner.Y-60; pos.LowerRightCorner.X = viewport.LowerRightCorner.X; // Split screen 3 or 4 players, left side: if(viewport.LowerRightCorner.X < UserConfigParams::m_width) { pos.UpperLeftCorner.X = 10; } else { pos.UpperLeftCorner.X = (int)(viewport.LowerRightCorner.X - m_lap_width -10 ); } char str[256]; sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps()); core::stringw s = m_string_lap+" "+str; font->draw(s.c_str(), pos, color); } } font->setScale(scale); font->disableShadow(); } // drawRankLap