home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / HexiomConnect.swf / scripts / Input.as < prev    next >
Text File  |  2008-08-29  |  11KB  |  410 lines

  1. package
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.KeyboardEvent;
  6.    import flash.events.MouseEvent;
  7.    import flash.ui.Keyboard;
  8.    
  9.    public class Input
  10.    {
  11.       
  12.       public static const NO_KEYCODE:uint = 258;
  13.       
  14.       private static var down:Array = new Array();
  15.       
  16.       private static var released:Array = new Array();
  17.       
  18.       private static var keyCount:uint = 0;
  19.       
  20.       public static const UNDO_KEY:uint = keyCount++ * 2;
  21.       
  22.       public static const CLEAR_SELECTION_KEY:uint = keyCount++ * 2;
  23.       
  24.       public static const CHAT_KEY:uint = keyCount++ * 2;
  25.       
  26.       public static const NEXT_CHARACTER_KEY:uint = keyCount++ * 2;
  27.       
  28.       public static const DEFEND_KEY:uint = keyCount++ * 2;
  29.       
  30.       public static const NUM_KEYS:uint = keyCount * 2;
  31.       
  32.       public static const DOWN_KEY:uint = keyCount++ * 2;
  33.       
  34.       public static const UP_KEY:uint = keyCount++ * 2;
  35.       
  36.       public static const SELF_ABILITY_KEY:uint = keyCount++ * 2;
  37.       
  38.       public static const TRANSPARENT_GUI_KEY:uint = keyCount++ * 2;
  39.       
  40.       public static const LEFT_KEY:uint = keyCount++ * 2;
  41.       
  42.       public static const CLOSEST_CHARACTER_KEY:uint = keyCount++ * 2;
  43.       
  44.       public static const MOUSE_KEYCODE:uint = 257;
  45.       
  46.       private static var keys:Array = new Array();
  47.       
  48.       public static const RIGHT_KEY:uint = keyCount++ * 2;
  49.       
  50.       public static const VIEW_FORTRESS_KEY:uint = keyCount++ * 2;
  51.        
  52.       
  53.       public function Input()
  54.       {
  55.          super();
  56.       }
  57.       
  58.       public static function flush() : void
  59.       {
  60.          var _loc1_:int = 0;
  61.          while(_loc1_ < NUM_KEYS)
  62.          {
  63.             down[keys[_loc1_]] = false;
  64.             released[keys[_loc1_]] = true;
  65.             _loc1_++;
  66.          }
  67.       }
  68.       
  69.       public static function newPress(param1:int) : Boolean
  70.       {
  71.          return down[keys[param1]] && released[keys[param1]] || down[keys[param1 + 1]] && released[keys[param1 + 1]];
  72.       }
  73.       
  74.       public static function getSecondaryBindString(param1:uint) : String
  75.       {
  76.          return getCharString(keys[param1 + 1]);
  77.       }
  78.       
  79.       public static function init(param1:Stage) : Boolean
  80.       {
  81.          defaults();
  82.          flush();
  83.          if(!param1)
  84.          {
  85.             return false;
  86.          }
  87.          param1.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
  88.          param1.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
  89.          param1.addEventListener(Event.MOUSE_LEAVE,mouseLeave);
  90.          param1.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
  91.          param1.addEventListener(KeyboardEvent.KEY_UP,keyUp);
  92.          return true;
  93.       }
  94.       
  95.       public static function mouseLeave(param1:Event) : void
  96.       {
  97.          var _loc2_:int = 0;
  98.          while(_loc2_ < NUM_KEYS)
  99.          {
  100.             down[keys[_loc2_]] = false;
  101.             released[keys[_loc2_]] = true;
  102.             _loc2_++;
  103.          }
  104.       }
  105.       
  106.       public static function getPrimaryBindString(param1:uint) : String
  107.       {
  108.          return getCharString(keys[param1]);
  109.       }
  110.       
  111.       public static function mouseUp(param1:MouseEvent) : void
  112.       {
  113.          down[MOUSE_KEYCODE] = false;
  114.          released[MOUSE_KEYCODE] = true;
  115.       }
  116.       
  117.       public static function keyDown(param1:KeyboardEvent) : void
  118.       {
  119.          var _loc2_:uint = param1.keyCode;
  120.          down[_loc2_] = true;
  121.       }
  122.       
  123.       public static function setBind(param1:int, param2:Boolean, param3:uint) : void
  124.       {
  125.          if(param2)
  126.          {
  127.             keys[param1] = param3;
  128.          }
  129.          else
  130.          {
  131.             keys[param1 + 1] = param3;
  132.          }
  133.       }
  134.       
  135.       public static function bindString(param1:uint) : String
  136.       {
  137.          var _loc2_:String = getPrimaryBindString(param1);
  138.          if(_loc2_ != "")
  139.          {
  140.             return _loc2_;
  141.          }
  142.          _loc2_ = getSecondaryBindString(param1);
  143.          if(_loc2_ != "")
  144.          {
  145.             return _loc2_;
  146.          }
  147.          return "No-Key-Set";
  148.       }
  149.       
  150.       public static function update() : void
  151.       {
  152.          var _loc1_:int = 0;
  153.          while(_loc1_ < NUM_KEYS)
  154.          {
  155.             released[keys[_loc1_]] = !down[keys[_loc1_]];
  156.             _loc1_++;
  157.          }
  158.       }
  159.       
  160.       public static function defaults() : void
  161.       {
  162.          var _loc1_:uint = 0;
  163.          while(_loc1_ < NUM_KEYS)
  164.          {
  165.             keys[_loc1_] = NO_KEYCODE;
  166.             _loc1_++;
  167.          }
  168.          keys[LEFT_KEY] = 65;
  169.          keys[LEFT_KEY + 1] = Keyboard.LEFT;
  170.          keys[RIGHT_KEY] = 68;
  171.          keys[RIGHT_KEY + 1] = Keyboard.RIGHT;
  172.          keys[UP_KEY] = 87;
  173.          keys[UP_KEY + 1] = Keyboard.UP;
  174.          keys[DOWN_KEY] = 83;
  175.          keys[DOWN_KEY + 1] = Keyboard.DOWN;
  176.          keys[UNDO_KEY] = 82;
  177.          keys[UNDO_KEY + 1] = Keyboard.BACKSPACE;
  178.          keys[CLEAR_SELECTION_KEY] = Keyboard.ESCAPE;
  179.          keys[NEXT_CHARACTER_KEY] = Keyboard.TAB;
  180.          keys[CLOSEST_CHARACTER_KEY] = 67;
  181.          keys[VIEW_FORTRESS_KEY] = 70;
  182.          keys[VIEW_FORTRESS_KEY + 1] = Keyboard.HOME;
  183.          keys[SELF_ABILITY_KEY] = 49;
  184.          keys[SELF_ABILITY_KEY + 1] = 96;
  185.          keys[DEFEND_KEY] = Keyboard.SPACE;
  186.          keys[DEFEND_KEY + 1] = Keyboard.END;
  187.          keys[CHAT_KEY] = Keyboard.ENTER;
  188.          keys[TRANSPARENT_GUI_KEY] = Keyboard.CONTROL;
  189.       }
  190.       
  191.       public static function keyUp(param1:KeyboardEvent) : void
  192.       {
  193.          var _loc2_:uint = param1.keyCode;
  194.          down[_loc2_] = false;
  195.          released[_loc2_] = true;
  196.       }
  197.       
  198.       public static function mouseDown(param1:MouseEvent) : void
  199.       {
  200.          down[MOUSE_KEYCODE] = true;
  201.       }
  202.       
  203.       public static function isDown(param1:int) : Boolean
  204.       {
  205.          return down[keys[param1]] || down[keys[param1 + 1]];
  206.       }
  207.       
  208.       public static function getCharString(param1:uint) : String
  209.       {
  210.          switch(param1)
  211.          {
  212.             case NO_KEYCODE:
  213.                return "";
  214.             case MOUSE_KEYCODE:
  215.                return "Mouse Button";
  216.             case 65:
  217.                return "A";
  218.             case 66:
  219.                return "B";
  220.             case 67:
  221.                return "C";
  222.             case 68:
  223.                return "D";
  224.             case 69:
  225.                return "E";
  226.             case 70:
  227.                return "F";
  228.             case 71:
  229.                return "G";
  230.             case 72:
  231.                return "H";
  232.             case 73:
  233.                return "I";
  234.             case 74:
  235.                return "J";
  236.             case 75:
  237.                return "K";
  238.             case 76:
  239.                return "L";
  240.             case 77:
  241.                return "M";
  242.             case 78:
  243.                return "N";
  244.             case 79:
  245.                return "O";
  246.             case 80:
  247.                return "P";
  248.             case 81:
  249.                return "Q";
  250.             case 82:
  251.                return "R";
  252.             case 83:
  253.                return "S";
  254.             case 84:
  255.                return "T";
  256.             case 85:
  257.                return "U";
  258.             case 86:
  259.                return "V";
  260.             case 87:
  261.                return "W";
  262.             case 88:
  263.                return "X";
  264.             case 89:
  265.                return "Y";
  266.             case 90:
  267.                return "Z";
  268.             case 27:
  269.                return "Esc";
  270.             case 112:
  271.                return "F1";
  272.             case 113:
  273.                return "F2";
  274.             case 114:
  275.                return "F3";
  276.             case 115:
  277.                return "F4";
  278.             case 116:
  279.                return "F5";
  280.             case 117:
  281.                return "F6";
  282.             case 118:
  283.                return "F7";
  284.             case 119:
  285.                return "F8";
  286.             case 120:
  287.                return "F9";
  288.             case 122:
  289.                return "F11";
  290.             case 123:
  291.                return "F12";
  292.             case 145:
  293.                return "Scroll Lock";
  294.             case 19:
  295.                return "Pause";
  296.             case 192:
  297.                return "`";
  298.             case 49:
  299.                return "1";
  300.             case 50:
  301.                return "2";
  302.             case 51:
  303.                return "3";
  304.             case 52:
  305.                return "4";
  306.             case 53:
  307.                return "5";
  308.             case 54:
  309.                return "6";
  310.             case 55:
  311.                return "7";
  312.             case 56:
  313.                return "8";
  314.             case 57:
  315.                return "9";
  316.             case 48:
  317.                return "0";
  318.             case 189:
  319.                return "-";
  320.             case 187:
  321.                return "=";
  322.             case 8:
  323.                return "Backspace";
  324.             case 9:
  325.                return "Tab";
  326.             case 20:
  327.                return "Caps Lock";
  328.             case 16:
  329.                return "Shift";
  330.             case 17:
  331.                return "Control";
  332.             case 32:
  333.                return "Space";
  334.             case 13:
  335.                return "Enter";
  336.             case 220:
  337.                return "\\";
  338.             case 37:
  339.                return "Left";
  340.             case 39:
  341.                return "Right";
  342.             case 38:
  343.                return "Up";
  344.             case 40:
  345.                return "Down";
  346.             case 45:
  347.                return "Insert";
  348.             case 46:
  349.                return "Del";
  350.             case 36:
  351.                return "Home";
  352.             case 35:
  353.                return "End";
  354.             case 33:
  355.                return "Page Up";
  356.             case 34:
  357.                return "Page Down";
  358.             case 144:
  359.                return "Num Lock";
  360.             case 96:
  361.                return "Numpad Ins";
  362.             case 97:
  363.                return "Numpad 1";
  364.             case 98:
  365.                return "Numpad 2";
  366.             case 99:
  367.                return "Numpad 3";
  368.             case 100:
  369.                return "Numpad 4";
  370.             case 101:
  371.                return "Numpad 5";
  372.             case 102:
  373.                return "Numpad 6";
  374.             case 103:
  375.                return "Numpad 7";
  376.             case 104:
  377.                return "Numpad 8";
  378.             case 105:
  379.                return "Numpad 9";
  380.             case 106:
  381.                return "Numpad *";
  382.             case 107:
  383.                return "Numpad +";
  384.             case 109:
  385.                return "Numpad -";
  386.             case 110:
  387.                return "Numpad Del";
  388.             case 111:
  389.                return "Numpad /";
  390.             case 219:
  391.                return "[";
  392.             case 221:
  393.                return "]";
  394.             case 186:
  395.                return ";";
  396.             case 222:
  397.                return "\'";
  398.             case 188:
  399.                return "<";
  400.             case 190:
  401.                return ">";
  402.             case 191:
  403.                return "/";
  404.             default:
  405.                return "";
  406.          }
  407.       }
  408.    }
  409. }
  410.