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

@ -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();