select and move POI nodes, and a handful of smaller fixes too
[potlatch2.git] / net / systemeD / halcyon / EntityUI.as
1 package net.systemeD.halcyon {
2
3         import flash.display.*;
4         import flash.events.MouseEvent;
5         import flash.text.AntiAliasType;
6         import flash.text.GridFitType;
7         import net.systemeD.halcyon.Globals;
8         import net.systemeD.halcyon.styleparser.StyleList;
9
10         public class EntityUI {
11
12                 protected var sprites:Array=new Array();                // instances in display list
13         protected var listenSprite:Sprite;                              // clickable sprite to receive events
14                 protected var stateClasses:Object=new Object(); // special context-sensitive classes, e.g. :hover
15                 protected var layer:int=0;                                              // map layer
16                 public var map:Map;                                                             // reference to parent map
17
18                 protected const FILLSPRITE:uint=0;
19                 protected const CASINGSPRITE:uint=1;
20                 protected const STROKESPRITE:uint=2;
21                 protected const NAMESPRITE:uint=3;
22                 protected const NODESPRITE:uint=4;
23                 protected const CLICKSPRITE:uint=5;
24
25                 public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
26                         embedFonts: true,
27                         antiAliasType: AntiAliasType.ADVANCED,
28                         gridFitType: GridFitType.NONE
29                 };
30
31                 public function EntityUI() {
32                 }
33
34                 // Add object (stroke/fill/roadname) to layer sprite
35                 
36                 protected function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
37                         var l:DisplayObject=Map(map).getChildAt(map.WAYSPRITE+layer);
38                         var o:DisplayObject=Sprite(l).getChildAt(t);
39                         if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
40                         Sprite(o).addChild(s);
41                         sprites.push(s);
42             if ( s is Sprite ) {
43                 Sprite(s).mouseEnabled = false;
44                 Sprite(s).mouseChildren = false;
45             }
46                 }
47                 
48                 public function removeSprites():void {
49                         while (sprites.length>0) {
50                                 var d:DisplayObject=sprites.pop();
51                                 if (d.parent) { d.parent.removeChild(d); }
52                         }
53                 }
54
55                 protected function createListenSprite(hitzone:Sprite):void {
56             if ( listenSprite == null ) {
57                 listenSprite = new Sprite();
58                 listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent);
59                 listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
60                 listenSprite.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent);
61                 listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent);
62                 listenSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent);
63                 listenSprite.addEventListener(MouseEvent.MOUSE_UP, mouseEvent);
64                 listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
65             }
66             listenSprite.hitArea = hitzone;
67             addToLayer(listenSprite, CLICKSPRITE);
68             listenSprite.buttonMode = true;
69             listenSprite.mouseEnabled = true;
70                 }
71
72         protected function mouseEvent(event:MouseEvent):void {
73         }
74
75         public function setHighlight(stateType:String, isOn:*):void {
76             if ( isOn && stateClasses[stateType] == null ) {
77                 stateClasses[stateType] = isOn;
78             } else if ( !isOn && stateClasses[stateType] != null ) {
79                 delete stateClasses[stateType];
80             }
81         }
82
83                 protected function applyStateClasses(tags:Object):Object {
84             for (var stateKey:String in stateClasses) {
85                 tags[":"+stateKey] = 'yes';
86             }
87                         return tags;
88                 }
89                 
90                 public function redraw(sl:StyleList=null):Boolean {
91                         return false;
92                 }
93
94         }
95
96 }