From 7384eee8f098d94adc9b43578887990ae49c1eae Mon Sep 17 00:00:00 2001
From: plasma <6374339+elleonard@users.noreply.github.com>
Date: Fri, 13 Oct 2023 13:38:27 +0900
Subject: [PATCH] =?UTF-8?q?1.1.0=20=E6=92=AE=E5=BD=B1=E6=99=82=E3=81=AB?=
=?UTF-8?q?=E3=83=95=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5=E3=83=97=E3=83=AC?=
=?UTF-8?q?=E3=83=93=E3=83=A5=E3=83=BC=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD?=
=?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DarkPlasma_ScreenshotGallery.ts | 167 ++++++++++++++++--
.../ScreenshotGallery/ScreenshotGallery.d.ts | 24 +++
src/codes/ScreenshotGallery/config.yml | 116 ++++++++++++
3 files changed, 290 insertions(+), 17 deletions(-)
diff --git a/src/codes/ScreenshotGallery/DarkPlasma_ScreenshotGallery.ts b/src/codes/ScreenshotGallery/DarkPlasma_ScreenshotGallery.ts
index 8faef824..cdf39269 100644
--- a/src/codes/ScreenshotGallery/DarkPlasma_ScreenshotGallery.ts
+++ b/src/codes/ScreenshotGallery/DarkPlasma_ScreenshotGallery.ts
@@ -8,22 +8,24 @@ function SceneManager_ScreenshotGalleryMixIn(sceneManager: typeof SceneManager)
sceneManager.saveScreenshot = function (format) {
const dataURLFormat = format === "jpg" ? "image/jpeg" : `image/${format}`;
const now = new Date();
+ const name = `${
+ now.getFullYear()
+ }-${
+ (now.getMonth()+1).toString().padStart(2, '0')
+ }-${
+ now.getDate().toString().padStart(2, '0')
+ }-${
+ now.getHours().toString().padStart(2, '0')
+ }${
+ now.getMinutes().toString().padStart(2, '0')
+ }${
+ now.getSeconds().toString().padStart(2, '0')
+ }${
+ now.getMilliseconds().toString().padStart(4, '0')
+ }`;
+ ImageManager.setLatestScreenshotName(name);
this.saveImage(
- `${
- now.getFullYear()
- }-${
- (now.getMonth()+1).toString().padStart(2, '0')
- }-${
- now.getDate().toString().padStart(2, '0')
- }-${
- now.getHours().toString().padStart(2, '0')
- }${
- now.getMinutes().toString().padStart(2, '0')
- }${
- now.getSeconds().toString().padStart(2, '0')
- }${
- now.getMilliseconds().toString().padStart(4, '0')
- }`,
+ name,
format,
this.snap().canvas.toDataURL(dataURLFormat, 1).replace(/^.*,/, '')
);
@@ -42,6 +44,14 @@ function SceneManager_ScreenshotGalleryMixIn(sceneManager: typeof SceneManager)
SceneManager_ScreenshotGalleryMixIn(SceneManager);
function ImageManager_ScreenshotGalleryMixIn(imageManager: typeof ImageManager) {
+ imageManager.setLatestScreenshotName = function (name) {
+ this._latestSceenshotName = name;
+ };
+
+ imageManager.loadLatestScreenshot = function () {
+ return this.loadScreenshot(this._latestSceenshotName);
+ };
+
imageManager.loadScreenshot = function (filename) {
return this.loadBitmap(`${settings.directory}/`, filename);
};
@@ -54,7 +64,8 @@ function ImageManager_ScreenshotGalleryMixIn(imageManager: typeof ImageManager)
}
const filenames: string[] = fs.readdirSync(dirpath, { withFileTypes: true })
.filter((dirent: any) => dirent.isFile())
- .map((dirent: any) => (dirent.name as string).replace(/\..+$/, ""));
+ .map((dirent: any) => (dirent.name as string).replace(/\..+$/, ""))
+ .slice(0, settings.maxView);
return filenames.map(filename => this.loadScreenshot(filename)).reverse();
};
@@ -95,21 +106,135 @@ function Bitmap_ScreenshotGalleryMixIn(bitmap: Bitmap) {
}
_startLoading.call(this);
};
+
+ bitmap.drawFrame = function (x: number, y: number, width: number, height: number, thick: number, color: string) {
+ this._context.strokeStyle = color;
+ this._context.lineWidth = thick;
+ this._context.strokeRect(x, y, width, height);
+ this._context.restore();
+ this._baseTexture.update();
+ };
}
Bitmap_ScreenshotGalleryMixIn(Bitmap.prototype);
function Scene_ScreenshotGalleryMixIn(sceneClass: Scene_Base) {
+ const _start = sceneClass.start;
+ sceneClass.start = function () {
+ _start.call(this);
+ /**
+ * 最前表示のためここで作る
+ */
+ if (settings.preview.show) {
+ this.createPreviewContainer();
+ }
+ };
+
+ sceneClass.createPreviewContainer = function () {
+ this._previewContainer = new Sprite();
+ this._previewContainer.bitmap = new Bitmap(
+ settings.preview.rect.width + settings.preview.frameWidth * 2,
+ settings.preview.rect.height + settings.preview.frameWidth * 2
+ );
+ this._previewContainer.x = settings.preview.rect.x - settings.preview.frameWidth;
+ this._previewContainer.y = settings.preview.rect.y - settings.preview.frameWidth;
+ this._previewContainer.bitmap.drawFrame(
+ 0,
+ 0,
+ settings.preview.rect.width + settings.preview.frameWidth * 2,
+ settings.preview.rect.height + settings.preview.frameWidth * 2,
+ settings.preview.frameWidth,
+ ColorManager.textColor(0)
+ );
+ this.addChild(this._previewContainer);
+ this._previewSprite = new Sprite();
+ this._previewSprite.x = settings.preview.frameWidth;
+ this._previewSprite.y = settings.preview.frameWidth;
+ this._previewSprite.scale.x = settings.preview.rect.width/Graphics.width;
+ this._previewSprite.scale.y = settings.preview.rect.height/Graphics.height;
+ this._previewContainer.addChild(this._previewSprite);
+ this._previewContainer.hide();
+ };
+
+ sceneClass.startPreview = function () {
+ this._previewDuration = settings.preview.duration;
+ this._previewSprite.bitmap = ImageManager.loadLatestScreenshot();
+ this._previewContainer.show();
+ };
+
+ sceneClass.hidePreview = function () {
+ if (this._previewContainer.visible) {
+ this._previewContainer.hide();
+ }
+ };
+
+ sceneClass.startFlash = function () {
+ this._flashDuration = settings.flash.duration;
+ this._flashOpacity = settings.flash.power;
+ this.updateFlash();
+ };
+
+ sceneClass.clearFlash = function () {
+ if (this._flashDuration > 0) {
+ this._flashDuration = 0;
+ this.updateColorFilter();
+ }
+ };
+
const _update = sceneClass.update;
sceneClass.update = function () {
_update.call(this);
if (Input.isTriggered(settings.key)) {
+ /**
+ * 直前の撮影時のフラッシュが写り込まないようにする
+ */
+ this.clearFlash();
+ this.hidePreview();
SceneManager.saveScreenshot(settings.format);
if (settings.se.name) {
AudioManager.playSe(settings.se);
+ this.startFlash();
+ }
+ if (settings.preview.show) {
+ this.startPreview();
+ }
+ }
+ this.updateFlash();
+ this.updatePreview();
+ };
+
+ sceneClass.updateColorFilter = function () {
+ this._colorFilter.setBlendColor(this.blendColor());
+ };
+
+ sceneClass.updateFlash = function () {
+ if (this._flashDuration > 0) {
+ this._flashOpacity *= (this._flashDuration - 1) / this._flashDuration;
+ this._flashDuration--;
+ }
+ };
+
+ sceneClass.updatePreview = function () {
+ if (this._previewDuration > 0) {
+ this._previewDuration--;
+ if (this._previewDuration <= 0) {
+ this._previewContainer.hide();
}
}
};
+
+ sceneClass.blendColor = function () {
+ if (this._fadeDuration === 0 && this._flashDuration > 0) {
+ return [
+ settings.flash.red,
+ settings.flash.green,
+ settings.flash.blue,
+ this._flashOpacity,
+ ];
+ }
+ const c = this._fadeWhite ? 255 : 0;
+ return [c, c, c, this._fadeOpacity];
+ };
}
settings.scenes
@@ -180,9 +305,17 @@ class Window_ScreenshotGallery extends Window_Selectable {
return Math.floor(Graphics.height / (Graphics.width / this.itemWidth()));
}
+ public itemRectWithPadding(index: number): Rectangle {
+ const rect = super.itemRectWithPadding(index);
+ const padding = this.itemPadding();
+ rect.y += padding;
+ rect.height -= padding * 2;
+ return rect;
+ }
+
public drawItem(index: number): void {
if (this._images[index]) {
- const rect = this.itemRect(index);
+ const rect = this.itemRectWithPadding(index);
const bitmap = this._images[index];
this.contents.blt(
bitmap,
diff --git a/src/codes/ScreenshotGallery/ScreenshotGallery.d.ts b/src/codes/ScreenshotGallery/ScreenshotGallery.d.ts
index d328ac86..d6ac70c7 100644
--- a/src/codes/ScreenshotGallery/ScreenshotGallery.d.ts
+++ b/src/codes/ScreenshotGallery/ScreenshotGallery.d.ts
@@ -1,12 +1,19 @@
///
///
+declare interface Bitmap {
+ drawFrame(x: number, y: number, width: number, height: number, thick: number, color: string): void;
+}
+
declare interface SceneManager {
saveScreenshot(format: string): void;
saveImage(filename: string, format: string, base64Image: string): void;
}
declare namespace ImageManager {
+ var _latestSceenshotName: string;
+ function setLatestScreenshotName(name: string): void
+ function loadLatestScreenshot(): Bitmap;
function loadAllScreenshot(): Bitmap[];
function loadScreenshot(filename: string): Bitmap;
function validScreenshotCount(): number;
@@ -15,3 +22,20 @@ declare namespace ImageManager {
declare namespace StorageManager {
function screenshotDirPath(): string;
}
+
+declare interface Scene_Base {
+ _flashDuration: number;
+ _flashOpacity: number;
+ _previewContainer: Sprite;
+ _previewDuration: number;
+ _previewSprite: Sprite;
+
+ createPreviewContainer(): void;
+ blendColor(): [number, number, number, number];
+ startFlash(): void;
+ updateFlash(): void;
+ clearFlash(): void;
+ startPreview(): void;
+ updatePreview(): void;
+ hidePreview(): void;
+}
diff --git a/src/codes/ScreenshotGallery/config.yml b/src/codes/ScreenshotGallery/config.yml
index 5b7115e0..0d262917 100644
--- a/src/codes/ScreenshotGallery/config.yml
+++ b/src/codes/ScreenshotGallery/config.yml
@@ -3,6 +3,11 @@ DarkPlasma_ScreenshotGallery:
year: 2023
license: MIT
histories:
+ - date: 2023/10/13
+ version: 1.1.0
+ description: '撮影時にフラッシュ・プレビューする機能を追加'
+ - description: '表示最大数設定を追加'
+ - description: '一覧での表示サイズを調整'
- date: 2023/03/12
version: 1.0.0
description: '公開'
@@ -57,11 +62,41 @@ DarkPlasma_ScreenshotGallery:
volume: 90
pitch: 100
pan: 0
+ - param: flash
+ text:
+ ja: フラッシュ
+ type: Flash
+ default:
+ red: 255
+ green: 255
+ blue: 255
+ power: 170
+ frame: 30
- param: directory
text:
ja: 保存先フォルダ名
type: string
default: screenshot
+ - param: maxView
+ text:
+ ja: 表示最大数
+ desc:
+ ja: スクショギャラリーでの表示最大数
+ type: number
+ default: 30
+ - param: preview
+ text:
+ ja: プレビュー設定
+ type: Preview
+ default:
+ show: true
+ frameWidth: 4
+ duration: 60
+ rect:
+ x: 16
+ y: 16
+ width: 102
+ height: 78
commands:
- command: sceneScreenshot
text:
@@ -94,6 +129,87 @@ DarkPlasma_ScreenshotGallery:
default: 0
max: 100
min: -100
+ Flash:
+ - param: red
+ text:
+ ja: 赤
+ type: number
+ default: 255
+ max: 255
+ min: 0
+ - param: green
+ text:
+ ja: 緑
+ type: number
+ default: 255
+ max: 255
+ min: 0
+ - param: blue
+ text:
+ ja: 青
+ type: number
+ default: 255
+ max: 255
+ min: 0
+ - param: power
+ text:
+ ja: 強さ
+ type: number
+ default: 170
+ max: 255
+ min: 0
+ - param: duration
+ text:
+ ja: 時間(フレーム)
+ type: number
+ default: 30
+ min: 1
+ Preview:
+ - param: show
+ text:
+ ja: プレビューを表示する
+ type: boolean
+ default: true
+ - param: frameWidth
+ text:
+ ja: フレーム幅
+ type: number
+ default: 4
+ - param: duration
+ text:
+ ja: 表示時間(フレーム)
+ type: number
+ default: 60
+ - param: rect
+ text:
+ ja: 位置とサイズ
+ type: Rectangle
+ default:
+ x: 16
+ y: 16
+ width: 102
+ height: 78
+ Rectangle:
+ - param: x
+ text:
+ ja: X座標
+ type: number
+ default: 16
+ - param: y
+ text:
+ ja: Y座標
+ type: number
+ default: 16
+ - param: width
+ text:
+ ja: 幅
+ type: number
+ default: 102
+ - param: height
+ text:
+ ja: 高さ
+ type: number
+ default: 78
dependencies:
base: []
orderAfter: []