From 2443d4f2921890a7278d437c42645093a9fe425a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADnez?= Date: Tue, 17 Jul 2018 14:12:48 +0200 Subject: [PATCH] Added tooltips to inputs and outputs --- src/Components/Atoms.cs | 5 +-- src/Components/BuilderUtils.cs | 13 ++++--- src/Components/ComponentPatches.cs | 56 ++++++++++++++++++++---------- src/Components/IOInfo.cs | 1 + src/Components/IOMap.cs | 8 +++-- src/Components/PrefabBuilder.cs | 44 +++++++++++++++-------- src/PiTung Bootstrap.csproj | 2 +- 7 files changed, 86 insertions(+), 43 deletions(-) diff --git a/src/Components/Atoms.cs b/src/Components/Atoms.cs index bf08b37..3180c9c 100644 --- a/src/Components/Atoms.cs +++ b/src/Components/Atoms.cs @@ -14,6 +14,7 @@ internal abstract class IOAtom : IAtom { public Vector3 Position; public Quaternion Rotation; + public string Description; public abstract void AddToGameObject(GameObject obj); } @@ -22,7 +23,7 @@ internal sealed class InputPegAtom : IOAtom { public override void AddToGameObject(GameObject obj) { - BuilderUtils.AddInputPeg(obj, this.Position).transform.localRotation = this.Rotation; + BuilderUtils.AddInputPeg(obj, this.Position, Description).transform.localRotation = this.Rotation; } } @@ -30,7 +31,7 @@ internal sealed class OutputAtom : IOAtom { public override void AddToGameObject(GameObject obj) { - BuilderUtils.AddOutputPeg(obj, this.Position).transform.localRotation = this.Rotation; + BuilderUtils.AddOutputPeg(obj, this.Position, Description).transform.localRotation = this.Rotation; } } diff --git a/src/Components/BuilderUtils.cs b/src/Components/BuilderUtils.cs index 51595ef..937e031 100644 --- a/src/Components/BuilderUtils.cs +++ b/src/Components/BuilderUtils.cs @@ -14,12 +14,12 @@ public static void ApplyIOMap(GameObject prefabRoot, IOMap map) int i = 0, j = 0; foreach (var item in map.Sides) { - var io = AddIO(prefabRoot, item.Type, item.Side, item.XOffset, item.YOffset); - io.AddComponent().Index = item.Type == SideType.Input ? i++ : j++; + var io = AddIO(prefabRoot, item.Type, item.Side, item.XOffset, item.YOffset, item.Description); + io.GetComponent().Index = item.Type == SideType.Input ? i++ : j++; } } - public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, float ox, float oy) + public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, float ox, float oy, string description) { if (type == SideType.None) return null; @@ -63,6 +63,7 @@ public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, var prefab = type == SideType.Input ? Prefabs.Peg : Prefabs.Output; GameObject Peg = GameObject.Instantiate(prefab, parent.transform); + Peg.AddComponent().Description = description; Peg.transform.localPosition = new Vector3(x, y, z); Peg.transform.localScale = type == SideType.Input ? PegScale : OutputScale; Peg.transform.localEulerAngles = new Vector3(rotX, rotY, rotZ); @@ -77,10 +78,11 @@ public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, return Peg; } - public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition = null) + public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition = null, string description = null) { var Peg = GameObject.Instantiate(Prefabs.Peg); + Peg.AddComponent().Description = description; Peg.transform.localScale = new Vector3(PegScale.x * 0.3f, PegScale.y * 0.3f, PegScale.z * 0.3f); Peg.transform.parent = parent.transform; @@ -90,10 +92,11 @@ public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition = return Peg; } - public static GameObject AddOutputPeg(GameObject parent, Vector3? localPosition = null) + public static GameObject AddOutputPeg(GameObject parent, Vector3? localPosition = null, string description = null) { var Peg = GameObject.Instantiate(Prefabs.Output); + Peg.AddComponent().Description = description; Peg.transform.localScale = new Vector3(OutputScale.x * 0.3f, OutputScale.y * 0.3f, OutputScale.z * 0.3f); Peg.transform.parent = parent.transform; diff --git a/src/Components/ComponentPatches.cs b/src/Components/ComponentPatches.cs index 7d96268..58c3574 100644 --- a/src/Components/ComponentPatches.cs +++ b/src/Components/ComponentPatches.cs @@ -52,7 +52,7 @@ public static void Prefix(SavedCustomObject save, ObjectInfo CreateFromThis) return; } } - + saveData.Add(customComponent.ComponentName); saveData.Add(outputs.Select(o => o.On).ToArray()); saveData.AddRange(GetSaveThisFields(customComponent)); @@ -88,7 +88,7 @@ static IEnumerable> GetFieldsAndProperties(object o } } } - + [HarmonyPatch(typeof(SavedObjectUtilities), "CreateSavedObjectFrom", new Type[] { typeof(ObjectInfo) })] internal static class CreateSavedObjectFromPatch { @@ -113,7 +113,7 @@ static bool Prefix(ref SavedObjectV2 __result, ObjectInfo worldsave) return true; } } - + [HarmonyPatch(typeof(SavedObjectUtilities), "GetCustomPrefab")] internal static class GetCustomPrefabPatch { @@ -125,7 +125,7 @@ static IEnumerable Transpiler(IEnumerable inst yield return new CodeInstruction(OpCodes.Ret); } - static void Postfix(ref GameObject __result, SavedCustomObject save) + static void Postfix(ref GameObject __result, SavedCustomObject save) { if (save.CustomData.Length == 0) { @@ -265,7 +265,7 @@ static bool Prefix(ObjectInfo __instance) return true; } } - + [HarmonyPatch(typeof(ComponentPlacer), "MakeSureThingBeingPlacedIsCorrect")] internal static class asdasd @@ -322,30 +322,50 @@ static void Postfix() if (ModUtilities.IsOnMainMenu || !ShouldShow) return; + string str = null; + if (Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, 20)) { - var info = hit.transform.GetComponent() ?? - hit.transform.parent?.GetComponent(); + bool input = hit.transform.tag == "Input"; + bool output = hit.transform.tag == "Output"; - if (info != null && info.ComponentType == ComponentType.CustomObject) + if (input || output) { - var handler = hit.transform.GetComponent() ?? - hit.transform.GetComponentInChildren(); + var ioInfo = hit.transform.GetComponent(); - if (handler != null) + if (ioInfo?.Description != null) { - string str = handler.Component?.DisplayName ?? handler.ComponentName; - - var size = GUI.skin.box.CalcSize(new GUIContent(str)); - size.x += 10; - size.y += 10; + str = $"{(input ? "Input" : "Output")}: {ioInfo.Description}"; + } + } + else + { + var info = hit.transform.GetComponent() ?? + hit.transform.parent?.GetComponent(); - var rect = new Rect(Screen.width / 2 - size.x / 2, 10, size.x, size.y); + if (info?.ComponentType == ComponentType.CustomObject) + { + var handler = hit.transform.GetComponent() ?? + hit.transform.GetComponentInChildren(); - GUI.Box(rect, str, Style); + if (handler != null) + { + str = handler.Component?.DisplayName ?? handler.ComponentName; + } } } } + + if (str != null) + { + var size = GUI.skin.box.CalcSize(new GUIContent(str)); + size.x += 10; + size.y += 10; + + var rect = new Rect(Screen.width / 2 - size.x / 2, 10, size.x, size.y); + + GUI.Box(rect, str, Style); + } } } } diff --git a/src/Components/IOInfo.cs b/src/Components/IOInfo.cs index 0094f39..317c2cb 100644 --- a/src/Components/IOInfo.cs +++ b/src/Components/IOInfo.cs @@ -9,5 +9,6 @@ namespace PiTung.Components internal class IOInfo : MonoBehaviour { public int Index { get; set; } + public string Description { get; set; } } } diff --git a/src/Components/IOMap.cs b/src/Components/IOMap.cs index 4f9da21..abcf74a 100644 --- a/src/Components/IOMap.cs +++ b/src/Components/IOMap.cs @@ -34,13 +34,15 @@ public struct IO public SideType Type; public float XOffset; public float YOffset; + public string Description; - public IO(CubeSide side, SideType type, float xOffset, float yOffset) + public IO(CubeSide side, SideType type, float xOffset, float yOffset, string description) { this.Side = side; this.Type = type; this.XOffset = xOffset; this.YOffset = yOffset; + this.Description = description; } } @@ -50,9 +52,9 @@ public IO(CubeSide side, SideType type, float xOffset, float yOffset) public int InputCount => Sides.Count(o => o.Type == SideType.Input); public int OutputCount => Sides.Count(o => o.Type == SideType.Output); - public IOMap SetSide(CubeSide side, SideType what, float ox, float oy) + public IOMap SetSide(CubeSide side, SideType what, float ox, float oy, string description) { - Sides.Add(new IO(side, what, ox, oy)); + Sides.Add(new IO(side, what, ox, oy, description)); Changed?.Invoke(this, EventArgs.Empty); return this; diff --git a/src/Components/PrefabBuilder.cs b/src/Components/PrefabBuilder.cs index 4b8d991..8a70b85 100644 --- a/src/Components/PrefabBuilder.cs +++ b/src/Components/PrefabBuilder.cs @@ -40,36 +40,46 @@ internal CustomBuilder(Func root) State.Structure = new CustomStructureAtom(root); } - public CustomBuilder WithInput(float x, float y, float z) + public CustomBuilder WithInput(float x, float y, float z) => WithInput(x, y, z, null); + public CustomBuilder WithInput(float x, float y, float z, string description) { - return WithInput(new Vector3(x, y, z)); + return WithInput(new Vector3(x, y, z), description); } - public CustomBuilder WithInput(Vector3 position) + + public CustomBuilder WithInput(Vector3 position) => WithInput(position, null); + public CustomBuilder WithInput(Vector3 position, string description) { - State.Atoms.Add(new InputPegAtom { Position = position }); + State.Atoms.Add(new InputPegAtom { Position = position, Description = description }); return this; } - public CustomBuilder WithInput(Vector3 position, Quaternion rotation) + + public CustomBuilder WithInput(Vector3 position, Quaternion rotation) => WithInput(position, rotation, null); + public CustomBuilder WithInput(Vector3 position, Quaternion rotation, string description) { - State.Atoms.Add(new InputPegAtom { Position = position, Rotation = rotation }); + State.Atoms.Add(new InputPegAtom { Position = position, Rotation = rotation, Description = description }); return this; } - public CustomBuilder WithOutput(float x, float y, float z) + public CustomBuilder WithOutput(float x, float y, float z) => WithOutput(x, y, z, null); + public CustomBuilder WithOutput(float x, float y, float z, string description) { - return WithOutput(new Vector3(x, y, z)); + return WithOutput(new Vector3(x, y, z), description); } - public CustomBuilder WithOutput(Vector3 position) + + public CustomBuilder WithOutput(Vector3 position) => WithOutput(position, null); + public CustomBuilder WithOutput(Vector3 position, string description) { - State.Atoms.Add(new OutputAtom { Position = position }); + State.Atoms.Add(new OutputAtom { Position = position, Description = description }); return this; } - public CustomBuilder WithOutput(Vector3 position, Quaternion rotation) + + public CustomBuilder WithOutput(Vector3 position, Quaternion rotation) => WithOutput(position, rotation, null); + public CustomBuilder WithOutput(Vector3 position, Quaternion rotation, string description) { - State.Atoms.Add(new OutputAtom { Position = position, Rotation = rotation }); + State.Atoms.Add(new OutputAtom { Position = position, Rotation = rotation, Description = description }); return this; } @@ -89,15 +99,21 @@ internal CubeBuilder() public CubeBuilder WithSide(CubeSide side, SideType what) => WithIO(side, what); public CubeBuilder WithIO(CubeSide side, SideType what) + => WithIO(side, what, null); + + public CubeBuilder WithIO(CubeSide side, SideType what, string description) { - Atom.Map.SetSide(side, what, 0, 0); + Atom.Map.SetSide(side, what, 0, 0, description); return this; } public CubeBuilder WithIO(CubeSide side, SideType what, float offsetX, float offsetY) + => WithIO(side, what, offsetX, offsetY, null); + + public CubeBuilder WithIO(CubeSide side, SideType what, float offsetX, float offsetY, string description) { - Atom.Map.SetSide(side, what, offsetX, offsetY); + Atom.Map.SetSide(side, what, offsetX, offsetY, description); return this; } diff --git a/src/PiTung Bootstrap.csproj b/src/PiTung Bootstrap.csproj index 49a967f..00bd665 100644 --- a/src/PiTung Bootstrap.csproj +++ b/src/PiTung Bootstrap.csproj @@ -38,7 +38,7 @@ true bin\x64\Debug\ - TRACE;DEBUG;HEADLESS + TRACE;DEBUG full x64 prompt