Super Sexy Properties Panel

Properties panel now allows nested lists with foldouts, item selection and click callbacks
Properties Panel UI has a new look
Refactored lambdas in control module code into methods for readability
This commit is contained in:
hyperion51 2020-05-31 03:10:11 +01:00
commit 50a8059ed4
43 changed files with 894 additions and 916 deletions

View file

@ -42,6 +42,8 @@ public class EntityTypeRestrictionAttribute : Attribute
}
}
public class RuntimeInspectable : Attribute { }
[AttributeUsage(AttributeTargets.Class)]
public class InspectableAttribute : Attribute { }

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10), RuntimeInspectable]
public class CooldownData : BehaviorData
{
[InspectableField, JsonProperty("cooldown"), Key(1)]
[InspectableField, JsonProperty("cooldown"), Key(1), RuntimeInspectable]
public PerformanceStat Cooldown = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(12)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(12), RuntimeInspectable]
public class EnergyDrawData : BehaviorData
{
[InspectableField, JsonProperty("draw"), Key(1)]
[InspectableField, JsonProperty("draw"), Key(1), RuntimeInspectable]
public PerformanceStat Draw = new PerformanceStat();
[InspectableField, JsonProperty("perSecond"), Key(2)]

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10), Inspectable]
public class HeatData : BehaviorData
{
[InspectableField, JsonProperty("heat"), Key(1)]
[InspectableField, JsonProperty("heat"), Key(1), RuntimeInspectable]
public PerformanceStat Heat = new PerformanceStat();
[InspectableField, JsonProperty("perSecond"), Key(2)]

View file

@ -4,10 +4,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5), RuntimeInspectable]
public class ItemUsageData : BehaviorData
{
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1)]
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1), RuntimeInspectable]
public Guid Item;
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -85,17 +85,7 @@ public class MiningController : ControllerBase, IBehavior, IPersistentBehavior,
else
{
_entity.SetMessage("Out of cargo space. Returning home to offload cargo.");
GoHome(() =>
{
var homeEntity = _context.Cache.Get<Entity>(HomeEntity);
if (!_entity.Cargo.ToArray().All(ii =>
_context.MoveCargo(_entity, homeEntity, _context.Cache.Get<ItemInstance>(ii))))
{
homeEntity.SetMessage("Colony is out of cargo space. Closing Mining Task.");
FinishTask();
_taskStarted = false;
}
});
GoHome(OnArriveHome);
}
}
}
@ -103,6 +93,17 @@ public class MiningController : ControllerBase, IBehavior, IPersistentBehavior,
return base.Update(delta);
}
private void OnArriveHome()
{
var homeEntity = _context.Cache.Get<Entity>(HomeEntity);
if (!_entity.Cargo.ToArray().All(ii => _context.MoveCargo(_entity, homeEntity, _context.Cache.Get<ItemInstance>(ii))))
{
homeEntity.SetMessage("Colony is out of cargo space. Closing Mining Task.");
FinishTask();
_taskStarted = false;
}
}
private void NextAsteroid()
{
var miningTask = _context.Cache.Get<Mining>(Task);

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class RadianceData : BehaviorData
{
[InspectableField, JsonProperty("radiance"), Key(1)]
[InspectableField, JsonProperty("radiance"), Key(1), RuntimeInspectable]
public PerformanceStat Radiance = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class RadiatorData : BehaviorData
{
[InspectableField, JsonProperty("emissivity"), Key(1)]
[InspectableField, JsonProperty("emissivity"), Key(1), RuntimeInspectable]
public PerformanceStat Emissivity = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -1,23 +1,23 @@
using MessagePack;
using Newtonsoft.Json;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ReactorData : BehaviorData
{
[InspectableField, JsonProperty("charge"), Key(1)]
[InspectableField, JsonProperty("charge"), Key(1), RuntimeInspectable]
public PerformanceStat Charge = new PerformanceStat();
[InspectableField, JsonProperty("capacitance"), Key(2)]
[InspectableField, JsonProperty("capacitance"), Key(2), RuntimeInspectable]
public PerformanceStat Capacitance = new PerformanceStat();
[InspectableField, JsonProperty("efficiency"), Key(3)]
[InspectableField, JsonProperty("efficiency"), Key(3), RuntimeInspectable]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("overload"), Key(4)]
[InspectableField, JsonProperty("overload"), Key(4), RuntimeInspectable]
public PerformanceStat OverloadEfficiency = new PerformanceStat();
[InspectableField, JsonProperty("underload"), Key(5)]
public PerformanceStat UnderloadRecovery = new PerformanceStat();
[InspectableField, JsonProperty("underload"), Key(5), RuntimeInspectable]
public PerformanceStat ThrottlingFactor = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
@ -55,7 +55,7 @@ public class Reactor : IBehavior
if (Entity.Energy > Capacitance)
{
Entity.AddHeat(-(Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Entity)));
Entity.AddHeat(-(Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item, Entity)));
Entity.Energy = Capacitance;
}

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ReflectorData : BehaviorData
{
[InspectableField, JsonProperty("crossSection"), Key(1)]
[InspectableField, JsonProperty("crossSection"), Key(1), RuntimeInspectable]
public PerformanceStat CrossSection = new PerformanceStat();
// [InspectableAnimationCurve, JsonProperty("visibility"), Key(1)]

View file

@ -5,16 +5,16 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ResourceScannerData : BehaviorData
{
[InspectableField, JsonProperty("range"), Key(1)]
[InspectableField, JsonProperty("range"), Key(1), RuntimeInspectable]
public PerformanceStat Range = new PerformanceStat();
[InspectableField, JsonProperty("minDensity"), Key(2)]
[InspectableField, JsonProperty("minDensity"), Key(2), RuntimeInspectable]
public PerformanceStat MinimumDensity = new PerformanceStat();
[InspectableField, JsonProperty("scanDuration"), Key(3)]
[InspectableField, JsonProperty("scanDuration"), Key(3), RuntimeInspectable]
public PerformanceStat ScanDuration = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -2,10 +2,10 @@
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class SensorData : BehaviorData
{
[InspectableField, JsonProperty("sensitivity"), Key(3)]
[InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable]
public PerformanceStat Sensitivity = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,13 +3,13 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ShieldData : BehaviorData
{
[InspectableField, JsonProperty("efficiency"), Key(1)]
[InspectableField, JsonProperty("efficiency"), Key(1), RuntimeInspectable]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("shielding"), Key(2)]
[InspectableField, JsonProperty("shielding"), Key(2), RuntimeInspectable]
public PerformanceStat Shielding = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22), RuntimeInspectable]
public class ThermotoggleData : BehaviorData
{
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1)]
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1), RuntimeInspectable]
public float TargetTemperature;
[InspectableField, JsonProperty("perSecond"), Key(2)]

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), RuntimeInspectable]
public class ThrusterData : BehaviorData
{
[InspectableField, JsonProperty("thrust"), Key(1)]
[InspectableField, JsonProperty("thrust"), Key(1), RuntimeInspectable]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(2)]

View file

@ -42,37 +42,54 @@ public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
{
if (!_taskStarted)
{
MoveTo(towingTask.Zone, () =>
{
_entity.SetMessage("Entering pickup phase.");
MoveTo(_context.Cache.Get<Entity>(towingTask.Station), true, () =>
{
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station] as OrbitalEntity;
_context.SetParent(target, _entity);
_entity.SetMessage("Entering delivery phase.");
MoveTo(() =>
{
var orbitParent = _context.GetOrbitPosition(towingTask.OrbitParent);
var parentToUs = _entity.Position - orbitParent;
return orbitParent + normalize(parentToUs) * towingTask.OrbitDistance;
}, () => _context.GetOrbitVelocity(towingTask.OrbitParent), () =>
{
_context.RemoveParent(target);
_entity.SetMessage("Target delivered. Returning Home.");
var orbit = _context.CreateOrbit(towingTask.Zone, towingTask.OrbitParent, _entity.Position);
target.OrbitData = orbit.ID;
FinishTask();
_taskStarted = false;
});
});
});
MoveTo(towingTask.Zone, OnZoneArrival);
_taskStarted = true;
}
}
return base.Update(delta);
}
void OnZoneArrival()
{
var towingTask = _context.Cache.Get<StationTowing>(Task);
_entity.SetMessage("Entering pickup phase.");
MoveTo(_context.Cache.Get<Entity>(towingTask.Station), true, OnPickup);
}
void OnPickup()
{
var towingTask = _context.Cache.Get<StationTowing>(Task);
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station] as OrbitalEntity;
_context.SetParent(target, _entity);
_entity.SetMessage("Entering delivery phase.");
MoveTo(() =>
{
var orbitParent = _context.GetOrbitPosition(towingTask.OrbitParent);
var parentToUs = _entity.Position - orbitParent;
return orbitParent + normalize(parentToUs) * towingTask.OrbitDistance;
}, () => _context.GetOrbitVelocity(towingTask.OrbitParent), OnDelivery);
}
void OnDelivery()
{
var towingTask = _context.Cache.Get<StationTowing>(Task);
var target = _context.ZoneEntities[_entity.Zone][towingTask.Station] as OrbitalEntity;
_context.RemoveParent(target);
_entity.SetMessage("Target delivered. Returning Home.");
var orbit = _context.CreateOrbit(towingTask.Zone, towingTask.OrbitParent, _entity.Position);
target.OrbitData = orbit.ID;
FinishTask();
_taskStarted = false;
}
public PersistentBehaviorData Store()
{

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class TurningData : BehaviorData
{
[InspectableField, JsonProperty("torque"), Key(1)]
[InspectableField, JsonProperty("torque"), Key(1), RuntimeInspectable]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(2)]

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class VelocityConversionData : BehaviorData
{
[InspectableField, JsonProperty("traction"), Key(1)]
[InspectableField, JsonProperty("traction"), Key(1), RuntimeInspectable]
public PerformanceStat Traction = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class VelocityLimitData : BehaviorData
{
[InspectableField, JsonProperty("topSpeed"), Key(1)]
[InspectableField, JsonProperty("topSpeed"), Key(1), RuntimeInspectable]
public PerformanceStat TopSpeed = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)

View file

@ -3,10 +3,10 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class VisibilityData : BehaviorData
{
[InspectableField, JsonProperty("visibility"), Key(1)]
[InspectableField, JsonProperty("visibility"), Key(1), RuntimeInspectable]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("visibilityDecay"), Key(2)]

View file

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text.RegularExpressions;
using LiteNetLib;
@ -47,6 +48,16 @@ public static class Extensions
"$1 $2"
);
}
public static string SignificantDigits(this float d, int digits=10)
{
int magnitude = (d == 0.0f) ? 0 : (int)Math.Floor(Math.Log10(Math.Abs(d))) + 1;
digits -= magnitude;
if (digits < 0)
digits = 0;
string fmt = "f" + digits.ToString();
return d.ToString(fmt);
}
private static Random? _random;
private static Random Random => (Random) (_random ?? (_random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue))));

View file

@ -160,6 +160,9 @@ public class GlobalData : DatabaseEntry
[InspectableField, JsonProperty("messageDuration"), Key(50)]
public float MessageDuration = 4f;
[InspectableField, JsonProperty("significantDigits"), Key(51)]
public int SignificantDigits = 3;
public float PlanetRadius(float mass)
{

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NaughtyAttributes;
using RethinkDb.Driver.Net;
using TMPro;
@ -178,7 +179,7 @@ public class StrategyGameManager : MonoBehaviour
}
}
CorpMenuContinueButton.OnClick += _ =>
CorpMenuContinueButton.OnClick += () =>
{
if (_selectedParent != null && !string.IsNullOrEmpty(CorpNameInputField.text))
{
@ -681,11 +682,14 @@ public class StrategyGameManager : MonoBehaviour
if(!detectedResources.Any())
PropertiesPanel.AddProperty("No resources detected", () => "");
else
PropertiesPanel.AddList("Resources", detectedResources.Select<KeyValuePair<Guid, float>, (string, Func<string>)>(resource =>
{
var list = PropertiesPanel.AddList("Resources");
foreach (var resource in detectedResources)
{
var itemData = _context.Cache.Get<SimpleCommodityData>(resource.Key);
return (itemData.Name, () => $"{resource.Value:0}");
}));
list.AddProperty(itemData.Name, () => $"{resource.Value:0}");
}
}
}
}
}
@ -700,18 +704,34 @@ public class StrategyGameManager : MonoBehaviour
hullData.HullType == HullType.Ship ? "Drone Ship" :
hullData.HullType == HullType.Station ? "Colony" :
"Weapons Platform");
PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
PropertiesPanel.AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity}");
PropertiesPanel.AddProperty("Mass", () => $"{entity.Mass}");
PopulateGearProperties(PropertiesPanel.AddList(hullData.Name), hull, entity);
//PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
PropertiesPanel.AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}");
PropertiesPanel.AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(_context.GlobalData.SignificantDigits)}");
PropertiesPanel.AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
PropertiesPanel.AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehaviors<Reactor>().First().Capacitance:0}");
PropertiesPanel.AddList("Gear", entity.EquippedItems.Select(g=>_context.Cache.Get<Gear>(g).ItemData.Name));
PropertiesPanel.AddList("Cargo", entity.Cargo.Select<Guid, (string, Func<string>)>(ii=>
var gearList = PropertiesPanel.AddList("Gear");
var equippedItems = entity.EquippedItems.Select(g => _context.Cache.Get<Gear>(g));
foreach(var gear in equippedItems)
PopulateGearProperties(gearList.AddList(gear.ItemData.Name), gear, entity);
// gearList.AddProperty(gear.ItemData.Name);
// var firstGear = equippedItems.First();
// PopulateGearProperties(gearList.AddList(firstGear.ItemData.Name), firstGear, entity);
if(!entity.Cargo.Any())
PropertiesPanel.AddProperty("No Cargo");
else
{
var itemInstance = _context.Cache.Get<ItemInstance>(ii);
var data = _context.Cache.Get<ItemData>(itemInstance.Data);
return (data.Name, () => itemInstance is SimpleCommodity simpleCommodity ? simpleCommodity.Quantity.ToString() : "");
}));
var cargoList = PropertiesPanel.AddList("Cargo");
foreach (var itemID in entity.Cargo)
{
var itemInstance = _context.Cache.Get<ItemInstance>(itemID);
var data = _context.Cache.Get<ItemData>(itemInstance.Data);
if(itemInstance is SimpleCommodity simpleCommodity)
cargoList.AddProperty(data.Name, () => simpleCommodity.Quantity.ToString());
else
cargoList.AddProperty(data.Name);
}
}
}
if (targetObject is ZoneData zone)
@ -723,6 +743,32 @@ public class StrategyGameManager : MonoBehaviour
}
}
void PopulateGearProperties(PropertiesList panel, Gear gear, Entity entity)
{
var data = gear.ItemData;
panel.AddProperty("Durability", () => $"{gear.Durability.SignificantDigits(_context.GlobalData.SignificantDigits)}/{_context.Evaluate(data.Durability, gear).SignificantDigits(_context.GlobalData.SignificantDigits)}");
foreach (var behavior in data.Behaviors)
{
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))
panel.AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(_context.GlobalData.SignificantDigits)}");
else if (fieldType == typeof(int))
panel.AddProperty(field.Name, () => $"{(int) field.GetValue(behavior)}");
else if (fieldType == typeof(PerformanceStat))
{
var stat = (PerformanceStat) field.GetValue(behavior);
panel.AddProperty(field.Name, () => $"{_context.Evaluate(stat, gear, entity).SignificantDigits(_context.GlobalData.SignificantDigits)}");
}
}
}
}
}
void PopulateGalaxy()
{
_galaxyPopulated = true;

View file

@ -337,18 +337,26 @@ public class TechTreeMsagl : MonoBehaviour
PropertiesPanel.AddProperty("Produces", () => $"{blueprint.Quantity} {Context.Cache.Get<ItemData>(blueprint.Item).Name}");
PropertiesPanel.AddProperty("Production Quality", () => $"{Mathf.RoundToInt(blueprint.Quality * 100)}%");
PropertiesPanel.AddProperty("Production Time", () => $"{blueprint.ProductionTime:0.##} MH");
PropertiesPanel.AddList("Ingredients", blueprint.Ingredients.Select(ingredient =>
var ingredientsList = PropertiesPanel.AddList("Ingredients");
foreach (var ingredient in blueprint.Ingredients)
{
var ingredientData = Context.Cache.Get<ItemData>(ingredient.Key);
return $"{ingredient.Value} {ingredientData.Name}";
}));
PropertiesPanel.AddList("Dependencies", blueprint.Dependencies.Select(dependency =>
ingredientsList.AddProperty(ingredientData.Name, () => ingredient.Value.ToString());
}
var dependenciesList = PropertiesPanel.AddList("Dependencies");
foreach (var dependency in blueprint.Dependencies)
{
var dependencyBlueprint = Context.Cache.Get<BlueprintData>(dependency);
return $"{dependencyBlueprint.Name}";
}));
PropertiesPanel.AddList("Descendants", Blueprints.Where(bp =>
bp.Dependencies.Any(dep => blueprint.ID == dep)).Select(descendant => $"{descendant.Name}"));
dependenciesList.AddProperty(dependencyBlueprint.Name);
}
var descendantsList = PropertiesPanel.AddList("Descendants");
foreach (var descendant in Blueprints.Where(bp => bp.Dependencies.Any(dep => blueprint.ID == dep)))
{
descendantsList.AddProperty(descendant.Name);
}
};
_techInstances.Add(tech.GetComponent<Prototype>());
}

View file

@ -8,12 +8,11 @@ using UnityEngine.UI;
public class FlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
public event Action<FlatButton> OnClick;
public event Action OnClick;
public float StateDamping;
// public RectTransform Tab;
public Image Fill;
public Image Outline;
public TextMeshProUGUI Label;
public VerticalLayoutGroup LabelLayout;
public FlatButtonState CurrentState = FlatButtonState.Unselected;
public bool DisableClickWhenSelected = true;
@ -50,7 +49,7 @@ public class FlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandl
{
Fill.color = ClickAppearance.FillColor;
Outline.color = ClickAppearance.OutlineColor;
OnClick?.Invoke(this);
OnClick?.Invoke();
}
}

View file

@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
public event Action OnClick;
public float StateDamping;
// public RectTransform Tab;
public Image Fill;
public FlatButtonState CurrentState = FlatButtonState.Unselected;
public bool DisableClickWhenSelected = true;
public Color UnselectedColor;
public Color SelectedColor;
public Color HoverColor;
public Color ClickColor;
public void OnPointerEnter(PointerEventData eventData)
{
if (OnClick != null && CurrentState == FlatButtonState.Unselected)
CurrentState = FlatButtonState.Hover;
}
public void OnPointerExit(PointerEventData eventData)
{
if (CurrentState == FlatButtonState.Hover)
CurrentState = FlatButtonState.Unselected;
}
public void OnPointerClick(PointerEventData eventData)
{
if (!DisableClickWhenSelected || CurrentState != FlatButtonState.Selected)
{
if (OnClick != null)
{
Fill.color = ClickColor;
OnClick();
}
}
}
private void Update()
{
Color appearance;
switch (CurrentState)
{
case FlatButtonState.Unselected:
appearance = UnselectedColor;
break;
case FlatButtonState.Selected:
appearance = SelectedColor;
break;
case FlatButtonState.Hover:
appearance = HoverColor;
break;
default:
appearance = Color.white;
break;
}
Fill.color = Color.Lerp(Fill.color, appearance, StateDamping * Time.deltaTime);
}
}

View file

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

View file

@ -24,7 +24,7 @@ public class LoginScreen : MonoBehaviour
LoginButton.CurrentState = FlatButtonState.Selected;
CultClient.AddMessageListener<LoginSuccessMessage>(success => SceneManager.LoadScene("Main"));
CultClient.OnError += s => Error.text = s;
RegisterButton.OnClick += _ =>
RegisterButton.OnClick += () =>
{
if(!CultClient.Connected)
CultClient.Connect(Server.text);
@ -42,7 +42,7 @@ public class LoginScreen : MonoBehaviour
RegisterButton.CurrentState = FlatButtonState.Selected;
}
};
LoginButton.OnClick += _ =>
LoginButton.OnClick += () =>
{
if(!CultClient.Connected)
CultClient.Connect(Server.text);

View file

@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PropertiesList : ReadOnlyPropertiesPanel
{
public Image FoldoutIcon;
public float FoldoutRotationDamping;
public FlatFlatButton Button;
public VerticalLayoutGroup LayoutGroup;
public int FoldedPadding = -8;
public int ExpandedPadding = 8;
private bool _expanded = false;
private float _targetFoldoutRotation = 0;
private float _foldoutRotation = 0;
public bool Expanded
{
set
{
_expanded = value;
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;
}
}
public void Start()
{
Button.OnClick += ToggleExpand;
}
public void ToggleExpand() => Expanded = !_expanded;
private void Update()
{
_foldoutRotation =
Mathf.Lerp(_foldoutRotation, _targetFoldoutRotation, FoldoutRotationDamping * Time.deltaTime);
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
}
public new PropertyLabel AddProperty(string name, Func<string> value = null, Action onClick = null)
{
var prop = base.AddProperty(name, value, onClick);
prop.gameObject.SetActive(false);
return prop;
}
public new PropertiesList AddList(string name)
{
var list = base.AddList(name);
list.gameObject.SetActive(false);
return list;
}
public new RectTransform AddSection(string name)
{
var section = base.AddSection(name);
section.gameObject.SetActive(false);
return section;
}
}

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

@ -9,9 +9,11 @@ public class PropertyLabel : MonoBehaviour
public TextMeshProUGUI Name;
public TextMeshProUGUI Value;
public Func<string> ValueFunction;
public FlatFlatButton Button;
private void Update()
{
Value.text = ValueFunction?.Invoke() ?? "";
if(ValueFunction != null)
Value.text = ValueFunction();
}
}

View file

@ -8,60 +8,67 @@ public class ReadOnlyPropertiesPanel : MonoBehaviour
{
public TextMeshProUGUI Title;
public RectTransform SectionPrefab;
public RectTransform ListPrefab;
public RectTransform ListItemPrefab;
public PropertyLabel ListPropertyPrefab;
public PropertiesList ListPrefab;
public PropertyLabel PropertyPrefab;
public bool ChildRadioSelection;
private List<GameObject> _properties = new List<GameObject>();
protected List<GameObject> Properties = new List<GameObject>();
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
protected FlatFlatButton SelectedChild;
public void Clear()
{
foreach(var property in _properties)
foreach(var property in Properties)
Destroy(property);
Properties.Clear();
Buttons.Clear();
SelectedChild = null;
}
public void AddProperty(string name, Func<string> value)
public PropertyLabel AddProperty(string name, Func<string> value = null, Action onClick = null)
{
var property = Instantiate(PropertyPrefab, transform);
property.Name.text = name;
property.Value.text = value();
property.Value.text = value?.Invoke() ?? "";
property.ValueFunction = value;
_properties.Add(property.gameObject);
if (ChildRadioSelection)
{
Buttons.Add(property.Button);
property.Button.OnClick += () =>
{
if (SelectedChild != null)
SelectedChild.CurrentState = FlatButtonState.Unselected;
SelectedChild = property.Button;
SelectedChild.CurrentState = FlatButtonState.Selected;
onClick?.Invoke();
};
}
else if(onClick!=null) property.Button.OnClick += onClick;
Properties.Add(property.gameObject);
return property;
}
public void AddSection(string name)
public RectTransform AddSection(string name)
{
var section = Instantiate(SectionPrefab, transform);
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
_properties.Add(section.gameObject);
Properties.Add(section.gameObject);
return section;
}
public void AddList(string name, IEnumerable<string> elements)
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(ListPrefab, transform);
list.GetComponentInChildren<TextMeshProUGUI>().text = name;
foreach (var element in elements)
{
var item = Instantiate(ListItemPrefab, list);
item.GetComponentInChildren<TextMeshProUGUI>().text = element;
_properties.Add(item.gameObject);
}
_properties.Add(list.gameObject);
}
public void AddList(string name, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(ListPrefab, transform);
list.GetComponentInChildren<TextMeshProUGUI>().text = name;
foreach (var element in elements)
{
var item = Instantiate(ListPropertyPrefab, list);
item.Name.text = element.Item1;
item.Value.text = element.Item2();
item.ValueFunction = element.Item2;
_properties.Add(item.gameObject);
}
_properties.Add(list.gameObject);
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);
// }
Properties.Add(list.gameObject);
return list;
}
}

View file

@ -15,7 +15,7 @@ public class TabGroup : MonoBehaviour
_tabButtons = GetComponentsInChildren<TabButton>();
foreach (var thisButton in _tabButtons)
{
thisButton.OnClick += button =>
thisButton.OnClick += () =>
{
if (_currentButton != null)
{