mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2025-03-24 21:59:40 -04:00
camera bullshit for menus a lil cooler
This commit is contained in:
parent
6cd6f9b0f7
commit
08074f56a5
6 changed files with 117 additions and 79 deletions
|
@ -122,7 +122,7 @@
|
|||
|
||||
<!--In case you want to use the ui package-->
|
||||
<haxelib name="flixel-ui" />
|
||||
<haxelib name="newgrounds" unless="switch"/>
|
||||
<!--haxelib name="newgrounds" unless="switch"/> -->
|
||||
<haxelib name="faxe" if='switch'/>
|
||||
<haxelib name="polymod"/>
|
||||
<haxelib name="hxcpp-debug-server" if="desktop debug"/>
|
||||
|
|
|
@ -43,6 +43,18 @@ class CoolUtil
|
|||
return dumbArray;
|
||||
}
|
||||
|
||||
/**
|
||||
Lerps camera, but accountsfor framerate shit?
|
||||
Right now it's simply for use to change the followLerp variable of a camera during update
|
||||
TODO LATER MAYBE:
|
||||
Actually make and modify the scroll and lerp shit in it's own function
|
||||
instead of solely relying on changing the lerp on the fly
|
||||
*/
|
||||
public static function camLerpShit(lerp:Float):Float
|
||||
{
|
||||
return lerp * (FlxG.elapsed / (1 / 60));
|
||||
}
|
||||
|
||||
public static function fromAnimate(Source:FlxGraphicAsset, Description:String):FlxAtlasFrames
|
||||
{
|
||||
var graphic:FlxGraphic = FlxG.bitmap.add(Source);
|
||||
|
|
|
@ -237,6 +237,8 @@ class MainMenuState extends MusicBeatState
|
|||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
FlxG.camera.followLerp = CoolUtil.camLerpShit(0.06);
|
||||
|
||||
if (FlxG.sound.music.volume < 0.8)
|
||||
{
|
||||
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
|
||||
|
|
|
@ -1453,7 +1453,7 @@ class PlayState extends MusicBeatState
|
|||
override public function update(elapsed:Float)
|
||||
{
|
||||
// makes the lerp non-dependant on the framerate
|
||||
FlxG.camera.followLerp = 0.04 * (elapsed / (1 / 60));
|
||||
FlxG.camera.followLerp = CoolUtil.camLerpShit(0.04);
|
||||
|
||||
#if !debug
|
||||
perfectMode = false;
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package ui;
|
||||
|
||||
import flixel.input.actions.FlxActionInput;
|
||||
import flixel.input.gamepad.FlxGamepadInputID;
|
||||
import flixel.FlxG;
|
||||
import Controls;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.input.actions.FlxActionInput;
|
||||
import flixel.input.gamepad.FlxGamepadInputID;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
|
||||
import Controls;
|
||||
import ui.AtlasText;
|
||||
import ui.MenuList;
|
||||
import ui.TextMenuList;
|
||||
|
@ -23,40 +22,40 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
* if the player sets Back to Z it also set ACCEPT to X. This prevents the player from setting the controls in
|
||||
* a way the prevents them from changing more controls or exiting the menu.
|
||||
*/
|
||||
static var controlGroups:Array<Array<Control>> =
|
||||
[ [ NOTE_UP, NOTE_DOWN, NOTE_LEFT, NOTE_RIGHT ]
|
||||
, [ UI_UP, UI_DOWN, UI_LEFT, UI_RIGHT, ACCEPT, BACK ]
|
||||
];
|
||||
|
||||
static var controlGroups:Array<Array<Control>> = [
|
||||
[NOTE_UP, NOTE_DOWN, NOTE_LEFT, NOTE_RIGHT],
|
||||
[UI_UP, UI_DOWN, UI_LEFT, UI_RIGHT, ACCEPT, BACK]
|
||||
];
|
||||
|
||||
var itemGroups:Array<Array<InputItem>> = [for (i in 0...controlGroups.length) []];
|
||||
|
||||
|
||||
var controlGrid:MenuTypedList<InputItem>;
|
||||
var deviceList:TextMenuList;
|
||||
var menuCamera:FlxCamera;
|
||||
var prompt:Prompt;
|
||||
var camFollow:FlxObject;
|
||||
var labels:FlxTypedGroup<AtlasText>;
|
||||
|
||||
|
||||
var currentDevice:Device = Keys;
|
||||
var deviceListSelected = false;
|
||||
|
||||
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
|
||||
|
||||
menuCamera = new FlxCamera();
|
||||
FlxG.cameras.add(menuCamera, false);
|
||||
menuCamera.bgColor = 0x0;
|
||||
camera = menuCamera;
|
||||
|
||||
|
||||
labels = new FlxTypedGroup<AtlasText>();
|
||||
var headers = new FlxTypedGroup<AtlasText>();
|
||||
controlGrid = new MenuTypedList(Columns(COLUMNS), Vertical);
|
||||
|
||||
|
||||
add(labels);
|
||||
add(headers);
|
||||
add(controlGrid);
|
||||
|
||||
|
||||
if (FlxG.gamepads.numActiveGamepads > 0)
|
||||
{
|
||||
var devicesBg = new FlxSprite();
|
||||
|
@ -65,18 +64,18 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
deviceList = new TextMenuList(Horizontal, None);
|
||||
add(deviceList);
|
||||
deviceListSelected = true;
|
||||
|
||||
|
||||
var item;
|
||||
|
||||
|
||||
item = deviceList.createItem("Keyboard", Bold, selectDevice.bind(Keys));
|
||||
item.x = FlxG.width / 2 - item.width - 30;
|
||||
item.y = (devicesBg.height - item.height) / 2;
|
||||
|
||||
|
||||
item = deviceList.createItem("Gamepad", Bold, selectDevice.bind(Gamepad(FlxG.gamepads.firstActive.id)));
|
||||
item.x = FlxG.width / 2 + 30;
|
||||
item.y = (devicesBg.height - item.height) / 2;
|
||||
}
|
||||
|
||||
|
||||
// FlxG.debugger.drawDebug = true;
|
||||
var y = deviceList == null ? 30 : 120;
|
||||
var spacer = 70;
|
||||
|
@ -98,18 +97,18 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
headers.add(new BoldText(0, y, "NOTES")).screenCenter(X);
|
||||
y += spacer;
|
||||
}
|
||||
|
||||
|
||||
if (currentHeader != null && name.indexOf(currentHeader) == 0)
|
||||
name = name.substr(currentHeader.length);
|
||||
|
||||
|
||||
var label = labels.add(new BoldText(150, y, name));
|
||||
label.alpha = 0.6;
|
||||
for (i in 0...COLUMNS)
|
||||
createItem(label.x + 400 + i * 300, y, control, i);
|
||||
|
||||
|
||||
y += spacer;
|
||||
}
|
||||
|
||||
|
||||
camFollow = new FlxObject(FlxG.width / 2, 0, 70, 70);
|
||||
if (deviceList != null)
|
||||
{
|
||||
|
@ -119,19 +118,19 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
}
|
||||
else
|
||||
camFollow.y = controlGrid.selectedItem.y;
|
||||
|
||||
|
||||
menuCamera.follow(camFollow, null, 0.06);
|
||||
var margin = 100;
|
||||
menuCamera.deadzone.set(0, margin, menuCamera.width, menuCamera.height - margin * 2);
|
||||
menuCamera.minScrollY = 0;
|
||||
controlGrid.onChange.add(function (selected)
|
||||
controlGrid.onChange.add(function(selected)
|
||||
{
|
||||
camFollow.y = selected.y;
|
||||
|
||||
labels.forEach((label)->label.alpha = 0.6);
|
||||
|
||||
labels.forEach((label) -> label.alpha = 0.6);
|
||||
labels.members[Std.int(controlGrid.selectedIndex / COLUMNS)].alpha = 1.0;
|
||||
});
|
||||
|
||||
|
||||
prompt = new Prompt("\nPress any key to rebind\n\n\n\n Escape to cancel", None);
|
||||
prompt.create();
|
||||
prompt.createBgFromMargin(100, 0xFFfafd6d);
|
||||
|
@ -139,7 +138,7 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
prompt.exists = false;
|
||||
add(prompt);
|
||||
}
|
||||
|
||||
|
||||
function createItem(x = 0.0, y = 0.0, control:Control, index:Int)
|
||||
{
|
||||
var item = new InputItem(x, y, currentDevice, control, index, onSelect);
|
||||
|
@ -148,17 +147,17 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
if (controlGroups[i].contains(control))
|
||||
itemGroups[i].push(item);
|
||||
}
|
||||
|
||||
|
||||
return controlGrid.addItem(item.name, item);
|
||||
}
|
||||
|
||||
|
||||
function onSelect():Void
|
||||
{
|
||||
controlGrid.enabled = false;
|
||||
canExit = false;
|
||||
prompt.exists = true;
|
||||
}
|
||||
|
||||
|
||||
function goToDeviceList()
|
||||
{
|
||||
controlGrid.selectedItem.idle();
|
||||
|
@ -169,23 +168,22 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
camFollow.y = deviceList.selectedItem.y;
|
||||
deviceListSelected = true;
|
||||
}
|
||||
|
||||
|
||||
function selectDevice(device:Device)
|
||||
{
|
||||
currentDevice = device;
|
||||
|
||||
|
||||
for (item in controlGrid.members)
|
||||
item.updateDevice(currentDevice);
|
||||
|
||||
|
||||
var inputName = device == Keys ? "key" : "button";
|
||||
var cancel = device == Keys ? "Escape" : "Back";
|
||||
//todo: alignment
|
||||
// todo: alignment
|
||||
if (device == Keys)
|
||||
prompt.setText('\nPress any key to rebind\n\n\n\n $cancel to cancel');
|
||||
else
|
||||
prompt.setText('\nPress any button\n to rebind\n\n\n $cancel to cancel');
|
||||
|
||||
|
||||
|
||||
controlGrid.selectedItem.select();
|
||||
labels.members[Std.int(controlGrid.selectedIndex / COLUMNS)].alpha = 1.0;
|
||||
controlGrid.enabled = true;
|
||||
|
@ -193,48 +191,48 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
deviceListSelected = false;
|
||||
canExit = false;
|
||||
}
|
||||
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
super.update(elapsed);
|
||||
|
||||
|
||||
var controls = PlayerSettings.player1.controls;
|
||||
if (controlGrid.enabled && deviceList != null && deviceListSelected == false && controls.BACK)
|
||||
goToDeviceList();
|
||||
|
||||
|
||||
if (prompt.exists)
|
||||
{
|
||||
switch (currentDevice)
|
||||
{
|
||||
case Keys:
|
||||
{
|
||||
// check released otherwise bugs can happen when you change the BACK key
|
||||
var key = FlxG.keys.firstJustReleased();
|
||||
if (key != NONE)
|
||||
{
|
||||
if (key != ESCAPE)
|
||||
onInputSelect(key);
|
||||
closePrompt();
|
||||
// check released otherwise bugs can happen when you change the BACK key
|
||||
var key = FlxG.keys.firstJustReleased();
|
||||
if (key != NONE)
|
||||
{
|
||||
if (key != ESCAPE)
|
||||
onInputSelect(key);
|
||||
closePrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
case Gamepad(id):
|
||||
{
|
||||
var button = FlxG.gamepads.getByID(id).firstJustReleasedID();
|
||||
if (button != NONE)
|
||||
{
|
||||
if (button != BACK)
|
||||
onInputSelect(button);
|
||||
closePrompt();
|
||||
var button = FlxG.gamepads.getByID(id).firstJustReleasedID();
|
||||
if (button != NONE)
|
||||
{
|
||||
if (button != BACK)
|
||||
onInputSelect(button);
|
||||
closePrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onInputSelect(input:Int)
|
||||
{
|
||||
var item = controlGrid.selectedItem;
|
||||
|
||||
|
||||
// check if that key is already set for this
|
||||
var column0 = Math.floor(controlGrid.selectedIndex / 2) * 2;
|
||||
for (i in 0...COLUMNS)
|
||||
|
@ -242,7 +240,7 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
if (controlGrid.members[column0 + i].input == input)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check if items in the same group already have the new input
|
||||
for (group in itemGroups)
|
||||
{
|
||||
|
@ -261,15 +259,15 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PlayerSettings.player1.controls.replaceBinding(item.control, currentDevice, input, item.input);
|
||||
// Don't use resetItem() since items share names/labels
|
||||
item.input = input;
|
||||
item.label.text = item.getLabel(input);
|
||||
|
||||
|
||||
PlayerSettings.player1.saveControls();
|
||||
}
|
||||
|
||||
|
||||
function closePrompt()
|
||||
{
|
||||
prompt.exists = false;
|
||||
|
@ -277,17 +275,17 @@ class ControlsMenu extends ui.OptionsState.Page
|
|||
if (deviceList == null)
|
||||
canExit = true;
|
||||
}
|
||||
|
||||
|
||||
override function destroy()
|
||||
{
|
||||
super.destroy();
|
||||
|
||||
|
||||
itemGroups = null;
|
||||
|
||||
|
||||
if (FlxG.cameras.list.contains(menuCamera))
|
||||
FlxG.cameras.remove(menuCamera);
|
||||
}
|
||||
|
||||
|
||||
override function set_enabled(value:Bool)
|
||||
{
|
||||
if (value == false)
|
||||
|
@ -312,17 +310,17 @@ class InputItem extends TextMenuItem
|
|||
public var control:Control;
|
||||
public var input:Int = -1;
|
||||
public var index:Int = -1;
|
||||
|
||||
public function new (x = 0.0, y = 0.0, device, control, index, ?callback)
|
||||
|
||||
public function new(x = 0.0, y = 0.0, device, control, index, ?callback)
|
||||
{
|
||||
this.device = device;
|
||||
this.control = control;
|
||||
this.index = index;
|
||||
this.input = getInput();
|
||||
|
||||
|
||||
super(x, y, getLabel(input), Default, callback);
|
||||
}
|
||||
|
||||
|
||||
public function updateDevice(device:Device)
|
||||
{
|
||||
if (this.device != device)
|
||||
|
@ -332,7 +330,7 @@ class InputItem extends TextMenuItem
|
|||
label.text = getLabel(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getInput()
|
||||
{
|
||||
var list = PlayerSettings.player1.controls.getInputsFor(control, device);
|
||||
|
@ -340,17 +338,17 @@ class InputItem extends TextMenuItem
|
|||
{
|
||||
if (list[index] != FlxKey.ESCAPE || list[index] != FlxGamepadInputID.BACK)
|
||||
return list[index];
|
||||
|
||||
|
||||
if (list.length > ControlsMenu.COLUMNS)
|
||||
// Escape isn't mappable, show a third option, instead.
|
||||
return list[ControlsMenu.COLUMNS];
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public function getLabel(input:Int)
|
||||
{
|
||||
return input == -1 ? "---" : InputFormatter.format(input, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ui;
|
||||
|
||||
import flixel.FlxCamera;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.util.FlxColor;
|
||||
|
@ -14,10 +16,18 @@ class PreferencesMenu extends ui.OptionsState.Page
|
|||
var items:TextMenuList;
|
||||
|
||||
var checkboxes:Array<CheckboxThingie> = [];
|
||||
var menuCamera:FlxCamera;
|
||||
var camFollow:FlxObject;
|
||||
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
|
||||
menuCamera = new FlxCamera();
|
||||
FlxG.cameras.add(menuCamera, false);
|
||||
menuCamera.bgColor = 0x0;
|
||||
camera = menuCamera;
|
||||
|
||||
add(items = new TextMenuList());
|
||||
|
||||
createPrefItem('naughtyness', 'censor-naughty', false);
|
||||
|
@ -25,6 +35,20 @@ class PreferencesMenu extends ui.OptionsState.Page
|
|||
createPrefItem('flashing menu', 'flashing-menu', true);
|
||||
createPrefItem('Camera Zooming on Beat', 'camera-zoom', true);
|
||||
createPrefItem('FPS Counter', 'fps-counter', true);
|
||||
|
||||
camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70);
|
||||
if (items != null)
|
||||
camFollow.y = items.selectedItem.y;
|
||||
|
||||
menuCamera.follow(camFollow, null, 0.06);
|
||||
var margin = 160;
|
||||
menuCamera.deadzone.set(0, margin, menuCamera.width, 40);
|
||||
menuCamera.minScrollY = 0;
|
||||
|
||||
items.onChange.add(function(selected)
|
||||
{
|
||||
camFollow.y = selected.y;
|
||||
});
|
||||
}
|
||||
|
||||
public static function getPref(pref:String):Dynamic
|
||||
|
@ -103,6 +127,8 @@ class PreferencesMenu extends ui.OptionsState.Page
|
|||
{
|
||||
super.update(elapsed);
|
||||
|
||||
menuCamera.followLerp = CoolUtil.camLerpShit(0.05);
|
||||
|
||||
items.forEach(function(daItem:TextMenuItem)
|
||||
{
|
||||
if (items.selectedItem == daItem)
|
||||
|
|
Loading…
Add table
Reference in a new issue