This commit is contained in:
Hubert Mattusch 2024-03-03 15:38:40 +01:00
parent 20e281f9dd
commit 85dee79cc8
26 changed files with 34 additions and 120 deletions

View File

@ -1,5 +1,5 @@
using KBCore.Refs; using KBCore.Refs;
using NEG.UI.UnityUi.Buttons.Reaction; using NEG.UI.UnityUi.Buttons.Behaviours;
using NEG.UI.UnityUi.Buttons.Settings; using NEG.UI.UnityUi.Buttons.Settings;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -43,7 +43,11 @@ namespace NEG.UI.UnityUi.Buttons
private void Start() => OnDeselect(null); private void Start() => OnDeselect(null);
private void OnValidate() => this.ValidateRefs(); private void OnValidate()
{
this.ValidateRefs();
text.text = gameObject.name;
}
public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData); public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData);

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 953c3353e3af44258625fe607ede632b
timeCreated: 1683915598

View File

@ -1,21 +0,0 @@
using NEG.UI.UnityUi.Buttons.Settings;
using System;
namespace NEG.UI.UnityUi.Buttons.Reaction
{
public abstract class ButtonElementBehaviour : IDisposable
{
protected readonly BaseButton button;
protected SettingData baseData;
public ButtonElementBehaviour(BaseButton baseButton, SettingData settingData)
{
button = baseButton;
baseData = settingData;
}
public abstract void Dispose();
public virtual void ChangeData(SettingData newData) => baseData = newData;
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a5e3decad6424cb288eff3e6f7e0d28e
timeCreated: 1683919740

View File

@ -1,41 +0,0 @@
using NEG.UI.UnityUi.Buttons.Settings;
using NEG.Utils;
using UnityEngine;
namespace NEG.UI.UnityUi.Buttons.Reaction
{
public class ChangeTextColorBehaviour : ButtonElementBehaviour
{
private ColorData data;
public ChangeTextColorBehaviour(BaseButton baseButton, ColorData data) : base(baseButton, data)
{
if (baseButton.Text == null)
return;
baseButton.OnSelected += OnButtonSelected;
baseButton.OnDeselected += OnButtonDeselected;
ChangeData(data);
}
public override void ChangeData(SettingData newData)
{
base.ChangeData(newData);
Debug.Assert(newData is ColorData, "newData is not ColorData");
data = (ColorData)newData;
}
public override void Dispose()
{
button.OnSelected -= OnButtonSelected;
button.OnDeselected -= OnButtonDeselected;
}
[FactoryRegistration]
private static void RegisterInFactory() =>
MonoUiManager.Instance.BehavioursFactory.Register("ChangeTextColor", typeof(ChangeTextColorBehaviour));
private void OnButtonSelected(bool _) => button.Text.color = data.SelectedColor;
private void OnButtonDeselected(bool _) => button.Text.color = data.DeselectedColor;
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f2079225d6e34001ae85f74a0a418d68
timeCreated: 1683919878

View File

@ -1,21 +0,0 @@
#if FMOD
namespace NEG.UI.UnityUi.Buttons.Reaction
{
public class SimpleSoundBehaviour : ButtonElementBehaviour
{
public SimpleSoundBehaviour(BaseButton baseButton, FmodSoundData data) : base(baseButton, data)
{
//TODO: use silnet to not play sound
}
[FactoryRegistration]
private static void RegisterInFactory() =>
MonoUiManager.Instance.BehavioursFactory.Register("SimpleSound", typeof(SimpleSoundBehaviour));
public override void ChangeData(SettingData newData) => throw new System.NotImplementedException();
public override void Dispose() => throw new System.NotImplementedException();
}
}
#endif

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d75c0d86eeab47a1a6340f0b03b83de0
timeCreated: 1684002680

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ccaf0d2f63be41f6956471dcd9c210d9
timeCreated: 1709465582

View File

@ -1,10 +1,10 @@
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons.Reactions
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class ChangeSceneButton : ButtonReaction public class ChangeScene : ButtonReaction
{ {
[Header("Leave empty to use int value")] [SerializeField] [Header("Leave empty to use int value")] [SerializeField]
private string sceneName; private string sceneName;

View File

@ -1,4 +1,4 @@
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons.Reactions
{ {
public class CloseAllWindows : ButtonReaction public class CloseAllWindows : ButtonReaction
{ {

View File

@ -2,7 +2,7 @@
using NEG.UI.Window; using NEG.UI.Window;
using UnityEngine; using UnityEngine;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons.Reactions
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class CloseWindow : ButtonReaction public class CloseWindow : ButtonReaction

View File

@ -0,0 +1,15 @@
using UnityEngine;
namespace NEG.UI.UnityUi.Buttons.Reactions
{
public class ExitGame : ButtonReaction
{
protected override void OnClicked()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
Application.Quit();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 185f765a5bf7487ab85a7d95fc0ef2c7
timeCreated: 1709473462

View File

@ -2,7 +2,7 @@
using NEG.UI.Window; using NEG.UI.Window;
using UnityEngine; using UnityEngine;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons.Reactions
{ {
public class OpenAsCurrentMainChild : ButtonReaction public class OpenAsCurrentMainChild : ButtonReaction
{ {

View File

@ -3,7 +3,7 @@ using NEG.UI.UnityUi.WindowSlot;
using NEG.UI.Window; using NEG.UI.Window;
using UnityEngine; using UnityEngine;
namespace NEG.UI.UnityUi.Buttons namespace NEG.UI.UnityUi.Buttons.Reactions
{ {
[RequireComponent(typeof(BaseButton))] [RequireComponent(typeof(BaseButton))]
public class OpenWindow : ButtonReaction public class OpenWindow : ButtonReaction

View File

@ -1,6 +1,6 @@
using NEG.UI.Area; using NEG.UI.Area;
using NEG.UI.Popup; using NEG.UI.Popup;
using NEG.UI.UnityUi.Buttons.Reaction; using NEG.UI.UnityUi.Buttons.Behaviours;
using NEG.UI.UnityUi.Buttons.Settings; using NEG.UI.UnityUi.Buttons.Settings;
using NEG.UI.UnityUi.Popup; using NEG.UI.UnityUi.Popup;
using NEG.UI.UnityUi.Window; using NEG.UI.UnityUi.Window;

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: da80835a1611a5e4d908f51f09e8d3bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 849242dbc213969488426f85222a43a9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: