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

[转载发布] Term Window

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

    连续签到: 2 天

    [LV.7]常住居民III

    8100

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 5 天前 | 显示全部楼层 |阅读模式
    Term Window v1.03b
    Author:
    Michael Morris @Blue Booth Studios, Yanfly (Message Core)


    Introduction
    Allows a popup help window to explain game "terms" (names, places, events, etc.) while and only while a message box (dialogue) is open.  A prompt specifying what button to press to toggle help displays atop the messagebox.  Data is loaded from JSON.  A term is any text enclosed with "\c[4]."  A different color code can be customized in plugin parameters.


    Features
    - Automatically load terms for any message box, provided terms are surrounded with "\c[4]."
    - Term highlighting color and term window keys are now customizable parameters!
    - If more than one term is present in a message, terms can be toggled between using left and right input.  An index and total number of terms are also shown.
    - Displays a small message above each message box with terms.
    - Terms can be one word or multiple words!
    - Each term is displayed only once in the Term Window regardless of number of repetitions in the message box.
    - Quick, easy, and unobtrusive - let interested players learn more about the lore without blocking less interested players from moving on!



    How to Use
    - Copy script into your game js/plugins directory.
    - Copy JSON into your game data directory.
    - Import and configure plugin.
    - Add any custom terms you have to Terms.JSON.

    Requirements
    -YEP_MessageCore.js (http://yanfly.moe/2015/10/10/yep-2-message-core/)

    Screenshots







    Demo
    No demo provided.

    Script
    Spoiler                Code:       
    1. //=============================================================================
    2. // Bluebooth Plugins - Term Window
    3. // BBS_TermWindow.js
    4. //=============================================================================
    5. //=============================================================================
    6. /*:
    7. * @title Term Window
    8. * @author Michael Morris (https://www.patreon.com/bluebooth)
    9. * @date Oct 12, 2016
    10. * @filename BBS_TermWindow.js
    11. * If you enjoy my work, consider supporting me on Patreon!
    12. *
    13. * https://www.patreon.com/bluebooth
    14. *
    15. * @plugindesc v1.03b Allows a popup help window to explain game terms while
    16. * and only while a message box (dialogue) is open.
    17. * Special thanks to Yanfly, this borrows structures from his YEP_MessageCore, and my
    18. * own BBS_RandomConversations.js.
    19. *
    20. * ============================================================================
    21. * Terms of Use
    22. * ============================================================================
    23. *  - Free for use in non-commercial projects with credits
    24. *  - Contact me for commercial use
    25. *
    26. * ============================================================================
    27. * Parameters
    28. * ============================================================================
    29. * @param Term File
    30. * @desc Name of an external term file (name + definition) to load at game start. Default: data/Terms.json
    31. * @default data/Terms.json
    32. *
    33. * @param Term Color Index
    34. * @desc Words wrapped in a specific color tag are identified as terms.  Which color do you want to wrap terms in?
    35. * Default: 4
    36. * @default 4
    37. *
    38. * @param === KEYS USED ===
    39. *
    40. * @param Help Key
    41. * @desc The button to check for to toggle help. Default: pageup
    42. * @default pageup
    43. *
    44. * @param Previous Term Key
    45. * @desc The button to cycle left (1-3-2-1) through active terms in the term window. Default: Left
    46. * @default left
    47. *
    48. * @param Next Term Key
    49. * @desc The button to cycle right (1-2-3-1) through active terms in the term window. Default: Right
    50. * @default right
    51. *
    52. * @param === HELP PROMPT WINDOW ===
    53. *
    54. * @param Help Prompt
    55. * @desc Text to display indicating what button to press to display term window. Default: PgUp - help
    56. * @default PgUp - help
    57. *
    58. * @param Help Prompt Width
    59. * @desc Maximum width for the Help Prompt. Default: 200
    60. * @default 200
    61. *
    62. * @param Help Prompt Buffer X
    63. * @desc This is the buffer for the x location of the Help Prompt.
    64. * @default -28
    65. *
    66. * @param Help Prompt Buffer Y
    67. * @desc This is the buffer for the y location of the Help Prompt.
    68. * @default 0
    69. *
    70. * @param Help Prompt Text Size
    71. * @desc Font size for the Help Prompt.
    72. * Default: 20
    73. * @default 20
    74. *
    75. * @param Help Prompt Text Color
    76. * @desc Help Prompt font color. Use CSS format, or leave blank
    77. * to use standard color.
    78. * @default
    79. *
    80. * @param === TERM WINDOW ===
    81. *
    82. * @param Term Window Windowskin
    83. * @desc The windowskin to apply to the Term Window. Default:
    84. * @default
    85. *
    86. * @param Term Window Width
    87. * @desc Maximum width for the Term window. Default: 200
    88. * @default 200
    89. *
    90. * @param Term Window Height
    91. * @desc Maximum height for the Term window. Default: 300
    92. * @default 300
    93. * @param === TERM WINDOW TITLE ===
    94. *
    95. * @param Title Font
    96. * @desc Font face for the title. Leave blank to use standard. See help.
    97. * @default
    98. *
    99. * @param Title Size
    100. * @desc Font size for the Title in the details window.
    101. * Default: 22
    102. * @default 22
    103. *
    104. * @param Title Color
    105. * @desc Title font color. Use CSS format, or leave blank
    106. * to use standard color.
    107. * @default
    108. *
    109. * @param Title Outline Color
    110. * @desc Title text outline color. Use CSS format or leave
    111. * blank to use standard.
    112. * @default
    113. *
    114. * @param Title Italic
    115. * @desc Title font in Italic.      YES: true      NO: false
    116. * Default: false
    117. * @default false
    118. *
    119. * @param === TERM WINDOW LINE ===
    120. *
    121. * @param Line Center Color
    122. * @desc Center color of the gradient line below the title.
    123. * Use CSS format.    Default: rgba(255,255,255,1)
    124. * @default rgba(255,255,255,1)
    125. *
    126. * @param Line Border Color
    127. * @desc Border color of the gradient line below the title.
    128. * Use CSS format.    Default: rgba(255,255,255,0)
    129. * @default rgba(255,255,255,0)
    130. *
    131. * @param === DETAILS TEXT ===
    132. *
    133. * @param Text Font
    134. * @desc Font face for the details text. Leave blank to use standard. See help.
    135. * @default
    136. *
    137. * @param Text Size
    138. * @desc Font size for the details text.
    139. * Default: 20
    140. * @default 20
    141. *
    142. * @param Text Outline Color
    143. * @desc Details text outline color. Use CSS format or leave blank to use standard.
    144. * @default
    145. *
    146. * @param Debug Mode
    147. * @desc Enable to activate console variable logging.  Use for debugging odd behaviour.
    148. * true to enable console variable logging.
    149. * @default false
    150. *
    151. * @help
    152. * ============================================================================
    153. * Description
    154. * ============================================================================
    155. *
    156. * Allows a popup help window to explain game terms while and only while a message
    157. * box (dialogue) is open.  A prompt specifying what button to press to toggle
    158. * help displays atop the messagebox.  Data is loaded from JSON.
    159. *
    160. * Any one term must have the opening tag + term + closing tag on the same line.
    161. *
    162. * ============================================================================
    163. * Change Log
    164. * ============================================================================
    165. * 1.03b- Added more friendly crash error message.
    166. * 1.03a- Fixed issue causing parameters not to register.
    167. * 1.03 - Added option to change color index for Terms (default 4), and option to change
    168. *         - keys for Term Window.
    169. * 1.02 - Multiple word terms now supported using _.
    170. * 1.01 - Plugin finished and tested.
    171. *
    172. */
    173. //=============================================================================
    174. //=============================================================================
    175. var Imported = Imported || {} ;
    176. var BBS = BBS || {};
    177. Imported.TermWindow = 1;
    178. BBS.TermWindow = BBS.TermWindow || {};
    179. (function() {
    180.     var _terms;
    181.     var _activeTerms = [];
    182.     //=============================================================================
    183.     // Parameter Variables
    184.     //=============================================================================
    185.     var parameters                     = PluginManager.parameters('BBS_TermWindow');
    186.     var pTermFile                    = String(parameters['Term File'] || 'data/Terms.json');
    187.     var pTermColorIndex                = Number(parameters['Term Color Index'] || 4);
    188.     var pHelpKey                    = String(parameters['Help Key'] || 'pageup');
    189.     var pPreviousTermKey            = String(parameters['Previous Term Key'] || 'left');
    190.     var pNextTermKey                = String(parameters['Next Term Key'] || 'right');
    191.     var pMsgHelpPromptText            = String(parameters['Help Prompt'] || 'X - help');
    192.     var pMsgHelpPromptBufferX         = Number(parameters['Help Prompt Buffer X'] || -28);
    193.     var pMsgHelpPromptBufferY         = Number(parameters['Help Prompt Buffer Y'] || 0);
    194.     var pMsgHelpPromptBufferWidth    = Number(parameters['Help Prompt Width'] || 200);
    195.     var pMsgHelpPromptTextColor        = String(parameters['Help Prompt Text Color'] || '').trim();
    196.     var pMsgHelpPromptTextSz        = Number(parameters['Help Prompt Text Size'] || 20);
    197.     var pCustomTermWindowskin        = String(parameters['Term Window Windowskin'] || '');
    198.     var pTermWindowWidth            = Number(parameters['Term Window Width'] || 200);
    199.     var pTermWindowHeight            = Number(parameters['Term Window Height'] || 300);
    200.     var pTitleTxtFont                = String(parameters['Title Font'] || '').trim();
    201.     var pTitleTxtSz                 = Number(parameters['Title Size'] || 22);
    202.     var pTitleTxtColor                = String(parameters['Title Color'] || '').trim();
    203.     var pTitleTxtOutlineColor        = String(parameters['Title Outline Color'] || '').trim();
    204.     var pTitleTxtItalic             = eval(String(parameters['Title Italic'] || 'false'));
    205.     var pGradientLineColorCenter     = String(parameters['Line Center Color'] || 'rgba(255,255,255,1)').trim();
    206.     var pGradientLineColorBorder     = String(parameters['Line Border Color'] || 'rgba(255,255,255,0)').trim();
    207.     var pDetailsTxtFont                = String(parameters['Text Font'] || '').trim();
    208.     var pDetailsTxtFontSz            = Number(parameters['Text Size'] || 20);
    209.     var pDetailsTxtOutlineColor        = String(parameters['Text Outline Color'] || '').trim();
    210.     var pDebugging                    = eval(String(parameters['Debug Mode'] || 'false'));
    211.     var BBS_helpPromptWnd = undefined;
    212.     var BBS_termWnd = undefined;
    213.     // Sanity check for valid color index.
    214.     if (pTermColorIndex < 0 || pTermColorIndex > 28) {
    215.         throw "BBS_TermWindow: Term color index " + pTermColorIndex + " is not a valid color!  Please use an index between 0 - 28 inclusive.";
    216.     }
    217.     //=============================================================================
    218.     // Term Class
    219.     //=============================================================================
    220.     function Term() {
    221.         this.initialize.apply(this, arguments);
    222.     };
    223.     Term.prototype.initialize = function(data) {
    224.         this._term = String(data.term);
    225.         this._desc = String(data.description);
    226.     };
    227.     Term.prototype = Object.create(Term.prototype);
    228.     Term.prototype.constructor = Term;
    229.     /**
    230.      * Creates rumors from the given data and loads their current state, afterwards.
    231.      */
    232.     var _create = function(data) {
    233.         var temp = [];
    234.         for(var i = 0, max = data.length; i < max; ++i) {
    235.             entry = data[i];
    236.             temp.push(new Term(entry));
    237.         }
    238.      
    239.         _terms = temp;
    240.      
    241.         if (pDebugging) {
    242.             console.log(_terms);
    243.         }
    244.     };
    245.     var _getIndex = function(term) {
    246.         if (pDebugging) {
    247.             console.log(term);
    248.             console.log(_terms);
    249.         }
    250.      
    251.         for(var i = 0; i < _terms.length; i++) {
    252.             if(_terms[i]._term === term) {
    253.                 return i;
    254.             }
    255.         }
    256.      
    257.         return -1;
    258.     };
    259.     //=============================================================================
    260.     // Window_MsgHelpPrompt
    261.     //=============================================================================
    262.     function Window_MsgHelpPrompt() {
    263.         this.initialize.apply(this, arguments);
    264.     }
    265.     Window_MsgHelpPrompt.prototype = Object.create(Window_Base.prototype);
    266.     Window_MsgHelpPrompt.prototype.constructor = Window_MsgHelpPrompt;
    267.     Window_MsgHelpPrompt.prototype.initialize = function(parentWindow) {
    268.         this._parentWindow = parentWindow;
    269.         Window_Base.prototype.initialize.call(this, 0, 0, 240, this.windowHeight());
    270.         this._text = '';
    271.         this._openness = 0;
    272.         this._closeCounter = 0;
    273.         this.deactivate();
    274.      
    275.         this.backOpacity = 0;
    276.         this.opacity = 0;
    277.         this.hide();
    278.     };
    279.     Window_MsgHelpPrompt.prototype.windowWidth = function() {
    280.         this.resetFontSettings();
    281.         var dw = this.textWidthEx(this._text);
    282.         dw += this.padding * 2;
    283.         var width = dw + eval(pMsgHelpPromptBufferWidth);
    284.         return Math.ceil(width);
    285.     };
    286.     Window_MsgHelpPrompt.prototype.textWidthEx = function(text) {
    287.         return this.drawTextEx(text, 0, this.contents.height);
    288.     };
    289.     Window_MsgHelpPrompt.prototype.calcNormalCharacter = function(textState) {
    290.         return this.textWidth(textState.text[textState.index++]);
    291.     };
    292.     Window_MsgHelpPrompt.prototype.windowHeight = function() {
    293.         return this.fittingHeight(1);
    294.     };
    295.     Window_MsgHelpPrompt.prototype.standardFontFace = function() {
    296.         return $gameSystem.getMessageFontName();
    297.     };
    298.     Window_MsgHelpPrompt.prototype.standardFontSize = function() {
    299.         return $gameSystem.getMessageFontSize();
    300.     };
    301.     Window_MsgHelpPrompt.prototype.update = function() {
    302.         Window_Base.prototype.update.call(this);
    303.         if (this.active) return;
    304.         if (this.isClosed()) return;
    305.         if (this.isClosing()) return;
    306.         if (this._parentWindow.isClosing()) {
    307.             this._openness = this._parentWindow.openness;
    308.         }
    309.     };
    310.     Window_MsgHelpPrompt.prototype.refresh = function(text, position) {
    311.         this.show();
    312.         this._text = text;
    313.         this._position = position;
    314.         this.width = this.windowWidth();
    315.         this.createContents();
    316.         this.contents.clear();
    317.         this.resetFontSettings();
    318.      
    319.         this.changeTextColor(this.textColor(pMsgHelpPromptTextColor));
    320.         var padding = eval(pMsgHelpPromptBufferWidth) / 2;
    321.         this.contents.fontSize = pMsgHelpPromptTextSz;
    322.      
    323.         this.drawTextEx(this._text, padding, 0, this.contents.width);
    324.         this._parentWindow.adjustWindowSettings();
    325.         this._parentWindow.updatePlacement();
    326.      
    327.         this.adjustPositionX();
    328.         this.adjustPositionY();
    329.         this.open();
    330.         this.activate();
    331.         this._closeCounter = 4;
    332.         return '';
    333.     };
    334.     Window_MsgHelpPrompt.prototype.adjustPositionX = function() {
    335.         if (this._position === 1) {
    336.          this.x = this._parentWindow.x;
    337.          this.x += eval(pMsgHelpPromptBufferX);
    338.         }
    339.         else if (this._position === 2) {
    340.          this.x = this._parentWindow.x;
    341.          this.x += this._parentWindow.width * 3 / 10;
    342.          this.x -= this.width / 2;
    343.         }
    344.         else if (this._position === 3) {
    345.          this.x = this._parentWindow.x;
    346.          this.x += this._parentWindow.width / 2;
    347.          this.x -= this.width / 2;
    348.         }
    349.         else if (this._position === 4) {
    350.          this.x = this._parentWindow.x;
    351.          this.x += this._parentWindow.width * 7 / 10;
    352.          this.x -= this.width / 2;
    353.         }
    354.         else {
    355.          this.x = this._parentWindow.x + this._parentWindow.width;
    356.          this.x -= this.width;
    357.          this.x -= eval(pMsgHelpPromptBufferX);
    358.         }
    359.         this.x = this.x.clamp(0, Graphics.boxWidth - this.width);
    360.     };
    361.     Window_MsgHelpPrompt.prototype.adjustPositionY = function() {
    362.         if ($gameMessage.positionType() === 0) {
    363.          this.y = this._parentWindow.y + this._parentWindow.height;
    364.          this.y -= eval(pMsgHelpPromptBufferY);
    365.         }
    366.         else {
    367.          this.y = this._parentWindow.y;
    368.          this.y -= this.height;
    369.          this.y += eval(pMsgHelpPromptBufferY);
    370.         }
    371.         if (this.y < 0) {
    372.          this.y = this._parentWindow.y + this._parentWindow.height;
    373.          this.y -= eval(pMsgHelpPromptBufferY);
    374.         }
    375.      
    376.     };
    377.     Window_MsgHelpPrompt.prototype.showPrompt = function() {
    378.         if (this === undefined) { return; }
    379.      
    380.         this.visible = !this.visible;
    381.         if(this.active) {
    382.             this.deactivate();
    383.         }
    384.         else {
    385.             this.activate();
    386.         }
    387.     };
    388.     //=============================================================================
    389.     // Window_MsgTerm
    390.     //=============================================================================
    391.     function Window_MsgTerm() {
    392.         this.initialize.apply(this, arguments);
    393.     }
    394.     Window_MsgTerm.prototype = Object.create(Window_Base.prototype);
    395.     Window_MsgTerm.prototype.constructor = Window_MsgTerm;
    396.     Window_MsgTerm.prototype.initialize = function() {
    397.         var width = pTermWindowWidth;
    398.         var height = Math.max(pTermWindowHeight, this.fittingHeight(1));
    399.         var x = Graphics.boxWidth - width;
    400.         var y = Graphics.boxHeight - height - 164;
    401.         this._wordWrap = true;
    402.      
    403.         Window_Base.prototype.initialize.call(this, x, y, width, height);
    404.         if (pCustomTermWindowskin !== '') {
    405.             this.windowskin = ImageManager.loadSystem(pCustomTermWindowskin);
    406.         }
    407.      
    408.         this._title = '';
    409.         this._text = '';
    410.         this.index = 0;
    411.      
    412.         this._termIds = [];
    413.      
    414.         this.active = false;
    415.         this.visible = false;
    416.     };
    417.     Window_MsgTerm.prototype.setDetails = function() {
    418.         if (this._termIds === undefined || this.index < 0) {
    419.             this._title = '';
    420.             this._text = '';
    421.             this.refresh();
    422.         }
    423.         else {
    424.          
    425.             // Handle odd case where index does not reset.
    426.             if(this.index >= this._termIds.length) {
    427.                 this.index = 0;
    428.             
    429.                 // Odd bug where lengths and term values are not synced.
    430.                 if(this._termIds[0] === -1) {
    431.                     this._title = '';
    432.                     this._text = '';
    433.                     this.refresh();
    434.                 }
    435.             }
    436.          
    437.             var termIndex = this._termIds[this.index];
    438.             // Handle odd case where termIds desync - resulting in a term Id with a bad ID.
    439.             if (termIndex < 0) {
    440.                 termIndex = this._termIds[0];
    441.             }
    442.          
    443.             if (_terms[termIndex] === undefined) {
    444.                 throw "Bad Term index: " + termIndex + "!  There's an error in the last or next message box's terms.";
    445.             }
    446.             this._title = _terms[termIndex]._term + " " + (this.index + 1) + "/" + this._termIds.length;
    447.             this._text = '<WordWrap>' + _terms[termIndex]._desc;
    448.             this.refresh();
    449.         }
    450.     };
    451.     Window_MsgTerm.prototype.clear = function() {
    452.         this.setDetails();
    453.     };
    454.     Window_MsgTerm.prototype.setActiveTerm = function(nextTerm, terms) {
    455.         this._termIds = [];
    456.         this._termIds = terms;
    457.      
    458.         for(var i = 0; i < this._termIds.length; i++) {
    459.             this._termIds[i] = _getIndex(terms[i]);
    460.         }
    461.      
    462.         if (pDebugging) {
    463.             console.log(this._termIds);
    464.             console.log(_activeTerms);
    465.         }
    466.      
    467.         this.setDetails();
    468.      
    469.     };
    470.     // Redefine the minimum number of functions to allow this non-command window to bind input handlers.
    471.     Window_MsgTerm.prototype.setHandler = function(symbol, method) {
    472.         this._handlers[symbol] = method;
    473.     };
    474.     Window_MsgTerm.prototype.isHandled = function(symbol) {
    475.         return !!this._handlers[symbol];
    476.     };
    477.     Window_MsgTerm.prototype.callHandler = function(symbol) {
    478.         if (this.isHandled(symbol)) {
    479.             this._handlers[symbol]();
    480.         }
    481.     };
    482.     Window_MsgTerm.prototype.update = function() {
    483.         Window_Base.prototype.update.call(this);
    484.      
    485.         this.processCursorMove();
    486.         this._stayCount++;
    487.     };
    488.     Window_MsgTerm.prototype.processCursorMove = function() {
    489.         if (Input.isRepeated(pNextTermKey)) {
    490.             if(Input.isTriggered(pNextTermKey) && this._termIds.length > 1) {
    491.                 this.flipSubEntry(1);
    492.             }
    493.         }
    494.         if (Input.isRepeated(pPreviousTermKey)) {
    495.             if(Input.isTriggered(pPreviousTermKey) && this._termIds.length > 1) {
    496.                 this.flipSubEntry(-1);
    497.             }
    498.         }
    499.     };
    500.     Window_MsgTerm.prototype.flipSubEntry = function(pageChange) {
    501.         if (this.visible === false) { return; }
    502.         if(this._termIds.length <= 1) {
    503.             return;
    504.         }
    505.      
    506.         this.index = this.index + pageChange;
    507.         SoundManager.playCursor();
    508.      
    509.         // Cycle over to locked entry before reiterating through sub-entries.
    510.         if (this.index >= this._termIds.length) {
    511.             this.index = 0;
    512.         }
    513.         else if (this.index < 0) {
    514.             this.index = this._termIds.length - 1;
    515.         }
    516.         this.setDetails();
    517.         this.refresh();
    518.     };
    519.     Window_MsgTerm.prototype.refresh = function() {
    520.         this.contents.clear();
    521.         var contentsW = this.width - this.textPadding() - this.standardPadding() * 2;
    522.         var contentsX = this.textPadding();
    523.         var y = 2;
    524.      
    525.         //Title
    526.         this.resetFontSettings();
    527.         this.contents.fontSize = pTitleTxtSz;
    528.         this.contents.fontItalic = pTitleTxtItalic;
    529.         if(pTitleTxtFont !== '') {
    530.             this.contents.fontFace = pTitleTxtFont;
    531.         }
    532.         if(pTitleTxtColor !== '') {
    533.             this.contents.textColor = pTitleTxtColor;
    534.         }
    535.         if(pTitleTxtOutlineColor !== '') {
    536.             this.contents.outlineColor = pTitleTxtOutlineColor;
    537.         }
    538.         this.drawText(this._title, contentsX, y, contentsW, 'center');
    539.      
    540.         //GradientLine
    541.         y += this.lineHeight() + 10;
    542.         this.drawGradientLine(y, contentsW);
    543.         y += 10;
    544.          
    545.         //text
    546.         this.resetFontSettings();
    547.         if(pDetailsTxtFont !== '') {
    548.             this.contents.fontFace = pDetailsTxtFont;
    549.         }
    550.         if(pDetailsTxtOutlineColor !== '') {
    551.             this.contents.outlineColor = pDetailsTxtOutlineColor;
    552.         }
    553.      
    554.         this.contents.fontSize = pDetailsTxtFontSz;
    555.         this.saveCurrentWindowSettings();
    556.         this.drawTextEx(this._text, 0, y);
    557.         this.restoreCurrentWindowSettings();
    558.     };
    559.     Window_MsgTerm.prototype.standardFontSize = function() {
    560.         return pDetailsTxtFontSz;
    561.     };
    562.     Window_MsgTerm.prototype.drawGradientLine = function(y,w) {
    563.         var ctx = this.contents.context;
    564.         var lw = w * 2/3;
    565.         var lx = (w - w * 2/3)/2;
    566.      
    567.         var lineargradient1 = ctx.createLinearGradient(lx,0,w/2,0);
    568.         lineargradient1.addColorStop(0, pGradientLineColorBorder);
    569.         lineargradient1.addColorStop(1, pGradientLineColorCenter);
    570.         ctx.fillStyle = lineargradient1;
    571.         ctx.fillRect(lx, y, lw/2, 2);
    572.      
    573.         var lineargradient2 = ctx.createLinearGradient(w/2,0,lx+lw,0);
    574.         lineargradient2.addColorStop(0, pGradientLineColorCenter);
    575.         lineargradient2.addColorStop(1, pGradientLineColorBorder);
    576.         ctx.fillStyle = lineargradient2;
    577.         ctx.fillRect(w/2, y, lw/2, 2);
    578.     };
    579.     Window_MsgTerm.prototype.toggleTermWindow = function(terms) {
    580.         if (this === undefined) { return; }
    581.      
    582.         this.visible = !this.visible;
    583.         if(this.active) {
    584.             this.deactivate();
    585.             this.index = 0;
    586.         }
    587.         else {
    588.             this.activate();
    589.         }
    590.     };
    591.     //=============================================================================
    592.     // Window_Message
    593.     //=============================================================================
    594.     var BBS_TW_Window_Message_createSubWindows = Window_Message.prototype.createSubWindows;
    595.     Window_Message.prototype.createSubWindows = function() {
    596.         BBS_TW_Window_Message_createSubWindows.call(this);
    597.         this._helpPromptWindow = new Window_MsgHelpPrompt(this);
    598.         this._termWindow = new Window_MsgTerm(this);
    599.         BBS_helpPromptWnd = this._helpPromptWindow;
    600.         BBS_termWnd = this._termWindow;
    601.      
    602.         var scene = SceneManager._scene;
    603.         scene.addChild(this._helpPromptWindow);
    604.         scene.addChild(this._termWindow);
    605.         _hasTerms = false;
    606.     };
    607.     var BBS_TW_Window_Message_startMessage = Window_Message.prototype.startMessage;
    608.     Window_Message.prototype.startMessage = function() {
    609.         this._helpPromptWindow.deactivate();
    610.         this._termWindow.deactivate();
    611.         BBS_TW_Window_Message_startMessage.call(this);
    612.     };
    613.     var BBS_TW_Window_Message_terminateMessage = Window_Message.prototype.terminateMessage;
    614.     Window_Message.prototype.terminateMessage = function() {
    615.         this._helpPromptWindow.deactivate();
    616.         this._termWindow.deactivate();
    617.      
    618.         this._helpPromptWindow.visible = false;
    619.         this._termWindow.visible = false;
    620.         this._termWindow._termIds = [];
    621.         _hasTerms = false;
    622.      
    623.         BBS_TW_Window_Message_terminateMessage.call(this);
    624.     };
    625.     Window_Message.prototype.isXPressed = function() {
    626.         return Input.isRepeated(pHelpKey);
    627.     };
    628.     var BBS_TW_Window_Message_updateInput = Window_Message.prototype.updateInput;
    629.     Window_Message.prototype.updateInput = function() {
    630.         if (this.isXPressed()) {
    631.             if (this._termWindow._termIds.length > 0) {
    632.                 this._termWindow.toggleTermWindow(_activeTerms);
    633.             }
    634.         }
    635.         return BBS_TW_Window_Message_updateInput.call(this);
    636.     };
    637.     var BBS_TW_Window_Message_newPage = Window_Message.prototype.newPage;
    638.     Window_Message.prototype.newPage = function(textState) {
    639.         BBS_TW_Window_Message_newPage.call(this, textState);
    640.      
    641.         if (pDebugging) {
    642.             console.log(_activeTerms);
    643.             console.log(_hasTerms);
    644.         }
    645.      
    646.         if(_hasTerms) {
    647.             BBS_termWnd.setActiveTerm(_activeTerms[0], _activeTerms);
    648.             BBS_helpPromptWnd.refresh(pMsgHelpPromptText, 4);
    649.             _activeTerms = [];
    650.             _hasTerms = false;
    651.         }
    652.     };
    653.     //=============================================================================
    654.     // class Game_Message
    655.     //=============================================================================
    656.     Game_Message.prototype.addText = function(text) {
    657.         // Don't override YEP.
    658.         if ($gameSystem.wordWrap()) text = '<WordWrap>' + text;
    659.          
    660.         var termPrefix = "c[" + pTermColorIndex + "]";
    661.         console.log(termPrefix);
    662.      
    663.         var termPostfix = "c[0]";
    664.         var textIter = text;
    665.          
    666.         var sIdx = 1;
    667.         var fIdx = -1;
    668.         while(sIdx >= 0) {
    669.             sIdx = textIter.indexOf(termPrefix);
    670.             if(sIdx >= 0) {
    671.                 sIdx = sIdx + termPrefix.length;
    672.             }
    673.             else {
    674.                 break;
    675.             }
    676.             
    677.             fIdx = textIter.indexOf(termPostfix) - 1;
    678.             if(fIdx < 0) {
    679.                 fIdx = text.length - 1;
    680.             }
    681.             
    682.             if(pDebugging) {
    683.                 console.log(fIdx);
    684.                 console.log(termPostfix.length);
    685.                 console.log(textIter.length);
    686.             }
    687.          
    688.             // We have a term if we got this far, so process it.
    689.             var termStr = textIter.substr(sIdx, (fIdx - sIdx));
    690.             var alreadyAdded = false;
    691.             for (var i = 0; i < _activeTerms.length; i++)
    692.             {
    693.                 if(_activeTerms[i] === termStr) {
    694.                     alreadyAdded = true;
    695.                     break;
    696.                 }
    697.             }
    698.          
    699.             if(alreadyAdded === false) {
    700.                 _activeTerms.push(termStr);
    701.                 _hasTerms = true;
    702.             }
    703.          
    704.             // Advance to avoid infinite loop over same term tag.
    705.             textIter = textIter.substr(sIdx);
    706.         }
    707.      
    708.         this.add(text);
    709.     };
    710.     //=============================================================================
    711.     // class Scene_Boot
    712.     //=============================================================================
    713.     var BBS_TW_Scene_Boot_create = Scene_Boot.prototype.create;
    714.     Scene_Boot.prototype.create = function() {
    715.         BBS_TW_Scene_Boot_create.call(this);
    716.         this._loadFile(pTermFile, _create);
    717.     };
    718.     Scene_Boot.prototype._loadFile = function(url, callback) {
    719.         var request = new XMLHttpRequest();
    720.         request.open('GET', url);
    721.         request.overrideMimeType('application/json');
    722.         request.onload = function() { callback(JSON.parse(request.responseText)); }
    723.         request.onerror = function() { throw new Error('There was an error loading the file ' + url); }
    724.         request.send();
    725.     };
    726.     var BBS_TW_Scene_Boot_isReady = Scene_Boot.prototype.isReady;
    727.     Scene_Boot.prototype.isReady = function() {
    728.         return !!_terms && BBS_TW_Scene_Boot_isReady.call(this);
    729.     };
    730. })(BBS.TermWindow);
    731. //=============================================================================
    732. // End of File
    733. //=============================================================================
    复制代码







    Change Log
    1.03b
    - Missing term definition error is now much more user-friendly.
    1.03a
    - Fixed plugin parameters not registering properly.  Sorry about that!
    1.03
    - Added option to change color index for Terms (default 4), and option to change keys for Term Window.
    1.02
      - Multiple word terms now supported using _.
    1.01
      - Plugin finished.


    Known Bugs / TODO
    Suggestions, bug reports, and feature requests are welcomed!


    Compatibility Issues
    None known.


    Credit and Thanks
    - Micheal Morris @Blue Booth Studios


    Author's Notes
    Free for non-commercial and commercial usage as long as credit is given.

    a JSON file is also needed: http://www.bluebooth.ca/downloads/Terms.json


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-1 12:54 , Processed in 0.102908 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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