Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(input): add interaction to resource gate (#104)
- Loading branch information
Showing
7 changed files
with
75 additions
and
12 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
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
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
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
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 ResourceGateInteractableUi : InventoryInteractableUI | ||
| { | ||
| private static PluginLogger Logger = PluginLogger.GetLogger<ResourceGateInteractableUi>(); | ||
|
|
||
| public ResourceGateInteractableUi(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
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