optimized lunar's code
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
2606
|
||||
2607
|
||||
@@ -16,6 +16,8 @@ class UIButton extends UISpliceSprite {
|
||||
field.borderSize = 1;
|
||||
field.alignment = CENTER;
|
||||
field.fieldWidth = w;
|
||||
|
||||
cursor = BUTTON;
|
||||
}
|
||||
|
||||
public override function resize(w:Int, h:Int) {
|
||||
|
||||
@@ -23,6 +23,8 @@ class UICheckbox extends UISprite {
|
||||
|
||||
members.push(check);
|
||||
members.push(field);
|
||||
|
||||
cursor = BUTTON;
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package funkin.editors.ui;
|
||||
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
import flixel.math.FlxRect;
|
||||
import openfl.ui.MouseCursor;
|
||||
|
||||
@:allow(funkin.editors.ui.UIState)
|
||||
@:allow(funkin.editors.ui.UIUtil)
|
||||
@@ -19,6 +20,8 @@ class UISprite extends FlxSprite {
|
||||
|
||||
public var hoverCallback:Void->Void = null;
|
||||
|
||||
public var cursor:MouseCursor = ARROW;
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
hovered = false;
|
||||
pressed = false;
|
||||
|
||||
@@ -8,8 +8,8 @@ import flixel.math.FlxRect;
|
||||
class UIState extends MusicBeatState {
|
||||
public static var state(get, null):UIState;
|
||||
|
||||
public var uiElements:Array<UISprite> = [];
|
||||
public var buttonHandler:Void->Void = null;
|
||||
public var hoveredSprite:UISprite = null;
|
||||
|
||||
private var __rect:FlxRect;
|
||||
private var __mousePos:FlxPoint;
|
||||
@@ -21,11 +21,6 @@ class UIState extends MusicBeatState {
|
||||
__rect = new FlxRect();
|
||||
__mousePos = FlxPoint.get();
|
||||
super.create();
|
||||
|
||||
memberAdded.add((basic:FlxBasic) -> {
|
||||
if (basic is UISprite) uiElements.push(cast basic);
|
||||
UIUtil.focusedUI = uiElements;
|
||||
});
|
||||
}
|
||||
|
||||
public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) {
|
||||
@@ -50,6 +45,7 @@ class UIState extends MusicBeatState {
|
||||
|
||||
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.hoveredSprite = spr;
|
||||
this.buttonHandler = buttonHandler;
|
||||
return;
|
||||
}
|
||||
@@ -64,7 +60,12 @@ class UIState extends MusicBeatState {
|
||||
buttonHandler = null;
|
||||
}
|
||||
|
||||
UIUtil.updateCursor();
|
||||
if (hoveredSprite != null) {
|
||||
Mouse.cursor = hoveredSprite.cursor;
|
||||
hoveredSprite = null;
|
||||
} else {
|
||||
Mouse.cursor = ARROW;
|
||||
}
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
|
||||
@@ -8,13 +8,4 @@ class UIUtil {
|
||||
spr.setPosition(target.x + x, target.y + y);
|
||||
spr.scrollFactor.set(target.scrollFactor.x, target.scrollFactor.y);
|
||||
}
|
||||
|
||||
public static var focusedUI:Array<UISprite> = [];
|
||||
|
||||
public static function updateCursor() {
|
||||
for (element in focusedUI)
|
||||
if (element.hovered) {Mouse.cursor = BUTTON; return;}
|
||||
|
||||
Mouse.cursor = ARROW;
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ class UIWarningSubstate extends MusicBeatSubstate {
|
||||
}
|
||||
|
||||
public override function create() {
|
||||
UIUtil.focusedUI = [];
|
||||
|
||||
for(c in FlxG.cameras.list) {
|
||||
camShaders.push(c);
|
||||
c.addShader(blurShader);
|
||||
@@ -55,8 +53,6 @@ class UIWarningSubstate extends MusicBeatSubstate {
|
||||
close();
|
||||
}, 160, 30);
|
||||
add(button);
|
||||
|
||||
UIUtil.focusedUI.push(button);
|
||||
}
|
||||
|
||||
FlxTween.tween(camera, {alpha: 1}, 0.25, {ease: FlxEase.cubeOut});
|
||||
@@ -66,7 +62,6 @@ class UIWarningSubstate extends MusicBeatSubstate {
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
UIUtil.focusedUI = UIState.state.uiElements;
|
||||
super.destroy();
|
||||
for(e in camShaders)
|
||||
e.removeShader(blurShader);
|
||||
|
||||
Reference in New Issue
Block a user