diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index f2fa10554..4ae7a596f 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -1021,6 +1021,11 @@ void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w, bool is_local) { #ifndef SERVER_ONLY + // this flag is set to true if we show at least one custom color for other karts + // in that case we want to draw a bigger circle around the player's own kart + // to make it easier for the player to identify + static bool showing_kart_colors = false; + video::ITexture *icon = kart->getKartProperties()->getIconMaterial()->getTexture(); @@ -1054,19 +1059,61 @@ void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w, const core::rect pos(x, y, x+w, y+w); + // Get color of kart + // Since kart->getKartProperties()->getColor() only gets the + // standard color of a kart of same type, we have to check if the user + // (or network manager) changed it. In that case we have to use + // hue value instead. + video::SColor kart_color = kart->getKartProperties()->getColor(); + const float kart_hue = RaceManager::get()->getKartColor(kart->getWorldKartId()); + if (kart_hue > 0.0) + { + // convert Hue to SColor + const video::SColorHSL kart_colorHSL(kart_hue * 360.0, 80.0, 50.0); + video::SColorf kart_colorf; + kart_colorHSL.toRGB(kart_colorf); + kart_color = kart_colorf.toSColor(); + } + //to bring to light the player's icon: add a background + const RaceManager::MinorRaceModeType minor_mode = RaceManager::get()->getMinorMode(); if (is_local && m_icons_kart_list != NULL) { video::SColor colors[4]; for (unsigned int i=0;i<4;i++) { - colors[i]=kart->getKartProperties()->getColor(); + colors[i]=kart_color; colors[i].setAlpha( - 100+(int)(100*cosf(M_PI/2*i+World::getWorld()->getTime()*2))); + 120+(int)(120*cosf(M_PI/2*i+World::getWorld()->getTime()*2))); + } + core::rect icon_pos; + if (showing_kart_colors) + { + // we are showing other kart's colors, so draw bigger circle + icon_pos = core::rect(x-9, y-7, x+w+7, y+w+2); + } + else + { + icon_pos = pos; } const core::rect rect(core::position2d(0,0), m_icons_kart_list->getSize()); - draw2DImage(m_icons_kart_list, pos, rect,NULL, colors, true); + draw2DImage(m_icons_kart_list, icon_pos, rect,NULL, colors, true); + } + else if (kart_hue > 0.0 && (minor_mode == RaceManager::MINOR_MODE_NORMAL_RACE + || minor_mode == RaceManager::MINOR_MODE_TIME_TRIAL)) + { + // in normal mode or time trial draw kart color circles for karts with custom color + // draw a little bigger in case an addon kart uses the full icon size + const core::rect color_pos(x-7, y+2, x+w, y+w+2); + video::SColor colors[4] = {kart_color, kart_color, kart_color, kart_color}; + colors[0].setAlpha(240); // higher alpha for left part + colors[1].setAlpha(240); + colors[2].setAlpha(125); // lower alpha for right part + colors[3].setAlpha(125); + const core::rect rect(core::position2d(0,0), m_icons_frame->getSize()); + draw2DImage(m_icons_frame, color_pos, rect, NULL, colors, true); + showing_kart_colors = true; } // Fixes crash bug, why are certain icons not showing up? diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index e4d6cdc25..621c666fd 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -821,6 +821,7 @@ void RaceResultGUI::displayCTFResults() video::ITexture *icon = kart->getKartProperties()->getIconMaterial()->getTexture(); ri->m_kart_icon = icon; + ri->m_kart_color = RaceManager::get()->getKartColor(kart->getWorldKartId()); // FTL karts will get a time assigned, they are not shown as eliminated if (kart->isEliminated() && !(RaceManager::get()->isFollowMode())) @@ -1249,6 +1250,7 @@ void RaceResultGUI::displayCTFResults() ri->m_kart_name += flag; } } + ri->m_kart_color = RaceManager::get()->getKartColor(kart_id); // In FTL karts do have a time, which is shown even when the kart // is eliminated if (kart->isEliminated() && !(RaceManager::get()->isFollowMode())) @@ -1313,6 +1315,21 @@ void RaceResultGUI::displayCTFResults() unsigned int current_x = x; + // Draw kart color circle if kart has custom color + if (ri->m_kart_color > 0.0) + { + const video::SColorHSL kart_colorHSL(ri->m_kart_color * 360.0, 80.0, 50.0); + video::SColorf kart_colorf; + kart_colorHSL.toRGB(kart_colorf); + const video::SColor kart_color = kart_colorf.toSColor(); + const video::SColor colors[4] = {kart_color, kart_color, kart_color, kart_color}; + const core::recti source_rect(core::vector2di(0, 0), m_icons_frame->getSize()); + // make frame bigger than icon to make color visible for all cases + const int extra_width = std::max((unsigned int)5, m_width_icon / 8); + core::recti dest_rect(current_x - extra_width, y - extra_width, + current_x + m_width_icon + extra_width, y + m_width_icon + extra_width); + draw2DImage(m_icons_frame, dest_rect, source_rect, NULL, colors, true); + } // First draw the icon // ------------------- if (ri->m_kart_icon) diff --git a/src/states_screens/race_result_gui.hpp b/src/states_screens/race_result_gui.hpp index c2e65bd8c..ca62abb83 100644 --- a/src/states_screens/race_result_gui.hpp +++ b/src/states_screens/race_result_gui.hpp @@ -101,6 +101,8 @@ private: video::ITexture *m_kart_icon; /** The times of all karts in the right order. */ core::stringw m_finish_time_string; + /** The kart color */ + float m_kart_color; }; // Rowinfo /** The team icons. */