Skip to content

Commit 2443d4f

Browse files
committed
Added tooltips to inputs and outputs
1 parent 97d2567 commit 2443d4f

File tree

7 files changed

+86
-43
lines changed

7 files changed

+86
-43
lines changed

src/Components/Atoms.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal abstract class IOAtom : IAtom
1414
{
1515
public Vector3 Position;
1616
public Quaternion Rotation;
17+
public string Description;
1718

1819
public abstract void AddToGameObject(GameObject obj);
1920
}
@@ -22,15 +23,15 @@ internal sealed class InputPegAtom : IOAtom
2223
{
2324
public override void AddToGameObject(GameObject obj)
2425
{
25-
BuilderUtils.AddInputPeg(obj, this.Position).transform.localRotation = this.Rotation;
26+
BuilderUtils.AddInputPeg(obj, this.Position, Description).transform.localRotation = this.Rotation;
2627
}
2728
}
2829

2930
internal sealed class OutputAtom : IOAtom
3031
{
3132
public override void AddToGameObject(GameObject obj)
3233
{
33-
BuilderUtils.AddOutputPeg(obj, this.Position).transform.localRotation = this.Rotation;
34+
BuilderUtils.AddOutputPeg(obj, this.Position, Description).transform.localRotation = this.Rotation;
3435
}
3536
}
3637

src/Components/BuilderUtils.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public static void ApplyIOMap(GameObject prefabRoot, IOMap map)
1414
int i = 0, j = 0;
1515
foreach (var item in map.Sides)
1616
{
17-
var io = AddIO(prefabRoot, item.Type, item.Side, item.XOffset, item.YOffset);
18-
io.AddComponent<IOInfo>().Index = item.Type == SideType.Input ? i++ : j++;
17+
var io = AddIO(prefabRoot, item.Type, item.Side, item.XOffset, item.YOffset, item.Description);
18+
io.GetComponent<IOInfo>().Index = item.Type == SideType.Input ? i++ : j++;
1919
}
2020
}
2121

22-
public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, float ox, float oy)
22+
public static GameObject AddIO(GameObject parent, SideType type, CubeSide side, float ox, float oy, string description)
2323
{
2424
if (type == SideType.None)
2525
return null;
@@ -63,6 +63,7 @@ public static GameObject AddIO(GameObject parent, SideType type, CubeSide side,
6363

6464
var prefab = type == SideType.Input ? Prefabs.Peg : Prefabs.Output;
6565
GameObject Peg = GameObject.Instantiate(prefab, parent.transform);
66+
Peg.AddComponent<IOInfo>().Description = description;
6667
Peg.transform.localPosition = new Vector3(x, y, z);
6768
Peg.transform.localScale = type == SideType.Input ? PegScale : OutputScale;
6869
Peg.transform.localEulerAngles = new Vector3(rotX, rotY, rotZ);
@@ -77,10 +78,11 @@ public static GameObject AddIO(GameObject parent, SideType type, CubeSide side,
7778
return Peg;
7879
}
7980

80-
public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition = null)
81+
public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition = null, string description = null)
8182
{
8283
var Peg = GameObject.Instantiate(Prefabs.Peg);
8384

85+
Peg.AddComponent<IOInfo>().Description = description;
8486
Peg.transform.localScale = new Vector3(PegScale.x * 0.3f, PegScale.y * 0.3f, PegScale.z * 0.3f);
8587
Peg.transform.parent = parent.transform;
8688

@@ -90,10 +92,11 @@ public static GameObject AddInputPeg(GameObject parent, Vector3? localPosition =
9092
return Peg;
9193
}
9294

93-
public static GameObject AddOutputPeg(GameObject parent, Vector3? localPosition = null)
95+
public static GameObject AddOutputPeg(GameObject parent, Vector3? localPosition = null, string description = null)
9496
{
9597
var Peg = GameObject.Instantiate(Prefabs.Output);
9698

99+
Peg.AddComponent<IOInfo>().Description = description;
97100
Peg.transform.localScale = new Vector3(OutputScale.x * 0.3f, OutputScale.y * 0.3f, OutputScale.z * 0.3f);
98101
Peg.transform.parent = parent.transform;
99102

src/Components/ComponentPatches.cs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void Prefix(SavedCustomObject save, ObjectInfo CreateFromThis)
5252
return;
5353
}
5454
}
55-
55+
5656
saveData.Add(customComponent.ComponentName);
5757
saveData.Add(outputs.Select(o => o.On).ToArray());
5858
saveData.AddRange(GetSaveThisFields(customComponent));
@@ -88,7 +88,7 @@ static IEnumerable<KeyValuePair<string, object>> GetFieldsAndProperties(object o
8888
}
8989
}
9090
}
91-
91+
9292
[HarmonyPatch(typeof(SavedObjectUtilities), "CreateSavedObjectFrom", new Type[] { typeof(ObjectInfo) })]
9393
internal static class CreateSavedObjectFromPatch
9494
{
@@ -113,7 +113,7 @@ static bool Prefix(ref SavedObjectV2 __result, ObjectInfo worldsave)
113113
return true;
114114
}
115115
}
116-
116+
117117
[HarmonyPatch(typeof(SavedObjectUtilities), "GetCustomPrefab")]
118118
internal static class GetCustomPrefabPatch
119119
{
@@ -125,7 +125,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
125125
yield return new CodeInstruction(OpCodes.Ret);
126126
}
127127

128-
static void Postfix(ref GameObject __result, SavedCustomObject save)
128+
static void Postfix(ref GameObject __result, SavedCustomObject save)
129129
{
130130
if (save.CustomData.Length == 0)
131131
{
@@ -265,7 +265,7 @@ static bool Prefix(ObjectInfo __instance)
265265
return true;
266266
}
267267
}
268-
268+
269269

270270
[HarmonyPatch(typeof(ComponentPlacer), "MakeSureThingBeingPlacedIsCorrect")]
271271
internal static class asdasd
@@ -322,30 +322,50 @@ static void Postfix()
322322
if (ModUtilities.IsOnMainMenu || !ShouldShow)
323323
return;
324324

325+
string str = null;
326+
325327
if (Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, 20))
326328
{
327-
var info = hit.transform.GetComponent<ObjectInfo>() ??
328-
hit.transform.parent?.GetComponent<ObjectInfo>();
329+
bool input = hit.transform.tag == "Input";
330+
bool output = hit.transform.tag == "Output";
329331

330-
if (info != null && info.ComponentType == ComponentType.CustomObject)
332+
if (input || output)
331333
{
332-
var handler = hit.transform.GetComponent<UpdateHandler>() ??
333-
hit.transform.GetComponentInChildren<UpdateHandler>();
334+
var ioInfo = hit.transform.GetComponent<IOInfo>();
334335

335-
if (handler != null)
336+
if (ioInfo?.Description != null)
336337
{
337-
string str = handler.Component?.DisplayName ?? handler.ComponentName;
338-
339-
var size = GUI.skin.box.CalcSize(new GUIContent(str));
340-
size.x += 10;
341-
size.y += 10;
338+
str = $"<b>{(input ? "Input" : "Output")}</b>: {ioInfo.Description}";
339+
}
340+
}
341+
else
342+
{
343+
var info = hit.transform.GetComponent<ObjectInfo>() ??
344+
hit.transform.parent?.GetComponent<ObjectInfo>();
342345

343-
var rect = new Rect(Screen.width / 2 - size.x / 2, 10, size.x, size.y);
346+
if (info?.ComponentType == ComponentType.CustomObject)
347+
{
348+
var handler = hit.transform.GetComponent<UpdateHandler>() ??
349+
hit.transform.GetComponentInChildren<UpdateHandler>();
344350

345-
GUI.Box(rect, str, Style);
351+
if (handler != null)
352+
{
353+
str = handler.Component?.DisplayName ?? handler.ComponentName;
354+
}
346355
}
347356
}
348357
}
358+
359+
if (str != null)
360+
{
361+
var size = GUI.skin.box.CalcSize(new GUIContent(str));
362+
size.x += 10;
363+
size.y += 10;
364+
365+
var rect = new Rect(Screen.width / 2 - size.x / 2, 10, size.x, size.y);
366+
367+
GUI.Box(rect, str, Style);
368+
}
349369
}
350370
}
351371
}

src/Components/IOInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ namespace PiTung.Components
99
internal class IOInfo : MonoBehaviour
1010
{
1111
public int Index { get; set; }
12+
public string Description { get; set; }
1213
}
1314
}

src/Components/IOMap.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ public struct IO
3434
public SideType Type;
3535
public float XOffset;
3636
public float YOffset;
37+
public string Description;
3738

38-
public IO(CubeSide side, SideType type, float xOffset, float yOffset)
39+
public IO(CubeSide side, SideType type, float xOffset, float yOffset, string description)
3940
{
4041
this.Side = side;
4142
this.Type = type;
4243
this.XOffset = xOffset;
4344
this.YOffset = yOffset;
45+
this.Description = description;
4446
}
4547
}
4648

@@ -50,9 +52,9 @@ public IO(CubeSide side, SideType type, float xOffset, float yOffset)
5052
public int InputCount => Sides.Count(o => o.Type == SideType.Input);
5153
public int OutputCount => Sides.Count(o => o.Type == SideType.Output);
5254

53-
public IOMap SetSide(CubeSide side, SideType what, float ox, float oy)
55+
public IOMap SetSide(CubeSide side, SideType what, float ox, float oy, string description)
5456
{
55-
Sides.Add(new IO(side, what, ox, oy));
57+
Sides.Add(new IO(side, what, ox, oy, description));
5658
Changed?.Invoke(this, EventArgs.Empty);
5759

5860
return this;

src/Components/PrefabBuilder.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,46 @@ internal CustomBuilder(Func<GameObject> root)
4040
State.Structure = new CustomStructureAtom(root);
4141
}
4242

43-
public CustomBuilder WithInput(float x, float y, float z)
43+
public CustomBuilder WithInput(float x, float y, float z) => WithInput(x, y, z, null);
44+
public CustomBuilder WithInput(float x, float y, float z, string description)
4445
{
45-
return WithInput(new Vector3(x, y, z));
46+
return WithInput(new Vector3(x, y, z), description);
4647
}
47-
public CustomBuilder WithInput(Vector3 position)
48+
49+
public CustomBuilder WithInput(Vector3 position) => WithInput(position, null);
50+
public CustomBuilder WithInput(Vector3 position, string description)
4851
{
49-
State.Atoms.Add(new InputPegAtom { Position = position });
52+
State.Atoms.Add(new InputPegAtom { Position = position, Description = description });
5053

5154
return this;
5255
}
53-
public CustomBuilder WithInput(Vector3 position, Quaternion rotation)
56+
57+
public CustomBuilder WithInput(Vector3 position, Quaternion rotation) => WithInput(position, rotation, null);
58+
public CustomBuilder WithInput(Vector3 position, Quaternion rotation, string description)
5459
{
55-
State.Atoms.Add(new InputPegAtom { Position = position, Rotation = rotation });
60+
State.Atoms.Add(new InputPegAtom { Position = position, Rotation = rotation, Description = description });
5661

5762
return this;
5863
}
5964

60-
public CustomBuilder WithOutput(float x, float y, float z)
65+
public CustomBuilder WithOutput(float x, float y, float z) => WithOutput(x, y, z, null);
66+
public CustomBuilder WithOutput(float x, float y, float z, string description)
6167
{
62-
return WithOutput(new Vector3(x, y, z));
68+
return WithOutput(new Vector3(x, y, z), description);
6369
}
64-
public CustomBuilder WithOutput(Vector3 position)
70+
71+
public CustomBuilder WithOutput(Vector3 position) => WithOutput(position, null);
72+
public CustomBuilder WithOutput(Vector3 position, string description)
6573
{
66-
State.Atoms.Add(new OutputAtom { Position = position });
74+
State.Atoms.Add(new OutputAtom { Position = position, Description = description });
6775

6876
return this;
6977
}
70-
public CustomBuilder WithOutput(Vector3 position, Quaternion rotation)
78+
79+
public CustomBuilder WithOutput(Vector3 position, Quaternion rotation) => WithOutput(position, rotation, null);
80+
public CustomBuilder WithOutput(Vector3 position, Quaternion rotation, string description)
7181
{
72-
State.Atoms.Add(new OutputAtom { Position = position, Rotation = rotation });
82+
State.Atoms.Add(new OutputAtom { Position = position, Rotation = rotation, Description = description });
7383

7484
return this;
7585
}
@@ -89,15 +99,21 @@ internal CubeBuilder()
8999
public CubeBuilder WithSide(CubeSide side, SideType what) => WithIO(side, what);
90100

91101
public CubeBuilder WithIO(CubeSide side, SideType what)
102+
=> WithIO(side, what, null);
103+
104+
public CubeBuilder WithIO(CubeSide side, SideType what, string description)
92105
{
93-
Atom.Map.SetSide(side, what, 0, 0);
106+
Atom.Map.SetSide(side, what, 0, 0, description);
94107

95108
return this;
96109
}
97110

98111
public CubeBuilder WithIO(CubeSide side, SideType what, float offsetX, float offsetY)
112+
=> WithIO(side, what, offsetX, offsetY, null);
113+
114+
public CubeBuilder WithIO(CubeSide side, SideType what, float offsetX, float offsetY, string description)
99115
{
100-
Atom.Map.SetSide(side, what, offsetX, offsetY);
116+
Atom.Map.SetSide(side, what, offsetX, offsetY, description);
101117

102118
return this;
103119
}

src/PiTung Bootstrap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
3939
<DebugSymbols>true</DebugSymbols>
4040
<OutputPath>bin\x64\Debug\</OutputPath>
41-
<DefineConstants>TRACE;DEBUG;HEADLESS</DefineConstants>
41+
<DefineConstants>TRACE;DEBUG</DefineConstants>
4242
<DebugType>full</DebugType>
4343
<PlatformTarget>x64</PlatformTarget>
4444
<ErrorReport>prompt</ErrorReport>

0 commit comments

Comments
 (0)