找回密码
 注册用户
查看: 412|回复: 0

[RMMZ] 【汉化】r88自定义按键

[复制链接]

88

主题

7

回帖

1277

积分

资深会员

积分
1277
发表于 2024-6-20 17:41:45 | 显示全部楼层 |阅读模式
本帖最后由 烁灵 于 2024-6-20 17:43 编辑

可自定义按键、禁用鼠标控制、按键触发公共事件

原地址:Custom Controls (RMMZ Plugin) by reflector88 (itch.io)

汉化脚本:命名为 r88_CustomControls.js
  1. /*:
  2. @target MZ
  3. @plugindesc 提供更多控制方法
  4. 汉化 by 烁灵 更多插件请访问 www.hknmtt.com
  5. @author reflector88
  6. @url https://reflector88.itch.io/
  7. @help
  8. "Custom Controls 1.3"

  9. 本插件提供更多可配置的控制方法(RPG MAKER 原版应该有这些功能,但是并没有)
  10. 同时提供一些快捷键,用于打开菜单、调用公共事件

  11. Update
  12. -V1.1 Improved compatibility
  13. -V1.2 Gamepad buttons can be mapped to common events
  14. -V1.3 (5/31) Refactored code. Added support for Left and Right Triggers and
  15.     Start and Select buttons. Gamepad names are less misleading.
  16. ___________________________________________________________________________
  17. 配置:

  18. 1. 双击参数打开列表窗口、你可以设置任意数量的按键

  19. 2. 在文本框中键入按建名. 多功能键和小键盘使用如下文本:

  20. ● alt                       ● backspace                 ● num0 - num9                     
  21. ● arrowdown                 ● capslock                  ● shift
  22. ● arrowleft                 ● ctrl                      ● space
  23. ● arrowright                ● enter                     ● tab
  24. ● arrowup                   ● esc

  25. 摇杆比较复杂. 摇杆按键各不相同,对如下按键名,你可以多试几次来确定对应的按键:

  26. ● gpadup          ● gpad0           ● gpad4          ● gpad8  
  27. ● gpaddown        ● gpad1           ● gpad5          ● gpad9
  28. ● gpadleft        ● gpad2           ● gpad6          ● gpad10
  29. ● gpadright       ● gpad3           ● gpad7          ● gpad11

  30. gpad0-3 通常为方向键
  31. gpad4-7 通常为触发键
  32. gpad8-11 通常为开始、选择、其他按键

  33. 3. "禁用鼠标控制" 禁用鼠标和触摸,同时去掉右上角菜单键

  34. ___________________________________________________________________________

  35. TERMS OF USE
  36. This plugin is free to use in both commercial and non-commercial projects,
  37. though please credit me.

  38. @param Up
  39. @text 上
  40. @type string[]
  41. @default ["arrowup", "gpadup"]

  42. @param Down
  43. @text 下
  44. @type string[]
  45. @default ["arrowdown", "gpaddown"]

  46. @param Left
  47. @text 左
  48. @type string[]
  49. @default ["arrowleft", "gpadleft"]

  50. @param Right
  51. @text 右
  52. @type string[]
  53. @default ["arrowright", "gpadright"]

  54. @param Confirm
  55. @text 确认
  56. @type string[]
  57. @default ["z", "gpad0"]

  58. @param Cancel/Menu
  59. @text 取消/菜单
  60. @type string[]
  61. @default ["x", "esc"]

  62. @param Sprint
  63. @text 跑步
  64. @type string[]
  65. @default ["shift", "gpad2"]

  66. @param Noclip
  67. @text 穿墙
  68. @type string[]
  69. @default ["ctrl"]

  70. @param Cancel
  71. @text 取消
  72. @type string[]
  73. @default ["gpad1"]

  74. @param Menu Scene
  75. @text 菜单
  76. @type string[]
  77. @default ["gpad3"]

  78. @param Item Scene
  79. @text 物品界面
  80. @type string[]
  81. @default []

  82. @param Skill Scene
  83. @text 技能界面
  84. @type string[]
  85. @default []

  86. @param Equip Scene
  87. @text 装备界面
  88. @type string[]
  89. @default []

  90. @param Options Scene
  91. @text 选项界面
  92. @type string[]
  93. @default []

  94. @param Save Scene
  95. @text 存档界面
  96. @type string[]
  97. @default []

  98. @param Load Scene
  99. @text 读档界面
  100. @type string[]
  101. @default []

  102. @param Common Events
  103. @text 调用公共事件
  104. @type struct<CommonEventsStruct>[]
  105. @desc 设定调用公共事件的热键
  106. @default []

  107. @param Disable Mouse Controls
  108. @text 禁用鼠标控制
  109. @type boolean
  110. @default false

  111. @param Disable UI Buttons
  112. @text 禁用UI按键
  113. @type boolean
  114. @default false

  115. */

  116. /*~struct~CommonEventsStruct:
  117. @param Key
  118. @text 按键
  119. @type string

  120. @param ID
  121. @text 公共事件ID
  122. @type common_event
  123. */

  124. (() => {
  125.     'use strict';

  126.     const parameters = PluginManager.parameters('r88_CustomControls');
  127.     const commonEvents = JSON.parse(parameters['Common Events']);
  128.     const keyCodes = new Map([
  129.         ["1", "49"], ["2", "50"], ["3", "51"], ["4", "52"], ["5", "53"], ["6", "54"], ["7", "55"], ["8", "56"],
  130.         ["9", "57"], ["backspace", "8"], ["tab", "9"], ["enter", "13"], ["shift", "16"], ["ctrl", "17"], ["alt", "18"], ["capslock", "20"], ["esc", "27"],
  131.         ["space", "32"], ["arrowleft", "37"], ["arrowup", "38"], ["arrowright", "39"], ["arrowdown", "40"], ["a", "65"],
  132.         ["b", "66"], ["c", "67"], ["d", "68"], ["e", "69"], ["f", "70"], ["g", "71"], ["h", "72"], ["i", "73"], ["j", "74"],
  133.         ["k", "75"], ["l", "76"], ["m", "77"], ["n", "78"], ["o", "79"], ["p", "80"], ["q", "81"], ["r", "82"], ["s", "83"],
  134.         ["t", "84"], ["u", "85"], ["v", "86"], ["w", "87"], ["x", "88"], ["y", "89"], ["z", "90"], ["num0", "96"],
  135.         ["num1", "97"], ["num2", "98"], ["num3", "99"], ["num4", "100"], ["num5", "101"], ["num6", "102"], ["num7", "103"],
  136.         ["num8", "104"], ["num9", "105"], ["=", "187"], [",", "188"], ["-", "189"], [".", "190"], ["/", "191"], ["`", "192"],
  137.         ["[", "219"], ["\", "220"], ["]", "221"]
  138.     ]);
  139.     const buttonCodes = new Map([
  140.         ["gpad0", "0"], ["gpad1", "1"], ["gpad2", "2"], ["gpad3", "3"], ["gpad4", "4"], ["gpad5", "5"],
  141.         ["gpad6", "6"], ["gpad7", "7"], ["gpad8", "8"], ["gpad9", "9"], ["gpad10", "10"],
  142.         ["gpad11", "11"], ["gpadup", "12"], ["gpaddown", "13"], ["gpadleft", "14"], ["gpadright", "15"],
  143.     ])
  144.     const keyMappings = new Map([
  145.         ["Up", "up"], ["Left", "left"], ["Down", "down"], ["Right", "right"], ["Confirm", "ok"], ["Cancel/Menu", "escape"],
  146.         ["Sprint", "shift"], ["Noclip", "control"], ["Cancel", "cancel"], ["Menu Scene", "openMenu"], ["Item Scene", "openItem"],
  147.         ["Skill Scene", "openSkill"], ["Equip Scene", "openEquip"], ["Options Scene", "openOptions"], ["Save Scene", "openSave"],
  148.         ["Load Scene", "openLoad"]
  149.     ]);

  150.     for (const key of [16, 17, 27, 37, 38, 39, 40, 88, 90]) {
  151.         delete Input.keyMapper[key];
  152.     }
  153.     for (const key of [0, 1, 2, 3, 12, 13, 14, 15]) {
  154.         delete Input.gamepadMapper[key];
  155.     }

  156.     if (JSON.parse(parameters['Disable Mouse Controls'])) {
  157.         TouchInput.initialize = function () { this.clear() };
  158.         TouchInput._onMouseDown = function (event) { };
  159.     }

  160.     if (JSON.parse(parameters['Disable UI Buttons'])) {
  161.         Scene_Map.prototype.createButtons = function () { };
  162.         Scene_Battle.prototype.createButtons = function () { };
  163.         Scene_MenuBase.prototype.createButtons = function () { };
  164.     }

  165.     for (const [name, action] of keyMappings) {
  166.         const binds = JSON.parse(parameters[name]);

  167.         for (const bind of binds) {
  168.             if (keyCodes.has(bind)) Input.keyMapper[keyCodes.get(bind)] = action;
  169.             else if (buttonCodes.has(bind)) Input.gamepadMapper[buttonCodes.get(bind)] = action;
  170.         }
  171.     }

  172.     for (const commonEvent of commonEvents) {
  173.         const bind = JSON.parse(commonEvent)["Key"];
  174.         const ID = JSON.parse(commonEvent)["ID"];

  175.         if (keyCodes.has(bind)) Input.keyMapper[keyCodes.get(bind)] = 'commonEvent' + ID;
  176.         else if (buttonCodes.has(bind)) Input.gamepadMapper[buttonCodes.get(bind)] = 'commonEvent' + ID;
  177.     }

  178.     const scenes = ["Menu", "Item", "Skill", "Equip", "Options", "Save", "Load"];

  179.     const Scene_Map_update = Scene_Map.prototype.update;
  180.     Scene_Map.prototype.update = function () {
  181.         Scene_Map_update.apply(this, arguments);

  182.         for (const scene of scenes) {
  183.             if (Input.isTriggered("open" + scene)) SceneManager.push(eval?.("Scene_" + scene));
  184.         }

  185.         for (const commonEvent of commonEvents) {
  186.             const ID = JSON.parse(commonEvent)["ID"];

  187.             if (Input.isTriggered('commonEvent' + ID)) {
  188.                 $gameTemp.reserveCommonEvent(ID);
  189.             }
  190.         }
  191.     };

  192.     for (const scene of scenes) {
  193.         closeScene(eval?.("Scene_" + scene), "open" + scene);
  194.     }

  195.     function closeScene(sceneClass, trigger) {
  196.         const Scene_update = sceneClass.prototype.update;
  197.         sceneClass.prototype.update = function () {
  198.             Scene_update.apply(this, arguments);

  199.             if (Input.isTriggered(trigger)) {
  200.                 SoundManager.playCancel();
  201.                 SceneManager.pop();
  202.             }
  203.         };
  204.     }

  205. })();
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-11-22 13:06 , Processed in 0.061315 second(s), 19 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表