| 1 | package elements.menu {
|
|---|
| 2 |
|
|---|
| 3 | import flash.display.Sprite;
|
|---|
| 4 | import flash.events.MouseEvent;
|
|---|
| 5 | import elements.menu.menuItem;
|
|---|
| 6 | import caurina.transitions.Tweener;
|
|---|
| 7 | import caurina.transitions.Equations;
|
|---|
| 8 | import string.Utils;
|
|---|
| 9 | import flash.filters.DropShadowFilter;
|
|---|
| 10 |
|
|---|
| 11 | public class Menu extends Sprite {
|
|---|
| 12 |
|
|---|
| 13 | private var original_alpha:Number;
|
|---|
| 14 | private var props:Properties;
|
|---|
| 15 | private var first_showing:Boolean;
|
|---|
| 16 | private var hidden_pos:Number;
|
|---|
| 17 |
|
|---|
| 18 | public function Menu( chartID:String, json:Object ) {
|
|---|
| 19 |
|
|---|
| 20 | this.props = new DefaultMenuProperties(json);
|
|---|
| 21 |
|
|---|
| 22 | this.original_alpha = 0.4;
|
|---|
| 23 | this.alpha = 1;
|
|---|
| 24 |
|
|---|
| 25 | var pos:Number = 5;
|
|---|
| 26 | var height:Number = 0;
|
|---|
| 27 | this.first_showing = true;
|
|---|
| 28 |
|
|---|
| 29 | for each ( var val:Object in json.values )
|
|---|
| 30 | {
|
|---|
| 31 | var tmp:DefaultCameraIconProperties = new DefaultCameraIconProperties(val);
|
|---|
| 32 | var menu_item:menuItem = menu_item_factory.make(chartID, tmp);
|
|---|
| 33 | menu_item.x = 5;
|
|---|
| 34 | menu_item.y = pos;
|
|---|
| 35 | this.addChild(menu_item);
|
|---|
| 36 | height = menu_item.y + menu_item.height + 5;
|
|---|
| 37 | pos += menu_item.height + 5;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | var width:Number = 0;
|
|---|
| 41 |
|
|---|
| 42 | for ( var i:Number = 0; i < this.numChildren; i++ )
|
|---|
| 43 | width = Math.max( width, this.getChildAt(i).width );
|
|---|
| 44 |
|
|---|
| 45 | this.draw(width+10, height);
|
|---|
| 46 | this.hidden_pos = height;
|
|---|
| 47 |
|
|---|
| 48 | /*
|
|---|
| 49 | var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
|
|---|
| 50 | dropShadow.blurX = 4;
|
|---|
| 51 | dropShadow.blurY = 4;
|
|---|
| 52 | dropShadow.distance = 4;
|
|---|
| 53 | dropShadow.angle = 45;
|
|---|
| 54 | dropShadow.quality = 2;
|
|---|
| 55 | dropShadow.alpha = 0.5;
|
|---|
| 56 | // apply shadow filter
|
|---|
| 57 | this.filters = [dropShadow];
|
|---|
| 58 | */
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
|
|---|
| 62 | this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | private function draw(width:Number, height:Number): void {
|
|---|
| 66 |
|
|---|
| 67 | this.graphics.clear();
|
|---|
| 68 |
|
|---|
| 69 | var colour:Number = string.Utils.get_colour( this.props.get('colour') );
|
|---|
| 70 | var o_colour:Number = string.Utils.get_colour( this.props.get('outline-colour') );
|
|---|
| 71 |
|
|---|
| 72 | this.graphics.lineStyle( 1, o_colour );
|
|---|
| 73 | this.graphics.beginFill(colour, 1);
|
|---|
| 74 | this.graphics.moveTo( 0, -2 );
|
|---|
| 75 | this.graphics.lineTo( 0, height );
|
|---|
| 76 | this.graphics.lineTo( width-25, height );
|
|---|
| 77 | this.graphics.lineTo( width-20, height+10 );
|
|---|
| 78 | this.graphics.lineTo( width, height+10 );
|
|---|
| 79 | this.graphics.lineTo( width, -2 );
|
|---|
| 80 | this.graphics.endFill();
|
|---|
| 81 |
|
|---|
| 82 | // arrows
|
|---|
| 83 | this.graphics.lineStyle( 1, o_colour );
|
|---|
| 84 | this.graphics.moveTo( width-15, height+3 );
|
|---|
| 85 | this.graphics.lineTo( width-10, height+8 );
|
|---|
| 86 | this.graphics.lineTo( width-5, height+3 );
|
|---|
| 87 |
|
|---|
| 88 | this.graphics.moveTo( width-15, height );
|
|---|
| 89 | this.graphics.lineTo( width-10, height+5 );
|
|---|
| 90 | this.graphics.lineTo( width-5, height );
|
|---|
| 91 |
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | public function mouseOverHandler(event:MouseEvent):void {
|
|---|
| 95 | Tweener.removeTweens(this);
|
|---|
| 96 | Tweener.addTween(this, { y:0, time:0.4, transition:Equations.easeOutBounce } );
|
|---|
| 97 | Tweener.addTween(this, { alpha:1, time:0.4, transition:Equations.easeOutBounce } );
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | public function mouseOutHandler(event:MouseEvent):void {
|
|---|
| 101 | this.hide_menu();
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | private function hide_menu(): void
|
|---|
| 105 | {
|
|---|
| 106 | Tweener.removeTweens(this);
|
|---|
| 107 | Tweener.addTween(this, { y:-this.hidden_pos, time:0.4, transition:Equations.easeOutBounce } );
|
|---|
| 108 | Tweener.addTween(this, { alpha:this.original_alpha, time:0.4, transition:Equations.easeOutBounce } );
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | public function resize(): void {
|
|---|
| 112 |
|
|---|
| 113 | if ( this.first_showing ) {
|
|---|
| 114 | this.y = 0;
|
|---|
| 115 | this.first_showing = false;
|
|---|
| 116 | Tweener.removeTweens(this);
|
|---|
| 117 | Tweener.addTween(this, { time:3, onComplete:this.hide_menu } );
|
|---|
| 118 | }
|
|---|
| 119 | else {
|
|---|
| 120 | this.y = -(this.height) + 10;
|
|---|
| 121 | }
|
|---|
| 122 | this.x = this.stage.stageWidth - this.width - 5;
|
|---|
| 123 |
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|