2023-02-10 12:01:31 +00:00
|
|
|
|
using QSB.Player;
|
2023-03-03 15:51:18 +00:00
|
|
|
|
using QSB.Player.Messages;
|
2023-02-10 12:01:31 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace QSB.HUD;
|
|
|
|
|
|
2023-03-04 19:09:50 +00:00
|
|
|
|
[UsedInUnityProject]
|
2023-02-10 12:01:31 +00:00
|
|
|
|
public class PlayerBox : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Text PlayerName;
|
|
|
|
|
public Image InfoImage;
|
|
|
|
|
|
|
|
|
|
private PlayerInfo _player;
|
|
|
|
|
private bool _planetIconOverride;
|
2023-03-03 17:16:02 +00:00
|
|
|
|
private bool _inUnknown;
|
2023-02-12 18:41:40 +00:00
|
|
|
|
|
|
|
|
|
public HUDIcon PlanetIcon { get; private set; }
|
2023-02-10 12:01:31 +00:00
|
|
|
|
|
|
|
|
|
public void AssignPlayer(PlayerInfo player)
|
|
|
|
|
{
|
|
|
|
|
_player = player;
|
|
|
|
|
_player.HUDBox = this;
|
|
|
|
|
|
|
|
|
|
if (player.Name != null)
|
|
|
|
|
{
|
2023-05-11 22:59:45 +00:00
|
|
|
|
Delay.RunWhen(
|
|
|
|
|
() => player.Name != null,
|
|
|
|
|
() => PlayerName.text = player.Name.ToUpper());
|
2023-02-10 12:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InfoImage.sprite = MultiplayerHUDManager.UnknownSprite;
|
2023-03-03 15:51:18 +00:00
|
|
|
|
|
|
|
|
|
new RequestStateResyncMessage().Send();
|
2023-02-10 12:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDeath()
|
|
|
|
|
{
|
|
|
|
|
InfoImage.sprite = MultiplayerHUDManager.DeadSprite;
|
|
|
|
|
_planetIconOverride = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnRespawn()
|
|
|
|
|
{
|
|
|
|
|
InfoImage.sprite = MultiplayerHUDManager.ShipSprite;
|
|
|
|
|
_planetIconOverride = true; // still in ship
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEnterShip()
|
|
|
|
|
{
|
2023-03-03 17:16:02 +00:00
|
|
|
|
if (_inUnknown)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 12:01:31 +00:00
|
|
|
|
InfoImage.sprite = MultiplayerHUDManager.ShipSprite;
|
|
|
|
|
_planetIconOverride = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnExitShip()
|
|
|
|
|
{
|
2023-03-03 17:16:02 +00:00
|
|
|
|
if (_inUnknown)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_planetIconOverride = false;
|
|
|
|
|
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEnterUnknown()
|
|
|
|
|
{
|
|
|
|
|
_inUnknown = true;
|
|
|
|
|
_planetIconOverride = true;
|
|
|
|
|
InfoImage.sprite = MultiplayerHUDManager.UnknownSprite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnExitUnknown()
|
|
|
|
|
{
|
|
|
|
|
_inUnknown = false;
|
2023-02-10 12:01:31 +00:00
|
|
|
|
_planetIconOverride = false;
|
2023-02-12 18:41:40 +00:00
|
|
|
|
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
2023-02-10 12:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateIcon(HUDIcon icon)
|
|
|
|
|
{
|
2023-02-12 18:41:40 +00:00
|
|
|
|
PlanetIcon = icon;
|
2023-02-10 12:01:31 +00:00
|
|
|
|
|
|
|
|
|
if (!_planetIconOverride)
|
|
|
|
|
{
|
2023-02-12 18:41:40 +00:00
|
|
|
|
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
2023-02-10 12:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Sprite SpriteFromEnum(HUDIcon icon) => icon switch
|
|
|
|
|
{
|
|
|
|
|
HUDIcon.SHIP => MultiplayerHUDManager.ShipSprite,
|
|
|
|
|
HUDIcon.DEAD => MultiplayerHUDManager.DeadSprite,
|
|
|
|
|
HUDIcon.SPACE => MultiplayerHUDManager.SpaceSprite,
|
|
|
|
|
HUDIcon.CAVE_TWIN => MultiplayerHUDManager.CaveTwin,
|
|
|
|
|
HUDIcon.TOWER_TWIN => MultiplayerHUDManager.TowerTwin,
|
|
|
|
|
HUDIcon.TIMBER_HEARTH => MultiplayerHUDManager.TimberHearth,
|
|
|
|
|
HUDIcon.ATTLEROCK => MultiplayerHUDManager.Attlerock,
|
|
|
|
|
HUDIcon.BRITTLE_HOLLOW => MultiplayerHUDManager.BrittleHollow,
|
|
|
|
|
HUDIcon.HOLLOWS_LANTERN => MultiplayerHUDManager.HollowsLantern,
|
|
|
|
|
HUDIcon.GIANTS_DEEP => MultiplayerHUDManager.GiantsDeep,
|
|
|
|
|
HUDIcon.DARK_BRAMBLE => MultiplayerHUDManager.DarkBramble,
|
|
|
|
|
HUDIcon.INTERLOPER => MultiplayerHUDManager.Interloper,
|
|
|
|
|
HUDIcon.WHITE_HOLE => MultiplayerHUDManager.WhiteHole,
|
|
|
|
|
_ => MultiplayerHUDManager.UnknownSprite,
|
|
|
|
|
};
|
|
|
|
|
}
|