Context Menus & Progress Bars
We now have a context menu UI for in-game actions, right click on an item to activate Database view has a progress bar (finally!) Data structures for Megacorps and loadouts Towing task complete? needs testing
This commit is contained in:
parent
ab8aa5fb9a
commit
c24c155673
93 changed files with 1410 additions and 324 deletions
47
Assets/Scripts/UI/ContextMenu.cs
Normal file
47
Assets/Scripts/UI/ContextMenu.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ContextMenu : MonoBehaviour
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public RectTransform OptionPrefab;
|
||||
|
||||
public RectTransform ContentRoot;
|
||||
|
||||
public float OptionHeight;
|
||||
public float PaddingHeight;
|
||||
|
||||
private List<GameObject> _options = new List<GameObject>();
|
||||
|
||||
public void SetOptions(IEnumerable<(string text, Action action)> options)
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
var pivot = rect.pivot;
|
||||
pivot.x = Input.mousePosition.x > Screen.width - rect.sizeDelta.x * Canvas.scaleFactor ? 1 : 0;
|
||||
pivot.y = Input.mousePosition.y < (PaddingHeight + options.Count() * OptionHeight) * Canvas.scaleFactor ? 0 : 1;
|
||||
rect.pivot = pivot;
|
||||
rect.position = Input.mousePosition;
|
||||
|
||||
// Destroy previous options
|
||||
foreach(var option in _options)
|
||||
Destroy(option);
|
||||
_options.Clear();
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.GetComponentInChildren<TextMeshProUGUI>().text = option.text;
|
||||
optionButton.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
option.action();
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue