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