From 94938313dd1e449b15f08c4b7798fc4e24f6b929 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 16 Feb 2024 05:24:43 -0500 Subject: [PATCH] click preview to open screenshots folder (and moved `openFolder` to FileUtil --- source/funkin/ui/debug/DebugMenuSubState.hx | 12 +--- source/funkin/util/FileUtil.hx | 19 ++++++ .../funkin/util/plugins/ScreenshotPlugin.hx | 65 ++++++++++++++++--- 3 files changed, 78 insertions(+), 18 deletions(-) diff --git a/source/funkin/ui/debug/DebugMenuSubState.hx b/source/funkin/ui/debug/DebugMenuSubState.hx index 861e99f6b..375fb8f5c 100644 --- a/source/funkin/ui/debug/DebugMenuSubState.hx +++ b/source/funkin/ui/debug/DebugMenuSubState.hx @@ -9,6 +9,7 @@ import funkin.ui.debug.charting.ChartEditorState; import funkin.ui.MusicBeatSubState; import funkin.util.logging.CrashHandler; import flixel.addons.transition.FlxTransitionableState; +import funkin.util.FileUtil; class DebugMenuSubState extends MusicBeatSubState { @@ -110,16 +111,7 @@ class DebugMenuSubState extends MusicBeatSubState #if sys function openLogFolder() { - #if windows - Sys.command('explorer', [CrashHandler.LOG_FOLDER]); - #elseif mac - // mac could be fuckie with where the log folder is relative to the game file... - // if this comment is still here... it means it has NOT been verified on mac yet! - Sys.command('open', [CrashHandler.LOG_FOLDER]); - #end - - // TODO: implement linux - // some shit with xdg-open :thinking: emoji... + FileUtil.openFolder(CrashHandler.LOG_FOLDER); } #end diff --git a/source/funkin/util/FileUtil.hx b/source/funkin/util/FileUtil.hx index 5d189c0e9..268aed57e 100644 --- a/source/funkin/util/FileUtil.hx +++ b/source/funkin/util/FileUtil.hx @@ -645,6 +645,25 @@ class FileUtil }; } + #if sys + public static function openFolder(pathFolder:String) + { + #if windows + Sys.command('explorer', [pathFolder]); + #elseif mac + // mac could be fuckie with where the log folder is relative to the game file... + // if this comment is still here... it means it has NOT been verified on mac yet! + // + // FileUtil.hx note: this was originally used to open the logs specifically! + // thats why the above comment is there! + Sys.command('open', [pathFolder]); + #end + + // TODO: implement linux + // some shit with xdg-open :thinking: emoji... + } + #end + static function convertTypeFilter(typeFilter:Array):String { var filter:String = null; diff --git a/source/funkin/util/plugins/ScreenshotPlugin.hx b/source/funkin/util/plugins/ScreenshotPlugin.hx index 40454854c..8d6f62a28 100644 --- a/source/funkin/util/plugins/ScreenshotPlugin.hx +++ b/source/funkin/util/plugins/ScreenshotPlugin.hx @@ -14,11 +14,13 @@ import flixel.util.FlxTimer; import funkin.graphics.FunkinSprite; import funkin.input.Cursor; import openfl.display.Bitmap; +import openfl.display.Sprite; import openfl.display.BitmapData; import openfl.display.PNGEncoderOptions; import openfl.geom.Matrix; import openfl.geom.Rectangle; import openfl.utils.ByteArray; +import openfl.events.MouseEvent; typedef ScreenshotPluginParams = { @@ -175,6 +177,27 @@ class ScreenshotPlugin extends FlxBasic function showFancyPreview(bitmap:Bitmap):Void { + // ermmm stealing this?? + var wasMouseHidden = false; + if (!FlxG.mouse.visible) + { + wasMouseHidden = true; + Cursor.show(); + } + + // so that it doesnt change the alpha when tweening in/out + var changingAlpha:Bool = false; + + // fuck it, cursed locally scoped functions, purely because im lazy + // (and so we can check changingAlpha, which is locally scoped.... because I'm lazy...) + var onHover = function(e:MouseEvent) { + if (!changingAlpha) e.target.alpha = 0.6; + }; + + var onHoverOut = function(e:MouseEvent) { + if (!changingAlpha) e.target.alpha = 1; + } + var scale:Float = 0.25; var w:Int = Std.int(bitmap.bitmapData.width * scale); var h:Int = Std.int(bitmap.bitmapData.height * scale); @@ -184,28 +207,49 @@ class ScreenshotPlugin extends FlxBasic matrix.scale(scale, scale); preview.draw(bitmap.bitmapData, matrix); + // used for movement + button stuff + var previewSprite = new Sprite(); + + previewSprite.buttonMode = true; + previewSprite.addEventListener(MouseEvent.MOUSE_DOWN, openScreenshotsFolder); + previewSprite.addEventListener(MouseEvent.MOUSE_OVER, onHover); + previewSprite.addEventListener(MouseEvent.MOUSE_OUT, onHoverOut); + + FlxG.stage.addChild(previewSprite); + + previewSprite.alpha = 0.0; + previewSprite.y -= 10; + var previewBitmap = new Bitmap(preview); - - FlxG.stage.addChild(previewBitmap); - - previewBitmap.alpha = 0.0; - previewBitmap.y -= 10; + previewSprite.addChild(previewBitmap); // Wait to fade in. new FlxTimer().start(PREVIEW_INITIAL_DELAY, function(_) { // Fade in. - FlxTween.tween(previewBitmap, {alpha: 1.0, y: 0}, PREVIEW_FADE_IN_DURATION, + changingAlpha = true; + FlxTween.tween(previewSprite, {alpha: 1.0, y: 0}, PREVIEW_FADE_IN_DURATION, { ease: FlxEase.quartOut, onComplete: function(_) { + changingAlpha = false; // Wait to fade out. new FlxTimer().start(PREVIEW_FADE_OUT_DELAY, function(_) { + changingAlpha = true; // Fade out. - FlxTween.tween(previewBitmap, {alpha: 0.0, y: 10}, PREVIEW_FADE_OUT_DURATION, + FlxTween.tween(previewSprite, {alpha: 0.0, y: 10}, PREVIEW_FADE_OUT_DURATION, { ease: FlxEase.quartInOut, onComplete: function(_) { - FlxG.stage.removeChild(previewBitmap); + if (wasMouseHidden) + { + Cursor.hide(); + } + + previewSprite.removeEventListener(MouseEvent.MOUSE_DOWN, openScreenshotsFolder); + previewSprite.removeEventListener(MouseEvent.MOUSE_OVER, onHover); + previewSprite.removeEventListener(MouseEvent.MOUSE_OUT, onHoverOut); + + FlxG.stage.removeChild(previewSprite); } }); }); @@ -214,6 +258,11 @@ class ScreenshotPlugin extends FlxBasic }); } + function openScreenshotsFolder(e:MouseEvent):Void + { + FileUtil.openFolder(SCREENSHOT_FOLDER); + } + static function getCurrentState():FlxState { var state = FlxG.state;