2020-12-22 03:13:43 +00:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using System;
|
2020-05-22 22:34:08 +01:00
|
|
|
|
using System.Collections.Generic;
|
2020-04-23 03:31:17 +01:00
|
|
|
|
using System.IO;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
2021-03-30 01:17:58 +01:00
|
|
|
|
using JsonKnownTypes;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
using RethinkDb.Driver;
|
|
|
|
|
|
using RethinkDb.Driver.Net;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
2020-04-14 04:08:33 +01:00
|
|
|
|
using static UnityEditor.EditorGUILayout;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
public class DatabaseListView : EditorWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
// Singleton to avoid multiple instances of window.
|
|
|
|
|
|
private static DatabaseListView _instance;
|
2020-12-12 00:02:00 +00:00
|
|
|
|
public static DatabaseListView Instance => _instance ? _instance : GetWindow<DatabaseListView>();
|
2021-03-30 01:17:58 +01:00
|
|
|
|
[MenuItem("Window/GameCult/Database Tools")]
|
2020-11-29 22:50:12 +00:00
|
|
|
|
static void Init() => Instance.Show();
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_instance = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public Guid SelectedItem;
|
|
|
|
|
|
public GUIStyle SelectedStyle;
|
|
|
|
|
|
|
|
|
|
|
|
public static RethinkDB R = RethinkDB.R;
|
|
|
|
|
|
|
|
|
|
|
|
private DatabaseCache _databaseCache;
|
2020-05-23 01:19:07 +01:00
|
|
|
|
private bool[] _itemTypeFoldouts;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
private bool _itemsFoldout;
|
|
|
|
|
|
private bool _compoundFoldout;
|
|
|
|
|
|
private bool _simpleFoldout;
|
|
|
|
|
|
private bool _commoditiesFoldout;
|
|
|
|
|
|
//private bool _consumablesFoldout;
|
|
|
|
|
|
private Type[] _itemTypes;
|
|
|
|
|
|
private bool _listItemStyle;
|
|
|
|
|
|
private GUIStyle _listStyleOdd;
|
|
|
|
|
|
private GUIStyle _listStyleEven;
|
|
|
|
|
|
private static DatabaseInspector _inspector;
|
|
|
|
|
|
private Type[] _entryTypes;
|
|
|
|
|
|
private bool[] _entryFoldouts;
|
|
|
|
|
|
private string _connectionString;
|
|
|
|
|
|
private const float LineHeight = 20;
|
2020-04-14 04:08:33 +01:00
|
|
|
|
private Vector2 _view;
|
2020-05-10 00:16:33 +01:00
|
|
|
|
private RethinkQueryStatus _queryStatus;
|
2020-05-23 01:19:07 +01:00
|
|
|
|
private HashSet<string> _itemGroupFoldouts = new HashSet<string>();
|
2021-03-22 05:22:31 +00:00
|
|
|
|
private HashSet<Guid> _itemManufacturerFoldouts = new HashSet<Guid>();
|
|
|
|
|
|
private HashSet<(Guid, HardpointType)> _itemManufacturerTypeFoldouts = new HashSet<(Guid, HardpointType)>();
|
2021-03-30 01:17:58 +01:00
|
|
|
|
private string _filePath => Path.Combine(new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData").FullName, _fileName);
|
2021-03-15 11:40:46 +00:00
|
|
|
|
private string _fileName = "AetherDB.msgpack";
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
|
public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
|
|
|
|
|
|
|
2020-03-22 19:05:26 +00:00
|
|
|
|
public GUIStyle ListItemStyle =>
|
|
|
|
|
|
(_listItemStyle = !_listItemStyle) ? _listStyleEven : _listStyleOdd;
|
2020-11-29 22:50:12 +00:00
|
|
|
|
|
2020-03-22 19:05:26 +00:00
|
|
|
|
void OnEnable()
|
|
|
|
|
|
{
|
2021-03-30 01:17:58 +01:00
|
|
|
|
|
2021-03-15 11:40:46 +00:00
|
|
|
|
//_filePath = ;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
// Create database cache
|
2021-03-16 11:06:54 +00:00
|
|
|
|
_databaseCache = new DatabaseCache(_filePath);
|
2020-05-22 22:34:08 +01:00
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
// var onInsert = new Action<DatabaseEntry>(entry =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// });
|
|
|
|
|
|
// _databaseCache.OnDataInsertLocal += onInsert;
|
|
|
|
|
|
// _databaseCache.OnDataInsertRemote += onInsert;
|
2020-05-22 22:34:08 +01:00
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
// var onDelete = new Action<DatabaseEntry>(entry =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// });
|
|
|
|
|
|
// _databaseCache.OnDataDeleteLocal += onDelete;
|
|
|
|
|
|
// _databaseCache.OnDataDeleteRemote += onDelete;
|
2020-05-22 22:34:08 +01:00
|
|
|
|
|
2020-03-22 19:05:26 +00:00
|
|
|
|
_databaseCache.OnDataUpdateLocal += _ => Repaint();
|
2020-05-23 01:19:07 +01:00
|
|
|
|
_databaseCache.OnDataInsertLocal += _ => Repaint();
|
|
|
|
|
|
_databaseCache.OnDataDeleteLocal += _ => Repaint();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
_databaseCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint);
|
2020-05-23 01:19:07 +01:00
|
|
|
|
_databaseCache.OnDataInsertRemote += _ => EditorDispatcher.Dispatch(Repaint);
|
|
|
|
|
|
_databaseCache.OnDataDeleteRemote += _ => EditorDispatcher.Dispatch(Repaint);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
DatabaseInspector.DatabaseCache = _databaseCache;
|
2020-11-29 22:50:12 +00:00
|
|
|
|
_inspector = DatabaseInspector.Instance;
|
|
|
|
|
|
_inspector.Show();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
_itemTypes = typeof(ItemData).GetAllChildClasses()
|
|
|
|
|
|
.Where(t => t.GetCustomAttribute<InspectableAttribute>() != null).ToArray();
|
|
|
|
|
|
_entryTypes = typeof(DatabaseEntry).GetAllChildClasses()
|
|
|
|
|
|
.Where(t => t.GetCustomAttribute<InspectableAttribute>() != null && !typeof(ItemData).IsAssignableFrom(t)).ToArray();
|
|
|
|
|
|
|
2020-05-23 01:19:07 +01:00
|
|
|
|
_itemTypeFoldouts = new bool[_itemTypes.Length];
|
2020-03-22 19:05:26 +00:00
|
|
|
|
_entryFoldouts = new bool[_entryTypes.Length];
|
|
|
|
|
|
|
|
|
|
|
|
if (EditorPrefs.HasKey("RethinkDB.URL"))
|
|
|
|
|
|
_connectionString = EditorPrefs.GetString("RethinkDB.URL");
|
|
|
|
|
|
else
|
|
|
|
|
|
_connectionString = "Enter DB URL";
|
|
|
|
|
|
|
|
|
|
|
|
InitStyles();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitStyles()
|
|
|
|
|
|
{
|
|
|
|
|
|
var isDark = EditorGUIUtility.isProSkin;
|
|
|
|
|
|
_listStyleOdd = new GUIStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
normal = {background = isDark ? XKCDColors.DarkGrey.ToTexture() : XKCDColors.LightGrey.ToTexture()},
|
|
|
|
|
|
margin = new RectOffset(0, 0, 0, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
_listStyleEven = new GUIStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
normal = {background = isDark ? Color.Lerp(XKCDColors.DarkGrey,Color.black,.5f).ToTexture() : Color.Lerp(XKCDColors.LightGrey,Color.white,.5f).ToTexture()},
|
|
|
|
|
|
margin = new RectOffset(0, 0, 0, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
SelectedStyle = new GUIStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
normal = {background = isDark ? XKCDColors.DarkGreyBlue.ToTexture() : XKCDColors.Greyblue.ToTexture()},
|
|
|
|
|
|
margin = new RectOffset(0, 0, 0, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnGUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
Event currentEvent = Event.current;
|
|
|
|
|
|
EventType currentEventType = currentEvent.type;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentEventType == EventType.DragUpdated)
|
|
|
|
|
|
// Indicate that we don't accept drags ourselves
|
|
|
|
|
|
DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
|
|
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope())
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2020-04-28 01:50:50 +01:00
|
|
|
|
_connectionString = TextField(_connectionString);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
if (GUILayout.Button("Connect"))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorPrefs.SetString("RethinkDB.URL", _connectionString);
|
2021-03-30 01:17:58 +01:00
|
|
|
|
JsonKnownTypesSettingsManager.RegisterTypeAssembly<ItemData>();
|
2020-05-10 00:16:33 +01:00
|
|
|
|
_queryStatus = RethinkConnection.RethinkConnect(_databaseCache, _connectionString);
|
2020-04-23 03:31:17 +01:00
|
|
|
|
}
|
2021-03-15 11:40:46 +00:00
|
|
|
|
// if (GUILayout.Button("Connect All"))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// EditorPrefs.SetString("RethinkDB.URL", _connectionString);
|
|
|
|
|
|
// _queryStatus = RethinkConnection.RethinkConnect(_databaseCache, _connectionString, true, false);
|
|
|
|
|
|
// }
|
2020-04-28 01:50:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
using (var h = new HorizontalScope())
|
|
|
|
|
|
{
|
2021-03-16 11:06:54 +00:00
|
|
|
|
//_fileName = TextField(_fileName);
|
2020-04-23 03:31:17 +01:00
|
|
|
|
if (GUILayout.Button("Save"))
|
|
|
|
|
|
{
|
2021-03-16 11:06:54 +00:00
|
|
|
|
_databaseCache.Save();
|
2021-01-08 12:44:10 +00:00
|
|
|
|
Debug.Log("Local DB Cache Saved!");
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
2020-11-27 22:47:33 +00:00
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Load"))
|
|
|
|
|
|
{
|
2021-03-16 11:06:54 +00:00
|
|
|
|
_databaseCache.Load();
|
2021-01-08 12:44:10 +00:00
|
|
|
|
Debug.Log("Loaded DB From Local Cache!");
|
2020-11-27 22:47:33 +00:00
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
2020-05-10 00:16:33 +01:00
|
|
|
|
|
|
|
|
|
|
if (_queryStatus != null && _queryStatus.RetrievedItems < _queryStatus.GalaxyEntries + _queryStatus.ItemsEntries)
|
|
|
|
|
|
{
|
|
|
|
|
|
var progressRect = GetControlRect(false, 20);
|
|
|
|
|
|
EditorGUI.ProgressBar(progressRect, (float)_queryStatus.RetrievedItems/(_queryStatus.GalaxyEntries + _queryStatus.ItemsEntries), "Sync Progress");
|
|
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
|
GUILayout.Space(5);
|
2020-05-10 00:16:33 +01:00
|
|
|
|
|
2021-03-15 11:40:46 +00:00
|
|
|
|
_view = BeginScrollView(
|
|
|
|
|
|
_view,
|
|
|
|
|
|
false,
|
|
|
|
|
|
false,
|
|
|
|
|
|
GUIStyle.none,
|
|
|
|
|
|
GUI.skin.verticalScrollbar,
|
|
|
|
|
|
GUI.skin.scrollView,
|
|
|
|
|
|
GUILayout.Width(EditorGUIUtility.currentViewWidth),
|
|
|
|
|
|
GUILayout.ExpandHeight(true));
|
|
|
|
|
|
|
2020-05-10 00:16:33 +01:00
|
|
|
|
// if(GUILayout.Button("Log Cache Count"))
|
|
|
|
|
|
// Debug.Log($"Cache contains {_databaseCache.AllEntries.Count()} elements");
|
2020-03-22 19:05:26 +00:00
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2020-04-28 01:50:50 +01:00
|
|
|
|
_itemsFoldout = Foldout(_itemsFoldout, "Items", true);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (_itemsFoldout)
|
|
|
|
|
|
{
|
|
|
|
|
|
var items = _databaseCache.AllEntries.Where(item => item is ItemData).Cast<ItemData>().ToArray();
|
|
|
|
|
|
for (var i = 0; i < _itemTypes.Length; i++)
|
|
|
|
|
|
{
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
GUILayout.Space(10);
|
2020-05-23 01:19:07 +01:00
|
|
|
|
_itemTypeFoldouts[i] = Foldout(_itemTypeFoldouts[i],
|
2020-04-09 07:48:45 +01:00
|
|
|
|
((NameAttribute) _itemTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_itemTypes[i].Name),
|
2020-03-22 19:05:26 +00:00
|
|
|
|
true);
|
|
|
|
|
|
}
|
2020-05-23 01:19:07 +01:00
|
|
|
|
if (_itemTypeFoldouts[i])
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
if (_itemTypes[i] == typeof(SimpleCommodityData) ||
|
|
|
|
|
|
_itemTypes[i] == typeof(CompoundCommodityData) ||
|
|
|
|
|
|
_itemTypes[i] == typeof(HullData))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
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");
|
2020-05-23 01:19:07 +01:00
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
foreach (var itemGroup in itemGroups)
|
2020-05-22 22:34:08 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-05-22 22:34:08 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
GUILayout.Space(20);
|
|
|
|
|
|
if (Foldout(_itemGroupFoldouts.Contains(itemGroup.Key), FormatTypeName(itemGroup.Key), true))
|
|
|
|
|
|
_itemGroupFoldouts.Add(itemGroup.Key);
|
|
|
|
|
|
else _itemGroupFoldouts.Remove(itemGroup.Key);
|
|
|
|
|
|
}
|
2020-05-22 22:34:08 +01:00
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
if (_itemGroupFoldouts.Contains(itemGroup.Key))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in itemGroup)
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
var style = ListItemStyle;
|
|
|
|
|
|
var selected = SelectedItem == item.ID;
|
|
|
|
|
|
using (new HorizontalScope(selected?SelectedStyle:style))
|
2020-05-22 22:34:08 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
using (var h = new HorizontalScope())
|
2020-05-22 22:34:08 +01:00
|
|
|
|
{
|
2020-05-23 01:19:07 +01:00
|
|
|
|
if (h.rect.Contains(currentEvent.mousePosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentEventType == EventType.MouseDrag)
|
|
|
|
|
|
{
|
|
|
|
|
|
DragAndDrop.PrepareStartDrag();
|
2021-03-22 05:22:31 +00:00
|
|
|
|
DragAndDrop.SetGenericData("Item", item.ID);
|
2020-05-23 01:19:07 +01:00
|
|
|
|
DragAndDrop.StartDrag("Database Item");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (currentEventType == EventType.MouseUp)
|
2021-03-22 05:22:31 +00:00
|
|
|
|
Select(item);
|
2020-05-23 01:19:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
GUILayout.Space(30);
|
|
|
|
|
|
GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
2020-05-22 22:34:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-22 05:22:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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";
|
2020-06-01 03:11:04 +01:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
|
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
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))
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
var itemGroups = manufacturerGroup.GroupBy(item => item.HardpointType);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var itemGroup in itemGroups)
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
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));
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|
2021-03-22 05:22:31 +00:00
|
|
|
|
|
|
|
|
|
|
if (_itemManufacturerTypeFoldouts.Contains((manufacturerGroup.Key, itemGroup.Key)))
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|
2021-03-22 05:22:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in manufacturerGroup)
|
|
|
|
|
|
{
|
|
|
|
|
|
var style = ListItemStyle;
|
|
|
|
|
|
var selected = SelectedItem == item.ID;
|
|
|
|
|
|
using (new HorizontalScope(selected?SelectedStyle:style))
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|
2021-03-22 05:22:31 +00:00
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
|
2021-03-22 05:22:31 +00:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2021-03-22 05:22:31 +00:00
|
|
|
|
if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
|
|
|
|
|
CreateItem(_itemTypes[i]);
|
|
|
|
|
|
GUILayout.Space(20);
|
|
|
|
|
|
GUILayout.Label("New " + FormatTypeName(_itemTypes[i].Name));
|
2021-03-30 01:17:58 +01:00
|
|
|
|
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
|
|
|
|
|
// GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-16 11:06:54 +00:00
|
|
|
|
//var entries = _databaseCache.AllEntries.Where(item => !(item is ItemData)).ToArray();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
for (var i = 0; i < _entryTypes.Length; i++)
|
|
|
|
|
|
{
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
2020-04-28 01:50:50 +01:00
|
|
|
|
_entryFoldouts[i] = Foldout(_entryFoldouts[i],
|
2020-04-09 07:48:45 +01:00
|
|
|
|
((NameAttribute) _entryTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_entryTypes[i].Name),
|
2020-03-22 19:05:26 +00:00
|
|
|
|
true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_entryFoldouts[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
2021-03-16 11:06:54 +00:00
|
|
|
|
foreach (var entry in _databaseCache.GetAll(_entryTypes[i]).OrderBy(entry=>entry is INamedEntry namedEntry ? namedEntry.EntryName : entry.ID.ToString()))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
index++;
|
|
|
|
|
|
var style = ListItemStyle;
|
|
|
|
|
|
var selected = SelectedItem == entry.ID;
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope(selected?SelectedStyle:style))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (h.rect.Contains(currentEvent.mousePosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentEventType == EventType.MouseDrag)
|
|
|
|
|
|
{
|
|
|
|
|
|
DragAndDrop.PrepareStartDrag();
|
|
|
|
|
|
DragAndDrop.SetGenericData("Item", entry.ID);
|
|
|
|
|
|
DragAndDrop.StartDrag("Database Item");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (currentEventType == EventType.MouseUp)
|
2020-05-22 22:34:08 +01:00
|
|
|
|
Select(entry);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
GUILayout.Space(10);
|
|
|
|
|
|
GUILayout.Label((entry as INamedEntry)?.EntryName ?? index.ToString(), selected ? EditorStyles.whiteLabel : GUI.skin.label);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
using (var h = new HorizontalScope(ListItemStyle))
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none))
|
|
|
|
|
|
CreateItem(_entryTypes[i]);
|
|
|
|
|
|
GUILayout.Space(10);
|
|
|
|
|
|
GUILayout.Label("New " + _entryTypes[i].Name);
|
2021-03-30 01:17:58 +01:00
|
|
|
|
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
|
|
|
|
|
// GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-14 04:08:33 +01:00
|
|
|
|
|
|
|
|
|
|
EndScrollView();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
|
private string FormatTypeName(string typeName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (typeName.EndsWith("Data")
|
|
|
|
|
|
? typeName.Substring(0, typeName.Length - 4)
|
|
|
|
|
|
: typeName).SplitCamelCase();
|
|
|
|
|
|
}
|
2020-05-22 22:34:08 +01:00
|
|
|
|
|
|
|
|
|
|
void Select(DatabaseEntry item)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedItem = item.ID;
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
_inspector.entry = _databaseCache.Get(SelectedItem);
|
|
|
|
|
|
_inspector.Repaint();
|
|
|
|
|
|
}
|
2020-04-09 07:48:45 +01:00
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
private DatabaseEntry CreateItem(Type type, Action<DatabaseEntry> onCreate = null)
|
2020-03-22 19:05:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
var newEntry = (DatabaseEntry) Activator.CreateInstance(type);
|
|
|
|
|
|
if(newEntry is INamedEntry entry)
|
2020-05-22 22:34:08 +01:00
|
|
|
|
entry.EntryName = $"New {FormatTypeName(type.Name)}";
|
2020-06-01 03:11:04 +01:00
|
|
|
|
onCreate?.Invoke(newEntry);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
_databaseCache.Add(newEntry);
|
2020-05-22 22:34:08 +01:00
|
|
|
|
Select(newEntry);
|
|
|
|
|
|
return newEntry;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|