Skip to content

Commit

Permalink
feat(input): add interaction to power generator (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Jan 23, 2024
1 parent b9e9605 commit 0c0b978
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plugin/src/input/ui/machine/PowerGeneratorInteractableUi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using TechtonicaVR.Util;
using UnityEngine;

namespace TechtonicaVR.Input.Ui.Machine;

public class PowerGeneratorInteractableUi : InteractableUi
{
private static PluginLogger Logger = PluginLogger.GetLogger<PowerGeneratorInteractableUi>();

private GeneratorUI generator;
public PowerGeneratorInteractableUi(GameObject gameObject) : base(gameObject)
{
generator = gameObject.GetComponentInParent<GeneratorUI>();

var button = GameObjectFinder.FindChildObjectByName("Controller Activate Crank CG", gameObject);
var rectTransform = button.GetComponent<RectTransform>();
var rect = rectTransform.rect;

Logger.LogDebug($"Button rect: {rect} {rectTransform.localPosition}");
rect.x += rectTransform.localPosition.x;
rect.y = 260; // TODO: Find a way to get this value dynamically

interactable = [
new InteractableBuilder(this, rect, button)
.withClick((ui) => onClick())
.build()
];
}

private void onClick()
{
generator.ActivateCrankOnClick();
}
}
14 changes: 14 additions & 0 deletions plugin/src/ui/patch/UiMenuPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using TechtonicaVR.Debug;
using TechtonicaVR.Input.Ui.Machine;
using TechtonicaVR.Util;
using TechtonicaVR.VRCamera;
using UnityEngine;
Expand Down Expand Up @@ -46,9 +47,22 @@ public static void StartPostfix(UIMenu __instance)
canvas.transform.localScale = ModConfig.menuScale.Value;
}

addInteractableUi(__instance);
disableButtonPrompts(__instance);
}

private static void addInteractableUi(UIMenu instance)
{
if (instance is GeneratorUI)
{
var container = GameObjectFinder.FindChildObjectByName("Content Container", instance.gameObject);
new PowerGeneratorInteractableUi(container)
{
menu = new UIMenuWrapper(instance)
};
}
}

private static void disableButtonPrompts(UIMenu __instance)
{
var mkbButtonPrompts = __instance.gameObject.GetComponentsInChildren<MKBInventoryButtonPrompts>();
Expand Down

0 comments on commit 0c0b978

Please sign in to comment.