Implement use skin action.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Crtr.Browsing.UI;
|
using Cryville.Crtr.Browsing.UI;
|
||||||
|
using Cryville.Crtr.Config;
|
||||||
using Cryville.Crtr.UI;
|
using Cryville.Crtr.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -16,14 +17,23 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public override void Invoke(Uri uri, IChartDetail resource) {
|
public override void Invoke(Uri uri, IChartDetail resource) {
|
||||||
|
Invoke(resource.RulesetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasTab(string ruleset) {
|
||||||
|
int tabId;
|
||||||
|
var master = ResourceBrowserMaster.Instance;
|
||||||
|
if (master == null) return false;
|
||||||
|
return _rulesetTabs.TryGetValue(ruleset, out tabId) && master.HasTab(tabId);
|
||||||
|
}
|
||||||
|
public static void Invoke(string ruleset, Action<RulesetConfig> overrides = null) {
|
||||||
var master = ResourceBrowserMaster.Instance;
|
var master = ResourceBrowserMaster.Instance;
|
||||||
var ruleset = resource.RulesetId;
|
|
||||||
int tabId;
|
int tabId;
|
||||||
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
|
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
|
||||||
return;
|
return;
|
||||||
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
||||||
try {
|
try {
|
||||||
browser.Load(ruleset);
|
browser.Load(ruleset, overrides);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Dialog.Show(null, ex.Message);
|
Dialog.Show(null, ex.Message);
|
||||||
@@ -32,6 +42,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_rulesetTabs[ruleset] = master.AddAndOpenTab(string.Format("Config: {0}", ruleset), browser);
|
_rulesetTabs[ruleset] = master.AddAndOpenTab(string.Format("Config: {0}", ruleset), browser);
|
||||||
|
browser.InitAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs
Normal file
33
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using Cryville.Crtr.Browsing.UI;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
|
internal class UseSkinAction : ResourceAction<ISkinDetail> {
|
||||||
|
readonly RulesetConfigBrowser _destination;
|
||||||
|
public UseSkinAction() : this(null) { }
|
||||||
|
public UseSkinAction(RulesetConfigBrowser destination) {
|
||||||
|
_destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name { get { return "Use"; } }
|
||||||
|
|
||||||
|
public override int Priority { get { return -100; } }
|
||||||
|
|
||||||
|
public override bool CanInvoke(Uri uri, ISkinDetail resource) {
|
||||||
|
if (_destination == null) {
|
||||||
|
return !OpenConfigAction.HasTab(resource.RulesetId);
|
||||||
|
}
|
||||||
|
return _destination.RulesetName == resource.RulesetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Invoke(Uri uri, ISkinDetail resource) {
|
||||||
|
if (_destination == null) {
|
||||||
|
OpenConfigAction.Invoke(resource.RulesetId, config => config.generic.Skin = resource.Name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_destination.SetSkin(resource.Name);
|
||||||
|
OpenConfigAction.Invoke(resource.RulesetId, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac898133ecfdb3f42bdade958381cd1a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
6
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs
Normal file
6
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
internal interface ISkinDetail : IResourceMeta {
|
||||||
|
string RulesetId { get; }
|
||||||
|
string Name { get; }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 38d9ea3c71d485a44ba9d335ddf95d67
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -2,15 +2,17 @@ using Cryville.Crtr.Skin;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Legacy {
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
internal class LegacySkinDetail : IResourceMeta {
|
internal class LegacySkinDetail : ISkinDetail {
|
||||||
public string Name { get; internal set; }
|
public string RulesetId { get { return Meta.ruleset; } }
|
||||||
|
public string Name { get { return Meta == null ? OverrideName : Meta.name; } }
|
||||||
|
public string OverrideName { get; internal set; }
|
||||||
public SkinDefinition Meta { get; internal set; }
|
public SkinDefinition Meta { get; internal set; }
|
||||||
|
|
||||||
public IEnumerable<MetaProperty> Properties {
|
public IEnumerable<MetaProperty> Properties {
|
||||||
get {
|
get {
|
||||||
if (Meta == null) {
|
if (Meta == null) {
|
||||||
if (Name != null)
|
if (OverrideName != null)
|
||||||
yield return new MetaProperty("Name", Name);
|
yield return new MetaProperty("Name", OverrideName);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
yield return new MetaProperty("Name", Meta.name);
|
yield return new MetaProperty("Name", Meta.name);
|
||||||
|
@@ -21,7 +21,7 @@ namespace Cryville.Crtr.Browsing.Legacy {
|
|||||||
return new LegacySkinDetail { Meta = meta };
|
return new LegacySkinDetail { Meta = meta };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return new LegacySkinDetail { Name = dir.Name };
|
return new LegacySkinDetail { OverrideName = dir.Name };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
Actions.Changed += OnActionsChanged;
|
Actions.Changed += OnActionsChanged;
|
||||||
Actions.Register(new PlayChartAction());
|
Actions.Register(new PlayChartAction());
|
||||||
Actions.Register(new OpenConfigAction());
|
Actions.Register(new OpenConfigAction());
|
||||||
|
Actions.Register(new UseSkinAction());
|
||||||
|
|
||||||
OnTabClicked(AddPathedBrowserTab("Local Charts", new LegacyChartResourceManager(Settings.Default.GameDataPath)));
|
OnTabClicked(AddPathedBrowserTab("Local Charts", new LegacyChartResourceManager(Settings.Default.GameDataPath)));
|
||||||
AddPathedBrowserTab("Local Skins", new LegacySkinResourceManager(Settings.Default.GameDataPath));
|
AddPathedBrowserTab("Local Skins", new LegacySkinResourceManager(Settings.Default.GameDataPath));
|
||||||
@@ -67,6 +68,9 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
OnTabClicked(tab);
|
OnTabClicked(tab);
|
||||||
return tab.GetHashCode();
|
return tab.GetHashCode();
|
||||||
}
|
}
|
||||||
|
public bool HasTab(int id) {
|
||||||
|
return _tabMap.ContainsKey(id);
|
||||||
|
}
|
||||||
public bool TryOpenTab(int id) {
|
public bool TryOpenTab(int id) {
|
||||||
BrowserTab tab;
|
BrowserTab tab;
|
||||||
if (_tabMap.TryGetValue(id, out tab)) {
|
if (_tabMap.TryGetValue(id, out tab)) {
|
||||||
|
@@ -22,14 +22,15 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
InputConfigPanel m_inputConfigPanel;
|
InputConfigPanel m_inputConfigPanel;
|
||||||
|
|
||||||
public RulesetDefinition ruleset;
|
RulesetDefinition _ruleset;
|
||||||
RulesetConfig _rscfg;
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
string _rulesetName;
|
public string RulesetName { get; private set; }
|
||||||
|
UseSkinAction _useSkinAction;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
|
|
||||||
public void Load(string rulesetName) {
|
public void Load(string rulesetName, Action<RulesetConfig> overrides = null) {
|
||||||
_rulesetName = rulesetName;
|
RulesetName = rulesetName;
|
||||||
FileInfo file = new FileInfo(Path.Combine(
|
FileInfo file = new FileInfo(Path.Combine(
|
||||||
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
||||||
));
|
));
|
||||||
@@ -38,11 +39,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
DirectoryInfo dir = file.Directory;
|
DirectoryInfo dir = file.Directory;
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||||
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
_ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
if (_ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||||
ruleset.LoadPdt(dir);
|
_ruleset.LoadPdt(dir);
|
||||||
}
|
}
|
||||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
FileInfo cfgfile = new FileInfo(Path.Combine(
|
||||||
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
|
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
|
||||||
@@ -59,12 +60,24 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overrides?.Invoke(_rscfg);
|
||||||
|
|
||||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||||
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(_ruleset.Root.configs, _rscfg.configs);
|
||||||
m_inputConfigPanel.Load(ruleset.Root, _rscfg);
|
m_inputConfigPanel.Load(_ruleset.Root, _rscfg);
|
||||||
|
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
}
|
}
|
||||||
|
public void InitAction() {
|
||||||
|
Master.Actions.Register(_useSkinAction = new UseSkinAction(this));
|
||||||
|
}
|
||||||
|
void OnDestroy() {
|
||||||
|
Master.Actions.Unregister(_useSkinAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetSkin(string skin) {
|
||||||
|
_rscfg.generic.Skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
public void SwitchCategory(GameObject cat) {
|
public void SwitchCategory(GameObject cat) {
|
||||||
foreach (Transform c in m_content) {
|
foreach (Transform c in m_content) {
|
||||||
@@ -77,7 +90,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
if (_loaded) {
|
if (_loaded) {
|
||||||
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
||||||
FileInfo cfgFile = new FileInfo(Path.Combine(
|
FileInfo cfgFile = new FileInfo(Path.Combine(
|
||||||
Game.GameDataPath, "config", "rulesets", _rulesetName + ".json"
|
Game.GameDataPath, "config", "rulesets", RulesetName + ".json"
|
||||||
));
|
));
|
||||||
using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
|
using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
|
||||||
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||||
|
Reference in New Issue
Block a user