From 8e9c0a74fc244597817f987cbcd40f283e9aaefa Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Wed, 23 Aug 2023 19:33:51 -0700 Subject: [PATCH] unsaved shit in the chart editor wip --- source/funkin/backend/system/Main.hx | 1 + source/funkin/backend/utils/WindowTitle.hx | 36 ++++++++++++++++++++++ source/funkin/editors/UndoList.hx | 9 ++++++ source/funkin/editors/charter/Charter.hx | 20 +++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 source/funkin/backend/utils/WindowTitle.hx diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index b3efb4d5..fbe59ac1 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -107,6 +107,7 @@ class Main extends Sprite } public static function loadGameSettings() { + WindowTitle.init(); MemoryUtil.init(); @:privateAccess FlxG.game.getTimer = getTimer; diff --git a/source/funkin/backend/utils/WindowTitle.hx b/source/funkin/backend/utils/WindowTitle.hx new file mode 100644 index 00000000..239efa4f --- /dev/null +++ b/source/funkin/backend/utils/WindowTitle.hx @@ -0,0 +1,36 @@ +package funkin.backend.utils; + +import openfl.Lib; + +class WindowTitle { + public static var winTitle(default, set):String; + public static function set_winTitle(newWinTitle:String):String { + winTitle = newWinTitle; + updateTitle(); + return newWinTitle; + } + public static var prefix(default, set):String = ""; + public static function set_prefix(newPrefix:String):String { + prefix = newPrefix; + updateTitle(); + return newPrefix; + } + public static var endfix(default, set):String = ""; + public static function set_endfix(endPrefix:String):String { + endfix = endPrefix; + updateTitle(); + return endPrefix; + } + + public static inline function init() + reset(); + + public static inline function reset() { + winTitle = Lib.application.meta["name"]; + prefix = endfix = ""; + updateTitle(); + } + + public static inline function updateTitle() + Lib.application.window.title = '$prefix$winTitle$endfix'; +} \ No newline at end of file diff --git a/source/funkin/editors/UndoList.hx b/source/funkin/editors/UndoList.hx index b736a992..cefdc12f 100644 --- a/source/funkin/editors/UndoList.hx +++ b/source/funkin/editors/UndoList.hx @@ -4,6 +4,12 @@ class UndoList { public var undoList:Array = []; public var redoList:Array = []; + var savedLength:Int = 0; + + public var unsaved(get, never):Bool; + public inline function get_unsaved():Bool + return undoList.length != savedLength; + public function new() {} public inline function addToUndo(c:T) { @@ -26,4 +32,7 @@ class UndoList { undoList.insert(0, redo); return redo; } + + public inline function save() + savedLength = undoList.length; } \ No newline at end of file diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 2fdacefd..57dd195c 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -97,6 +97,7 @@ class Charter extends UIState { public override function create() { super.create(); + WindowTitle.endfix = " (Chart Editor)"; topMenu = [ { label: "File", @@ -468,6 +469,7 @@ class Charter extends UIState { Framerate.memoryCounter.alpha = 1; Framerate.codenameBuildField.alpha = 1; } + WindowTitle.reset(); super.destroy(); } @@ -961,6 +963,8 @@ class Charter extends UIState { if (charterCamera.zoom != (charterCamera.zoom = lerp(charterCamera.zoom, __camZoom, 0.125))) { updateDisplaySprites(); } + + WindowTitle.prefix = undos.unsaved ? "UNSAVED | " : ""; } public static var startTime:Float = 0; @@ -1016,12 +1020,25 @@ class Charter extends UIState { // TOP MENU OPTIONS #if REGION function _file_exit(_) { - FlxG.switchState(new CharterSelection()); + if (undos.unsaved) { + FlxG.state.openSubState(new UIWarningSubstate("Unsaved Changes", "Your changes will be lost if you don't save them.", [ + { + label: "Exit", + onClick: function(_) FlxG.switchState(new CharterSelection()) + }, + { + label: "Cancel", + onClick: function (_) {} + } + ])); + } else + FlxG.switchState(new CharterSelection()); } function _file_save(_) { #if sys saveTo('${Paths.getAssetsRoot()}/songs/${__song.toLowerCase().replace("-", " ")}'); + undos.save(); return; #end _file_saveas(_); @@ -1031,6 +1048,7 @@ class Charter extends UIState { openSubState(new SaveSubstate(Json.stringify(Chart.filterChartForSaving(PlayState.SONG, false)), { defaultSaveFile: '${__diff.toLowerCase()}.json' })); + undos.save(); } function _file_meta_save(_) {