home *** CD-ROM | disk | FTP | other *** search
- class com.neodelight.std.Inputs
- {
- static var hookMc;
- static var vMouseA;
- static var vMouseVMax;
- static var vMouseXMin;
- static var vMouseXMax;
- static var vMouseYMin;
- static var vMouseYMax;
- static var inputs = new Object();
- static var listeners = new Array();
- static var locked = false;
- static var vKeysDown = new Object();
- static var vKeysReset = new Array();
- static var vMouse = false;
- static var vMouseKeys = new Object();
- static var vMousePos = new com.neodelight.std.Vector();
- static var vMouseV = new com.neodelight.std.Vector(0,0);
- static var vMouseReal = new com.neodelight.std.Vector();
- static var inited = false;
- static var KEY_BACKSPACE = 8;
- static var KEY_CAPSLOCK = 20;
- static var KEY_CONTROL = 17;
- static var KEY_DELETEKEY = 46;
- static var KEY_DOWN = 40;
- static var KEY_END = 35;
- static var KEY_ENTER = 13;
- static var KEY_ESCAPE = 27;
- static var KEY_HOME = 36;
- static var KEY_INSERT = 45;
- static var KEY_LEFT = 37;
- static var KEY_PGDN = 34;
- static var KEY_PGUP = 33;
- static var KEY_RIGHT = 39;
- static var KEY_SHIFT = 16;
- static var KEY_SPACE = 32;
- static var KEY_TAB = 9;
- static var KEY_UP = 38;
- static var JOY_UP = 400;
- static var JOY_DOWN = 401;
- static var JOY_LEFT = 402;
- static var JOY_RIGHT = 403;
- static var JOY_BUTTON0 = 404;
- static var JOY_BUTTON1 = 405;
- static var MOUSE_BUTTON = 406;
- function Inputs()
- {
- }
- static function init()
- {
- if(!com.neodelight.std.Inputs.inited)
- {
- com.neodelight.std.Inputs.inited = true;
- var _loc6_ = com.neodelight.std.Blueprint.getBlueprint("inputs");
- if(_loc6_)
- {
- var _loc3_ = _loc6_.inputsKeys;
- if(_loc3_)
- {
- var _loc2_ = _loc3_.length;
- while(true)
- {
- _loc2_;
- if(!_loc2_--)
- {
- break;
- }
- com.neodelight.std.Inputs.define(_loc3_[_loc2_][0],_loc3_[_loc2_][1]);
- }
- }
- }
- Mouse.addListener(com.neodelight.std.Inputs);
- }
- if(!com.neodelight.std.Inputs.hookMc)
- {
- var _loc0_ = null;
- var _loc5_ = com.neodelight.std.Inputs.hookMc = _root.createEmptyMovieClip(com.neodelight.std.Unique.getKey(),_root.getNextHighestDepth());
- _loc5_.onEnterFrame = function()
- {
- com.neodelight.std.Inputs.updateInputs();
- if(com.neodelight.std.Inputs.isDown("mouse_click"))
- {
- com.neodelight.std.Inputs.hookMc.onMouseDown();
- }
- if(com.neodelight.std.Inputs.isTriggeredUp("mouse_click"))
- {
- com.neodelight.std.Inputs.hookMc.onMouseUp();
- }
- };
- _loc5_.onMouseDown = function()
- {
- var _loc2_ = com.neodelight.std.Inputs.listeners;
- var _loc1_ = _loc2_.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- if(_loc2_[_loc1_].onVMouseDown)
- {
- _loc2_[_loc1_].onVMouseDown();
- }
- }
- };
- _loc5_.onMouseUp = function()
- {
- var _loc2_ = com.neodelight.std.Inputs.listeners;
- var _loc1_ = _loc2_.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- if(_loc2_[_loc1_].onVMouseUp)
- {
- _loc2_[_loc1_].onVMouseUp();
- }
- }
- };
- }
- }
- static function define(id, key)
- {
- com.neodelight.std.Inputs.init();
- trace("define: \"" + key + "\" as \"" + id + "\"");
- switch(typeof key)
- {
- case "string":
- var _loc2_ = String(key).length;
- while(true)
- {
- _loc2_;
- if(!_loc2_--)
- {
- break;
- }
- com.neodelight.std.Inputs.define(id,String(key).charCodeAt(_loc2_));
- }
- break;
- case "number":
- if(!com.neodelight.std.Inputs.inputs[id])
- {
- com.neodelight.std.Inputs.inputs[id] = {isDown:false,triggerDown:false,triggerUp:false,keys:new Array()};
- }
- com.neodelight.std.Inputs.inputs[id].keys.push(key);
- break;
- default:
- _global.bin.syslog("Inputs","define(): unknown variable type: " + typeof key,2);
- }
- }
- static function setVirtual(id, isDown)
- {
- com.neodelight.std.Inputs.vKeysDown[id] = isDown;
- }
- static function triggerVirtual(id, sustain)
- {
- com.neodelight.std.Inputs.vKeysDown[id] = true;
- com.neodelight.std.Inputs.vKeysReset.push({id:id,sustain:int(sustain)});
- }
- static function addListener(listener)
- {
- com.neodelight.std.Inputs.init();
- var _loc2_ = com.neodelight.std.Inputs.listeners;
- var _loc3_ = false;
- var _loc1_ = _loc2_.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- if(_loc2_[_loc1_] == listener)
- {
- _loc3_ = true;
- break;
- }
- }
- if(!_loc3_)
- {
- _loc2_.push(listener);
- }
- }
- static function removeListener(listener)
- {
- var _loc2_ = com.neodelight.std.Inputs.listeners;
- var _loc4_ = false;
- var _loc1_ = _loc2_.length;
- while(true)
- {
- _loc1_;
- if(!_loc1_--)
- {
- break;
- }
- if(_loc2_[_loc1_] == listener)
- {
- _loc2_.splice(_loc1_,1);
- break;
- }
- }
- }
- static function updateInputs()
- {
- var _loc9_ = com.neodelight.std.Inputs.inputs;
- var _loc7_ = com.neodelight.std.Inputs.vKeysReset;
- var _loc8_ = com.neodelight.std.Inputs.vKeysDown;
- for(var _loc10_ in _loc9_)
- {
- var _loc3_ = _loc9_[_loc10_];
- var _loc2_ = false;
- var _loc5_ = _loc3_.keys;
- var _loc4_ = _loc5_.length;
- while(true)
- {
- _loc4_;
- if(!_loc4_--)
- {
- break;
- }
- var _loc1_ = _loc5_[_loc4_];
- if(_loc1_ < 256)
- {
- if(Key.isDown(_loc1_))
- {
- _loc2_ = true;
- break;
- }
- }
- else if(_loc8_[_loc1_])
- {
- _loc2_ = true;
- break;
- }
- }
- _loc3_.triggerDown = !_loc3_.isDown && _loc2_;
- _loc3_.triggerUp = _loc3_.isDown && !_loc2_;
- _loc3_.isDown = _loc2_;
- }
- var _loc6_ = _loc7_.length;
- while(true)
- {
- _loc6_;
- if(!_loc6_--)
- {
- break;
- }
- if(--_loc7_[_loc6_].sustain <= 0)
- {
- _loc8_[Number(_loc7_[_loc6_].id)] = false;
- _loc7_.splice(_loc6_,1);
- }
- }
- }
- static function isDown(id)
- {
- return !com.neodelight.std.Inputs.locked && com.neodelight.std.Inputs.inputs[id].isDown;
- }
- static function isTriggeredDown(id)
- {
- return !com.neodelight.std.Inputs.locked && com.neodelight.std.Inputs.inputs[id].triggerDown;
- }
- static function isTriggeredUp(id)
- {
- return !com.neodelight.std.Inputs.locked && com.neodelight.std.Inputs.inputs[id].triggerUp;
- }
- static function getMousePos(mc)
- {
- var _loc6_ = undefined;
- if(com.neodelight.std.Inputs.vMouse)
- {
- var _loc2_ = com.neodelight.std.Inputs.vMouseV;
- var _loc3_ = com.neodelight.std.Inputs.vMousePos;
- var _loc4_ = com.neodelight.std.Inputs.vMouseReal;
- if(_loc4_.x != int(_root._xmouse) || _loc4_.y != int(_root._ymouse))
- {
- _loc4_.x = _loc3_.x = int(_root._xmouse);
- _loc4_.y = _loc3_.y = int(_root._ymouse);
- }
- else
- {
- if(com.neodelight.std.Inputs.isDown("mouse_right"))
- {
- _loc2_.x = Math.max(0,_loc2_.x + com.neodelight.std.Inputs.vMouseA);
- }
- else if(com.neodelight.std.Inputs.isDown("mouse_left"))
- {
- _loc2_.x = Math.min(0,_loc2_.x - com.neodelight.std.Inputs.vMouseA);
- }
- else
- {
- _loc2_.x = 0;
- }
- if(com.neodelight.std.Inputs.isDown("mouse_down"))
- {
- _loc2_.y = Math.max(0,_loc2_.y + com.neodelight.std.Inputs.vMouseA);
- }
- else if(com.neodelight.std.Inputs.isDown("mouse_up"))
- {
- _loc2_.y = Math.min(0,_loc2_.y - com.neodelight.std.Inputs.vMouseA);
- }
- else
- {
- _loc2_.y = 0;
- }
- if(_loc2_.x != 0 || _loc2_.y != 0)
- {
- var _loc5_ = Math.min(com.neodelight.std.Inputs.vMouseVMax,Math.max(Math.abs(_loc2_.x),Math.abs(_loc2_.y)));
- if(_loc2_.x != 0)
- {
- if(_loc2_.x > 0)
- {
- _loc2_.x = _loc5_;
- }
- else
- {
- _loc2_.x = _loc5_ * -1;
- }
- }
- if(_loc2_.y != 0)
- {
- if(_loc2_.y > 0)
- {
- _loc2_.y = _loc5_;
- }
- else
- {
- _loc2_.y = _loc5_ * -1;
- }
- }
- }
- _loc3_.x = Math.max(com.neodelight.std.Inputs.vMouseXMin,Math.min(com.neodelight.std.Inputs.vMouseXMax,_loc3_.x + _loc2_.x));
- _loc3_.y = Math.max(com.neodelight.std.Inputs.vMouseYMin,Math.min(com.neodelight.std.Inputs.vMouseYMax,_loc3_.y + _loc2_.y));
- }
- _loc6_ = new com.neodelight.std.Vector(_loc3_.x,_loc3_.y);
- mc.globalToLocal(_loc6_);
- }
- else
- {
- _loc6_ = new com.neodelight.std.Vector(mc._xmouse,mc._ymouse);
- }
- return _loc6_;
- }
- static function initVMouse(cfg)
- {
- com.neodelight.std.Inputs.vMouseReal.x = com.neodelight.std.Inputs.vMousePos.x = int(_root._xmouse);
- com.neodelight.std.Inputs.vMouseReal.y = com.neodelight.std.Inputs.vMousePos.y = int(_root._ymouse);
- com.neodelight.std.Inputs.vMouseA = !cfg.acc ? 1 : com.neodelight.std.XMath.toNumber(cfg.acc);
- com.neodelight.std.Inputs.vMouseVMax = !cfg.vMax ? 10 : com.neodelight.std.XMath.toNumber(cfg.vMax);
- com.neodelight.std.Inputs.vMouseXMin = !cfg.xMin ? 0 : com.neodelight.std.XMath.toNumber(cfg.xMin);
- com.neodelight.std.Inputs.vMouseXMax = !cfg.xMax ? 550 : com.neodelight.std.XMath.toNumber(cfg.xMax);
- com.neodelight.std.Inputs.vMouseYMin = !cfg.yMin ? 0 : com.neodelight.std.XMath.toNumber(cfg.yMin);
- com.neodelight.std.Inputs.vMouseYMax = !cfg.yMax ? 400 : com.neodelight.std.XMath.toNumber(cfg.yMax);
- com.neodelight.std.Inputs.vMouse = true;
- com.neodelight.std.Inputs.init();
- }
- static function onMouseDown()
- {
- com.neodelight.std.Inputs.setVirtual(com.neodelight.std.Inputs.MOUSE_BUTTON,true);
- }
- static function onMouseUp()
- {
- com.neodelight.std.Inputs.setVirtual(com.neodelight.std.Inputs.MOUSE_BUTTON,false);
- }
- }
-