cool sprites + fluent top menu bar

This commit is contained in:
Yoshman29
2023-03-19 15:29:59 +01:00
parent 3e2c0a0ed1
commit 09372e6608
9 changed files with 102 additions and 12 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="button.png">
<!-- Created without animate lol i wrote this-->
<SubTexture name="normal-topleft" x="0" y="0" width="4" height="4"/>
<SubTexture name="normal-top" x="4" y="0" width="12" height="4"/>
<SubTexture name="normal-topright" x="16" y="0" width="4" height="4"/>
<SubTexture name="normal-middleleft" x="0" y="4" width="4" height="15"/>
<SubTexture name="normal-middle" x="4" y="4" width="12" height="15"/>
<SubTexture name="normal-middleright" x="16" y="4" width="4" height="15"/>
<SubTexture name="normal-bottomleft" x="0" y="19" width="4" height="4"/>
<SubTexture name="normal-bottom" x="4" y="19" width="12" height="4"/>
<SubTexture name="normal-bottomright" x="16" y="19" width="4" height="4"/>
<SubTexture name="pressed-topleft" x="20" y="0" width="4" height="4"/>
<SubTexture name="pressed-top" x="24" y="0" width="12" height="4"/>
<SubTexture name="pressed-topright" x="36" y="0" width="4" height="4"/>
<SubTexture name="pressed-middleleft" x="20" y="4" width="4" height="15"/>
<SubTexture name="pressed-middle" x="24" y="4" width="12" height="15"/>
<SubTexture name="pressed-middleright" x="36" y="4" width="4" height="15"/>
<SubTexture name="pressed-bottomleft" x="20" y="19" width="4" height="4"/>
<SubTexture name="pressed-bottom" x="24" y="19" width="12" height="4"/>
<SubTexture name="pressed-bottomright" x="36" y="19" width="4" height="4"/>
</TextureAtlas>
+1 -1
View File
@@ -1 +1 @@
2615
2623
+1 -1
View File
@@ -16,7 +16,7 @@ class UIDebugState extends UIState {
add(new UITopMenu([
{
label: "Chart",
label: "File",
childs: [
{
label: "New"
+13 -3
View File
@@ -1,7 +1,7 @@
package funkin.editors.ui;
class UIContextMenu extends MusicBeatSubstate {
var options:Array<UIContextMenuOption>;
public var options:Array<UIContextMenuOption>;
var x:Float;
var y:Float;
var contextCam:FlxCamera;
@@ -12,6 +12,12 @@ class UIContextMenu extends MusicBeatSubstate {
public var contextMenuOptions:Array<UIContextMenuOptionSpr> = [];
public var separators:Array<FlxSprite> = [];
private var __oobDeletion:Bool = true;
public inline function preventOutOfBoxClickDeletion() {
__oobDeletion = false;
}
public function new(options:Array<UIContextMenuOption>, 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);
}
+5 -1
View File
@@ -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;
}
}
+53 -5
View File
@@ -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<UIContextMenuOption>;
public var parent:UITopMenu;
public var curMenu:UIContextMenu = null;
public function new(x:Float, y:Float, parent:UITopMenu, label:String, contextMenu:Array<UIContextMenuOption>) {
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);
}
}
}
}
}
+5 -1
View File
@@ -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;
}
}
@@ -66,6 +66,7 @@ class UIWarningSubstate extends MusicBeatSubstate {
for(e in camShaders)
e.removeShader(blurShader);
FlxTween.cancelTweensOf(warnCam);
FlxG.cameras.remove(warnCam);
}