Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input): add interaction to production terminal #105

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading