Skip to content

Commit

Permalink
2.0.0 実装をItemDetailに合わせる Window_SkillDetailMixInを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed Apr 16, 2024
1 parent bb3374f commit bce5246
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 170 deletions.
165 changes: 6 additions & 159 deletions src/codes/SkillDetail/DarkPlasma_SkillDetail.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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();
}
};

Expand All @@ -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 () {
Expand All @@ -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();
}
};

Expand All @@ -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 () {
Expand All @@ -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;
12 changes: 2 additions & 10 deletions src/codes/SkillDetail/SkillDetail.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference path="../../typings/rmmz.d.ts" />
/// <reference path="../../common/window/detailWindow.d.ts" />
/// <reference path="../AutoLineBreak/AutoLineBreak.d.ts" />
/// <reference path="../CustomKeyHandler/CustomKeyHandler.d.ts" />
/// <reference path="../CustomKeyHandler/CustomKeyHandlerExport.d.ts" />
Expand Down Expand Up @@ -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 {
}
6 changes: 5 additions & 1 deletion src/codes/SkillDetail/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '戦闘中に表示する機能を追加'
Expand Down Expand Up @@ -36,7 +40,7 @@ DarkPlasma_SkillDetail:
dependencies:
base:
- name: DarkPlasma_CustomKeyHandler
version: 1.1.0
version: 1.3.0
orderAfter:
- name: DarkPlasma_CustomKeyHandler
orderBefore: []
Expand Down
7 changes: 7 additions & 0 deletions src/common/window/withDetailWindow.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference path="./detailWindow.d.ts" />

declare interface Window_Selectable {
_detailWindow?: Window_DetailText;

setDetailWindow(detailWindow: Window_DetailText): void;
}
31 changes: 31 additions & 0 deletions src/common/window/withDetailWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// <reference path="./withDetailWindow.d.ts" />

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);
};
}

0 comments on commit bce5246

Please sign in to comment.