mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-27 18:41:03 +00:00
Add NH compat to planet hud
This commit is contained in:
parent
3f525dd937
commit
701dc598a1
@ -1,10 +1,15 @@
|
||||
using Mirror;
|
||||
using System.Reflection;
|
||||
using Mirror;
|
||||
using NewHorizons;
|
||||
using NewHorizons.Builder.ShipLog;
|
||||
using NewHorizons.Components.Orbital;
|
||||
using OWML.Common;
|
||||
using OWML.ModHelper;
|
||||
using QSB;
|
||||
using QSB.HUD;
|
||||
using QSB.Messaging;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace QSBNH
|
||||
{
|
||||
@ -19,6 +24,48 @@ namespace QSBNH
|
||||
Instance = this;
|
||||
DebugLog.DebugWrite($"Start of QSB-NH compatibility code.", MessageType.Success);
|
||||
NewHorizonsAPI = QSBCore.Helper.Interaction.TryGetModApi<INewHorizons>("xen.NewHorizons");
|
||||
|
||||
GlobalMessenger.AddListener(OWEvents.WakeUp, OnWakeUp);
|
||||
}
|
||||
|
||||
private void OnWakeUp()
|
||||
{
|
||||
// Allow time for MultiplayerHUDManager.OnWakeUp to run
|
||||
Delay.RunNextFrame(() =>
|
||||
{
|
||||
var currentPlanets = NewHorizons.Main.BodyDict[NewHorizons.Main.Instance.CurrentStarSystem];
|
||||
foreach (var planet in currentPlanets)
|
||||
{
|
||||
if (planet.Object == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var nhAstro = planet.Object.GetComponent<NHAstroObject>();
|
||||
|
||||
if (planet.Config?.ShipLog == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var _astroObjectToShipLog = (Dictionary<GameObject, ShipLogAstroObject>)typeof(MapModeBuilder)
|
||||
.GetField("_astroObjectToShipLog", BindingFlags.Static | BindingFlags.NonPublic)
|
||||
.GetValue(null);
|
||||
var shipLogAstroObject = _astroObjectToShipLog[planet.Object];
|
||||
|
||||
var astroObjName = nhAstro.isVanilla
|
||||
? Enum.GetName(typeof(AstroObject.Name), nhAstro.GetAstroObjectName())
|
||||
: planet.Config.name;
|
||||
|
||||
var sprite = shipLogAstroObject._imageObj.GetComponent<Image>().sprite;
|
||||
MultiplayerHUDManager.Instance.PlanetToSprite[astroObjName] = sprite;
|
||||
|
||||
if (!nhAstro.isVanilla)
|
||||
{
|
||||
MultiplayerHUDManager.CreateTrigger(nhAstro.GetRootSector().gameObject, astroObjName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static string HashToMod(int hash)
|
||||
|
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
namespace QSB.HUD;
|
||||
|
||||
public enum HUDIcon
|
||||
{
|
||||
UNKNOWN,
|
||||
SPACE,
|
||||
DEAD,
|
||||
SHIP,
|
||||
CAVE_TWIN,
|
||||
TOWER_TWIN,
|
||||
TIMBER_HEARTH,
|
||||
ATTLEROCK,
|
||||
BRITTLE_HOLLOW,
|
||||
HOLLOWS_LANTERN,
|
||||
GIANTS_DEEP,
|
||||
DARK_BRAMBLE,
|
||||
INTERLOPER,
|
||||
WHITE_HOLE
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
|
||||
namespace QSB.HUD.Messages;
|
||||
|
||||
public class PlanetMessage : QSBMessage<HUDIcon>
|
||||
public class PlanetMessage : QSBMessage<string>
|
||||
{
|
||||
public PlanetMessage(HUDIcon icon) : base(icon) { }
|
||||
public PlanetMessage(string planet) : base(planet) { }
|
||||
|
||||
public override void OnReceiveLocal() => OnReceiveRemote();
|
||||
|
||||
|
@ -7,6 +7,7 @@ using QSB.ServerSettings;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@ -39,12 +40,16 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
public static Sprite DarkBramble;
|
||||
public static Sprite Interloper;
|
||||
public static Sprite WhiteHole;
|
||||
public static Sprite Ringworld;
|
||||
public static Sprite QuantumMoon;
|
||||
|
||||
public static readonly ListStack<HUDIcon> HUDIconStack = new(true);
|
||||
public static readonly ListStack<string> HUDIconStack = new(true);
|
||||
|
||||
public class ChatEvent : UnityEvent<string, uint> { }
|
||||
public static readonly ChatEvent OnChatMessageEvent = new();
|
||||
|
||||
public Dictionary<string, Sprite> PlanetToSprite = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Instance = this;
|
||||
@ -57,16 +62,6 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
UnknownSprite = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_unknown.png");
|
||||
DeadSprite = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_dead.png");
|
||||
ShipSprite = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_ship.png");
|
||||
CaveTwin = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_cavetwin.png");
|
||||
TowerTwin = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_towertwin.png");
|
||||
TimberHearth = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_timberhearth.png");
|
||||
Attlerock = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_attlerock.png");
|
||||
BrittleHollow = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_brittlehollow.png");
|
||||
HollowsLantern = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_hollowslantern.png");
|
||||
GiantsDeep = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_giantsdeep.png");
|
||||
DarkBramble = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_darkbramble.png");
|
||||
Interloper = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_interloper.png");
|
||||
WhiteHole = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_whitehole.png");
|
||||
SpaceSprite = QSBCore.HUDAssetBundle.LoadAsset<Sprite>("Assets/MULTIPLAYER_UI/playerbox_space.png");
|
||||
}
|
||||
|
||||
@ -265,6 +260,52 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
}
|
||||
}
|
||||
|
||||
public void CreatePlanetToSprite()
|
||||
{
|
||||
PlanetToSprite = new Dictionary<string, Sprite>()
|
||||
{
|
||||
{ "__SHIP__", MultiplayerHUDManager.ShipSprite },
|
||||
{ "__DEAD__", MultiplayerHUDManager.DeadSprite },
|
||||
{ "__SPACE__", MultiplayerHUDManager.SpaceSprite },
|
||||
{ "__UNKNOWN__", MultiplayerHUDManager.UnknownSprite },
|
||||
{ nameof(AstroObject.Name.CaveTwin), MultiplayerHUDManager.CaveTwin },
|
||||
{ nameof(AstroObject.Name.TowerTwin), MultiplayerHUDManager.TowerTwin },
|
||||
{ nameof(AstroObject.Name.TimberHearth), MultiplayerHUDManager.TimberHearth },
|
||||
{ nameof(AstroObject.Name.TimberMoon), MultiplayerHUDManager.Attlerock },
|
||||
{ nameof(AstroObject.Name.BrittleHollow), MultiplayerHUDManager.BrittleHollow },
|
||||
{ nameof(AstroObject.Name.VolcanicMoon), MultiplayerHUDManager.HollowsLantern },
|
||||
{ nameof(AstroObject.Name.GiantsDeep), MultiplayerHUDManager.GiantsDeep },
|
||||
{ nameof(AstroObject.Name.DarkBramble), MultiplayerHUDManager.DarkBramble },
|
||||
{ nameof(AstroObject.Name.Comet), MultiplayerHUDManager.Interloper },
|
||||
{ nameof(AstroObject.Name.WhiteHole), MultiplayerHUDManager.WhiteHole },
|
||||
{ nameof(AstroObject.Name.RingWorld), MultiplayerHUDManager.Ringworld },
|
||||
{ nameof(AstroObject.Name.QuantumMoon), MultiplayerHUDManager.QuantumMoon },
|
||||
};
|
||||
}
|
||||
|
||||
private string AstroObjectNameToStringID(AstroObject.Name name) => name switch
|
||||
{
|
||||
AstroObject.Name.TimberHearth => "TIMBER_HEARTH",
|
||||
AstroObject.Name.DreamWorld => "DREAMWORLD",
|
||||
AstroObject.Name.RingWorld => "RINGWORLD",
|
||||
AstroObject.Name.GiantsDeep => "GIANTS_DEEP",
|
||||
AstroObject.Name.VolcanicMoon => "VOLCANIC_MOON",
|
||||
AstroObject.Name.BrittleHollow => "BRITTLE_HOLLOW",
|
||||
AstroObject.Name.WhiteHole => "WHITE_HOLE",
|
||||
AstroObject.Name.ProbeCannon => "ORBITAL_PROBE_CANNON",
|
||||
AstroObject.Name.TimberMoon => "TIMBER_MOON",
|
||||
AstroObject.Name.QuantumMoon => "QUANTUM_MOON",
|
||||
AstroObject.Name.Eye => "EYE_OF_THE_UNIVERSE",
|
||||
AstroObject.Name.SunStation => "SUN_STATION",
|
||||
AstroObject.Name.Sun => "SUN",
|
||||
AstroObject.Name.DarkBramble => "DARK_BRAMBLE",
|
||||
AstroObject.Name.WhiteHoleTarget => "WHITE_HOLE_TARGET",
|
||||
AstroObject.Name.Comet => "COMET",
|
||||
AstroObject.Name.TowerTwin => "TOWER_TWIN",
|
||||
AstroObject.Name.CaveTwin => "CAVE_TWIN",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(name), name, null),
|
||||
};
|
||||
|
||||
private void OnWakeUp()
|
||||
{
|
||||
var hudController = Locator.GetPlayerCamera().transform.Find("Helmet").Find("HUDController").GetComponent<HUDCanvas>();
|
||||
@ -299,22 +340,59 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
}
|
||||
}
|
||||
|
||||
CreateTrigger("TowerTwin_Body/Sector_TowerTwin", HUDIcon.TOWER_TWIN);
|
||||
CreateTrigger("CaveTwin_Body/Sector_CaveTwin", HUDIcon.CAVE_TWIN);
|
||||
CreateTrigger("TimberHearth_Body/Sector_TH", HUDIcon.TIMBER_HEARTH);
|
||||
CreateTrigger("Moon_Body/Sector_THM", HUDIcon.ATTLEROCK);
|
||||
CreateTrigger("BrittleHollow_Body/Sector_BH", HUDIcon.BRITTLE_HOLLOW);
|
||||
CreateTrigger("VolcanicMoon_Body/Sector_VM", HUDIcon.HOLLOWS_LANTERN);
|
||||
CreateTrigger("GiantsDeep_Body/Sector_GD", HUDIcon.GIANTS_DEEP);
|
||||
CreateTrigger("DarkBramble_Body/Sector_DB", HUDIcon.DARK_BRAMBLE);
|
||||
CreateTrigger("Comet_Body/Sector_CO", HUDIcon.INTERLOPER);
|
||||
CreateTrigger("WhiteHole_Body/Sector_WhiteHole", HUDIcon.WHITE_HOLE);
|
||||
var shipLogMapMode = Resources.FindObjectsOfTypeAll<ShipLogMapMode>()[0];
|
||||
var allShipLogAstroObjects = new List<ShipLogAstroObject>();
|
||||
allShipLogAstroObjects.AddRange(shipLogMapMode._topRow);
|
||||
allShipLogAstroObjects.AddRange(shipLogMapMode._midRow);
|
||||
allShipLogAstroObjects.AddRange(shipLogMapMode._bottomRow);
|
||||
|
||||
Sprite GetSprite(AstroObject.Name name)
|
||||
{
|
||||
var stringID = AstroObjectNameToStringID(name);
|
||||
var shipLogAstroObject = allShipLogAstroObjects.FirstOrDefault(x => x._id == stringID);
|
||||
|
||||
if (shipLogAstroObject == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Couldn't find ShipLogAstroObject for {name} ({stringID})", MessageType.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
return shipLogAstroObject._image.sprite;
|
||||
}
|
||||
|
||||
CaveTwin = GetSprite(AstroObject.Name.CaveTwin);
|
||||
TowerTwin = GetSprite(AstroObject.Name.TowerTwin);
|
||||
TimberHearth = GetSprite(AstroObject.Name.TimberHearth);
|
||||
Attlerock = GetSprite(AstroObject.Name.TimberMoon);
|
||||
BrittleHollow = GetSprite(AstroObject.Name.BrittleHollow);
|
||||
HollowsLantern = GetSprite(AstroObject.Name.VolcanicMoon);
|
||||
GiantsDeep = GetSprite(AstroObject.Name.GiantsDeep);
|
||||
DarkBramble = GetSprite(AstroObject.Name.DarkBramble);
|
||||
Interloper = GetSprite(AstroObject.Name.Comet);
|
||||
WhiteHole = GetSprite(AstroObject.Name.WhiteHole);
|
||||
Ringworld = GetSprite(AstroObject.Name.RingWorld);
|
||||
QuantumMoon = GetSprite(AstroObject.Name.QuantumMoon);
|
||||
|
||||
CreatePlanetToSprite();
|
||||
|
||||
CreateTrigger("TowerTwin_Body/Sector_TowerTwin", AstroObject.Name.TowerTwin);
|
||||
CreateTrigger("CaveTwin_Body/Sector_CaveTwin", AstroObject.Name.CaveTwin);
|
||||
CreateTrigger("TimberHearth_Body/Sector_TH", AstroObject.Name.TimberHearth);
|
||||
CreateTrigger("Moon_Body/Sector_THM", AstroObject.Name.TimberMoon);
|
||||
CreateTrigger("BrittleHollow_Body/Sector_BH", AstroObject.Name.BrittleHollow);
|
||||
CreateTrigger("VolcanicMoon_Body/Sector_VM", AstroObject.Name.VolcanicMoon);
|
||||
CreateTrigger("GiantsDeep_Body/Sector_GD", AstroObject.Name.GiantsDeep);
|
||||
CreateTrigger("DarkBramble_Body/Sector_DB", AstroObject.Name.DarkBramble);
|
||||
CreateTrigger("Comet_Body/Sector_CO", AstroObject.Name.Comet);
|
||||
CreateTrigger("WhiteHole_Body/Sector_WhiteHole", AstroObject.Name.WhiteHole);
|
||||
CreateTrigger("RingWorld_Body/Sector_RingWorld", AstroObject.Name.RingWorld); // TODO : this doesnt work????
|
||||
CreateTrigger("QuantumMoon_Body/Sector_QuantumMoon", AstroObject.Name.QuantumMoon);
|
||||
|
||||
HUDIconStack.Clear();
|
||||
HUDIconStack.Push(HUDIcon.SPACE);
|
||||
HUDIconStack.Push(HUDIcon.TIMBER_HEARTH);
|
||||
HUDIconStack.Push("__SPACE__");
|
||||
|
||||
new PlanetMessage(HUDIcon.TIMBER_HEARTH).Send();
|
||||
HUDIconStack.Push("TimberHearth");
|
||||
new PlanetMessage("TimberHearth").Send();
|
||||
|
||||
_textChat = multiplayerGroup.transform.Find("TextChat");
|
||||
var inputFieldGO = _textChat.Find("InputField");
|
||||
@ -460,10 +538,10 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
WriteSystemMessage(string.Format(QSBLocalization.Current.PlayerLeftTheGame, player.Name), Color.yellow);
|
||||
}
|
||||
|
||||
private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon)
|
||||
=> CreateTrigger(Find(parentPath), icon);
|
||||
public static PlanetTrigger CreateTrigger(string parentPath, AstroObject.Name name)
|
||||
=> CreateTrigger(Find(parentPath), Enum.GetName(typeof(AstroObject.Name), name));
|
||||
|
||||
private PlanetTrigger CreateTrigger(GameObject parent, HUDIcon icon)
|
||||
public static PlanetTrigger CreateTrigger(GameObject parent, string name)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
@ -474,7 +552,7 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
if (triggerGO != null)
|
||||
{
|
||||
var trigger = triggerGO.GetAddComponent<PlanetTrigger>();
|
||||
trigger.Icon = icon;
|
||||
trigger.PlanetID = name;
|
||||
return trigger;
|
||||
}
|
||||
else
|
||||
@ -483,7 +561,7 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
|
||||
triggerGO.transform.SetParent(parent.transform, false);
|
||||
triggerGO.SetActive(false);
|
||||
var trigger = triggerGO.AddComponent<PlanetTrigger>();
|
||||
trigger.Icon = icon;
|
||||
trigger.PlanetID = name;
|
||||
triggerGO.SetActive(true);
|
||||
return trigger;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace QSB.HUD;
|
||||
|
||||
public class PlanetTrigger : SectoredMonoBehaviour
|
||||
{
|
||||
public HUDIcon Icon;
|
||||
public string PlanetID;
|
||||
|
||||
public override void OnSectorOccupantAdded(SectorDetector detector)
|
||||
{
|
||||
@ -15,7 +15,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
MultiplayerHUDManager.HUDIconStack.Push(Icon);
|
||||
MultiplayerHUDManager.HUDIconStack.Push(PlanetID);
|
||||
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
|
||||
new PlanetMessage(top).Send();
|
||||
}
|
||||
@ -27,7 +27,7 @@ public class PlanetTrigger : SectoredMonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
MultiplayerHUDManager.HUDIconStack.Remove(Icon);
|
||||
MultiplayerHUDManager.HUDIconStack.Remove(PlanetID);
|
||||
var top = MultiplayerHUDManager.HUDIconStack.PeekFront();
|
||||
new PlanetMessage(top).Send();
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
using QSB.Player;
|
||||
using OWML.Common;
|
||||
using QSB.Player;
|
||||
using QSB.Player.Messages;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QSB.ServerSettings;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace QSB.HUD;
|
||||
@ -16,10 +15,8 @@ public class PlayerBox : MonoBehaviour
|
||||
public Image InfoImage;
|
||||
|
||||
private PlayerInfo _player;
|
||||
private bool _planetIconOverride;
|
||||
private bool _inUnknown;
|
||||
|
||||
public HUDIcon PlanetIcon { get; private set; }
|
||||
public string CurrentPlanet { get; private set; }
|
||||
|
||||
public void AssignPlayer(PlayerInfo player)
|
||||
{
|
||||
@ -38,79 +35,86 @@ public class PlayerBox : MonoBehaviour
|
||||
new RequestStateResyncMessage().Send();
|
||||
}
|
||||
|
||||
public void OnDeath()
|
||||
private void SetSprite(Sprite sprite)
|
||||
{
|
||||
InfoImage.sprite = MultiplayerHUDManager.DeadSprite;
|
||||
_planetIconOverride = true;
|
||||
if (InfoImage.sprite != sprite)
|
||||
{
|
||||
InfoImage.sprite = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRespawn()
|
||||
void Update()
|
||||
{
|
||||
InfoImage.sprite = MultiplayerHUDManager.ShipSprite;
|
||||
_planetIconOverride = true; // still in ship
|
||||
}
|
||||
var isDead = _player.IsDead;
|
||||
var inShip = _player.IsInShip;
|
||||
var currentSprite = InfoImage.sprite;
|
||||
|
||||
public void OnEnterShip()
|
||||
{
|
||||
if (_inUnknown)
|
||||
if (isDead)
|
||||
{
|
||||
SetSprite(MultiplayerHUDManager.DeadSprite);
|
||||
return;
|
||||
}
|
||||
|
||||
InfoImage.sprite = MultiplayerHUDManager.ShipSprite;
|
||||
_planetIconOverride = true;
|
||||
}
|
||||
|
||||
public void OnExitShip()
|
||||
{
|
||||
if (_inUnknown)
|
||||
if (inShip)
|
||||
{
|
||||
SetSprite(MultiplayerHUDManager.ShipSprite);
|
||||
return;
|
||||
}
|
||||
|
||||
_planetIconOverride = false;
|
||||
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
||||
var isUnknown = IsUnknown();
|
||||
|
||||
if (isUnknown && !ServerSettingsManager.ServerAlwaysShowPlanetIcons)
|
||||
{
|
||||
SetSprite(MultiplayerHUDManager.UnknownSprite);
|
||||
}
|
||||
|
||||
public void OnEnterUnknown()
|
||||
else
|
||||
{
|
||||
_inUnknown = true;
|
||||
_planetIconOverride = true;
|
||||
InfoImage.sprite = MultiplayerHUDManager.UnknownSprite;
|
||||
}
|
||||
|
||||
public void OnExitUnknown()
|
||||
{
|
||||
_inUnknown = false;
|
||||
_planetIconOverride = false;
|
||||
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
||||
}
|
||||
|
||||
public void UpdateIcon(HUDIcon icon)
|
||||
{
|
||||
PlanetIcon = icon;
|
||||
|
||||
if (!_planetIconOverride)
|
||||
{
|
||||
InfoImage.sprite = SpriteFromEnum(PlanetIcon);
|
||||
SetSprite(GetSprite(CurrentPlanet));
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite SpriteFromEnum(HUDIcon icon) => icon switch
|
||||
private bool IsUnknown()
|
||||
{
|
||||
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,
|
||||
};
|
||||
if (ServerSettingsManager.AlwaysShowPlanetIcons)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CurrentPlanet is "__UNKNOWN__" or "RingWorld" or "QuantumMoon")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO : Get NH interference volumes / map restrictions working here
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateIcon(string planet)
|
||||
{
|
||||
CurrentPlanet = planet;
|
||||
}
|
||||
|
||||
private Sprite GetSprite(string planetName)
|
||||
{
|
||||
if (planetName == null)
|
||||
{
|
||||
return MultiplayerHUDManager.UnknownSprite;
|
||||
}
|
||||
|
||||
if (MultiplayerHUDManager.Instance.PlanetToSprite.TryGetValue(planetName, out var sprite))
|
||||
{
|
||||
if (sprite != null)
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLog.DebugWrite($"Sprite for {planetName} is null.", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"No sprite found for {planetName}", MessageType.Warning);
|
||||
return MultiplayerHUDManager.UnknownSprite;
|
||||
}
|
||||
}
|
||||
|
@ -60,19 +60,15 @@ public class EnterLeaveMessage : QSBMessage<EnterLeaveType>
|
||||
{
|
||||
case EnterLeaveType.EnterMoon:
|
||||
player.IsInMoon = true;
|
||||
player.HUDBox.OnEnterUnknown();
|
||||
break;
|
||||
case EnterLeaveType.ExitMoon:
|
||||
player.IsInMoon = false;
|
||||
player.HUDBox.OnExitUnknown();
|
||||
break;
|
||||
case EnterLeaveType.EnterCloak:
|
||||
player.IsInCloak = true;
|
||||
player.HUDBox.OnEnterUnknown();
|
||||
break;
|
||||
case EnterLeaveType.ExitCloak:
|
||||
player.IsInCloak = false;
|
||||
player.HUDBox.OnExitUnknown();
|
||||
break;
|
||||
case EnterLeaveType.EnterPlatform:
|
||||
CustomNomaiRemoteCameraPlatform.CustomPlatformList[ObjectId]
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Mirror;
|
||||
using OWML.Common;
|
||||
using QSB.ClientServerStateSync;
|
||||
using QSB.HUD;
|
||||
using QSB.Messaging;
|
||||
using QSB.Utility;
|
||||
|
||||
@ -21,7 +20,7 @@ public class PlayerInformationMessage : QSBMessage
|
||||
private ClientState ClientState;
|
||||
private float FieldOfView;
|
||||
private bool IsInShip;
|
||||
private HUDIcon HUDIcon;
|
||||
private string CurrentPlanet;
|
||||
private string SkinType;
|
||||
private string JetpackType;
|
||||
|
||||
@ -40,7 +39,7 @@ public class PlayerInformationMessage : QSBMessage
|
||||
ClientState = player.State;
|
||||
FieldOfView = PlayerData.GetGraphicSettings().fieldOfView;
|
||||
IsInShip = player.IsInShip;
|
||||
HUDIcon = player.HUDBox == null ? HUDIcon.UNKNOWN : player.HUDBox.PlanetIcon;
|
||||
CurrentPlanet = player.HUDBox == null ? "__UNKNOWN__" : player.HUDBox.CurrentPlanet;
|
||||
SkinType = QSBCore.SkinVariation;
|
||||
JetpackType = QSBCore.JetpackVariation;
|
||||
}
|
||||
@ -60,7 +59,7 @@ public class PlayerInformationMessage : QSBMessage
|
||||
writer.Write(ClientState);
|
||||
writer.Write(FieldOfView);
|
||||
writer.Write(IsInShip);
|
||||
writer.Write(HUDIcon);
|
||||
writer.Write(CurrentPlanet);
|
||||
writer.Write(SkinType);
|
||||
writer.Write(JetpackType);
|
||||
}
|
||||
@ -80,7 +79,7 @@ public class PlayerInformationMessage : QSBMessage
|
||||
ClientState = reader.Read<ClientState>();
|
||||
FieldOfView = reader.ReadFloat();
|
||||
IsInShip = reader.ReadBool();
|
||||
HUDIcon = reader.Read<HUDIcon>();
|
||||
CurrentPlanet = reader.Read<string>();
|
||||
SkinType = reader.ReadString();
|
||||
JetpackType = reader.ReadString();
|
||||
}
|
||||
@ -120,7 +119,7 @@ public class PlayerInformationMessage : QSBMessage
|
||||
Delay.RunWhen(() => player.HUDBox != null, () =>
|
||||
{
|
||||
player.HUDBox.PlayerName.text = PlayerName.ToUpper();
|
||||
player.HUDBox.UpdateIcon(HUDIcon);
|
||||
player.HUDBox.UpdateIcon(CurrentPlanet);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -171,14 +171,12 @@ public partial class PlayerInfo
|
||||
{
|
||||
IsDead = true;
|
||||
SetVisible(false, 1);
|
||||
HUDBox.OnDeath();
|
||||
}
|
||||
|
||||
public void Revive()
|
||||
{
|
||||
IsDead = false;
|
||||
SetVisible(true, 1);
|
||||
HUDBox.OnRespawn();
|
||||
}
|
||||
|
||||
// internal for RequestStateResyncMessage
|
||||
|
@ -6,7 +6,6 @@ using QSB.Localization;
|
||||
using QSB.Menus;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.QuantumSync;
|
||||
using QSB.SaveSync;
|
||||
using QSB.ServerSettings;
|
||||
using QSB.Utility;
|
||||
@ -24,7 +23,6 @@ using QSB.BodyCustomization;
|
||||
using QSB.Player.Messages;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Random = System.Random;
|
||||
using QSB.Utility.Deterministic;
|
||||
|
||||
/*
|
||||
@ -70,6 +68,7 @@ public class QSBCore : ModBehaviour
|
||||
public static bool ShowPlayerNames { get; private set; }
|
||||
public static bool ShipDamage { get; private set; }
|
||||
public static bool ShowExtraHUDElements { get; private set; }
|
||||
public static bool AlwaysShowPlanetIcons { get; private set; }
|
||||
public static bool TextChatInput { get; private set; }
|
||||
public static string SkinVariation { get; private set; } = "Default";
|
||||
public static string JetpackVariation { get; private set; } = "Orange";
|
||||
@ -413,6 +412,7 @@ public class QSBCore : ModBehaviour
|
||||
ShipDamage = config.GetSettingsValue<bool>("shipDamage");
|
||||
ShowExtraHUDElements = config.GetSettingsValue<bool>("showExtraHud");
|
||||
TextChatInput = config.GetSettingsValue<bool>("textChatInput");
|
||||
AlwaysShowPlanetIcons = config.GetSettingsValue<bool>("alwaysShowPlanetIcons");
|
||||
|
||||
if (DebugSettings.RandomizeSkins)
|
||||
{
|
||||
@ -428,6 +428,7 @@ public class QSBCore : ModBehaviour
|
||||
if (IsHost)
|
||||
{
|
||||
ServerSettingsManager.ServerShowPlayerNames = ShowPlayerNames;
|
||||
ServerSettingsManager.ServerAlwaysShowPlanetIcons = AlwaysShowPlanetIcons;
|
||||
new ServerSettingsMessage().Send();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ namespace QSB.ServerSettings;
|
||||
public class ServerSettingsManager : MonoBehaviour, IAddComponentOnStart
|
||||
{
|
||||
public static bool ServerShowPlayerNames;
|
||||
public static bool ServerAlwaysShowPlanetIcons;
|
||||
public static bool ShowPlayerNames => (ServerShowPlayerNames || QSBCore.IsHost) && QSBCore.ShowPlayerNames;
|
||||
public static bool ShowExtraHUD => ShowPlayerNames && QSBCore.ShowExtraHUDElements;
|
||||
public static bool AlwaysShowPlanetIcons => (ServerAlwaysShowPlanetIcons || QSBCore.IsHost) && QSBCore.AlwaysShowPlanetIcons;
|
||||
}
|
||||
|
@ -6,22 +6,31 @@ namespace QSB.ServerSettings;
|
||||
public class ServerSettingsMessage : QSBMessage
|
||||
{
|
||||
private bool _showPlayerNames;
|
||||
private bool _alwaysShowPlanetIcons;
|
||||
|
||||
public ServerSettingsMessage()
|
||||
=> _showPlayerNames = QSBCore.ShowPlayerNames;
|
||||
{
|
||||
_showPlayerNames = QSBCore.ShowPlayerNames;
|
||||
_alwaysShowPlanetIcons = QSBCore.AlwaysShowPlanetIcons;
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(_showPlayerNames);
|
||||
writer.Write(_alwaysShowPlanetIcons);
|
||||
}
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
_showPlayerNames = reader.ReadBool();
|
||||
_alwaysShowPlanetIcons = reader.ReadBool();
|
||||
}
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
=> ServerSettingsManager.ServerShowPlayerNames = _showPlayerNames;
|
||||
{
|
||||
ServerSettingsManager.ServerShowPlayerNames = _showPlayerNames;
|
||||
ServerSettingsManager.ServerAlwaysShowPlanetIcons = _alwaysShowPlanetIcons;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Mirror;
|
||||
using OWML.Common;
|
||||
using QSB.Animation.Player.Thrusters;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.ShipSync.Messages;
|
||||
@ -10,7 +9,6 @@ using QSB.ShipSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
@ -173,7 +171,6 @@ public class ShipManager : WorldObjectManager
|
||||
public void AddPlayerToShip(PlayerInfo player)
|
||||
{
|
||||
player.IsInShip = true;
|
||||
player.HUDBox.OnEnterShip();
|
||||
_playersInShip.Add(player);
|
||||
UpdateElectricalComponent();
|
||||
}
|
||||
@ -181,7 +178,6 @@ public class ShipManager : WorldObjectManager
|
||||
public void RemovePlayerFromShip(PlayerInfo player)
|
||||
{
|
||||
player.IsInShip = false;
|
||||
player.HUDBox.OnExitShip();
|
||||
_playersInShip.Remove(player);
|
||||
UpdateElectricalComponent();
|
||||
}
|
||||
|
@ -52,6 +52,12 @@
|
||||
"value": true,
|
||||
"tooltip": "Show extra HUD elements, like player status and minimap icons."
|
||||
},
|
||||
"alwaysShowPlanetIcons": {
|
||||
"title": "Always Show Planet Icons",
|
||||
"type": "toggle",
|
||||
"value": false,
|
||||
"tooltip": "If disabled, the planet icon shown for each player will be replaced by a question mark (?) in thematically appropriate situations."
|
||||
} ,
|
||||
"textChatInput": {
|
||||
"title": "Text Chat Input",
|
||||
"type": "toggle",
|
||||
|
Loading…
x
Reference in New Issue
Block a user