more selection fixes
[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
9         public class EntityUI {
10
11                 protected var sprites:Array=new Array();                // instances in display list
12         protected var listenSprite:Sprite;                              // clickable sprite to receive events
13                 protected var stateClasses:Object=new Object(); // special context-sensitive classes, e.g. :hover
14                 protected var layer:int=0;                                              // map layer
15                 public var map:Map;                                                             // reference to parent map
16
17                 protected const FILLSPRITE:uint=0;
18                 protected const CASINGSPRITE:uint=1;
19                 protected const STROKESPRITE:uint=2;
20                 protected const NAMESPRITE:uint=3;
21                 protected const NODESPRITE:uint=4;
22                 protected const CLICKSPRITE:uint=5;
23
24                 public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
25                         embedFonts: true,
26                         antiAliasType: AntiAliasType.ADVANCED,
27                         gridFitType: GridFitType.NONE
28                 };
29
30                 public function EntityUI() {
31                 }
32
33                 // Add object (stroke/fill/roadname) to layer sprite
34                 
35                 protected function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
36                         var l:DisplayObject=Map(map).getChildAt(map.WAYSPRITE+layer);
37                         var o:DisplayObject=Sprite(l).getChildAt(t);
38                         if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
39                         Sprite(o).addChild(s);
40                         sprites.push(s);
41             if ( s is Sprite ) {
42                 Sprite(s).mouseEnabled = false;
43                 Sprite(s).mouseChildren = false;
44             }
45                 }
46                 
47                 public function removeSprites():void {
48                         while (sprites.length>0) {
49                                 var d:DisplayObject=sprites.pop();
50                                 if (d.parent) { d.parent.removeChild(d); }
51                         }
52                 }
53
54                 protected function createListenSprite(hitzone:Sprite):void {
55             if ( listenSprite == null ) {
56                 listenSprite = new Sprite();
57                 listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent);
58                 listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
59                 listenSprite.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent);
60                 listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent);
61                 listenSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent);
62                 listenSprite.addEventListener(MouseEvent.MOUSE_UP, mouseEvent);
63                 listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
64             }
65             listenSprite.hitArea = hitzone;
66             addToLayer(listenSprite, CLICKSPRITE);
67             listenSprite.buttonMode = true;
68             listenSprite.mouseEnabled = true;
69                 }
70
71         protected function mouseEvent(event:MouseEvent):void {
72         }
73
74         public function setHighlight(stateType:String, isOn:*):void {
75             if ( isOn && stateClasses[stateType] == null ) {
76                 stateClasses[stateType] = isOn;
77             } else if ( !isOn && stateClasses[stateType] != null ) {
78                 delete stateClasses[stateType];
79             }
80         }
81
82         }
83
84 }