Skip to content

Commit 283b0d8

Browse files
authored
Merge pull request #700 from qsb-dev/dev
1.3.0
2 parents 8154f01 + 06206c8 commit 283b0d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+702
-1271
lines changed

APITestMod/APITestMod.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class APITestMod : ModBehaviour
1010
public void Start()
1111
{
1212
var qsbAPI = ModHelper.Interaction.TryGetModApi<IQSBAPI>("Raicuparta.QuantumSpaceBuddies");
13-
var menuFrameworkAPI = ModHelper.Interaction.TryGetModApi<IMenuAPI>("_nebula.MenuFramework");
1413

1514
LoadManager.OnCompleteSceneLoad += (oldScene, newScene) =>
1615
{
@@ -19,7 +18,7 @@ public void Start()
1918
return;
2019
}
2120

22-
var button = menuFrameworkAPI.PauseMenu_MakeSimpleButton("QSB Api Test");
21+
var button = ModHelper.MenuHelper.PauseMenuManager.MakeSimpleButton("QSB API Test", 0, false);
2322

2423
qsbAPI.OnPlayerJoin().AddListener((uint playerId) => ModHelper.Console.WriteLine($"{playerId} joined the game!", MessageType.Success));
2524
qsbAPI.OnPlayerLeave().AddListener((uint playerId) => ModHelper.Console.WriteLine($"{playerId} left the game!", MessageType.Success));
@@ -29,7 +28,7 @@ public void Start()
2928
qsbAPI.RegisterHandler<int>("apitest-int", MessageHandler);
3029
qsbAPI.RegisterHandler<float>("apitest-float", MessageHandler);
3130

32-
button.onClick.AddListener(() =>
31+
button.OnSubmitAction += () =>
3332
{
3433
ModHelper.Console.WriteLine("TESTING QSB API!");
3534

@@ -57,7 +56,7 @@ public void Start()
5756

5857
qsbAPI.SendChatMessage("Non-system chat message", false, Color.white);
5958
qsbAPI.SendChatMessage("System chat message", true, Color.cyan);
60-
});
59+
};
6160
};
6261
}
6362

APITestMod/IMenuAPI.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

APITestMod/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"uniqueName": "_nebula.QSBAPITest",
66
"version": "1.0.0",
77
"owmlVersion": "2.11.1",
8-
"dependencies": [ "Raicuparta.QuantumSpaceBuddies", "_nebula.MenuFramework" ]
8+
"dependencies": [ "Raicuparta.QuantumSpaceBuddies" ]
99
}

QSB-NH/QSBNH.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
using Mirror;
1+
using System.Reflection;
2+
using Mirror;
23
using NewHorizons;
4+
using NewHorizons.Builder.ShipLog;
5+
using NewHorizons.Components.Orbital;
36
using OWML.Common;
4-
using OWML.ModHelper;
57
using QSB;
8+
using QSB.HUD;
9+
using QSB.Messaging;
610
using QSB.Utility;
711
using UnityEngine;
12+
using UnityEngine.UI;
813

914
namespace QSBNH
1015
{
@@ -19,6 +24,48 @@ private void Start()
1924
Instance = this;
2025
DebugLog.DebugWrite($"Start of QSB-NH compatibility code.", MessageType.Success);
2126
NewHorizonsAPI = QSBCore.Helper.Interaction.TryGetModApi<INewHorizons>("xen.NewHorizons");
27+
28+
GlobalMessenger.AddListener(OWEvents.WakeUp, OnWakeUp);
29+
}
30+
31+
private void OnWakeUp()
32+
{
33+
// Allow time for MultiplayerHUDManager.OnWakeUp to run
34+
Delay.RunNextFrame(() =>
35+
{
36+
var currentPlanets = NewHorizons.Main.BodyDict[NewHorizons.Main.Instance.CurrentStarSystem];
37+
foreach (var planet in currentPlanets)
38+
{
39+
if (planet.Object == null)
40+
{
41+
continue;
42+
}
43+
44+
var nhAstro = planet.Object.GetComponent<NHAstroObject>();
45+
46+
if (planet.Config?.ShipLog == null)
47+
{
48+
continue;
49+
}
50+
51+
var _astroObjectToShipLog = (Dictionary<GameObject, ShipLogAstroObject>)typeof(MapModeBuilder)
52+
.GetField("_astroObjectToShipLog", BindingFlags.Static | BindingFlags.NonPublic)
53+
.GetValue(null);
54+
var shipLogAstroObject = _astroObjectToShipLog[planet.Object];
55+
56+
var astroObjName = nhAstro.isVanilla
57+
? Enum.GetName(typeof(AstroObject.Name), nhAstro.GetAstroObjectName())
58+
: planet.Config.name;
59+
60+
var sprite = shipLogAstroObject._imageObj.GetComponent<Image>().sprite;
61+
MultiplayerHUDManager.Instance.PlanetToSprite[astroObjName] = sprite;
62+
63+
if (!nhAstro.isVanilla)
64+
{
65+
MultiplayerHUDManager.CreateTrigger(nhAstro.GetRootSector().gameObject, astroObjName);
66+
}
67+
}
68+
});
2269
}
2370

2471
public static string HashToMod(int hash)

QSB/Animation/Player/AnimationSync.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ namespace QSB.Animation.Player;
1515
[UsedInUnityProject]
1616
public class AnimationSync : PlayerSyncObject
1717
{
18+
public static int DropHeldItem = Animator.StringToHash("DropHeldItem");
19+
public static int HoldLantern = Animator.StringToHash("HoldLantern");
20+
public static int HoldSharedStone = Animator.StringToHash("HoldSharedStone");
21+
public static int HoldScroll = Animator.StringToHash("HoldScroll");
22+
public static int HoldWarpCore = Animator.StringToHash("HoldWarpCore");
23+
public static int HoldAdvWarpCore = Animator.StringToHash("HoldAdvWarpCore");
24+
public static int HoldItem = Animator.StringToHash("HoldItem");
25+
1826
private RuntimeAnimatorController _suitedAnimController;
1927
private AnimatorOverrideController _unsuitedAnimController;
2028
private GameObject _suitedGraphics;
@@ -209,4 +217,20 @@ public void SetSuitState(bool suitedUp)
209217
Mirror.RebuildFloatParams();
210218
NetworkAnimator.Invoke("Awake");
211219
}
220+
221+
public void PickUpItem(int animHash)
222+
{
223+
VisibleAnimator.SetTrigger(animHash);
224+
VisibleAnimator.SetLayerWeight(2, 1);
225+
InvisibleAnimator.SetTrigger(animHash);
226+
InvisibleAnimator.SetLayerWeight(2, 1);
227+
}
228+
229+
public void DropItem()
230+
{
231+
VisibleAnimator.SetTrigger(DropHeldItem);
232+
VisibleAnimator.SetLayerWeight(2, 1);
233+
InvisibleAnimator.SetTrigger(DropHeldItem);
234+
InvisibleAnimator.SetLayerWeight(2, 1);
235+
}
212236
}

QSB/Animation/Player/AnimatorMirror.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AnimatorMirror : MonoBehaviour
1515
private Animator _to;
1616
private NetworkAnimator _networkAnimator;
1717

18-
private readonly Dictionary<string, AnimFloatParam> _floatParams = new();
18+
private readonly Dictionary<int, AnimFloatParam> _floatParams = new();
1919

2020
/// <summary>
2121
/// Initializes the Animator Mirror
@@ -82,36 +82,38 @@ private void SyncParams()
8282
switch (fromParam.type)
8383
{
8484
case AnimatorControllerParameterType.Float:
85-
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
85+
_floatParams[fromParam.nameHash].Target = _from.GetFloat(fromParam.nameHash);
8686
break;
8787

8888
case AnimatorControllerParameterType.Int:
89-
_to.SetInteger(fromParam.name, _from.GetInteger(fromParam.name));
89+
_to.SetInteger(fromParam.nameHash, _from.GetInteger(fromParam.nameHash));
9090
break;
9191

9292
case AnimatorControllerParameterType.Bool:
93-
_to.SetBool(fromParam.name, _from.GetBool(fromParam.name));
93+
_to.SetBool(fromParam.nameHash, _from.GetBool(fromParam.nameHash));
9494
break;
9595

9696
case AnimatorControllerParameterType.Trigger:
97-
if (_from.GetBool(fromParam.name) && !_to.GetBool(fromParam.name))
97+
if (_from.GetBool(fromParam.nameHash) && !_to.GetBool(fromParam.nameHash))
9898
{
9999
if (_networkAnimator != null)
100100
{
101-
_networkAnimator.SetTrigger(fromParam.name);
101+
DebugLog.DebugWrite($"Set {fromParam.name} on netanim");
102+
_networkAnimator.SetTrigger(fromParam.nameHash);
102103
}
103104

104-
_to.SetTrigger(fromParam.name);
105+
_to.SetTrigger(fromParam.nameHash);
105106
}
106107

107-
if (!_from.GetBool(fromParam.name) && _to.GetBool(fromParam.name))
108+
if (!_from.GetBool(fromParam.nameHash) && _to.GetBool(fromParam.nameHash))
108109
{
109110
if (_networkAnimator != null)
110111
{
111-
_networkAnimator.ResetTrigger(fromParam.name);
112+
DebugLog.DebugWrite($"Reset {fromParam.name} on netanim");
113+
_networkAnimator.ResetTrigger(fromParam.nameHash);
112114
}
113115

114-
_to.ResetTrigger(fromParam.name);
116+
_to.ResetTrigger(fromParam.nameHash);
115117
}
116118

117119
break;
@@ -142,7 +144,7 @@ public void RebuildFloatParams()
142144
_floatParams.Clear();
143145
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
144146
{
145-
_floatParams.Add(param.name, new AnimFloatParam());
147+
_floatParams.Add(param.nameHash, new AnimFloatParam());
146148
}
147149
}
148150
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using HarmonyLib;
2+
using QSB.Patches;
3+
4+
namespace QSB.Animation.Player.Patches;
5+
6+
[HarmonyPatch(typeof(PlayerAnimController))]
7+
public class PlayerAnimControllerPatches : QSBPatch
8+
{
9+
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
10+
11+
/*
12+
* These patches preserve layer weights between animatorcontroller changes.
13+
* No idea if this is intended Unity behaviour,
14+
* but when changing the controller the layer weights get
15+
* reset back to 0 - even if their default is not 0.
16+
*/
17+
18+
[HarmonyPrefix]
19+
[HarmonyPatch(nameof(PlayerAnimController.OnPutOnSuit))]
20+
public static bool OnPutOnSuit(PlayerAnimController __instance)
21+
{
22+
var layerCount = __instance._animator.layerCount;
23+
var layerWeights = new float[layerCount];
24+
for (var i = 0; i < layerCount; i++)
25+
{
26+
layerWeights[i] = __instance._animator.GetLayerWeight(i);
27+
}
28+
29+
__instance._animator.runtimeAnimatorController = __instance._baseAnimController;
30+
__instance._unsuitedGroup.SetActive(false);
31+
__instance._suitedGroup.SetActive(!PlayerState.InMapView());
32+
33+
for (var i = 0; i < layerCount; i++)
34+
{
35+
__instance._animator.SetLayerWeight(i, layerWeights[i]);
36+
}
37+
38+
return false;
39+
}
40+
41+
[HarmonyPrefix]
42+
[HarmonyPatch(nameof(PlayerAnimController.OnRemoveSuit))]
43+
public static bool OnRemoveSuit(PlayerAnimController __instance)
44+
{
45+
var layerCount = __instance._animator.layerCount;
46+
var layerWeights = new float[layerCount];
47+
for (var i = 0; i < layerCount; i++)
48+
{
49+
layerWeights[i] = __instance._animator.GetLayerWeight(i);
50+
}
51+
52+
__instance._animator.runtimeAnimatorController = __instance._unsuitedAnimOverride;
53+
__instance._unsuitedGroup.SetActive(!PlayerState.InMapView());
54+
__instance._suitedGroup.SetActive(false);
55+
56+
for (var i = 0; i < layerCount; i++)
57+
{
58+
__instance._animator.SetLayerWeight(i, layerWeights[i]);
59+
}
60+
61+
return false;
62+
}
63+
}

QSB/AssetBundles/qsb_hud

-445 KB
Binary file not shown.

QSB/AssetBundles/qsb_network

288 KB
Binary file not shown.

QSB/AssetBundles/qsb_network_big

-12.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)