New Inventory System + Overhaul

Removed universal GameContext references
Refactored GameContext: It's now only responsible for item management. As such it's now called ItemManager
GlobalData is gone, relevant settings are distributed amongst specialized settings classes
Entities are no longer database entries, references to them are now direct - Zone is reponsible for storing them in ZonePacks
Controller subtypes are now generic classes, class argument is task type
Inventory is now a 2D grid instead of a list
Entity temperature is now a 2D grid instead of a number
Item sizes are now arbitrary shapes instead of a number
Hardpoints are now arbitrary shapes instead
Equipped items have their own temperatures
Map view now displays sunlight colors
Integrated Allegorithmic Substance Plugin
Imported Djinni ship and assigned Substance materials
Removed Node Editor framework (might come back later but needs work to integrate with behavior system)
This commit is contained in:
Reinier Vens 2020-12-10 23:20:38 +00:00
commit f643f6cc8a
330 changed files with 24242 additions and 2830 deletions

View file

@ -1,450 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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;
public ConfirmationDialog ConfirmationDialog;
public GameContext Context
{
get => _context;
set
{
_context = value;
General.Context = value;
Inventory.Context = value;
ChildInventory.Context = value;
Details.Context = value;
}
}
private GameContext _context;
private Hardpoint _selectedHardpoint;
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)
{
_selectedHardpoint = null;
_parentEntity = Context.Cache.Get<Entity>(colony);
Title.text = _parentEntity.Name;
UpdateGeneral(_parentEntity);
UpdateInventory(_parentEntity, Inventory);
}
private void OnDisable()
{
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.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, 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));
// 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)
{
panel.Title.text = entity.Name;
panel.AddField("Active", () => entity.Active, active => entity.Active = active);
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();
// 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)
{
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();
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)
{
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
{
Action<Guid, int> showHaulingDialog = (id, maxQuantity) =>
{
var itemData = Context.Cache.Get<ItemData>(id);
ConfirmationDialog.gameObject.SetActive(true);
ConfirmationDialog.Clear();
ConfirmationDialog.Title.text = $"Haul {itemData.Name}";
var quantity = maxQuantity;
var colonies = Context.Cache.GetAll<Entity>()
.Where(e => e.Corporation == entity.Corporation && e is OrbitalEntity && e != entity).ToArray();
var colonyNames = colonies.Select(c => c.Name).ToArray();
ConfirmationDialog.AddField("Quantity", () => quantity, i => quantity = clamp(i, 1, maxQuantity));
var selectedColony = 0;
ConfirmationDialog.AddField("Target Colony", () => selectedColony, i => selectedColony = i,
colonyNames);
ConfirmationDialog.Show(() =>
{
var haulingTask = new HaulingTask
{
Context = Context,
ItemType = id,
Origin = entity.ID,
Quantity = quantity,
Target = colonies[selectedColony].ID,
Zone = entity.Zone.Data.ID
};
Context.Cache.Add(haulingTask);
var corp = Context.Cache.Get<Corporation>(entity.Corporation);
corp.Tasks.Add(haulingTask.ID);
});
};
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 =>
{
if (eventData.button == PointerEventData.InputButton.Left)
{
Details.Clear();
Details.RemoveListener();
Details.AddItemProperties(entity, simpleCommodity);
Details.RefreshValues();
}
else if (eventData.button == PointerEventData.InputButton.Right)
{
ContextMenu.gameObject.SetActive(true);
ContextMenu.Clear();
ContextMenu.AddOption("Haul", () => showHaulingDialog(simpleCommodity.Data, simpleCommodity.Quantity));
ContextMenu.Show();
}
}, 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 maxQuantity = min((int) ((targetEntity.Capacity - targetEntity.OccupiedCapacity) / simpleCommodity.ItemData.Size), simpleCommodity.Quantity);
if (maxQuantity > 0)
{
ConfirmationDialog.gameObject.SetActive(true);
ConfirmationDialog.Clear();
ConfirmationDialog.Title.text = $"Move {simpleCommodity.ItemData.Name}";
var quantity = maxQuantity;
ConfirmationDialog.AddField("Quantity", () => quantity, i => quantity = clamp(i, 1, maxQuantity));
ConfirmationDialog.Show(() =>
{
var newItem = entity.RemoveCargo(simpleCommodity, quantity);
targetEntity.AddCargo(newItem);
});
}
}
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)
{
// Item is a hull, create a ship entity and make it a child
if (gear.ItemData is HullData)
{
entity.RemoveCargo(gear);
var ship = Context.CreateShip(gear.ID, Enumerable.Empty<Guid>(),
Enumerable.Empty<Guid>(), entity.Zone, entity.Corporation, _parentEntity.ID, gear.Name);
ship.SetParent(entity);
}
else // Equip Item
entity.Equip(gear.ID, true);
}
}
else if (data.button == PointerEventData.InputButton.Right)
{
ContextMenu.gameObject.SetActive(true);
ContextMenu.Clear();
ContextMenu.AddOption("Haul", () => showHaulingDialog(item.Data, group.Count()));
ContextMenu.Show();
}
};
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 instanceList = panel.AddList($"{group.Count().ToString()} {group.Key.Name}");
foreach (var item in group)
{
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);
}
}
}
panel.RefreshValues();
}
void PopulateDetails(Entity entity, IEnumerable<BlueprintData> blueprints)
{
Details.RemoveListener();
Details.Clear();
foreach (var blueprint in blueprints)
{
var blueprintList = Details.AddList(blueprint.Name);
foreach (var ingredient in blueprint.Ingredients)
{
var itemData = _context.Cache.Get<ItemData>(ingredient.Key);
blueprintList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
}
var bpItemData = _context.Cache.Get<ItemData>(blueprint.Item);
if(entity.GetBlueprintIngredients(blueprint, out _, out _))
blueprintList.AddButton("Build", _ =>
{
entity.Build(blueprint, 1, bpItemData.Name, true);
Details.Clear();
});
blueprintList.RefreshValues();
// blueprintList.SetExpanded(false, true);
}
Details.RefreshValues();
}
}

View file

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

View file

@ -30,7 +30,7 @@ public class PropertiesPanel : MonoBehaviour
public ButtonField ButtonField;
public IncrementField IncrementField;
[HideInInspector] public FlatFlatButton SelectedChild;
[HideInInspector] public GameContext Context;
[HideInInspector] public ItemManager Context;
protected List<GameObject> Properties = new List<GameObject>();
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
@ -38,7 +38,6 @@ public class PropertiesPanel : MonoBehaviour
protected bool RadioSelection = false;
protected event Action<GameObject> OnPropertyAdded;
protected IChangeSource ChangeSource;
protected Action OnPropertiesChanged;
public int Children => Properties.Count + Buttons.Count;
@ -55,7 +54,6 @@ public class PropertiesPanel : MonoBehaviour
private void OnDestroy()
{
RemoveListener();
}
// private void OnDisable()
@ -332,23 +330,12 @@ public class PropertiesPanel : MonoBehaviour
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}
public void RemoveListener()
{
if (ChangeSource != null)
{
ChangeSource.OnChanged -= OnPropertiesChanged;
ChangeSource = null;
OnPropertiesChanged = null;
}
}
public void Inspect(Entity entity)
{
Clear();
Title.text = entity.Name;
var hull = Context.Cache.Get<Gear>(entity.Hull);
var hullData = Context.Cache.Get<HullData>(hull.Data);
var hullData = Context.GetData(entity.Hull) as HullData;
AddSection(
hullData.HullType == HullType.Ship ? "Ship" :
hullData.HullType == HullType.Station ? "Station" :
@ -356,162 +343,46 @@ public class PropertiesPanel : MonoBehaviour
//AddList(hullData.Name).Inspect(hull, entity);
//PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
AddEntityProperties(entity);
var hardpointList = AddList("Gear");
hardpointList.InspectHardpoints(entity);
//hardpointList.SetExpanded(false,true);
var cargoList = AddList("Cargo");
cargoList.InspectCargo(entity);
//cargoList.SetExpanded(false,true);
RefreshValues();
}
public void InspectHardpoints(Entity entity)
{
RemoveListener();
ChangeSource = entity.GearEvent;
OnPropertiesChanged = InspectGearInternal;
ChangeSource.OnChanged += OnPropertiesChanged;
if (this is PropertiesList list)
{
if (list.Expanded)
InspectGearInternal();
else
list.OnExpand += b =>
{
if (b) InspectGearInternal();
};
}
else
InspectGearInternal();
void InspectGearInternal()
{
Clear();
var equippedItems = entity.Hardpoints.Where(hp => hp.Gear != null);
foreach (var hardpoint in equippedItems)
{
var propertyList = AddList(hardpoint.Gear.Name);
propertyList.Inspect(entity, hardpoint);
//propertyList.SetExpanded(false,true);
}
RefreshValues();
}
}
public void InspectCargo(Entity entity)
{
RemoveListener();
ChangeSource = entity.CargoEvent;
OnPropertiesChanged = InspectCargoInternal;
ChangeSource.OnChanged += OnPropertiesChanged;
if (this is PropertiesList list)
{
if (list.Expanded)
InspectCargoInternal();
else
list.OnExpand += b =>
{
if (b) InspectCargoInternal();
};
}
else
InspectCargoInternal();
void InspectCargoInternal()
{
Clear();
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;
var propertiesList = AddList($"{simpleCommodity.Quantity.ToString()} {data.Name}");
propertiesList.AddItemProperties(entity, simpleCommodity);
propertiesList.RefreshValues();
//propertiesList.SetExpanded(false, true);
}
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);
}))
{
if (group.Count() == 1)
{
var item = group.First();
var propertiesList = AddList(item.Name);
propertiesList.AddItemProperties(entity, item);
propertiesList.RefreshValues();
//propertiesList.SetExpanded(false, true);
}
else
{
var instanceList = AddList($"{group.Count().ToString()} {group.Key.Name}");
instanceList.OnExpand += b =>
{
if (!b || instanceList.Children > 0) return;
foreach (var item in group)
{
var propertiesList = instanceList.AddList(item.Name);
propertiesList.AddItemProperties(entity, item);
propertiesList.RefreshValues();
}
};
}
}
RefreshValues();
}
}
public void AddEntityProperties(Entity entity)
{
AddField("Name", () => entity.Name, name => entity.Name = 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.GetBehavior<Reactor>()?.Capacitance??0:0}");
AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GameplaySettings.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);
var data = Context.ItemData.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 CraftedItemInstance craftedItemInstance)
// {
// var sourceEntity = Context.ItemData.Get<Entity>(craftedItemInstance.SourceEntity);
// if (sourceEntity != null)
// {
// var corporation = Context.ItemData.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));
AddProperty("Thermal Mass", () => item.ThermalMass.SignificantDigits(Context.GlobalData.SignificantDigits));
AddProperty("Size", () => item.Size.SignificantDigits(Context.GlobalData.SignificantDigits));
if (item is Gear gear)
AddProperty("Mass", () => Context.GetMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
if (item is EquippableItem gear)
{
var gearData = gear.ItemData;
var gearData = Context.GetData(gear);
AddProperty("Durability", () =>
$"{gear.Durability.SignificantDigits(Context.GlobalData.SignificantDigits)}/{Context.Evaluate(gearData.Durability, gear).SignificantDigits(Context.GlobalData.SignificantDigits)}");
$"{gear.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}/{gearData.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
foreach (var behavior in gearData.Behaviors)
{
var type = behavior.GetType();
@ -521,13 +392,13 @@ public class PropertiesPanel : MonoBehaviour
{
var fieldType = field.FieldType;
if (fieldType == typeof(float))
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GlobalData.SignificantDigits)}");
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GameplaySettings.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)}");
AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear, entity).SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
}
}
}
@ -535,35 +406,8 @@ public class PropertiesPanel : MonoBehaviour
}
}
public void InspectChildren(Entity entity, Action<Entity> onSelect)
public void Inspect(Entity entity, EquippedItem item)
{
RemoveListener();
ChangeSource = entity.ChildEvent;
OnPropertiesChanged = InspectChildrenInternal;
ChangeSource.OnChanged += OnPropertiesChanged;
InspectChildrenInternal();
void InspectChildrenInternal()
{
Clear();
foreach (var child in entity.Children)
{
var childEntity = Context.Cache.Get<Entity>(child);
AddProperty(childEntity.Name, null, data => onSelect(childEntity), true);
}
}
}
public void Inspect(Entity entity, Hardpoint hardpoint)
{
RemoveListener();
ChangeSource = hardpoint.Gear;
if (ChangeSource == null)
return;
OnPropertiesChanged = InspectGearInternal;
ChangeSource.OnChanged += OnPropertiesChanged;
if (this is PropertiesList list)
{
if (list.Expanded)
@ -581,10 +425,10 @@ public class PropertiesPanel : MonoBehaviour
{
//Debug.Log($"Refreshing {hardpoint.Gear.Name} properties");
Clear();
if (hardpoint.Gear != null)
if (item.EquippableItem != null)
{
AddItemProperties(entity, hardpoint.Gear);
foreach (var behavior in hardpoint.Behaviors)
AddItemProperties(entity, item.EquippableItem);
foreach (var behavior in item.Behaviors)
{
if(behavior is IPopulationAssignment populationAssignment)
AddIncrementField("Assigned Population",
@ -593,53 +437,53 @@ public class PropertiesPanel : MonoBehaviour
() => 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();
}
}
}
}
// if (behavior is Factory factory)
// {
// AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
// var corporation = Context.ItemData.Get<Corporation>(entity.Corporation);
// var compatibleBlueprints = corporation.UnlockedBlueprints
// .Select(id => Context.ItemData.Get<BlueprintData>(id))
// .Where(bp => bp.FactoryItem == item.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.ItemData.Get<CraftedItemInstance>(factory.ItemUnderConstruction);
// var blueprintData = Context.ItemData.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.ItemData.Get<BlueprintData>(factory.Blueprint);
// foreach (var ingredient in blueprintData.Ingredients)
// {
// var itemData = Context.ItemData.Get<ItemData>(ingredient.Key);
// ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
// }
// // ingredientsList.SetExpanded(false, true);
// ingredientsList.RefreshValues();
// }
// }
// }
// }
}
}
RefreshValues();