Restore the stable legacy Unity project

This commit is contained in:
Meta Vens 2026-08-10 14:57:50 +01:00
commit 7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions

View file

@ -1,143 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UniRx;
public class ConfirmationDialog : MonoBehaviour
public class ConfirmationDialog : PropertiesPanel
{
public TextMeshProUGUI Title;
public RectTransform Content;
public Property Property;
public InputField InputField;
public ClickCatcher CancelClickCatcher;
public GameObject ButtonGroup;
public Button Cancel;
public Button Confirm;
public TextMeshProUGUI ConfirmText;
public TextMeshProUGUI CancelText;
public bool LockDialog { get; set; }
private readonly List<GameObject> _entries = new();
private readonly List<Action> _refreshers = new();
private Action _onCancel;
private Action _onConfirm;
private Action _enableGlobalInput;
private Action _disableGlobalInput;
private void Start()
{
Cancel.onClick.AddListener(() => End());
Confirm.onClick.AddListener(() => End(true));
if (CancelClickCatcher != null)
{
CancelClickCatcher.OnClick.Subscribe(_ =>
CancelClickCatcher.OnClick.Subscribe(data =>
{
if (!LockDialog)
{
End();
}
if (!LockDialog) End();
});
}
OnPropertyAdded += go =>
{
go.SetActive(true);
go.transform.SetSiblingIndex(Title.transform.GetSiblingIndex() + 1);
};
gameObject.SetActive(false);
}
private void Update()
{
RefreshValues();
}
public void Clear()
{
foreach (var entry in _entries)
{
Destroy(entry);
}
_entries.Clear();
_refreshers.Clear();
Title.text = "Properties";
}
public Property AddProperty(Func<string> read)
{
if (read == null)
{
throw new ArgumentException("Attempted to add confirmation-dialog property with null read function!");
}
var property = Instantiate(Property, Content ?? (RectTransform)transform);
_refreshers.Add(() => property.Label.text = read());
property.Label.text = read();
RegisterEntry(property.gameObject);
return property;
}
public Property AddProperty(string text)
{
var property = Instantiate(Property, Content ?? (RectTransform)transform);
property.Label.text = text;
RegisterEntry(property.gameObject);
return property;
}
public void SetInputGate(Action enableGlobalInput, Action disableGlobalInput)
{
_enableGlobalInput = enableGlobalInput;
_disableGlobalInput = disableGlobalInput;
}
public void AddField(string name, Func<string> read, Action<string> write)
{
var field = Instantiate(InputField, Content ?? (RectTransform)transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.Standard;
field.Field.onValueChanged.AddListener(write.Invoke);
_refreshers.Add(() => SyncField(field.Field, read()));
SyncField(field.Field, read());
RegisterEntry(field.gameObject);
}
public void AddField(string name, Func<int> read, Action<int> write)
{
var field = Instantiate(InputField, Content ?? (RectTransform)transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
field.Field.onValueChanged.AddListener(value =>
{
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsed))
{
write(parsed);
}
});
_refreshers.Add(() => SyncField(field.Field, read().ToString(CultureInfo.InvariantCulture)));
SyncField(field.Field, read().ToString(CultureInfo.InvariantCulture));
RegisterEntry(field.gameObject);
}
public void End(bool success = false)
{
if (success)
{
_onConfirm?.Invoke();
}
else
{
_onCancel?.Invoke();
}
if(success) _onConfirm?.Invoke();
else _onCancel?.Invoke();
CancelClickCatcher?.gameObject.SetActive(false);
gameObject.SetActive(false);
_enableGlobalInput?.Invoke();
ActionGameManager.Instance?.Input.Global.Enable();
}
public void MoveToCursor()
@ -147,43 +59,19 @@ public class ConfirmationDialog : MonoBehaviour
public void Show(Action onConfirm = null, Action onCancel = null, string confirmText = "OK", string cancelText = "Cancel")
{
RefreshValues();
gameObject.SetActive(true);
_onConfirm = onConfirm;
Confirm.gameObject.SetActive(onConfirm != null);
Confirm.gameObject.SetActive(onConfirm!=null);
ConfirmText.text = confirmText;
_onCancel = onCancel;
Cancel.gameObject.SetActive(onCancel != null);
Cancel.gameObject.SetActive(onCancel!=null);
CancelText.text = cancelText;
ButtonGroup.SetActive(onConfirm != null || onCancel != null);
ButtonGroup.SetActive(onConfirm!=null || onCancel!=null);
CancelClickCatcher?.gameObject.SetActive(true);
_disableGlobalInput?.Invoke();
}
private void RegisterEntry(GameObject entry)
{
_entries.Add(entry);
entry.SetActive(true);
entry.transform.SetSiblingIndex(Title.transform.GetSiblingIndex() + _entries.Count);
}
private void RefreshValues()
{
foreach (var refresh in _refreshers)
{
refresh();
}
}
private static void SyncField(TMP_InputField field, string value)
{
if (!string.Equals(field.text, value, StringComparison.Ordinal))
{
field.SetTextWithoutNotify(value);
}
ActionGameManager.Instance?.Input.Global.Disable();
}
}