-
Notifications
You must be signed in to change notification settings - Fork 1
/
TF_ScreenUtil.js
257 lines (231 loc) · 7.85 KB
/
TF_ScreenUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
//========================================
// TF_ScreenUtil.js
// Version :0.1.1.0
// For : RPGツクールMV (RPG Maker MV)
// -----------------------------------------------
// Copyright : Tobishima-Factory 2020
// Website : http://tonbi.jp
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//========================================
/*:ja
* @plugindesc 各種画面サイズ設定と画面固定
* @author とんび@鳶嶋工房
*
* @param screenWidth
* @desc ゲーム画面全体の幅(本体設定: 816ピクセル)
* @type number
* @default 1280
*
* @param screenHeight
* @desc ゲーム画面全体の高さ(本体設定: 624ピクセル)
* @type number
* @default 720
*
* @param boxWidth
* @desc ウィンドウ表示部分の幅(本体設定: 816ピクセル)
* @type number
* @default 1080
*
* @param boxHeight
* @desc ウィンドウ表示部分の高さ(本体設定: 624ピクセル)
* @type number
* @default 720
*
* @help
* 多分、screenWidth・screenHeight と boxWidth・boxHeight の値が違っていると
* レイアウトが崩れる箇所が[名前入力の処理]などに残ってると思います。
*
* 【タグ】
* [マップ]のメモにタグを書き込むと、そのマップはスクロールせず固定となります。
* <TF_fixedMap:0 0>
*
* 【注意点】
* プロジェクトフォルダの package.json の width, height のサイズを揃えておくと
* 起動時のウィンドウのパタパタした挙動がなくなります。
* また「RPGアツマール」などのサイトで公開する場合、
* サイト側に画面サイズ設定を揃えておく必要があります。
*
* TODO :
* 固定のON/OFFするコマンド
*
* 利用規約 : MITライセンス
*/
( function() {
'use strict';
const PLUGIN_NAME = 'TF_ScreenUtil';
const PARAM_TRUE = 'true';
let _isMapFixed, _FixedX, _FixedY;
/**
* パラメータを受け取る
*/
const TF = ( () => {
const parameters = PluginManager.parameters( PLUGIN_NAME );
return JSON.parse( JSON.stringify(
parameters,
( key, value ) => {
try { return JSON.parse( value ); } catch( e ) { }
return value;
}
) );
} )();
/**
* @param {RPG.MetaData} object メタタグを持ったJSON
* @param {String} tagName タグ名
* @returns {String} タグの引数部分
*/
function getMetaValue( object, tagName ) {
return object.meta.hasOwnProperty( tagName ) ? object.meta[ tagName ] : undefined;
}
/**
* 文字列の座標を数値配列にして返す。
* @param {String} str スペース区切りの座標
* @returns {Array<Number>} 座標 x, y の配列
*/
function string2pos( str ) {
const args = str.split( ' ' );
if( args.length !== 2 ) throw PLUGIN_NAME + ': no parameter';
const x = parseFloat( args[ 0 ] );
const y = parseFloat( args[ 1 ] );
if( isNaN( x ) || isNaN( y ) ) throw PLUGIN_NAME + ': NaN';
return [ x, y ];
}
/*---- Game_Player ----*/
const _Game_Player_updateScroll = Game_Player.prototype.updateScroll;
Game_Player.prototype.updateScroll = function( lastScrolledX, lastScrolledY ) {
if( _isMapFixed ) return;
_Game_Player_updateScroll.apply( this, arguments );
};
/*---- Scene_Map ----*/
const _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call( this );
// マップメモ固定座標の指定メタタグの処理
// 例: <TF_fixedMap:0.84 0.2>
const fixedMapArgs = getMetaValue( $dataMap, 'TF_fixedMap' );
if( fixedMapArgs === undefined ) {
_isMapFixed = false;
} else {
[ _FixedX, _FixedY ] = string2pos( fixedMapArgs );
_isMapFixed = true;
}
if( _isMapFixed ) {
$gameMap.setDisplayPos( _FixedX, _FixedY );
}
};
/*==== 画面設定 ====*/
/*--- SceneManager ---*/
const _SceneManager_initialize = SceneManager.initialize;
SceneManager.initialize = function() {
this._screenWidth = TF.screenWidth;
this._screenHeight = TF.screenHeight;
this._boxWidth = TF.boxWidth;
this._boxHeight = TF.boxHeight;
_SceneManager_initialize.call( this );
};
/*--- WindowLayer ---*/
/**
* コアスクリプトのバグ対応で、メソッドごと入れ替え
*/
WindowLayer.prototype._maskWindow = function( window, shift ) {
this._windowMask._currentBounds = null;
this._windowMask.boundsDirty = true;
var rect = this._windowRect;
rect.x = this.x + shift.x + window.x;
rect.y = this.y + shift.y + window.y + window.height / 2 * ( 1 - window._openness / 255 );// this.y が this.x になっていた
rect.width = window.width;
rect.height = window.height * window._openness / 255;
};
/*--- Spriteset_Base ---*/
/**
* コアスクリプトのバグ対応
*/
const _Spriteset_Base_createPictures = Spriteset_Base.prototype.createPictures;
Spriteset_Base.prototype.createPictures = function() {
_Spriteset_Base_createPictures.call( this );
this._pictureContainer.setFrame( 0, 0, TF.screenWidth, TF.screenHeight );// 表示位置を原点に戻す
};
/*--- Scene_Title ---*/
const _Scene_Title_start = Scene_Title.prototype.start;
Scene_Title.prototype.start = function() {
_Scene_Title_start.call( this );
fitToScreen( this._backSprite1 );
fitToScreen( this._backSprite2 );
};
/**
* スプライトを画面いっぱいに拡大
* @param {Sprite} sprite スプライト
*/
function fitToScreen( sprite ) {
if( !sprite.bitmap ) return;
if( !sprite.bitmap.width ) {
return setTimeout( fitToScreen.bind( this, sprite ), 5 ); // ビットマップの読み込み確認
}
const scaleX = Graphics.width / sprite.bitmap.width;
const scaleY = Graphics.height / sprite.bitmap.height;
if( 1 < scaleX ) sprite.scale.x = scaleX;
if( 1 < scaleY ) sprite.scale.y = scaleY;
centerSprite( sprite );
}
/**
* スプライトを画面中央に表示
* @param {Sprite} sprite スプライト
*/
function centerSprite( sprite ) {
sprite.x = Graphics.width / 2;
sprite.y = Graphics.height / 2;
sprite.anchor.x = 0.5;
sprite.anchor.y = 0.5;
}
/*--- Spriteset_Battle ---*/
const TYPE_STAGE = 1; // ステージ(地面)背景
const TYPE_SET = 2; // セット(建物)背景
Spriteset_Battle.prototype.createBattleback = function() {
this._back1Sprite = new Sprite_Battleback( this.battleback1Name(), TYPE_STAGE );
this._back2Sprite = new Sprite_Battleback( this.battleback2Name(), TYPE_SET );
fitToScreen( this._back1Sprite );
fitToScreen( this._back2Sprite );
this._battleField.addChild( this._back1Sprite );
this._battleField.addChild( this._back2Sprite );
};
Spriteset_Battle.prototype.updateBattleback = function() { };
/*--- Sprite_Battleback ---*/
class Sprite_Battleback extends Sprite {
constructor( bitmapName, type ) {
super();
this.bitmap = this.createBitmap( bitmapName, type );
}
/**
* 背景画像の生成・読み込み
*/
createBitmap( bitmapName, type ) {
if( bitmapName === '' ) {
return new Bitmap( Graphics.width, Graphics.height );
} else if( type === TYPE_STAGE ) {
return ImageManager.loadBattleback1( bitmapName );
} else {
return ImageManager.loadBattleback2( bitmapName );
}
}
}
/*--- Sprite_Enemy ---*/
const DEFAULT_SCREEN_WIDTH = 816;
const DEFAULT_SCREEN_HEIGHT = 624;
/**
* 敵位置をスクリーンサイズに合わせて調整
*/
const _Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
Sprite_Enemy.prototype.setBattler = function( battler ) {
_Sprite_Enemy_setBattler.call( this, battler );
if( !this._enemy._alteredScreenY ) {
this._homeY += Math.floor( ( Graphics.height - DEFAULT_SCREEN_HEIGHT ) / 2 );
this._enemy._screenY = this._homeY;
this._enemy._alteredScreenY = true;
}
if( $gameSystem.isSideView() || this._enemy._alteredScreenX ) return;
this._homeX += ( Graphics.width - DEFAULT_SCREEN_WIDTH ) / 2;
this._enemy._screenX = this._homeX;
this._enemy._alteredScreenX = true;
};
} )();