popup menu refactor, player class refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -9,47 +9,47 @@ public class RadialMenuItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Button _radialMenuItemPrefab;
|
||||
private Action<RadialMenuActions> _menuButtonClick=null;
|
||||
private Dictionary<RadialMenuActions, RadialMenuActionDescription> _actions;
|
||||
TaskCompletionSource<RadialMenuActions> tcs = new TaskCompletionSource<RadialMenuActions>();
|
||||
|
||||
public void ShowButtons(RadialMenuItem popupMenu, Dictionary<RadialMenuActions, RadialMenuActionDescription> actions, Action<RadialMenuActions> menuButtonClick)
|
||||
|
||||
public Task<RadialMenuActions> ShowButtons(RadialMenuItem popupMenu, Dictionary<RadialMenuActions, RadialMenuActionDescription> actions)
|
||||
{
|
||||
|
||||
_actions = actions;
|
||||
_menuButtonClick = menuButtonClick;
|
||||
for (int buttonsCount = 0; buttonsCount < actions.Count; buttonsCount++)
|
||||
{
|
||||
var button = Instantiate(_radialMenuItemPrefab);
|
||||
button.transform.SetParent(transform, false);
|
||||
|
||||
float theta = (2 * Mathf.PI / actions.Count) * buttonsCount;
|
||||
float posX=Mathf.Sin(theta);
|
||||
float posY=Mathf.Cos(theta);
|
||||
float posX = Mathf.Sin(theta);
|
||||
float posY = Mathf.Cos(theta);
|
||||
|
||||
button.transform.localPosition = new Vector3(posX, posY, 0)*100f;
|
||||
button.transform.localPosition = new Vector3(posX, posY, 0) * 100f;
|
||||
var textMeshPro = button.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (textMeshPro != null)
|
||||
{
|
||||
textMeshPro.text = actions.ElementAt(buttonsCount).Value.Description;
|
||||
}
|
||||
|
||||
AddEvent(button, buttonsCount);
|
||||
|
||||
}
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
|
||||
void AddEvent(Button b, int buttonNumber)
|
||||
{
|
||||
b.onClick.AddListener(() =>
|
||||
{
|
||||
tcs.SetResult(_actions.ElementAt(buttonNumber).Key);
|
||||
Close();
|
||||
_menuButtonClick?.Invoke(_actions.ElementAt(buttonNumber).Key);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void CancelAndClose()
|
||||
{
|
||||
Close();
|
||||
_menuButtonClick?.Invoke(RadialMenuActions.Cancel);
|
||||
}
|
||||
|
||||
private void Close()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class UISystem : MonoBehaviour
|
||||
@@ -32,12 +33,12 @@ public class UISystem : MonoBehaviour
|
||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowItemPopupMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions,Action<RadialMenuActions> itemsMenuCallback)
|
||||
public async Task<RadialMenuActions> ShowItemPopupMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions)
|
||||
{
|
||||
_popupMenu = Instantiate(_radialMenuItemPrefab);
|
||||
_popupMenu.transform.transform.SetParent(transform, false);
|
||||
_popupMenu.transform.position = Input.mousePosition;
|
||||
_popupMenu.ShowButtons(_popupMenu, actions,itemsMenuCallback);
|
||||
return await _popupMenu.ShowButtons(_popupMenu, actions);
|
||||
}
|
||||
|
||||
public void ClosePopupMenu()
|
||||
|
||||
Reference in New Issue
Block a user