92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
using Cryville.Common.Unity;
|
|
using Cryville.Common.Unity.UI;
|
|
using Cryville.Crtr.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Cryville.Crtr.Browsing.UI {
|
|
public class PathedResourceBrowser : ResourceBrowser {
|
|
public IPathedResourceManager<ChartDetail> ResourceManager;
|
|
public ScrollableItemGrid ItemContainer;
|
|
|
|
readonly HashSet<int> _selectedItems = new HashSet<int>();
|
|
readonly Dictionary<int, BrowserItem> _items = new Dictionary<int, BrowserItem>();
|
|
|
|
[Obsolete]
|
|
FileDialog _dialog;
|
|
|
|
protected virtual void Start() {
|
|
ItemContainer.LoadItem = LoadItem;
|
|
ResourceManager.ItemChanged += OnItemChanged;
|
|
ResourceManager.ChangeDirectory(new string[] { "" });
|
|
InitDialog();
|
|
}
|
|
|
|
[Obsolete]
|
|
protected void InitDialog() {
|
|
_dialog = Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
|
_dialog.gameObject.SetActive(false);
|
|
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
|
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
|
|
_dialog.OnClose += OnAddDialogClosed;
|
|
}
|
|
|
|
bool _itemChanged;
|
|
void OnItemChanged() { _itemChanged = true; }
|
|
void Update() {
|
|
if (_itemChanged) {
|
|
_itemChanged = false;
|
|
_selectedItems.Clear();
|
|
_items.Clear();
|
|
ItemContainer.ItemCount = ResourceManager.Count;
|
|
}
|
|
}
|
|
|
|
private bool LoadItem(int id, GameObject obj) {
|
|
var bi = obj.GetComponent<BrowserItem>();
|
|
_items[id] = bi;
|
|
try {
|
|
var item = ResourceManager[id];
|
|
bi.Load(id, item, _selectedItems.Contains(id));
|
|
}
|
|
catch (Exception) {
|
|
bi.Load(id, default(ChartDetail), _selectedItems.Contains(id));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public virtual void OnDirectoryItemClicked(int id) {
|
|
ResourceManager.OpenDirectory(id);
|
|
}
|
|
|
|
public void OnObjectItemClicked(int id) {
|
|
foreach (var item in _selectedItems) _items[item].OnDeselect();
|
|
_selectedItems.Clear();
|
|
_items[id].OnSelect();
|
|
_selectedItems.Add(id);
|
|
Master.ShowDetail(id, ResourceManager[id]);
|
|
}
|
|
|
|
public void OnPathClicked(int index) {
|
|
ResourceManager.ReturnToDirectory(index);
|
|
}
|
|
|
|
[Obsolete]
|
|
public void OnAddButtonClicked() {
|
|
_dialog.Show();
|
|
}
|
|
|
|
[Obsolete]
|
|
private void OnAddDialogClosed() {
|
|
if (_dialog.FileName == null) return;
|
|
if (ResourceManager.ImportItemFrom(new Uri(_dialog.FileName))) {
|
|
Popup.Create("Import succeeded");
|
|
}
|
|
else {
|
|
Popup.Create("Import failed");
|
|
}
|
|
}
|
|
}
|
|
}
|