44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using Cryville.Crtr.Browsing.UI;
|
|
using Cryville.Crtr.Config;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace Cryville.Crtr.Browsing.Actions {
|
|
internal class OpenConfigAction : ResourceAction<IChartDetail> {
|
|
public override string Name { get { return "Config"; } }
|
|
|
|
public override int Priority { get { return -50; } }
|
|
|
|
static readonly Dictionary<string, int> _rulesetTabs = new();
|
|
|
|
public override bool CanInvoke(Uri uri, IChartDetail resource) {
|
|
return true;
|
|
}
|
|
public override void Invoke(Uri uri, IChartDetail resource) {
|
|
Invoke(resource.RulesetId);
|
|
}
|
|
|
|
public static bool HasTab(string ruleset) {
|
|
var master = ResourceBrowserMaster.Instance;
|
|
if (master == null) return false;
|
|
return _rulesetTabs.TryGetValue(ruleset, out int tabId) && master.HasTab(tabId);
|
|
}
|
|
public static void Invoke(string ruleset, Action<RulesetConfig> overrides = null) {
|
|
var master = ResourceBrowserMaster.Instance;
|
|
if (_rulesetTabs.TryGetValue(ruleset, out int tabId) && master.TryOpenTab(tabId))
|
|
return;
|
|
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
|
try {
|
|
browser.Load(ruleset, overrides);
|
|
}
|
|
catch (Exception) {
|
|
Object.Destroy(browser.gameObject);
|
|
throw;
|
|
}
|
|
_rulesetTabs[ruleset] = master.AddAndOpenTab(string.Format("{0} (Config)", ruleset), browser);
|
|
browser.InitAction();
|
|
}
|
|
}
|
|
}
|