1 package net.systemeD.potlatch2 {
2 import net.systemeD.halcyon.Map;
3 import net.systemeD.halcyon.MapController;
4 import net.systemeD.halcyon.connection.*;
5 import net.systemeD.potlatch2.controller.*;
6 import mx.managers.CursorManager;
10 public class EditController implements MapController {
13 public var tagViewer:TagViewer;
14 private var toolbox:Toolbox;
16 public var state:ControllerState;
17 private var _connection:Connection;
19 private var keys:Object={};
20 public var clipboards:Object={};
21 public var imagery:Array=[];
22 public var imagerySelected:Object={};
23 public var stylesheets:Array=[];
24 public var cursorsEnabled:Boolean=true;
26 [Embed(source="../../../embedded/pen.png")] public var pen:Class;
27 [Embed(source="../../../embedded/pen_x.png")] public var pen_x:Class;
28 [Embed(source="../../../embedded/pen_o.png")] public var pen_o:Class;
29 [Embed(source="../../../embedded/pen_so.png")] public var pen_so:Class;
30 [Embed(source="../../../embedded/pen_plus.png")] public var pen_plus:Class;
32 public function EditController(map:Map, tagViewer:TagViewer, toolbox:Toolbox) {
34 this.tagViewer = tagViewer;
35 this.toolbox = toolbox;
36 this.toolbox.init(this);
37 setState(new NoSelection());
39 map.parent.addEventListener(MouseEvent.MOUSE_MOVE, mapMouseEvent);
40 map.parent.addEventListener(MouseEvent.MOUSE_UP, mapMouseEvent);
41 map.parent.addEventListener(MouseEvent.MOUSE_DOWN, mapMouseEvent);
42 map.parent.addEventListener(MouseEvent.MOUSE_WHEEL, mapMouseEvent);
43 map.parent.addEventListener(MouseEvent.CLICK, mapMouseEvent);
44 map.parent.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
45 map.parent.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
48 public function setActive():void {
49 map.setController(this);
50 _connection = map.connection;
53 public function get map():Map {
57 public function get connection():Connection {
61 public function updateSelectionUI():void {
62 tagViewer.setEntity(state.selection);
63 toolbox.updateSelectionUI();
66 private function keyDownHandler(event:KeyboardEvent):void {
67 keys[event.keyCode]=true;
70 private function keyUpHandler(event:KeyboardEvent):void {
71 trace("key code "+event.keyCode);
72 if (keys[event.keyCode]) { delete keys[event.keyCode]; }
73 var newState:ControllerState = state.processKeyboardEvent(event);
77 public function keyDown(key:Number):Boolean {
78 return Boolean(keys[key]);
81 private function mapMouseEvent(event:MouseEvent):void {
82 if (event.type!=MouseEvent.ROLL_OVER) map.stage.focus = map.parent;
83 if (event.type==MouseEvent.MOUSE_UP && map.dragstate==map.DRAGGING) { return; }
85 var mapLoc:Point = map.globalToLocal(new Point(event.stageX, event.stageY));
86 event.localX = mapLoc.x;
87 event.localY = mapLoc.y;
89 var newState:ControllerState = state.processMouseEvent(event, null);
93 public function entityMouseEvent(event:MouseEvent, entity:Entity):void {
94 if (event.type!=MouseEvent.ROLL_OVER) map.stage.focus = map.parent;
95 //if ( event.type == MouseEvent.MOUSE_DOWN )
96 event.stopPropagation();
98 var mapLoc:Point = map.globalToLocal(new Point(event.stageX, event.stageY));
99 event.localX = mapLoc.x;
100 event.localY = mapLoc.y;
102 var newState:ControllerState = state.processMouseEvent(event, entity);
106 public function setState(newState:ControllerState):void {
107 if ( newState == state )
111 state.exitState(newState);
112 newState.setController(this);
113 newState.setPreviousState(state);
118 public function setCursor(cursor:Class):void {
119 CursorManager.removeAllCursors();
120 if (cursor && cursorsEnabled) { CursorManager.setCursor(cursor,2,-4,0); }