-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(input): add interaction to production terminal (#105)
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
plugin/src/input/ui/machine/ProductionTerminalInteractableUi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters