home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 161 / MOBICLIC161.ISO / pc / DATA / DSS161 / DSS161_02 / DSS161_02.swf / scripts / dss161 / DragDropSituation.as < prev    next >
Text File  |  2014-01-15  |  14KB  |  409 lines

  1. package dss161
  2. {
  3.    import com.milanpresse.engine.cursor.NativeCursor;
  4.    import com.milanpresse.tools.GlobalesFunctions;
  5.    import dss161.engineaddons.facades.GameEngine;
  6.    import dss161.engineaddons.gamesprotos.Actor;
  7.    import dss161.engineaddons.gamesprotos.actors.actorClip.ActorClip;
  8.    import flash.display.DisplayObject;
  9.    import flash.display.Sprite;
  10.    import flash.display.StageScaleMode;
  11.    import flash.events.Event;
  12.    import flash.geom.Point;
  13.    import flash.geom.Rectangle;
  14.    import flash.ui.Mouse;
  15.    
  16.    public dynamic class DragDropSituation extends Actor
  17.    {
  18.        
  19.       
  20.       private var dragMCPattern:String = "OBJ_##";
  21.       
  22.       private var dragMCFirstNo:int = 1;
  23.       
  24.       private var dragMCLastNo:int = 999;
  25.       
  26.       private var targetMCPattern:String = "ZONE_##";
  27.       
  28.       private var targetMCFirstNo:int = 1;
  29.       
  30.       private var targetMCLastNo:int = 999;
  31.       
  32.       public var limites:Rectangle = null;
  33.       
  34.       public var typeCollision:String = "auto";
  35.       
  36.       public var paramsCollision = null;
  37.       
  38.       public var cursorPosMode:String = "0x0";
  39.       
  40.       public var onDragRollOver:Object;
  41.       
  42.       public var onDragRollOverOnTarget:Object;
  43.       
  44.       public var onDragRollOut:Object;
  45.       
  46.       public var onDragClick:Object;
  47.       
  48.       public var onTargetsClick:Object;
  49.       
  50.       public var onTargetsRollOver:Object;
  51.       
  52.       public var onTargetsRollOut:Object;
  53.       
  54.       public var onDrag:Function;
  55.       
  56.       public var onDrop:Function;
  57.       
  58.       public var container:ActorClip;
  59.       
  60.       public var dragActors:Array;
  61.       
  62.       public var targetActors:Array;
  63.       
  64.       public var dragClips:Object;
  65.       
  66.       public var targetClips:Object;
  67.       
  68.       public var cursor;
  69.       
  70.       public var cursorSize:Point;
  71.       
  72.       public var onDragEvent:Function;
  73.       
  74.       private var pt_temp:Point;
  75.       
  76.       public function DragDropSituation(param1:Object)
  77.       {
  78.          var _loc2_:* = null;
  79.          var _loc3_:int = 0;
  80.          var _loc4_:int = 0;
  81.          var _loc5_:DisplayObject = null;
  82.          this.onDragRollOver = {
  83.             "label":"",
  84.             "noiseCode":""
  85.          };
  86.          this.onDragRollOverOnTarget = {
  87.             "label":"",
  88.             "noiseCode":""
  89.          };
  90.          this.onDragRollOut = {"label":""};
  91.          this.onDragClick = {"label":""};
  92.          this.onTargetsClick = {"label":""};
  93.          this.onTargetsRollOver = {
  94.             "label":"",
  95.             "noiseCode":""
  96.          };
  97.          this.onTargetsRollOut = {"label":""};
  98.          this.onDrag = function(param1:*):void
  99.          {
  100.          };
  101.          this.onDrop = function(param1:*):void
  102.          {
  103.          };
  104.          this.dragActors = [];
  105.          this.targetActors = [];
  106.          this.targetClips = {};
  107.          this.cursor = new NativeCursor.mainF();
  108.          this.onDragEvent = function(param1:*):void
  109.          {
  110.          };
  111.          super(game);
  112.          this.limites = param1.limites;
  113.          this.cursorSize = new Point(this.cursor.width,this.cursor.height);
  114.          for(_loc2_ in param1)
  115.          {
  116.             this[_loc2_] = param1[_loc2_];
  117.          }
  118.          if(param1.dragClips.clips != undefined)
  119.          {
  120.             _loc3_ = 0;
  121.             while(_loc3_ < param1.dragClips.clips.length)
  122.             {
  123.                this.dragActors.push(this.dragMCInit(param1.dragClips.clips[_loc3_],_loc3_));
  124.                _loc3_++;
  125.             }
  126.          }
  127.          else
  128.          {
  129.             _loc4_ = this.dragClips.numeros[0];
  130.             while(_loc4_ <= this.dragClips.numeros[1])
  131.             {
  132.                if((_loc5_ = this.container.getChildByName(this.dragClips.pattern.replace("##",GlobalesFunctions.gimme2digits(_loc4_)).replace("#",_loc4_))) != null)
  133.                {
  134.                   this.dragActors.push(this.dragMCInit(_loc5_,_loc4_));
  135.                }
  136.                _loc4_++;
  137.             }
  138.          }
  139.          if(this.targetClips.clips != undefined)
  140.          {
  141.             _loc3_ = 0;
  142.             while(_loc3_ < this.targetClips.clips.length)
  143.             {
  144.                this.targetActors.push(this.targetMCInit(param1.targetClips.clips[_loc3_],_loc3_));
  145.                _loc3_++;
  146.             }
  147.          }
  148.          else if(this.targetClips.pattern != undefined)
  149.          {
  150.             _loc4_ = this.targetClips.numeros[0];
  151.             while(_loc4_ <= this.targetClips.numeros[1])
  152.             {
  153.                if((_loc5_ = this.container.getChildByName(this.targetClips.pattern.replace("##",GlobalesFunctions.gimme2digits(_loc4_)).replace("#",_loc4_))) != null)
  154.                {
  155.                   this.targetActors.push(this.targetMCInit(_loc5_,_loc4_));
  156.                }
  157.                _loc4_++;
  158.             }
  159.          }
  160.       }
  161.       
  162.       public static function create(param1:GameEngine, param2:*) : DragDropSituation
  163.       {
  164.          return new DragDropSituation(param2);
  165.       }
  166.       
  167.       private function dragMCInit(param1:DisplayObject, param2:int) : ActorClip
  168.       {
  169.          var _loc4_:* = null;
  170.          var _loc3_:Object = {};
  171.          for(_loc4_ in this.dragClips.onRollOverState)
  172.          {
  173.             _loc3_[_loc4_] = this.dragClips.onRollOverState[_loc4_];
  174.          }
  175.          if(_loc3_.noiseCode != undefined)
  176.          {
  177.             _loc3_.noiseCode = _loc3_.noiseCode.replace("##",GlobalesFunctions.gimme2digits(param2)).replace("#",param2);
  178.          }
  179.          if(_loc3_.ibId != undefined)
  180.          {
  181.             _loc3_.ibId = _loc3_.ibId.replace("##",GlobalesFunctions.gimme2digits(param2)).replace("#",param2);
  182.          }
  183.          var _loc5_:ActorClip = addActor({
  184.             "mc":param1,
  185.             "no":param2,
  186.             "onRollOverState":_loc3_,
  187.             "onRollOutState":this.dragClips.onRollOutState,
  188.             "onClickState":this.dragClips.onClickState,
  189.             "dragEnabled":true,
  190.             "onClick":this.onClickHandler,
  191.             "onRollOver":this.onRollOverHandler,
  192.             "onRollOut":this.onRollOutHandler,
  193.             "onDrag":this.onDragHandler,
  194.             "onDrop":this.onDropHandler,
  195.             "enabled":true
  196.          });
  197.          _loc5_.dragDrop.dropTargets = this.targetActors;
  198.          _loc5_.setCollision(this.typeCollision,this.paramsCollision);
  199.          _loc5_.limitZone = this.limites == null ? null : this.limites;
  200.          return _loc5_;
  201.       }
  202.       
  203.       public function getWindowSize() : Rectangle
  204.       {
  205.          var _loc1_:String = game.stage.scaleMode;
  206.          game.stage.scaleMode = StageScaleMode.NO_SCALE;
  207.          var _loc2_:Rectangle = new Rectangle(0,0,stage.stageWidth,stage.stageHeight);
  208.          game.stage.scaleMode = _loc1_;
  209.          return _loc2_;
  210.       }
  211.       
  212.       private function onClickHandler(param1:ActorClip) : void
  213.       {
  214.          var _loc4_:DisplayObject = null;
  215.          var _loc5_:Point = null;
  216.          if(game.engine.pad != null)
  217.          {
  218.             game.engine.pad.activated = false;
  219.          }
  220.          Mouse.hide();
  221.          this.dragActorsDisable();
  222.          var _loc2_:Rectangle = this.getWindowSize();
  223.          var _loc3_:Number = Math.min(_loc2_.width / 800,_loc2_.height / 600);
  224.          this.cursor.scaleX = this.cursor.scaleY = game.stage.scaleMode == StageScaleMode.NO_SCALE ? 1 : 1 / _loc3_;
  225.          this.cursor.scaleX = this.cursor.scaleY = this.cursor.scaleY / param1.clip.scaleY;
  226.          switch(this.cursorPosMode)
  227.          {
  228.             case "none":
  229.                _loc4_ = param1.getChildByName("REP_CENTER2");
  230.                if(_loc4_ == null)
  231.                {
  232.                   _loc4_ = param1.clip.addChild(new Sprite());
  233.                   _loc4_.name = "REP_CENTER2";
  234.                }
  235.                _loc5_ = param1.clip.globalToLocal(new Point(game.stage.mouseX,game.stage.mouseY));
  236.                _loc4_.x = _loc5_.x;
  237.                _loc4_.y = _loc5_.y;
  238.                this.cursor.x = _loc4_.x - this.cursor.width / 2;
  239.                this.cursor.y = _loc4_.y - this.cursor.height / 2;
  240.                param1.repereDragName = "REP_CENTER2";
  241.                break;
  242.             case "0x0":
  243.                _loc4_ = param1.getChildByName("REP_CENTER");
  244.                if(_loc4_ == null)
  245.                {
  246.                   this.cursor.x = -this.cursor.width / 2;
  247.                   this.cursor.y = -this.cursor.height / 2;
  248.                }
  249.                else
  250.                {
  251.                   this.cursor.x = _loc4_.x - this.cursor.width / 2;
  252.                   this.cursor.y = _loc4_.y - this.cursor.height / 2;
  253.                }
  254.                param1.repereDragName = "REP_CENTER";
  255.          }
  256.          param1.clip.addChild(this.cursor);
  257.          param1.bringToFront();
  258.          this.onDragEvent({
  259.             "actor":param1,
  260.             "action":"dragClipClick"
  261.          });
  262.       }
  263.       
  264.       private function onRollOverHandler(param1:ActorClip) : void
  265.       {
  266.          game.changeCursor("mainO");
  267.          this.onDragEvent({
  268.             "actor":param1,
  269.             "action":"dragClipRollOver",
  270.             "targetHited":param1.dragDrop.dropTarget
  271.          });
  272.       }
  273.       
  274.       private function onRollOutHandler(param1:ActorClip) : void
  275.       {
  276.          game.changeCursor("auto");
  277.          this.onDragEvent({
  278.             "actor":param1,
  279.             "action":"dragClipRollOut",
  280.             "targetHited":param1.dragDrop.dropTarget
  281.          });
  282.       }
  283.       
  284.       private function dragActorsDisable() : void
  285.       {
  286.          var _loc1_:int = 0;
  287.          while(_loc1_ < this.dragActors.length)
  288.          {
  289.             this.dragActors[_loc1_].enabled = false;
  290.             _loc1_++;
  291.          }
  292.       }
  293.       
  294.       private function dragActorsEnable() : void
  295.       {
  296.          var _loc1_:int = 0;
  297.          while(_loc1_ < this.dragActors.length)
  298.          {
  299.             this.dragActors[_loc1_].enabled = this.dragActors[_loc1_].blocked == true ? false : true;
  300.             _loc1_++;
  301.          }
  302.       }
  303.       
  304.       private function onDragHandler(param1:ActorClip) : void
  305.       {
  306.          param1.setToPos(game.stage.mouseX,game.stage.mouseY,param1.repereDragName);
  307.          var _loc2_:int = 0;
  308.          while(_loc2_ < param1.dragDrop.dropTargets.length)
  309.          {
  310.             if(param1.dragDrop.dropTargets[_loc2_] == param1.dragDrop.dropTarget)
  311.             {
  312.                if(this.targetClips.onDragOverState != undefined && this.targetClips.onDragOverState.label)
  313.                {
  314.                   if(param1.dragDrop.dropTargets[_loc2_].currentLabel != this.targetClips.onDragOverState.label)
  315.                   {
  316.                      param1.dragDrop.dropTargets[_loc2_].gotoAndStop(this.targetClips.onDragOverState.label);
  317.                   }
  318.                }
  319.             }
  320.             else if(this.targetClips.onDragOutState != undefined && this.targetClips.onDragOutState.label)
  321.             {
  322.                if(param1.dragDrop.dropTargets[_loc2_].currentLabel != this.targetClips.onDragOutState.label)
  323.                {
  324.                   param1.dragDrop.dropTargets[_loc2_].gotoAndStop(this.targetClips.onDragOutState.label);
  325.                }
  326.             }
  327.             _loc2_++;
  328.          }
  329.          this.onDragEvent({
  330.             "actor":param1,
  331.             "action":"dragging",
  332.             "targetHited":param1.dragDrop.dropTarget
  333.          });
  334.       }
  335.       
  336.       private function onDropHandler(param1:ActorClip) : void
  337.       {
  338.          param1.clip.removeChild(this.cursor);
  339.          game.ibHide();
  340.          if(game.engine.pad != null)
  341.          {
  342.             game.engine.pad.activated = true;
  343.          }
  344.          this.onDragEvent({
  345.             "actor":param1,
  346.             "action":"drop",
  347.             "targetHited":param1.dragDrop.dropTarget
  348.          });
  349.          if(param1.clip != null && param1.enabled && param1.clip.hitTestPoint(game.stage.mouseX,game.stage.mouseY,true))
  350.          {
  351.             game.changeCursor("auto");
  352.             Mouse.show();
  353.          }
  354.          else
  355.          {
  356.             game.changeCursor("auto");
  357.             Mouse.show();
  358.          }
  359.          this.dragActorsEnable();
  360.       }
  361.       
  362.       private function onMouseShowEnterFrameHandler(param1:Event) : void
  363.       {
  364.          param1.currentTarget.removeEventListener(Event.ENTER_FRAME,this.onMouseShowEnterFrameHandler);
  365.          Mouse.show();
  366.       }
  367.       
  368.       private function targetMCInit(param1:DisplayObject, param2:int) : ActorClip
  369.       {
  370.          return addActor({
  371.             "mc":param1,
  372.             "no":param2,
  373.             "onRollOverState":this.targetClips.onRollOverState,
  374.             "onRollOutState":this.targetClips.onRollOutState,
  375.             "onClickState":this.targetClips.onClickState,
  376.             "onClick":this.onTargetClickHandler,
  377.             "onRollOver":this.onTargetRollOverHandler,
  378.             "onRollOut":this.onTargetRollOutHandler,
  379.             "enabled":false
  380.          });
  381.       }
  382.       
  383.       private function onTargetClickHandler(param1:ActorClip) : void
  384.       {
  385.       }
  386.       
  387.       private function onTargetRollOverHandler(param1:ActorClip) : void
  388.       {
  389.       }
  390.       
  391.       private function onTargetRollOutHandler(param1:ActorClip) : void
  392.       {
  393.       }
  394.       
  395.       override protected function _destroy() : void
  396.       {
  397.          game.stage.removeEventListener(Event.ENTER_FRAME,this.onMouseShowEnterFrameHandler);
  398.          this.dragActors.length = 0;
  399.          this.targetActors.length = 0;
  400.          this.onDrag = null;
  401.          this.onDrop = null;
  402.          this.onDragEvent = null;
  403.          this.targetClips = null;
  404.          this.dragClips = null;
  405.          super._destroy();
  406.       }
  407.    }
  408. }
  409.