diff --git a/assets/images/editors/ui/menu-item.png b/assets/images/editors/ui/menu-item.png
new file mode 100644
index 00000000..58a7b72f
Binary files /dev/null and b/assets/images/editors/ui/menu-item.png differ
diff --git a/assets/images/editors/ui/menu-item.xml b/assets/images/editors/ui/menu-item.xml
new file mode 100644
index 00000000..a7029751
--- /dev/null
+++ b/assets/images/editors/ui/menu-item.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/buildnumber.txt b/buildnumber.txt
index a51f76e9..dabbcbfb 100644
--- a/buildnumber.txt
+++ b/buildnumber.txt
@@ -1 +1 @@
-2615
\ No newline at end of file
+2623
\ No newline at end of file
diff --git a/source/funkin/editors/UIDebugState.hx b/source/funkin/editors/UIDebugState.hx
index a5b2b36c..0efeb1b8 100644
--- a/source/funkin/editors/UIDebugState.hx
+++ b/source/funkin/editors/UIDebugState.hx
@@ -16,7 +16,7 @@ class UIDebugState extends UIState {
add(new UITopMenu([
{
- label: "Chart",
+ label: "File",
childs: [
{
label: "New"
diff --git a/source/funkin/editors/ui/UIContextMenu.hx b/source/funkin/editors/ui/UIContextMenu.hx
index d692f036..4f3bcdb2 100644
--- a/source/funkin/editors/ui/UIContextMenu.hx
+++ b/source/funkin/editors/ui/UIContextMenu.hx
@@ -1,7 +1,7 @@
package funkin.editors.ui;
class UIContextMenu extends MusicBeatSubstate {
- var options:Array;
+ public var options:Array;
var x:Float;
var y:Float;
var contextCam:FlxCamera;
@@ -12,6 +12,12 @@ class UIContextMenu extends MusicBeatSubstate {
public var contextMenuOptions:Array = [];
public var separators:Array = [];
+ private var __oobDeletion:Bool = true;
+
+ public inline function preventOutOfBoxClickDeletion() {
+ __oobDeletion = false;
+ }
+
public function new(options:Array, callback:UIContextMenuCallback, x:Float, y:Float) {
super();
this.options = options.getDefault([]);
@@ -72,9 +78,11 @@ class UIContextMenu extends MusicBeatSubstate {
}
public override function update(elapsed:Float) {
- if (FlxG.mouse.pressed && !bg.hoveredByChild)
+ if (__oobDeletion && FlxG.mouse.pressed && !bg.hoveredByChild)
close();
+ __oobDeletion = true;
+
super.update(elapsed);
contextCam.alpha = CoolUtil.fpsLerp(contextCam.alpha, 1, 0.25);
@@ -83,6 +91,8 @@ class UIContextMenu extends MusicBeatSubstate {
public override function destroy() {
super.destroy();
FlxG.cameras.remove(contextCam);
+ if (UIState.state.curContextMenu == this)
+ UIState.state.curContextMenu = null;
}
}
@@ -105,7 +115,7 @@ class UIContextMenuOptionSpr extends UISliceSprite {
this.option = option;
this.parent = parent;
- super(x, y, label.frameWidth + 22, label.frameHeight, 'editors/ui/button');
+ super(x, y, label.frameWidth + 22, label.frameHeight, 'editors/ui/menu-item');
members.push(label);
}
diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx
index 1843c28d..8b5b8435 100644
--- a/source/funkin/editors/ui/UIState.hx
+++ b/source/funkin/editors/ui/UIState.hx
@@ -7,6 +7,9 @@ import flixel.math.FlxPoint;
import flixel.math.FlxRect;
class UIState extends MusicBeatState {
+
+ public var curContextMenu:UIContextMenu = null;
+
public static var state(get, null):UIState;
public var buttonHandler:Void->Void = null;
@@ -82,6 +85,7 @@ class UIState extends MusicBeatState {
state.persistentDraw = true;
state.persistentUpdate = true;
- openSubState(new UIContextMenu(options, callback, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y)));
+ 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/UITopMenu.hx b/source/funkin/editors/ui/UITopMenu.hx
index 9cb4e17e..12e96ae8 100644
--- a/source/funkin/editors/ui/UITopMenu.hx
+++ b/source/funkin/editors/ui/UITopMenu.hx
@@ -11,18 +11,66 @@ class UITopMenu extends UISliceSprite {
var x:Int = 0;
for(o in options) {
- var b:UIButton = null;
- b = new UIButton(x, 0, o.label, function() {
- UIState.state.openContextMenu(o.childs, null, b.x, b.y + b.bHeight);
- }, 0, 23);
- b.resize(b.field.frameWidth + 8, b.bHeight);
+ var b = new UITopMenuButton(x, 0, this, o.label, o.childs);
x += b.bWidth;
members.push(b);
}
}
+ public var anyMenuOpened:Bool = false;
+
public override function update(elapsed:Float) {
+ anyMenuOpened = false;
+ for(c in members) if (cast(c, UITopMenuButton).curMenu.contextMenuOpened()) {
+ anyMenuOpened = true;
+ break;
+ }
+
super.update(elapsed);
+
+
bWidth = FlxG.width;
}
+}
+
+class UITopMenuButton extends UISliceSprite {
+ public var label:UIText;
+ public var contextMenu:Array;
+ public var parent:UITopMenu;
+
+ public var curMenu:UIContextMenu = null;
+
+ public function new(x:Float, y:Float, parent:UITopMenu, label:String, contextMenu:Array) {
+ super(x, y, 0, 23, "editors/ui/menu-item");
+ this.contextMenu = contextMenu;
+ this.parent = parent;
+ cursor = BUTTON;
+
+ this.label = new UIText(4, 0, 0, label);
+ this.label.alignment = CENTER;
+ bWidth = this.label.frameWidth + 8;
+ members.push(this.label);
+ }
+
+ public override function update(elapsed:Float) {
+ label.follow(this, 4, 0);
+ super.update(elapsed);
+
+ var opened = curMenu.contextMenuOpened();
+ alpha = (hovered || opened) ? 1 : 0;
+ framesOffset = opened ? 9 : 0;
+ }
+
+ public override function onHovered() {
+ super.onHovered();
+ if (hovered) {
+ if (curMenu.contextMenuOpened()) {
+ UIState.state.curContextMenu.preventOutOfBoxClickDeletion();
+ } else {
+ if (parent.anyMenuOpened || FlxG.mouse.justReleased) {
+ curMenu = UIState.state.openContextMenu(contextMenu, null, x, y + bHeight);
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/source/funkin/editors/ui/UIUtil.hx b/source/funkin/editors/ui/UIUtil.hx
index 5f36e5a3..766c2264 100644
--- a/source/funkin/editors/ui/UIUtil.hx
+++ b/source/funkin/editors/ui/UIUtil.hx
@@ -1,6 +1,6 @@
package funkin.editors.ui;
-import openfl.ui.Mouse;
+import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
class UIUtil {
public static function follow(spr:FlxSprite, target:FlxSprite, x:Float = 0, y:Float = 0) {
@@ -8,4 +8,8 @@ class UIUtil {
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;
+ }
}
\ No newline at end of file
diff --git a/source/funkin/editors/ui/UIWarningSubstate.hx b/source/funkin/editors/ui/UIWarningSubstate.hx
index db6f185a..38365f4a 100644
--- a/source/funkin/editors/ui/UIWarningSubstate.hx
+++ b/source/funkin/editors/ui/UIWarningSubstate.hx
@@ -66,6 +66,7 @@ class UIWarningSubstate extends MusicBeatSubstate {
for(e in camShaders)
e.removeShader(blurShader);
+ FlxTween.cancelTweensOf(warnCam);
FlxG.cameras.remove(warnCam);
}