prep auto-population of property menu

This commit is contained in:
minenice55
2022-09-01 20:57:47 -04:00
parent b19afcd2e2
commit b84dc9a2de
23 changed files with 552 additions and 25 deletions

View File

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

View File

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
namespace HeavenStudio.Editor
{
public class BoolChartPropertyPrefab : RemixPropertyPrefab
{
[Header("Boolean")]
[Space(10)]
public Toggle toggle;
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
{
InitProperties(diag, propertyName, caption);
// ' (bool)type ' always results in false
toggle.isOn = Convert.ToBoolean(parameterManager.chart[propertyName]);
toggle.onValueChanged.AddListener(
_ => parameterManager.chart[propertyName] = toggle.isOn
);
}
private void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5765785c18f751f4196e09d11dd30ff3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
namespace HeavenStudio.Editor
{
public class ColorChartPropertyPrefab : RemixPropertyPrefab
{
[Header("Color")]
[Space(10)]
public Button ColorBTN;
public RectTransform ColorTable;
public bool colorTableActive;
public ColorPreview colorPreview;
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
{
InitProperties(diag, propertyName, caption);
colorPreview.colorPicker.onColorChanged += _ =>
parameterManager.chart[propertyName] = colorPreview.colorPicker.color;
Color paramCol = parameterManager.chart[propertyName];
ColorBTN.onClick.AddListener(
() =>
{
ColorTable.gameObject.SetActive(true);
colorTableActive = true;
colorPreview.ChangeColor(paramCol);
}
);
colorPreview.ChangeColor(paramCol);
ColorTable.gameObject.SetActive(false);
}
private void Update()
{
if (colorTableActive)
{
if (!Editor.MouseInRectTransform(ColorTable))
{
if (Input.GetMouseButtonDown(0))
{
ColorTable.gameObject.SetActive(false);
colorTableActive = false;
}
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83f718678c662f9448813df185f1283f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
namespace HeavenStudio.Editor
{
public class EnumChartPropertyPrefab : RemixPropertyPrefab
{
[Header("Dropdown")]
[Space(10)]
public TMP_Dropdown dropdown;
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
{
InitProperties(diag, propertyName, caption);
var enumType = type.GetType();
var enumVals = Enum.GetValues(enumType);
var enumNames = Enum.GetNames(enumType).ToList();
// Can we assume non-holey enum?
// If we can we can simplify to dropdown.value = (int) parameterManager.chart[propertyName]
var currentlySelected = (int) parameterManager.chart[propertyName];
var selected = enumVals
.Cast<object>()
.ToList()
.FindIndex(val => (int) val == currentlySelected);
dropdown.AddOptions(enumNames);
dropdown.value = selected;
dropdown.onValueChanged.AddListener(_ =>
parameterManager.chart[propertyName] = (int) enumVals.GetValue(dropdown.value)
);
}
private void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bddf1f894c08d91429a4a36f21a3c10e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
namespace HeavenStudio.Editor
{
public class NumberChartPropertyPrefab : RemixPropertyPrefab
{
[Header("Integer and Float")]
[Space(10)]
public Slider slider;
public TMP_InputField inputField;
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
{
InitProperties(diag, propertyName, caption);
switch (type)
{
case EntityTypes.Integer integer:
slider.minValue = integer.min;
slider.maxValue = integer.max;
slider.wholeNumbers = true;
slider.value = Convert.ToSingle(parameterManager.chart[propertyName]);
inputField.text = slider.value.ToString();
slider.onValueChanged.AddListener(
_ =>
{
inputField.text = slider.value.ToString();
parameterManager.chart[propertyName] = (int) slider.value;
}
);
inputField.onSelect.AddListener(
_ =>
Editor.instance.editingInputField = true
);
inputField.onEndEdit.AddListener(
_ =>
{
slider.value = Convert.ToSingle(inputField.text);
parameterManager.chart[propertyName] = (int) slider.value;
Editor.instance.editingInputField = false;
}
);
break;
case EntityTypes.Float fl:
slider.minValue = fl.min;
slider.maxValue = fl.max;
slider.value = Convert.ToSingle(parameterManager.chart[propertyName]);
inputField.text = slider.value.ToString("G");
slider.onValueChanged.AddListener(
_ =>
{
var newValue = (float) Math.Round(slider.value, 4);
inputField.text = newValue.ToString("G");
parameterManager.chart[propertyName] = newValue;
}
);
inputField.onSelect.AddListener(
_ =>
Editor.instance.editingInputField = true
);
inputField.onEndEdit.AddListener(
_ =>
{
slider.value = (float) Math.Round(Convert.ToSingle(inputField.text), 4);
parameterManager.chart[propertyName] = slider.value;
Editor.instance.editingInputField = false;
}
);
break;
default:
throw new ArgumentOutOfRangeException(
nameof(type), type, "I don't know how to make a property of this type!"
);
}
}
private void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3541b2824368eef4b94655619c05c3bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
namespace HeavenStudio.Editor
{
public class StringChartPropertyPrefab : RemixPropertyPrefab
{
[Header("String")] //why wasn't this a thing before
[Space(10)]
public TMP_InputField inputFieldString;
new public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption)
{
InitProperties(diag, propertyName, caption);
inputFieldString.text = (string) parameterManager.chart[propertyName];
inputFieldString.onSelect.AddListener(
_ =>
Editor.instance.editingInputField = true
);
inputFieldString.onEndEdit.AddListener(
_ =>
{;
parameterManager.chart[propertyName] = inputFieldString.text;
Editor.instance.editingInputField = false;
}
);
}
private void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d094b0b57b4a1945a8ca587d9478b75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,6 +9,18 @@ namespace HeavenStudio.Editor
{
public class RemixPropertiesDialog : Dialog
{
[Header("Editable Properties")]
[SerializeField] string[] infoTags;
[SerializeField] string[] infoLabels;
[SerializeField] string[] flavourTags;
[SerializeField] string[] flavourLabels;
[Header("Containers")]
[SerializeField] ChartInfoProperties infoContainer;
// [SerializeField] ChartFlavourProperties flavourContainer;
public DynamicBeatmap chart;
private void Start() {}
public void SwitchPropertiesDialog()
@ -17,11 +29,46 @@ namespace HeavenStudio.Editor
Editor.instance.canSelect = true;
Editor.instance.inAuthorativeMenu = false;
dialog.SetActive(false);
CleanDialog();
} else {
ResetAllDialogs();
Editor.instance.canSelect = false;
Editor.instance.inAuthorativeMenu = true;
dialog.SetActive(true);
SetupDialog();
}
}
private void SetupDialog() {
chart = GameManager.instance.Beatmap;
string[] tags = infoTags;
string[] labels = infoLabels;
int i = 0;
foreach (string property in tags) {
if (chart.properties.ContainsKey(property)) {
infoContainer.AddParam(this, property, chart.properties[property], labels[i]);
}
else
{
if (property == "divider")
{
//TODO: prefab that's just a dividing line
}
else
{
Debug.LogWarning("Property Menu generation Warning: Property " + property + " not found");
}
}
i++;
}
}
private void CleanDialog() {
foreach (Transform child in dialog.transform) {
Destroy(child.gameObject);
}
}

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using TMPro;
using Starpelly;
using HeavenStudio.Util;
namespace HeavenStudio.Editor
{
public class RemixPropertyPrefab : MonoBehaviour
{
public TMP_Text caption;
public RemixPropertiesDialog parameterManager;
public string propertyName;
public void SetProperties(RemixPropertiesDialog diag, string propertyName, object type, string caption) {}
public void InitProperties(RemixPropertiesDialog diag, string propertyName, string caption)
{
this.parameterManager = diag;
this.propertyName = propertyName;
this.caption.text = caption;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2483aa618d773c143857f608a2d2d32a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,14 +4,11 @@ using TMPro;
namespace HeavenStudio.Editor
{
public class ChartInfoProperties : MonoBehaviour
public class ChartInfoProperties : TabsContent
{
[Header("General References")]
[SerializeField] private GameObject propertyHolder;
[Header("Editable Properties")]
[SerializeField] private string[] propertyNames;
[Header("Property Prefabs")]
[SerializeField] private GameObject IntegerP;
[SerializeField] private GameObject FloatP;
@ -20,7 +17,7 @@ namespace HeavenStudio.Editor
[SerializeField] private GameObject ColorP;
[SerializeField] private GameObject StringP;
private void AddParam(string propertyName, object type, string caption, string tooltip = "")
public void AddParam(RemixPropertiesDialog diag, string propertyName, object type, string caption, string tooltip = "")
{
GameObject prefab = IntegerP;
GameObject input;
@ -31,43 +28,43 @@ namespace HeavenStudio.Editor
{
prefab = IntegerP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<NumberPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(EntityTypes.Float))
{
prefab = FloatP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<NumberPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (type is bool)
{
prefab = BooleanP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<BoolPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<BoolChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType.IsEnum)
{
prefab = DropdownP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<EnumPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<EnumChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(Color))
{
prefab = ColorP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<ColorPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<ColorChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(string))
{
prefab = StringP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<StringPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
var property = input.GetComponent<StringChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else
{
@ -88,5 +85,13 @@ namespace HeavenStudio.Editor
return input;
}
public override void OnOpenTab()
{
}
public override void OnCloseTab()
{
}
}
}