Advertisement
Guest User

Untitled

a guest
May 28th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class dofus.managers.KeyManager extends dofus.utils.ApiElement
  2. {
  3.    var _bIsBroadcasting = true;
  4.    var _bPressedKeys = new Array();
  5.    var _bCtrlDown = false;
  6.    var _bShiftDown = true;
  7.    static var _sSelf = null;
  8.    function KeyManager(oAPI)
  9.    {
  10.       super();
  11.       dofus.managers.KeyManager._sSelf = this;
  12.       this.initialize(oAPI);
  13.    }
  14.    function __get__Broadcasting()
  15.    {
  16.       return this._bIsBroadcasting;
  17.    }
  18.    function __set__Broadcasting(bIsBroadcasting)
  19.    {
  20.       this._bIsBroadcasting = bIsBroadcasting;
  21.       return this.__get__Broadcasting();
  22.    }
  23.    static function getInstance()
  24.    {
  25.       return dofus.managers.KeyManager._sSelf;
  26.    }
  27.    function initialize(oAPI)
  28.    {
  29.       super.initialize(oAPI);
  30.       Key.addListener(this);
  31.       this._aAnyTimeShortcuts = new Array();
  32.       this._aNoChatShortcuts = new Array();
  33.       this._so = SharedObject.getLocal(this.api.datacenter.Player.login + dofus.Constants.GLOBAL_SO_SHORTCUTS_NAME);
  34.       this._nCurrentSet = this.api.kernel.OptionsManager.getOption("ShortcutSet");
  35.       this.loadShortcuts();
  36.    }
  37.    function addShortcutsListener(sMethod, oListener)
  38.    {
  39.       if(this._aListening == undefined)
  40.       {
  41.          this._aListening = new Array();
  42.       }
  43.       var _loc4_ = 0;
  44.       while(_loc4_ < this._aListening.length)
  45.       {
  46.          if(String(this._aListening[_loc4_].o) == String(oListener) && this._aListening[_loc4_].m == sMethod)
  47.          {
  48.             this.removeShortcutsListener(this._aListening[_loc4_].o);
  49.          }
  50.          _loc4_ = _loc4_ + 1;
  51.       }
  52.       this._aListening.push({o:oListener,m:sMethod});
  53.    }
  54.    function removeShortcutsListener(oListener)
  55.    {
  56.       if(this._aListening == undefined)
  57.       {
  58.          return undefined;
  59.       }
  60.       var _loc3_ = new Array();
  61.       var _loc4_ = 0;
  62.       while(_loc4_ < this._aListening.length)
  63.       {
  64.          if(this._aListening[_loc4_].o == oListener)
  65.          {
  66.             _loc3_.push(_loc4_);
  67.          }
  68.          _loc4_ = _loc4_ + 1;
  69.       }
  70.       _loc3_.sort(Array.DESCENDING);
  71.       var _loc5_ = 0;
  72.       while(_loc5_ < _loc3_.length)
  73.       {
  74.          this._aListening.splice(_loc3_[_loc5_],1);
  75.          _loc5_ = _loc5_ + 1;
  76.       }
  77.    }
  78.    function addKeysListener(sMethod, oListener)
  79.    {
  80.       if(this._aKeysListening == undefined)
  81.       {
  82.          this._aKeysListening = new Array();
  83.       }
  84.       var _loc4_ = 0;
  85.       while(_loc4_ < this._aKeysListening.length)
  86.       {
  87.          if(String(this._aKeysListening[_loc4_].o) == String(oListener) && this._aKeysListening[_loc4_].m == sMethod)
  88.          {
  89.             this._aKeysListening[_loc4_] = undefined;
  90.          }
  91.          _loc4_ = _loc4_ + 1;
  92.       }
  93.       this._aKeysListening.push({o:oListener,m:sMethod});
  94.    }
  95.    function removeKeysListener(oListener)
  96.    {
  97.       if(this._aKeysListening == undefined)
  98.       {
  99.          return undefined;
  100.       }
  101.       var _loc3_ = new Array();
  102.       var _loc4_ = 0;
  103.       while(_loc4_ < this._aKeysListening.length)
  104.       {
  105.          if(this._aKeysListening[_loc4_].o == oListener)
  106.          {
  107.             _loc3_.push(_loc4_);
  108.          }
  109.          _loc4_ = _loc4_ + 1;
  110.       }
  111.       _loc3_.sort(Array.DESCENDING);
  112.       var _loc5_ = 0;
  113.       while(_loc5_ < _loc3_.length)
  114.       {
  115.          this._aKeysListening.splice(_loc3_[_loc5_],1);
  116.          _loc5_ = _loc5_ + 1;
  117.       }
  118.    }
  119.    function getDefaultShortcut(sShortcut)
  120.    {
  121.       return this.api.lang.getKeyboardShortcutsKeys(this._nCurrentSet,sShortcut);
  122.    }
  123.    function getCurrentShortcut(sShortcut)
  124.    {
  125.       var _loc3_ = new Array();
  126.       var _loc4_ = 0;
  127.       while(_loc4_ < this._aAnyTimeShortcuts.length)
  128.       {
  129.          if(this._aAnyTimeShortcuts[_loc4_].d == sShortcut)
  130.          {
  131.             _loc3_.push({k:this._aAnyTimeShortcuts[_loc4_].k,c:this._aAnyTimeShortcuts[_loc4_].c,d:this._aAnyTimeShortcuts[_loc4_].l});
  132.          }
  133.          _loc4_ = _loc4_ + 1;
  134.       }
  135.       var _loc5_ = 0;
  136.       while(_loc5_ < this._aNoChatShortcuts.length)
  137.       {
  138.          if(this._aNoChatShortcuts[_loc5_].d == sShortcut)
  139.          {
  140.             _loc3_.push({k:this._aNoChatShortcuts[_loc5_].k,c:this._aNoChatShortcuts[_loc5_].c,d:this._aNoChatShortcuts[_loc5_].l});
  141.          }
  142.          _loc5_ = _loc5_ + 1;
  143.       }
  144.       if(_loc3_.length == 1)
  145.       {
  146.          return _loc3_[0];
  147.       }
  148.       if(_loc3_.length == 2)
  149.       {
  150.          return {k:_loc3_[0].k,c:_loc3_[0].c,d:_loc3_[0].d,k2:_loc3_[1].k,c2:_loc3_[1].c,d2:_loc3_[1].d};
  151.       }
  152.       return undefined;
  153.    }
  154.    function clearCustomShortcuts()
  155.    {
  156.       this._so.clear();
  157.       this.loadShortcuts();
  158.    }
  159.    function askCustomShortcut(sShortcut, bIsAlternative)
  160.    {
  161.       this.api.ui.loadUIComponent("AskCustomShortcut","AskCustomShortcut",{title:this.api.lang.getText("SHORTCUTS_CUSTOM"),ShortcutCode:sShortcut,IsAlt:bIsAlternative,Description:this.api.lang.getKeyboardShortcuts()[sShortcut].d});
  162.    }
  163.    function setCustomShortcut(sShortcut, bIsAlternative, nKeyCode, nCtrlCode, sAscii)
  164.    {
  165.       if(sShortcut == undefined || bIsAlternative == undefined)
  166.       {
  167.          return undefined;
  168.       }
  169.       var _loc7_ = sShortcut + (!bIsAlternative?"_MAIN":"_ALT");
  170.       if(nKeyCode == undefined)
  171.       {
  172.          this._so.data[_loc7_] = undefined;
  173.       }
  174.       else
  175.       {
  176.          if(nCtrlCode == undefined)
  177.          {
  178.             nCtrlCode = 0;
  179.          }
  180.          if(sAscii == undefined || sAscii == "")
  181.          {
  182.             sAscii = this.api.lang.getKeyStringFromKeyCode(nKeyCode);
  183.             sAscii = this.api.lang.getControlKeyString(nCtrlCode) + sAscii;
  184.          }
  185.          this._so.data[_loc7_] = {s:sShortcut,a:bIsAlternative,k:nKeyCode,c:nCtrlCode,i:sAscii};
  186.       }
  187.       this.loadShortcuts();
  188.    }
  189.    function getCustomShortcut(sShortcut, bIsAlternative)
  190.    {
  191.       var _loc4_ = sShortcut + (!bIsAlternative?"_MAIN":"_ALT");
  192.       return this._so.data[_loc4_];
  193.    }
  194.    function isCustomShortcut(sShortcut, bIsAlternative)
  195.    {
  196.       return this.getCustomShortcut(sShortcut,bIsAlternative) != undefined;
  197.    }
  198.    function deleteCustomShortcut(sShortcut, bIsAlternative)
  199.    {
  200.       this.setCustomShortcut(sShortcut,bIsAlternative);
  201.    }
  202.    function getCurrentDefaultSet()
  203.    {
  204.       var _loc2_ = Number(this.api.lang.getText("SHORTCUTS_DEFAULT_SET"));
  205.       if(_loc2_ < 1)
  206.       {
  207.          _loc2_ = 1;
  208.       }
  209.       return _loc2_;
  210.    }
  211.    function dispatchCtrlState(bNewCtrlState)
  212.    {
  213.       this.dispatchShortcut(!bNewCtrlState?"CTRL_STATE_CHANGED_OFF":"CTRL_STATE_CHANGED_ON");
  214.    }
  215.    function dispatchShortcut(sShortcut)
  216.    {
  217.       if(!this._bIsBroadcasting)
  218.       {
  219.          return false;
  220.       }
  221.       if(this._aListening == undefined)
  222.       {
  223.          return true;
  224.       }
  225.       var _loc3_ = new Array();
  226.       var _loc4_ = true;
  227.       var _loc5_ = 0;
  228.       while(_loc5_ < this._aListening.length)
  229.       {
  230.          if(this._aListening[_loc5_] == undefined || this._aListening[_loc5_].o == undefined)
  231.          {
  232.             _loc3_.push(_loc5_);
  233.          }
  234.          else
  235.          {
  236.             var _loc6_ = eval(String(this._aListening[_loc5_].o) + "." + this._aListening[_loc5_].m).call(this._aListening[_loc5_].o,sShortcut);
  237.             if(_loc6_ != undefined && _loc6_ == false)
  238.             {
  239.                _loc4_ = false;
  240.                break;
  241.             }
  242.          }
  243.          _loc5_ = _loc5_ + 1;
  244.       }
  245.       _loc3_.sort(Array.DESCENDING);
  246.       var _loc7_ = 0;
  247.       while(_loc7_ < _loc3_.length)
  248.       {
  249.          this._aListening.splice(_loc3_[_loc7_],1);
  250.          _loc7_ = _loc7_ + 1;
  251.       }
  252.       if(_loc4_)
  253.       {
  254.          _loc4_ = this.onShortcut(sShortcut);
  255.       }
  256.       return _loc4_;
  257.    }
  258.    function dispatchKey(sKey)
  259.    {
  260.       if(!this._bIsBroadcasting)
  261.       {
  262.          return undefined;
  263.       }
  264.       if(this._aKeysListening == undefined)
  265.       {
  266.          return undefined;
  267.       }
  268.       sKey = new ank.utils.ExtendedString(sKey).trim().toString();
  269.       if(sKey.length == 0)
  270.       {
  271.          return undefined;
  272.       }
  273.       var _loc3_ = new Array();
  274.       var _loc4_ = 0;
  275.       while(_loc4_ < this._aKeysListening.length)
  276.       {
  277.          if(this._aKeysListening[_loc4_] == undefined || this._aKeysListening[_loc4_].o == undefined)
  278.          {
  279.             _loc3_.push(_loc4_);
  280.          }
  281.          else
  282.          {
  283.             eval(String(this._aKeysListening[_loc4_].o) + "." + this._aKeysListening[_loc4_].m).call(this._aKeysListening[_loc4_].o,sKey);
  284.          }
  285.          _loc4_ = _loc4_ + 1;
  286.       }
  287.       _loc3_.sort(Array.DESCENDING);
  288.       var _loc5_ = 0;
  289.       while(_loc5_ < _loc3_.length)
  290.       {
  291.          this._aKeysListening.splice(_loc3_[_loc5_],1);
  292.          _loc5_ = _loc5_ + 1;
  293.       }
  294.    }
  295.    function loadShortcuts()
  296.    {
  297.       var _loc2_ = this.api.lang.getKeyboardShortcuts();
  298.       this._aNoChatShortcuts = new Array();
  299.       this._aAnyTimeShortcuts = new Array();
  300.       for(var k in _loc2_)
  301.       {
  302.          var _loc3_ = this.api.lang.getKeyboardShortcutsKeys(this._nCurrentSet,k);
  303.          var _loc4_ = this.getCustomShortcut(k,false);
  304.          if(_loc4_ != undefined && !_loc2_[k].s)
  305.          {
  306.             if(_loc3_.o)
  307.             {
  308.                this._aNoChatShortcuts.push({k:_loc4_.k,c:_loc4_.c,o:_loc3_.o,d:k,l:_loc4_.i,s:_loc2_[k].s});
  309.             }
  310.             else
  311.             {
  312.                this._aAnyTimeShortcuts.push({k:_loc4_.k,c:_loc4_.c,o:_loc3_.o,d:k,l:_loc4_.i,s:_loc2_[k].s});
  313.             }
  314.          }
  315.          else if(_loc3_.o)
  316.          {
  317.             this._aNoChatShortcuts.push({k:_loc3_.k,c:_loc3_.c,o:_loc3_.o,d:k,l:_loc3_.s,s:_loc2_[k].s});
  318.          }
  319.          else if(_loc3_.k != undefined)
  320.          {
  321.             this._aAnyTimeShortcuts.push({k:_loc3_.k,c:_loc3_.c,o:_loc3_.o,d:k,l:_loc3_.s,s:_loc2_[k].s});
  322.          }
  323.          var _loc5_ = this.getCustomShortcut(k,true);
  324.          if(_loc5_ != undefined && !_loc2_[k].s)
  325.          {
  326.             if(_loc3_.o)
  327.             {
  328.                this._aNoChatShortcuts.push({k:_loc5_.k,c:_loc5_.c,o:_loc3_.o,d:k,l:_loc5_.i,s:_loc2_[k].s});
  329.             }
  330.             else
  331.             {
  332.                this._aAnyTimeShortcuts.push({k:_loc5_.k,c:_loc5_.c,o:_loc3_.o,d:k,l:_loc5_.i,s:_loc2_[k].s});
  333.             }
  334.          }
  335.          else if(!_global.isNaN(_loc3_.k2) && _loc3_.k2 != undefined)
  336.          {
  337.             if(_loc3_.o)
  338.             {
  339.                this._aNoChatShortcuts.push({k:_loc3_.k2,c:_loc3_.c2,o:_loc3_.o,d:k,l:_loc3_.s2,s:_loc2_[k].s});
  340.             }
  341.             else
  342.             {
  343.                this._aAnyTimeShortcuts.push({k:_loc3_.k2,c:_loc3_.c2,o:_loc3_.o,d:k,l:_loc3_.s2,s:_loc2_[k].s});
  344.             }
  345.          }
  346.       }
  347.       if(this._aNoChatShortcuts.length == 0 && this._aAnyTimeShortcuts.length == 0)
  348.       {
  349.          this._aAnyTimeShortcuts.push({k:38,c:0,o:true,d:"HISTORY_UP"});
  350.          this._aAnyTimeShortcuts.push({k:40,c:0,o:true,d:"HISTORY_DOWN"});
  351.          this._aAnyTimeShortcuts.push({k:13,c:1,o:true,d:"GUILD_MESSAGE"});
  352.          this._aAnyTimeShortcuts.push({k:13,c:0,o:true,d:"ACCEPT_CURRENT_DIALOG"});
  353.          this._aAnyTimeShortcuts.push({k:70,c:1,o:true,d:"FULLSCREEN"});
  354.          var _loc6_ = this.api.lang.getDefaultConsoleShortcuts();
  355.          var _loc7_ = 0;
  356.          while(_loc7_ < _loc6_.length)
  357.          {
  358.             this._aAnyTimeShortcuts.push({k:_loc6_[_loc7_].k,c:_loc6_[_loc7_].c,o:true,d:"CONSOLE"});
  359.             _loc7_ = _loc7_ + 1;
  360.          }
  361.       }
  362.    }
  363.    function processShortcuts(aShortcuts, nKeyCode, bCtrl, bShift)
  364.    {
  365.       var _loc6_ = true;
  366.       var _loc7_ = 0;
  367.       while(_loc7_ < aShortcuts.length)
  368.       {
  369.          if(Number(aShortcuts[_loc7_].k) == nKeyCode)
  370.          {
  371.             var _loc8_ = false;
  372.             switch(aShortcuts[_loc7_].c)
  373.             {
  374.                case 1:
  375.                   if(bCtrl && !bShift)
  376.                   {
  377.                      _loc8_ = true;
  378.                   }
  379.                   break;
  380.                case 2:
  381.                   if(!bCtrl && bShift)
  382.                   {
  383.                      _loc8_ = true;
  384.                   }
  385.                   break;
  386.                case 3:
  387.                   if(bCtrl && bShift)
  388.                   {
  389.                      _loc8_ = true;
  390.                   }
  391.                   break;
  392.                default:
  393.                   if(!bCtrl && !bShift)
  394.                   {
  395.                      _loc8_ = true;
  396.                      break;
  397.                   }
  398.             }
  399.             if(_loc8_)
  400.             {
  401.                _loc6_ = this.dispatchShortcut(aShortcuts[_loc7_].d);
  402.             }
  403.          }
  404.          _loc7_ = _loc7_ + 1;
  405.       }
  406.       return _loc6_;
  407.    }
  408.    function onSetChange(nSetID)
  409.    {
  410.       this._nCurrentSet = nSetID;
  411.       this.loadShortcuts();
  412.    }
  413.    function onKeyDown()
  414.    {
  415.       var _loc2_ = Key.getCode();
  416.       var _loc3_ = Key.getAscii();
  417.       var _loc4_ = Key.isDown(Key.CONTROL);
  418.       var _loc5_ = Key.isDown(Key.SHIFT);
  419.       if(this._lastCtrlState != _loc4_)
  420.       {
  421.          this._lastCtrlState = _loc4_;
  422.          this.dispatchCtrlState(_loc4_);
  423.       }
  424.       if(this._bPressedKeys[_loc2_] != undefined)
  425.       {
  426.          return undefined;
  427.       }
  428.       this._bPressedKeys[_loc2_] = true;
  429.       if(!this.processShortcuts(this._aAnyTimeShortcuts,_loc2_,_loc4_,_loc5_))
  430.       {
  431.          return undefined;
  432.       }
  433.       if(Selection.getFocus() != undefined)
  434.       {
  435.          return undefined;
  436.       }
  437.       if(!this.processShortcuts(this._aNoChatShortcuts,_loc2_,_loc4_,_loc5_))
  438.       {
  439.          return undefined;
  440.       }
  441.       if(_loc3_ > 0)
  442.       {
  443.          this.dispatchKey(String.fromCharCode(_loc3_));
  444.       }
  445.    }
  446.    function onKeyUp()
  447.    {
  448.       var _loc2_ = Key.getCode();
  449.       delete this._bPressedKeys.register2;
  450.    }
  451.    function onShortcut(sShortcut)
  452.    {
  453.       var _loc3_ = true;
  454.       switch(sShortcut)
  455.       {
  456.          case "TOGGLE_FIGHT_INFOS":
  457.             this.api.kernel.OptionsManager.setOption("ChatEffects",!this.api.kernel.OptionsManager.getOption("ChatEffects"));
  458.             _loc3_ = false;
  459.             break;
  460.          case "ESCAPE":
  461.             this.api.datacenter.Basics.gfx_canLaunch = false;
  462.             if(!this.api.ui.removeCursor(true))
  463.             {
  464.                if(this.api.ui.callCloseOnLastUI() == false)
  465.                {
  466.                   this.api.ui.loadUIComponent("AskMainMenu","AskMainMenu");
  467.                }
  468.             }
  469.             break;
  470.          case "CONSOLE":
  471.             if(this.api.datacenter.Player.isAuthorized)
  472.             {
  473.                this.api.ui.loadUIComponent("Debug","Debug",undefined,{bAlwaysOnTop:true});
  474.                _loc3_ = false;
  475.             }
  476.             break;
  477.          case "GRID":
  478.             this.api.kernel.OptionsManager.setOption("Grid");
  479.             _loc3_ = false;
  480.             break;
  481.          case "TRANSPARENCY":
  482.             this.api.kernel.OptionsManager.setOption("Transparency",!this.api.gfx.bGhostView);
  483.             _loc3_ = false;
  484.             break;
  485.          case "SPRITEINFOS":
  486.             this.api.kernel.OptionsManager.setOption("SpriteInfos");
  487.             _loc3_ = false;
  488.             break;
  489.          case "COORDS":
  490.             this.api.kernel.OptionsManager.setOption("MapInfos");
  491.             _loc3_ = false;
  492.             break;
  493.          case "STRINGCOURSE":
  494.             this.api.kernel.OptionsManager.setOption("StringCourse");
  495.             _loc3_ = false;
  496.             break;
  497.          case "BUFF":
  498.             this.api.kernel.OptionsManager.setOption("Buff");
  499.             _loc3_ = false;
  500.             break;
  501.          case "MOVABLEBAR":
  502.             this.api.kernel.OptionsManager.setOption("MovableBar",!this.api.kernel.OptionsManager.getOption("MovableBar"));
  503.             _loc3_ = false;
  504.             break;
  505.          case "MOUNTING":
  506.             this.api.network.Mount.ride();
  507.             _loc3_ = false;
  508.             break;
  509.          case "FULLSCREEN":
  510.             this.api.kernel.GameManager.isFullScreen = _loc0_ = !this.api.kernel.GameManager.isFullScreen;
  511.             getURL("FSCommand:" add "fullscreen",_loc0_);
  512.             _loc3_ = false;
  513.             break;
  514.          case "ALLOWSCALE":
  515.             this.api.kernel.GameManager.isAllowingScale = _loc0_ = !this.api.kernel.GameManager.isAllowingScale;
  516.             getURL("FSCommand:" add "allowscale",_loc0_);
  517.             _loc3_ = false;
  518.             break;
  519.          case "OVERHEAD_MONSTERGROUPS":
  520.             var _loc4_ = this.api.gfx.spriteHandler.getSprites().getItems();
  521.             for(var k in _loc4_)
  522.             {
  523.                if(_loc4_[k] instanceof dofus.datacenter.MonsterGroup && k.length < 4)
  524.                {
  525.                   this.api.gfx.addSpriteOverHeadItem(_loc4_[k].id,"text",dofus.graphics.battlefield.TextWithTitleOverHead,[_loc4_[k].name,_loc4_[k],dofus.Constants.NPC_ALIGNMENT_COLOR[_loc4_[k].alignment.index],_loc4_[k].id,this.api.lang.getText("LEVEL") + " " + _loc4_[k].totalLevel,dofus.Constants.OVERHEAD_TEXT_TITLE,_loc4_[k].bonusValue]);
  526.                }
  527.             }
  528.             _loc3_ = false;
  529.       }
  530.       return _loc3_;
  531.    }
  532. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement