From bce5246157f0fed15f6ebe55c7a56bba481f0e49 Mon Sep 17 00:00:00 2001 From: plasma <6374339+elleonard@users.noreply.github.com> Date: Wed, 17 Apr 2024 04:57:35 +0900 Subject: [PATCH] =?UTF-8?q?2.0.0=20=E5=AE=9F=E8=A3=85=E3=82=92ItemDetail?= =?UTF-8?q?=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=82=8B=20Window=5FSkillD?= =?UTF-8?q?etailMixIn=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SkillDetail/DarkPlasma_SkillDetail.ts | 165 +----------------- src/codes/SkillDetail/SkillDetail.d.ts | 12 +- src/codes/SkillDetail/config.yml | 6 +- src/common/window/withDetailWindow.d.ts | 7 + src/common/window/withDetailWindow.ts | 31 ++++ 5 files changed, 51 insertions(+), 170 deletions(-) create mode 100644 src/common/window/withDetailWindow.d.ts create mode 100644 src/common/window/withDetailWindow.ts diff --git a/src/codes/SkillDetail/DarkPlasma_SkillDetail.ts b/src/codes/SkillDetail/DarkPlasma_SkillDetail.ts index f5954fde..1a3271b4 100644 --- a/src/codes/SkillDetail/DarkPlasma_SkillDetail.ts +++ b/src/codes/SkillDetail/DarkPlasma_SkillDetail.ts @@ -1,4 +1,6 @@ import { settings } from './_build/DarkPlasma_SkillDetail_parameters'; +import { Window_DetailText } from '../../common/window/detailWindow'; +import { Window_WithDetailWindowMixIn } from '../../common/window/withDetailWindow'; const _DataManager_extractMetadata = DataManager.extractMetadata; DataManager.extractMetadata = function (data) { @@ -27,10 +29,8 @@ function Scene_Skill_SkillDetailMixIn(sceneSkill: Scene_Skill) { this._itemWindow.activate(); if (!this._detailWindow.visible) { this._detailWindow.show(); - this._detailWindow.resetCursor(); } else { this._detailWindow.hide(); - this._detailWindow.resetCursor(); } }; @@ -41,7 +41,7 @@ function Scene_Skill_SkillDetailMixIn(sceneSkill: Scene_Skill) { this.addChild(this._detailWindowLayer); this._detailWindow = new Window_SkillDetail(this.detailWindowRect()); this._detailWindowLayer.addChild(this._detailWindow); - this._itemWindow.setDescriptionWindow(this._detailWindow); + this._itemWindow.setDetailWindow(this._detailWindow); }; sceneSkill.detailWindowRect = function () { @@ -68,10 +68,8 @@ function Scene_Battle_SkillDetailMixIn(sceneBattle: Scene_Battle) { this._skillWindow.activate(); if (!this._skillDetailWindow.visible) { this._skillDetailWindow.show(); - this._skillDetailWindow.resetCursor(); } else { this._skillDetailWindow.hide(); - this._skillDetailWindow.resetCursor(); } }; @@ -82,7 +80,7 @@ function Scene_Battle_SkillDetailMixIn(sceneBattle: Scene_Battle) { this.addChild(this._skillDetailWindowLayer); this._skillDetailWindow = new Window_SkillDetail(this.skillDetailWindowRect()); this._skillDetailWindowLayer.addChild(this._skillDetailWindow); - this._skillWindow.setDescriptionWindow(this._skillDetailWindow); + this._skillWindow.setDetailWindow(this._skillDetailWindow); }; sceneBattle.skillDetailWindowRect = function () { @@ -92,164 +90,13 @@ function Scene_Battle_SkillDetailMixIn(sceneBattle: Scene_Battle) { Scene_Battle_SkillDetailMixIn(Scene_Battle.prototype); -Window_CustomKeyHandlerMixIn(settings.openDetailKey, Window_SkillList.prototype, 'detail'); +Window_WithDetailWindowMixIn(settings.openDetailKey, Window_SkillList.prototype); -function Window_SkillDetailMixIn(windowClass: Window_SkillList) { - windowClass.setDescriptionWindow = function (detailWindow) { - this._detailWindow = detailWindow; - this.callUpdateHelp(); - }; - - const _setHelpWindowItem = windowClass.setHelpWindowItem; - windowClass.setHelpWindowItem = function (item) { - _setHelpWindowItem.call(this, item); - if (this._detailWindow) { - this._detailWindow.setItem(item); - } - }; - - const _isCursorMovable = windowClass.isCursorMovable; - windowClass.isCursorMovable = function () { - if (this._detailWindow) { - return _isCursorMovable.call(this) && !this._detailWindow.visible; - } - return _isCursorMovable.call(this); - }; - - const _isOkEnabled = windowClass.isOkEnabled; - windowClass.isOkEnabled = function () { - if (this._detailWindow) { - return _isOkEnabled.call(this) && !this._detailWindow.visible; - } - return _isOkEnabled.call(this); - }; - - const _processCancel = windowClass.processCancel; - windowClass.processCancel = function () { - if (this._detailWindow) { - this._detailWindow.hide(); - this._detailWindow.resetCursor(); - } - _processCancel.call(this); - }; -} - -Window_SkillDetailMixIn(Window_SkillList.prototype); - -class Window_SkillDetail extends Window_Base { - _text: string; - _cursor: number; - _textHeight: number; - _lineCount: number; - - initialize(rect: Rectangle) { - super.initialize(rect); - this._text = ''; - this.opacity = 255; - this._cursor = 0; - this.hide(); - } - - drawDetail(detail: string) { - this.drawTextEx(detail, this.lineWidthMargin ? this.lineWidthMargin() : 0, this.baseLineHeight()); - } - - baseLineHeight(): number { - return -this._cursor * this.lineHeight(); - } - - refresh() { - this.contents.clear(); - this.drawDetail(this._text); - } - - setItem(item: MZ.Skill) { - this.setText(item && item.detail ? item.detail : ''); - } - - setText(text: string) { - if (this._text !== text) { - this._text = text; - this._textHeight = this.calcHeight(); - this._lineCount = Math.floor(this._textHeight / this.lineHeight()); - this.refresh(); - } - } - - calcHeight(): number { - if (this._text) { - return this.textSizeEx(this._text).height; - } - return 0; - } - - /** - * 1画面で表示する最大行数 - */ - maxLine() { - return Math.floor(this.contentsHeight() / this.lineHeight()); - } - - clear() { - this.setText(''); - } - - update() { - super.update(); - this.updateArrows(); - this.processCursorMove(); - } - - updateArrows() { - this.upArrowVisible = this._cursor > 0; - this.downArrowVisible = !this.isCursorMax(); - } - - processCursorMove() { - if (this.isCursorMovable()) { - if (Input.isRepeated('down')) { - this.cursorDown(); - } - if (Input.isRepeated('up')) { - this.cursorUp(); - } - } - } - - isCursorMovable(): boolean { - return this.visible; - } - - cursorUp() { - if (this._cursor > 0) { - this._cursor--; - this.refresh(); - } - } - - cursorDown() { - if (!this.isCursorMax()) { - this._cursor++; - this.refresh(); - } - } - - isCursorMax(): boolean { - return this.maxLine() + this._cursor >= this._lineCount; - } - - resetCursor() { - if (this._cursor > 0) { - this._cursor = 0; - this.refresh(); - } - } +class Window_SkillDetail extends Window_DetailText { } type _Window_SkillDetail = typeof Window_SkillDetail; declare global { - function Window_SkillDetailMixIn(windowClass: Window_SkillList): void; var Window_SkillDetail: _Window_SkillDetail; } -globalThis.Window_SkillDetailMixIn = Window_SkillDetailMixIn; globalThis.Window_SkillDetail = Window_SkillDetail; diff --git a/src/codes/SkillDetail/SkillDetail.d.ts b/src/codes/SkillDetail/SkillDetail.d.ts index 5845a67c..ab0eff99 100644 --- a/src/codes/SkillDetail/SkillDetail.d.ts +++ b/src/codes/SkillDetail/SkillDetail.d.ts @@ -1,4 +1,5 @@ /// +/// /// /// /// @@ -27,14 +28,5 @@ declare interface Scene_Battle { toggleSkillDetailWindow(): void; } -declare interface Window_SkillList { - _detailWindow: Window_SkillDetail - - setDescriptionWindow(detailWindow: Window_SkillDetail): void; -} - -declare interface Window_SkillDetail extends Window_Base { - setItem(item: DataManager.DrawableItem|null): void; - setText(text: string): void; - resetCursor(): void; +declare interface Window_SkillDetail extends Window_DetailText { } diff --git a/src/codes/SkillDetail/config.yml b/src/codes/SkillDetail/config.yml index 4f4c01de..e8f6e707 100644 --- a/src/codes/SkillDetail/config.yml +++ b/src/codes/SkillDetail/config.yml @@ -3,6 +3,10 @@ DarkPlasma_SkillDetail: year: 2022 license: MIT histories: + - date: 2024/04/17 + version: 2.0.0 + description: '実装をItemDetailに合わせる' + - description: 'Window_SkillDetailMixInを削除' - date: 2023/12/09 version: 1.1.0 description: '戦闘中に表示する機能を追加' @@ -36,7 +40,7 @@ DarkPlasma_SkillDetail: dependencies: base: - name: DarkPlasma_CustomKeyHandler - version: 1.1.0 + version: 1.3.0 orderAfter: - name: DarkPlasma_CustomKeyHandler orderBefore: [] diff --git a/src/common/window/withDetailWindow.d.ts b/src/common/window/withDetailWindow.d.ts new file mode 100644 index 00000000..9603c919 --- /dev/null +++ b/src/common/window/withDetailWindow.d.ts @@ -0,0 +1,7 @@ +/// + +declare interface Window_Selectable { + _detailWindow?: Window_DetailText; + + setDetailWindow(detailWindow: Window_DetailText): void; +} diff --git a/src/common/window/withDetailWindow.ts b/src/common/window/withDetailWindow.ts new file mode 100644 index 00000000..ada368aa --- /dev/null +++ b/src/common/window/withDetailWindow.ts @@ -0,0 +1,31 @@ +/// + +export function Window_WithDetailWindowMixIn(openDetailKey: string, windowClass: Window_Selectable) { + Window_CustomKeyHandlerMixIn(openDetailKey, windowClass, 'detail'); + + windowClass.setDetailWindow = function (detailWindow) { + this._detailWindow = detailWindow; + }; + + const _setHelpWindowItem = windowClass.setHelpWindowItem; + windowClass.setHelpWindowItem = function (item) { + _setHelpWindowItem.call(this, item); + this._detailWindow?.setItem(item as DataManager.NoteHolder); + }; + + const _isCursorMovable = windowClass.isCursorMovable; + windowClass.isCursorMovable = function () { + return _isCursorMovable.call(this) && (!this._detailWindow || !this._detailWindow.visible); + }; + + const _isOkEnabled = windowClass.isOkEnabled; + windowClass.isOkEnabled = function () { + return _isOkEnabled.call(this) && (!this._detailWindow || !this._detailWindow.visible); + }; + + const _processCancel = windowClass.processCancel; + windowClass.processCancel = function () { + this._detailWindow?.hide(); + _processCancel.call(this); + }; +} \ No newline at end of file