fix some layering issues
authorRichard Fairhurst <richard@systemed.net>
Mon, 4 Oct 2010 12:56:32 +0000 (12:56 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 4 Oct 2010 12:56:32 +0000 (12:56 +0000)
net/systemeD/halcyon/Elastic.as
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/potlatch2/controller/DrawWay.as

index a3b6190..2cd8ad9 100755 (executable)
@@ -62,7 +62,7 @@ package net.systemeD.halcyon {
                        var stroke:Shape = new Shape();
             stroke.graphics.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
 
-                       var l:DisplayObject=map.paint.getChildAt(map.paint.maxlayer-map.paint.minlayer);
+                       var l:DisplayObject=map.paint.getPaintSpriteAt(map.paint.maxlayer);
                        var o:DisplayObject=Sprite(l).getChildAt(3);    // names layer
                        (o as Sprite).addChild(stroke);
                        sprites.push(stroke);
index 30b5f89..a6d6b45 100644 (file)
@@ -28,8 +28,8 @@ package net.systemeD.halcyon {
                protected const CASINGSPRITE:uint=1;
                protected const STROKESPRITE:uint=2;
                protected const NAMESPRITE:uint=3;
-               protected const WAYCLICKSPRITE:uint=4;
-               protected const NODECLICKSPRITE:uint=5;
+               protected const WAYCLICKSPRITE:uint=0;
+               protected const NODECLICKSPRITE:uint=1;
 
                public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
                        embedFonts: true,
@@ -97,21 +97,38 @@ package net.systemeD.halcyon {
                // Add object (stroke/fill/roadname) to layer sprite
                
                protected function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
-                       var l:DisplayObject, o:Sprite;
+                       var l:Sprite, o:Sprite;
                        if (sublayer!=-1) {
                                o=paint.sublayer(layer,sublayer);
                        } else {
-                               l=paint.getChildAt(layer-paint.minlayer);
-                               o=(l as Sprite).getChildAt(t) as Sprite;
+                               l=paint.getPaintSpriteAt(layer);
+                               o=l.getChildAt(t) as Sprite;
                        }
                        o.addChild(s);
-                       sprites.push(s);
+                       if (sprites.indexOf(s)==-1) { sprites.push(s); }
             if ( s is Sprite ) {
                 Sprite(s).mouseChildren = false;
                 Sprite(s).mouseEnabled = false;
             }
                }
 
+               protected function setListenSprite(hitzone:Sprite):void {
+                       var l:Sprite=paint.getHitSpriteAt(layer);
+                       var s:Sprite;
+                       if (entity is Way) { s=l.getChildAt(0) as Sprite; }
+                                     else { s=l.getChildAt(1) as Sprite; }
+                       
+                       if (hitzone) {
+                               if (!listenSprite.parent) { s.addChild(listenSprite); if (sprites.indexOf(listenSprite)==-1) { sprites.push(listenSprite); } }
+                               if (!hitzone.parent)      { s.addChild(hitzone     ); if (sprites.indexOf(hitzone     )==-1) { sprites.push(hitzone     ); } }
+                               listenSprite.hitArea = hitzone;
+                               listenSprite.buttonMode = true;
+                               listenSprite.mouseChildren = true;
+                               listenSprite.mouseEnabled = true;
+                       } else if (listenSprite.parent) { 
+                               listenSprite.parent.removeChild(listenSprite);
+                       }
+               }
 
                public function removeSprites():void {
                        while (sprites.length>0) {
@@ -127,18 +144,6 @@ package net.systemeD.halcyon {
                        }
                }
 
-               protected function setListenSprite(spriteContainer:uint, hitzone:Sprite):void {
-                       if (hitzone) {
-                               if (!listenSprite.parent) { addToLayer(listenSprite, spriteContainer); }
-                   listenSprite.hitArea = hitzone;
-                   listenSprite.buttonMode = true;
-                   listenSprite.mouseChildren = true;
-                   listenSprite.mouseEnabled = true;
-                       } else {
-                               if (listenSprite.parent) { listenSprite.parent.removeChild(listenSprite); }
-                       }
-               }
-
         public function setHighlight(settings:Object):void {
                        var changed:Boolean=false;
                        for (var stateType:String in settings) {
index 7b0d2fa..ab36a73 100755 (executable)
@@ -73,11 +73,6 @@ package net.systemeD.halcyon {
                
                public var connection:Connection;                               // server connection
                public var vectorlayers:Object={};                              // VectorLayer objects 
-
-               public const TILESPRITE:uint=0;
-               public const VECTORSPRITE:uint=1;
-               public const WAYSPRITE:uint=2;
-               public const NAMESPRITE:uint=13;
                
                // ------------------------------------------------------------------------------------------
                // Map constructor function
index 8b1faf0..5dfb344 100644 (file)
@@ -23,30 +23,43 @@ package net.systemeD.halcyon {
                private const VERYBIG:Number=Math.pow(2,16);
 
                // Set up layering
-               // [layer][3]                   - names
-               // [layer][2][sublayer] - stroke
-               // [layer][1]                   - casing
-               // [layer][0]                   - fill
 
                public function MapPaint(map:Map,minlayer:int,maxlayer:int) {
+                       mouseEnabled=false;
+
                        this.map=map;
                        this.minlayer=minlayer;
                        this.maxlayer=maxlayer;
                        sublayerIndex[1]=0;
+                       var s:Sprite, l:int;
 
-                       for (var l:int=minlayer; l<=maxlayer; l++) {    // each layer (10 is +5, 0 is -5)
-                               var s:Sprite = getHitSprite();                  //  |
+                       // Add paint sprites
+                       for (l=minlayer; l<=maxlayer; l++) {                    // each layer (10 is +5, 0 is -5)
+                               s = getPaintSprite();                                           //  |
                                s.addChild(getPaintSprite());                           //      | 0 fill
                                s.addChild(getPaintSprite());                           //      | 1 casing
                                var t:Sprite = getPaintSprite();                        //  | 2 stroke
                                t.addChild(getPaintSprite());                           //  |  | sublayer
                                s.addChild(t);                                                          //  |  |
                                s.addChild(getPaintSprite());                           //      | 3 names
-                               s.addChild(getHitSprite());                                     //      | 4 way hit tests
-                               s.addChild(getHitSprite());                                 //  | 5 node hit tests
                                addChild(s);                                                            //  |
                        }
-                       addChild(getPaintSprite());                                     // name sprite
+                       
+                       // Add hit sprites
+                       for (l=minlayer; l<=maxlayer; l++) {                    // each layer (21 is +5, 11 is -5)
+                               s = getHitSprite();                                                     //  |
+                               s.addChild(getHitSprite());                                     //      | 0 way hit tests
+                               s.addChild(getHitSprite());                                 //  | 1 node hit tests
+                               addChild(s);
+                       }
+               }
+               
+               public function getPaintSpriteAt(l:int):Sprite {
+                       return getChildAt(l-minlayer) as Sprite;
+               }
+
+               public function getHitSpriteAt(l:int):Sprite {
+                       return getChildAt((l-minlayer) + (maxlayer-minlayer+1)) as Sprite;
                }
                
                public function get ready():Boolean {
index 96e980d..fb825b6 100644 (file)
@@ -151,9 +151,8 @@ package net.systemeD.halcyon {
             hitzone.graphics.lineStyle(4, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
                        hitzone.graphics.beginFill(0);
                        hitzone.graphics.drawRect(0,0,w,w);
-            addToLayer(hitzone, NODECLICKSPRITE);
-            hitzone.visible = false;
-                       setListenSprite(NODECLICKSPRITE, hitzone);
+                       hitzone.visible = false;
+                       setListenSprite(hitzone);
                }
 
                private function loadedIcon(event:Event):void {
index 560e078..f38f6ba 100755 (executable)
@@ -302,9 +302,8 @@ package net.systemeD.halcyon {
                    hitzone = new Sprite();
                    hitzone.graphics.lineStyle(maxwidth, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
                    solidLines(hitzone.graphics,[]);
-                   addToLayer(hitzone, WAYCLICKSPRITE);
                    hitzone.visible = false;
-                               setListenSprite(WAYCLICKSPRITE, hitzone);
+                               setListenSprite(hitzone);
                        }
 
                        return true;
index 2d78f8b..f02492d 100644 (file)
@@ -168,13 +168,14 @@ package net.systemeD.potlatch2.controller {
                }
                
                protected function keyExitDrawing():ControllerState {
+                       var cs:ControllerState=stopDrawing();
                        if (selectedWay.length==1) { 
                                if (MainUndoStack.getGlobalStack().undoIfAction(BeginWayAction)) { 
                                        return new NoSelection();
                                }
                                return deleteWay();
                        }
-                       return stopDrawing();
+                       return cs;
                }
                
                protected function stopDrawing():ControllerState {
@@ -183,17 +184,11 @@ package net.systemeD.potlatch2.controller {
                                hoverEntity = null;
                        }
 
-                       if ( false ) {
-                               controller.map.setHighlightOnNodes(selectedWay, { selectedway: false });
-                               selectedWay.remove(MainUndoStack.getGlobalStack().addAction);
-                               // delete controller.map.ways[selectedWay.id];
-                               return new NoSelection();
-                       } else if ( leaveNodeSelected ) {
+                       if ( leaveNodeSelected ) {
                            return new SelectedWayNode(selectedWay, editEnd ? selectedWay.length - 1 : 0);
                        } else {
                            return new SelectedWay(selectedWay);
                        }
-                       return this;
                }
 
                public function createAndAddNode(event:MouseEvent, performAction:Function):Node {