| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Events; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public interface ISceneLimitsView |
| | 8 | | { |
| | 9 | | Color lfColor { get; } |
| | 10 | | Color mfColor { get; } |
| | 11 | | Color hfColor { get; } |
| | 12 | | Image[] limitUsageFillsImages { get; } |
| | 13 | |
|
| | 14 | | bool isBodyActived { get; } |
| | 15 | |
|
| | 16 | | event Action OnToggleSceneLimitsInfo; |
| | 17 | |
|
| | 18 | | void SetBodyActive(bool isActive); |
| | 19 | | void SetDetailsToggleAsClose(); |
| | 20 | | void SetDetailsToggleAsOpen(); |
| | 21 | | void SetLeftDescText(string text); |
| | 22 | | void SetRightDescText(string text); |
| | 23 | | void SetTitleText(string text); |
| | 24 | | void SetUpdateCallback(UnityAction call); |
| | 25 | | void ToggleSceneLimitsInfo(DCLAction_Trigger action); |
| | 26 | | } |
| | 27 | |
|
| | 28 | | public class SceneLimitsView : MonoBehaviour, ISceneLimitsView |
| | 29 | | { |
| | 30 | | private const int FRAMES_BETWEEN_UPDATES = 15; |
| | 31 | |
|
| 0 | 32 | | public Color lfColor => lowFillColor; |
| 0 | 33 | | public Color mfColor => mediumFillColor; |
| 0 | 34 | | public Color hfColor => highFillColor; |
| 0 | 35 | | public Image[] limitUsageFillsImages => limitUsageFillsImgs; |
| | 36 | |
|
| | 37 | | public event Action OnToggleSceneLimitsInfo; |
| | 38 | |
|
| | 39 | | [Header("Sprites")] |
| | 40 | | [SerializeField] internal Sprite openMenuSprite; |
| | 41 | | [SerializeField] internal Sprite closeMenuSprite; |
| | 42 | |
|
| | 43 | | [Header("Design")] |
| | 44 | | [SerializeField] internal Color lowFillColor; |
| | 45 | | [SerializeField] internal Color mediumFillColor; |
| | 46 | | [SerializeField] internal Color highFillColor; |
| | 47 | |
|
| | 48 | | [Header("Scene references")] |
| | 49 | | [SerializeField] internal Image detailsToggleBtn; |
| | 50 | | [SerializeField] internal GameObject sceneLimitsBodyGO; |
| | 51 | | [SerializeField] internal TextMeshProUGUI titleTxt; |
| | 52 | | [SerializeField] internal TextMeshProUGUI leftDescTxt; |
| | 53 | | [SerializeField] internal TextMeshProUGUI rightDescTxt; |
| | 54 | | [SerializeField] internal Image[] limitUsageFillsImgs; |
| | 55 | | [SerializeField] internal Button toggleButton; |
| | 56 | |
|
| | 57 | | [Header("Input Actions")] |
| | 58 | | [SerializeField] internal InputAction_Trigger toggleSceneInfoInputAction; |
| | 59 | |
|
| 0 | 60 | | public bool isBodyActived => sceneLimitsBodyGO.activeSelf; |
| | 61 | |
|
| | 62 | | private DCLAction_Trigger dummyActionTrigger = new DCLAction_Trigger(); |
| | 63 | | internal UnityAction updateInfoAction; |
| | 64 | |
|
| | 65 | | private const string VIEW_PATH = "GodMode/Inspector/SceneLimitsView"; |
| | 66 | |
|
| | 67 | | internal static SceneLimitsView Create() |
| | 68 | | { |
| 9 | 69 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<SceneLimitsView>(); |
| 9 | 70 | | view.gameObject.name = "_SceneLimitsView"; |
| | 71 | |
|
| 9 | 72 | | return view; |
| | 73 | | } |
| | 74 | |
|
| | 75 | | private void Awake() |
| | 76 | | { |
| 17 | 77 | | toggleSceneInfoInputAction.OnTriggered += ToggleSceneLimitsInfo; |
| 17 | 78 | | toggleButton.onClick.AddListener(() => ToggleSceneLimitsInfo(dummyActionTrigger)); |
| 17 | 79 | | } |
| | 80 | |
|
| | 81 | | private void Update() |
| | 82 | | { |
| 0 | 83 | | if (Time.frameCount % FRAMES_BETWEEN_UPDATES == 0) |
| 0 | 84 | | updateInfoAction(); |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | private void OnDestroy() |
| | 88 | | { |
| 17 | 89 | | toggleSceneInfoInputAction.OnTriggered -= ToggleSceneLimitsInfo; |
| 17 | 90 | | toggleButton.onClick.RemoveAllListeners(); |
| 17 | 91 | | } |
| | 92 | |
|
| 0 | 93 | | public void SetUpdateCallback(UnityAction call) { updateInfoAction = call; } |
| | 94 | |
|
| 2 | 95 | | public void ToggleSceneLimitsInfo(DCLAction_Trigger action) { OnToggleSceneLimitsInfo?.Invoke(); } |
| | 96 | |
|
| 4 | 97 | | public void SetBodyActive(bool isActive) { sceneLimitsBodyGO.SetActive(isActive); } |
| | 98 | |
|
| 2 | 99 | | public void SetDetailsToggleAsOpen() { detailsToggleBtn.sprite = openMenuSprite; } |
| | 100 | |
|
| 2 | 101 | | public void SetDetailsToggleAsClose() { detailsToggleBtn.sprite = closeMenuSprite; } |
| | 102 | |
|
| 2 | 103 | | public void SetTitleText(string text) { titleTxt.text = text; } |
| | 104 | |
|
| 2 | 105 | | public void SetLeftDescText(string text) { leftDescTxt.text = text; } |
| | 106 | |
|
| 2 | 107 | | public void SetRightDescText(string text) { rightDescTxt.text = text; } |
| | 108 | | } |