Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit b2b74d9

Browse files
committed
Fix item HUD only appearing for player 1
1 parent 21162ee commit b2b74d9

File tree

1 file changed

+74
-72
lines changed

1 file changed

+74
-72
lines changed

Entities/HeldDevice.cpp

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void HeldDevice::Clear()
5353
m_PickupableByPresetNames.clear();
5454
m_GripStrengthMultiplier = 1.0F;
5555
m_BlinkTimer.Reset();
56+
m_BlinkTimer.SetSimTimeLimitMS(1000);
5657
m_PieSlices.clear();
5758
m_Loudness = -1;
5859

@@ -482,6 +483,8 @@ void HeldDevice::Update()
482483
// m_aSprite->SetAngle(m_Rotation);
483484
// m_aSprite->SetScale(m_Scale);
484485
}
486+
487+
if (m_BlinkTimer.IsPastSimTimeLimit()) { m_BlinkTimer.Reset(); }
485488
}
486489

487490

@@ -530,84 +533,83 @@ void HeldDevice::Draw(BITMAP *pTargetBitmap,
530533
// Description: Draws this Actor's current graphical HUD overlay representation to a
531534
// BITMAP of choice.
532535

533-
void HeldDevice::DrawHUD(BITMAP *pTargetBitmap, const Vector &targetPos, int whichScreen, bool playerControlled)
534-
{
535-
if (!m_HUDVisible)
536-
return;
536+
void HeldDevice::DrawHUD(BITMAP *pTargetBitmap, const Vector &targetPos, int whichScreen, bool playerControlled) {
537+
if (!m_HUDVisible) {
538+
return;
539+
}
537540

538541
Attachable::DrawHUD(pTargetBitmap, targetPos, whichScreen);
539542

540-
if (!m_Parent && !IsUnPickupable())
541-
{
542-
// Only draw if the team viewing this has seen the space where this is located
543-
int viewingPlayer = g_ActivityMan.GetActivity()->PlayerOfScreen(whichScreen);
544-
int viewingTeam = g_ActivityMan.GetActivity()->GetTeamOfPlayer(viewingPlayer);
545-
if (viewingTeam != Activity::NoTeam)
546-
{
547-
if (g_SceneMan.IsUnseen(m_Pos.m_X, m_Pos.m_Y, viewingTeam))
548-
return;
549-
}
550-
551-
Vector drawPos = m_Pos - targetPos;
552-
// Adjust the draw position to work if drawn to a target screen bitmap that is straddling a scene seam
553-
if (!targetPos.IsZero())
554-
{
555-
// Spans vertical scene seam
556-
int sceneWidth = g_SceneMan.GetSceneWidth();
557-
if (g_SceneMan.SceneWrapsX() && pTargetBitmap->w < sceneWidth)
558-
{
559-
if ((targetPos.m_X < 0) && (m_Pos.m_X > (sceneWidth - pTargetBitmap->w)))
560-
drawPos.m_X -= sceneWidth;
561-
else if (((targetPos.m_X + pTargetBitmap->w) > sceneWidth) && (m_Pos.m_X < pTargetBitmap->w))
562-
drawPos.m_X += sceneWidth;
563-
}
564-
// Spans horizontal scene seam
565-
int sceneHeight = g_SceneMan.GetSceneHeight();
566-
if (g_SceneMan.SceneWrapsY() && pTargetBitmap->h < sceneHeight)
567-
{
568-
if ((targetPos.m_Y < 0) && (m_Pos.m_Y > (sceneHeight - pTargetBitmap->h)))
569-
drawPos.m_Y -= sceneHeight;
570-
else if (((targetPos.m_Y + pTargetBitmap->h) > sceneHeight) && (m_Pos.m_Y < pTargetBitmap->h))
571-
drawPos.m_Y += sceneHeight;
572-
}
573-
}
543+
if (!IsUnPickupable()) {
544+
if (m_Parent) {
545+
m_SeenByPlayer.fill(false);
546+
m_BlinkTimer.Reset();
547+
} else {
548+
// Only draw if the team viewing this has seen the space where this is located.
549+
int viewingPlayer = g_ActivityMan.GetActivity()->PlayerOfScreen(whichScreen);
550+
int viewingTeam = g_ActivityMan.GetActivity()->GetTeamOfPlayer(viewingPlayer);
551+
if (viewingTeam != Activity::NoTeam && g_SceneMan.IsUnseen(m_Pos.GetFloorIntX(), m_Pos.GetFloorIntY(), viewingTeam)) {
552+
return;
553+
}
574554

575-
char str[64];
576-
str[0] = 0;
577-
GUIFont *pSymbolFont = g_FrameMan.GetLargeFont();
578-
GUIFont *pTextFont = g_FrameMan.GetSmallFont();
579-
if (pSymbolFont && pTextFont) {
580-
if (m_BlinkTimer.GetElapsedSimTimeMS() < 250) {
581-
str[0] = 0;
582-
} else if (m_BlinkTimer.GetElapsedSimTimeMS() < 500) {
583-
str[0] = -42;
584-
str[1] = 0;
585-
} else if (m_BlinkTimer.GetElapsedSimTimeMS() < 750) {
586-
str[0] = -41;
587-
str[1] = 0;
588-
} else if (m_BlinkTimer.GetElapsedSimTimeMS() < 1000) {
589-
str[0] = -40;
590-
str[1] = 0;
591-
} else {
592-
m_BlinkTimer.Reset();
593-
// Check for nearby actors that will toggle this pickup HUD
594-
float range = g_SettingsMan.GetUnheldItemsHUDDisplayRange();
595-
if (g_ActivityMan.GetActivity()->GetActivityState() != Activity::ActivityState::Running) { range = -1.0F; }
596-
if (const GameActivity *gameActivity = dynamic_cast<const GameActivity *>(g_ActivityMan.GetActivity())) {
597-
if (gameActivity->GetViewState(viewingPlayer) == GameActivity::ViewState::ActorSelect) {
598-
range = -1.0F;
599-
}
600-
}
601-
m_SeenByPlayer.at(viewingPlayer) = range < 0 || (range > 0 && g_SceneMan.ShortestDistance(m_Pos, g_SceneMan.GetScrollTarget(whichScreen), g_SceneMan.SceneWrapsX()).GetMagnitude() < range);
555+
Vector drawPos = m_Pos - targetPos;
556+
// Adjust the draw position to work if drawn to a target screen bitmap that is straddling a scene seam.
557+
if (!targetPos.IsZero()) {
558+
int sceneWidth = g_SceneMan.GetSceneWidth();
559+
if (g_SceneMan.SceneWrapsX() && pTargetBitmap->w < sceneWidth) {
560+
if ((targetPos.GetFloorIntX() < 0) && (m_Pos.GetFloorIntX() > (sceneWidth - pTargetBitmap->w))) {
561+
drawPos.m_X -= static_cast<float>(sceneWidth);
562+
} else if ((targetPos.GetFloorIntX() + pTargetBitmap->w > sceneWidth) && (m_Pos.GetFloorIntX() < pTargetBitmap->w)) {
563+
drawPos.m_X += static_cast<float>(sceneWidth);
564+
}
565+
}
566+
int sceneHeight = g_SceneMan.GetSceneHeight();
567+
if (g_SceneMan.SceneWrapsY() && pTargetBitmap->h < sceneHeight) {
568+
if ((targetPos.GetFloorIntY() < 0) && (m_Pos.GetFloorIntY() > (sceneHeight - pTargetBitmap->h))) {
569+
drawPos.m_Y -= static_cast<float>(sceneHeight);
570+
} else if ((targetPos.GetFloorIntY() + pTargetBitmap->h > sceneHeight) && (m_Pos.GetFloorIntY() < pTargetBitmap->h)) {
571+
drawPos.m_Y += static_cast<float>(sceneHeight);
572+
}
573+
}
602574
}
603-
if (m_SeenByPlayer.at(viewingPlayer)) {
604-
AllegroBitmap pBitmapInt(pTargetBitmap);
605-
pSymbolFont->DrawAligned(&pBitmapInt, drawPos.GetFloorIntX() - 1, drawPos.GetFloorIntY() - 20, str, GUIFont::Centre);
606-
std::snprintf(str, sizeof(str), "%s", m_PresetName.c_str());
607-
pTextFont->DrawAligned(&pBitmapInt, drawPos.GetFloorIntX(), drawPos.GetFloorIntY() - 29, str, GUIFont::Centre);
575+
576+
char str[64];
577+
str[0] = 0;
578+
GUIFont *pSymbolFont = g_FrameMan.GetLargeFont();
579+
GUIFont *pTextFont = g_FrameMan.GetSmallFont();
580+
if (pSymbolFont && pTextFont) {
581+
if (m_BlinkTimer.GetElapsedSimTimeMS() > 750) {
582+
str[0] = -40;
583+
str[1] = 0;
584+
} else if (m_BlinkTimer.GetElapsedSimTimeMS() > 500) {
585+
str[0] = -41;
586+
str[1] = 0;
587+
} else if (m_BlinkTimer.GetElapsedSimTimeMS() > 250) {
588+
str[0] = -42;
589+
str[1] = 0;
590+
} else if (m_BlinkTimer.GetElapsedSimTimeMS() > 0) {
591+
str[0] = 0;
592+
} else {
593+
// Check for nearby cursors that will toggle this pickup HUD.
594+
float range = g_SettingsMan.GetUnheldItemsHUDDisplayRange();
595+
if (g_ActivityMan.GetActivity()->GetActivityState() != Activity::ActivityState::Running) {
596+
range = -1.0F;
597+
} else if (const GameActivity *gameActivity = dynamic_cast<const GameActivity *>(g_ActivityMan.GetActivity())) {
598+
if (gameActivity->GetViewState(viewingPlayer) == GameActivity::ViewState::ActorSelect) {
599+
range = -1.0F;
600+
}
601+
}
602+
m_SeenByPlayer.at(viewingPlayer) = range < 0 || (range > 0 && g_SceneMan.ShortestDistance(m_Pos, g_SceneMan.GetScrollTarget(whichScreen), g_SceneMan.SceneWrapsX()).GetMagnitude() < range);
603+
}
604+
if (m_SeenByPlayer.at(viewingPlayer)) {
605+
AllegroBitmap pBitmapInt(pTargetBitmap);
606+
pSymbolFont->DrawAligned(&pBitmapInt, drawPos.GetFloorIntX() - 1, drawPos.GetFloorIntY() - 20, str, GUIFont::Centre);
607+
std::snprintf(str, sizeof(str), "%s", m_PresetName.c_str());
608+
pTextFont->DrawAligned(&pBitmapInt, drawPos.GetFloorIntX(), drawPos.GetFloorIntY() - 29, str, GUIFont::Centre);
609+
}
608610
}
609-
}
610-
}
611+
}
612+
}
611613
}
612614

613615
} // namespace RTE

0 commit comments

Comments
 (0)