Skip to content

Commit

Permalink
1.0.3 詳細説明ウィンドウの実装を共通ファイルに切り出す
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed Apr 16, 2024
1 parent 5a399db commit 9c5f0f9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 75 deletions.
79 changes: 4 additions & 75 deletions src/codes/ItemDetail/DarkPlasma_ItemDetail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="./ItemDetail.d.ts" />

import { settings } from "./_build/DarkPlasma_ItemDetail_parameters";
import { Window_DetailText } from '../../common/window/detailWindow';

function Scene_Item_DetailMixIn(sceneItem: Scene_Item) {
const _create = sceneItem.create;
Expand Down Expand Up @@ -76,80 +77,8 @@ function Window_ItemList_DetailMixIn(windowClass: Window_ItemList) {

Window_ItemList_DetailMixIn(Window_ItemList.prototype);

class Window_ItemDetail extends Window_Scrollable {
_text: string;

initialize(rect: Rectangle) {
super.initialize(rect);
this._text = '';
this.hide();
}

setItem(item: MZ.Item|MZ.Weapon|MZ.Armor|null) {
this.setText(String(item?.meta.detail || ''));
}

setText(text: string) {
if (this._text !== text) {
this._text = text;
this.refresh();
}
}

drawDetail(detail: string) {
this.drawTextEx(detail, 0, this.baseLineY());
}

baseLineY() {
return -(this.scrollBaseY()/this.scrollBlockHeight()) * this.lineHeight();
}

public scrollBlockHeight(): number {
return this.lineHeight();
}

public overallHeight(): number {
return this.textSizeEx(this._text).height + settings.heightAdjustment;
}

public paint(): void {
this.contents.clear();
this.drawDetail(this._text);
}

refresh() {
this.paint();
}

public update(): void {
super.update();
this.processCursorMove();
}

processCursorMove() {
if (this.isCursorMovable()) {
if (Input.isRepeated('down')) {
this.cursorDown();
}
if (Input.isRepeated('up')) {
this.cursorUp();
}
}
}

isCursorMovable() {
return this.visible;
}

cursorDown() {
if (this.scrollY() <= this.maxScrollY()) {
this.smoothScrollDown(1);
}
}

cursorUp() {
if (this.scrollY() > 0) {
this.smoothScrollUp(1);
}
class Window_ItemDetail extends Window_DetailText {
heightAdjustment(): number {
return settings.heightAdjustment;
}
}
3 changes: 3 additions & 0 deletions src/codes/ItemDetail/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ DarkPlasma_ItemDetail:
year: 2023
license: MIT
histories:
- date: 2024/04/17
version: 1.0.3
description: '詳細説明ウィンドウの実装を共通ファイルに切り出す'
- date: 2023/10/20
version: 1.0.2
description: '型の指定を修正 (動作に影響なし)'
Expand Down
81 changes: 81 additions & 0 deletions src/common/window/detailWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export class Window_DetailText extends Window_Scrollable {
_text: string;

initialize(rect: Rectangle) {
super.initialize(rect);
this._text = '';
this.hide();
}

setItem(item: DataManager.NoteHolder|null) {
this.setText(String(item?.meta.detail || ''));
}

setText(text: string) {
if (this._text !== text) {
this._text = text;
this.refresh();
}
}

drawDetail(detail: string) {
this.drawTextEx(detail, 0, this.baseLineY());
}

baseLineY() {
return -(this.scrollBaseY()/this.scrollBlockHeight()) * this.lineHeight();
}

public scrollBlockHeight(): number {
return this.lineHeight();
}

public overallHeight(): number {
return this.textSizeEx(this._text).height + this.heightAdjustment();
}

heightAdjustment() {
return 32;
}

public paint(): void {
this.contents.clear();
this.drawDetail(this._text);
}

refresh() {
this.paint();
}

public update(): void {
super.update();
this.processCursorMove();
}

processCursorMove() {
if (this.isCursorMovable()) {
if (Input.isRepeated('down')) {
this.cursorDown();
}
if (Input.isRepeated('up')) {
this.cursorUp();
}
}
}

isCursorMovable() {
return this.visible;
}

cursorDown() {
if (this.scrollY() <= this.maxScrollY()) {
this.smoothScrollDown(1);
}
}

cursorUp() {
if (this.scrollY() > 0) {
this.smoothScrollUp(1);
}
}
}

0 comments on commit 9c5f0f9

Please sign in to comment.