Skip to content

Commit

Permalink
feat(input): add interaction to blast smelter menu (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira authored Mar 13, 2024
1 parent b805334 commit 441cd8f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugin/src/input/ui/machine/BlastSmelterInteractableUi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using PiUtils.Util;
using UnityEngine;

namespace TechtonicaVR.Input.Ui.Machine;

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

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

getInteractables = () => gameObject.GetComponentsInChildren<InventoryResourceSlotUI>().Select((slot) => getInteractable(slot)).ToList();
Logger.LogDebug($"Interactable: {rectTransform.rect}");
}

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();
}
}
8 changes: 8 additions & 0 deletions plugin/src/ui/patch/UiMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ private static void addInteractableUi(UIMenu instance)
menu = new UIMenuWrapper(instance)
};
}
else if (instance is BlastSmelterUI)
{
var container = GameObjectFinder.FindChildObjectByName("Container", instance.gameObject);
new BlastSmelterInteractableUi(container)
{
menu = new UIMenuWrapper(instance)
};
}
}

private static void disableButtonPrompts(UIMenu __instance)
Expand Down

0 comments on commit 441cd8f

Please sign in to comment.