context menu done
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.FlxCamera;
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
import flixel.FlxSprite;
|
||||
import funkin.desktop.sprites.*;
|
||||
import flixel.FlxObject;
|
||||
@@ -9,9 +11,16 @@ class ContextMenu extends WindowGroup<FlxObject> {
|
||||
public var bg:SpliceSprite;
|
||||
public var texts:Array<WindowText> = [];
|
||||
public var selectionBGs:Array<FlxSprite> = [];
|
||||
public var callback:Int->Void;
|
||||
public var contextOptions:Array<ContextOption> = [];
|
||||
public var contextCamera:FlxCamera;
|
||||
|
||||
public override function new(x:Float, y:Float, options:Array<ContextOption>, callback:Int->Void) {
|
||||
super();
|
||||
this.callback = callback;
|
||||
this.contextOptions = options;
|
||||
|
||||
DesktopMain.contextMenu = FlxDestroyUtil.destroy(DesktopMain.contextMenu);
|
||||
|
||||
var bgTheme = DesktopMain.theme.contextBackground;
|
||||
var optionTheme = DesktopMain.theme.contextOption;
|
||||
@@ -23,23 +32,67 @@ class ContextMenu extends WindowGroup<FlxObject> {
|
||||
var w:Float = 80;
|
||||
for(k=>o in options) {
|
||||
var selectSpr = new FlxSprite(bgTheme.left, bgTheme.top + (k * optionTheme.height));
|
||||
selectSpr.loadGraphic(Paths.image(bgTheme.sprite));
|
||||
selectSpr.loadGraphic(Paths.image(optionTheme.sprite));
|
||||
selectSpr.setGraphicSize(10, Std.int(optionTheme.height));
|
||||
selectSpr.visible = false;
|
||||
selectionBGs.push(selectSpr);
|
||||
add(selectSpr);
|
||||
|
||||
var text = new WindowText(4, 4, 0, o.name);
|
||||
text.y = selectSpr.y + ((selectSpr.height - text.height) / 2);
|
||||
text.applyFontSettings(bgTheme);
|
||||
texts.push(text);
|
||||
add(text);
|
||||
if (w < text.width)
|
||||
w = text.width;
|
||||
|
||||
lastOption = selectSpr;
|
||||
}
|
||||
var ow = Std.int(w) + 20;
|
||||
for(o in selectionBGs) {
|
||||
o.setGraphicSize(ow, Std.int(optionTheme.height));
|
||||
o.updateHitbox();
|
||||
}
|
||||
bg.resize(bgTheme.left + ow + bgTheme.right, lastOption.y + lastOption.height + bgTheme.bottom);
|
||||
contextCamera = camera = new FlxCamera(Std.int(x), Std.int(y), Std.int(bg.width), Std.int(bg.height));
|
||||
contextCamera.pixelPerfectRender = true;
|
||||
contextCamera.bgColor = 0;
|
||||
FlxG.cameras.add(contextCamera, false);
|
||||
|
||||
DesktopMain.contextMenu = this;
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
if (DesktopMain.mouseInput.overlaps(bg, camera)) {
|
||||
for(i=>o in selectionBGs) {
|
||||
var wasVisible = o.visible;
|
||||
if (o.visible = DesktopMain.mouseInput.overlaps(o, camera)) {
|
||||
if (DesktopMain.mouseInput.justReleased) {
|
||||
// select option
|
||||
if (contextOptions[i].callback != null)
|
||||
contextOptions[i].callback();
|
||||
if (callback != null)
|
||||
callback(i);
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
if (o.visible != wasVisible) {
|
||||
texts[i].applyFontSettings(o.visible ? DesktopMain.theme.contextOption : DesktopMain.theme.contextBackground);
|
||||
}
|
||||
}
|
||||
DesktopMain.mouseInput.cancel();
|
||||
} else {
|
||||
if (DesktopMain.mouseInput.justPressed) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
super.destroy();
|
||||
FlxG.cameras.remove(camera, true);
|
||||
DesktopMain.contextMenu = null;
|
||||
FlxG.cameras.remove(contextCamera, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,18 @@ class WindowDragHitbox extends FlxObject {
|
||||
var screenPos = FlxG.mouse.getScreenPosition(FlxG.camera);
|
||||
offset = FlxPoint.get(parent.content.winX - screenPos.x, parent.content.winY - screenPos.y);
|
||||
dragging = true;
|
||||
} else if (DesktopMain.mouseInput.justPressedRight) {
|
||||
var input = DesktopMain.mouseInput;
|
||||
new ContextMenu(input.screenPos.x, input.screenPos.y, [
|
||||
{
|
||||
name: "Close",
|
||||
callback: function() {
|
||||
parent.close();
|
||||
}
|
||||
}
|
||||
], function(i) {
|
||||
trace(i);
|
||||
});
|
||||
}
|
||||
DesktopMain.mouseInput.cancel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user