From b3e349d099beb9c403080d85cee899f4bc3cb87b Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Fri, 4 Feb 2011 09:14:15 -0800 Subject: [PATCH] esc to quit to menu --- src/Token.as | 5 +++++ src/WorldMenu.as | 2 +- src/WorldStage.as | 30 +++++++++++++++++++++++++++++- todo.txt | 6 +++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Token.as b/src/Token.as index 77a614b..774b51f 100644 --- a/src/Token.as +++ b/src/Token.as @@ -37,6 +37,10 @@ package else this.xml = xml; } + public function FDirty():Boolean + { + return int(xml.@x) !== posReal.x || int(xml.@y) !== posReal.y; + } public function FSelected(): Boolean { return WorldStage(this.world).tokSelected === this; @@ -142,6 +146,7 @@ package xml.@x = int(posReal.x); xml.@y = int(posReal.y); xml.@path = urff; + this.xml = xml; return xml; } } diff --git a/src/WorldMenu.as b/src/WorldMenu.as index 38c36ca..36f99df 100644 --- a/src/WorldMenu.as +++ b/src/WorldMenu.as @@ -71,7 +71,7 @@ package { var file: File = new File(File.userDirectory.nativePath + File.separator + "NewStage.xml"); file.addEventListener(Event.SELECT, function():void { - FP.world = new WorldStage(file.url); + FP.world = new WorldStage(file.url, function():World { return new WorldMenu(); }); }); return file; diff --git a/src/WorldStage.as b/src/WorldStage.as index ff4327c..277a8bc 100644 --- a/src/WorldStage.as +++ b/src/WorldStage.as @@ -59,6 +59,7 @@ package public static const LAYER_MSG: int = 70; public static const LAYER_OFFSTAGE: int = 1000; + private var dgWorldPrev: Function; private var imgdir: Imgdir; private var dragView: Drag; private var urff: String; @@ -75,9 +76,11 @@ package public var pointView: Point; public var uabd: String; - public function WorldStage(uabf: String) + public function WorldStage(uabf: String, dgWorldPrev: Function) { super(); + this.dgWorldPrev = dgWorldPrev; + var match:* = /(.*\/)([^\/]*)$/.exec(uabf); this.uabd = match[1]; this.urff = match[2]; @@ -221,6 +224,7 @@ package // I've passed the stage in my programming career where I would happily spend a few months designing a generic GUI library in // response to this problem and consequently forget about my original goal; there are a few other projects doing that for me + private var fForceQuit:Boolean = false; override public function update():void { if (Input.mouseUp && dragView !== null) @@ -260,6 +264,30 @@ package if (Input.pressed(Key.TAB)) ToggleUI(); + if (Input.pressed(Key.ESCAPE)) + { + var fDirty:Boolean = false; + if (!fForceQuit) + { + var rgtok: Array = []; + getLayer(LAYER_TOKENS, rgtok); + for each (var tok:Token in rgtok) + { + if (tok.FDirty()) + { + fDirty = true; + break; + } + } + } + if (fDirty && !fForceQuit) + { + fForceQuit = true; + ShowMsg("Unsaved! Press ESC again to confirm.", function() { fForceQuit = false; }); + } + else + FP.world = dgWorldPrev(); + } if (Input.mouseWheel) { diff --git a/todo.txt b/todo.txt index 0aebfc1..fd7a823 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,12 @@ - decide on a license -- create a readme - push to github +- JSON output? +- fixed-sized factories - finalize "library" notion - text objects - UI refactoring? +- put it into a package - tilemap - layers @@ -15,3 +17,5 @@ DONE: - zoom to 100% (magnifying glass icon?) - show 0,0, maybe some other griddy options - fix scrollwheel sensitivity +- create a readme +- quit to menu \ No newline at end of file