From 51b5e815907aadc0a7e991340a9e4d2ca73bbdf0 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:02:51 -0700 Subject: [PATCH] SCROLLABLE EVENTS SCREEN !!! --- .../charter/CharterEventTypeSelection.hx | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/source/funkin/editors/charter/CharterEventTypeSelection.hx b/source/funkin/editors/charter/CharterEventTypeSelection.hx index 2ae3986e..82f51249 100644 --- a/source/funkin/editors/charter/CharterEventTypeSelection.hx +++ b/source/funkin/editors/charter/CharterEventTypeSelection.hx @@ -5,6 +5,11 @@ import funkin.backend.chart.EventsData; class CharterEventTypeSelection extends UISubstateWindow { var callback:String->Void; + var buttons:Array = []; + + var buttonsBG:UISliceSprite; + var buttonCameras:FlxCamera; + public function new(callback:String->Void) { super(); this.callback = callback; @@ -13,15 +18,24 @@ class CharterEventTypeSelection extends UISubstateWindow { public override function create() { winTitle = "Choose an event type..."; super.create(); + var w:Int = winWidth - 20; - var lastIndex:Int = 0; + + buttonCameras = new FlxCamera(Std.int(windowSpr.x+41), Std.int(windowSpr.y), w, (32 * 16)); + FlxG.cameras.add(buttonCameras, false); + buttonCameras.bgColor = 0; + + buttonsBG = new UIWindow(10, 41, buttonCameras.width, buttonCameras.height, ""); + buttonsBG.frames = Paths.getFrames('editors/ui/inputbox'); + add(buttonsBG); for(k=>eventName in EventsData.eventsList) { - var button = new UIButton(10, 41 + (32 * k), eventName, function() { + var button = new UIButton(0, (32 * k), eventName, function() { close(); callback(eventName); }, w); - add(button); + button.cameras = [buttonCameras]; + buttons.push(cast add(button)); var icon = CharterEvent.generateEventIcon({ name: eventName, @@ -30,17 +44,38 @@ class CharterEventTypeSelection extends UISubstateWindow { }); icon.setGraphicSize(20, 20); // Std.int(button.bHeight - 12) icon.updateHitbox(); + icon.cameras = [buttonCameras]; icon.x = button.x + 8; icon.y = button.y + Math.abs(button.bHeight - icon.height) / 2; add(icon); - - lastIndex = k; } - add(new UIButton(10, 51 + (32 * (lastIndex+1)), "Cancel", function() { + windowSpr.bHeight = 61 + (32 * (17)); + + add(new UIButton(10, windowSpr.bHeight-42, "Cancel", function() { close(); }, w)); - windowSpr.bHeight = 61 + (32 * (lastIndex+2)); + } + + override function update(elapsed:Float) { + super.update(elapsed); + buttonCameras.zoom = subCam.zoom; + + buttonCameras.x = -subCam.scroll.x + Std.int(windowSpr.x+10); + buttonCameras.y = -subCam.scroll.y + Std.int(windowSpr.y+41); + + buttonCameras.scroll.y = FlxMath.bound(buttonCameras.scroll.y - (buttonsBG.hovered ? FlxG.mouse.wheel : 0) * 12, 0, + (buttons[buttons.length-1].y + buttons[buttons.length-1].bHeight) - buttonCameras.height); + } + + override function destroy() { + super.destroy(); + + if(buttonCameras != null) { + if (FlxG.cameras.list.contains(buttonCameras)) + FlxG.cameras.remove(buttonCameras); + buttonCameras = null; + } } } \ No newline at end of file