fix horrid merge bug (yay!). Implement suspend/resume events for redrawing, to speed...
[potlatch2.git] / net / systemeD / halcyon / EntityUI.as
index 1cfb1bf7fd32f5b4f727ae28ed145ddc168e7197..284fe9c5515d72c78aa6c0e62be5c2b878cc2fcc 100644 (file)
@@ -4,6 +4,9 @@ package net.systemeD.halcyon {
        import flash.events.MouseEvent;
        import flash.text.AntiAliasType;
        import flash.text.GridFitType;
+       import net.systemeD.halcyon.Globals;
+       import net.systemeD.halcyon.styleparser.StyleList;
+    import net.systemeD.halcyon.connection.EntityEvent;
 
        public class EntityUI {
 
@@ -11,6 +14,9 @@ package net.systemeD.halcyon {
         protected var listenSprite:Sprite;                             // clickable sprite to receive events
                protected var stateClasses:Object=new Object(); // special context-sensitive classes, e.g. :hover
                protected var layer:int=0;                                              // map layer
+               protected var suspended:Boolean=false;                  // suspend redrawing?
+               protected var redrawDue:Boolean=false;                  // redraw called while suspended?
+               protected var redrawStyleList:StyleList;                // stylelist to be used when redrawing?
                public var map:Map;                                                             // reference to parent map
 
                protected const FILLSPRITE:uint=0;
@@ -45,8 +51,10 @@ package net.systemeD.halcyon {
                
                public function removeSprites():void {
                        while (sprites.length>0) {
-                               var d:DisplayObject=sprites.pop(); d.parent.removeChild(d);
+                               var d:DisplayObject=sprites.pop();
+                               if (d.parent) { d.parent.removeChild(d); }
                        }
+                       listenSprite=null;
                }
 
                protected function createListenSprite(hitzone:Sprite):void {
@@ -69,14 +77,47 @@ package net.systemeD.halcyon {
         protected function mouseEvent(event:MouseEvent):void {
         }
 
-        public function setHighlight(stateType:String, isOn:Boolean):void {
+        public function setHighlight(stateType:String, isOn:*):void {
             if ( isOn && stateClasses[stateType] == null ) {
-                stateClasses[stateType] = true;
+                stateClasses[stateType] = isOn;
             } else if ( !isOn && stateClasses[stateType] != null ) {
                 delete stateClasses[stateType];
             }
         }
 
+               protected function applyStateClasses(tags:Object):Object {
+            for (var stateKey:String in stateClasses) {
+                tags[":"+stateKey] = 'yes';
+            }
+                       return tags;
+               }
+               
+               // Redraw control
+               
+               public function redraw(sl:StyleList=null):Boolean {
+                       if (suspended) { redrawStyleList=sl; redrawDue=true; return false; }
+                       return doRedraw(sl);
+               }
+               
+               public function doRedraw(sl:StyleList):Boolean {
+                       // to be overwritten
+                       return false;
+               }
+               
+               public function suspendRedraw(event:EntityEvent):void {
+                       suspended=true;
+                       redrawDue=false;
+               }
+               
+               public function resumeRedraw(event:EntityEvent):void {
+                       suspended=false;
+                       if (redrawDue) { 
+                               doRedraw(redrawStyleList);
+                               redrawDue=false;
+                               redrawStyleList=null; 
+                       }
+               }
+
        }
 
 }