1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-05-22 07:01:27 +00:00

camera bullshit for menus a lil cooler

This commit is contained in:
Cameron Taylor 2021-04-04 10:17:46 -07:00
parent 6cd6f9b0f7
commit 08074f56a5
6 changed files with 117 additions and 79 deletions

View file

@ -122,7 +122,7 @@
<!--In case you want to use the ui package--> <!--In case you want to use the ui package-->
<haxelib name="flixel-ui" /> <haxelib name="flixel-ui" />
<haxelib name="newgrounds" unless="switch"/> <!--haxelib name="newgrounds" unless="switch"/> -->
<haxelib name="faxe" if='switch'/> <haxelib name="faxe" if='switch'/>
<haxelib name="polymod"/> <haxelib name="polymod"/>
<haxelib name="hxcpp-debug-server" if="desktop debug"/> <haxelib name="hxcpp-debug-server" if="desktop debug"/>

View file

@ -43,6 +43,18 @@ class CoolUtil
return dumbArray; 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 public static function fromAnimate(Source:FlxGraphicAsset, Description:String):FlxAtlasFrames
{ {
var graphic:FlxGraphic = FlxG.bitmap.add(Source); var graphic:FlxGraphic = FlxG.bitmap.add(Source);

View file

@ -237,6 +237,8 @@ class MainMenuState extends MusicBeatState
override function update(elapsed:Float) override function update(elapsed:Float)
{ {
FlxG.camera.followLerp = CoolUtil.camLerpShit(0.06);
if (FlxG.sound.music.volume < 0.8) if (FlxG.sound.music.volume < 0.8)
{ {
FlxG.sound.music.volume += 0.5 * FlxG.elapsed; FlxG.sound.music.volume += 0.5 * FlxG.elapsed;

View file

@ -1453,7 +1453,7 @@ class PlayState extends MusicBeatState
override public function update(elapsed:Float) override public function update(elapsed:Float)
{ {
// makes the lerp non-dependant on the framerate // 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 #if !debug
perfectMode = false; perfectMode = false;

View file

@ -1,15 +1,14 @@
package ui; package ui;
import flixel.input.actions.FlxActionInput; import Controls;
import flixel.input.gamepad.FlxGamepadInputID;
import flixel.FlxG;
import flixel.FlxCamera; import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxObject; import flixel.FlxObject;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.group.FlxGroup; import flixel.group.FlxGroup;
import flixel.input.actions.FlxActionInput;
import flixel.input.gamepad.FlxGamepadInputID;
import flixel.input.keyboard.FlxKey; import flixel.input.keyboard.FlxKey;
import Controls;
import ui.AtlasText; import ui.AtlasText;
import ui.MenuList; import ui.MenuList;
import ui.TextMenuList; 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 * 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. * a way the prevents them from changing more controls or exiting the menu.
*/ */
static var controlGroups:Array<Array<Control>> = static var controlGroups:Array<Array<Control>> = [
[ [ NOTE_UP, NOTE_DOWN, NOTE_LEFT, NOTE_RIGHT ] [NOTE_UP, NOTE_DOWN, NOTE_LEFT, NOTE_RIGHT],
, [ UI_UP, UI_DOWN, UI_LEFT, UI_RIGHT, ACCEPT, BACK ] [UI_UP, UI_DOWN, UI_LEFT, UI_RIGHT, ACCEPT, BACK]
]; ];
var itemGroups:Array<Array<InputItem>> = [for (i in 0...controlGroups.length) []]; var itemGroups:Array<Array<InputItem>> = [for (i in 0...controlGroups.length) []];
var controlGrid:MenuTypedList<InputItem>; var controlGrid:MenuTypedList<InputItem>;
var deviceList:TextMenuList; var deviceList:TextMenuList;
var menuCamera:FlxCamera; var menuCamera:FlxCamera;
var prompt:Prompt; var prompt:Prompt;
var camFollow:FlxObject; var camFollow:FlxObject;
var labels:FlxTypedGroup<AtlasText>; var labels:FlxTypedGroup<AtlasText>;
var currentDevice:Device = Keys; var currentDevice:Device = Keys;
var deviceListSelected = false; var deviceListSelected = false;
public function new() public function new()
{ {
super(); super();
menuCamera = new FlxCamera(); menuCamera = new FlxCamera();
FlxG.cameras.add(menuCamera, false); FlxG.cameras.add(menuCamera, false);
menuCamera.bgColor = 0x0; menuCamera.bgColor = 0x0;
camera = menuCamera; camera = menuCamera;
labels = new FlxTypedGroup<AtlasText>(); labels = new FlxTypedGroup<AtlasText>();
var headers = new FlxTypedGroup<AtlasText>(); var headers = new FlxTypedGroup<AtlasText>();
controlGrid = new MenuTypedList(Columns(COLUMNS), Vertical); controlGrid = new MenuTypedList(Columns(COLUMNS), Vertical);
add(labels); add(labels);
add(headers); add(headers);
add(controlGrid); add(controlGrid);
if (FlxG.gamepads.numActiveGamepads > 0) if (FlxG.gamepads.numActiveGamepads > 0)
{ {
var devicesBg = new FlxSprite(); var devicesBg = new FlxSprite();
@ -65,18 +64,18 @@ class ControlsMenu extends ui.OptionsState.Page
deviceList = new TextMenuList(Horizontal, None); deviceList = new TextMenuList(Horizontal, None);
add(deviceList); add(deviceList);
deviceListSelected = true; deviceListSelected = true;
var item; var item;
item = deviceList.createItem("Keyboard", Bold, selectDevice.bind(Keys)); item = deviceList.createItem("Keyboard", Bold, selectDevice.bind(Keys));
item.x = FlxG.width / 2 - item.width - 30; item.x = FlxG.width / 2 - item.width - 30;
item.y = (devicesBg.height - item.height) / 2; item.y = (devicesBg.height - item.height) / 2;
item = deviceList.createItem("Gamepad", Bold, selectDevice.bind(Gamepad(FlxG.gamepads.firstActive.id))); item = deviceList.createItem("Gamepad", Bold, selectDevice.bind(Gamepad(FlxG.gamepads.firstActive.id)));
item.x = FlxG.width / 2 + 30; item.x = FlxG.width / 2 + 30;
item.y = (devicesBg.height - item.height) / 2; item.y = (devicesBg.height - item.height) / 2;
} }
// FlxG.debugger.drawDebug = true; // FlxG.debugger.drawDebug = true;
var y = deviceList == null ? 30 : 120; var y = deviceList == null ? 30 : 120;
var spacer = 70; var spacer = 70;
@ -98,18 +97,18 @@ class ControlsMenu extends ui.OptionsState.Page
headers.add(new BoldText(0, y, "NOTES")).screenCenter(X); headers.add(new BoldText(0, y, "NOTES")).screenCenter(X);
y += spacer; y += spacer;
} }
if (currentHeader != null && name.indexOf(currentHeader) == 0) if (currentHeader != null && name.indexOf(currentHeader) == 0)
name = name.substr(currentHeader.length); name = name.substr(currentHeader.length);
var label = labels.add(new BoldText(150, y, name)); var label = labels.add(new BoldText(150, y, name));
label.alpha = 0.6; label.alpha = 0.6;
for (i in 0...COLUMNS) for (i in 0...COLUMNS)
createItem(label.x + 400 + i * 300, y, control, i); createItem(label.x + 400 + i * 300, y, control, i);
y += spacer; y += spacer;
} }
camFollow = new FlxObject(FlxG.width / 2, 0, 70, 70); camFollow = new FlxObject(FlxG.width / 2, 0, 70, 70);
if (deviceList != null) if (deviceList != null)
{ {
@ -119,19 +118,19 @@ class ControlsMenu extends ui.OptionsState.Page
} }
else else
camFollow.y = controlGrid.selectedItem.y; camFollow.y = controlGrid.selectedItem.y;
menuCamera.follow(camFollow, null, 0.06); menuCamera.follow(camFollow, null, 0.06);
var margin = 100; var margin = 100;
menuCamera.deadzone.set(0, margin, menuCamera.width, menuCamera.height - margin * 2); menuCamera.deadzone.set(0, margin, menuCamera.width, menuCamera.height - margin * 2);
menuCamera.minScrollY = 0; menuCamera.minScrollY = 0;
controlGrid.onChange.add(function (selected) controlGrid.onChange.add(function(selected)
{ {
camFollow.y = selected.y; 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; 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 = new Prompt("\nPress any key to rebind\n\n\n\n Escape to cancel", None);
prompt.create(); prompt.create();
prompt.createBgFromMargin(100, 0xFFfafd6d); prompt.createBgFromMargin(100, 0xFFfafd6d);
@ -139,7 +138,7 @@ class ControlsMenu extends ui.OptionsState.Page
prompt.exists = false; prompt.exists = false;
add(prompt); add(prompt);
} }
function createItem(x = 0.0, y = 0.0, control:Control, index:Int) function createItem(x = 0.0, y = 0.0, control:Control, index:Int)
{ {
var item = new InputItem(x, y, currentDevice, control, index, onSelect); 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)) if (controlGroups[i].contains(control))
itemGroups[i].push(item); itemGroups[i].push(item);
} }
return controlGrid.addItem(item.name, item); return controlGrid.addItem(item.name, item);
} }
function onSelect():Void function onSelect():Void
{ {
controlGrid.enabled = false; controlGrid.enabled = false;
canExit = false; canExit = false;
prompt.exists = true; prompt.exists = true;
} }
function goToDeviceList() function goToDeviceList()
{ {
controlGrid.selectedItem.idle(); controlGrid.selectedItem.idle();
@ -169,23 +168,22 @@ class ControlsMenu extends ui.OptionsState.Page
camFollow.y = deviceList.selectedItem.y; camFollow.y = deviceList.selectedItem.y;
deviceListSelected = true; deviceListSelected = true;
} }
function selectDevice(device:Device) function selectDevice(device:Device)
{ {
currentDevice = device; currentDevice = device;
for (item in controlGrid.members) for (item in controlGrid.members)
item.updateDevice(currentDevice); item.updateDevice(currentDevice);
var inputName = device == Keys ? "key" : "button"; var inputName = device == Keys ? "key" : "button";
var cancel = device == Keys ? "Escape" : "Back"; var cancel = device == Keys ? "Escape" : "Back";
//todo: alignment // todo: alignment
if (device == Keys) if (device == Keys)
prompt.setText('\nPress any key to rebind\n\n\n\n $cancel to cancel'); prompt.setText('\nPress any key to rebind\n\n\n\n $cancel to cancel');
else else
prompt.setText('\nPress any button\n to rebind\n\n\n $cancel to cancel'); prompt.setText('\nPress any button\n to rebind\n\n\n $cancel to cancel');
controlGrid.selectedItem.select(); controlGrid.selectedItem.select();
labels.members[Std.int(controlGrid.selectedIndex / COLUMNS)].alpha = 1.0; labels.members[Std.int(controlGrid.selectedIndex / COLUMNS)].alpha = 1.0;
controlGrid.enabled = true; controlGrid.enabled = true;
@ -193,48 +191,48 @@ class ControlsMenu extends ui.OptionsState.Page
deviceListSelected = false; deviceListSelected = false;
canExit = false; canExit = false;
} }
override function update(elapsed:Float) override function update(elapsed:Float)
{ {
super.update(elapsed); super.update(elapsed);
var controls = PlayerSettings.player1.controls; var controls = PlayerSettings.player1.controls;
if (controlGrid.enabled && deviceList != null && deviceListSelected == false && controls.BACK) if (controlGrid.enabled && deviceList != null && deviceListSelected == false && controls.BACK)
goToDeviceList(); goToDeviceList();
if (prompt.exists) if (prompt.exists)
{ {
switch (currentDevice) switch (currentDevice)
{ {
case Keys: 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) // check released otherwise bugs can happen when you change the BACK key
onInputSelect(key); var key = FlxG.keys.firstJustReleased();
closePrompt(); if (key != NONE)
{
if (key != ESCAPE)
onInputSelect(key);
closePrompt();
}
} }
}
case Gamepad(id): case Gamepad(id):
{
var button = FlxG.gamepads.getByID(id).firstJustReleasedID();
if (button != NONE)
{ {
if (button != BACK) var button = FlxG.gamepads.getByID(id).firstJustReleasedID();
onInputSelect(button); if (button != NONE)
closePrompt(); {
if (button != BACK)
onInputSelect(button);
closePrompt();
}
} }
}
} }
} }
} }
function onInputSelect(input:Int) function onInputSelect(input:Int)
{ {
var item = controlGrid.selectedItem; var item = controlGrid.selectedItem;
// check if that key is already set for this // check if that key is already set for this
var column0 = Math.floor(controlGrid.selectedIndex / 2) * 2; var column0 = Math.floor(controlGrid.selectedIndex / 2) * 2;
for (i in 0...COLUMNS) for (i in 0...COLUMNS)
@ -242,7 +240,7 @@ class ControlsMenu extends ui.OptionsState.Page
if (controlGrid.members[column0 + i].input == input) if (controlGrid.members[column0 + i].input == input)
return; return;
} }
// Check if items in the same group already have the new input // Check if items in the same group already have the new input
for (group in itemGroups) for (group in itemGroups)
{ {
@ -261,15 +259,15 @@ class ControlsMenu extends ui.OptionsState.Page
} }
} }
} }
PlayerSettings.player1.controls.replaceBinding(item.control, currentDevice, input, item.input); PlayerSettings.player1.controls.replaceBinding(item.control, currentDevice, input, item.input);
// Don't use resetItem() since items share names/labels // Don't use resetItem() since items share names/labels
item.input = input; item.input = input;
item.label.text = item.getLabel(input); item.label.text = item.getLabel(input);
PlayerSettings.player1.saveControls(); PlayerSettings.player1.saveControls();
} }
function closePrompt() function closePrompt()
{ {
prompt.exists = false; prompt.exists = false;
@ -277,17 +275,17 @@ class ControlsMenu extends ui.OptionsState.Page
if (deviceList == null) if (deviceList == null)
canExit = true; canExit = true;
} }
override function destroy() override function destroy()
{ {
super.destroy(); super.destroy();
itemGroups = null; itemGroups = null;
if (FlxG.cameras.list.contains(menuCamera)) if (FlxG.cameras.list.contains(menuCamera))
FlxG.cameras.remove(menuCamera); FlxG.cameras.remove(menuCamera);
} }
override function set_enabled(value:Bool) override function set_enabled(value:Bool)
{ {
if (value == false) if (value == false)
@ -312,17 +310,17 @@ class InputItem extends TextMenuItem
public var control:Control; public var control:Control;
public var input:Int = -1; public var input:Int = -1;
public var index: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.device = device;
this.control = control; this.control = control;
this.index = index; this.index = index;
this.input = getInput(); this.input = getInput();
super(x, y, getLabel(input), Default, callback); super(x, y, getLabel(input), Default, callback);
} }
public function updateDevice(device:Device) public function updateDevice(device:Device)
{ {
if (this.device != device) if (this.device != device)
@ -332,7 +330,7 @@ class InputItem extends TextMenuItem
label.text = getLabel(input); label.text = getLabel(input);
} }
} }
function getInput() function getInput()
{ {
var list = PlayerSettings.player1.controls.getInputsFor(control, device); 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) if (list[index] != FlxKey.ESCAPE || list[index] != FlxGamepadInputID.BACK)
return list[index]; return list[index];
if (list.length > ControlsMenu.COLUMNS) if (list.length > ControlsMenu.COLUMNS)
// Escape isn't mappable, show a third option, instead. // Escape isn't mappable, show a third option, instead.
return list[ControlsMenu.COLUMNS]; return list[ControlsMenu.COLUMNS];
} }
return -1; return -1;
} }
public function getLabel(input:Int) public function getLabel(input:Int)
{ {
return input == -1 ? "---" : InputFormatter.format(input, device); return input == -1 ? "---" : InputFormatter.format(input, device);
} }
} }

View file

@ -1,6 +1,8 @@
package ui; package ui;
import flixel.FlxCamera;
import flixel.FlxG; import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.group.FlxGroup; import flixel.group.FlxGroup;
import flixel.util.FlxColor; import flixel.util.FlxColor;
@ -14,10 +16,18 @@ class PreferencesMenu extends ui.OptionsState.Page
var items:TextMenuList; var items:TextMenuList;
var checkboxes:Array<CheckboxThingie> = []; var checkboxes:Array<CheckboxThingie> = [];
var menuCamera:FlxCamera;
var camFollow:FlxObject;
public function new() public function new()
{ {
super(); super();
menuCamera = new FlxCamera();
FlxG.cameras.add(menuCamera, false);
menuCamera.bgColor = 0x0;
camera = menuCamera;
add(items = new TextMenuList()); add(items = new TextMenuList());
createPrefItem('naughtyness', 'censor-naughty', false); createPrefItem('naughtyness', 'censor-naughty', false);
@ -25,6 +35,20 @@ class PreferencesMenu extends ui.OptionsState.Page
createPrefItem('flashing menu', 'flashing-menu', true); createPrefItem('flashing menu', 'flashing-menu', true);
createPrefItem('Camera Zooming on Beat', 'camera-zoom', true); createPrefItem('Camera Zooming on Beat', 'camera-zoom', true);
createPrefItem('FPS Counter', 'fps-counter', 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 public static function getPref(pref:String):Dynamic
@ -103,6 +127,8 @@ class PreferencesMenu extends ui.OptionsState.Page
{ {
super.update(elapsed); super.update(elapsed);
menuCamera.followLerp = CoolUtil.camLerpShit(0.05);
items.forEach(function(daItem:TextMenuItem) items.forEach(function(daItem:TextMenuItem)
{ {
if (items.selectedItem == daItem) if (items.selectedItem == daItem)