In Game Input Screen

Implemented saving/loading of custom input settings
Incorporated Input Screen in game
Organized UI scripts into folders
Deleted some unused UI scripts
Reimplemented Fog Blur (by copying modified DoF to assets)
This commit is contained in:
Reinier Vens 2021-05-08 07:35:16 +01:00
commit 81acaf2a47
173 changed files with 8236 additions and 7329 deletions

View file

@ -0,0 +1,17 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class AttributeProperty : MonoBehaviour
{
public TextMeshProUGUI Title;
public TextMeshProUGUI LowLabel;
public TextMeshProUGUI HighLabel;
public Slider Slider;
}

View file

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

View file

@ -0,0 +1,15 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class BoolField : MonoBehaviour
{
public TextMeshProUGUI Label;
public Toggle Toggle;
}

View file

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

View file

@ -0,0 +1,16 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ButtonField : MonoBehaviour
{
public TextMeshProUGUI Label;
public TextMeshProUGUI ButtonLabel;
public Button Button;
}

View file

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

View file

@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Msagl.DebugHelpers;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UI.Extensions;
using static Unity.Mathematics.math;
public class CurveField : MonoBehaviour
{
public int Segments = 16;
public int SigDigs = 3;
public TextMeshProUGUI Title;
public TextMeshProUGUI MinLabel;
public TextMeshProUGUI MidLabel;
public TextMeshProUGUI MaxLabel;
public UILineRenderer Line;
public Image CurrentX;
public Image CurrentY;
private BezierCurve _curve;
//private Func<float, string> _xFunc;
public void SetCurrent(float x)
{
CurrentX.gameObject.SetActive(true);
CurrentY.gameObject.SetActive(true);
var xrect = CurrentX.GetComponent<RectTransform>();
var yrect = CurrentY.GetComponent<RectTransform>();
var y = _curve.Evaluate(x);
xrect.anchorMin = new Vector2(x, 0);
xrect.anchorMax = new Vector2(x, y);
yrect.anchorMin = new Vector2(x, y);
yrect.anchorMax = new Vector2(x, y);
}
public void Show(string label, BezierCurve curve, Func<float, string> xFunc, bool showMax = false)
{
_curve = curve;
//_xFunc = xFunc;
CurrentX.gameObject.SetActive(false);
CurrentY.gameObject.SetActive(false);
Title.text = label;
var points = new List<Vector2>();
var keys = curve.Keys.Select(v => new Vector2(v.x, v.y));
if (curve.Keys[0].x > .01f) keys = keys.Prepend(new Vector2(0, curve.Keys[0].y));
if (curve.Keys[curve.Keys.Length-1].x < .99f) keys = keys.Append(new Vector2(1, curve.Keys[curve.Keys.Length-1].y));
var keysArray = keys.ToArray();
for (int i = 0; i < keysArray.Length - 1; i++)
{
for (int j = 0; j < Segments; j++)
{
var x = lerp(keysArray[i].x, keysArray[i + 1].x, (float) j / Segments);
points.Add(new Vector2(x, curve.Evaluate(x)));
}
}
points.Add(new Vector2(1, curve.Evaluate(1)));
Line.Points = points.ToArray();
MinLabel.text = xFunc(0);
MaxLabel.text = xFunc(1);
if (showMax)
{
var midX = curve.Maximum;
MidLabel.text = xFunc(midX);
var rect = MidLabel.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(midX, rect.anchorMin.y);
rect.anchorMax = new Vector2(midX, rect.anchorMax.y);
}
else MidLabel.text = xFunc(.5f);
}
}

View file

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

View file

@ -0,0 +1,16 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class EnumField : MonoBehaviour
{
public TextMeshProUGUI Label;
public Button Dropdown;
public TextMeshProUGUI DropdownLabel;
}

View file

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

View file

@ -0,0 +1,17 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class IncrementField : MonoBehaviour
{
public TextMeshProUGUI Label;
public TextMeshProUGUI Value;
public Button Increment;
public Button Decrement;
}

View file

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

View file

@ -0,0 +1,14 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class InputField : MonoBehaviour
{
public TextMeshProUGUI Label;
public TMP_InputField Field;
}

View file

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

View file

@ -0,0 +1,89 @@
/* 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 TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PropertiesList : PropertiesPanel
{
public Image FoldoutIcon;
public float FoldoutRotationDamping;
public Button Button;
public VerticalLayoutGroup LayoutGroup;
public int FoldedPadding = -8;
public int ExpandedPadding = 8;
public event Action<bool> OnExpand;
private bool _expanded = false;
private float _targetFoldoutRotation = 0;
private float _foldoutRotation = 0;
public bool Expanded => _expanded;
public new void Awake()
{
Button.onClick.AddListener(ToggleExpand);
OnPropertyAdded += go => go.SetActive(_expanded);
//SetExpanded(true, true);
}
public override void Update()
{
RefreshValues();
_foldoutRotation =
Mathf.Lerp(_foldoutRotation, _targetFoldoutRotation, FoldoutRotationDamping * Time.deltaTime);
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
}
public void ToggleExpand() => SetExpanded(!_expanded, false);
public void SetExpanded(bool expanded, bool force)
{
_expanded = expanded;
var padding = LayoutGroup.padding;
padding = new RectOffset(padding.left, padding.right, padding.top, _expanded ? ExpandedPadding : FoldedPadding);
LayoutGroup.padding = padding;
foreach (var property in Properties) property.SetActive(_expanded);
_targetFoldoutRotation = _expanded ? -90 : 0;
if (force)
{
_foldoutRotation = _targetFoldoutRotation;
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
}
OnExpand?.Invoke(_expanded);
}
// public override PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
// {
// var prop = base.AddProperty(name, read, onClick, radio);
// prop.gameObject.SetActive(false);
// return prop;
// }
//
// public override PropertiesList AddList(string name)
// {
// var list = base.AddList(name);
// list.gameObject.SetActive(false);
// return list;
// }
//
// public override RectTransform AddSection(string name)
// {
// var section = base.AddSection(name);
// section.gameObject.SetActive(false);
// return section;
// }
//
// public override PropertyButton AddButton(string name, Action<PointerEventData> onClick)
// {
// var button = base.AddButton(name, onClick);
// button.gameObject.SetActive(false);
// return button;
// }
}

View file

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

View file

@ -0,0 +1,665 @@
/* 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 System.Linq;
using System.Reflection;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class PropertiesPanel : MonoBehaviour
{
public RectTransform Spacer;
public DropdownMenu Dropdown;
public TextMeshProUGUI Title;
public RectTransform Section;
public PropertiesList List;
public Property Property;
public PropertyLabel PropertyLabel;
public AttributeProperty Attribute;
public InputField InputField;
public RangedFloatField RangedFloatField;
public RangedFloatField ProgressField;
public EnumField EnumField;
public BoolField BoolField;
public PropertyButton PropertyButton;
public ButtonField ButtonField;
public IncrementField IncrementField;
public StatSheet StatSheet;
public CurveField CurveField;
public WeaponGroupAssignment WeaponGroupAssignment;
public RectTransform Content;
public RectTransform DragParent;
[HideInInspector] public ActionGameManager GameManager;
protected List<GameObject> Properties = new List<GameObject>();
protected event Action RefreshPropertyValues;
protected bool RadioSelection = false;
private RectTransform _dragObject;
protected event Action<GameObject> OnPropertyAdded;
protected Action OnPropertiesChanged;
public int Children => Properties.Count;
public void Awake()
{
OnPropertyAdded += go => go.SetActive(true);
}
public virtual void Update()
{
RefreshValues();
}
private void OnDestroy()
{
}
// private void OnDisable()
// {
// RemoveListener();
// }
public void Clear()
{
//RemoveListener();
foreach(var property in Properties)
Destroy(property);
Title.text = "Properties";
Properties.Clear();
RefreshPropertyValues = null;
RadioSelection = false;
}
public RectTransform AddSpacer()
{
var spacer = Instantiate(Spacer, Content ?? transform);
Properties.Add(spacer.gameObject);
OnPropertyAdded?.Invoke(spacer.gameObject);
return spacer;
}
public RectTransform AddSection(string name)
{
var section = Instantiate(Section, Content ?? transform);
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
Properties.Add(section.gameObject);
OnPropertyAdded?.Invoke(section.gameObject);
return section;
}
public Property AddProperty(Func<string> read)
{
if (read == null) throw new ArgumentException("Attempted to add property with null read function!");
var property = Instantiate(Property, Content ?? transform);
property.Label.text = read();
RefreshPropertyValues += () => property.Label.text = read();
Properties.Add(property.gameObject);
OnPropertyAdded?.Invoke(property.gameObject);
return property;
}
public Property AddProperty(string name, Func<string> read = null)
{
Property property;
if(read != null)
property = Instantiate(PropertyLabel, Content ?? transform);
else
property = Instantiate(Property, Content ?? transform);
property.Label.text = name;
if (read != null)
RefreshPropertyValues += () => ((PropertyLabel) property).Value.text = read.Invoke();
Properties.Add(property.gameObject);
OnPropertyAdded?.Invoke(property.gameObject);
return property;
}
public StatSheet AddStatSheet()
{
var sheet = Instantiate(StatSheet, Content ?? transform);
Properties.Add(sheet.gameObject);
OnPropertyAdded?.Invoke(sheet.gameObject);
RefreshPropertyValues += () => sheet.RefreshValues();
return sheet;
}
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(List, Content ?? transform);
list.GameManager = GameManager;
list.Dropdown = Dropdown;
list.Title.text = name;
// foreach (var element in elements)
// {
// var item = Instantiate(PropertyPrefab, list);
// item.Name.text = element.Item1;
// item.Value.text = element.Item2();
// item.ValueFunction = element.Item2;
// Properties.Add(item.gameObject);
// }
//RefreshPropertyValues += () => list.RefreshValues();
Properties.Add(list.gameObject);
OnPropertyAdded?.Invoke(list.gameObject);
return list;
}
public AttributeProperty AddPersonalityProperty(PersonalityAttribute attribute, Func<float> read)
{
var attributeInstance = Instantiate(Attribute, Content ?? transform);
attributeInstance.Title.text = attribute.Name;
attributeInstance.HighLabel.text = attribute.HighName;
attributeInstance.LowLabel.text = attribute.LowName;
RefreshPropertyValues += () => attributeInstance.Slider.value = read();
Properties.Add(attributeInstance.gameObject);
OnPropertyAdded?.Invoke(attributeInstance.gameObject);
return attributeInstance;
}
public CurveField AddCurveField()
{
var curveInstance = Instantiate(CurveField, Content ?? transform);
Properties.Add(curveInstance.gameObject);
return curveInstance;
}
public virtual PropertyButton AddButton(string name, Action onClick)
{
var button = Instantiate(PropertyButton, Content ?? transform);
button.Label.text = name;
button.Button.interactable = onClick != null;
button.Button.onClick.AddListener(() => onClick());
Properties.Add(button.gameObject);
OnPropertyAdded?.Invoke(button.gameObject);
return button;
}
public void AddButton(string name, string label, Action onClick)
{
var button = Instantiate(ButtonField, Content ?? transform);
button.Label.text = name;
button.ButtonLabel.text = label;
button.Button.interactable = onClick != null;
button.Button.onClick.AddListener(() => onClick());
Properties.Add(button.gameObject);
OnPropertyAdded?.Invoke(button.gameObject);
}
public void AddField(string name, Func<string> read, Action<string> write)
{
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.Standard;
field.Field.onValueChanged.AddListener(val => write(val));
// field.Field.text = read();
RefreshPropertyValues += () =>
{
var s = read();
if (field.Field.text != s)
{
field.Field.text = s;
field.gameObject.SetActive(false);
Observable.NextFrame().Subscribe(_ =>
{
if(field != null)
OnPropertyAdded?.Invoke(field.gameObject);
});
}
};
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<float> read, Action<float> write)
{
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
RefreshPropertyValues += () =>
{
var s = read().ToString(CultureInfo.InvariantCulture);
if (field.Field.text != s)
{
field.Field.text = s;
field.gameObject.SetActive(false);
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
}
};
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<int> read, Action<int> write)
{
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
RefreshPropertyValues += () =>
{
var s = read().ToString(CultureInfo.InvariantCulture);
if (field.Field.text != s)
{
field.Field.text = s;
field.gameObject.SetActive(false);
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
}
};
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddIncrementField(string name, Func<int> read, Action<int> write, Func<int> min, Func<int> max)
{
var field = Instantiate(IncrementField, Content ?? transform);
field.Label.text = name;
field.Increment.onClick.AddListener(() => write(read() + 1));
field.Decrement.onClick.AddListener(() => write(read() - 1));
RefreshPropertyValues += () =>
{
var val = read();
var minval = min();
var maxval = max();
if (val < minval || val > maxval)
write(val = clamp(val, minval, maxval));
field.Value.text = val.ToString(CultureInfo.InvariantCulture);
field.Increment.interactable = val == maxval;
field.Decrement.interactable = val == minval;
};
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
{
var field = Instantiate(RangedFloatField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = false;
field.Slider.minValue = min;
field.Slider.maxValue = max;
field.Slider.onValueChanged.AddListener(val => write(val));
RefreshPropertyValues += () => field.Slider.value = read();
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddProgressField(string name, Func<float> read)
{
var field = Instantiate(ProgressField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = false;
field.Slider.minValue = 0;
field.Slider.maxValue = 1;
//field.Slider.onValueChanged.AddListener(val => write(val));
RefreshPropertyValues += () => field.Slider.value = read();
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
{
var field = Instantiate(RangedFloatField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = true;
field.Slider.minValue = min;
field.Slider.maxValue = max;
field.Slider.onValueChanged.AddListener(val => write(Mathf.RoundToInt(val)));
RefreshPropertyValues += () => field.Slider.value = read();
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<bool> read, Action<bool> write)
{
var field = Instantiate(BoolField, Content ?? transform);
field.Label.text = name;
field.Toggle.onValueChanged.AddListener(val => write(val));
RefreshPropertyValues += () => field.Toggle.isOn = read();
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
{
var field = Instantiate(EnumField, Content ?? transform);
field.Label.text = name;
field.Dropdown.onClick.AddListener(() =>
{
var selected = read();
Dropdown.gameObject.SetActive(true);
Dropdown.Clear();
for (int i = 0; i < enumOptions.Length; i++)
{
var index = i;
Dropdown.AddOption(enumOptions[i], () => write(index), index == selected);
}
Dropdown.Show((RectTransform) field.Dropdown.transform);
});
RefreshPropertyValues += () => field.DropdownLabel.text = enumOptions[read()];
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
// public void Inspect(Entity entity)
// {
// Clear();
// Title.text = entity.Name;
// var hullData = Context.GetData(entity.Hull) as HullData;
// AddSection(
// hullData.HullType == HullType.Ship ? "Ship" :
// hullData.HullType == HullType.Station ? "Station" :
// "Platform");
// //AddList(hullData.Name).Inspect(hull, entity);
// //PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
// AddEntityProperties(entity);
// //cargoList.SetExpanded(false,true);
//
// RefreshValues();
// }
// private void AddEntityProperties(Entity entity)
// {
// AddField("Name", () => entity.Name, name => entity.Name = name);
// AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
// }
private void AddItemProperties(ItemInstance item)
{
var data = item.Data.Value;
AddProperty(data.Description);
if (item is SimpleCommodity simpleCommodity)
AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
var sheet = AddStatSheet();
var manufacturer = ActionGameManager.CultCache.Get<Faction>(data.Manufacturer);
sheet.AddStat("Manufacturer", () => manufacturer?.Name ?? "GameCult");
sheet.AddStat("Mass", () => ActionGameManager.PlayerSettings.Format(GameManager.ItemManager.GetMass(item)));
//AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
}
private void AddEquippableItemProperties(EquippableItem item, Func<PerformanceStat, float> statValueFunction)
{
if (item.Durability < .01f)
{
return;
}
var gearData = GameManager.ItemManager.GetData(item);
var sheet = AddStatSheet();
foreach (var behavior in gearData.Behaviors)
{
if (behavior is StatModifierData statMod)
{
sheet.AddStat($"{statMod.Stat.Target.SplitCamelCase()}:{statMod.Stat.Stat.SplitCamelCase()}", () => $"{(statMod.Type == StatModifierType.Constant ? "+" : "x")}{ActionGameManager.PlayerSettings.Format(statValueFunction(statMod.Modifier))}");
}
else
{
var type = behavior.GetType();
if (type.GetCustomAttribute(typeof(RuntimeInspectable)) == null) continue;
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
{
var fieldType = field.FieldType;
if (fieldType == typeof(float))
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{ActionGameManager.PlayerSettings.Format((float) field.GetValue(behavior))}");
else if (fieldType == typeof(int))
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{(int) field.GetValue(behavior)}");
else if (fieldType == typeof(PerformanceStat))
{
var stat = (PerformanceStat) field.GetValue(behavior);
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{ActionGameManager.PlayerSettings.Format(statValueFunction(stat))}");
}
}
}
}
if (gearData.Behaviors.FirstOrDefault(b => b is WeaponData) is WeaponData weapon)
{
var range = AddCurveField();
range.Show("Damage Range", weapon.DamageCurve, t => ActionGameManager.PlayerSettings.Format(lerp(statValueFunction(weapon.MinRange), statValueFunction(weapon.Range), t)));
}
}
private string GetTitle(EquippableItem item)
{
var data = item.Data.Value;
var (tier, upgrades) = GameManager.ItemManager.GetTier(item);
return
$"<color=#{ColorUtility.ToHtmlStringRGB(tier.Color.ToColor())}>{data.Name}</color><smallcaps><size=60%> ({tier.Name}{new string('+', upgrades)})";
}
public void Inspect(EquippedItem item)
{
Clear();
if (item?.EquippableItem == null) return;
Title.text = GetTitle(item.EquippableItem);
AddItemProperties(item.EquippableItem);
AddSpacer();
if (item.GetBehavior<Weapon>() != null)
{
var weaponGroups = Instantiate(WeaponGroupAssignment, Content ?? transform);
weaponGroups.Inspect(item);
var dragOffset = Vector2.zero;
Transform dragObject = null;
weaponGroups.OnBeginDragAsObservable().Subscribe(x =>
{
//Debug.Log($"Began dragging weapon group {x.group}");
GameManager.BeginDrag(new WeaponGroupDragObject(x.group));
dragObject = Instantiate(weaponGroups.Groups[x.group], DragParent, true).transform;
dragOffset = (Vector2)dragObject.position - x.pointerEventData.position;
});
weaponGroups.OnDragAsObservable().Subscribe(x =>
{
dragObject.position = x.pointerEventData.position + dragOffset;
});
weaponGroups.OnEndDragAsObservable().Subscribe(x =>
{
//Debug.Log($"Ended dragging weapon group {x.group}");
GameManager.EndDrag();
Destroy(dragObject.gameObject);
});
Properties.Add(weaponGroups.gameObject);
OnPropertyAdded?.Invoke(weaponGroups.gameObject);
}
var gearData = GameManager.ItemManager.GetData(item.EquippableItem);
var statusSheet = AddStatSheet();
if (item.EquippableItem.Durability < .01f)
statusSheet.AddStat("Durability", () => "Item Destroyed!");
else statusSheet.AddStat("Durability", () => $"{(int)(item.EquippableItem.Durability / gearData.Durability * 100)}%");
statusSheet.AddStat("Temperature", () => ActionGameManager.PlayerSettings.FormatTemperature(item.Temperature));
var heatCurve = AddCurveField();
heatCurve.Show(
"Thermal Performance",
gearData.HeatPerformanceCurve,
t => ActionGameManager.PlayerSettings.FormatTemperature(lerp(gearData.MinimumTemperature, gearData.MaximumTemperature, t)),
true);
RefreshPropertyValues += () => heatCurve.SetCurrent(unlerp(gearData.MinimumTemperature, gearData.MaximumTemperature, item.Temperature));
AddEquippableItemProperties(item.EquippableItem, item.Evaluate);
AddSpacer();
AddField("Override Shutdown", () => item.EquippableItem.OverrideShutdown, b => item.EquippableItem.OverrideShutdown = b);
foreach (var behavior in item.Behaviors)
{
switch (behavior)
{
case Thermotoggle thermotoggle when thermotoggle.ThermotoggleData.Adjustable:
AddField("Target Temperature",
() => thermotoggle.TargetTemperature,
temp => thermotoggle.TargetTemperature = temp);
break;
}
}
RefreshValues();
}
public void Inspect(ItemInstance item)
{
Clear();
AddItemProperties(item);
if (item is EquippableItem gear)
{
Title.text = GetTitle(gear);
AddSpacer();
var gearData = GameManager.ItemManager.GetData(gear);
var statusSheet = AddStatSheet();
statusSheet.AddStat("Durability", () => $"{(int)(gear.Durability / gearData.Durability * 100)}%");
var heatCurve = AddCurveField();
heatCurve.Show(
"Thermal Performance",
gearData.HeatPerformanceCurve,
t => ActionGameManager.PlayerSettings.FormatTemperature(lerp(gearData.MinimumTemperature, gearData.MaximumTemperature, t)),
true);
AddEquippableItemProperties(gear, stat => GameManager.ItemManager.Evaluate(stat, gear));
}
RefreshValues();
}
public void Inspect(ItemData data)
{
AddProperty("Type", () => data.Name);
AddProperty(data.Description).Label.fontStyle = FontStyles.Normal;
if (data is EquippableItemData gearData)
{
AddProperty("Durability", () => ActionGameManager.PlayerSettings.Format(gearData.Durability));
var sheet = AddStatSheet();
foreach (var behavior in gearData.Behaviors)
{
if (behavior is StatModifierData statMod)
{
if(Math.Abs(statMod.Modifier.Min - statMod.Modifier.Max) < .001f)
sheet.AddStat($"{statMod.Stat.Target}:{statMod.Stat.Stat}", () => $"{(statMod.Type == StatModifierType.Constant ? "+" : "x")}{ActionGameManager.PlayerSettings.Format(statMod.Modifier.Min)}");
else
sheet.AddStat($"{statMod.Stat.Target}:{statMod.Stat.Stat}", () => $"{(statMod.Type == StatModifierType.Constant ? "+" : "x")}{ActionGameManager.PlayerSettings.Format(statMod.Modifier.Min)}-{ActionGameManager.PlayerSettings.Format(statMod.Modifier.Max)}");
}
var type = behavior.GetType();
if (type.GetCustomAttribute(typeof(RuntimeInspectable)) != null)
{
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
{
var fieldType = field.FieldType;
if (fieldType == typeof(float))
sheet.AddStat(field.Name, () => $"{ActionGameManager.PlayerSettings.Format((float) field.GetValue(behavior))}");
else if (fieldType == typeof(int))
sheet.AddStat(field.Name, () => $"{(int) field.GetValue(behavior)}");
else if (fieldType == typeof(PerformanceStat))
{
var stat = (PerformanceStat) field.GetValue(behavior);
if(Math.Abs(stat.Min - stat.Max) < .001f)
sheet.AddStat(field.Name, () => $"{ActionGameManager.PlayerSettings.Format(stat.Min)}");
else
sheet.AddStat(field.Name, () => $"{ActionGameManager.PlayerSettings.Format(stat.Min)}-{ActionGameManager.PlayerSettings.Format(stat.Max)}");
}
}
}
}
}
}
// public void Inspect(object obj, bool inspectablesOnly = false, bool readWrite = false, bool topLevel = true)
// {
// if(topLevel)
// Clear();
//
// var fields = obj.GetType().GetFields();
// foreach (var field in fields)
// Inspect(obj, field, inspectablesOnly, readWrite);
//
// if(topLevel)
// foreach (var field in _propertyFields)
// field.transform.SetSiblingIndex(_propertyFields.IndexOf(field));
//
// RefreshValues();
// }
//
// public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false, bool readWrite = false)
// {
// var inspectable = field.GetCustomAttribute<InspectableFieldAttribute>();
// if (inspectable == null && inspectablesOnly) return;
// var type = field.FieldType;
//
// if (type == typeof(float))
// {
// if (readWrite)
// {
// var ranged = inspectable as RangedFloatInspectableAttribute;
// if (ranged != null)
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f),
// ranged.Min, ranged.Max);
// else
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f));
// } else Inspect(field.Name.SplitCamelCase(), () => ((float) field.GetValue(obj)).ToString("0.##"));
// }
// else if (type == typeof(int))
// {
// if (readWrite)
// {
// var ranged = inspectable as RangedIntInspectableAttribute;
// if (ranged != null)
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f),
// ranged.Min, ranged.Max);
// else
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f));
// } else Inspect(field.Name.SplitCamelCase(), () => ((int) field.GetValue(obj)).ToString());
// }
// else if (type.IsEnum)
// {
// if (readWrite)
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), i => field.SetValue(obj, i),
// Enum.GetNames(field.FieldType));
// else
// Inspect(field.Name.SplitCamelCase(), () => Enum.GetName(type, field.GetValue(obj)).SplitCamelCase());
// }
// else if (type == typeof(string))
// {
// if (readWrite)
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj), i => field.SetValue(obj, i));
// else
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj));
// }
// //else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
// else if (field.FieldType == typeof(bool)) Inspect(field.Name, () => (bool) field.GetValue(obj), b => field.SetValue(obj, b));
// else if (type.GetCustomAttribute<InspectableFieldAttribute>() != null)
// {
// if(!_propertyFields.Any() || !_propertyFields.Last().gameObject.name.ToUpper().Contains("DIVIDER"))
// _propertyFields.Add(Divider.Instantiate<Prototype>());
// Inspect(field.GetValue(obj), inspectablesOnly, readWrite, false);
// }
// else
// Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated.");
// }
public void RefreshValues()
{
RefreshPropertyValues?.Invoke();
}
}

View file

@ -0,0 +1,31 @@
fileFormatVersion: 2
guid: 8c2bf4a7080061d42a87046c37bf0c60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- Spacer: {instanceID: 0}
- Dropdown: {instanceID: 0}
- Title: {instanceID: 0}
- Section: {instanceID: 0}
- List: {instanceID: 0}
- Property: {instanceID: 0}
- PropertyLabel: {instanceID: 0}
- Attribute: {instanceID: 0}
- InputField: {instanceID: 0}
- RangedFloatField: {instanceID: 0}
- ProgressField: {instanceID: 0}
- EnumField: {instanceID: 0}
- BoolField: {instanceID: 0}
- PropertyButton: {instanceID: 0}
- ButtonField: {instanceID: 0}
- IncrementField: {instanceID: 0}
- StatSheet: {fileID: 3416329628306957711, guid: 4f75723ed178a084e813965e84825bd4,
type: 3}
- Content: {instanceID: 0}
- SelectedChild: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,13 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Property : MonoBehaviour
{
public TextMeshProUGUI Label;
}

View file

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

View file

@ -0,0 +1,13 @@
/* 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.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PropertyButton : Property
{
public Button Button;
}

View file

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

View file

@ -0,0 +1,14 @@
/* 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 TMPro;
using UnityEngine;
public class PropertyLabel : Property
{
public TextMeshProUGUI Value;
}

View file

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

View file

@ -0,0 +1,15 @@
/* 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.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class RangedFloatField : MonoBehaviour
{
public TextMeshProUGUI Label;
public Slider Slider;
}

View file

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

View file

@ -0,0 +1,24 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StatSheet : MonoBehaviour
{
public PropertyLabel StatPrefab;
private List<(PropertyLabel property, Func<string> value)> _stats = new List<(PropertyLabel property, Func<string> value)>();
public void AddStat(string label, Func<string> value)
{
var instance = Instantiate(StatPrefab, transform);
instance.Label.text = label;
_stats.Add((instance, value));
}
public void RefreshValues()
{
foreach(var stat in _stats)
stat.property.Value.text = stat.value();
}
}

View file

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