From 381651aa2fa160d3531f4c9145e7d20dcc3913c6 Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Fri, 24 Mar 2023 13:54:15 +0100 Subject: [PATCH] Implemented Framerate Offset + Fixed keybinds on mac --- source/funkin/editors/charter/Charter.hx | 434 +++++++++--------- .../funkin/editors/charter/CharterBackdrop.hx | 74 +-- .../editors/charter/CharterSelection.hx | 79 ++-- source/funkin/editors/ui/UIState.hx | 136 +++--- source/funkin/editors/ui/UIUtil.hx | 20 +- source/funkin/system/MusicBeatState.hx | 4 +- source/funkin/system/framerate/Framerate.hx | 161 +++---- 7 files changed, 460 insertions(+), 448 deletions(-) diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 3e625660..0dd271cc 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -15,30 +15,30 @@ import funkin.editors.ui.UIState; import openfl.net.FileReference; class Charter extends UIState { - var __song:String; - var __diff:String; + var __song:String; + var __diff:String; - var chart(get, null):ChartData; - private function get_chart() - return PlayState.SONG; + var chart(get, null):ChartData; + private function get_chart() + return PlayState.SONG; public static var instance(get, null):Charter; private static inline function get_instance() return FlxG.state is Charter ? cast FlxG.state : null; - /** - * CONFIG & UI (might make this customizable later) - */ - public var uiGroup:FlxTypedGroup = new FlxTypedGroup(); - private var gridColor1:FlxColor = 0xFF272727; // white - private var gridColor2:FlxColor = 0xFF545454; // gray + /** + * CONFIG & UI (might make this customizable later) + */ + public var uiGroup:FlxTypedGroup = new FlxTypedGroup(); + private var gridColor1:FlxColor = 0xFF272727; // white + private var gridColor2:FlxColor = 0xFF545454; // gray - public var topMenu:Array; + public var topMenu:Array; - public var topMenuSpr:UITopMenu; - public var gridBackdrop:CharterBackdrop; - public var gridBackdropDummy:CharterBackdropDummy; + public var topMenuSpr:UITopMenu; + public var gridBackdrop:CharterBackdrop; + public var gridBackdropDummy:CharterBackdropDummy; public var conductorFollowerSpr:FlxSprite; public var hitsound:FlxSound; @@ -46,190 +46,190 @@ class Charter extends UIState { public var vocals:FlxSound; - /** - * ACTUAL CHART DATA - */ - public var strumLines:Array = []; - public var notesGroup:CharterNoteGroup = new CharterNoteGroup(); + /** + * ACTUAL CHART DATA + */ + public var strumLines:Array = []; + public var notesGroup:CharterNoteGroup = new CharterNoteGroup(); - /** - * CAMERAS - */ - // camera for the chart itself so that it can be unzoomed/zoomed in again - public var charterCamera:FlxCamera; - // camera for the ui - public var uiCamera:FlxCamera; + /** + * CAMERAS + */ + // camera for the chart itself so that it can be unzoomed/zoomed in again + public var charterCamera:FlxCamera; + // camera for the ui + public var uiCamera:FlxCamera; // selection box for the ui public var selectionBox:UISliceSprite; - public var selection:Array = []; + public var selection:Array = []; public var undoList:Array = []; public var redoList:Array = []; - public function new(song:String, diff:String) { - super(); - __song = song; - __diff = diff; - } + public function new(song:String, diff:String) { + super(); + __song = song; + __diff = diff; + } - public override function create() { - super.create(); + public override function create() { + super.create(); - topMenu = [ - { - label: "File", - childs: [ - { - label: "New" - }, - null, - { - label: "Exit", - onSelect: _file_exit - } - ] - }, - { - label: "Edit", - childs: [ - { - label: "Undo", + topMenu = [ + { + label: "File", + childs: [ + { + label: "New" + }, + null, + { + label: "Exit", + onSelect: _file_exit + } + ] + }, + { + label: "Edit", + childs: [ + { + label: "Undo", keybind: [CONTROL, Z], onSelect: _edit_undo - }, - { - label: "Redo", + }, + { + label: "Redo", keybind: [CONTROL, Y], onSelect: _edit_redo - }, - null, - { - label: "Cut", + }, + null, + { + label: "Cut", keybind: [CONTROL, X] - }, - { - label: "Copy", + }, + { + label: "Copy", keybind: [CONTROL, C] - }, - { - label: "Paste", + }, + { + label: "Paste", keybind: [CONTROL, V] - }, - null, - { - label: "Delete", + }, + null, + { + label: "Delete", keybind: [DELETE], - onSelect: _edit_delete - } - ] - }, - { - label: "Chart", - childs: [ - { - label: "Playtest", + onSelect: _edit_delete + } + ] + }, + { + label: "Chart", + childs: [ + { + label: "Playtest", keybind: [ENTER] - }, - { - label: "Playtest here", + }, + { + label: "Playtest here", keybind: [SHIFT, ENTER] - }, - null, - { - label: "Playtest as opponent", + }, + null, + { + label: "Playtest as opponent", keybind: [CONTROL, ENTER] - }, - { - label: "Playtest as opponent here", + }, + { + label: "Playtest as opponent here", keybind: [CONTROL, SHIFT, ENTER] - }, - null, - { - label: "Zoom in", + }, + null, + { + label: "Zoom in", keybind: [CONTROL, NUMPADPLUS], onSelect: _chart_zoomin - }, - { - label: "Zoom out", + }, + { + label: "Zoom out", keybind: [CONTROL, NUMPADMINUS], onSelect: _chart_zoomout - }, - { - label: "Reset zoom", + }, + { + label: "Reset zoom", keybind: [CONTROL, NUMPADZERO], onSelect: _chart_zoomreset - }, - null, - { - label: "Edit metadata information" - } - ] - }, - { - label: "Playback", - childs: [ - { - label: "Play/Pause", + }, + null, + { + label: "Edit metadata information" + } + ] + }, + { + label: "Playback", + childs: [ + { + label: "Play/Pause", keybind: [SPACE], onSelect: _playback_play - }, - null, - { - label: "Go back a section", + }, + null, + { + label: "Go back a section", keybind: [A], onSelect: _playback_back - }, - { - label: "Go forward a section", + }, + { + label: "Go forward a section", keybind: [D], onSelect: _playback_forward - }, - null, - { - label: "Go back to the start", + }, + null, + { + label: "Go back to the start", keybind: [HOME], onSelect: _playback_start - }, - { - label: "Go to the end", + }, + { + label: "Go to the end", keybind: [END], onSelect: _playback_end - }, - null, - { - label: "Metronome", + }, + null, + { + label: "Metronome", onSelect: _playback_metronome - }, - { - label: "Visual metronome" - }, - null, - { - label: "Mute instrumental", + }, + { + label: "Visual metronome" + }, + null, + { + label: "Mute instrumental", onSelect: _playback_muteinst - }, - { - label: "Mute voices", + }, + { + label: "Mute voices", onSelect: _playback_mutevoices - } - ] - } - ]; + } + ] + } + ]; hitsound = FlxG.sound.load(Paths.sound('editors/charter/hitsound')); metronome = FlxG.sound.load(Paths.sound('editors/charter/metronome')); - charterCamera = FlxG.camera; - uiCamera = new FlxCamera(); - uiCamera.bgColor = 0; - FlxG.cameras.add(uiCamera); + charterCamera = FlxG.camera; + uiCamera = new FlxCamera(); + uiCamera.bgColor = 0; + FlxG.cameras.add(uiCamera); - - gridBackdrop = new CharterBackdrop(); + + gridBackdrop = new CharterBackdrop(); - add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrop)); + add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrop)); selectionBox = new UISliceSprite(0, 0, 2, 2, 'editors/ui/selection'); selectionBox.visible = false; @@ -243,44 +243,44 @@ class Charter extends UIState { conductorFollowerSpr.cameras = selectionBox.cameras = notesGroup.cameras = gridBackdrop.cameras = [charterCamera]; - topMenuSpr = new UITopMenu(topMenu); - topMenuSpr.cameras = uiGroup.cameras = [uiCamera]; + topMenuSpr = new UITopMenu(topMenu); + topMenuSpr.cameras = uiGroup.cameras = [uiCamera]; - // adds grid and notes so that they're ALWAYS behind the UI - add(gridBackdrop); - add(notesGroup); + // adds grid and notes so that they're ALWAYS behind the UI + add(gridBackdrop); + add(notesGroup); add(conductorFollowerSpr); add(selectionBox); - // add the ui group - add(uiGroup); - // add the top menu last OUT of the ui group so that it stays on top - add(topMenuSpr); - - loadSong(); - } + // add the ui group + add(uiGroup); + // add the top menu last OUT of the ui group so that it stays on top + add(topMenuSpr); + + loadSong(); + } - public function loadSong() { - CoolUtil.loadSong(__song, __diff, false, false); + public function loadSong() { + CoolUtil.loadSong(__song, __diff, false, false); - Conductor.setupSong(PlayState.SONG); + Conductor.setupSong(PlayState.SONG); FlxG.sound.music = FlxG.sound.load(Paths.inst(__song, __diff)); vocals = FlxG.sound.load(Paths.voices(__song, __diff)); - - for(strID=>strL in PlayState.SONG.strumLines) { - for(note in strL.notes) { - var n = new CharterNote(); - n.updatePos(Conductor.getStepForTime(note.time), (strID * 4) + note.id, note.sLen, note.type); - notesGroup.add(n); - } + + for(strID=>strL in PlayState.SONG.strumLines) { + for(note in strL.notes) { + var n = new CharterNote(); + n.updatePos(Conductor.getStepForTime(note.time), (strID * 4) + note.id, note.sLen, note.type); + notesGroup.add(n); + } strumLines.push({ strumLine: strL, hitsounds: true }); - } - } + } + } public override function beatHit(curBeat:Int) { super.beatHit(curBeat); @@ -299,27 +299,27 @@ class Charter extends UIState { public function updateNoteLogic(elapsed:Float) { notesGroup.forEach(function(n) { - n.selected = false; - if (n.hovered && !selectionBoxEnabled) { - if (FlxG.mouse.justReleased) { - if (FlxG.keys.pressed.CONTROL) - selection.push(n); - else if (FlxG.keys.pressed.SHIFT) - selection.remove(n); - else - selection = [n]; - } - if (FlxG.mouse.justReleasedRight) { - if (!selection.contains(n)) - selection = [n]; - openContextMenu(topMenu[1].childs); - } - } - }); - for(n in selection) - n.selected = true; + n.selected = false; + if (n.hovered && !selectionBoxEnabled) { + if (FlxG.mouse.justReleased) { + if (FlxG.keys.pressed.CONTROL) + selection.push(n); + else if (FlxG.keys.pressed.SHIFT) + selection.remove(n); + else + selection = [n]; + } + if (FlxG.mouse.justReleasedRight) { + if (!selection.contains(n)) + selection = [n]; + openContextMenu(topMenu[1].childs); + } + } + }); + for(n in selection) + n.selected = true; - if (gridBackdropDummy.hovered || (selectionBoxEnabled && gridBackdropDummy.hoveredByChild)) { + if (gridBackdropDummy.hovered || (selectionBoxEnabled && gridBackdropDummy.hoveredByChild)) { var mousePos = FlxG.mouse.getWorldPosition(charterCamera); if (FlxG.mouse.justPressed) { selectionBoxEnabled = false; @@ -381,14 +381,14 @@ class Charter extends UIState { selectionBox.visible = selectionBoxEnabled; } - public function deleteNote(note:CharterNote):CharterNote { + public function deleteNote(note:CharterNote):CharterNote { if (note == null) return note; - notesGroup.remove(note, true); - note.kill(); + notesGroup.remove(note, true); + note.kill(); addToUndo(CDeleteNotes([note])); - return null; - } + return null; + } public function deleteNotes(notes:Array) { if (notes.length <= 0) return []; @@ -490,19 +490,19 @@ class Charter extends UIState { #end var __crochet:Float; - public override function update(elapsed:Float) { - // TODO: do optimization like NoteGroup + public override function update(elapsed:Float) { + // TODO: do optimization like NoteGroup updateNoteLogic(elapsed); - super.update(elapsed); + super.update(elapsed); - if (gridBackdrop.strumlinesAmount != (gridBackdrop.strumlinesAmount = strumLines.length)) { + if (gridBackdrop.strumlinesAmount != (gridBackdrop.strumlinesAmount = strumLines.length)) { conductorFollowerSpr.scale.set(gridBackdrop.strumlinesAmount * 4 * 40, 4); conductorFollowerSpr.updateHitbox(); } - // TODO: canTypeText in case an ui input element is focused - if (true) { + // TODO: canTypeText in case an ui input element is focused + if (true) { __crochet = ((60 / Conductor.bpm) * 1000); UIUtil.processShortcuts(topMenu); @@ -517,7 +517,7 @@ class Charter extends UIState { Conductor.songPosition -= __crochet * FlxG.mouse.wheel; } } - } + } Conductor.songPosition = FlxMath.bound(Conductor.songPosition, 0, FlxG.sound.music.length); @@ -530,20 +530,20 @@ class Charter extends UIState { if (charterCamera.zoom != (charterCamera.zoom = lerp(charterCamera.zoom, __camZoom, 0.125))) { } - } + } var zoom:Float = 0; var __camZoom:Float = 1; - // TOP MENU OPTIONS - #if REGION - function _file_exit(_) { - FlxG.switchState(new CharterSelection()); - } - function _edit_delete(_) { - if (selection == null) return; + // TOP MENU OPTIONS + #if REGION + function _file_exit(_) { + FlxG.switchState(new CharterSelection()); + } + function _edit_delete(_) { + if (selection == null) return; selection = deleteNotes(selection); - } + } function _playback_back(_) { if (FlxG.sound.music.playing) return; Conductor.songPosition -= Conductor.beatsPerMesure * __crochet; @@ -572,7 +572,7 @@ class Charter extends UIState { zoom = 0; __camZoom = Math.pow(2, zoom); } - #end + #end public inline function hitsoundsEnabled(id:Int) return strumLines[Std.int(id / 4)] != null && strumLines[Std.int(id / 4)].hitsounds; diff --git a/source/funkin/editors/charter/CharterBackdrop.hx b/source/funkin/editors/charter/CharterBackdrop.hx index c9f38ed5..25e0d4b5 100644 --- a/source/funkin/editors/charter/CharterBackdrop.hx +++ b/source/funkin/editors/charter/CharterBackdrop.hx @@ -4,48 +4,48 @@ import openfl.geom.Rectangle; import flixel.addons.display.FlxBackdrop; class CharterBackdrop extends FlxBackdrop { - public var strumlinesAmount:Int = 1; - - public function new() { - super(null, Y, 0, 0); + public var strumlinesAmount:Int = 1; - makeGraphic(160, 160, 0xFF272727, true); - pixels.lock(); - for(y in 0...4) - for(x in 0...2) - pixels.fillRect(new Rectangle(40*((x*2)+(y%2)), 40*y, 40, 40), 0xFF545454); - pixels.fillRect(new Rectangle(0, 0, 1, 160), 0xFFDDDDDD); - pixels.fillRect(new Rectangle(159, 0, 1, 160), 0xFFDDDDDD); - pixels.unlock(); - // loadFrame(frame); - } + public function new() { + super(null, Y, 0, 0); - public override function draw() { - var ogX:Float = x; - for(_ in 0...strumlinesAmount) { - super.draw(); - x += width; - } - x = ogX; - } + makeGraphic(160, 160, 0xFF272727, true); + pixels.lock(); + for(y in 0...4) + for(x in 0...2) + pixels.fillRect(new Rectangle(40*((x*2)+(y%2)), 40*y, 40, 40), 0xFF545454); + pixels.fillRect(new Rectangle(0, 0, 1, 160), 0xFFDDDDDD); + pixels.fillRect(new Rectangle(159, 0, 1, 160), 0xFFDDDDDD); + pixels.unlock(); + // loadFrame(frame); + } + + public override function draw() { + var ogX:Float = x; + for(_ in 0...strumlinesAmount) { + super.draw(); + x += width; + } + x = ogX; + } } class CharterBackdropDummy extends UISprite { - var parent:CharterBackdrop; - public function new(parent:CharterBackdrop) { - super(); - this.parent = parent; - cameras = parent.cameras; + var parent:CharterBackdrop; + public function new(parent:CharterBackdrop) { + super(); + this.parent = parent; + cameras = parent.cameras; scrollFactor.set(1, 0); - } - - public override function updateButton() { - camera.getViewRect(__rect); - UIState.state.updateRectButtonHandler(this, __rect, onHovered); - } + } - public override function draw() { - @:privateAccess - __lastDrawCameras = [for(c in cameras) c]; - } + public override function updateButton() { + camera.getViewRect(__rect); + UIState.state.updateRectButtonHandler(this, __rect, onHovered); + } + + public override function draw() { + @:privateAccess + __lastDrawCameras = [for(c in cameras) c]; + } } \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterSelection.hx b/source/funkin/editors/charter/CharterSelection.hx index 7415ee63..02908d8b 100644 --- a/source/funkin/editors/charter/CharterSelection.hx +++ b/source/funkin/editors/charter/CharterSelection.hx @@ -1,5 +1,6 @@ package funkin.editors.charter; +import funkin.system.framerate.Framerate; import flixel.util.FlxColor; import funkin.menus.FreeplayState.FreeplaySonglist; import funkin.editors.EditorTreeMenu; @@ -7,48 +8,50 @@ import funkin.options.*; import funkin.options.type.*; class CharterSelection extends EditorTreeMenu { - public var freeplayList:FreeplaySonglist; - public override function create() { - bgType = "charter"; + public var freeplayList:FreeplaySonglist; + public override function create() { + bgType = "charter"; - super.create(); + super.create(); - freeplayList = FreeplaySonglist.get(false); + Framerate.offset.y = 60; - main = new OptionsScreen("Chart Editor", "Select a song to modify the charts from.", [ - for(s in freeplayList.songs) new IconOption(s.name, "Press ACCEPT to choose a difficulty to edit.", s.icon, function() { - optionsTree.add(new OptionsScreen(s.name, "Select a difficulty to continue, or press 1 to add a new one.", [ - for(d in s.difficulties) new TextOption(d, "Press ACCEPT to edit the chart for the selected difficulty", function() { - FlxG.switchState(new Charter(s.name, d)); - }) - ])); - }) - ]); - } + freeplayList = FreeplaySonglist.get(false); - public override function update(elapsed:Float) { - super.update(elapsed); + main = new OptionsScreen("Chart Editor", "Select a song to modify the charts from.", [ + for(s in freeplayList.songs) new IconOption(s.name, "Press ACCEPT to choose a difficulty to edit.", s.icon, function() { + optionsTree.add(new OptionsScreen(s.name, "Select a difficulty to continue, or press 1 to add a new one.", [ + for(d in s.difficulties) new TextOption(d, "Press ACCEPT to edit the chart for the selected difficulty", function() { + FlxG.switchState(new Charter(s.name, d)); + }) + ])); + }) + ]); + } - bg.colorTransform.redOffset = lerp(bg.colorTransform.redOffset, 0, 0.0625); - bg.colorTransform.greenOffset = lerp(bg.colorTransform.greenOffset, 0, 0.0625); - bg.colorTransform.blueOffset = lerp(bg.colorTransform.blueOffset, 0, 0.0625); - bg.colorTransform.redMultiplier = lerp(bg.colorTransform.redMultiplier, 1, 0.0625); - bg.colorTransform.greenMultiplier = lerp(bg.colorTransform.greenMultiplier, 1, 0.0625); - bg.colorTransform.blueMultiplier = lerp(bg.colorTransform.blueMultiplier, 1, 0.0625); - } + public override function update(elapsed:Float) { + super.update(elapsed); - public override function onMenuChange() { - super.onMenuChange(); - if (optionsTree.members.length > 1) { // selected a song - // small flashbang - var color:FlxColor = freeplayList.songs[main.curSelected].parsedColor.getDefault(0xFFFFFFFF); - - bg.colorTransform.redOffset = 0.25 * color.red; - bg.colorTransform.greenOffset = 0.25 * color.green; - bg.colorTransform.blueOffset = 0.25 * color.blue; - bg.colorTransform.redMultiplier = FlxMath.lerp(1, color.redFloat, 0.25); - bg.colorTransform.greenMultiplier = FlxMath.lerp(1, color.greenFloat, 0.25); - bg.colorTransform.blueMultiplier = FlxMath.lerp(1, color.blueFloat, 0.25); - } - } + bg.colorTransform.redOffset = lerp(bg.colorTransform.redOffset, 0, 0.0625); + bg.colorTransform.greenOffset = lerp(bg.colorTransform.greenOffset, 0, 0.0625); + bg.colorTransform.blueOffset = lerp(bg.colorTransform.blueOffset, 0, 0.0625); + bg.colorTransform.redMultiplier = lerp(bg.colorTransform.redMultiplier, 1, 0.0625); + bg.colorTransform.greenMultiplier = lerp(bg.colorTransform.greenMultiplier, 1, 0.0625); + bg.colorTransform.blueMultiplier = lerp(bg.colorTransform.blueMultiplier, 1, 0.0625); + } + + public override function onMenuChange() { + super.onMenuChange(); + if (optionsTree.members.length > 1) { // selected a song + // small flashbang + var color:FlxColor = freeplayList.songs[main.curSelected].parsedColor.getDefault(0xFFFFFFFF); + + bg.colorTransform.redOffset = 0.25 * color.red; + bg.colorTransform.greenOffset = 0.25 * color.green; + bg.colorTransform.blueOffset = 0.25 * color.blue; + bg.colorTransform.redMultiplier = FlxMath.lerp(1, color.redFloat, 0.25); + bg.colorTransform.greenMultiplier = FlxMath.lerp(1, color.greenFloat, 0.25); + bg.colorTransform.blueMultiplier = FlxMath.lerp(1, color.blueFloat, 0.25); + } + } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 1bb6e6dc..e0eebfc2 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -1,5 +1,6 @@ package funkin.editors.ui; +import funkin.system.framerate.Framerate; import funkin.editors.ui.UIContextMenu.UIContextMenuCallback; import openfl.ui.Mouse; import funkin.editors.ui.UIContextMenu.UIContextMenuOption; @@ -8,89 +9,88 @@ import flixel.math.FlxRect; class UIState extends MusicBeatState { - public var curContextMenu:UIContextMenu = null; + public var curContextMenu:UIContextMenu = null; - public static var state(get, null):UIState; + public static var state(get, null):UIState; - public var buttonHandler:Void->Void = null; - public var hoveredSprite:UISprite = null; + public var buttonHandler:Void->Void = null; + public var hoveredSprite:UISprite = null; - private var __rect:FlxRect; - private var __mousePos:FlxPoint; + private var __rect:FlxRect; + private var __mousePos:FlxPoint; - private inline static function get_state() - return FlxG.state is UIState ? cast FlxG.state : null; + private inline static function get_state() + return FlxG.state is UIState ? cast FlxG.state : null; - public override function create() { - __rect = new FlxRect(); - __mousePos = FlxPoint.get(); - super.create(); - } + public override function create() { + __rect = new FlxRect(); + __mousePos = FlxPoint.get(); + super.create(); + Framerate.offset.y = 30; + } - public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) { - spr.__rect.x = spr.x; - spr.__rect.y = spr.y; - spr.__rect.width = spr.width; - spr.__rect.height = spr.height; - updateRectButtonHandler(spr, spr.__rect, buttonHandler); - } + public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) { + spr.__rect.x = spr.x; + spr.__rect.y = spr.y; + spr.__rect.width = spr.width; + spr.__rect.height = spr.height; + updateRectButtonHandler(spr, spr.__rect, buttonHandler); + } - public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) { - - - for(camera in spr.__lastDrawCameras) { + public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) { + for(camera in spr.__lastDrawCameras) { var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get()); - __rect.x = rect.x; - __rect.y = rect.y; - __rect.width = rect.width; - __rect.height = rect.height; - - __rect.x -= camera.scroll.x * spr.scrollFactor.x; - __rect.y -= camera.scroll.y * spr.scrollFactor.y; - - if (((pos.x > __rect.x) && (pos.x < __rect.x + rect.width)) && ((pos.y > __rect.y) && (pos.y < __rect.y + __rect.height))) { - spr.hoveredByChild = true; - this.hoveredSprite = spr; - this.buttonHandler = buttonHandler; - pos.put(); - return; - } - pos.put(); - } - } + __rect.x = rect.x; + __rect.y = rect.y; + __rect.width = rect.width; + __rect.height = rect.height; - public override function tryUpdate(elapsed:Float) { + __rect.x -= camera.scroll.x * spr.scrollFactor.x; + __rect.y -= camera.scroll.y * spr.scrollFactor.y; + + if (((pos.x > __rect.x) && (pos.x < __rect.x + rect.width)) && ((pos.y > __rect.y) && (pos.y < __rect.y + __rect.height))) { + spr.hoveredByChild = true; + this.hoveredSprite = spr; + this.buttonHandler = buttonHandler; + pos.put(); + return; + } + pos.put(); + } + } + + public override function tryUpdate(elapsed:Float) { FlxG.mouse.getScreenPosition(FlxG.camera, __mousePos); - super.tryUpdate(elapsed); + super.tryUpdate(elapsed); - if (buttonHandler != null) { - buttonHandler(); - buttonHandler = null; - } + if (buttonHandler != null) { + buttonHandler(); + buttonHandler = null; + } - if (hoveredSprite != null) { - Mouse.cursor = hoveredSprite.cursor; - hoveredSprite = null; - } else { - Mouse.cursor = ARROW; - } - } + if (hoveredSprite != null) { + Mouse.cursor = hoveredSprite.cursor; + hoveredSprite = null; + } else { + Mouse.cursor = ARROW; + } + } - public override function destroy() { - super.destroy(); - __mousePos.put(); - } + public override function destroy() { + super.destroy(); + __mousePos.put(); + } - public function openContextMenu(options:Array, ?callback:UIContextMenuCallback, ?x:Float, ?y:Float) { - var state = FlxG.state; - while(state.subState != null) - state = state.subState; + public function openContextMenu(options:Array, ?callback:UIContextMenuCallback, ?x:Float, ?y:Float) { + var state = FlxG.state; + while(state.subState != null) + state = state.subState; - state.persistentDraw = true; - state.persistentUpdate = true; + state.persistentDraw = true; + state.persistentUpdate = true; - openSubState(curContextMenu = new UIContextMenu(options, callback, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y))); - return curContextMenu; - } + openSubState(curContextMenu = new UIContextMenu(options, callback, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y))); + return curContextMenu; + } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIUtil.hx b/source/funkin/editors/ui/UIUtil.hx index f63e4d5a..346c0b2b 100644 --- a/source/funkin/editors/ui/UIUtil.hx +++ b/source/funkin/editors/ui/UIUtil.hx @@ -4,15 +4,15 @@ import flixel.input.keyboard.FlxKey; import funkin.editors.ui.UIContextMenu.UIContextMenuOption; class UIUtil { - public static function follow(spr:FlxSprite, target:FlxSprite, x:Float = 0, y:Float = 0) { - spr.cameras = target is UISprite ? cast(target, UISprite).__lastDrawCameras : target.cameras; - spr.setPosition(target.x + x, target.y + y); - spr.scrollFactor.set(target.scrollFactor.x, target.scrollFactor.y); - } + public static function follow(spr:FlxSprite, target:FlxSprite, x:Float = 0, y:Float = 0) { + spr.cameras = target is UISprite ? cast(target, UISprite).__lastDrawCameras : target.cameras; + spr.setPosition(target.x + x, target.y + y); + spr.scrollFactor.set(target.scrollFactor.x, target.scrollFactor.y); + } - public static function contextMenuOpened(contextMenu:UIContextMenu) { - return contextMenu != null && UIState.state.curContextMenu == contextMenu; - } + public static function contextMenuOpened(contextMenu:UIContextMenu) { + return contextMenu != null && UIState.state.curContextMenu == contextMenu; + } /** * Process all options with shortcuts present in a `Array`. Also checks childrens. @@ -34,9 +34,9 @@ class UIUtil { default: keybind; } - if (FlxG.keys.checkStatus(keybind, JUST_PRESSED)) { + if (FlxG.keys.checkStatus(k, JUST_PRESSED)) { justPressed = true; - } else if (!FlxG.keys.checkStatus(keybind, PRESSED)) { + } else if (!FlxG.keys.checkStatus(k, PRESSED)) { pressed = false; break; } diff --git a/source/funkin/system/MusicBeatState.hx b/source/funkin/system/MusicBeatState.hx index afcbf3d1..a5419388 100644 --- a/source/funkin/system/MusicBeatState.hx +++ b/source/funkin/system/MusicBeatState.hx @@ -1,5 +1,6 @@ package funkin.system; +import funkin.system.framerate.Framerate; import funkin.scripting.DummyScript; import flixel.FlxState; import flixel.FlxSubState; @@ -73,7 +74,7 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver * Game Controls (Player 1 only) */ public var controlsP1(get, never):Controls; - + /** * Game Controls (Player 2 only) */ @@ -136,6 +137,7 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver } override function create() { + Framerate.offset.y = 0; super.create(); call("create"); } diff --git a/source/funkin/system/framerate/Framerate.hx b/source/funkin/system/framerate/Framerate.hx index dd7d58b0..f5205518 100644 --- a/source/funkin/system/framerate/Framerate.hx +++ b/source/funkin/system/framerate/Framerate.hx @@ -1,5 +1,6 @@ package funkin.system.framerate; +import flixel.math.FlxPoint; import openfl.events.KeyboardEvent; import openfl.display.DisplayObject; import openfl.display.Sprite; @@ -8,93 +9,99 @@ import openfl.text.TextFormat; import openfl.ui.Keyboard; class Framerate extends Sprite { - public static var instance:Framerate; - - public static var textFormat:TextFormat; - public static var fpsCounter:FramerateCounter; - public static var memoryCounter:MemoryCounter; - #if SHOW_BUILD_ON_FPS - public static var codenameBuildField:CodenameBuildField; - #end + public static var instance:Framerate; - public static var fontName:String = #if windows '${Sys.getEnv("windir")}\\Fonts\\consola.ttf' #else "_sans" #end; + public static var textFormat:TextFormat; + public static var fpsCounter:FramerateCounter; + public static var memoryCounter:MemoryCounter; + #if SHOW_BUILD_ON_FPS + public static var codenameBuildField:CodenameBuildField; + #end - public static var debugMode:Bool = false; - - public var bgSprite:Sprite; + public static var fontName:String = #if windows '${Sys.getEnv("windir")}\\Fonts\\consola.ttf' #else "_sans" #end; - public var categories:Array = []; + public static var debugMode:Bool = false; + public static var offset:FlxPoint = new FlxPoint(); - public function new() { - super(); - if (instance != null) throw "Cannot create another instance"; - instance = this; - textFormat = new TextFormat("Consolas", 12, -1); + public var bgSprite:Sprite; - x = 10; - y = 2; + public var categories:Array = []; - FlxG.stage.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent) { - switch(e.keyCode) { - case #if web Keyboard.NUMBER_3 #else Keyboard.F3 #end: // 3 on web or F3 on windows, linux and other things that runs code - debugMode = !debugMode; - } - }); + public function new() { + super(); + if (instance != null) throw "Cannot create another instance"; + instance = this; + textFormat = new TextFormat("Consolas", 12, -1); - bgSprite = new Sprite(); - bgSprite.graphics.beginFill(0xFF000000); - bgSprite.graphics.drawRect(0, 0, 1, 1); - bgSprite.graphics.endFill(); - bgSprite.alpha = 0; - addChild(bgSprite); + x = 10; + y = 2; - __addToList(fpsCounter = new FramerateCounter()); - __addToList(memoryCounter = new MemoryCounter()); - #if SHOW_BUILD_ON_FPS - __addToList(codenameBuildField = new CodenameBuildField()); - #end - __addCategory(new ConductorInfo()); - __addCategory(new FlixelInfo()); - __addCategory(new SystemInfo()); - __addCategory(new AssetTreeInfo()); - - #if (gl_stats && !disable_cffi && (!html5 || !canvas)) - __addCategory(new StatsInfo()); - #end - } + FlxG.stage.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent) { + switch(e.keyCode) { + case #if web Keyboard.NUMBER_3 #else Keyboard.F3 #end: // 3 on web or F3 on windows, linux and other things that runs code + debugMode = !debugMode; + } + }); - private function __addCategory(category:FramerateCategory) { - categories.push(category); - __addToList(category); - } - private var __lastAddedSprite:DisplayObject = null; - private function __addToList(spr:DisplayObject) { - spr.x = 0; - spr.y = __lastAddedSprite != null ? (__lastAddedSprite.y + __lastAddedSprite.height) : 4; - __lastAddedSprite = spr; - addChild(spr); - } + bgSprite = new Sprite(); + bgSprite.graphics.beginFill(0xFF000000); + bgSprite.graphics.drawRect(0, 0, 1, 1); + bgSprite.graphics.endFill(); + bgSprite.alpha = 0; + addChild(bgSprite); - - var debugAlpha:Float = 0; - public override function __enterFrame(t:Int) { - super.__enterFrame(t); - debugAlpha = CoolUtil.fpsLerp(debugAlpha, debugMode ? 1 : 0, 1); - bgSprite.alpha = debugAlpha * 0.5; - - var width = Math.max(fpsCounter.width, #if SHOW_BUILD_ON_FPS Math.max(memoryCounter.width, codenameBuildField.width) #else memoryCounter.width #end) + (x*2); - var height = #if SHOW_BUILD_ON_FPS codenameBuildField.y + codenameBuildField.height #else memoryCounter.y + memoryCounter.height #end; - bgSprite.x = -x; - bgSprite.scaleX = width; - bgSprite.scaleY = height; + __addToList(fpsCounter = new FramerateCounter()); + __addToList(memoryCounter = new MemoryCounter()); + #if SHOW_BUILD_ON_FPS + __addToList(codenameBuildField = new CodenameBuildField()); + #end + __addCategory(new ConductorInfo()); + __addCategory(new FlixelInfo()); + __addCategory(new SystemInfo()); + __addCategory(new AssetTreeInfo()); - var y:Float = height + 4; + #if (gl_stats && !disable_cffi && (!html5 || !canvas)) + __addCategory(new StatsInfo()); + #end + } - for(c in categories) { - c.alpha = debugAlpha; - c.x = FlxMath.lerp(-c.width, 0, debugAlpha); - c.y = y; - y = c.y + c.height + 4; - } - } + private function __addCategory(category:FramerateCategory) { + categories.push(category); + __addToList(category); + } + private var __lastAddedSprite:DisplayObject = null; + private function __addToList(spr:DisplayObject) { + spr.x = 0; + spr.y = __lastAddedSprite != null ? (__lastAddedSprite.y + __lastAddedSprite.height) : 4; + //spr.y += offset.y; + __lastAddedSprite = spr; + addChild(spr); + } + + + var debugAlpha:Float = 0; + public override function __enterFrame(t:Int) { + super.__enterFrame(t); + debugAlpha = CoolUtil.fpsLerp(debugAlpha, debugMode ? 1 : 0, 1); + bgSprite.alpha = debugAlpha * 0.5; + + x = 10 + offset.x; + y = 2 + offset.y; + + var width = Math.max(fpsCounter.width, #if SHOW_BUILD_ON_FPS Math.max(memoryCounter.width, codenameBuildField.width) #else memoryCounter.width #end) + (x*2); + var height = #if SHOW_BUILD_ON_FPS codenameBuildField.y + codenameBuildField.height #else memoryCounter.y + memoryCounter.height #end; + bgSprite.x = -x; + bgSprite.y = offset.x; + bgSprite.scaleX = width; + bgSprite.scaleY = height; + + var y:Float = height + 4; + + for(c in categories) { + c.alpha = debugAlpha; + c.x = FlxMath.lerp(-c.width - offset.x, 0, debugAlpha); + c.y = y; + y = c.y + c.height + 4; + } + } } \ No newline at end of file