custom controls stuff
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package funkin.options.keybinds;
|
||||
|
||||
import flixel.util.FlxColor;
|
||||
|
||||
import haxe.xml.Access;
|
||||
using StringTools;
|
||||
|
||||
|
||||
class KeybindsOptions extends MusicBeatSubstate {
|
||||
public static var instance:KeybindsOptions;
|
||||
|
||||
public var categories = [
|
||||
public var categories:Array<ControlsCategory> = [
|
||||
{
|
||||
name: 'Notes',
|
||||
settings: [
|
||||
@@ -127,6 +128,9 @@ class KeybindsOptions extends MusicBeatSubstate {
|
||||
FlxG.camera.follow(camFollow, LOCKON, 0.125);
|
||||
}
|
||||
|
||||
var customCategories = loadCustomCategories();
|
||||
for (i in customCategories) categories.push(i);
|
||||
|
||||
var k:Int = 0;
|
||||
for(category in categories) {
|
||||
k++;
|
||||
@@ -152,8 +156,10 @@ class KeybindsOptions extends MusicBeatSubstate {
|
||||
};
|
||||
e.name = e.name.substring(5, e.name.length - 1);
|
||||
}
|
||||
if (e.sparrowIcon != null) sparrowIcon = e.sparrowIcon;
|
||||
if (e.sparrowAnim != null) sparrowAnim = e.sparrowAnim;
|
||||
|
||||
var text = new KeybindSetting(100, k * 75, e.name, e.control, sparrowIcon, sparrowAnim);
|
||||
var text = new KeybindSetting(100, k * 75, e.name, e.control, sparrowIcon, sparrowAnim, e.custom == null ? false : e.custom);
|
||||
if (!isSubState)
|
||||
text.bind1.color = text.bind2.color = FlxColor.BLACK;
|
||||
alphabets.add(text);
|
||||
@@ -199,7 +205,9 @@ class KeybindsOptions extends MusicBeatSubstate {
|
||||
close();
|
||||
else
|
||||
FlxG.switchState(new OptionsMenu());
|
||||
ControlsUtil.resetCustomControls();
|
||||
Options.applyKeybinds();
|
||||
ControlsUtil.loadCustomControls();
|
||||
Options.save();
|
||||
return;
|
||||
}
|
||||
@@ -248,4 +256,59 @@ class KeybindsOptions extends MusicBeatSubstate {
|
||||
camFollow.setPosition(FlxG.width / 2, FlxG.height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadCustomCategories() {
|
||||
var customCategories:Array<ControlsCategory> = [];
|
||||
|
||||
var xmlPath = Paths.xml("config/controls");
|
||||
for(source in [funkin.backend.assets.AssetsLibraryList.AssetSource.SOURCE, funkin.backend.assets.AssetsLibraryList.AssetSource.MODS]) {
|
||||
if (Paths.assetsTree.existsSpecific(xmlPath, "TEXT", source)) {
|
||||
var access:Access = null;
|
||||
try {
|
||||
access = new Access(Xml.parse(Paths.assetsTree.getSpecificAsset(xmlPath, "TEXT", source)).firstElement());
|
||||
} catch(e) {
|
||||
Logs.trace('Error while parsing controls.xml: ${Std.string(e)}', ERROR);
|
||||
}
|
||||
|
||||
if (access != null) {
|
||||
for (category in access.elements) {
|
||||
if (!category.has.name) continue;
|
||||
|
||||
var cat:ControlsCategory = {
|
||||
name: category.getAtt("name"),
|
||||
settings: []
|
||||
};
|
||||
|
||||
for (control in category.elements) {
|
||||
if (control.has.menuName && control.has.saveName) {
|
||||
cat.settings.push({
|
||||
name: control.getAtt("menuName"),
|
||||
control: control.getAtt("saveName"),
|
||||
custom: true,
|
||||
sparrowIcon: control.getAtt("menuIcon").getDefault(null),
|
||||
sparrowAnim: control.getAtt("menuAnim").getDefault(null)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
customCategories.push(cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return customCategories;
|
||||
}
|
||||
}
|
||||
|
||||
typedef KeybindSettingData = {
|
||||
var name:String;
|
||||
var control:String;
|
||||
var ?custom:Bool;
|
||||
var ?sparrowIcon:String;
|
||||
var ?sparrowAnim:String;
|
||||
}
|
||||
|
||||
typedef ControlsCategory = {
|
||||
var name:String;
|
||||
var settings:Array<KeybindSettingData>;
|
||||
}
|
||||
Reference in New Issue
Block a user