Skip to content

Commit

Permalink
feat(input): add interaction to production terminal (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Jan 27, 2024
1 parent 4c867f5 commit b24b093
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin/src/MainGamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void Start()
new IaCMenuPatch(),
new SaveNotificationPatch(),
new HudPatch(),
new ProductionTerminalPatch(),
]).ToArray();

Logger.LogDebug("Hello World!");
Expand Down
52 changes: 52 additions & 0 deletions plugin/src/input/ui/machine/ProductionTerminalInteractableUi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Linq;
using TechtonicaVR.Util;
using UnityEngine;

namespace TechtonicaVR.Input.Ui.Machine;

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

public ProductionTerminalInteractableUi(GameObject gameObject) : base(gameObject)
{
zIndex = 0.001f;

interactable = gameObject.GetComponentsInChildren<InventoryResourceSlotUI>().Select(getInteractable).ToList();

var upgradeButton = gameObject.GetComponentInChildren<ProductionTerminalUpgradeButton>();
var upgradeButtonInteractable = new InteractableBuilder(this, getRect(upgradeButton.GetComponent<RectTransform>()), upgradeButton.gameObject)
.withClick((ui) => onClick(upgradeButton), () => upgradeButton.canUpgrade)
.withHoverEnter((ui) => upgradeButton.mouseEnterCallback?.Invoke())
.withHoverExit((ui) => upgradeButton.mouseExitCallback?.Invoke())
.build();
interactable.Add(upgradeButtonInteractable);
}


protected override void init()
{
}

private Interactable getInteractable(InventoryResourceSlotUI slot)
{
var rectTransform = slot.GetComponent<RectTransform>();
var rect = getRect(rectTransform);
Logger.LogDebug($"Slot rect: {slot} {rect} {rectTransform.localPosition}");

return new InteractableBuilder(this, rect, rectTransform.gameObject)
.withRecalculate(() => getRect(rectTransform))
.withDrag(() => draggedResourceInfo ?? slot.resourceType,
(ui) => onDrag(slot),
(ui, source, target) => onDrop(ui, target, slot),
(ui) => onCancelDrag(slot))
.withDrop(onAcceptsDrop, (ui, source) => onReceiveDrop(source, slot))
.withHoverEnter((ui) => onHoverEnter(slot))
.withHoverExit((ui) => onHoverExit(slot))
.build();
}
private void onClick(ProductionTerminalUpgradeButton upgradeButton)
{
upgradeButton.mouseLeftClickCallback?.Invoke();
}
}
18 changes: 18 additions & 0 deletions plugin/src/patch/main_game/ui/ProductionTerminalPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;

namespace TechtonicaVR.Patches.MainGame.UI;

public class ProductionTerminalPatch : GameComponentPatch<ProductionTerminalMenu>
{
protected override bool Apply(ProductionTerminalMenu component)
{
var tlc = component.transform.GetChild(0);
if (tlc == null)
{
return false;
}

tlc.localPosition = Vector3.zero;
return true;
}
}
8 changes: 8 additions & 0 deletions plugin/src/ui/patch/UiMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ private static void addInteractableUi(UIMenu instance)
menu = new UIMenuWrapper(instance)
};
}
else if (instance is ProductionTerminalMenu)
{
var container = GameObjectFinder.FindChildObjectByName("Container", instance.gameObject);
new ProductionTerminalInteractableUi(container)
{
menu = new UIMenuWrapper(instance)
};
}
}

private static void disableButtonPrompts(UIMenu __instance)
Expand Down

0 comments on commit b24b093

Please sign in to comment.