260 lines
8.2 KiB
Haxe
260 lines
8.2 KiB
Haxe
package funkin.options.keybinds;
|
|
|
|
import flixel.FlxCamera;
|
|
import flixel.effects.FlxFlicker;
|
|
import funkin.system.Controls;
|
|
import funkin.options.Options;
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
|
import flixel.addons.transition.FlxTransitionableState;
|
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
|
import funkin.ui.Alphabet;
|
|
import flixel.util.FlxColor;
|
|
import flixel.input.keyboard.FlxKey;
|
|
import flixel.math.FlxMath;
|
|
import flixel.FlxObject;
|
|
import flixel.FlxSprite;
|
|
import flixel.FlxG;
|
|
|
|
using StringTools;
|
|
|
|
class KeybindsOptions extends MusicBeatSubstate {
|
|
public static var instance:KeybindsOptions;
|
|
|
|
public var categories = [
|
|
{
|
|
name: 'Notes',
|
|
settings: [
|
|
{
|
|
name: '{noteLeft}',
|
|
control: 'NOTE_LEFT'
|
|
},
|
|
{
|
|
name: '{noteDown}',
|
|
control: 'NOTE_DOWN'
|
|
},
|
|
{
|
|
name: '{noteUp}',
|
|
control: 'NOTE_UP'
|
|
},
|
|
{
|
|
name: '{noteRight}',
|
|
control: 'NOTE_RIGHT'
|
|
},
|
|
]
|
|
},
|
|
{
|
|
name: 'UI',
|
|
settings: [
|
|
{
|
|
name: 'Left',
|
|
control: 'LEFT'
|
|
},
|
|
{
|
|
name: 'Down',
|
|
control: 'DOWN'
|
|
},
|
|
{
|
|
name: 'Up',
|
|
control: 'UP'
|
|
},
|
|
{
|
|
name: 'Right',
|
|
control: 'RIGHT'
|
|
},
|
|
{
|
|
name: 'Accept',
|
|
control: 'ACCEPT'
|
|
},
|
|
{
|
|
name: 'Back',
|
|
control: 'BACK'
|
|
},
|
|
{
|
|
name: 'Reset',
|
|
control: 'RESET'
|
|
},
|
|
{
|
|
name: 'Pause',
|
|
control: 'PAUSE'
|
|
},
|
|
]
|
|
}
|
|
];
|
|
|
|
public var settingCam:FlxCamera;
|
|
|
|
public var p2Selected:Bool = false;
|
|
public var curSelected:Int = -1;
|
|
public var canSelect:Bool = true;
|
|
public var alphabets:FlxTypedGroup<KeybindSetting>;
|
|
public var bg:FlxSprite;
|
|
public var coloredBG:FlxSprite;
|
|
public var noteColors:Array<FlxColor> = [
|
|
0xFFC24B99,
|
|
0xFF00FFFF,
|
|
0xFF12FA05,
|
|
0xFFF9393F
|
|
];
|
|
public var camFollow:FlxObject = new FlxObject(0, 0, 2, 2);
|
|
|
|
var isSubState:Bool = false;
|
|
|
|
public override function create() {
|
|
super.create();
|
|
instance = this;
|
|
|
|
|
|
isSubState = FlxG.state != this;
|
|
alphabets = new FlxTypedGroup<KeybindSetting>();
|
|
bg = new FlxSprite(-80).loadGraphic(Paths.image(isSubState ? 'menuTransparent' : 'menuBGBlue'));
|
|
coloredBG = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat'));
|
|
for(bg in [bg, coloredBG]) {
|
|
bg.scrollFactor.set();
|
|
bg.scale.set(1.15, 1.15);
|
|
bg.updateHitbox();
|
|
bg.screenCenter();
|
|
bg.antialiasing = true;
|
|
add(bg);
|
|
}
|
|
coloredBG.alpha = 0;
|
|
|
|
if (isSubState) {
|
|
// is substate, opened from pause menu
|
|
if (settingCam == null) {
|
|
settingCam = new FlxCamera();
|
|
settingCam.bgColor = 0xAA000000;
|
|
FlxG.cameras.add(settingCam, false);
|
|
}
|
|
cameras = [settingCam];
|
|
bg.alpha = 0;
|
|
settingCam.follow(camFollow, LOCKON, 0.125);
|
|
} else {
|
|
FlxG.camera.follow(camFollow, LOCKON, 0.125);
|
|
}
|
|
|
|
var k:Int = 0;
|
|
for(category in categories) {
|
|
k++;
|
|
var title = new Alphabet(0, k * 75, category.name, true);
|
|
title.screenCenter(X);
|
|
add(title);
|
|
|
|
k++;
|
|
for(e in category.settings) {
|
|
// TODO!!
|
|
var xOffset:Float = 200;
|
|
var sparrowIcon:String = null;
|
|
var sparrowAnim:String = null;
|
|
if (e.name.startsWith('{note')) {// is actually a note!!
|
|
sparrowIcon = "NOTE_assets";
|
|
sparrowAnim = switch(e.name) {
|
|
case '{noteLeft}':
|
|
"purple0";
|
|
case '{noteDown}':
|
|
"blue0";
|
|
case '{noteUp}':
|
|
"green0";
|
|
default:
|
|
"red0";
|
|
};
|
|
e.name = e.name.substring(5, e.name.length - 1);
|
|
}
|
|
|
|
var text = new KeybindSetting(100, k * 75, e.name, e.control, sparrowIcon, sparrowAnim);
|
|
if (!isSubState)
|
|
text.bind1.color = text.bind2.color = FlxColor.BLACK;
|
|
alphabets.add(text);
|
|
k++;
|
|
}
|
|
}
|
|
add(alphabets);
|
|
changeSelection(1);
|
|
|
|
add(camFollow);
|
|
}
|
|
|
|
public override function destroy() {
|
|
super.destroy();
|
|
if (settingCam != null) FlxG.cameras.remove(settingCam);
|
|
instance = null;
|
|
}
|
|
|
|
var skipThisFrame:Bool = true;
|
|
|
|
public override function update(elapsed:Float) {
|
|
super.update(elapsed);
|
|
|
|
|
|
if (isSubState) {
|
|
bg.alpha = lerp(bg.alpha, 0.1, 0.125);
|
|
} else {
|
|
if (curSelected < 4) {
|
|
if (coloredBG.alpha == 0)
|
|
coloredBG.color = noteColors[curSelected];
|
|
else
|
|
coloredBG.color = CoolUtil.lerpColor(coloredBG.color, noteColors[curSelected], 0.0625);
|
|
|
|
coloredBG.alpha = lerp(coloredBG.alpha, 1, 0.0625);
|
|
} else
|
|
coloredBG.alpha = lerp(coloredBG.alpha, 0, 0.0625);
|
|
}
|
|
|
|
|
|
if (canSelect) {
|
|
changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0));
|
|
if (controls.BACK) {
|
|
FlxTransitionableState.skipNextTransIn = true;
|
|
if (isSubState)
|
|
close();
|
|
else
|
|
FlxG.switchState(new OptionsMenu());
|
|
controls.setKeyboardScheme(Solo);
|
|
return;
|
|
}
|
|
|
|
if (controls.ACCEPT && !skipThisFrame) {
|
|
if (alphabets.members[curSelected] != null) {
|
|
canSelect = false;
|
|
CoolUtil.playMenuSFX(1);
|
|
FlxFlicker.flicker(alphabets.members[curSelected], 0.4, 0.1, true, false, function(t) {
|
|
alphabets.members[curSelected].changeKeybind(function() {
|
|
canSelect = true;
|
|
}, function() {
|
|
canSelect = true;
|
|
}, p2Selected);
|
|
});
|
|
}
|
|
}
|
|
|
|
if (controls.LEFT_P || controls.RIGHT_P) {
|
|
if (alphabets.members[curSelected] != null) {
|
|
CoolUtil.playMenuSFX(0);
|
|
alphabets.members[curSelected].p2Selected = (p2Selected = !p2Selected);
|
|
}
|
|
}
|
|
}
|
|
super.update(elapsed);
|
|
skipThisFrame = false;
|
|
|
|
}
|
|
|
|
public function changeSelection(change:Int) {
|
|
if (change == 0) return;
|
|
CoolUtil.playMenuSFX(0, 0.4);
|
|
curSelected = FlxMath.wrap(curSelected + change, 0, alphabets.length-1);
|
|
alphabets.forEach(function(e) {
|
|
e.alpha = 0.55;
|
|
});
|
|
if (alphabets.members[curSelected] != null) {
|
|
var alphabet = alphabets.members[curSelected];
|
|
alphabet.p2Selected = p2Selected;
|
|
alphabet.alpha = 1;
|
|
var minH = FlxG.height / 2;
|
|
var maxH = alphabets.members[alphabets.length-1].y + alphabets.members[alphabets.length-1].height - (FlxG.height / 2);
|
|
if (minH < maxH)
|
|
camFollow.setPosition(FlxG.width / 2, FlxMath.bound(alphabet.y + (alphabet.height / 2) - (35), minH, maxH));
|
|
else
|
|
camFollow.setPosition(FlxG.width / 2, FlxG.height / 2);
|
|
}
|
|
}
|
|
} |