From 8a7729367b8d402f3177b08bb2278fae251d9ec7 Mon Sep 17 00:00:00 2001 From: xian18 <44394537+xian18@users.noreply.github.com> Date: Mon, 1 Jan 2024 23:28:59 +0800 Subject: [PATCH] Refactor actor state and buff icons in battle status window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 未测试 --- js/plugins/YEP_BattleStatusWindow.js | 75 +++++++++++++++++++--------- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/js/plugins/YEP_BattleStatusWindow.js b/js/plugins/YEP_BattleStatusWindow.js index c76752a..2629b18 100755 --- a/js/plugins/YEP_BattleStatusWindow.js +++ b/js/plugins/YEP_BattleStatusWindow.js @@ -468,10 +468,10 @@ Yanfly.BSW.Window_BattleStatus_initialize = Window_BattleStatus.prototype.initia Window_BattleStatus.prototype.initialize = function () { this._guageHeight = Imported.YEP_CoreEngine ? this.gaugeHeight() : 6; this._guageHeight = Math.max(16, this._guageHeight); - this._actorsStateIcon = []; // [index] = [nextRenderStartIndex ,icons] - this._actorsStateIconMaxTick = 90; - this._actorsStateIconCurrentTick = 0; - this._actorsStateIconNum = 4; + this._actorsStateBuff = []; // [index] = [nextRenderStartIndex ,icons] + this._actorsStateBuffMaxTick = 90; + this._actorsStateBuffCurrentTick = 0; + this._actorsStateBuffNum = 4; Yanfly.BSW.Window_BattleStatus_initialize.call(this); }; @@ -544,7 +544,19 @@ Window_BattleStatus.prototype.drawItem = function (index) { this.drawGuages(index, actor); // this.drawActorActionIcon(actor, rect.x + rect.width - Window_Base._iconWidth, rect.y); - this._actorsStateIcon[index] = [0, actor.allIcons()]; + this._actorsStateBuff[index] = { + startIndex: 0, + states: actor.states().filter(function (state) { + return state.iconIndex > 0; + }), + buffs: actor._buffs + .map(function (_, index) { + return index; + }) + .filter(function (index) { + return actor.isBuffOrDebuffAffected(index); + }), + }; this.drawActorIcons(index); }; @@ -738,38 +750,55 @@ Window_BattleStatus.prototype.update = function () { }; Window_BattleStatus.prototype.updateStateIcons = function () { - this._actorsStateIconCurrentTick++; - if (this._actorsStateIconCurrentTick < this._actorsStateIconMaxTick) return; + this._actorsStateBuffCurrentTick++; + if (this._actorsStateBuffCurrentTick < this._actorsStateBuffMaxTick) return; - this._actorsStateIconCurrentTick = 0; + this._actorsStateBuffCurrentTick = 0; for (var index = 0; index < $gameParty.battleMembers().length; index++) { this.drawActorIcons(index); } }; Window_BattleStatus.prototype.drawActorIcons = function (index) { - var startIcons = this._actorsStateIcon[index][0]; - var icons = this._actorsStateIcon[index][1]; var rect = this.stateAreaRect(index); + var actor = $gameParty.battleMembers()[index]; - this.contents.clearRect(rect.x, rect.y, rect.width, rect.height); - if (icons.length <= 0) { - return; - } + var states = this._actorsStateBuff[index]["states"]; + var buffs = this._actorsStateBuff[index]["buffs"]; + var startIndex = this._actorsStateBuff[index]["startIndex"]; + var endIndex = startIndex + this._actorsStateBuffNum; var iconWidth = Window_Base._iconWidth; var x = rect.x + 2; var y = rect.y; - for (var i = 0; i < this._actorsStateIconNum; i++) { - if (icons[i + startIcons] === undefined) continue; - var icon = icons[i + startIcons]; - this.drawIcon(icon, x, y); - x += iconWidth; - } - this._actorsStateIcon[index][0] += this._actorsStateIconNum; - if (this._actorsStateIcon[index][0] >= icons.length) { - this._actorsStateIcon[index][0] = 0; + this.contents.clearRect(rect.x, rect.y, rect.width, rect.height); + + states.slice(startIndex, endIndex).forEach(function (state, i) { + var wx = x + iconWidth * i; + var wy = y; + + this.drawIcon(state.iconIndex, wx, wy); + this.drawStateTurns(actor, state, wx, wy); + this.drawStateCounter(actor, state, wx, wy); + }, this); + + x = x + iconWidth * states.slice(startIndex, endIndex).length; + startIndex = startIndex < states.length ? 0 : startIndex - states.length; + endIndex = endIndex < states.length ? 0 : endIndex - states.length; + + buffs.slice(startIndex, endIndex).forEach(function (buff, i) { + var wx = x + iconWidth * i; + var wy = y; + + this.drawIcon(actor.buffIconIndex(actor.buff(buff), buff), wx, wy); + this.drawBuffTurns(actor, buff, wx, wy); + this.drawBuffRate(actor, buff, wx, wy); + }, this); + + this._actorsStateBuff[index]["startIndex"] += this._actorsStateBuffNum; + if (this._actorsStateBuff[index]["startIndex"] >= states.length + buffs.length) { + this._actorsStateBuff[index]["startIndex"] = 0; } };