SAVE YOUR FUCKING WORK, DUDES
authorRichard Fairhurst <richard@systemeD.net>
Sun, 19 Jun 2011 09:52:39 +0000 (10:52 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 19 Jun 2011 09:52:39 +0000 (10:52 +0100)
potlatch2.mxml

index 4754b11..0c3e996 100644 (file)
                import mx.managers.PopUpManager;
                import flash.system.Security;
                import flash.net.*;
+               import flash.utils.Timer;
+               import flash.events.TimerEvent;
                import flash.events.MouseEvent;
                import flash.display.Sprite;
                import mx.core.IChildList;
 
                private var savecount:uint=0;
                private var loadcount:uint=0;
+               private var saveLabel:String='Save';
+               private var saveTimer:Timer;
 
         include "version.as";
 
                        Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
                        Globals.vars.flashvars = loaderInfo.parameters;
 
+                       // Remember localised Save text, because we change this dynamically
+                       saveLabel=saveButton.label;
+
                        // populate sharedObject with loaderInfo parameters if supplied
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        var objChanged:Boolean = false;
             if (ExternalInterface.available) {
               ExternalInterface.call("markChanged", false);
             }
+                       if (!saveTimer || !saveTimer.running) {
+                               saveTimer=new Timer(60*1000,0);
+                               saveTimer.addEventListener(TimerEvent.TIMER,saveTimeUpdate);
+                               saveTimer.start();
+                       }
                }
                private function onDataClean(event:Event):void {
                        saveButton.enabled=false;
             if (ExternalInterface.available) {
               ExternalInterface.call("markChanged", true);
             }
+            if (saveTimer && saveTimer.running) {
+                               saveTimer.stop();
+                               saveTimer.removeEventListener(TimerEvent.TIMER,saveTimeUpdate);
+                               saveTimeWrite(0);
+                       }
+               }
+               private function saveTimeUpdate(event:TimerEvent):void {
+                       var timer:Timer=Timer(event.target);
+                       saveTimeWrite(uint(timer.delay*timer.currentCount/1000/60));
+               }
+               private function saveTimeWrite(minutes:uint):void {
+                       if (minutes<5) {
+                               saveButton.label=saveLabel;
+                       } else {
+                               saveButton.label=saveLabel+" ("+minutes+"m"+")"; 
+                               if (minutes>=20 && minutes/5==int(minutes/5)) {
+                                       theController.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, minutes+"m since last save - please save regularly"));
+                               }
+                       }
                }
-               
-
 
                private function scaleHandler(event:MapEvent):void {
                        dispatchEvent(new Event("rescale"));