Skip to content

Commit

Permalink
Added tooltips to inputs and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jul 17, 2018
1 parent 97d2567 commit 2443d4f
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 43 deletions.
5 changes: 3 additions & 2 deletions src/Components/Atoms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal abstract class IOAtom : IAtom
{
public Vector3 Position;
public Quaternion Rotation;
public string Description;

public abstract void AddToGameObject(GameObject obj);
}
Expand All @@ -22,15 +23,15 @@ 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;
}
}

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

Expand Down
13 changes: 8 additions & 5 deletions src/Components/BuilderUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOInfo>().Index = item.Type == SideType.Input ? i++ : j++;
var io = AddIO(prefabRoot, item.Type, item.Side, item.XOffset, item.YOffset, item.Description);
io.GetComponent<IOInfo>().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;
Expand Down Expand Up @@ -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<IOInfo>().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);
Expand All @@ -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<IOInfo>().Description = description;
Peg.transform.localScale = new Vector3(PegScale.x * 0.3f, PegScale.y * 0.3f, PegScale.z * 0.3f);
Peg.transform.parent = parent.transform;

Expand All @@ -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<IOInfo>().Description = description;
Peg.transform.localScale = new Vector3(OutputScale.x * 0.3f, OutputScale.y * 0.3f, OutputScale.z * 0.3f);
Peg.transform.parent = parent.transform;

Expand Down
56 changes: 38 additions & 18 deletions src/Components/ComponentPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -88,7 +88,7 @@ static IEnumerable<KeyValuePair<string, object>> GetFieldsAndProperties(object o
}
}
}

[HarmonyPatch(typeof(SavedObjectUtilities), "CreateSavedObjectFrom", new Type[] { typeof(ObjectInfo) })]
internal static class CreateSavedObjectFromPatch
{
Expand All @@ -113,7 +113,7 @@ static bool Prefix(ref SavedObjectV2 __result, ObjectInfo worldsave)
return true;
}
}

[HarmonyPatch(typeof(SavedObjectUtilities), "GetCustomPrefab")]
internal static class GetCustomPrefabPatch
{
Expand All @@ -125,7 +125,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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)
{
Expand Down Expand Up @@ -265,7 +265,7 @@ static bool Prefix(ObjectInfo __instance)
return true;
}
}


[HarmonyPatch(typeof(ComponentPlacer), "MakeSureThingBeingPlacedIsCorrect")]
internal static class asdasd
Expand Down Expand Up @@ -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<ObjectInfo>() ??
hit.transform.parent?.GetComponent<ObjectInfo>();
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<UpdateHandler>() ??
hit.transform.GetComponentInChildren<UpdateHandler>();
var ioInfo = hit.transform.GetComponent<IOInfo>();

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 = $"<b>{(input ? "Input" : "Output")}</b>: {ioInfo.Description}";
}
}
else
{
var info = hit.transform.GetComponent<ObjectInfo>() ??
hit.transform.parent?.GetComponent<ObjectInfo>();

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<UpdateHandler>() ??
hit.transform.GetComponentInChildren<UpdateHandler>();

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);
}
}
}
}
1 change: 1 addition & 0 deletions src/Components/IOInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ namespace PiTung.Components
internal class IOInfo : MonoBehaviour
{
public int Index { get; set; }
public string Description { get; set; }
}
}
8 changes: 5 additions & 3 deletions src/Components/IOMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand Down
44 changes: 30 additions & 14 deletions src/Components/PrefabBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,46 @@ internal CustomBuilder(Func<GameObject> 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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PiTung Bootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;HEADLESS</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand Down

0 comments on commit 2443d4f

Please sign in to comment.