pr coments implementation

This commit is contained in:
Hubert Mattusch 2023-02-06 19:20:01 +01:00
parent 829de37cd6
commit 2fe84c5c0b
9 changed files with 39 additions and 20 deletions

View File

@ -20,7 +20,7 @@ namespace NEG.UI.Popup
/// <summary> /// <summary>
/// Close popup or mark as closed if not visible /// Close popup or mark as closed if not visible
/// </summary> /// </summary>
/// <param name="silence">if true hide visually, without firing callbacks to properly close</param> /// <param name="silent">if true hide visually, without firing callbacks to properly close</param>
void Close(bool silence = false); void Close(bool silent = false);
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using UnityEngine;
namespace NEG.UI.UnityUi.Buttons
{
[RequireComponent(typeof(BaseButton))]
public abstract class ButtonReaction : MonoBehaviour
{
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
private void OnDestroy() => GetComponent<BaseButton>().OnButtonPressed -= OnClicked;
protected abstract void OnClicked();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a9761128a04b49c2a26eddfabe70331f
timeCreated: 1675707257

View File

@ -1,3 +1,4 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -6,16 +7,14 @@ using UnityEngine.SceneManagement;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class ChangeSceneButton : MonoBehaviour public class ChangeSceneButton : ButtonReaction
{ {
[Header("Leave empty to use int value")] [Header("Leave empty to use int value")]
[SerializeField] private string sceneName; [SerializeField] private string sceneName;
[SerializeField] private int sceneIndex; [SerializeField] private int sceneIndex;
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
private void OnClicked() protected override void OnClicked()
{ {
if (string.IsNullOrEmpty(sceneName)) if (string.IsNullOrEmpty(sceneName))
SceneManager.LoadScene(sceneIndex); SceneManager.LoadScene(sceneIndex);

View File

@ -2,10 +2,8 @@
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons
{ {
[RequireComponent(typeof(BaseButton))] public class CloseAllWindows : ButtonReaction
public class CloseAllWindows : MonoBehaviour
{ {
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked; protected override void OnClicked() => UiManager.Instance.CurrentArea.CloseAllWindows();
private void OnClicked() => UiManager.Instance.CurrentArea.CloseAllWindows();
} }
} }

View File

@ -6,12 +6,11 @@ using UnityEngine;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class CloseWindow : MonoBehaviour public class CloseWindow : ButtonReaction
{ {
[SerializeField] private MonoWindow windowToClose; [SerializeField] private MonoWindow windowToClose;
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked; protected override void OnClicked() => windowToClose.Close();
private void OnClicked() => windowToClose.Close();
private void OnValidate() private void OnValidate()
{ {

View File

@ -8,14 +8,12 @@ using NEG.UI.WindowSlot;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class OpenWindow : MonoBehaviour public class OpenWindow : ButtonReaction
{ {
[SerializeField] private MonoWindow window; [SerializeField] private MonoWindow window;
[Header("Open on default area slot if empty")] [Header("Open on default area slot if empty")]
[SerializeField] private MonoWindowSlot slot; [SerializeField] private MonoWindowSlot slot;
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
private void OnClicked() => window.Open(slot); protected override void OnClicked() => window.Open(slot);
} }
} }

View File

@ -1,5 +1,6 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using NEG.UI.UnityUi.Buttons; using NEG.UI.UnityUi.Buttons;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@ -83,6 +84,12 @@ namespace NEG.UI.UnityUi
prevButton.OnButtonPressed += SelectPrevOption; prevButton.OnButtonPressed += SelectPrevOption;
} }
private void OnDestroy()
{
nextButton.OnButtonPressed -= SelectNextOption;
prevButton.OnButtonPressed -= SelectPrevOption;
}
private void ChangeOption(bool next) => SelectOption((CurrentOptionId + (next ? 1 : -1) + options.Count) % options.Count); private void ChangeOption(bool next) => SelectOption((CurrentOptionId + (next ? 1 : -1) + options.Count) % options.Count);
} }
} }

View File

@ -16,11 +16,11 @@ namespace NEG.UI.UnityUi.Popup
gameObject.SetActive(true); gameObject.SetActive(true);
} }
public void Close(bool silence = false) public void Close(bool silent = false)
{ {
gameObject.SetActive(false); gameObject.SetActive(false);
if(silence) if(silent)
return; return;
OnPopupClosed?.Invoke(data); OnPopupClosed?.Invoke(data);