diff --git a/source/funkin/editors/UIDebugState.hx b/source/funkin/editors/UIDebugState.hx index 9f6845c9..146dd2f3 100644 --- a/source/funkin/editors/UIDebugState.hx +++ b/source/funkin/editors/UIDebugState.hx @@ -1,9 +1,15 @@ package funkin.editors; +import funkin.editors.ui.UITopMenu.UITopMenuButton; import flixel.tweens.FlxTween; import funkin.editors.ui.*; class UIDebugState extends UIState { + public var topMenuSpr:UITopMenu; + + public var testingUIItems:Array = []; + public var testingUIHidden:Bool = false; + public override function create() { super.create(); @@ -14,7 +20,7 @@ class UIDebugState extends UIState { bg.scrollFactor.set(); add(bg); - add(new UITopMenu([ + add(topMenuSpr = new UITopMenu([ { label: "File", childs: [ @@ -45,15 +51,45 @@ class UIDebugState extends UIState { }, { label: "Help" + }, + { + label: "9-Splice Benchmark >", + childs: [ + { + label: "Hide Other UI Items", + onSelect: (t) -> { + testingUIHidden = !testingUIHidden; + t.icon = testingUIHidden ? 1 : 0; + + for (item in testingUIItems) + item.visible = !testingUIHidden; + }, + icon: testingUIHidden ? 1 : 0 + }, + { + label: "Clear Benchmark Sprites", + onSelect: (t) -> { + for (splice in spliceSprites) { + splice.kill(); + splice.destroy(); + + this.remove(splice); + } + + spliceSprites.resize(0); + MemoryUtil.clearMajor(); + } + } + ] } ])); - add(new UICheckbox(10, 40, "Test unchecked", false)); - add(new UICheckbox(10, 70, "Test checked", true)); - add(new UIButton(10, 100, "Test button", function() { + testingUIItems.push(cast add(new UICheckbox(10, 40, "Test unchecked", false))); + testingUIItems.push(cast add(new UICheckbox(10, 70, "Test checked", true))); + testingUIItems.push(cast add(new UIButton(10, 100, "Test button", function() { trace("Hello, World!"); - }, 130, 32)); - add(new UIButton(10, 140, "Warning test", function() { + }, 130, 32))); + testingUIItems.push(cast add(new UIButton(10, 140, "Warning test", function() { openSubState(new UIWarningSubstate("Test", "This is a test message", [ { label: "Alt. Choice", @@ -68,8 +104,8 @@ class UIDebugState extends UIState { } } ])); - }, 130, 32)); - add(new UIButton(10, 180, "Warning test (Overflowing)", function() { + }, 130, 32))); + testingUIItems.push(cast add(new UIButton(10, 180, "Warning test (Overflowing)", function() { openSubState(new UIWarningSubstate("Test", "This is a test message", [ { label: "Alt. Choice", @@ -98,15 +134,49 @@ class UIDebugState extends UIState { onClick: function(t) {} } ])); - }, 130, 48)); - add(new UITextBox(10, 220, "")); + }, 130, 48))); + testingUIItems.push(cast add(new UITextBox(10, 220, ""))); - var spliceSprite:UISliceSprite = new UISliceSprite(650, 350, 10, 30, "editors/ui/context-bg"); - add(spliceSprite); + spliceText = new UIText(0, 0, 0, "(0) Sprites"); + add(spliceText); } + public var spliceSprites:Array = []; + public var spliceText:UIText; + + public var spliceTimer:Float = 0; + public var spliceCoolDown:Float = 0.04; + public override function update(elapsed:Float) { super.update(elapsed); + + if (FlxG.keys.pressed.SPACE) { + spliceTimer += elapsed; + if (spliceTimer >= spliceCoolDown) { + spliceTimer -= spliceCoolDown; + + for (i in 0...3) { + var width:Int = FlxG.random.int(10, 200); + var height:Int = FlxG.random.int(10, 200); + + var spliceSprite:UISliceSprite = new UISliceSprite( + FlxG.random.float(0, FlxG.width-width), + FlxG.random.float(22, FlxG.height-height), + width, height, "editors/ui/context-bg" + ); + + spliceSprites.push(cast add(spliceSprite)); + } + } + } + + var spliceTopButton:UITopMenuButton = cast topMenuSpr.members[topMenuSpr.members.length-1]; + + spliceText.x = spliceTopButton.x + spliceTopButton.bWidth - 2; + spliceText.y = spliceTopButton.label.y+1; + + spliceText.text = '(${spliceSprites.length}) 9-Splice Sprites'; + if (FlxG.mouse.justReleasedRight) { openContextMenu([ {