forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_EventNames.js
448 lines (400 loc) · 14.4 KB
/
MrTS_EventNames.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
//=============================================================================
// MrTS_EventNames.js
//=============================================================================
/*:
* @plugindesc Allows events to show their names above them.
* @author Mr. Trivel
*
* @param Default Range
* @desc How close player has to be to see event's name in tiles.
* Default: 5
* @default 5
*
* @param Font Size
* @desc Default Font size for event's name.
* Default: 24
* @default 24
*
* @param Font Name
* @desc Default Font for event's name.
* Default: GameFont
* @default GameFont
*
* @param Fade
* @desc Should event names/pictures/icons have a fade effect? True/False
* Default: True
* @default True
*
* @param Fade Timer
* @desc How quickly should by fade happen by default? In frames. 60 = 1s
* Default: 30
* @default 30
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial and non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.6
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Event Comment Tags
* --------------------------------------------------------------------------------
* - If tag is in comment, it'll display according to event's page.
* Use "Comment..." command under Flow Control for those tags.
*
* <EventNameText: TEXT>
* <EventNamePicture: NAME, WIDTH, HEIGHT>
* <EventNameRange: RANGE>
* <EventNameOffsetX: PIXELS>
* <EventNameOffsetY: PIXELS>
* <EventNameFont: FONT>
* <EventNameFontSize: SIZE>
*
* TEXT - Text to show above event, can use text codes, too - \v[10]
* NAME - Picture Name (Pictures stored in img\system)
* WIDTH - Picture width in pixels
* HEIGHT - Picture height in pixels
* RANGE - How close player has to be to see the event name/picture.
* PIXELS - How big is the offset from default position in pixels
* FONT - Different font for text
* SIZE - Font Size
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* EventNames Hide - Disables event names from showing
* EventNames Show - Enables event names for showing
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.6 - Removed event notetags. Tags are written in comments only.
* - Changed comment tags.
* - Removed Icon tags.
* - Added X and Y offset for Text/Pictures.
* - Added Font name, size tags.
* - Added plugin commands.
* - Fixed names being shown out of range for short moment after scene change.
* 1.5 - Added Icon drawing, cleaned up the code.
* 1.4 - Added Fade in and Fade out effects for event names and pictures.
* - Fixed layering of pictures and names. They're properly above now.
* 1.3 - Crash fix
* 1.2 - Bug fix
* 1.1 - Added Pictures above event heads.
* Added Picture and Names changing when event switches pages.
* 1.0 - Release
*/
(function() {
//-----------------------------------------------------------------------------
// Parameters
//
var parameters = PluginManager.parameters('MrTS_EventNames');
var paramDefaultRange = Number(parameters['Default Range'] || 5);
var paramFontSize = Number(parameters['Font Size'] || 24);
var paramFontName = String(parameters['Font Name'] || "GameFont");
var paramFade = (parameters['Fade'] || "true").toLowerCase() === "true";
var paramFadeTimer = Number(parameters['Fade Timer'] || 30);
var regexEventNameText = /<EventNameText:[ ]*(.*)>/i;
var regexEventNamePicture = /<EventNamePicture:[ ]*(\w+),[ ]*(\d+),[ ]*(\d+)>/i;
var regexEventNameRange = /<EventNameRange:(.*)>/i;
var regexEventNameOffsetX = /<EventNameOffsetX:(.*)>/i;
var regexEventNameOffsetY = /<EventNameOffsetY:(.*)>/i;
var regexEventNameFont = /<EventNameFont:(.*)>/i;
var regexEventNameFontSize = /<EventNameFontSize:(.*)>/i;
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "eventnames") {
switch (args[0].toUpperCase())
{
case 'SHOW':
{
$gameSystem.showEventNames();
} break;
case 'HIDE':
{
$gameSystem.hideEventNames();
} break;
}
}
};
//-----------------------------------------------------------------------------
// Game_System
//
var _Game_System_initialize = Game_System.prototype.initialize
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this._showEventNames = true;
};
Game_System.prototype.showEventNames = function() {
this._showEventNames = true;
};
Game_System.prototype.hideEventNames = function() {
this._showEventNames = false;
};
Game_System.prototype.getEventNamesShown = function() {
return this._showEventNames;
};
//-----------------------------------------------------------------------------
// Game_Event
//
var _GameEvent_initialize = Game_Event.prototype.initialize;
Game_Event.prototype.initialize = function(mapId, eventId) {
_GameEvent_initialize.call(this, mapId, eventId);
this.updateEventNameData();
};
Game_Event.prototype.resetEventNameData = function() {
this._eventNameText = null;
this._eventNamePicture = null;
this._eventNamePictureWidth = null;
this._eventNamePictureHeight = null;
this._eventNameRange = paramDefaultRange;
this._eventNameOffsetX = 0;
this._eventNameOffsetY = 0;
this._eventNameFont = paramFontName;
this._eventNameFontSize = paramFontSize;
};
Game_Event.prototype.updateEventNameData = function() {
this._overheadPageIndex = this._pageIndex;
if (!this.page()) return;
this.resetEventNameData();
if (this.list())
{
for (action of this.list())
{
if (action.code == "108" || action.code == "408") {
var a = action.parameters[0];
var matchText = regexEventNameText.exec(a);
if (matchText) {
this._eventNameText = matchText[1];
continue;
}
var matchPicture = regexEventNamePicture.exec(a);
if (matchPicture) {
this._eventNamePicture = matchPicture[1];
this._eventNamePictureWidth = Number(matchPicture[2]);
this._eventNamePictureHeight = Number(matchPicture[2]);
continue;
}
var matchRange = regexEventNameRange.exec(a);
if (matchRange) {
this._eventNameRange = matchRange[1];
continue;
}
var matchOffsetX = regexEventNameOffsetX.exec(a);
if (matchOffsetX) {
this._eventNameOffsetX = matchOffsetX[1];
continue;
}
var matchOffsetY = regexEventNameOffsetY.exec(a);
if (matchOffsetY) {
this._eventNameOffsetY = matchOffsetY[1];
continue;
}
var matchFont = regexEventNameFont.exec(a);
if (matchFont) {
this._eventNameFont = matchFont[1];
continue;
}
var matchFontSize = regexEventNameFontSize.exec(a);
if (matchFontSize) {
this._eventNameFontSize = matchFontSize[1];
continue;
}
}
} // for
} // if
this._eventNameNeedUpdate = true;
};
var _GameEvent_update = Game_Event.prototype.update;
Game_Event.prototype.update = function()
{
_GameEvent_update.call(this);
if (this._pageIndex != this._overheadPageIndex)
this.updateEventNameData();
};
Game_Event.prototype.getEventNameNeedUpdate = function() {
return this._eventNameNeedUpdate;
};
Game_Event.prototype.setEventNameNeedUpdate = function(value) {
this._eventNameNeedUpdate = value;
};
Game_Event.prototype.createEventNameWindow = function() {
return true;
};
Game_Character.prototype.getEventNameNeedUpdate = function() {
return false;
};
Game_Character.prototype.createEventNameWindow = function() {
return false;
};
//-----------------------------------------------------------------------------
// Sprite_Character
//
var _SpriteCharacter_initialize = Sprite_Character.prototype.initialize;
Sprite_Character.prototype.initialize = function(character) {
_SpriteCharacter_initialize.call(this, character);
if (this._character.createEventNameWindow())
{
this._eventNameWindow = new Window_EventName(0, 0, 40, 40);
this._eventNameAdded = false;
}
};
var _SpriteCharacter_update = Sprite_Character.prototype.update;
Sprite_Character.prototype.update = function() {
_SpriteCharacter_update.call(this);
if (this._character.createEventNameWindow())
{
this.updateEventNameData();
this.updateEventNameOther();
if (!this._eventNameAdded) {
this.parent.parent.addChild(this._eventNameWindow);
this._eventNameAdded = true;
}
}
};
Sprite_Character.prototype.updateEventNameData = function() {
if (this._eventNameWindow && (this._character.getEventNameNeedUpdate() || this._eventNameWindow._needUpdate))
{
this._character.setEventNameNeedUpdate(false);
this._eventNameWindow._needUpdate = false;
this._eventNameWindow.setText(this._character._eventNameText);
this._eventNameWindow.setPicture(this._character._eventNamePicture);
this._eventNameWindow.setRange(this._character._eventNameRange);
this._eventNameWindow.setOffsetX(this._character._eventNameOffsetX);
this._eventNameWindow.setOffsetY(this._character._eventNameOffsetY);
this._eventNameWindow.setFont(this._character._eventNameFont);
this._eventNameWindow.setFontSize(this._character._eventNameFontSize);
if (this._character._eventNamePictureWidth)
this._eventNameWindow.width = this._character._eventNamePictureWidth;
if (this._character._eventNamePictureHeight)
this._eventNameWindow.height = this._character._eventNamePictureHeight;
this._eventNameWindow.refresh();
if (this._eventNameWindow._range < Math.abs(($gamePlayer.x - this._character.x)) + Math.abs(($gamePlayer.y - this._character.y)))
this._eventNameWindow.contentsOpacity = 0;
else
this._eventNameWindow.contentsOpacity = 255;
}
};
Sprite_Character.prototype.updateEventNameOther = function() {
if (this._eventNameWindow) {
this._eventNameWindow.x = this.x - this._eventNameWindow.width/2 + this._eventNameWindow._offsetX;
this._eventNameWindow.y = this.y -this._eventNameWindow.height/2 - 12 - this._frame.height + this._eventNameWindow._offsetY;
if (!$gameSystem.getEventNamesShown())
{
this._eventNameWindow.visible = false;
this._eventNameOpacityNeed = true;
return;
}
else if ($gameSystem.getEventNamesShown() && this._eventNameOpacityNeed)
{
this._eventNameOpacityNeed = false;
this._eventNameWindow.visible = true;
if (this._eventNameWindow._range < Math.abs(($gamePlayer.x - this._character.x)) + Math.abs(($gamePlayer.y - this._character.y)))
this._eventNameWindow.contentsOpacity = 0;
else
this._eventNameWindow.contentsOpacity = 255;
}
if (this._eventNameWindow._range < Math.abs(($gamePlayer.x - this._character.x)) + Math.abs(($gamePlayer.y - this._character.y)))
{
if (paramFade)
{
if (this._eventNameWindow.contentsOpacity !== 0)
{
this._eventNameWindow.contentsOpacity -= 255/paramFadeTimer;
if (this._eventNameWindow.contentsOpacity < 0) this._eventNameWindow.contentsOpacity = 0;
}
}
else this._eventNameWindow.visible = false;
}
else {
if (paramFade)
{
if (this._eventNameWindow.contentsOpacity !== 255)
{
this._eventNameWindow.contentsOpacity += 255/paramFadeTimer;
if (this._eventNameWindow.contentsOpacity > 255) this._eventNameWindow.contentsOpacity = 255;
}
}
else this._eventNameWindow.visible = true;
}
}
};
//--------------------------------------------------------------------------
// Window_EventName
//
function Window_EventName() {
this.initialize.apply(this, arguments);
};
Window_EventName.prototype = Object.create(Window_Base.prototype);
Window_EventName.prototype.constructor = Window_EventName;
Window_EventName.prototype.initialize = function(x, y, w, h) {
this._fontSize = paramFontSize;
this._font = paramFontName;
this._range = paramDefaultRange;
this._text = null;
this._picture = null;
this._offsetX = 0;
this._offsetY = 0;
Window_Base.prototype.initialize.call(this, x, y, w, h);
this.opacity = 0;
this._needUpdate = true;
};
Window_EventName.prototype.refresh = function() {
if (this._text) {
this.width = this.textWidthEx(this._text);
this.height = this._fontSize < 32 ? 32 : this._fontSize + 4;
this.createContents();
this.drawTextEx(this._text, 0, 0);
}
if (this._picture) {
this.createContents();
this.contents = ImageManager.loadSystem(this._picture);
}
};
Window_EventName.prototype.setFont = function(font) {
this._font = font;
};
Window_EventName.prototype.setFontSize = function(fontSize) {
this._fontSize = Number(fontSize);
};
Window_EventName.prototype.setRange = function(range) {
this._range = Number(range);
};
Window_EventName.prototype.setText = function(text) {
this._text = text;
};
Window_EventName.prototype.setPicture = function(name) {
this._picture = name;
};
Window_EventName.prototype.setOffsetX = function(offsetX) {
this._offsetX = Number(offsetX);
};
Window_EventName.prototype.setOffsetY = function(offsetY) {
this._offsetY = Number(offsetY);
};
Window_EventName.prototype.standardFontSize = function() {
return this._fontSize;
};
Window_EventName.prototype.standardFontFace = function() {
return this._font;
};
Window_EventName.prototype.textWidthEx = function(text) {
return this.drawTextEx(text, 0, this.contents.height);
};
Window_EventName.prototype.standardPadding = function() {
return 0;
};
Window_EventName.prototype.textPadding = function() {
return 0;
};
})();