Implement use skin action.
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
Actions.Changed += OnActionsChanged;
|
||||
Actions.Register(new PlayChartAction());
|
||||
Actions.Register(new OpenConfigAction());
|
||||
Actions.Register(new UseSkinAction());
|
||||
|
||||
OnTabClicked(AddPathedBrowserTab("Local Charts", new LegacyChartResourceManager(Settings.Default.GameDataPath)));
|
||||
AddPathedBrowserTab("Local Skins", new LegacySkinResourceManager(Settings.Default.GameDataPath));
|
||||
@@ -67,6 +68,9 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
OnTabClicked(tab);
|
||||
return tab.GetHashCode();
|
||||
}
|
||||
public bool HasTab(int id) {
|
||||
return _tabMap.ContainsKey(id);
|
||||
}
|
||||
public bool TryOpenTab(int id) {
|
||||
BrowserTab tab;
|
||||
if (_tabMap.TryGetValue(id, out tab)) {
|
||||
|
@@ -22,14 +22,15 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
[SerializeField]
|
||||
InputConfigPanel m_inputConfigPanel;
|
||||
|
||||
public RulesetDefinition ruleset;
|
||||
RulesetDefinition _ruleset;
|
||||
RulesetConfig _rscfg;
|
||||
|
||||
string _rulesetName;
|
||||
public string RulesetName { get; private set; }
|
||||
UseSkinAction _useSkinAction;
|
||||
bool _loaded;
|
||||
|
||||
public void Load(string rulesetName) {
|
||||
_rulesetName = rulesetName;
|
||||
public void Load(string rulesetName, Action<RulesetConfig> overrides = null) {
|
||||
RulesetName = rulesetName;
|
||||
FileInfo file = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
||||
));
|
||||
@@ -38,11 +39,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
}
|
||||
DirectoryInfo dir = file.Directory;
|
||||
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
|
||||
});
|
||||
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
if (_ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
_ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
||||
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_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
||||
m_inputConfigPanel.Load(ruleset.Root, _rscfg);
|
||||
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(_ruleset.Root.configs, _rscfg.configs);
|
||||
m_inputConfigPanel.Load(_ruleset.Root, _rscfg);
|
||||
|
||||
_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) {
|
||||
foreach (Transform c in m_content) {
|
||||
@@ -77,7 +90,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
if (_loaded) {
|
||||
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
||||
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)) {
|
||||
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
|
Reference in New Issue
Block a user