Child Inventory Drag & Drop
Added child selection and child inventory panel to colony tab, and implemented drag and drop functionality between parent and child inventories
This commit is contained in:
parent
5766fe8eba
commit
7b3c0cad64
16 changed files with 1101 additions and 333 deletions
|
|
@ -1298,7 +1298,7 @@
|
|||
<e p="Extensions.cs" t="Include" />
|
||||
<e p="GameContext.cs" t="Include" />
|
||||
<e p="GlobalData.cs" t="Include" />
|
||||
<e p="IDynamicProperties.cs" t="Include" />
|
||||
<e p="IChangeSource.cs" t="Include" />
|
||||
<e p="ItemData.cs" t="Include" />
|
||||
<e p="ItemInstance.cs" t="Include" />
|
||||
<e p="JsonConverters.cs" t="Include" />
|
||||
|
|
|
|||
|
|
@ -257,13 +257,17 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
StateDamping: 10
|
||||
Fill: {fileID: 8035498868821314605}
|
||||
Label: {fileID: 0}
|
||||
CurrentState: 0
|
||||
DisableClickWhenSelected: 1
|
||||
DragObject: {fileID: 2677123916507168719}
|
||||
UnselectedColor: {r: 0, g: 0.4180913, b: 1, a: 0.15294118}
|
||||
SelectedColor: {r: 1, g: 0.44583336, b: 0.050000012, a: 0.65882355}
|
||||
HoverColor: {r: 0, g: 0.4180913, b: 1, a: 0.29803923}
|
||||
ClickColor: {r: 0, g: 0.4180913, b: 1, a: 0.7490196}
|
||||
DisabledColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
EnabledTextColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
DisabledTextColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
--- !u!114 &2227437186655761277
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Padding:
|
||||
m_Left: 32
|
||||
m_Left: 16
|
||||
m_Right: 8
|
||||
m_Top: 40
|
||||
m_Bottom: -8
|
||||
|
|
@ -300,6 +300,8 @@ MonoBehaviour:
|
|||
type: 3}
|
||||
ButtonField: {fileID: 6566784227922820057, guid: 6db1feb4cda7b8c419384cd42c85a5c4,
|
||||
type: 3}
|
||||
IncrementField: {fileID: 5486709585343280439, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
|
||||
type: 3}
|
||||
SelectedChild: {fileID: 0}
|
||||
FoldoutIcon: {fileID: 6485458701090981364}
|
||||
FoldoutRotationDamping: 10
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Padding:
|
||||
m_Left: 32
|
||||
m_Left: 16
|
||||
m_Right: 8
|
||||
m_Top: 40
|
||||
m_Bottom: -8
|
||||
|
|
@ -300,6 +300,8 @@ MonoBehaviour:
|
|||
type: 3}
|
||||
ButtonField: {fileID: 6566784227922820057, guid: 6db1feb4cda7b8c419384cd42c85a5c4,
|
||||
type: 3}
|
||||
IncrementField: {fileID: 5486709585343280439, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
|
||||
type: 3}
|
||||
SelectedChild: {fileID: 0}
|
||||
FoldoutIcon: {fileID: 6485458701090981364}
|
||||
FoldoutRotationDamping: 10
|
||||
|
|
|
|||
|
|
@ -333,13 +333,17 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
StateDamping: 10
|
||||
Fill: {fileID: 3871492197986661902}
|
||||
Label: {fileID: 0}
|
||||
CurrentState: 0
|
||||
DisableClickWhenSelected: 1
|
||||
DragObject: {fileID: 9159917045172241900}
|
||||
UnselectedColor: {r: 0, g: 0.4180913, b: 1, a: 0.15294118}
|
||||
SelectedColor: {r: 1, g: 0.44583336, b: 0.050000012, a: 0.65882355}
|
||||
HoverColor: {r: 0, g: 0.4180913, b: 1, a: 0.29803923}
|
||||
ClickColor: {r: 0, g: 0.4180913, b: 1, a: 0.7490196}
|
||||
DisabledColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
EnabledTextColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
DisabledTextColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
--- !u!114 &9159917045172241898
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3,13 +3,13 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22), RuntimeInspectable]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)]
|
||||
public class ThermotoggleData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1), RuntimeInspectable]
|
||||
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1)]
|
||||
public float TargetTemperature;
|
||||
|
||||
[InspectableField, JsonProperty("perSecond"), Key(2)]
|
||||
[InspectableField, JsonProperty("highPass"), Key(2)]
|
||||
public bool HighPass;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
[IgnoreMember] public float ThermalMass { get; private set; }
|
||||
[IgnoreMember] public float Visibility => VisibilitySources.Values.Sum();
|
||||
|
||||
public class InventoryEvent : IDynamicProperties
|
||||
public class ChangeEvent : IChangeSource
|
||||
{
|
||||
public event Action OnChanged;
|
||||
|
||||
|
|
@ -93,9 +93,12 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
}
|
||||
}
|
||||
private bool _cargoChanged;
|
||||
public InventoryEvent CargoEvent = new InventoryEvent();
|
||||
public ChangeEvent CargoEvent = new ChangeEvent();
|
||||
|
||||
private bool _gearChanged;
|
||||
public InventoryEvent GearEvent = new InventoryEvent();
|
||||
public ChangeEvent GearEvent = new ChangeEvent();
|
||||
|
||||
public ChangeEvent ChildEvent = new ChangeEvent();
|
||||
|
||||
public float Capacity
|
||||
{
|
||||
|
|
@ -196,16 +199,24 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
|
||||
public void Equip(Gear gear, Hardpoint hardpoint)
|
||||
public void Unequip(Hardpoint hardpoint)
|
||||
{
|
||||
// Hardpoint is occupied, remove existing item from gear list
|
||||
if (hardpoint.Gear != null)
|
||||
{
|
||||
Gear.Remove(hardpoint.Gear.ID);
|
||||
Cargo.Add(hardpoint.Gear.ID);
|
||||
hardpoint.Gear = null;
|
||||
_cargoChanged = true;
|
||||
_gearChanged = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Equip(Gear gear, Hardpoint hardpoint)
|
||||
{
|
||||
// Hardpoint is occupied, remove existing item from gear list
|
||||
if (hardpoint.Gear != null) Unequip(hardpoint);
|
||||
if (Cargo.Contains(gear.ID)) Cargo.Remove(gear.ID);
|
||||
|
||||
hardpoint.Gear = gear;
|
||||
HydrateHardpoint(hardpoint);
|
||||
_gearChanged = true;
|
||||
|
|
@ -307,6 +318,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Data = item.Data,
|
||||
Quantity = quantity
|
||||
};
|
||||
Context.Cache.Add(newSimpleCommodity);
|
||||
item.Quantity -= quantity;
|
||||
item = newSimpleCommodity;
|
||||
}
|
||||
|
|
@ -324,6 +336,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Mass += entity.Mass;
|
||||
ThermalMass += entity.ThermalMass;
|
||||
Children.Add(entity.ID);
|
||||
ChildEvent.Change();
|
||||
}
|
||||
|
||||
public void RemoveChild(Entity entity)
|
||||
|
|
@ -331,6 +344,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Mass -= entity.Mass;
|
||||
ThermalMass -= entity.ThermalMass;
|
||||
Children.Remove(entity.ID);
|
||||
ChildEvent.Change();
|
||||
}
|
||||
|
||||
public Guid Build(BlueprintData blueprint, float quality, string name, bool direct = false)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
|
||||
public interface IDynamicProperties
|
||||
public interface IChangeSource
|
||||
{
|
||||
event Action OnChanged;
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ public class SimpleCommodity : ItemInstance
|
|||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class Gear : CraftedItemInstance, IDynamicProperties
|
||||
public class Gear : CraftedItemInstance, IChangeSource
|
||||
{
|
||||
[JsonProperty("durability"), Key(7)] public float Durability;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ using System.Reflection;
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class ColonyTab : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public PropertiesPanel General;
|
||||
public PropertiesPanel Inventory;
|
||||
public PropertiesPanel ChildInventory;
|
||||
public PropertiesPanel Details;
|
||||
public ContextMenu ContextMenu;
|
||||
|
||||
|
|
@ -24,218 +27,337 @@ public class ColonyTab : MonoBehaviour
|
|||
_context = value;
|
||||
General.Context = value;
|
||||
Inventory.Context = value;
|
||||
ChildInventory.Context = value;
|
||||
Details.Context = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Guid _selectedColony;
|
||||
private GameContext _context;
|
||||
private Hardpoint _selectedHardpoint;
|
||||
private IDynamicProperties HardpointChange;
|
||||
private IDynamicProperties CargoChange;
|
||||
private Action OnHardpointsChanged;
|
||||
private Action OnCargoChanged;
|
||||
private Entity _parentEntity;
|
||||
private Entity _selectedChild;
|
||||
|
||||
private IChangeSource _colonyGearChange;
|
||||
private IChangeSource _colonyCargoChange;
|
||||
private Action _onColonyInventoryChanged;
|
||||
|
||||
private IChangeSource _childGearChange;
|
||||
private IChangeSource _childCargoChange;
|
||||
private Action _onChildInventoryChanged;
|
||||
|
||||
public void Open(Guid colony)
|
||||
{
|
||||
_selectedColony = colony;
|
||||
_selectedHardpoint = null;
|
||||
|
||||
var entity = Context.Cache.Get<Entity>(_selectedColony);
|
||||
_parentEntity = Context.Cache.Get<Entity>(colony);
|
||||
|
||||
Title.text = entity.Name;
|
||||
Title.text = _parentEntity.Name;
|
||||
|
||||
UpdateGeneral(entity);
|
||||
UpdateGeneral(_parentEntity);
|
||||
|
||||
UpdateInventory(entity);
|
||||
UpdateInventory(_parentEntity, Inventory);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
HardpointChange.OnChanged -= OnHardpointsChanged;
|
||||
CargoChange.OnChanged -= OnCargoChanged;
|
||||
if (_onColonyInventoryChanged == null)
|
||||
return;
|
||||
_colonyGearChange.OnChanged -= _onColonyInventoryChanged;
|
||||
_colonyCargoChange.OnChanged -= _onColonyInventoryChanged;
|
||||
Details.Clear();
|
||||
DeselectChild();
|
||||
}
|
||||
|
||||
private void DeselectChild()
|
||||
{
|
||||
if (_onChildInventoryChanged == null)
|
||||
return;
|
||||
_childGearChange.OnChanged -= _onChildInventoryChanged;
|
||||
_childGearChange.OnChanged -= _onChildInventoryChanged;
|
||||
ChildInventory.Clear();
|
||||
}
|
||||
|
||||
public void UpdateGeneral(Entity entity)
|
||||
{
|
||||
General.Clear();
|
||||
|
||||
General.AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}");
|
||||
General.AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
General.AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
|
||||
General.AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehaviors<Reactor>().First().Capacitance:0}");
|
||||
General.AddEntityProperties(entity);
|
||||
General.AddProperty("Assigned Population", () => $"{entity.AssignedPopulation}/{entity.Population}");
|
||||
|
||||
var personalityList = General.AddList("Personality");
|
||||
foreach (var attribute in entity.Personality.Keys)
|
||||
personalityList.AddPersonalityProperty(Context.Cache.Get<PersonalityAttribute>(attribute),
|
||||
() => entity.Personality[attribute]);
|
||||
personalityList.SetExpanded(false, true);
|
||||
|
||||
var childList = General.AddList("Children");
|
||||
childList.InspectChildren(entity, child =>
|
||||
{
|
||||
_selectedChild = child;
|
||||
UpdateInventory(child, ChildInventory);
|
||||
});
|
||||
childList.SetExpanded(false, true);
|
||||
|
||||
General.RefreshValues();
|
||||
}
|
||||
|
||||
public void UpdateInventory(Entity entity)
|
||||
public void UpdateInventory(Entity entity, PropertiesPanel panel)
|
||||
{
|
||||
if (panel == Inventory)
|
||||
{
|
||||
_colonyGearChange = entity.GearEvent;
|
||||
_colonyCargoChange = entity.CargoEvent;
|
||||
_onColonyInventoryChanged = () => RefreshInventory(entity, panel);
|
||||
_colonyGearChange.OnChanged += _onColonyInventoryChanged;
|
||||
_colonyCargoChange.OnChanged += _onColonyInventoryChanged;
|
||||
RefreshInventory(entity, panel);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeselectChild();
|
||||
_childGearChange = entity.GearEvent;
|
||||
_childCargoChange = entity.CargoEvent;
|
||||
_onChildInventoryChanged = () => RefreshInventory(entity, panel, true);
|
||||
_childGearChange.OnChanged += _onChildInventoryChanged;
|
||||
_childCargoChange.OnChanged += _onChildInventoryChanged;
|
||||
RefreshInventory(entity, panel, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RefreshInventory(Entity entity, PropertiesPanel panel, bool child = false)
|
||||
{
|
||||
//Debug.Log("Refreshing Inventory!");
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
var blueprints = corporation.UnlockedBlueprints.Select(id => Context.Cache.Get<BlueprintData>(id));
|
||||
var hull = Context.Cache.Get<Gear>(entity.Hull);
|
||||
var hullData = Context.Cache.Get<HullData>(hull.Data);
|
||||
|
||||
OnHardpointsChanged = RefreshInventory;
|
||||
HardpointChange = entity.GearEvent;
|
||||
HardpointChange.OnChanged += OnHardpointsChanged;
|
||||
OnCargoChanged = RefreshInventory;
|
||||
CargoChange = entity.CargoEvent;
|
||||
CargoChange.OnChanged += OnCargoChanged;
|
||||
|
||||
RefreshInventory();
|
||||
|
||||
void RefreshInventory()
|
||||
// Create item data mapping for cargo
|
||||
var cargoData = entity.Cargo.ToDictionary(id => _context.Cache.Get<ItemInstance>(id),
|
||||
id => Context.Cache.Get<ItemData>(_context.Cache.Get<ItemInstance>(id).Data));
|
||||
|
||||
panel.Clear();
|
||||
|
||||
if (child)
|
||||
{
|
||||
//Debug.Log("Refreshing Inventory!");
|
||||
panel.Title.text = entity.Name;
|
||||
panel.AddSection("General");
|
||||
panel.AddEntityProperties(entity);
|
||||
}
|
||||
|
||||
panel.AddSection("Hardpoints");
|
||||
var incompleteGearList = entity.IncompleteGear.Keys
|
||||
.Select(id => Context.Cache.Get<Gear>(id))
|
||||
.ToList();
|
||||
// Skip first hardpoint, that one is always the hull
|
||||
foreach (var hardpoint in entity.Hardpoints.Skip(1))
|
||||
{
|
||||
// These are the items in the inventory which can be equipped to the current hardpoint
|
||||
var matchingCargoGear = cargoData
|
||||
.Where(x =>
|
||||
x.Value is GearData gearData &&
|
||||
gearData.HardpointType == hardpoint.HardpointData.Type)
|
||||
.Select(x => x.Key as Gear)
|
||||
.ToArray();
|
||||
|
||||
// Create item data mapping for cargo
|
||||
var cargoData = entity.Cargo.ToDictionary(id => _context.Cache.Get<ItemInstance>(id),
|
||||
id => Context.Cache.Get<ItemData>(_context.Cache.Get<ItemInstance>(id).Data));
|
||||
|
||||
Inventory.Clear();
|
||||
Inventory.AddSection("Hardpoints");
|
||||
var incompleteGearList = entity.IncompleteGear.Keys
|
||||
.Select(id => Context.Cache.Get<Gear>(id))
|
||||
.ToList();
|
||||
// Skip first hardpoint, that one is always the hull
|
||||
foreach (var hardpoint in entity.Hardpoints.Skip(1))
|
||||
// Hardpoint has no gear assigned to it
|
||||
if (hardpoint.Gear == null)
|
||||
{
|
||||
// These are the items in the inventory which can be equipped to the current hardpoint
|
||||
var matchingCargoGear = cargoData
|
||||
.Where(x =>
|
||||
x.Value is GearData gearData &&
|
||||
gearData.HardpointType == hardpoint.HardpointData.Type)
|
||||
.Select(x => x.Key as Gear)
|
||||
.ToArray();
|
||||
|
||||
// Hardpoint has no gear assigned to it
|
||||
if (hardpoint.Gear == null)
|
||||
// Check whether we're currently building some gear for this hardpoint
|
||||
var incompleteGear = incompleteGearList.FirstOrDefault(g => g.ItemData.HardpointType == hardpoint.HardpointData.Type);
|
||||
|
||||
// We're building something for this hardpoint, show a progress bar!
|
||||
if (incompleteGear != null)
|
||||
{
|
||||
// Check whether we're currently building some gear for this hardpoint
|
||||
var incompleteGear = incompleteGearList.FirstOrDefault(g => g.ItemData.HardpointType == hardpoint.HardpointData.Type);
|
||||
incompleteGearList.Remove(incompleteGear);
|
||||
panel.AddProgressField(incompleteGear.Name, () =>
|
||||
{
|
||||
var productionTime = _context.Cache.Get<BlueprintData>(incompleteGear.Blueprint).ProductionTime;
|
||||
return (productionTime - (float) entity.IncompleteGear[incompleteGear.ID]) / productionTime;
|
||||
});
|
||||
}
|
||||
else // We're not building anything
|
||||
{
|
||||
// These are the blueprints we could build onto this hardpoint directly
|
||||
var matchingBlueprints = blueprints.Where(bp =>
|
||||
bp.FactoryItem == Guid.Empty &&
|
||||
Context.Cache.Get<ItemData>(bp.Item) is GearData gearData &&
|
||||
gearData.HardpointType == hardpoint.HardpointData.Type).ToArray();
|
||||
|
||||
// We're building something for this hardpoint, show a progress bar!
|
||||
if (incompleteGear != null)
|
||||
{
|
||||
incompleteGearList.Remove(incompleteGear);
|
||||
Inventory.AddProgressField(incompleteGear.Name, () =>
|
||||
Action<PointerEventData> onClick = null;
|
||||
if (matchingCargoGear.Any() || matchingBlueprints.Any())
|
||||
onClick = data =>
|
||||
{
|
||||
var productionTime = _context.Cache.Get<BlueprintData>(incompleteGear.Blueprint).ProductionTime;
|
||||
return (productionTime - (float) entity.IncompleteGear[incompleteGear.ID]) / productionTime;
|
||||
});
|
||||
}
|
||||
else // We're not building anything
|
||||
{
|
||||
// These are the blueprints we could build onto this hardpoint directly
|
||||
var matchingBlueprints = blueprints.Where(bp =>
|
||||
bp.FactoryItem == Guid.Empty &&
|
||||
Context.Cache.Get<ItemData>(bp.Item) is GearData gearData &&
|
||||
gearData.HardpointType == hardpoint.HardpointData.Type).ToArray();
|
||||
|
||||
Action<PointerEventData> onClick = null;
|
||||
if (matchingCargoGear.Any() || matchingBlueprints.Any())
|
||||
onClick = data =>
|
||||
if (data.button == PointerEventData.InputButton.Left)
|
||||
PopulateDetails(entity, matchingBlueprints);
|
||||
|
||||
else if (data.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
if (data.button == PointerEventData.InputButton.Left)
|
||||
PopulateDetails(entity, matchingBlueprints);
|
||||
|
||||
else if (data.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.Clear();
|
||||
if (matchingCargoGear.Any())
|
||||
ContextMenu.AddDropdown("Install", matchingCargoGear
|
||||
.Select<Gear, (string, Action, bool)>(gear => (gear.Name, () => entity.Equip(gear, hardpoint), true)));
|
||||
if (matchingBlueprints.Any())
|
||||
ContextMenu.AddDropdown("Build", matchingBlueprints
|
||||
.Select<BlueprintData, (string, Action, bool)>(blueprint =>
|
||||
(blueprint.Name, () =>
|
||||
entity.Build(blueprint, 1, _context.Cache.Get<ItemData>(blueprint.Item).Name, true),
|
||||
entity.GetBlueprintIngredients(blueprint, out _, out _))));
|
||||
ContextMenu.Show();
|
||||
}
|
||||
};
|
||||
Inventory.AddProperty($"Empty {Enum.GetName(typeof(HardpointType), hardpoint.HardpointData.Type)} Hardpoint", null, onClick, matchingBlueprints.Any());
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.Clear();
|
||||
if (matchingCargoGear.Any())
|
||||
ContextMenu.AddDropdown("Install", matchingCargoGear
|
||||
.Select<Gear, (string, Action, bool)>(gear => (gear.Name, () => entity.Equip(gear, hardpoint), true)));
|
||||
if (matchingBlueprints.Any())
|
||||
ContextMenu.AddDropdown("Build", matchingBlueprints
|
||||
.Select<BlueprintData, (string, Action, bool)>(blueprint =>
|
||||
(blueprint.Name, () =>
|
||||
entity.Build(blueprint, 1, _context.Cache.Get<ItemData>(blueprint.Item).Name, true),
|
||||
entity.GetBlueprintIngredients(blueprint, out _, out _))));
|
||||
ContextMenu.Show();
|
||||
}
|
||||
};
|
||||
panel.AddProperty($"Empty {Enum.GetName(typeof(HardpointType), hardpoint.HardpointData.Type)} Hardpoint", null, onClick, matchingBlueprints.Any());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = panel.AddProperty(hardpoint.Gear.Name, null, data =>
|
||||
{
|
||||
if (data.button == PointerEventData.InputButton.Left)
|
||||
{
|
||||
if (data.clickCount == 1)
|
||||
{
|
||||
_selectedHardpoint = hardpoint;
|
||||
Details.Inspect(entity, hardpoint);
|
||||
}
|
||||
|
||||
if (data.clickCount == 2)
|
||||
{
|
||||
entity.Unequip(hardpoint);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
prop.Button.DisableClickWhenSelected = false;
|
||||
|
||||
if (hardpoint == _selectedHardpoint)
|
||||
{
|
||||
panel.SelectedChild = prop.Button;
|
||||
prop.Button.CurrentState = FlatButtonState.Selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!entity.Cargo.Any())
|
||||
panel.AddSection("No Cargo");
|
||||
else
|
||||
{
|
||||
panel.AddSection("Cargo");
|
||||
foreach (var itemID in entity.Cargo.Where(id => Context.Cache.Get<ItemInstance>(id) is SimpleCommodity))
|
||||
{
|
||||
var simpleCommodity = Context.Cache.Get<SimpleCommodity>(itemID);
|
||||
var data = simpleCommodity.ItemData;
|
||||
panel.AddProperty(data.Name, () => simpleCommodity.Quantity.ToString(), eventData =>
|
||||
{
|
||||
Details.Clear();
|
||||
Details.RemoveListener();
|
||||
Details.AddItemProperties(entity, simpleCommodity);
|
||||
Details.RefreshValues();
|
||||
}, true).Button.DragSuccess = eventData =>
|
||||
{
|
||||
Entity targetEntity = null;
|
||||
if (panel == Inventory &&
|
||||
_selectedChild != null &&
|
||||
((RectTransform) ChildInventory.transform).ContainsWorldPoint(eventData.position))
|
||||
targetEntity = _selectedChild;
|
||||
else if (panel == ChildInventory &&
|
||||
((RectTransform) Inventory.transform).ContainsWorldPoint(eventData.position))
|
||||
targetEntity = _parentEntity;
|
||||
|
||||
if (targetEntity != null)
|
||||
{
|
||||
int quantity = min((int) ((targetEntity.Capacity - targetEntity.OccupiedCapacity) / simpleCommodity.ItemData.Size), simpleCommodity.Quantity);
|
||||
if (quantity > 0)
|
||||
{
|
||||
var newItem = entity.RemoveCargo(simpleCommodity, quantity);
|
||||
targetEntity.AddCargo(newItem);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var group in entity.Cargo
|
||||
.Select(id => Context.Cache.Get<ItemInstance>(id))
|
||||
.Where(item => item is CraftedItemInstance)
|
||||
.Cast<CraftedItemInstance>()
|
||||
.GroupBy(craftedItem =>
|
||||
{
|
||||
var corp = "GameCult";
|
||||
if (craftedItem.SourceEntity != Guid.Empty)
|
||||
corp = Context.Cache.Get<Corporation>(Context.Cache.Get<Entity>(craftedItem.SourceEntity).Corporation).Name;
|
||||
return (craftedItem.Data, craftedItem.Name, corp) ;
|
||||
}))
|
||||
{
|
||||
Action<CraftedItemInstance, PointerEventData> onClick = (item, data) =>
|
||||
{
|
||||
if (data.button == PointerEventData.InputButton.Left)
|
||||
{
|
||||
if (data.clickCount == 1)
|
||||
{
|
||||
Details.Clear();
|
||||
Details.RemoveListener();
|
||||
Details.AddItemProperties(entity, item);
|
||||
Details.RefreshValues();
|
||||
}
|
||||
else if (data.clickCount == 2 && item is Gear gear)
|
||||
{
|
||||
// Equip Item
|
||||
entity.Equip(gear.ID, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
Func<PointerEventData, CraftedItemInstance, bool> dragSuccess = (data, item) =>
|
||||
{
|
||||
Entity targetEntity = null;
|
||||
if (panel == Inventory &&
|
||||
_selectedChild != null &&
|
||||
((RectTransform) ChildInventory.transform).ContainsWorldPoint(data.position))
|
||||
targetEntity = _selectedChild;
|
||||
else if (panel == ChildInventory &&
|
||||
((RectTransform) Inventory.transform).ContainsWorldPoint(data.position))
|
||||
targetEntity = _parentEntity;
|
||||
|
||||
if (targetEntity != null)
|
||||
{
|
||||
if (targetEntity.Capacity - targetEntity.OccupiedCapacity >
|
||||
Context.Cache.Get<ItemData>(item.Data).Size)
|
||||
{
|
||||
entity.RemoveCargo(item);
|
||||
targetEntity.AddCargo(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
if (group.Count() == 1)
|
||||
{
|
||||
var item = group.First();
|
||||
var button = panel.AddProperty(item.Name, null, eventData => onClick(item, eventData), true).Button;
|
||||
button.DisableClickWhenSelected = false;
|
||||
button.DragSuccess = data => dragSuccess(data, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = Inventory.AddProperty(hardpoint.Gear.Name, null, _ =>
|
||||
var instanceList = panel.AddList(group.Key.Name);
|
||||
foreach (var item in group)
|
||||
{
|
||||
_selectedHardpoint = hardpoint;
|
||||
Details.Inspect(entity, hardpoint);
|
||||
}, true);
|
||||
|
||||
if (hardpoint == _selectedHardpoint)
|
||||
{
|
||||
Inventory.SelectedChild = prop.Button;
|
||||
prop.Button.CurrentState = FlatButtonState.Selected;
|
||||
var button = instanceList.AddProperty(item.Name, null, eventData => onClick(item, eventData), true).Button;
|
||||
button.DisableClickWhenSelected = false;
|
||||
button.DragSuccess = data => dragSuccess(data, item);
|
||||
}
|
||||
instanceList.SetExpanded(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(!entity.Cargo.Any())
|
||||
Inventory.AddSection("No Cargo");
|
||||
else
|
||||
{
|
||||
Inventory.AddSection("Cargo");
|
||||
foreach (var itemID in entity.Cargo.Where(id => Context.Cache.Get<ItemInstance>(id) is SimpleCommodity))
|
||||
{
|
||||
var simpleCommodity = Context.Cache.Get<SimpleCommodity>(itemID);
|
||||
var data = simpleCommodity.ItemData;
|
||||
Inventory.AddProperty(data.Name, () => simpleCommodity.Quantity.ToString(), eventData =>
|
||||
{
|
||||
Details.Clear();
|
||||
Details.AddItemProperties(simpleCommodity);
|
||||
Details.RefreshValues();
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var group in entity.Cargo
|
||||
.Select(id => Context.Cache.Get<ItemInstance>(id))
|
||||
.Where(item => item is CraftedItemInstance)
|
||||
.Cast<CraftedItemInstance>()
|
||||
.GroupBy(craftedItem => (craftedItem.Data, craftedItem.Name, Context.Cache.Get<Corporation>(Context.Cache.Get<Entity>(craftedItem.SourceEntity).Corporation))))
|
||||
{
|
||||
if (group.Count() == 1)
|
||||
{
|
||||
var item = group.First();
|
||||
Inventory.AddProperty(item.Name, null, eventData =>
|
||||
{
|
||||
Details.Clear();
|
||||
Details.AddItemProperties(item);
|
||||
Details.RefreshValues();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var instanceList = Inventory.AddList(group.Key.Name);
|
||||
foreach (var item in group)
|
||||
{
|
||||
instanceList.AddProperty(item.Name, null, eventData =>
|
||||
{
|
||||
Details.Clear();
|
||||
Details.AddItemProperties(item);
|
||||
Details.RefreshValues();
|
||||
});
|
||||
}
|
||||
instanceList.SetExpanded(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Inventory.RefreshValues();
|
||||
}
|
||||
panel.RefreshValues();
|
||||
}
|
||||
|
||||
void PopulateDetails(Entity entity, IEnumerable<BlueprintData> blueprints)
|
||||
{
|
||||
Details.RemoveListener();
|
||||
Details.Clear();
|
||||
foreach (var blueprint in blueprints)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using UnityEngine;
|
|||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public event Action<PointerEventData> OnClick;
|
||||
public float StateDamping;
|
||||
|
|
@ -15,6 +15,7 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
public TextMeshProUGUI Label;
|
||||
public FlatButtonState CurrentState = FlatButtonState.Unselected;
|
||||
public bool DisableClickWhenSelected = true;
|
||||
public RectTransform DragObject;
|
||||
|
||||
public Color UnselectedColor;
|
||||
public Color SelectedColor;
|
||||
|
|
@ -24,6 +25,11 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
public Color EnabledTextColor;
|
||||
public Color DisabledTextColor;
|
||||
|
||||
public Func<PointerEventData, bool> DragSuccess;
|
||||
private int _siblingIndex;
|
||||
private Transform _dragParent;
|
||||
private Vector3 _dragPositionOffset;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (OnClick != null && CurrentState == FlatButtonState.Unselected)
|
||||
|
|
@ -48,6 +54,40 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
}
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (DragSuccess == null || DragObject == null) return;
|
||||
|
||||
var canvas = gameObject.FindInParents<Canvas>();
|
||||
if (canvas == null)
|
||||
return;
|
||||
|
||||
_siblingIndex = DragObject.GetSiblingIndex();
|
||||
_dragParent = DragObject.parent;
|
||||
|
||||
DragObject.SetParent(canvas.transform, true);
|
||||
_dragPositionOffset = DragObject.position - (Vector3)eventData.position;
|
||||
DragObject.SetAsLastSibling();
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
var targetPosition = (Vector3)eventData.position + _dragPositionOffset;
|
||||
//Debug.Log($"Moving drag object to {targetPosition}");
|
||||
DragObject.position = targetPosition;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if(DragSuccess(eventData))
|
||||
Destroy(DragObject.gameObject);
|
||||
else
|
||||
{
|
||||
DragObject.parent = _dragParent;
|
||||
DragObject.SetSiblingIndex(_siblingIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Color appearance;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
protected bool RadioSelection = false;
|
||||
|
||||
protected event Action<GameObject> OnPropertyAdded;
|
||||
protected IDynamicProperties ChangeSource;
|
||||
protected IChangeSource ChangeSource;
|
||||
protected Action OnPropertiesChanged;
|
||||
|
||||
public void Start()
|
||||
|
|
@ -186,8 +186,6 @@ public class PropertiesPanel : MonoBehaviour
|
|||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
// TODO Find out what's going on with the TMP Input Field
|
||||
// BODY Setting an input field value causes the text to layout wrong, current workaround is disabling and enabling the gameobject
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
|
||||
}
|
||||
|
|
@ -202,7 +200,16 @@ public class PropertiesPanel : MonoBehaviour
|
|||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
|
||||
RefreshPropertyValues += () => field.Field.text = read().ToString(CultureInfo.InvariantCulture);
|
||||
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);
|
||||
}
|
||||
|
|
@ -213,7 +220,16 @@ public class PropertiesPanel : MonoBehaviour
|
|||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
|
||||
RefreshPropertyValues += () => field.Field.text = read().ToString(CultureInfo.InvariantCulture);
|
||||
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);
|
||||
}
|
||||
|
|
@ -310,10 +326,14 @@ public class PropertiesPanel : MonoBehaviour
|
|||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
void RemoveListener()
|
||||
public void RemoveListener()
|
||||
{
|
||||
if (ChangeSource != null)
|
||||
{
|
||||
ChangeSource.OnChanged -= OnPropertiesChanged;
|
||||
ChangeSource = null;
|
||||
OnPropertiesChanged = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(Entity entity)
|
||||
|
|
@ -328,10 +348,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
"Platform");
|
||||
//AddList(hullData.Name).Inspect(hull, entity);
|
||||
//PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
|
||||
AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}");
|
||||
AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
|
||||
AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehaviors<Reactor>().First().Capacitance:0}");
|
||||
AddEntityProperties(entity);
|
||||
|
||||
var hardpointList = AddList("Gear");
|
||||
hardpointList.InspectHardpoints(entity);
|
||||
|
|
@ -384,7 +401,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
var simpleCommodity = Context.Cache.Get<SimpleCommodity>(itemID);
|
||||
var data = simpleCommodity.ItemData;
|
||||
var propertiesList = AddList($"{simpleCommodity.Quantity.ToString()} {data.Name}");
|
||||
propertiesList.AddItemProperties(simpleCommodity);
|
||||
propertiesList.AddItemProperties(entity, simpleCommodity);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
|
|
@ -399,7 +416,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
{
|
||||
var item = group.First();
|
||||
var propertiesList = AddList(item.Name);
|
||||
propertiesList.AddItemProperties(item);
|
||||
propertiesList.AddItemProperties(entity, item);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
|
|
@ -409,7 +426,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
foreach (var item in group)
|
||||
{
|
||||
var propertiesList = instanceList.AddList(item.Name);
|
||||
propertiesList.AddItemProperties(item);
|
||||
propertiesList.AddItemProperties(entity, item);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
|
|
@ -421,11 +438,32 @@ public class PropertiesPanel : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public void AddItemProperties(ItemInstance item)
|
||||
public void AddEntityProperties(Entity entity)
|
||||
{
|
||||
AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}");
|
||||
AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
|
||||
AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehavior<Reactor>()?.Capacitance??0:0}");
|
||||
}
|
||||
|
||||
public void AddItemProperties(Entity entity, ItemInstance item)
|
||||
{
|
||||
var data = Context.Cache.Get<ItemData>(item.Data);
|
||||
AddProperty("Type", () => data.Name);
|
||||
AddProperty(data.Description).Label.fontStyle = FontStyles.Normal;
|
||||
if (item is CraftedItemInstance craftedItemInstance)
|
||||
{
|
||||
var sourceEntity = Context.Cache.Get<Entity>(craftedItemInstance.SourceEntity);
|
||||
if (sourceEntity != null)
|
||||
{
|
||||
var corporation = Context.Cache.Get<Corporation>(sourceEntity.Corporation);
|
||||
AddProperty("Manufacturer", () => corporation.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddProperty("Manufacturer", () => "GameCult");
|
||||
}
|
||||
}
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
|
||||
AddProperty("Mass", () => item.Mass.SignificantDigits(Context.GlobalData.SignificantDigits));
|
||||
|
|
@ -436,20 +474,47 @@ public class PropertiesPanel : MonoBehaviour
|
|||
var gearData = gear.ItemData;
|
||||
AddProperty("Durability", () =>
|
||||
$"{gear.Durability.SignificantDigits(Context.GlobalData.SignificantDigits)}/{Context.Evaluate(gearData.Durability, gear).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
foreach (var behavior in gearData.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))
|
||||
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
else if (fieldType == typeof(int))
|
||||
AddProperty(field.Name, () => $"{(int) field.GetValue(behavior)}");
|
||||
else if (fieldType == typeof(PerformanceStat))
|
||||
{
|
||||
var stat = (PerformanceStat) field.GetValue(behavior);
|
||||
AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear, entity).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item is CraftedItemInstance craftedItemInstance)
|
||||
}
|
||||
|
||||
public void InspectChildren(Entity entity, Action<Entity> onSelect)
|
||||
{
|
||||
RemoveListener();
|
||||
|
||||
ChangeSource = entity.ChildEvent;
|
||||
OnPropertiesChanged = InspectChildrenInternal;
|
||||
ChangeSource.OnChanged += OnPropertiesChanged;
|
||||
InspectChildrenInternal();
|
||||
|
||||
void InspectChildrenInternal()
|
||||
{
|
||||
var entity = Context.Cache.Get<Entity>(craftedItemInstance.SourceEntity);
|
||||
if (entity != null)
|
||||
foreach (var child in entity.Children)
|
||||
{
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
AddProperty("Manufacturer", () => corporation.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddProperty("Manufacturer", () => "God");
|
||||
var childEntity = Context.Cache.Get<Entity>(child);
|
||||
AddProperty(childEntity.Name, null, data => onSelect(childEntity), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Inspect(Entity entity, Hardpoint hardpoint)
|
||||
|
|
@ -465,84 +530,67 @@ public class PropertiesPanel : MonoBehaviour
|
|||
{
|
||||
//Debug.Log($"Refreshing {hardpoint.Gear.Name} properties");
|
||||
Clear();
|
||||
AddItemProperties(hardpoint.Gear);
|
||||
foreach (var behavior in hardpoint.ItemData.Behaviors)
|
||||
if (hardpoint.Gear != null)
|
||||
{
|
||||
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))
|
||||
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
else if (fieldType == typeof(int))
|
||||
AddProperty(field.Name, () => $"{(int) field.GetValue(behavior)}");
|
||||
else if (fieldType == typeof(PerformanceStat))
|
||||
{
|
||||
var stat = (PerformanceStat) field.GetValue(behavior);
|
||||
AddProperty(field.Name, () => $"{Context.Evaluate(stat, hardpoint.Gear, entity).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
AddItemProperties(entity, hardpoint.Gear);
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
AddIncrementField("Assigned Population",
|
||||
() => populationAssignment.AssignedPopulation,
|
||||
p => populationAssignment.AssignedPopulation = p,
|
||||
() => 0, () => entity.Population - entity.AssignedPopulation + populationAssignment.AssignedPopulation);
|
||||
if (behavior is Thermotoggle thermotoggle)
|
||||
AddField("Target Temperature", () => thermotoggle.TargetTemperature, temp => thermotoggle.TargetTemperature = temp);
|
||||
if (behavior is Factory factory)
|
||||
{
|
||||
AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
var compatibleBlueprints = corporation.UnlockedBlueprints
|
||||
.Select(id => Context.Cache.Get<BlueprintData>(id))
|
||||
.Where(bp => bp.FactoryItem == hardpoint.ItemData.ID).ToList();
|
||||
if (factory.RetoolingTime > 0)
|
||||
{
|
||||
AddProgressField("Retooling", () => (factory.ToolingTime - (float) factory.RetoolingTime) / factory.ToolingTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddField("Item",
|
||||
() => compatibleBlueprints.FindIndex(bp=>bp.ID== factory.Blueprint) + 1,
|
||||
i => factory.Blueprint = i == 0 ? Guid.Empty : compatibleBlueprints[i - 1].ID,
|
||||
new []{"None"}.Concat(compatibleBlueprints.Select(bp=>bp.Name)).ToArray());
|
||||
AddField("Active", () => factory.Active, active => factory.Active = active);
|
||||
if (factory.Blueprint != Guid.Empty)
|
||||
{
|
||||
if (factory.Active && factory.ItemUnderConstruction != Guid.Empty)
|
||||
{
|
||||
AddProgressField("Production", () =>
|
||||
{
|
||||
if (factory.ItemUnderConstruction == Guid.Empty) return 1;
|
||||
var itemInstance = Context.Cache.Get<CraftedItemInstance>(factory.ItemUnderConstruction);
|
||||
var blueprintData = Context.Cache.Get<BlueprintData>(itemInstance.Blueprint);
|
||||
return (blueprintData.ProductionTime - (float) entity.IncompleteCargo[factory.ItemUnderConstruction]) / blueprintData.ProductionTime;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
||||
AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
||||
var ingredientsList = AddList("Ingredients Needed");
|
||||
var blueprintData = Context.Cache.Get<BlueprintData>(factory.Blueprint);
|
||||
foreach (var ingredient in blueprintData.Ingredients)
|
||||
{
|
||||
var itemData = Context.Cache.Get<ItemData>(ingredient.Key);
|
||||
ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
ingredientsList.SetExpanded(false, true);
|
||||
ingredientsList.RefreshValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
AddIncrementField("Assigned Population",
|
||||
() => populationAssignment.AssignedPopulation,
|
||||
p => populationAssignment.AssignedPopulation = p,
|
||||
() => 0, () => entity.Population - entity.AssignedPopulation + populationAssignment.AssignedPopulation);
|
||||
if (behavior is Thermotoggle thermotoggle)
|
||||
AddField("Target Temperature", () => thermotoggle.TargetTemperature, temp => thermotoggle.TargetTemperature = temp);
|
||||
if (behavior is Factory factory)
|
||||
{
|
||||
AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
var compatibleBlueprints = corporation.UnlockedBlueprints
|
||||
.Select(id => Context.Cache.Get<BlueprintData>(id))
|
||||
.Where(bp => bp.FactoryItem == hardpoint.ItemData.ID).ToList();
|
||||
if (factory.RetoolingTime > 0)
|
||||
{
|
||||
AddProgressField("Retooling", () => (factory.ToolingTime - (float) factory.RetoolingTime) / factory.ToolingTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddField("Item",
|
||||
() => compatibleBlueprints.FindIndex(bp=>bp.ID== factory.Blueprint) + 1,
|
||||
i => factory.Blueprint = i == 0 ? Guid.Empty : compatibleBlueprints[i - 1].ID,
|
||||
new []{"None"}.Concat(compatibleBlueprints.Select(bp=>bp.Name)).ToArray());
|
||||
AddField("Active", () => factory.Active, active => factory.Active = active);
|
||||
if (factory.Blueprint != Guid.Empty)
|
||||
{
|
||||
if (factory.Active && factory.ItemUnderConstruction != Guid.Empty)
|
||||
{
|
||||
AddProgressField("Production", () =>
|
||||
{
|
||||
if (factory.ItemUnderConstruction == Guid.Empty) return 1;
|
||||
var itemInstance = Context.Cache.Get<CraftedItemInstance>(factory.ItemUnderConstruction);
|
||||
var blueprintData = Context.Cache.Get<BlueprintData>(itemInstance.Blueprint);
|
||||
return (blueprintData.ProductionTime - (float) entity.IncompleteCargo[factory.ItemUnderConstruction]) / blueprintData.ProductionTime;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
||||
AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
||||
var ingredientsList = AddList("Ingredients Needed");
|
||||
var blueprintData = Context.Cache.Get<BlueprintData>(factory.Blueprint);
|
||||
foreach (var ingredient in blueprintData.Ingredients)
|
||||
{
|
||||
var itemData = Context.Cache.Get<ItemData>(ingredient.Key);
|
||||
ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
ingredientsList.SetExpanded(false, true);
|
||||
ingredientsList.RefreshValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RefreshValues();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,29 @@ using static Unity.Mathematics.math;
|
|||
|
||||
public static class UnityExtensions
|
||||
{
|
||||
public static T FindInParents<T>(this GameObject go) where T : Component
|
||||
{
|
||||
if (go == null) return null;
|
||||
var comp = go.GetComponent<T>();
|
||||
|
||||
if (comp != null)
|
||||
return comp;
|
||||
|
||||
Transform t = go.transform.parent;
|
||||
while (t != null && comp == null)
|
||||
{
|
||||
comp = t.gameObject.GetComponent<T>();
|
||||
t = t.parent;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public static bool ContainsWorldPoint(this RectTransform rectTransform, Vector3 point)
|
||||
{
|
||||
Vector2 localMousePosition = rectTransform.InverseTransformPoint(point);
|
||||
return rectTransform.rect.Contains(localMousePosition);
|
||||
}
|
||||
|
||||
public static void BroadcastAll(string fun, System.Object msg) {
|
||||
GameObject[] gos = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
|
||||
foreach (GameObject go in gos) {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@
|
|||
<Compile Include="Assets\Scripts\ServerShared\Extensions.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\GameContext.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\GlobalData.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\IDynamicProperties.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\IChangeSource.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\ItemData.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\ItemInstance.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\JsonConverters.cs" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue