new ui stuff

This commit is contained in:
Yoshman29
2023-03-18 01:28:13 +01:00
parent fee84bd87c
commit 418089fdf6
9 changed files with 117 additions and 5 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 906 B

+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="context-bg.png">
<!-- Created without animate lol i wrote this-->
<SubTexture name="topleft" x="0" y="0" width="10" height="10"/>
<SubTexture name="top" x="10" y="0" width="44" height="10"/>
<SubTexture name="topright" x="54" y="0" width="10" height="10"/>
<SubTexture name="middleleft" x="0" y="10" width="10" height="44"/>
<SubTexture name="middle" x="10" y="10" width="44" height="44"/>
<SubTexture name="middleright" x="54" y="10" width="10" height="44"/>
<SubTexture name="bottomleft" x="0" y="54" width="10" height="10"/>
<SubTexture name="bottom" x="10" y="54" width="44" height="10"/>
<SubTexture name="bottomright" x="54" y="54" width="10" height="10"/>
</TextureAtlas>
Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

+1 -1
View File
@@ -1 +1 @@
2559
2566
+31
View File
@@ -63,4 +63,35 @@ class UIDebugState extends UIState {
]));
}, 130, 48));
}
public override function update(elapsed:Float) {
super.update(elapsed);
if (FlxG.mouse.justReleasedRight) {
openContextMenu([
{
label: "Test 1",
onSelect: function() {
}
},
{
label: "Test 2",
onSelect: function() {
}
},
{
label: "Test 3",
childs: [
{
label: "Test 2",
onSelect: function() {
}
}
]
}
]);
}
}
}
+44
View File
@@ -0,0 +1,44 @@
package funkin.editors.ui;
class UIContextMenu extends MusicBeatSubstate {
var options:Array<UIContextMenuOption>;
var x:Float;
var y:Float;
var contextCam:FlxCamera;
var bg:UISpliceSprite;
public function new(options:Array<UIContextMenuOption>, x:Float, y:Float) {
super();
this.options = options.getDefault([]);
this.x = x;
this.y = y;
}
public override function create() {
super.create();
camera = contextCam = new FlxCamera();
contextCam.bgColor = 0;
contextCam.alpha = 0;
FlxG.cameras.add(contextCam, false);
bg = new UISpliceSprite(x, y, 100, 100, 'editors/ui/context-bg');
add(bg);
}
public override function update(elapsed:Float) {
if (FlxG.mouse.pressed && !bg.hoveredByChild)
close();
super.update(elapsed);
contextCam.alpha = CoolUtil.fpsLerp(contextCam.alpha, 1, 0.25);
}
}
typedef UIContextMenuOption = {
var label:String;
var ?icon:Int;
var ?onSelect:Void->Void;
var ?childs:Array<UIContextMenuOption>;
}
+8 -2
View File
@@ -13,8 +13,11 @@ class UISprite extends FlxSprite {
private var __oldDefCams:Array<FlxCamera>;
var hovered:Bool = false;
var pressed:Bool = false;
public var hovered:Bool = false;
public var hoveredByChild:Bool = false;
public var pressed:Bool = false;
public var hoverCallback:Void->Void = null;
public override function update(elapsed:Float) {
super.update(elapsed);
@@ -32,6 +35,7 @@ class UISprite extends FlxSprite {
hovered = false;
pressed = false;
hoveredByChild = false;
}
public override function draw() {
@@ -72,5 +76,7 @@ class UISprite extends FlxSprite {
hovered = true;
if (FlxG.mouse.pressed)
pressed = true;
if (hoverCallback != null)
hoverCallback();
}
}
+18 -2
View File
@@ -1,5 +1,6 @@
package funkin.editors.ui;
import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
@@ -29,7 +30,8 @@ class UIState extends MusicBeatState {
}
public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) {
var pos = FlxG.mouse.getScreenPosition(camera);
FlxG.mouse.getScreenPosition(camera, __mousePos);
for(camera in spr.__lastDrawCameras) {
__rect.x = rect.x;
__rect.y = rect.y;
@@ -39,7 +41,8 @@ class UIState extends MusicBeatState {
__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))) {
if (((__mousePos.x > __rect.x) && (__mousePos.x < __rect.x + rect.width)) && ((__mousePos.y > __rect.y) && (__mousePos.y < __rect.y + __rect.height))) {
spr.hoveredByChild = true;
this.buttonHandler = buttonHandler;
return;
}
@@ -59,4 +62,17 @@ class UIState extends MusicBeatState {
super.destroy();
__mousePos.put();
}
public function openContextMenu(options:Array<UIContextMenuOption>, ?x:Float, ?y:Float) {
var state = FlxG.state;
while(state.subState != null)
state = state.subState;
state.persistentDraw = true;
state.persistentUpdate = true;
openSubState(new UIContextMenu(options, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y)));
}
}