设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 75|回复: 0

[转载发布] Player Input in ShowText Window Plugin [RMMZ]

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9015

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58751
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68660

    灌水之王

    发表于 2026-7-19 15:50:13 | 显示全部楼层 |阅读模式
    Player Input Text MZ
    playerInputText.js

    ◆ Plugin Overview
    This RPG Maker MZ plugin allows players to input their own text into a Show Text window, styled like NPC dialogue.
    It offers customizable options including actor image, name, font size, input text color, and placeholder settings.

    The plugin enhances interactive storytelling by enabling players to actively participate in conversations and scenarios. It's designed to be flexible and easy to integrate into various game events, making it a versatile tool for RPG creators seeking to add personalized player interaction in their games.





    ◆ DEMO

    https://www.youtube.com/embed/9zRCHZJhGPs

    ◆ Plugin Commands
    ▶ inputText


    ◆ Configurable Arguments
    ▶ Actor Image
    ▶ Actor Name
    ▶ Text Font Size
    ▶ Text Color
    ▶ Placeholder text
    ▶ Placeholder Text Color

    ◆ Download Plugin code

    Spoiler                JavaScript:       
    1. /*:
    2. * @target MZ
    3. * @plugindesc [RPG Maker MZ] [Version 1.1.1] [Gamer Tools Studio]
    4. * @author Gamer Tool Studio
    5. *
    6. * @command PlayerInput
    7. * @text Player Input
    8. * @desc Allows the player to input their own message.
    9. *
    10. * @arg actorName
    11. * @text Actor Name
    12. * @desc The name of the actor. Default is main player name.
    13. * @type text
    14. * @default
    15. *
    16. * @arg actorFaceImage
    17. * @text Actor Face Image
    18. * @desc The face image of the actor. Default is main player image.
    19. * @type file
    20. * @dir img/faces/
    21. * @default
    22. *
    23. * @arg actorFaceImageIndex
    24. * @text Actor Face Image Index
    25. * @desc The face image index of the actor. Default is main player face index.
    26. * @type number
    27. * @default 0
    28. *
    29. * @arg placeholderText
    30. * @text Placeholder Text
    31. * @desc The placeholder text. Default is "Enter your message...".
    32. * @type text
    33. * @default Enter your message...
    34. *
    35. * @arg inputVariable
    36. * @text Input Variable
    37. * @desc The variable to store the input text. Default is variable 19.
    38. * @type variable
    39. * @default 19
    40. *
    41. * @help PlayerInputText.js
    42. *
    43. * Allows players to input text in a Show Text window with the style of the game window skins and store it in a custom variable.
    44. * Use the plugin command "Player Input" in an event to trigger this feature.
    45. */
    46. (() => {
    47.     const pluginName = "PlayerInputText";
    48.     PluginManager.registerCommand(pluginName, "PlayerInput", args => {
    49.         const actorName = args.actorName || $gameParty.leader().name();
    50.         const actorFaceImage = args.actorFaceImage || $gameParty.leader().faceName();
    51.         const actorFaceImageIndex = parseInt(args.actorFaceImageIndex, 10) || $gameParty.leader().faceIndex();
    52.         const placeholderText = args.placeholderText ? args.placeholderText : 'Enter your message...';
    53.         // Set up the game message with speaker name and face image, but no text.
    54.         $gameMessage.setFaceImage(actorFaceImage, actorFaceImageIndex);
    55.         $gameMessage.setSpeakerName(actorName);
    56.         $gameMessage.add(placeholderText);
    57.         // Ensure the message window activates input mode once it's open.
    58.         const scene = SceneManager._scene;
    59.         if (scene instanceof Scene_Map) {
    60.             const messageWindow = scene._messageWindow;
    61.             if (messageWindow) {
    62.                 messageWindow.prepareInputWindow(args);
    63.                 messageWindow.activateInput();
    64.             }
    65.         }
    66.     });
    67.     // Prepare Input
    68.     Window_Message.prototype.prepareInputWindow = function(args) {
    69.         this._inputArgs = args;
    70.         this._inputVariable = parseInt(args.inputVariable, 10) || 19;
    71.         this._inputLines = [''];
    72.         // Set speaker name to actorName each time before displaying the input window.
    73.         const actorName = args.actorName || $gameParty.leader().name();
    74.         $gameMessage.setSpeakerName(actorName);
    75.         this.activateInput();
    76.         this.open();
    77.         this.setPositionType();
    78.         this.refreshInputWindow(); // This will now reflect the updated speakerName
    79.     };
    80.     Window_Message.prototype.setPositionType = function() {
    81.         // Position type: 0 (top), 1 (middle), 2 (bottom)
    82.         const positionType = 2; // Force to bottom for input
    83.         this.y = this.calculateY(positionType);
    84.     };
    85.     Window_Message.prototype.calculateY = function(positionType) {
    86.         const messageY = {
    87.             0: 0, // Top
    88.             1: (Graphics.boxHeight - this.height) / 2, // Middle
    89.             2: Graphics.boxHeight - this.height // Bottom
    90.         };
    91.         return messageY[positionType];
    92.     };
    93.      // Activate Input
    94.     Window_Message.prototype.activateInput = function() {
    95.         if (this._inputActive) return; // Prevent multiple activations
    96.         this._originalKeyMapper = Object.assign({}, Input.keyMapper);
    97.         this._overrideKeyMapperForTextInput();
    98.         this._inputActive = true;
    99.         this._boundHandleInput = this.handleInput.bind(this);
    100.         document.addEventListener('keydown', this._boundHandleInput);
    101.         this._lastInputTime = 0; // Debounce setup
    102.         this.refreshInputWindow();
    103.     };
    104.     // Deactivate Input
    105.     Window_Message.prototype.deactivateInput = function() {
    106.         document.removeEventListener('keydown', this._boundHandleInput);
    107.         Input.keyMapper = this._originalKeyMapper;
    108.         this._inputActive = false;
    109.     };
    110.     // Temporarily override key mappings for special keys.
    111.     Window_Message.prototype._overrideKeyMapperForTextInput = function() {
    112.         Input.keyMapper[32] = 'space';
    113.         Input.keyMapper[90] = 'z';     
    114.         Input.keyMapper[88] = 'x';
    115.         Input.keyMapper[87] = 'w';
    116.     };
    117.     // Handle Input
    118.     Window_Message.prototype.handleInput = function(event) {
    119.         if (!this._inputActive || !this.isOpen()) return;
    120.         const currentLineIndex = this._inputLines.length - 1;
    121.         let currentLine = this._inputLines[currentLineIndex];
    122.         if (event.key === 'Enter') {
    123.             this.processInput();
    124.             event.preventDefault();
    125.         } else if (event.key === 'Backspace') {
    126.             if (currentLine.length > 0) {
    127.                 this._inputLines[currentLineIndex] = currentLine.slice(0, -1);
    128.             } else if (this._inputLines.length > 1) {
    129.                 this._inputLines.pop();
    130.             }
    131.             this.refreshInputWindow();
    132.         } else if (event.key.length === 1) {
    133.             if (currentLine.length < 40) {
    134.                 this._inputLines[currentLineIndex] += event.key;
    135.             } else if (this._inputLines.length < 4) {
    136.                 this._inputLines.push(event.key);
    137.             }
    138.             this.refreshInputWindow();
    139.         }
    140.     };
    141.     // Process Input
    142.     Window_Message.prototype.processInput = function() {
    143.         const inputText = this._inputLines.join('\n');
    144.         $gameVariables.setValue(this._inputVariable, inputText);
    145.         this.deactivateInput();
    146.         this.close();
    147.         // Reset the speakerName after processing the input.
    148.         $gameMessage.setSpeakerName('');
    149.     };
    150.     // Refresh Input Window
    151.     Window_Message.prototype.refreshInputWindow = function() {
    152.         if (!this._inputLines) {
    153.             return; // Guard clause
    154.         }
    155.         
    156.         // Face Image and text input positioning
    157.         const faceImageWidth = 144;
    158.         const textMargin = 15;
    159.         const textStartX = faceImageWidth + textMargin;
    160.         // This sets the text to start at the very top of the window.
    161.         const textStartY = 0;
    162.         // This ensures the actor's face image remains on the screen.
    163.         this.contents.clearRect(textStartX, textStartY, this.contents.width - textStartX, this.contents.height);
    164.         this.resetFontSettings();
    165.         const args = this._inputArgs;
    166.         
    167.         const textToShow = this._inputLines.join('').trim() !== '' ? this._inputLines.join('\n') : "Enter your message...";
    168.         // Draw the text at the calculated position.
    169.         this.drawTextEx(textToShow, textStartX, textStartY);
    170.     };
    171.     // Clear contents
    172.     Window_Message.prototype.clear = function() {
    173.         this.contents.clear(); // Clears the window's drawing contents
    174.         this._textState = null; // Reset text state
    175.     };
    176. })();
    复制代码






    ◆ Terms of Use
    This plugin is released under MIT license.
    You can download it by free, make a copy, modify and redistribute it as you want. (However, you should not delete the copyright claim and the MIT license clause written inside the plugin)
    ❤ Would be great if you put "Gamer Tool Studio " on the credits



    本贴来自国际rpgmaker官方论坛作者:S3mz处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/player-input-in-showtext-window-plugin-rmmz.164839/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-4 21:30 , Processed in 0.149752 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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