Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.26.0 #599

Merged
merged 38 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8d3a37f
move the comment
JohnCorby Feb 8, 2023
f8f795a
add 1.1.13 qm patch
JohnCorby Feb 8, 2023
9d308ee
fix being able to wake up instantly
misternebula Feb 8, 2023
62cbc37
update asset bundles
misternebula Feb 10, 2023
4fdefcb
Update Extensions.cs
misternebula Feb 10, 2023
8b4bd22
add hud assetbundle to QSBCore
misternebula Feb 10, 2023
b5968fe
add HUD player boxes
misternebula Feb 10, 2023
0e2c406
better hack
JohnCorby Feb 11, 2023
95361ad
dont move player if attached
JohnCorby Feb 11, 2023
8609f5b
silly invincibility hack
JohnCorby Feb 11, 2023
b26832f
todo
JohnCorby Feb 11, 2023
eae2cf3
okay nvm
JohnCorby Feb 11, 2023
52c7ed9
Revert "dont move player if attached"
JohnCorby Feb 11, 2023
6a074e7
Fix an inappropriate translation
isrecalpear Feb 12, 2023
7ce55b1
initial sync of player hud icon
misternebula Feb 12, 2023
8f7b351
Merge pull request #600 from isrecalpear/master
misternebula Feb 13, 2023
385ebd5
do this properly
JohnCorby Mar 1, 2023
7bb2f1c
DebugLog: slight refactor
JohnCorby Mar 1, 2023
4a51b91
Merge branch 'dev' into hud
misternebula Mar 3, 2023
b319a86
Update qsb_hud
misternebula Mar 3, 2023
51ced1c
request resync when box is set up
misternebula Mar 3, 2023
be99b69
fix issues with icon/name not updating and NRE
misternebula Mar 3, 2023
82824c6
destroy box when players leave
misternebula Mar 3, 2023
1372dbe
OnEnter/OnExitUnknown
misternebula Mar 3, 2023
082aa5a
add option to disable hud
misternebula Mar 3, 2023
3e30535
remove null log on PlayerInfo.Camera
misternebula Mar 4, 2023
6dcb938
Don't break if we find a null script in FontReplacer
misternebula Mar 4, 2023
94e47a6
add remote ruleset detector
misternebula Mar 4, 2023
310539c
add minimap stuff
misternebula Mar 4, 2023
e8c8efe
remove some debug logs
misternebula Mar 4, 2023
fa60466
remove more logs
misternebula Mar 4, 2023
fd91b35
add patch to make custom rulesetdetector work
misternebula Mar 4, 2023
9c718e4
fix NREs in debugGUI
misternebula Mar 4, 2023
bd6fa0a
change to probe marker, actually make it work
misternebula Mar 4, 2023
2eb1d04
change color of marker, and make be affected by config
misternebula Mar 4, 2023
9cec403
fix positioning on othe resolutions
misternebula Mar 4, 2023
20b5699
Merge pull request #601 from misternebula/hud
misternebula Mar 4, 2023
e124e86
Update manifest.json
misternebula Mar 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified QSB/AssetBundles/qsb_conversation
Binary file not shown.
Binary file modified QSB/AssetBundles/qsb_debug
Binary file not shown.
Binary file modified QSB/AssetBundles/qsb_empty
Binary file not shown.
Binary file added QSB/AssetBundles/qsb_hud
Binary file not shown.
Binary file modified QSB/AssetBundles/qsb_network
Binary file not shown.
Binary file modified QSB/AssetBundles/qsb_network_big
Binary file not shown.
2 changes: 1 addition & 1 deletion QSB/CampfireSync/Patches/CampfirePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static bool UpdateReplacement(Campfire __instance)
}
}

if (__instance._isPlayerSleeping)
if (__instance._isPlayerSleeping && Time.timeSinceLevelLoad > __instance._fastForwardStartTime)
{
__instance._wakePrompt.SetVisibility(OWInput.IsInputMode(InputMode.None) && Time.timeSinceLevelLoad - __instance._fastForwardStartTime > __instance.GetWakePromptDelay());
if (__instance.ShouldWakeUp())
Expand Down
19 changes: 19 additions & 0 deletions QSB/HUD/HUDIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
}
24 changes: 24 additions & 0 deletions QSB/HUD/Messages/PlanetMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;

namespace QSB.HUD.Messages;

internal class PlanetMessage : QSBMessage<HUDIcon>
{
public PlanetMessage(HUDIcon icon) : base(icon) { }

public override void OnReceiveLocal() => OnReceiveRemote();

public override void OnReceiveRemote()
{
var from = QSBPlayerManager.GetPlayer(From);

if (from == default)
{
return;
}

from.HUDBox?.UpdateIcon(Data);
}
}
272 changes: 272 additions & 0 deletions QSB/HUD/MultiplayerHUDManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
using QSB.HUD.Messages;
using QSB.Messaging;
using QSB.Player;
using QSB.ServerSettings;
using QSB.Utility;
using QSB.WorldSync;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace QSB.HUD;

internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart
{
public static MultiplayerHUDManager Instance;

private Transform _playerList;
private Material _markerMaterial;

public static Sprite UnknownSprite;
public static Sprite DeadSprite;
public static Sprite SpaceSprite;
public static Sprite ShipSprite;
public static Sprite TimberHearth;
public static Sprite Attlerock;
public static Sprite CaveTwin;
public static Sprite TowerTwin;
public static Sprite BrittleHollow;
public static Sprite HollowsLantern;
public static Sprite GiantsDeep;
public static Sprite DarkBramble;
public static Sprite Interloper;
public static Sprite WhiteHole;

public static ListStack<HUDIcon> HUDIconStack = new();

private void Start()
{
Instance = this;

GlobalMessenger.AddListener(OWEvents.WakeUp, OnWakeUp);

QSBPlayerManager.OnAddPlayer += OnAddPlayer;
QSBPlayerManager.OnRemovePlayer += OnRemovePlayer;

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");
}

private void Update()
{
if (!QSBWorldSync.AllObjectsReady || _playerList == null)
{
return;
}

_playerList.gameObject.SetActive(ServerSettingsManager.ShowExtraHUD);
}

private void OnWakeUp()
{
var hudController = Locator.GetPlayerCamera().transform.Find("Helmet").Find("HUDController").GetComponent<HUDCanvas>();
var hudCamera = hudController._hudCamera;
var hudCanvas = hudCamera.transform.parent.Find("UICanvas");

var multiplayerGroup = Instantiate(QSBCore.HUDAssetBundle.LoadAsset<GameObject>("assets/Prefabs/multiplayergroup.prefab"));

Delay.RunNextFrame(() =>
{
// no idea why this has to be next frame, but it does
multiplayerGroup.transform.parent = hudCanvas;
multiplayerGroup.transform.localPosition = Vector3.zero;
var rect = multiplayerGroup.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(1, 0.5f);
rect.anchorMax = new Vector2(1, 0.5f);
rect.sizeDelta = new Vector2(100, 100);
rect.anchoredPosition3D = new Vector3(-267, 0, 0);
rect.localRotation = Quaternion.Euler(0, 55, 0);
rect.localScale = Vector3.one;
});

_playerList = multiplayerGroup.transform.Find("PlayerList");

foreach (var player in QSBPlayerManager.PlayerList)
{
AddBox(player);

foreach (var item in QSBWorldSync.GetUnityObjects<Minimap>())
{
AddMinimapMarker(player, item);
}
}

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);

HUDIconStack.Clear();
HUDIconStack.Push(HUDIcon.SPACE);
HUDIconStack.Push(HUDIcon.TIMBER_HEARTH);

new PlanetMessage(HUDIcon.TIMBER_HEARTH).Send();

var playerMinimap = QSBWorldSync.GetUnityObjects<Minimap>().First(x => x.name == "Minimap_Root");
_markerMaterial = Instantiate(playerMinimap._probeMarkerTransform.GetComponent<MeshRenderer>().material);
_markerMaterial.color = Color.gray;
}

public void UpdateMinimapMarkers(Minimap minimap)
{
var localRuleset = Locator.GetPlayerRulesetDetector().GetPlanetoidRuleset();

foreach (var player in QSBPlayerManager.PlayerList)
{
if (player.IsDead || player.IsLocalPlayer || !player.IsReady)
{
continue;
}

if (player.RulesetDetector == null)
{
if (player.Body != null)
{
DebugLog.ToConsole($"Error - {player.PlayerId}'s RulesetDetector is null.", OWML.Common.MessageType.Error);
}

continue;
}

if (player.RulesetDetector.GetPlanetoidRuleset() == null
|| player.RulesetDetector.GetPlanetoidRuleset() != localRuleset)
{
continue;
}

if (player.MinimapPlayerMarker == null)
{
continue;
}

if (ServerSettingsManager.ShowExtraHUD)
{
player.MinimapPlayerMarker.localPosition = GetLocalMapPosition(player, minimap);
player.MinimapPlayerMarker.LookAt(minimap._globeMeshTransform, minimap._globeMeshTransform.up);
}
else
{
player.MinimapPlayerMarker.localPosition = Vector3.zero;
player.MinimapPlayerMarker.localRotation = Quaternion.identity;
}
}
}

private void AddMinimapMarker(PlayerInfo player, Minimap minimap)
{
player.MinimapPlayerMarker = Instantiate(minimap._probeMarkerTransform);
player.MinimapPlayerMarker.parent = minimap._probeMarkerTransform.parent;
player.MinimapPlayerMarker.localScale = new Vector3(0.05f, 0.05f, 0.05f);
player.MinimapPlayerMarker.localPosition = Vector3.zero;
player.MinimapPlayerMarker.localRotation = Quaternion.identity;
player.MinimapPlayerMarker.GetComponent<MeshRenderer>().material = _markerMaterial;
}

private void AddBox(PlayerInfo player)
{
var box = Instantiate(QSBCore.HUDAssetBundle.LoadAsset<GameObject>("assets/Prefabs/playerbox.prefab"));
box.transform.parent = _playerList;
box.transform.localScale = new Vector3(1, 1, 1);
box.transform.localPosition = Vector3.zero;
box.transform.localRotation = Quaternion.identity;

var boxScript = box.GetComponent<PlayerBox>();
boxScript.AssignPlayer(player);
}

private Vector3 GetLocalMapPosition(PlayerInfo player, Minimap minimap)
{
return Vector3.Scale(
player.RulesetDetector.GetPlanetoidRuleset().transform.InverseTransformPoint(player.Body.transform.position).normalized * 0.51f,
minimap._globeMeshTransform.localScale);
}

private void OnAddPlayer(PlayerInfo player)
{
if (!QSBWorldSync.AllObjectsReady)
{
return;
}

AddBox(player);

foreach (var item in QSBWorldSync.GetUnityObjects<Minimap>())
{
AddMinimapMarker(player, item);
}
}

private void OnRemovePlayer(PlayerInfo player)
{
Destroy(player.HUDBox.gameObject);
}

private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon)
=> CreateTrigger(Find(parentPath), icon);

private PlanetTrigger CreateTrigger(GameObject parent, HUDIcon icon)
{
if (parent == null)
{
return null;
}

var triggerGO = parent.FindChild("HUD_PLANET_TRIGGER");
if (triggerGO != null)
{
var trigger = triggerGO.GetAddComponent<PlanetTrigger>();
trigger.Icon = icon;
return trigger;
}
else
{
triggerGO = new GameObject("HUD_PLANET_TRIGGER");
triggerGO.transform.SetParent(parent.transform, false);
triggerGO.SetActive(false);
var trigger = triggerGO.AddComponent<PlanetTrigger>();
trigger.Icon = icon;
triggerGO.SetActive(true);
return trigger;
}
}

public static GameObject Find(string path)
{
var go = GameObject.Find(path);

if (go == null)
{
// find inactive use root + transform.find
var names = path.Split('/');
var rootName = names[0];
var root = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault(x => x.name == rootName);
if (root == null)
{
return null;
}

var childPath = string.Join("/", names.Skip(1));
go = root.FindChild(childPath);
}

return go;
}
}
17 changes: 17 additions & 0 deletions QSB/HUD/Patches/MinimapPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HarmonyLib;
using QSB.Patches;

namespace QSB.HUD.Patches;

[HarmonyPatch(typeof(Minimap))]
internal class MinimapPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;

[HarmonyPostfix]
[HarmonyPatch(nameof(Minimap.UpdateMarkers))]
public static void UpdateMarkers(Minimap __instance)
{
MultiplayerHUDManager.Instance.UpdateMinimapMarkers(__instance);
}
}
Loading