Skip to content

Instantly share code, notes, and snippets.

@typebird
Created October 29, 2021 07:06
Show Gist options
  • Save typebird/ba8908cbaabbbf159c280e169e755d48 to your computer and use it in GitHub Desktop.
Save typebird/ba8908cbaabbbf159c280e169e755d48 to your computer and use it in GitHub Desktop.
This snippet allows most RPG Maker MZ's options to be display one by one.
//=============================================================================
// RPG Maker MZ - Snippet: Display Options One by One
//=============================================================================
/*:
* @target MZ
* @author 竹鳥
* @plugindesc (v1.0.0) 令所有選擇項目逐一顯示。
*
* @help snippet_DisplayOptionsOneByOne.js
*
* # 功能簡介
*
* 讓所有繼承(或間接繼承)了 Window_Selectable 的窗口,如事件選擇、選單及道具欄
* 等,均改為逐一顯示。
*
* 如果你不想要以插件的形式修改,而是直接改寫官方程式,請以下方註解標記的
* 「正文」區塊,覆蓋到 rmmz_windows.js 中
* Window_Selectable.prototype.drawAllItems 函數,並將 _waitTime 改為需要的數字。
*
* @param wait_time
* @type number
* @default 60
* @text 時間間隔(毫秒)
* @desc 每個物件的顯示時間間隔毫秒數。使用文字以執行表達式。
*
*/
(() => {
const filename = "snippet_DisplayOptionsOneByOne"
const userParams = PluginManager.parameters(filename)["wait_time"]
const _waitTime = !userParams || userParams === ""
? 60
: isNaN(Number(userParams))
? (new Function(`try{ return ${userParams} } catch(err){ console.error(err); return 60 }`))()
: Number(userParams)
//=============================================================================
// 以下正文
//=============================================================================
Window_Selectable.prototype.drawAllItems = function () {
const sleep = ms => new Promise(res => setTimeout(res, ms))
const topIndex = this.topIndex()
for (let i = 0; i < this.maxVisibleItems(); i++) {
const index = topIndex + i
if (index < this.maxItems())
Promise.resolve((i || 1) * _waitTime)
.then(sleep)
.then(() => {
this.drawItemBackground(index)
this.drawItem(index)
})
}
}
//=============================================================================
// 以上正文
//=============================================================================
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment