esc to quit to menu

This commit is contained in:
Jeremy Penner 2011-02-04 09:14:15 -08:00
parent 86e300ba7d
commit b3e349d099
4 changed files with 40 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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)
{

View file

@ -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