From 2dbefc46d5645954bc72ce5de0f681cf30aaedb9 Mon Sep 17 00:00:00 2001
From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com>
Date: Fri, 23 Dec 2022 15:32:18 +0100
Subject: [PATCH] context menu done
---
assets/images/desktop/ui.xml | 2 +-
assets/images/desktop/ui/buttonHover.png | Bin 245 -> 257 bytes
assets/images/desktop/ui/contextOption.png | Bin 202 -> 308 bytes
buildnumber.txt | 2 +-
source/funkin/desktop/DesktopMain.hx | 34 +++++++++--
source/funkin/desktop/windows/ContextMenu.hx | 57 +++++++++++++++++-
.../desktop/windows/WindowDragHitbox.hx | 12 ++++
7 files changed, 99 insertions(+), 8 deletions(-)
diff --git a/assets/images/desktop/ui.xml b/assets/images/desktop/ui.xml
index 9c6ad81a..79c6909a 100644
--- a/assets/images/desktop/ui.xml
+++ b/assets/images/desktop/ui.xml
@@ -23,5 +23,5 @@
-
+
\ No newline at end of file
diff --git a/assets/images/desktop/ui/buttonHover.png b/assets/images/desktop/ui/buttonHover.png
index 28f0f77da9f7adfc973152700dcfd80b27f54efc..a178e6c7765970553a2608a7d5f2346274c254a8 100644
GIT binary patch
delta 208
zcmV;>05AXb0f7RLIe)WBL_t(|+O^d;62d?bL{ZIIkc7Dcg;N0${-F3sP}t%M7)hLE
zVU`&cG23+1(MvxWV>})aea?@2J7gUO8M{86Jg-t9i?ZsBeWMn9ZjK0000<
KMNUMnLSTX{D^ZaE
delta 196
zcmV;#06YJI0`&oqIe(`~L_t(|+SSiF5`s_=gkk0^0t$z~rPN47PU=PkmfIl&0nhT_
zJ!dFmX#@YLqpzw-DP`%1=smuyb;vjx)Y#+I%d`9e8C0viu}{>1ISBLwENTomvVR3W
zLEx|hD-h@~Sb{)TzzPI99aw@um%$nY+5)Bt23)Qf%s}8mz&+Cu1I|MR&j$=RTQhh8
yfl~pmdki><7`*K;;CRE}eTxBu_-`&lG_C=*SYiF&`u<`70000#lwrNH
zh9UXjMPp`Rg~Gm0Vd4oB8KK){BW#&QCO3{@3qG&5mzR`+slt
z-#4qqK5z2g(Dyb1^%ZZW{_nO*USY+2bM-|V56yO49`lgHU$e4T_?@~J=0Ej*-nEt5
zO*|3}I_yHqix`+V6dG_5{~0@_^;S${Jt-a%^U%sU_5;^<-gpg(cTdjG+W_=BgQu&X
J%Q~loCIHkJa#jEU
delta 167
zcmdnObc%6;IF|qi8v_HwgTPzO6BQ-uYdl>XLn>~)ooL9_U?9M9cJ`mi`P&6uLPShI
zws0@mut6|vW@Bpp&LXF~OG5s(e|a!H@7 {
public var bg:SpliceSprite;
public var texts:Array = [];
public var selectionBGs:Array = [];
+ public var callback:Int->Void;
+ public var contextOptions:Array = [];
+ public var contextCamera:FlxCamera;
public override function new(x:Float, y:Float, options:Array, 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 {
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);
}
}
diff --git a/source/funkin/desktop/windows/WindowDragHitbox.hx b/source/funkin/desktop/windows/WindowDragHitbox.hx
index 24344b75..c2d8a6e7 100644
--- a/source/funkin/desktop/windows/WindowDragHitbox.hx
+++ b/source/funkin/desktop/windows/WindowDragHitbox.hx
@@ -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();
}