keybindings and other shit
This commit is contained in:
271
source/KeyBindMenu.hx
Normal file
271
source/KeyBindMenu.hx
Normal file
@ -0,0 +1,271 @@
|
||||
package;
|
||||
|
||||
/// Code created by Rozebud for FPS Plus (thanks rozebud)
|
||||
// modified by KadeDev for use in Kade Engine/Tricky
|
||||
|
||||
import flixel.FlxSubState;
|
||||
import Options.Option;
|
||||
import flixel.input.FlxInput;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.effects.FlxFlicker;
|
||||
import flixel.graphics.frames.FlxAtlasFrames;
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.tweens.FlxEase;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.util.FlxColor;
|
||||
import io.newgrounds.NG;
|
||||
import lime.app.Application;
|
||||
import lime.utils.Assets;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.input.FlxKeyManager;
|
||||
|
||||
|
||||
using StringTools;
|
||||
|
||||
class KeyBindMenu extends FlxSubState
|
||||
{
|
||||
|
||||
var keyTextDisplay:FlxText;
|
||||
var keyWarning:FlxText;
|
||||
var warningTween:FlxTween;
|
||||
var keyText:Array<String> = ["LEFT", "DOWN", "UP", "RIGHT"];
|
||||
var defaultKeys:Array<String> = ["A", "S", "W", "D", "R"];
|
||||
var curSelected:Int = 0;
|
||||
|
||||
var keys:Array<String> = [FlxG.save.data.leftBind,
|
||||
FlxG.save.data.downBind,
|
||||
FlxG.save.data.upBind,
|
||||
FlxG.save.data.rightBind];
|
||||
|
||||
var tempKey:String = "";
|
||||
var blacklist:Array<String> = ["ESCAPE", "ENTER", "BACKSPACE", "SPACE"];
|
||||
|
||||
var blackBox:FlxSprite;
|
||||
var infoText:FlxText;
|
||||
|
||||
var state:String = "select";
|
||||
|
||||
override function create()
|
||||
{
|
||||
|
||||
for (i in 0...keys.length)
|
||||
{
|
||||
var k = keys[i];
|
||||
if (k == null)
|
||||
keys[i] = defaultKeys[i];
|
||||
}
|
||||
|
||||
//FlxG.sound.playMusic('assets/music/configurator' + TitleState.soundExt);
|
||||
|
||||
persistentUpdate = persistentDraw = true;
|
||||
|
||||
keyTextDisplay = new FlxText(-10, 0, 1280, "", 72);
|
||||
keyTextDisplay.scrollFactor.set(0, 0);
|
||||
keyTextDisplay.setFormat("VCR OSD Mono", 42, FlxColor.WHITE, FlxTextAlign.CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
|
||||
keyTextDisplay.borderSize = 2;
|
||||
keyTextDisplay.borderQuality = 3;
|
||||
|
||||
blackBox = new FlxSprite(0,0).makeGraphic(FlxG.width,FlxG.height,FlxColor.BLACK);
|
||||
add(blackBox);
|
||||
|
||||
infoText = new FlxText(-10, 580, 1280, "(Escape to save, backspace to leave without saving)", 72);
|
||||
infoText.scrollFactor.set(0, 0);
|
||||
infoText.setFormat("VCR OSD Mono", 24, FlxColor.WHITE, FlxTextAlign.CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
|
||||
infoText.borderSize = 2;
|
||||
infoText.borderQuality = 3;
|
||||
infoText.alpha = 0;
|
||||
add(infoText);
|
||||
add(keyTextDisplay);
|
||||
|
||||
blackBox.alpha = 0;
|
||||
keyTextDisplay.alpha = 0;
|
||||
|
||||
FlxTween.tween(keyTextDisplay, {alpha: 1}, 1, {ease: FlxEase.expoInOut});
|
||||
FlxTween.tween(infoText, {alpha: 1}, 1.4, {ease: FlxEase.expoInOut});
|
||||
FlxTween.tween(blackBox, {alpha: 0.7}, 1, {ease: FlxEase.expoInOut});
|
||||
|
||||
OptionsMenu.instance.acceptInput = false;
|
||||
|
||||
textUpdate();
|
||||
|
||||
super.create();
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
|
||||
switch(state){
|
||||
|
||||
case "select":
|
||||
if (FlxG.keys.justPressed.UP)
|
||||
{
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
changeItem(-1);
|
||||
}
|
||||
|
||||
if (FlxG.keys.justPressed.DOWN)
|
||||
{
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
changeItem(1);
|
||||
}
|
||||
|
||||
if (FlxG.keys.justPressed.ENTER){
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'));
|
||||
state = "input";
|
||||
}
|
||||
else if(FlxG.keys.justPressed.ESCAPE){
|
||||
quit();
|
||||
}
|
||||
else if (FlxG.keys.justPressed.BACKSPACE){
|
||||
reset();
|
||||
}
|
||||
|
||||
case "input":
|
||||
tempKey = keys[curSelected];
|
||||
keys[curSelected] = "?";
|
||||
textUpdate();
|
||||
state = "waiting";
|
||||
|
||||
case "waiting":
|
||||
if(FlxG.keys.justPressed.ESCAPE){
|
||||
keys[curSelected] = tempKey;
|
||||
state = "select";
|
||||
FlxG.sound.play(Paths.sound('confirmMenu'));
|
||||
}
|
||||
else if(FlxG.keys.justPressed.ENTER){
|
||||
addKey(defaultKeys[curSelected]);
|
||||
save();
|
||||
state = "select";
|
||||
}
|
||||
else if(FlxG.keys.justPressed.ANY){
|
||||
addKey(FlxG.keys.getIsDown()[0].ID.toString());
|
||||
save();
|
||||
state = "select";
|
||||
}
|
||||
|
||||
|
||||
case "exiting":
|
||||
|
||||
|
||||
default:
|
||||
state = "select";
|
||||
|
||||
}
|
||||
|
||||
if(FlxG.keys.justPressed.ANY)
|
||||
textUpdate();
|
||||
|
||||
super.update(elapsed);
|
||||
|
||||
}
|
||||
|
||||
function textUpdate(){
|
||||
|
||||
keyTextDisplay.text = "\n\n";
|
||||
|
||||
for(i in 0...4){
|
||||
|
||||
var textStart = (i == curSelected) ? "> " : " ";
|
||||
keyTextDisplay.text += textStart + keyText[i] + ": " + ((keys[i] != keyText[i]) ? (keys[i] + " / ") : "" ) + keyText[i] + " ARROW\n";
|
||||
|
||||
}
|
||||
|
||||
keyTextDisplay.screenCenter();
|
||||
|
||||
}
|
||||
|
||||
function save(){
|
||||
|
||||
FlxG.save.data.upBind = keys[2];
|
||||
FlxG.save.data.downBind = keys[1];
|
||||
FlxG.save.data.leftBind = keys[0];
|
||||
FlxG.save.data.rightBind = keys[3];
|
||||
|
||||
FlxG.save.flush();
|
||||
|
||||
PlayerSettings.player1.controls.loadKeyBinds();
|
||||
|
||||
}
|
||||
|
||||
function reset(){
|
||||
|
||||
for(i in 0...5){
|
||||
keys[i] = defaultKeys[i];
|
||||
}
|
||||
quit();
|
||||
|
||||
}
|
||||
|
||||
function quit(){
|
||||
|
||||
state = "exiting";
|
||||
|
||||
save();
|
||||
|
||||
OptionsMenu.instance.acceptInput = true;
|
||||
|
||||
FlxTween.tween(keyTextDisplay, {alpha: 0}, 1, {ease: FlxEase.expoInOut});
|
||||
FlxTween.tween(blackBox, {alpha: 0}, 1.1, {ease: FlxEase.expoInOut, onComplete: function(flx:FlxTween){close();}});
|
||||
FlxTween.tween(infoText, {alpha: 0}, 1, {ease: FlxEase.expoInOut});
|
||||
}
|
||||
|
||||
|
||||
function addKey(r:String){
|
||||
|
||||
var shouldReturn:Bool = true;
|
||||
|
||||
var notAllowed:Array<String> = [];
|
||||
|
||||
for(x in keys){
|
||||
if(x != tempKey){notAllowed.push(x);}
|
||||
}
|
||||
|
||||
for(x in blacklist){notAllowed.push(x);}
|
||||
|
||||
if(curSelected != 4){
|
||||
|
||||
for(x in keyText){
|
||||
if(x != keyText[curSelected]){notAllowed.push(x);}
|
||||
}
|
||||
|
||||
}
|
||||
else {for(x in keyText){notAllowed.push(x);}}
|
||||
|
||||
trace(notAllowed);
|
||||
|
||||
for(x in 0...keys.length)
|
||||
{
|
||||
var oK = keys[x];
|
||||
if(oK == r)
|
||||
keys[x] = null;
|
||||
}
|
||||
|
||||
if(shouldReturn){
|
||||
keys[curSelected] = r;
|
||||
FlxG.sound.play(Paths.sound('Hover','clown'));
|
||||
}
|
||||
else{
|
||||
keys[curSelected] = tempKey;
|
||||
FlxG.sound.play(Paths.sound('confirm','clown'));
|
||||
keyWarning.alpha = 1;
|
||||
warningTween.cancel();
|
||||
warningTween = FlxTween.tween(keyWarning, {alpha: 0}, 0.5, {ease: FlxEase.circOut, startDelay: 2});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function changeItem(_amount:Int = 0)
|
||||
{
|
||||
curSelected += _amount;
|
||||
|
||||
if (curSelected > 3)
|
||||
curSelected = 0;
|
||||
if (curSelected < 0)
|
||||
curSelected = 3;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user