Code structure cleanup.
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
internal class BrowserItemTile : BrowserItem {
|
||||
#pragma warning disable IDE0044
|
||||
[SerializeField]
|
||||
private Sprite m_iconPlaceholder;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
private bool _dir;
|
||||
private Image _icon;
|
||||
private TMP_Text _title;
|
||||
private TMP_Text _desc;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_icon = transform.Find("__content__/Icon").GetComponent<Image>();
|
||||
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<TMP_Text>();
|
||||
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<TMP_Text>();
|
||||
}
|
||||
void OnDestroy() {
|
||||
if (meta.Icon != null) meta.Icon.Cancel();
|
||||
if (_icon.sprite != null && _icon.sprite != m_iconPlaceholder) {
|
||||
Texture2D.Destroy(_icon.sprite.texture);
|
||||
Sprite.Destroy(_icon.sprite);
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
internal override void Load(int id, ResourceItemMeta item) {
|
||||
OnDestroy();
|
||||
base.Load(id, item);
|
||||
_dir = meta.IsDirectory;
|
||||
_icon.sprite = m_iconPlaceholder;
|
||||
if (meta.Icon != null) meta.Icon.Destination = DisplayCover;
|
||||
_title.text = meta.Name;
|
||||
_desc.text = string.Format("{0}\n{1}", meta.DescriptionMain, meta.DescriptionSub);
|
||||
}
|
||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||
if (succeeded) {
|
||||
_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
|
||||
}
|
||||
}
|
||||
public void OnClick() {
|
||||
if (Id == null) return;
|
||||
ResourceBrowser resourceBrowser = GetComponentInParent<ResourceBrowser>();
|
||||
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
|
||||
else resourceBrowser.OnObjectItemClicked(Id.Value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b38d66b3e6e5d94438c72f855c4efff9
|
||||
timeCreated: 1637554149
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal file
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Extension;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public struct ChartDetail {
|
||||
public AsyncDelivery<Texture2D> Cover { get; set; }
|
||||
public ChartMeta Meta { get; set; }
|
||||
}
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 477e04b1ed5b60e48886fb76081245c5
|
||||
timeCreated: 1637722157
|
||||
licenseType: Free
|
||||
guid: 5f9870328bccefa4d8d4f6d5e3cef591
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
@@ -1,67 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class DetailPanel : ResourceBrowserUnit {
|
||||
#pragma warning disable IDE0044
|
||||
[SerializeField]
|
||||
private Sprite m_coverPlaceholder;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
int _id;
|
||||
ChartDetail _data;
|
||||
GameObject _placeholder;
|
||||
GameObject _outerContent;
|
||||
Transform _content;
|
||||
Image _cover;
|
||||
TMP_Text _title;
|
||||
TMP_Text _desc;
|
||||
|
||||
protected override void Awake() {
|
||||
base.Awake();
|
||||
_placeholder = transform.Find("__placeholder__").gameObject;
|
||||
_outerContent = transform.Find("__content__").gameObject;
|
||||
_content = _outerContent.transform.Find("__content__");
|
||||
_cover = _content.Find("Cover").GetComponent<Image>();
|
||||
_title = _content.Find("Texts/Title").GetComponent<TMP_Text>();
|
||||
_desc = _content.Find("Texts/Description").GetComponent<TMP_Text>();
|
||||
}
|
||||
void OnDestroy() {
|
||||
if (_data.Cover != null) _data.Cover.Cancel();
|
||||
if (_cover.sprite != null && _cover.sprite != m_coverPlaceholder) {
|
||||
Texture2D.Destroy(_cover.sprite.texture);
|
||||
Sprite.Destroy(_cover.sprite);
|
||||
}
|
||||
}
|
||||
public void Load(int id, ChartDetail data) {
|
||||
_id = id;
|
||||
_placeholder.SetActive(false);
|
||||
_outerContent.SetActive(true);
|
||||
OnDestroy();
|
||||
_data = data;
|
||||
_cover.sprite = m_coverPlaceholder;
|
||||
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
||||
var meta = data.Meta;
|
||||
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
|
||||
_desc.text = string.Format(
|
||||
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
||||
meta.song.author, meta.author,
|
||||
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
|
||||
);
|
||||
}
|
||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||
if (succeeded) {
|
||||
_cover.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
|
||||
}
|
||||
}
|
||||
public void OnPlay() {
|
||||
Master.Open(_id, _data);
|
||||
}
|
||||
public void OnConfig() {
|
||||
Master.OpenConfig(_id, _data);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ using Cryville.Common.Unity;
|
||||
using Cryville.Crtr.Extension;
|
||||
using Cryville.Crtr.Extensions;
|
||||
using Cryville.Crtr.Extensions.Umg;
|
||||
using Cryville.Crtr.UI;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@@ -1,27 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
internal class PathPart : MonoBehaviour {
|
||||
private int _id;
|
||||
private Text _exp;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_exp = transform.Find("__text__").GetComponent<Text>();
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
internal void Load(int id, string exp) {
|
||||
_id = id;
|
||||
_exp.text = Parse(exp);
|
||||
}
|
||||
string Parse(string exp) {
|
||||
if (exp == "") return "(root)";
|
||||
else return exp;
|
||||
}
|
||||
public void OnClick() {
|
||||
GetComponentInParent<ResourceBrowser>().OnPathClicked(_id);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d443a346e9a19d4eabbb0fa9ec7016f
|
||||
timeCreated: 1637566071
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,77 +0,0 @@
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class ResourceBrowser : ResourceBrowserUnit {
|
||||
public IResourceManager<ChartDetail> ResourceManager;
|
||||
public ScrollableItemGrid PathContainer;
|
||||
public ScrollableItemGrid ItemContainer;
|
||||
|
||||
FileDialog _dialog;
|
||||
|
||||
protected void Start() {
|
||||
PathContainer.LoadItem = LoadPathPart;
|
||||
ItemContainer.LoadItem = LoadItem;
|
||||
ItemContainer.ItemCount = ResourceManager.ChangeDirectory(new string[] { "" });
|
||||
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
|
||||
|
||||
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||
_dialog.gameObject.SetActive(false);
|
||||
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
||||
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
|
||||
_dialog.OnClose += OnAddDialogClosed;
|
||||
}
|
||||
|
||||
private bool LoadPathPart(int id, GameObject obj) {
|
||||
var item = ResourceManager.CurrentDirectory[id];
|
||||
obj.GetComponent<PathPart>().Load(id, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool LoadItem(int id, GameObject obj) {
|
||||
var bi = obj.GetComponent<BrowserItem>();
|
||||
try {
|
||||
var item = ResourceManager.GetItemMeta(id);
|
||||
bi.Load(id, item);
|
||||
}
|
||||
catch (Exception) {
|
||||
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDirectoryItemClicked(int id) {
|
||||
ItemContainer.ItemCount = ResourceManager.OpenDirectory(id);
|
||||
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
|
||||
if (PathContainer.ItemCount >= PathContainer.VisibleLines - 1)
|
||||
PathContainer.GetComponentInParent<ScrollRect>().velocity = new Vector2(-Screen.width, 0);
|
||||
}
|
||||
|
||||
public void OnObjectItemClicked(int id) {
|
||||
Master.ShowDetail(id, ResourceManager.GetItemDetail(id));
|
||||
}
|
||||
|
||||
public void OnPathClicked(int id) {
|
||||
ItemContainer.ItemCount = ResourceManager.ReturnToDirectory(id);
|
||||
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
|
||||
}
|
||||
|
||||
public void OnAddButtonClicked() {
|
||||
_dialog.Show();
|
||||
}
|
||||
|
||||
private void OnAddDialogClosed() {
|
||||
if (_dialog.FileName == null) return;
|
||||
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
||||
Popup.Create("Import succeeded");
|
||||
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
||||
}
|
||||
else {
|
||||
Popup.Create("Import failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6b4df13dea0e4a469d7e54e7e8fb428
|
||||
timeCreated: 1637234060
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,97 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Extension;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class ResourceBrowserMaster : MonoBehaviour {
|
||||
[SerializeField]
|
||||
private Button m_playButton;
|
||||
[SerializeField]
|
||||
private Button m_configButton;
|
||||
[SerializeField]
|
||||
private ConfigPanelMaster m_configPanel;
|
||||
|
||||
private DockLayoutGroup _group;
|
||||
public ResourceBrowser MainBrowser { get; private set; }
|
||||
private DetailPanel _detailPanel;
|
||||
readonly List<ResourceBrowserUnit> _units = new List<ResourceBrowserUnit>();
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_group = GetComponent<DockLayoutGroup>();
|
||||
MainBrowser = transform.GetChild(0).GetComponent<ResourceBrowser>();
|
||||
MainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
|
||||
_detailPanel = transform.GetChild(1).GetComponent<DetailPanel>();
|
||||
_units.Add(MainBrowser);
|
||||
_units.Add(_detailPanel);
|
||||
}
|
||||
|
||||
int _slideDest = 0;
|
||||
void Update() {
|
||||
var cv = _group.SlideIndex;
|
||||
_group.SlideIndex = (cv - _slideDest) * 0.86f + _slideDest;
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
public void ShowDetail(int id, ChartDetail detail) {
|
||||
SlideIntoView(1);
|
||||
_detailPanel.Load(id, detail);
|
||||
m_playButton.gameObject.SetActive(true);
|
||||
m_configButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
/*[Obsolete]
|
||||
public void ShowSettings(int id, ChartDetail detail) {
|
||||
SlideIntoView(2);
|
||||
_settingsPanel.Load(id, detail);
|
||||
}*/
|
||||
|
||||
public bool Back() {
|
||||
if (_slideDest == 0) return false;
|
||||
SlideIntoView(_slideDest - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SlideIntoView(int v) {
|
||||
v = Mathf.Clamp(v, 0, _units.Count - 1);
|
||||
var cv = _group.SlideIndex;
|
||||
if (cv < v) _slideDest = v - 1;
|
||||
else _slideDest = v;
|
||||
_units[_slideDest].SlideToLeft();
|
||||
_units[_slideDest + 1].SlideToRight();
|
||||
}
|
||||
|
||||
public void Open(int id, ChartDetail detail) {
|
||||
SetDataSettings(id, detail);
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
||||
#else
|
||||
Application.LoadLevelAdditive("Play");
|
||||
#endif
|
||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OpenConfig(int id, ChartDetail detail) {
|
||||
SetDataSettings(id, detail);
|
||||
}
|
||||
|
||||
void SetDataSettings(int id, ChartDetail detail) {
|
||||
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
||||
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
||||
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
|
||||
}
|
||||
}
|
||||
|
||||
public struct ChartDetail {
|
||||
public AsyncDelivery<Texture2D> Cover { get; set; }
|
||||
public ChartMeta Meta { get; set; }
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 256d7d3efda1f9b4c882eb42e608cc8e
|
||||
timeCreated: 1638414803
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class ResourceBrowserUnit : MonoBehaviour {
|
||||
protected ResourceBrowserMaster Master { get; private set; }
|
||||
protected virtual void Awake() {
|
||||
Master = GetComponentInParent<ResourceBrowserMaster>();
|
||||
}
|
||||
public virtual void SlideToLeft() { }
|
||||
public virtual void SlideToRight() { }
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a69c80e5f3e7bd04485bc3afc5826584
|
||||
timeCreated: 1638415083
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -2,15 +2,6 @@ using Cryville.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
internal abstract class BrowserItem : MonoBehaviour {
|
||||
public int? Id { get; private set; }
|
||||
protected ResourceItemMeta meta;
|
||||
internal virtual void Load(int id, ResourceItemMeta item) {
|
||||
Id = id;
|
||||
meta = item;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ResourceItemMeta {
|
||||
public bool IsDirectory { get; set; }
|
||||
public AsyncDelivery<Texture2D> Icon { get; set; }
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfa7de3f6f944914d9999fcfda245f97
|
||||
timeCreated: 1637552994
|
||||
licenseType: Free
|
||||
guid: f535064222dd08c4f8e52d6e9144079a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
Reference in New Issue
Block a user