Equipment Data Simplification
Removed blueprint system for crafting (and excised anything depending on that) Implemented smootherstep and used it for wormhole animation Quality dependent durability and heat exponents are now global instead of item specific Database list view now groups equipment by manufacturer Thrusters can now consume energy Weapons can have reloads even when they don't have ammo
This commit is contained in:
parent
017335e09d
commit
47189c8a7e
49 changed files with 6943 additions and 1548 deletions
|
|
@ -204,78 +204,6 @@ public class DatabaseInspector : EditorWindow
|
|||
Inspect(field.Name.SplitCamelCase(), ref dict, link.EntryType, ranged.Min, ranged.Max);
|
||||
else Inspect(field.Name.SplitCamelCase(), ref dict, link.EntryType);
|
||||
}
|
||||
else if (type == typeof(List<BlueprintStatEffect>))
|
||||
{
|
||||
var list = (List<BlueprintStatEffect>) field.GetValue(obj);
|
||||
if(list==null) field.SetValue(obj, list = new List<BlueprintStatEffect>());
|
||||
|
||||
var blueprint = obj as BlueprintData;
|
||||
var blueprintItem = DatabaseCache.Get(blueprint.Item);
|
||||
if (blueprintItem is EquippableItemData equippableBlueprintItem)
|
||||
{
|
||||
Space();
|
||||
LabelField(field.Name.SplitCamelCase(), EditorStyles.boldLabel);
|
||||
|
||||
using (var v = new VerticalScope(GUI.skin.box))
|
||||
{
|
||||
var ingredients = blueprint.Ingredients.Keys
|
||||
.Select(i => DatabaseCache.Get(i))
|
||||
.Where(i => i is CraftedItemData)
|
||||
.Cast<CraftedItemData>().ToArray();
|
||||
var ingredientNames = ingredients.Select(i => i.Name).ToArray();
|
||||
foreach (var effect in list)
|
||||
{
|
||||
using (var v2 = new VerticalScope(_list.ListItemStyle))
|
||||
{
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Ingredient", GUILayout.Width(width));
|
||||
if(ingredients.Length==0)
|
||||
GUILayout.Label("No Ingredients!");
|
||||
else
|
||||
{
|
||||
var selectedIngredientIndex =
|
||||
Array.FindIndex(ingredients, item => item.ID == effect.Ingredient);
|
||||
if (selectedIngredientIndex == -1)
|
||||
{
|
||||
selectedIngredientIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
var newSelection = Popup(selectedIngredientIndex, ingredientNames);
|
||||
if (newSelection != selectedIngredientIndex)
|
||||
GUI.changed = true;
|
||||
effect.Ingredient = ingredients[newSelection].ID;
|
||||
}
|
||||
|
||||
var rect = GetControlRect(false,
|
||||
GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1,
|
||||
LabelColor, 0, 0);
|
||||
if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
|
||||
{
|
||||
list.Remove(effect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Inspect(ref effect.StatReference, equippableBlueprintItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using (var h = new HorizontalScope(_list.ListItemStyle))
|
||||
{
|
||||
GUILayout.Label("Add new Stat Effect", GUILayout.ExpandWidth(true));
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
||||
if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
|
||||
{
|
||||
list.Add(new BlueprintStatEffect());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == typeof(List<Guid>) && link != null)
|
||||
{
|
||||
var list = (List<Guid>) field.GetValue(obj);
|
||||
|
|
@ -735,6 +663,14 @@ public class DatabaseInspector : EditorWindow
|
|||
}
|
||||
}
|
||||
}
|
||||
var rect = GetControlRect(false,
|
||||
GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1,
|
||||
LabelColor, 0, 0);
|
||||
if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
@ -974,103 +910,6 @@ public class DatabaseInspector : EditorWindow
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(string label, ref StatReference effect)
|
||||
{
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label(label, GUILayout.Width(width));
|
||||
|
||||
using (new VerticalScope())
|
||||
{
|
||||
var targetObjects = typeof(BehaviorData).GetAllChildClasses()
|
||||
.Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray();
|
||||
var objectNames = targetObjects.Select(b => b.Name).ToArray();
|
||||
var selectedIndex = Array.IndexOf(objectNames, effect.Target);
|
||||
if (selectedIndex == -1)
|
||||
{
|
||||
selectedIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Target", GUILayout.Width(width));
|
||||
var newSelection = Popup(selectedIndex, objectNames);
|
||||
if (newSelection != selectedIndex)
|
||||
GUI.changed = true;
|
||||
effect.Target = objectNames[newSelection];
|
||||
}
|
||||
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Stat", GUILayout.Width(width));
|
||||
var stats = targetObjects[selectedIndex].GetFields()
|
||||
.Where(f => f.FieldType == typeof(PerformanceStat)).ToArray();
|
||||
if(stats.Length==0)
|
||||
GUILayout.Label("No Stats!");
|
||||
else
|
||||
{
|
||||
var statNames = stats.Select(s => s.Name).ToArray();
|
||||
var selectedStatIndex = Array.IndexOf(statNames, effect.Stat);
|
||||
if (selectedStatIndex == -1)
|
||||
{
|
||||
selectedStatIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
var newSelection = Popup(selectedStatIndex, statNames);
|
||||
if (newSelection != selectedStatIndex)
|
||||
GUI.changed = true;
|
||||
effect.Stat = statNames[newSelection];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(ref StatReference effect, EquippableItemData item)
|
||||
{
|
||||
using (new VerticalScope())
|
||||
{
|
||||
var behaviorNames = new []{item.Name}.Concat(item.Behaviors.Select(b => b.GetType().Name)).ToArray();
|
||||
var selectedBehaviorIndex = Array.IndexOf(behaviorNames, effect.Target);
|
||||
if (selectedBehaviorIndex == -1)
|
||||
{
|
||||
selectedBehaviorIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Behavior", GUILayout.Width(width));
|
||||
var newSelection = Popup(selectedBehaviorIndex, behaviorNames);
|
||||
if (newSelection != selectedBehaviorIndex)
|
||||
GUI.changed = true;
|
||||
effect.Target = behaviorNames[newSelection];
|
||||
}
|
||||
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Stat", GUILayout.Width(width));
|
||||
var stats = (selectedBehaviorIndex == 0 ? item.GetType() : item.Behaviors[selectedBehaviorIndex-1].GetType()).GetFields()
|
||||
.Where(f => f.FieldType == typeof(PerformanceStat)).ToArray();
|
||||
if(stats.Length==0)
|
||||
GUILayout.Label("No Stats!");
|
||||
else
|
||||
{
|
||||
var statNames = stats.Select(s => s.Name).ToArray();
|
||||
var selectedStatIndex = Array.IndexOf(statNames, effect.Stat);
|
||||
if (selectedStatIndex == -1)
|
||||
{
|
||||
selectedStatIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
var newSelection = Popup(selectedStatIndex, statNames);
|
||||
if (newSelection != selectedStatIndex)
|
||||
GUI.changed = true;
|
||||
effect.Stat = statNames[newSelection];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Shape Inspect(string label, Shape value, HullData hull = null)
|
||||
{
|
||||
|
|
@ -1144,6 +983,58 @@ public class DatabaseInspector : EditorWindow
|
|||
return value;
|
||||
}
|
||||
|
||||
public void Inspect(string label, ref StatReference effect)
|
||||
{
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label(label, GUILayout.Width(width));
|
||||
|
||||
using (new VerticalScope())
|
||||
{
|
||||
var targetObjects = typeof(BehaviorData).GetAllChildClasses()
|
||||
.Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray();
|
||||
var objectNames = targetObjects.Select(b => b.Name).ToArray();
|
||||
var selectedIndex = Array.IndexOf(objectNames, effect.Target);
|
||||
if (selectedIndex == -1)
|
||||
{
|
||||
selectedIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Target", GUILayout.Width(width));
|
||||
var newSelection = Popup(selectedIndex, objectNames);
|
||||
if (newSelection != selectedIndex)
|
||||
GUI.changed = true;
|
||||
effect.Target = objectNames[newSelection];
|
||||
}
|
||||
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Stat", GUILayout.Width(width));
|
||||
var stats = targetObjects[selectedIndex].GetFields()
|
||||
.Where(f => f.FieldType == typeof(PerformanceStat)).ToArray();
|
||||
if(stats.Length==0)
|
||||
GUILayout.Label("No Stats!");
|
||||
else
|
||||
{
|
||||
var statNames = stats.Select(s => s.Name).ToArray();
|
||||
var selectedStatIndex = Array.IndexOf(statNames, effect.Stat);
|
||||
if (selectedStatIndex == -1)
|
||||
{
|
||||
selectedStatIndex = 0;
|
||||
GUI.changed = true;
|
||||
}
|
||||
var newSelection = Popup(selectedStatIndex, statNames);
|
||||
if (newSelection != selectedStatIndex)
|
||||
GUI.changed = true;
|
||||
effect.Stat = statNames[newSelection];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PerformanceStat Inspect(string label, PerformanceStat value, bool isSimple = false)
|
||||
{
|
||||
if(value == null)
|
||||
|
|
@ -1167,13 +1058,13 @@ public class DatabaseInspector : EditorWindow
|
|||
GUILayout.Label("", GUILayout.Width(width));
|
||||
if (!isSimple)
|
||||
{
|
||||
GUILayout.Label("H", _labelStyle);
|
||||
value.HeatDependent = Toggle(value.HeatDependent);
|
||||
GUILayout.Label("HEx", _labelStyle, GUILayout.Width(labelWidth + 5));
|
||||
GUILayout.Label("H", _labelStyle, GUILayout.Width(labelWidth));
|
||||
value.HeatExponentMultiplier = DelayedFloatField(value.HeatExponentMultiplier);
|
||||
GUILayout.Label("D", _labelStyle);
|
||||
value.DurabilityDependent = Toggle(value.DurabilityDependent);
|
||||
GUILayout.Label("QEx", _labelStyle, GUILayout.Width(labelWidth + 5));
|
||||
|
||||
GUILayout.Label("D", _labelStyle, GUILayout.Width(labelWidth));
|
||||
value.DurabilityExponentMultiplier = DelayedFloatField(value.DurabilityExponentMultiplier);
|
||||
|
||||
GUILayout.Label("Q", _labelStyle, GUILayout.Width(labelWidth));
|
||||
value.QualityExponent = DelayedFloatField(value.QualityExponent);
|
||||
}
|
||||
else
|
||||
|
|
@ -1222,6 +1113,9 @@ public class DatabaseInspector : EditorWindow
|
|||
return;
|
||||
}
|
||||
|
||||
if(entry is INamedEntry namedEntry)
|
||||
GUILayout.Label(namedEntry.EntryName, EditorStyles.boldLabel);
|
||||
|
||||
_view = BeginScrollView(
|
||||
_view,
|
||||
false,
|
||||
|
|
@ -1282,86 +1176,6 @@ public class DatabaseInspector : EditorWindow
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region Loadout
|
||||
var loadout = entry as LoadoutData;
|
||||
if (loadout != null)
|
||||
{
|
||||
Space();
|
||||
LabelField("Loadout Hull", EditorStyles.boldLabel);
|
||||
|
||||
if (DatabaseCache.Get(loadout.Hull) is HullData loadoutHull)
|
||||
{
|
||||
// Reserve slots in the loadout for all equippable (non-hull) hardpoints
|
||||
var hardpoints = loadoutHull.Hardpoints.Where(h => h.Type != HardpointType.Hull).ToArray();
|
||||
if (loadout.Gear.Count < hardpoints.Length)
|
||||
loadout.Gear.AddRange(Enumerable.Repeat(Guid.Empty, hardpoints.Length - loadout.Gear.Count));
|
||||
|
||||
Space();
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
// GUILayout.Label($"Equipped Items: {loadout.Gear.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Size ?? 0)}/{loadoutHull.Capacity.Min}", EditorStyles.boldLabel);
|
||||
GUILayout.Label($"Mass: {loadout.Gear.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Mass ?? 0)}", EditorStyles.boldLabel, GUILayout.ExpandWidth(false));
|
||||
}
|
||||
|
||||
int itemIndex = 0;
|
||||
using (var v = new VerticalScope(GUI.skin.box))
|
||||
{
|
||||
for (; itemIndex < hardpoints.Length; itemIndex++)
|
||||
{
|
||||
var hp = hardpoints[itemIndex];
|
||||
|
||||
var loadoutItem = DatabaseCache.Get(loadout.Gear[itemIndex]) as EquippableItemData;
|
||||
|
||||
if (loadoutItem != null && loadoutItem.HardpointType != hp.Type)
|
||||
{
|
||||
loadout.Gear[itemIndex] = Guid.Empty;
|
||||
Debug.Log($"Invalid Item \"{loadoutItem.Name}\" in {Enum.GetName(typeof(HardpointType),hp.Type)} hardpoint for loadout \"{loadout.Name}\"");
|
||||
GUI.changed = true;
|
||||
}
|
||||
|
||||
using (var h = new HorizontalScope(_list.ListItemStyle))
|
||||
{
|
||||
if (h.rect.Contains(current.mousePosition) &&
|
||||
(currentEventType == EventType.DragUpdated || currentEventType == EventType.DragPerform))
|
||||
{
|
||||
var guid = (Guid) DragAndDrop.GetGenericData("Item");
|
||||
var draggedEquippable = DatabaseCache.Get(guid) as EquippableItemData;
|
||||
var good = draggedEquippable != null && draggedEquippable.HardpointType == hp.Type;
|
||||
if (currentEventType == EventType.DragUpdated)
|
||||
DragAndDrop.visualMode = good ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
|
||||
else if (currentEventType == EventType.DragPerform && good)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
loadout.Gear[itemIndex] = guid;
|
||||
|
||||
GUI.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label(Enum.GetName(typeof(HardpointType), hp.Type));
|
||||
if (loadoutItem == null || loadoutItem.HardpointType != hp.Type)
|
||||
GUILayout.Label("Empty Hardpoint", GUILayout.ExpandWidth(false));
|
||||
else
|
||||
{
|
||||
GUILayout.Label(loadoutItem.Name, GUILayout.ExpandWidth(false));
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, Color.black, 0, 0);
|
||||
if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
|
||||
loadout.Gear[itemIndex] = Guid.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (; itemIndex < loadout.Gear.Count; itemIndex++)
|
||||
{
|
||||
loadout.Gear.RemoveAt(itemIndex--);
|
||||
GUI.changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if(!previousBytes.ByteEquals(MessagePackSerializer.Serialize(entry)))
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ public class DatabaseListView : EditorWindow
|
|||
private const float LineHeight = 20;
|
||||
private Vector2 _view;
|
||||
private RethinkQueryStatus _queryStatus;
|
||||
private Dictionary<Guid, HashSet<Guid>> _itemBlueprints = new Dictionary<Guid, HashSet<Guid>>();
|
||||
private HashSet<Guid> _itemBlueprintFoldouts = new HashSet<Guid>();
|
||||
private HashSet<string> _itemGroupFoldouts = new HashSet<string>();
|
||||
private HashSet<Guid> _itemManufacturerFoldouts = new HashSet<Guid>();
|
||||
private HashSet<(Guid, HardpointType)> _itemManufacturerTypeFoldouts = new HashSet<(Guid, HardpointType)>();
|
||||
private string _filePath => Path.Combine(ActionGameManager.GameDataDirectory.FullName, _fileName);
|
||||
private string _fileName = "AetherDB.msgpack";
|
||||
|
||||
|
|
@ -65,30 +65,17 @@ public class DatabaseListView : EditorWindow
|
|||
// Create database cache
|
||||
_databaseCache = new DatabaseCache(_filePath);
|
||||
|
||||
var onInsert = new Action<DatabaseEntry>(entry =>
|
||||
{
|
||||
if (entry is ItemData itemData)
|
||||
{
|
||||
if(!_itemBlueprints.ContainsKey(itemData.ID))
|
||||
_itemBlueprints[itemData.ID] = new HashSet<Guid>();
|
||||
}
|
||||
if (entry is BlueprintData blueprintData)
|
||||
{
|
||||
if(!_itemBlueprints.ContainsKey(blueprintData.Item))
|
||||
_itemBlueprints[blueprintData.Item] = new HashSet<Guid>();
|
||||
_itemBlueprints[blueprintData.Item].Add(blueprintData.ID);
|
||||
}
|
||||
});
|
||||
_databaseCache.OnDataInsertLocal += onInsert;
|
||||
_databaseCache.OnDataInsertRemote += onInsert;
|
||||
// var onInsert = new Action<DatabaseEntry>(entry =>
|
||||
// {
|
||||
// });
|
||||
// _databaseCache.OnDataInsertLocal += onInsert;
|
||||
// _databaseCache.OnDataInsertRemote += onInsert;
|
||||
|
||||
var onDelete = new Action<DatabaseEntry>(entry =>
|
||||
{
|
||||
if (entry is BlueprintData blueprintData)
|
||||
_itemBlueprints[blueprintData.Item].Remove(blueprintData.ID);
|
||||
});
|
||||
_databaseCache.OnDataDeleteLocal += onDelete;
|
||||
_databaseCache.OnDataDeleteRemote += onDelete;
|
||||
// var onDelete = new Action<DatabaseEntry>(entry =>
|
||||
// {
|
||||
// });
|
||||
// _databaseCache.OnDataDeleteLocal += onDelete;
|
||||
// _databaseCache.OnDataDeleteRemote += onDelete;
|
||||
|
||||
_databaseCache.OnDataUpdateLocal += _ => Repaint();
|
||||
_databaseCache.OnDataInsertLocal += _ => Repaint();
|
||||
|
|
@ -176,23 +163,6 @@ public class DatabaseListView : EditorWindow
|
|||
}
|
||||
}
|
||||
|
||||
using (new HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Delete Orphaned Blueprints"))
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var blueprintData in _databaseCache.GetAll<BlueprintData>().ToArray())
|
||||
{
|
||||
if (_databaseCache.Get(blueprintData.Item) == null)
|
||||
{
|
||||
_databaseCache.Delete(blueprintData);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Debug.Log($"Deleted {count} orphaned blueprints!");
|
||||
}
|
||||
}
|
||||
|
||||
if (_queryStatus != null && _queryStatus.RetrievedItems < _queryStatus.GalaxyEntries + _queryStatus.ItemsEntries)
|
||||
{
|
||||
var progressRect = GetControlRect(false, 20);
|
||||
|
|
@ -231,175 +201,169 @@ public class DatabaseListView : EditorWindow
|
|||
}
|
||||
if (_itemTypeFoldouts[i])
|
||||
{
|
||||
var typedItems = items.Where(e => e.GetType() == _itemTypes[i]).OrderBy(item => item.Name);
|
||||
IEnumerable<IGrouping<string, ItemData>> itemGroups = new List<IGrouping<string, ItemData>>();
|
||||
if(_itemTypes[i] == typeof(SimpleCommodityData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(SimpleCommodityCategory), (item as SimpleCommodityData).Category));
|
||||
else if(_itemTypes[i] == typeof(CompoundCommodityData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(CompoundCommodityCategory), (item as CompoundCommodityData).Category));
|
||||
else if(_itemTypes[i] == typeof(GearData) || _itemTypes[i] == typeof(WeaponItemData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HardpointType), (item as GearData).Hardpoint) ?? "Invalid Hardpoint");
|
||||
else if (_itemTypes[i] == typeof(HullData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HullType), (item as HullData).HullType));
|
||||
else itemGroups = typedItems.GroupBy(item => "All");
|
||||
|
||||
foreach (var itemGroup in itemGroups)
|
||||
if (_itemTypes[i] == typeof(SimpleCommodityData) ||
|
||||
_itemTypes[i] == typeof(CompoundCommodityData) ||
|
||||
_itemTypes[i] == typeof(HullData))
|
||||
{
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
GUILayout.Space(20);
|
||||
if (Foldout(_itemGroupFoldouts.Contains(itemGroup.Key), FormatTypeName(itemGroup.Key), true))
|
||||
_itemGroupFoldouts.Add(itemGroup.Key);
|
||||
else _itemGroupFoldouts.Remove(itemGroup.Key);
|
||||
}
|
||||
var typedItems = items
|
||||
.Where(e => e.GetType() == _itemTypes[i])
|
||||
.OrderBy(item => item.Name);
|
||||
IEnumerable<IGrouping<string, ItemData>> itemGroups = new List<IGrouping<string, ItemData>>();
|
||||
if(_itemTypes[i] == typeof(SimpleCommodityData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(SimpleCommodityCategory), (item as SimpleCommodityData).Category));
|
||||
else if(_itemTypes[i] == typeof(CompoundCommodityData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(CompoundCommodityCategory), (item as CompoundCommodityData).Category));
|
||||
else if (_itemTypes[i] == typeof(HullData))
|
||||
itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HullType), (item as HullData).HullType));
|
||||
else itemGroups = typedItems.GroupBy(item => "All");
|
||||
|
||||
if (_itemGroupFoldouts.Contains(itemGroup.Key))
|
||||
foreach (var itemGroup in itemGroups)
|
||||
{
|
||||
foreach (var item in itemGroup)
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
var style = ListItemStyle;
|
||||
var selected = SelectedItem == item.ID;
|
||||
using (new HorizontalScope(selected?SelectedStyle:style))
|
||||
{
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
if (h.rect.Contains(currentEvent.mousePosition))
|
||||
{
|
||||
if (currentEventType == EventType.MouseDrag)
|
||||
{
|
||||
DragAndDrop.PrepareStartDrag();
|
||||
DragAndDrop.SetGenericData("Item", item.ID);
|
||||
DragAndDrop.StartDrag("Database Item");
|
||||
}
|
||||
else if (currentEventType == EventType.MouseUp)
|
||||
Select(item);
|
||||
}
|
||||
GUILayout.Space(20);
|
||||
if (Foldout(_itemGroupFoldouts.Contains(itemGroup.Key), FormatTypeName(itemGroup.Key), true))
|
||||
_itemGroupFoldouts.Add(itemGroup.Key);
|
||||
else _itemGroupFoldouts.Remove(itemGroup.Key);
|
||||
}
|
||||
|
||||
GUILayout.Space(30);
|
||||
GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
||||
}
|
||||
|
||||
using (var h = new HorizontalScope(GUILayout.Width(15)))
|
||||
{
|
||||
if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
||||
{
|
||||
if(_itemBlueprintFoldouts.Contains(item.ID))
|
||||
_itemBlueprintFoldouts.Remove(item.ID);
|
||||
else
|
||||
_itemBlueprintFoldouts.Add(item.ID);
|
||||
}
|
||||
GUILayout.Label(_itemBlueprints[item.ID].Count.ToString());
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
var controlId = GUIUtility.GetControlID(1337, FocusType.Keyboard, position);
|
||||
EditorStyles.foldout.Draw(rect, GUIContent.none, controlId, _itemBlueprintFoldouts.Contains(item.ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_itemBlueprintFoldouts.Contains(item.ID))
|
||||
if (_itemGroupFoldouts.Contains(itemGroup.Key))
|
||||
{
|
||||
foreach (var item in itemGroup)
|
||||
{
|
||||
foreach (var blueprintData in _itemBlueprints[item.ID]
|
||||
.Select(id => _databaseCache.Get<BlueprintData>(id))
|
||||
.OrderBy(bp => bp.Quality))
|
||||
var style = ListItemStyle;
|
||||
var selected = SelectedItem == item.ID;
|
||||
using (new HorizontalScope(selected?SelectedStyle:style))
|
||||
{
|
||||
var blueprintStyle = ListItemStyle;
|
||||
var blueprintSelected = SelectedItem == blueprintData.ID;
|
||||
using (var h = new HorizontalScope(blueprintSelected ? SelectedStyle : blueprintStyle))
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
if (h.rect.Contains(currentEvent.mousePosition))
|
||||
{
|
||||
if (currentEventType == EventType.MouseDrag)
|
||||
{
|
||||
DragAndDrop.PrepareStartDrag();
|
||||
DragAndDrop.SetGenericData("Item", blueprintData.ID);
|
||||
DragAndDrop.SetGenericData("Item", item.ID);
|
||||
DragAndDrop.StartDrag("Database Item");
|
||||
}
|
||||
else if (currentEventType == EventType.MouseUp)
|
||||
Select(blueprintData);
|
||||
Select(item);
|
||||
}
|
||||
|
||||
GUILayout.Space(40);
|
||||
GUILayout.Label(blueprintData.Name,
|
||||
blueprintSelected ? EditorStyles.whiteLabel : GUI.skin.label);
|
||||
GUILayout.Space(30);
|
||||
GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
||||
}
|
||||
}
|
||||
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
||||
{
|
||||
var blueprint = new BlueprintData
|
||||
{
|
||||
Item = item.ID,
|
||||
Name = item.Name
|
||||
};
|
||||
_databaseCache.Add(blueprint);
|
||||
Select(blueprint);
|
||||
}
|
||||
GUILayout.Space(40);
|
||||
GUILayout.Label("New Blueprint");
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor,
|
||||
0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!typeof(EquippableItemData).IsAssignableFrom(_itemTypes[i]))
|
||||
throw new InvalidCastException($"Type {_itemTypes[i].Name} is invalid! Expected equippable item.");
|
||||
var typedItems = items
|
||||
.Where(e => e.GetType() == _itemTypes[i])
|
||||
.Cast<EquippableItemData>()
|
||||
.OrderBy(item => item.Name);
|
||||
var manufacturerGroups = typedItems.GroupBy(item => item.Manufacturer);
|
||||
foreach (var manufacturerGroup in manufacturerGroups)
|
||||
{
|
||||
var manufacturer = _databaseCache.Get<Faction>(manufacturerGroup.Key);
|
||||
var manufacturerName = manufacturer?.Name ?? "None";
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
||||
GUILayout.Space(20);
|
||||
if (Foldout(_itemManufacturerFoldouts.Contains(manufacturerGroup.Key), manufacturerName, true))
|
||||
_itemManufacturerFoldouts.Add(manufacturerGroup.Key);
|
||||
else _itemManufacturerFoldouts.Remove(manufacturerGroup.Key);
|
||||
}
|
||||
|
||||
if (_itemManufacturerFoldouts.Contains(manufacturerGroup.Key))
|
||||
{
|
||||
if (_itemTypes[i] == typeof(GearData) || _itemTypes[i] == typeof(WeaponItemData))
|
||||
{
|
||||
CreateItem(_itemTypes[i], newItem =>
|
||||
var itemGroups = manufacturerGroup.GroupBy(item => item.HardpointType);
|
||||
|
||||
foreach (var itemGroup in itemGroups)
|
||||
{
|
||||
if(newItem is SimpleCommodityData simpleCommodityData)
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
simpleCommodityData.Category =
|
||||
(SimpleCommodityCategory) Enum.Parse(typeof(SimpleCommodityCategory),
|
||||
itemGroup.Key);
|
||||
simpleCommodityData.Name = $"New {itemGroup.Key}";
|
||||
GUILayout.Space(30);
|
||||
if (Foldout(_itemManufacturerTypeFoldouts.Contains((manufacturerGroup.Key, itemGroup.Key)), Enum.GetName(typeof(HardpointType), itemGroup.Key), true))
|
||||
_itemManufacturerTypeFoldouts.Add((manufacturerGroup.Key, itemGroup.Key));
|
||||
else _itemManufacturerTypeFoldouts.Remove((manufacturerGroup.Key, itemGroup.Key));
|
||||
}
|
||||
else if(newItem is CompoundCommodityData compoundCommodityData)
|
||||
|
||||
if (_itemManufacturerTypeFoldouts.Contains((manufacturerGroup.Key, itemGroup.Key)))
|
||||
{
|
||||
compoundCommodityData.Category =
|
||||
(CompoundCommodityCategory) Enum.Parse(
|
||||
typeof(CompoundCommodityCategory), itemGroup.Key);
|
||||
compoundCommodityData.Name = $"New {itemGroup.Key}";
|
||||
foreach (var item in itemGroup)
|
||||
{
|
||||
var style = ListItemStyle;
|
||||
var selected = SelectedItem == item.ID;
|
||||
using (new HorizontalScope(selected?SelectedStyle:style))
|
||||
{
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
if (h.rect.Contains(currentEvent.mousePosition))
|
||||
{
|
||||
if (currentEventType == EventType.MouseDrag)
|
||||
{
|
||||
DragAndDrop.PrepareStartDrag();
|
||||
DragAndDrop.SetGenericData("Item", item.ID);
|
||||
DragAndDrop.StartDrag("Database Item");
|
||||
}
|
||||
else if (currentEventType == EventType.MouseUp)
|
||||
Select(item);
|
||||
}
|
||||
|
||||
GUILayout.Space(40);
|
||||
GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(newItem is GearData gearData)
|
||||
{
|
||||
gearData.Hardpoint =
|
||||
(HardpointType) Enum.Parse(typeof(HardpointType), itemGroup.Key);
|
||||
gearData.Name = $"New {itemGroup.Key}";
|
||||
}
|
||||
else if(newItem is HullData hullData)
|
||||
{
|
||||
hullData.HullType = (HullType) Enum.Parse(typeof(HullType), itemGroup.Key);
|
||||
hullData.Name = $"New {itemGroup.Key}";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in manufacturerGroup)
|
||||
{
|
||||
var style = ListItemStyle;
|
||||
var selected = SelectedItem == item.ID;
|
||||
using (new HorizontalScope(selected?SelectedStyle:style))
|
||||
{
|
||||
using (var h = new HorizontalScope())
|
||||
{
|
||||
if (h.rect.Contains(currentEvent.mousePosition))
|
||||
{
|
||||
if (currentEventType == EventType.MouseDrag)
|
||||
{
|
||||
DragAndDrop.PrepareStartDrag();
|
||||
DragAndDrop.SetGenericData("Item", item.ID);
|
||||
DragAndDrop.StartDrag("Database Item");
|
||||
}
|
||||
else if (currentEventType == EventType.MouseUp)
|
||||
Select(item);
|
||||
}
|
||||
|
||||
GUILayout.Space(30);
|
||||
GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.Space(30);
|
||||
GUILayout.Label("New " + itemGroup.Key);
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!itemGroups.Any())
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
using (var h = new HorizontalScope(ListItemStyle))
|
||||
{
|
||||
if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
||||
CreateItem(_itemTypes[i]);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.Label("New " + _itemTypes[i].Name);
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
||||
}
|
||||
if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
||||
CreateItem(_itemTypes[i]);
|
||||
GUILayout.Space(20);
|
||||
GUILayout.Label("New " + FormatTypeName(_itemTypes[i].Name));
|
||||
var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
||||
GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue