Hightlight current spectating kart in race gui

This commit is contained in:
Benau 2019-02-02 16:06:41 +08:00
parent 0cb12ea124
commit 52cddf6208
3 changed files with 40 additions and 21 deletions

View File

@ -49,6 +49,7 @@ using namespace irr;
#include "modes/linear_world.hpp" #include "modes/linear_world.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "modes/soccer_world.hpp" #include "modes/soccer_world.hpp"
#include "network/protocols/client_lobby.hpp"
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
#include "states_screens/race_gui_multitouch.hpp" #include "states_screens/race_gui_multitouch.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
@ -569,19 +570,25 @@ void RaceGUI::drawGlobalMiniMap()
lower_y -(int)(draw_at.getY()-(m_minimap_player_size/2.2f))); lower_y -(int)(draw_at.getY()-(m_minimap_player_size/2.2f)));
draw2DImage(m_blue_flag, bp, bs, NULL, NULL, true); draw2DImage(m_blue_flag, bp, bs, NULL, NULL, true);
} }
AbstractKart* target_kart = NULL;
Camera* cam = Camera::getActiveCamera();
auto cl = LobbyProtocol::get<ClientLobby>();
bool is_nw_spectate = cl && cl->isSpectator();
// For network spectator highlight
if (race_manager->getNumLocalPlayers() == 1 && cam && is_nw_spectate)
target_kart = cam->getKart();
// Move AI/remote players to the beginning, so that local players icons // Move AI/remote players to the beginning, so that local players icons
// are drawn above them // are drawn above them
World::KartList karts = world->getKarts(); World::KartList karts = world->getKarts();
std::sort(karts.begin(), karts.end(), [] std::partition(karts.begin(), karts.end(), [target_kart, is_nw_spectate]
(const std::shared_ptr<AbstractKart>& a, (const std::shared_ptr<AbstractKart>& k)->bool
const std::shared_ptr<AbstractKart>& b)->bool
{ {
bool aIsLocalPlayer = a->getController()->isLocalPlayerController(); if (is_nw_spectate)
bool bIsLocalPlayer = b->getController()->isLocalPlayerController(); return k.get() != target_kart;
else
// strictly greater than, so return false if equal return !k->getController()->isLocalPlayerController();
return !aIsLocalPlayer && aIsLocalPlayer != bIsLocalPlayer;
}); });
for (unsigned int i = 0; i < karts.size(); i++) for (unsigned int i = 0; i < karts.size(); i++)
@ -589,7 +596,7 @@ void RaceGUI::drawGlobalMiniMap()
const AbstractKart *kart = karts[i].get(); const AbstractKart *kart = karts[i].get();
const SpareTireAI* sta = const SpareTireAI* sta =
dynamic_cast<const SpareTireAI*>(kart->getController()); dynamic_cast<const SpareTireAI*>(kart->getController());
// don't draw eliminated kart // don't draw eliminated kart
if (kart->isEliminated() && !(sta && sta->isMoving())) if (kart->isEliminated() && !(sta && sta->isMoving()))
continue; continue;
@ -605,9 +612,11 @@ void RaceGUI::drawGlobalMiniMap()
{ {
continue; continue;
} }
bool is_local = is_nw_spectate ? kart == target_kart :
kart->getController()->isLocalPlayerController();
// int marker_height = m_marker->getSize().Height; // int marker_height = m_marker->getSize().Height;
core::rect<s32> source(core::position2di(0, 0), icon->getSize()); core::rect<s32> source(core::position2di(0, 0), icon->getSize());
int marker_half_size = (kart->getController()->isLocalPlayerController() int marker_half_size = (is_local
? m_minimap_player_size ? m_minimap_player_size
: m_minimap_ai_size )>>1; : m_minimap_ai_size )>>1;
core::rect<s32> position(m_map_left+(int)(draw_at.getX()-marker_half_size), core::rect<s32> position(m_map_left+(int)(draw_at.getX()-marker_half_size),
@ -618,8 +627,7 @@ void RaceGUI::drawGlobalMiniMap()
bool has_teams = (ctf_world || soccer_world); bool has_teams = (ctf_world || soccer_world);
// Highlight the player icons with some backgorund image. // Highlight the player icons with some backgorund image.
if ((has_teams || kart->getController()->isLocalPlayerController()) && if ((has_teams || is_local) && m_icons_frame != NULL)
m_icons_frame != NULL)
{ {
video::SColor color = kart->getKartProperties()->getColor(); video::SColor color = kart->getKartProperties()->getColor();

View File

@ -43,6 +43,7 @@
#include "modes/capture_the_flag.hpp" #include "modes/capture_the_flag.hpp"
#include "modes/linear_world.hpp" #include "modes/linear_world.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/network_config.hpp" #include "network/network_config.hpp"
#include "states_screens/race_gui_multitouch.hpp" #include "states_screens/race_gui_multitouch.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
@ -894,10 +895,19 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
font->setBlackBorder(false); font->setBlackBorder(false);
} }
int w = kart->getController()
->isLocalPlayerController() ? ICON_PLAYER_WIDTH AbstractKart* target_kart = NULL;
: ICON_WIDTH; Camera* cam = Camera::getActiveCamera();
drawPlayerIcon(kart, x, y, w); auto cl = LobbyProtocol::get<ClientLobby>();
bool is_nw_spectate = cl && cl->isSpectator();
// For network spectator highlight
if (race_manager->getNumLocalPlayers() == 1 && cam && is_nw_spectate)
target_kart = cam->getKart();
bool is_local = is_nw_spectate ? kart == target_kart :
kart->getController()->isLocalPlayerController();
int w = is_local ? ICON_PLAYER_WIDTH : ICON_WIDTH;
drawPlayerIcon(kart, x, y, w, is_local);
} //next position } //next position
#endif #endif
} // drawGlobalPlayerIcons } // drawGlobalPlayerIcons
@ -906,7 +916,8 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
/** Draw one player icon /** Draw one player icon
* Takes care of icon looking different due to plumber, squashing, ... * Takes care of icon looking different due to plumber, squashing, ...
*/ */
void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w) void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w,
bool is_local)
{ {
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
video::ITexture *icon = video::ITexture *icon =
@ -943,8 +954,7 @@ void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w)
const core::rect<s32> pos(x, y, x+w, y+w); const core::rect<s32> pos(x, y, x+w, y+w);
//to bring to light the player's icon: add a background //to bring to light the player's icon: add a background
if (kart->getController()->isLocalPlayerController() && if (is_local && m_icons_frame != NULL)
m_icons_frame != NULL)
{ {
video::SColor colors[4]; video::SColor colors[4];
for (unsigned int i=0;i<4;i++) for (unsigned int i=0;i<4;i++)

View File

@ -249,7 +249,8 @@ public:
virtual void clearAllMessages() { m_messages.clear(); } virtual void clearAllMessages() { m_messages.clear(); }
void drawGlobalPlayerIcons(int bottom_margin); void drawGlobalPlayerIcons(int bottom_margin);
void drawPlayerIcon(AbstractKart *kart, int x, int y, int w); void drawPlayerIcon(AbstractKart *kart, int x, int y, int w,
bool is_local);
virtual void drawEnergyMeter(int x, int y, const AbstractKart *kart, virtual void drawEnergyMeter(int x, int y, const AbstractKart *kart,
const core::recti &viewport, const core::recti &viewport,