Rewrite property panel to adapt to ruleset config.
This commit is contained in:
@@ -3,12 +3,12 @@ using System;
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class RangeAttribute : Attribute {
|
||||
public RangeAttribute(float min, float max) {
|
||||
public RangeAttribute(double min, double max) {
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public float Min { get; set; }
|
||||
public float Max { get; set; }
|
||||
public double Min { get; set; }
|
||||
public double Max { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ using System;
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class StepAttribute : Attribute {
|
||||
public StepAttribute(float step) {
|
||||
public StepAttribute(double step) {
|
||||
Step = step;
|
||||
}
|
||||
public float Step { get; set; }
|
||||
public double Step { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,76 +0,0 @@
|
||||
using Cryville.Common.ComponentModel;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class PropertyPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_bool;
|
||||
[SerializeField]
|
||||
GameObject m_number;
|
||||
[SerializeField]
|
||||
GameObject m_string;
|
||||
|
||||
PropertyInfo _property;
|
||||
object _target;
|
||||
|
||||
Text _key;
|
||||
Transform _valueContainer;
|
||||
PropertyValuePanel _value;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_key = transform.Find("Key").GetComponent<Text>();
|
||||
_valueContainer = transform.Find("Value");
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
public void Load(PropertyInfo prop, object target) {
|
||||
_target = target;
|
||||
_property = prop;
|
||||
_key.text = prop.Name;
|
||||
|
||||
GameObject vp;
|
||||
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
||||
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
||||
else if (prop.PropertyType == typeof(string)) vp = m_string;
|
||||
else return;
|
||||
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||
if (_value is PVPNumber) {
|
||||
var t = (PVPNumber)_value;
|
||||
t.IntegerMode = prop.PropertyType == typeof(int);
|
||||
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (RangeAttribute)attr[0];
|
||||
t.Range = new Vector2(u.Min, u.Max);
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (PrecisionAttribute)attr[0];
|
||||
t.Precision = u.Precision;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (StepAttribute)attr[0];
|
||||
t.MaxStep = u.Step;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
t.LogarithmicMode = true;
|
||||
}
|
||||
}
|
||||
_value.Callback = SetValueToObject;
|
||||
GetValueFromObject();
|
||||
}
|
||||
|
||||
void GetValueFromObject() {
|
||||
_value.Value = _property.GetValue(_target, null);
|
||||
}
|
||||
|
||||
void SetValueToObject(object value) {
|
||||
_property.SetValue(_target, value, null);
|
||||
GetValueFromObject();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
||||
public Action<object> Callback { protected get; set; }
|
||||
public abstract object Value { get; set; }
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ namespace Cryville.Crtr.Config {
|
||||
Transform m_content;
|
||||
|
||||
[SerializeField]
|
||||
SettingsPanel m_genericConfigPanel;
|
||||
PropertyMasterPanel m_genericConfigPanel;
|
||||
|
||||
[SerializeField]
|
||||
InputConfigPanel m_inputConfigPanel;
|
||||
@@ -56,7 +56,7 @@ namespace Cryville.Crtr.Config {
|
||||
}
|
||||
}
|
||||
|
||||
m_genericConfigPanel.Target = _rscfg.generic;
|
||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||
|
||||
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
|
||||
proxy.LoadFrom(_rscfg.inputs);
|
||||
|
102
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs
Normal file
102
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using Cryville.Common.ComponentModel;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public interface IPropertyAdapter {
|
||||
string Category { get; }
|
||||
string Name { get; }
|
||||
PropertyType Type { get; }
|
||||
object[] Range { get; }
|
||||
object GetValue();
|
||||
void SetValue(object value);
|
||||
object MapValue(object value);
|
||||
bool SetMapped { get; }
|
||||
object MapValueInverse(object value);
|
||||
}
|
||||
|
||||
public enum PropertyType {
|
||||
Unknown,
|
||||
Number,
|
||||
SteppedNumber,
|
||||
Boolean,
|
||||
String,
|
||||
}
|
||||
|
||||
public class DefaultPropertyAdapter : IPropertyAdapter {
|
||||
readonly object _target;
|
||||
readonly PropertyInfo _prop;
|
||||
readonly string m_category;
|
||||
public string Category { get { return m_category; } }
|
||||
readonly string m_name;
|
||||
public string Name { get { return m_name; } }
|
||||
readonly PropertyType m_type = PropertyType.Unknown;
|
||||
public PropertyType Type { get { return m_type; } }
|
||||
readonly object[] m_range;
|
||||
public object[] Range { get { return m_range; } }
|
||||
public object GetValue() { return _prop.GetValue(_target, null); }
|
||||
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
|
||||
|
||||
double _precision;
|
||||
double _step;
|
||||
bool _logarithmic;
|
||||
public object MapValue(object value) {
|
||||
if (Type == PropertyType.Number || Type == PropertyType.SteppedNumber) {
|
||||
var result = (double)value;
|
||||
if (_step != 0) result *= _step;
|
||||
if (_logarithmic) result = Math.Pow(Math.E, result);
|
||||
if (_precision != 0) result = Math.Round(result / _precision) * _precision;
|
||||
return Convert.ChangeType(result, _prop.PropertyType);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public bool SetMapped { get { return true; } }
|
||||
public object MapValueInverse(object value) {
|
||||
if (Type == PropertyType.Number || Type == PropertyType.SteppedNumber) {
|
||||
var result = Convert.ToDouble(value);
|
||||
if (_logarithmic) result = Math.Log(result);
|
||||
if (_step != 0) result /= _step;
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public DefaultPropertyAdapter(object target, PropertyInfo prop) {
|
||||
_target = target;
|
||||
_prop = prop;
|
||||
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
|
||||
if (attrs.Length > 0) m_category = ((CategoryAttribute)attrs.Single()).Category;
|
||||
m_name = prop.Name;
|
||||
if (prop.PropertyType == typeof(bool)) m_type = PropertyType.Boolean;
|
||||
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
|
||||
else if (prop.PropertyType.IsPrimitive) {
|
||||
m_type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0
|
||||
? PropertyType.SteppedNumber
|
||||
: PropertyType.Number;
|
||||
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (RangeAttribute)attr.Single();
|
||||
m_range = new object[] { u.Min, u.Max };
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (PrecisionAttribute)attr.Single();
|
||||
_precision = u.Precision;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (StepAttribute)attr.Single();
|
||||
_step = u.Step;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
_logarithmic = true;
|
||||
}
|
||||
}
|
||||
else if (prop.PropertyType == typeof(string)) m_type = PropertyType.String;
|
||||
else return;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9653d5e145f2866439a0fcd1b27f49c4
|
||||
guid: 9b3e9219783719544bcbceade34a1090
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal file
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public interface IPropertyMasterAdapter {
|
||||
string DefaultCategory { get; }
|
||||
IEnumerable<IPropertyAdapter> GetProperties();
|
||||
}
|
||||
public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
|
||||
readonly object _target;
|
||||
|
||||
public DefaultPropertyMasterAdapter(object target) {
|
||||
if (target == null) throw new ArgumentNullException("target");
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public string DefaultCategory { get { return "miscellaneous"; } }
|
||||
|
||||
public IEnumerable<IPropertyAdapter> GetProperties() {
|
||||
return _target.GetType().GetProperties().Where(p => {
|
||||
var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
||||
if (attrs.Length == 0) return true;
|
||||
else return ((BrowsableAttribute)attrs.Single()).Browsable;
|
||||
}).Select(p => new DefaultPropertyAdapter(_target, p));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e0b160d43716cf4d8ba20b5a7eafd13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,14 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
|
||||
bool _value;
|
||||
public override object Value {
|
||||
get { return _value; }
|
||||
set { _value = (bool)value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
RectTransform m_on;
|
||||
[SerializeField]
|
||||
@@ -16,21 +10,22 @@ namespace Cryville.Crtr.Browsing {
|
||||
[SerializeField]
|
||||
RectTransform m_handle;
|
||||
|
||||
protected override void OnValueUpdated() { }
|
||||
|
||||
public void Toggle() {
|
||||
_value = !_value;
|
||||
Callback(Value);
|
||||
RawValue = !(bool)RawValue;
|
||||
}
|
||||
|
||||
const float SPEED = 8;
|
||||
float _ratio;
|
||||
#pragma warning disable IDE0051
|
||||
void Update() {
|
||||
if (_value && _ratio != 1) {
|
||||
if ((bool)RawValue && _ratio != 1) {
|
||||
_ratio += SPEED * Time.deltaTime;
|
||||
if (_ratio > 1) _ratio = 1;
|
||||
UpdateGraphics();
|
||||
}
|
||||
else if (!_value && _ratio != 0) {
|
||||
else if (!(bool)RawValue && _ratio != 0) {
|
||||
_ratio -= SPEED * Time.deltaTime;
|
||||
if (_ratio < 0) _ratio = 0;
|
||||
UpdateGraphics();
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b281561aca5d19f43ba8af035de8ec98
|
||||
guid: 362a7cfafb57b9f46bbca9ed88d18c53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
18
Assets/Cryville/Crtr/Config/PVPNumber.cs
Normal file
18
Assets/Cryville/Crtr/Config/PVPNumber.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PVPNumber : PVPNumberBase {
|
||||
protected override void OnValueUpdated() {
|
||||
base.OnValueUpdated();
|
||||
if (Range != null && Range.Length == 2) {
|
||||
var min = (double)Range[0];
|
||||
var max = (double)Range[1];
|
||||
SetRatio((float)((Convert.ToDouble(RawValue) - min) / (max - min)));
|
||||
}
|
||||
}
|
||||
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
|
||||
// if (LogarithmicMode) throw new NotImplementedException();
|
||||
return (1 - ratio) * min + ratio * max;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1eb74ffd69f934d4a8eca80aa3077b6c
|
||||
guid: 5b5d86b95e0bf894b86c63127d5ac06c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,44 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class PVPNumber : PropertyValuePanel {
|
||||
static Color _steppedTint = new Color(1.0f, 0.8f, 0.5f);
|
||||
|
||||
double m_value;
|
||||
public override object Value {
|
||||
get {
|
||||
float s_value = GetDisplayValue();
|
||||
return IntegerMode ? (int)s_value : (object)s_value;
|
||||
}
|
||||
set {
|
||||
if (value is double) m_value = (double)value;
|
||||
else m_value = IntegerMode ? (int)value : (double)(float)value;
|
||||
float s_value = GetDisplayValue();
|
||||
m_text.text = s_value.ToString();
|
||||
if (Range != null && MaxStep == 0) {
|
||||
SetRatio((float)(m_value - Range.Value.x) / (Range.Value.y - Range.Value.x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float GetDisplayValue() {
|
||||
double s_value = m_value;
|
||||
if (Precision > 0)
|
||||
s_value = Math.Round(s_value / Precision) * Precision;
|
||||
if (IntegerMode)
|
||||
s_value = Math.Round(s_value);
|
||||
return (float)s_value;
|
||||
}
|
||||
|
||||
public bool IntegerMode { get; set; }
|
||||
public bool LogarithmicMode { get; set; }
|
||||
public float MaxStep { get; set; }
|
||||
public double Precision { get; set; }
|
||||
public Vector2? Range { get; set; }
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public abstract class PVPNumberBase : PropertyValuePanel {
|
||||
[SerializeField]
|
||||
EventTrigger m_ctn;
|
||||
[SerializeField]
|
||||
@@ -48,7 +13,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
[SerializeField]
|
||||
Text m_text;
|
||||
#pragma warning disable IDE0051
|
||||
void Start() {
|
||||
protected void Start() {
|
||||
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
|
||||
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
|
||||
m_ctn.triggers.Add(ev);
|
||||
@@ -61,15 +26,17 @@ namespace Cryville.Crtr.Browsing {
|
||||
ev = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
|
||||
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
|
||||
m_ctn.triggers.Add(ev);
|
||||
|
||||
if (MaxStep != 0) {
|
||||
m_handle.color = _steppedTint;
|
||||
SetRatio(0.5f);
|
||||
}
|
||||
OnIdle();
|
||||
}
|
||||
|
||||
protected override void OnValueUpdated() {
|
||||
m_text.text = MappedValue.ToString();
|
||||
}
|
||||
|
||||
protected virtual void OnIdle() { }
|
||||
|
||||
void Update() {
|
||||
if (use && MaxStep != 0) {
|
||||
if (use) {
|
||||
SetRatio(GetRatioFromPos(pp));
|
||||
SetValueFromPos(pp);
|
||||
}
|
||||
@@ -99,7 +66,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
if (use) {
|
||||
pp = eventData.position;
|
||||
if (MaxStep == 0) SetValueFromPos(eventData.position);
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
@@ -107,8 +73,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
public void OnEndDrag(PointerEventData eventData) {
|
||||
if (!nouse) {
|
||||
SetValueFromPos(eventData.position);
|
||||
Callback(Value);
|
||||
if (MaxStep != 0) SetRatio(0.5f);
|
||||
OnIdle();
|
||||
eventData.Use();
|
||||
use = false;
|
||||
}
|
||||
@@ -117,7 +82,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData) {
|
||||
SetValueFromPos(eventData.position);
|
||||
Callback(Value);
|
||||
eventData.Use();
|
||||
}
|
||||
|
||||
@@ -131,25 +95,21 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
|
||||
void SetValueFromPos(Vector2 pos) {
|
||||
double min = double.NegativeInfinity, max = double.PositiveInfinity;
|
||||
if (Range != null && Range.Length == 2) {
|
||||
min = (double)Range[0];
|
||||
max = (double)Range[1];
|
||||
}
|
||||
double ratio = GetRatioFromPos(pos);
|
||||
double result;
|
||||
if (MaxStep == 0) {
|
||||
if (LogarithmicMode) throw new NotImplementedException();
|
||||
else result = (1 - ratio) * Range.Value.x + ratio * Range.Value.y;
|
||||
}
|
||||
else {
|
||||
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * MaxStep * Time.deltaTime;
|
||||
if (LogarithmicMode) result = Math.Pow(Math.E, Math.Log(m_value) + delta);
|
||||
else result = m_value + delta;
|
||||
}
|
||||
if (Range != null) {
|
||||
if (result < Range.Value.x) result = Range.Value.x;
|
||||
else if (result > Range.Value.y) result = Range.Value.y;
|
||||
}
|
||||
Value = result;
|
||||
double result = GetValue(ratio, Time.deltaTime, min, max);
|
||||
if (result < min) result = min;
|
||||
else if (result > max) result = max;
|
||||
RawValue = result;
|
||||
}
|
||||
|
||||
void SetRatio(float ratio) {
|
||||
protected abstract double GetValue(double ratio, float deltaTime, double min, double max);
|
||||
|
||||
protected void SetRatio(float ratio) {
|
||||
m_handle.rectTransform.anchorMin = new Vector2(ratio, m_handle.rectTransform.anchorMin.y);
|
||||
m_handle.rectTransform.anchorMax = new Vector2(ratio, m_handle.rectTransform.anchorMax.y);
|
||||
}
|
11
Assets/Cryville/Crtr/Config/PVPNumberBase.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/PVPNumberBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32fb9b8479cd8294296453d1aa651ff4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Cryville/Crtr/Config/PVPNumberStepped.cs
Normal file
14
Assets/Cryville/Crtr/Config/PVPNumberStepped.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PVPNumberStepped : PVPNumberBase {
|
||||
protected override void OnIdle() {
|
||||
SetRatio(0.5f);
|
||||
}
|
||||
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
|
||||
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * deltaTime;
|
||||
// if (LogarithmicMode) return Math.Pow(Math.E, Math.Log(m_value) + delta);
|
||||
return Convert.ToDouble(RawValue) + delta;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Config/PVPNumberStepped.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/PVPNumberStepped.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f754d98e38098654a878fc9121db536d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,17 +1,8 @@
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PVPString : PropertyValuePanel {
|
||||
string m_value;
|
||||
public override object Value {
|
||||
get {
|
||||
return m_value;
|
||||
}
|
||||
set {
|
||||
m_value = (string)value;
|
||||
_inputField.text = m_value;
|
||||
}
|
||||
}
|
||||
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }
|
||||
|
||||
InputField _inputField;
|
||||
|
||||
@@ -21,8 +12,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
|
||||
void OnValueChanged(string value) {
|
||||
m_value = value;
|
||||
Callback(Value);
|
||||
RawValue = value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aadf11739189bc94e9cb4f702eb7ccd3
|
||||
guid: 1b9a6e3b503784e4aa78215e9b004a8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PropertyCategoryPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
private GameObject m_propertyPrefab;
|
||||
@@ -29,11 +28,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
|
||||
public void Load(string name, IEnumerable<IPropertyAdapter> props) {
|
||||
Name = name.ToUpper();
|
||||
foreach (var prop in props) {
|
||||
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab, transform, false);
|
||||
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
||||
var obj = Instantiate(m_propertyPrefab, transform, false);
|
||||
obj.GetComponent<PropertyPanel>().Load(prop);
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a13b7ea14b96e54ea8a7e6ba1275281
|
||||
timeCreated: 1638435211
|
||||
licenseType: Free
|
||||
guid: 71da54f24b65d2f41a00c5a4bd0ff1bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
51
Assets/Cryville/Crtr/Config/PropertyMasterPanel.cs
Normal file
51
Assets/Cryville/Crtr/Config/PropertyMasterPanel.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PropertyMasterPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_categoryPrefab;
|
||||
|
||||
[SerializeField]
|
||||
Transform m_container;
|
||||
|
||||
bool _invalidated = true;
|
||||
|
||||
public void Invalidate() {
|
||||
_invalidated = true;
|
||||
}
|
||||
|
||||
private IPropertyMasterAdapter m_adapter;
|
||||
public IPropertyMasterAdapter Adapter {
|
||||
get { return m_adapter; }
|
||||
set {
|
||||
m_adapter = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
if (!_invalidated) return;
|
||||
LoadProperties();
|
||||
foreach (Transform c in m_container) Destroy(c.gameObject);
|
||||
foreach (var c in _categories) {
|
||||
var obj = Instantiate(m_categoryPrefab, m_container, false);
|
||||
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value);
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new Dictionary<string, List<IPropertyAdapter>>();
|
||||
public void LoadProperties() {
|
||||
_categories.Clear();
|
||||
_invalidated = false;
|
||||
if (Adapter == null) return;
|
||||
foreach (var p in Adapter.GetProperties()) {
|
||||
string category = p.Category;
|
||||
if (category == null) category = Adapter.DefaultCategory;
|
||||
if (!_categories.ContainsKey(category))
|
||||
_categories.Add(category, new List<IPropertyAdapter>());
|
||||
_categories[category].Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Config/PropertyMasterPanel.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/PropertyMasterPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e6129746af547242bfa4e7404185936
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Cryville/Crtr/Config/PropertyPanel.cs
Normal file
40
Assets/Cryville/Crtr/Config/PropertyPanel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PropertyPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_bool;
|
||||
[SerializeField]
|
||||
GameObject m_number;
|
||||
[SerializeField]
|
||||
GameObject m_steppedNumber;
|
||||
[SerializeField]
|
||||
GameObject m_string;
|
||||
|
||||
Text _key;
|
||||
Transform _valueContainer;
|
||||
PropertyValuePanel _value;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_key = transform.Find("Key").GetComponent<Text>();
|
||||
_valueContainer = transform.Find("Value");
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
public void Load(IPropertyAdapter prop) {
|
||||
_key.text = prop.Name;
|
||||
|
||||
GameObject vp;
|
||||
switch (prop.Type) {
|
||||
case PropertyType.Number: vp = m_number; break;
|
||||
case PropertyType.SteppedNumber: vp = m_steppedNumber; break;
|
||||
case PropertyType.Boolean: vp = m_bool; break;
|
||||
case PropertyType.String: vp = m_string; break;
|
||||
default: return;
|
||||
}
|
||||
_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||
_value.Init(prop);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcca29fea992ac24698a213f0e2baedc
|
||||
timeCreated: 1638435590
|
||||
licenseType: Free
|
||||
guid: e47c05cfd69aa3f4d9886293e66877e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
39
Assets/Cryville/Crtr/Config/PropertyValuePanel.cs
Normal file
39
Assets/Cryville/Crtr/Config/PropertyValuePanel.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
||||
IPropertyAdapter _property;
|
||||
public void Init(IPropertyAdapter property) {
|
||||
_property = property;
|
||||
GetValue();
|
||||
}
|
||||
protected object[] Range { get { return _property.Range; } }
|
||||
public object MappedValue { get; private set; }
|
||||
private object m_rawValue;
|
||||
public object RawValue {
|
||||
get { return m_rawValue; }
|
||||
set {
|
||||
m_rawValue = value;
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
protected abstract void OnValueUpdated();
|
||||
void GetValue() {
|
||||
if (_property.SetMapped) {
|
||||
MappedValue = _property.GetValue();
|
||||
m_rawValue = _property.MapValueInverse(MappedValue);
|
||||
}
|
||||
else {
|
||||
m_rawValue = _property.GetValue();
|
||||
MappedValue = _property.MapValue(m_rawValue);
|
||||
}
|
||||
OnValueUpdated();
|
||||
}
|
||||
void SetValue() {
|
||||
var outRaw = RawValue;
|
||||
MappedValue = _property.MapValue(outRaw);
|
||||
_property.SetValue(_property.SetMapped ? MappedValue : outRaw);
|
||||
OnValueUpdated();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fca3da10a8b0677439885f6732ac3b6e
|
||||
guid: c71cc11a0b1429c4fac91296bf8c5a63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -14,13 +14,13 @@ namespace Cryville.Crtr.Config {
|
||||
|
||||
[Category("gameplay")]
|
||||
[JsonProperty("sound_offset")]
|
||||
[Step(0.04f)]
|
||||
[Step(0.04)]
|
||||
[Precision(1e-3)]
|
||||
public float SoundOffset { get; set; }
|
||||
|
||||
[Category("deprecated")][Obsolete]
|
||||
[JsonProperty("scroll_velocity")][DefaultValue(1)]
|
||||
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
||||
[LogarithmicScale][Step(0.5)][Precision(1e-1)]
|
||||
public float ScrollVelocity { get; set; }
|
||||
|
||||
public Generic() {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common.Unity.UI;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Cryville.Crtr.Config;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -15,7 +16,7 @@ namespace Cryville.Crtr {
|
||||
[SerializeField]
|
||||
ProgressBar m_progressBar;
|
||||
[SerializeField]
|
||||
SettingsPanel m_settingsPanel;
|
||||
PropertyMasterPanel m_settingsPanel;
|
||||
[SerializeField]
|
||||
TMP_Text m_title;
|
||||
[SerializeField]
|
||||
@@ -29,7 +30,7 @@ namespace Cryville.Crtr {
|
||||
void Awake() {
|
||||
Game.Init();
|
||||
transform.parent.Find("Canvas/Contents").gameObject.SetActive(true);
|
||||
m_settingsPanel.Target = Settings.Default;
|
||||
m_settingsPanel.Adapter = new DefaultPropertyMasterAdapter(Settings.Default);
|
||||
PushTitle("Chart Browser");
|
||||
}
|
||||
void Update() {
|
||||
|
@@ -6,7 +6,7 @@ using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
|
||||
namespace Cryville.Crtr {
|
||||
public class Settings {
|
||||
[Category("gameplay")]
|
||||
[Range(0f, 10f)][Precision(1)]
|
||||
[Range(0, 10)][Precision(1)]
|
||||
public int AreaJudgePrecision {
|
||||
get {
|
||||
return PlayerPrefs.GetInt("AreaJudgePrecision", 4);
|
||||
@@ -17,7 +17,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("graphics")]
|
||||
[LogarithmicScale][Range(0.01f, 20f)][Step(1f)][Precision(1e-2)]
|
||||
[LogarithmicScale][Range(-4.6, 3)][Step(1)][Precision(1e-2)]
|
||||
public float BackwardClippingDistance {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("BackwardClippingDistance", 0.2f);
|
||||
@@ -73,7 +73,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("gameplay")]
|
||||
[Step(0.02f)][Precision(1e-3)]
|
||||
[Step(0.02)][Precision(1e-3)]
|
||||
public float GraphicalOffset {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("GraphicalOffset", 0);
|
||||
@@ -142,7 +142,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("graphics")]
|
||||
[LogarithmicScale][Range(0.1f, 200f)][Step(1f)][Precision(1e-1)]
|
||||
[LogarithmicScale][Range(-2.3, 6)][Step(1)][Precision(1e-1)]
|
||||
public float RenderDistance {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("RenderDistance", 4);
|
||||
@@ -154,7 +154,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
[Category("graphics")]
|
||||
[Description("The span before the renderer fetches the object data again. Smaller value generates more detailed objects while increasing CPU load. Leave 0 to let the game decides the value automatically.")]
|
||||
[Range(0, 0.1f)][Precision(1e-3)]
|
||||
[Range(0, 0.1)][Precision(1e-3)]
|
||||
public float RenderStep {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("RenderStep", 0f);
|
||||
@@ -165,7 +165,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("gameplay")]
|
||||
[Step(0.1f)][Precision(1e-3)]
|
||||
[Step(0.1)][Precision(1e-3)]
|
||||
public float SoundOffset {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("SoundOffset", 0);
|
||||
@@ -176,7 +176,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("debug")]
|
||||
[Range(0, float.PositiveInfinity)][Step(60f)][Precision(1e-1)]
|
||||
[Range(0, double.PositiveInfinity)][Step(60)][Precision(1e-1)]
|
||||
public float StartOffset {
|
||||
get {
|
||||
return PlayerPrefs.GetFloat("StartOffset", 0);
|
||||
@@ -187,7 +187,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
[Category("graphics")]
|
||||
[LogarithmicScale][Range(15, 1024)][Step(2f)]
|
||||
[LogarithmicScale][Range(1.15, 3.5)][Step(2)]
|
||||
public int TargetFrameRate {
|
||||
get {
|
||||
return PlayerPrefs.GetInt("TargetFrameRate", 60);
|
||||
|
@@ -1,63 +0,0 @@
|
||||
using Cryville.Crtr.Browsing;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class SettingsPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_categoryPrefab;
|
||||
|
||||
[SerializeField]
|
||||
Transform m_container;
|
||||
|
||||
bool _invalidated = true;
|
||||
object m_target;
|
||||
public object Target {
|
||||
get {
|
||||
return m_target;
|
||||
}
|
||||
set {
|
||||
if (m_target != value) {
|
||||
m_target = value;
|
||||
_invalidated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
if (!_invalidated) return;
|
||||
LoadProperties();
|
||||
foreach (Transform c in m_container) GameObject.Destroy(c.gameObject);
|
||||
foreach (var c in _categories) {
|
||||
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab, m_container, false);
|
||||
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Target);
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<string, List<PropertyInfo>> _categories = new Dictionary<string, List<PropertyInfo>>();
|
||||
public void LoadProperties() {
|
||||
_categories.Clear();
|
||||
_invalidated = false;
|
||||
if (Target == null) return;
|
||||
foreach (var p in Target.GetType().GetProperties()) {
|
||||
bool browsable = true;
|
||||
string category = "miscellaneous";
|
||||
foreach (var attr in p.GetCustomAttributes(true)) {
|
||||
if (attr is BrowsableAttribute) {
|
||||
browsable = ((BrowsableAttribute)attr).Browsable;
|
||||
if (!browsable) break;
|
||||
}
|
||||
else if (attr is CategoryAttribute) {
|
||||
category = ((CategoryAttribute)attr).Category;
|
||||
}
|
||||
}
|
||||
if (!browsable) continue;
|
||||
if (!_categories.ContainsKey(category))
|
||||
_categories.Add(category, new List<PropertyInfo>());
|
||||
_categories[category].Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user