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)
{