搜索附件  
同能RPG制作大师 附件中心 同能RM技术讨论区 RPG Maker MV 讨论区 【2016.07.18】按键调用插件或脚本: InputUsePlugins.zip

【2016.07.18】按键调用插件或脚本: InputUsePlugins.zip

 

【2016.07.18】按键调用插件或脚本:


本人的 输入按键重新设置 同时使用时,请在适当时机使用     ww.InputUsePlugins.start() 以确保按键安装
JAVASCRIPT 代码下载
  1. //=============================================================================
  2. // InputUsePlugins.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc 按键调用插件
  6. * @author wangwang
  7. *
  8. * @param  InputUsePlugins
  9. * @desc 确定是按键调用插件的参数,请勿修改
  10. * @default 汪汪
  11. *
  12. * @param KeyName
  13. * @desc 键对应名,请勿与mv默认设置冲突
  14. * @default "65":"A","68":"D"
  15. *
  16. * @param UsePlugin
  17. * @desc 键名调用方法
  18. * @default "A":{"isTriggerLongPressed":"IUP test isTriggerLongPressed","isTriggered":"IUP test1 isTriggered","isKeyUpTriggered":"IUP test2 isKeyUpTriggered"}
  19. *
  20. * @param UseEval
  21. * @desc 键名调用脚本
  22. * @default "D":"console.log('D')"
  23. *
  24. * @help
  25. * 帮助的信息
  26. *
  27. * kayname 用来扩展mv的按键
  28. * 是给键盘按键设置一个名称,不同的键可以设置相同的名称,
  29. * 前面的是键对应的值,具体哪个按键对应的什么值可以上网上查询 键盘键值,比如 65 对应的是 键盘上 的 A键
  30. * 后面的是键对应的名称,可以任意设置,比如 我们把 65 设置为 "A" , 68 (d键) 设置为 "D" ,当然你也可以吧 65 设置为 "随便起个名",
  31. * 写法是  
  32. * "数字":"名称"   
  33. * 如
  34. * "65":"A"
  35. *
  36. * mv本事也设置了一些 ,如下
  37. * 9: 'tab',       // tab
  38. * 13: 'ok',       // enter
  39. * 16: 'shift',    // shift
  40. * 17: 'control',  // control
  41. * 18: 'control',  // alt
  42. * 27: 'escape',   // escape
  43. * 32: 'ok',       // space
  44. * 33: 'pageup',   // pageup
  45. * 34: 'pagedown', // pagedown
  46. * 37: 'left',     // left arrow
  47. * 38: 'up',       // up arrow
  48. * 39: 'right',    // right arrow
  49. * 40: 'down',     // down arrow
  50. * 45: 'escape',   // insert
  51. * 81: 'pageup',   // Q
  52. * 87: 'pagedown', // W
  53. * 88: 'escape',   // X
  54. * 90: 'ok',       // Z
  55. * 96: 'escape',   // numpad 0
  56. * 98: 'down',     // numpad 2
  57. * 100: 'left',    // numpad 4
  58. * 102: 'right',   // numpad 6
  59. * 104: 'up',      // numpad 8
  60. * 120: 'debug'    // F9
  61. *
  62. * UsePlugin 是用来调用插件方法 相当于事件里最后一页的 插件指令
  63. * UseEval 是用来调用脚本 相当于事件里最后一页的 脚本
  64. * 前面写用于判断的键名,如 "A" 就是指对于键名 "A" 的调用 ,
  65. * 当然,你也可以使用mv原有的那些名字比如 "ok" ,"shift" 不过不建议,因为那样可能影响正常游戏操作
  66. *
  67. * 后面有两种写法
  68. * 1,字符串, 比如 "IUP test isTriggerLongPressed"
  69. * 这样就是调用 插件指令 IUP test isTriggerLongPressed ,记得字符串两边加""
  70. * 当然也可以是脚本 比如 "$gameVariables.setValue(1,100)"  
  71. * 设置1号变量为100
  72. * 这种情况下,默认是按下键的瞬间调用它
  73. * 2,对象,使用{"isTriggerLongPressed":"IUP test isTriggerLongPressed","isTriggered":"IUP test1 isTriggered"} 这样的写法
  74. * 这种情况下, 会在
  75. * "isTriggered"
  76. * 按下瞬间(按下,只触发一次)调用 插件指令 "IUP test1 isTriggered"
  77. * "isTriggerLongPressed"
  78. * 长按下瞬间(长按一会,只触发一次)调用 插件指令 "IUP test isTriggerLongPressed"
  79. *
  80. * isPressed 是按下
  81. * isTriggered 是刚按下 (推荐)
  82. * isRepeated 是重复按下
  83. * isLongPressed 是长按下
  84. * isTriggerLongPressed 是长按下瞬间 (添加,推荐)
  85. * isKeyUpTriggered 是抬起瞬间(添加)
  86. *
  87. * 一个键写完后要写另一个键用 , 隔开
  88. * 如 "A":"XXXXXXX","D":"YYYYYYYYY"
  89. *
  90. *
  91. *
  92. */
  93. (function () {
  94.     var _Game_Interpreter_pluginCommand =
  95.         Game_Interpreter.prototype.pluginCommand;
  96.     Game_Interpreter.prototype.pluginCommand = function (command, args) {
  97.         _Game_Interpreter_pluginCommand.call(this, command, args);
  98.         if (command === 'IUP') {
  99.             switch (args[0]) {
  100.                 case 'start':
  101.                     ww.InputUsePlugins.start()
  102.                     break;
  103.                 case 'open':
  104.                     ww.InputUsePlugins.open()
  105.                     break;
  106.                 case 'close':
  107.                     ww.InputUsePlugins.close()
  108.                     break;
  109.                 case 'test':
  110.                     console.log("测试  " + args[1] + " 是长按下瞬间")
  111.                     break;
  112.                 case 'test1':
  113.                     console.log("测试 1  " + args[1] + " 是按下")
  114.                     break;
  115.                 case 'test2':
  116.                     console.log("测试 2  " + args[1] + " 是抬起")
  117.                     break;
  118.             }
  119.         }
  120.     };
  121.     //长按后瞬间
  122.     Input.isTriggerLongPressed = function (keyName) {
  123.         if (this._isEscapeCompatible(keyName) && this.isLongPressed('escape')) {
  124.             return true;
  125.         } else {
  126.             return (this._latestButton === keyName &&
  127.                 this._pressedTime === this.keyRepeatWait);
  128.         }
  129.     };   
  130.     //抬起按键
  131.     Input.isKeyUpTriggered = function (keyName) {
  132.         if (this._isEscapeCompatible(keyName) && this.isLongPressed('escape')) {
  133.             return true;
  134.         } else {
  135.             return ( !this._currentState[keyName]&& this._previousState[keyName]);
  136.         }  
  137.     };
  138.     ww = {}
  139.     ww.InputUsePlugins = {}
  140.     ww.InputUsePlugins._keyname = {}
  141.     ww.InputUsePlugins._useplugin = {}
  142.     ww.InputUsePlugins._useeval = {}
  143.     ww.InputUsePlugins.SceneManager_updateInputData = SceneManager.updateInputData
  144.     SceneManager.updateInputData = function () {
  145.         if (ww.InputUsePlugins.open) {
  146.             ww.InputUsePlugins.use()
  147.         }
  148.         ww.InputUsePlugins.SceneManager_updateInputData.call(this)
  149.     };
  150.     ww.InputUsePlugins.init = function (p) {
  151.         var p = p
  152.         var keyname = p.parameters["KeyName"] || ""
  153.         var useplugin = p.parameters["UsePlugin"] || ""
  154.         var useeval = p.parameters["UseEval"] || ""
  155.         try { eval('this._keyname = {' + keyname + '}') } catch (e) { console.log( "keyname is error")}
  156.         try { eval('this._useplugin = {' + useplugin + '}') } catch (e) {console.log( "useplugin is error") }
  157.         try { eval('this._useeval = {' + useeval + '}') } catch (e) {console.log( "useeval is error") }
  158.         var kn = this._keyname
  159.         for (var i in kn) {
  160.             if (!Input.keyMapper[i]) {
  161.                 Input.keyMapper[i] = kn[i]
  162.             }
  163.         }
  164.     }
  165.     ww.InputUsePlugins.use = function () {
  166.         var use = this._useeval
  167.         for (var name in use) {
  168.             try {
  169.                 var nr = use[name]
  170.                 var type = typeof (nr)
  171.                 if (type === "string") {
  172.                     if (Input.isTriggered(name)) {
  173.                         eval(nr)
  174.                     }
  175.                 } else if (type === "object") {
  176.                     for (var f in nr) {
  177.                         if (Input[f] && Input[f](name)) {
  178.                             var nr2 = nr[f]
  179.                             if (typeof (nr2) === "string") {
  180.                                 eval(nr2)
  181.                             }
  182.                         }
  183.                     }
  184.                 }
  185.             } catch (e) {
  186.             }
  187.         }
  188.         var use = this._useplugin
  189.         for (var name in use) {
  190.             try {
  191.                 var nr = use[name]
  192.                 var type = typeof (nr)
  193.                 if (type === "string") {
  194.                     if (Input.isTriggered(name)) {
  195.                         this.usepc(nr)
  196.                     }
  197.                 } else if (type === "object") {
  198.                     for (var f in nr) {
  199.                         if (Input[f] && Input[f](name)) {
  200.                             var nr2 = nr[f]
  201.                             if (typeof (nr2) === "string") {
  202.                                 this.usepc(nr2)
  203.                             }
  204.                         }
  205.                     }
  206.                 }
  207.             } catch (e) {
  208.             }
  209.         }
  210.     }
  211.     ww.InputUsePlugins.usepc = function (s) {
  212.         var pc = Game_Interpreter.prototype.pluginCommand
  213.         var args = s.split(" ");
  214.         var command = args.shift();
  215.         pc(command, args);
  216.     }
  217.     ww.InputUsePlugins.start = function () {
  218.         this._open = true
  219.         this.load()
  220.     }
  221.     ww.InputUsePlugins.open = function () {
  222.         this._open = true
  223.     }
  224.     ww.InputUsePlugins.close = function () {
  225.         this._open = false
  226.     }
  227.     ww.InputUsePlugins.load = function () {
  228.         for (var i = 0; i < $plugins.length; i++) {
  229.             var plugin = $plugins[i]
  230.             if (plugin.parameters["InputUsePlugins"]) {
  231.                 if (plugin.status == true) {
  232.                     ww.InputUsePlugins.init(plugin)
  233.                 }
  234.             }
  235.         }
  236.     }
  237.     ww.InputUsePlugins.start()
  238. })();
复制代码

             本帖来自P1论坛作者汪汪,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=394707  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

GMT+8, 2024-5-20 13:16 , Processed in 0.076909 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部