-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSkillTree_LayoutEx.js
588 lines (517 loc) · 21 KB
/
SkillTree_LayoutEx.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*:
@target MV MZ
@plugindesc Skill Tree Layout Extension v1.3.1
@author unagi ootoro
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/SkillTree_LayoutEx.js
@help
Extend the layout of the skill tree.
By installing this plugin, you will be able to:
-Display the skill name on the skill tree icon
-Display a background image on the skill tree icon
-Add an image to the icon when learning skills
-Display an icon in the skill tree type options
・ Display background image in skill tree scene
[Display skill name on skill tree icon]
Apply "icon_ex" to the icon information.
When using an icon ["icon_ex", icon background image, iconIndex]
iconIndex ... Index of the icon to use
iconIndex is optional. If omitted, the icon set for the skill will be used.
Icon Background image ... Specify the file name of the background image or the index of the background.
When specifying the index, [Background image file name, X-axis index, Y-axis index]
Specify in the format of.
fileName ... The file name of the image. Import the images into the "img / pictures" folder.
[Display icon in skill tree type choice]
By adding icon information to the type information in the skill tree type setting, the icon will be displayed in the options.
In this case, the type information is set in the following format.
[Type type, type name, type description, type enabled / disabled, icon index]
Type Type ... Sets a unique identifier to identify the type in the skill derivation settings.
Type name ... Set the type name to be displayed in the type list window.
Type Description ... Sets the type description to display in the Type List window.
Type Enabled / Disabled ... Specify true to enable the type, false to disable it.
Icon index ... Index of the icon to use
[license]
This plugin is available under the terms of the MIT license.
@param IconXOfs
@type number
@default 5
@desc
Specifies the X coordinate offset of the icon.
@param OpenedImage
@type struct <OpenedImage>
@default {"EnableOpenedImage":"false","FileName":"","XOfs":"0","YOfs":"0"}
@desc
Set the image to be added to the acquired skill.
@param ChangeOpenedTextColor
@type boolean
@default true
@desc
Set to true to change the text color of acquired skills.
@param IconFontSize
@type number
@default 20
@desc
Specifies the font size of the skill's characters.
@param BackgroundImage
@type struct <BackgroundImage>
@default {"FileName":"","BackgroundImage2":"[]","BackgroundImage2XOfs":"240","BackgroundImage2YOfs":"300"}
@desc
Set the background image of the skill tree scene.
*/
/*~struct~OpenedImage:
@param EnableOpenedImage
@type boolean
@default false
@desc
Set to true to add an image to the acquired skill.
@param FileName
@type file
@dir img
@desc
Specify the file name of the image to be added to the acquired skill.
@param XOfs
@type number
@default 0
@desc
Specifies the X coordinate offset of the image to add to the acquired skill.
@param YOfs
@type number
@default 0
@desc
Specifies the Y coordinate offset of the image to add to the acquired skill.
*/
/*~struct~BackgroundImage:
@param FileName
@type file
@dir img
@desc
Specifies the file name of the background image of the skill tree scene.
@param BackgroundImage2
@type struct <BackgroundImage2>[]
@dir img
@desc
Skill Tree Specifies the file name of the image to add to the background image of the scene.
@param BackgroundImage2XOfs
@type number
@default 240
@desc
Specifies the X coordinate offset of the image to add to the background image of the skill tree scene.
@param BackgroundImage2YOfs
@type number
@default 300
@desc
Skill Tree Specifies the Y coordinate offset of the image to add to the background image of the scene.
*/
/*~struct~BackgroundImage2:
@param FileName
@type file
@dir img
@desc
Specifies the file name of the background image of the skill tree scene.
@param ActorId
@type actor
@desc
Specify the actor ID.
*/
/*:ja
@target MV MZ
@plugindesc スキルツリー レイアウト拡張 v1.3.0
@author うなぎおおとろ
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/SkillTree_LayoutEx.js
@help
スキルツリーのレイアウトを拡張します。
このプラグインを導入することによって、次のことができるようになります。
・スキルツリーのアイコンにスキル名を表示
・スキルツリーのアイコンに背景画像を表示
・スキル習得時にアイコンに画像を追加
・スキルツリータイプの選択肢にアイコンを表示
・スキルツリーシーンで背景画像を表示
[スキルツリーのアイコンにスキル名を表示]
アイコン情報に"icon_ex"を適用します。
アイコンを使用する場合 ["icon_ex", アイコン背景画像, iconIndex]
iconIndex...使用するアイコンのインデックス
iconIndexは省略可能です。省略した場合、スキルに設定されているアイコンが使用されます。
アイコン背景画像...背景画像のファイル名、または背景のインデックスを指定します。
インデックス指定を行う場合、[背景画像のファイル名、X軸インデックス、Y軸インデックス]
の形式で指定します。
fileName...画像のファイル名。画像は、「img/pictures」フォルダにインポートしてください。
[スキルツリータイプの選択肢にアイコンを表示]
スキルツリーのタイプの設定で、タイプ情報にアイコン情報を追加することで、選択肢にアイコンが表示されるようになります。
この場合、タイプ情報は次の形式で設定します。
[タイプ種別, タイプ名, タイプの説明, タイプ有効/無効, アイコンのインデックス]
タイプ種別...スキルの派生設定でタイプを識別するためのユニークな識別子を設定します。
タイプ名...タイプ一覧のウィンドウに表示するタイプ名を設定します。
タイプの説明...タイプ一覧のウィンドウに表示するタイプの説明を設定します。
タイプ有効/無効...タイプを有効にする場合は、trueを、無効にする場合は、falseを指定します。
アイコンのインデックス...使用するアイコンのインデックス
[ライセンス]
このプラグインは、MITライセンスの条件の下で利用可能です。
@param IconXOfs
@type number
@default 5
@desc
アイコンのX座標オフセットを指定します。
@param OpenedImage
@type struct<OpenedImage>
@default {"EnableOpenedImage":"false","FileName":"","XOfs":"0","YOfs":"0"}
@desc
習得済みスキルに追加する画像を設定します。
@param ChangeOpenedTextColor
@type boolean
@default true
@desc
trueを設定すると、習得済みスキルの文字の色を変更します。
@param IconFontSize
@type number
@default 20
@desc
スキルの文字のフォントサイズを指定します。
@param BackgroundImage
@type struct<BackgroundImage>
@default {"FileName":"","BackgroundImage2":"[]","BackgroundImage2XOfs":"240","BackgroundImage2YOfs":"300"}
@desc
スキルツリーシーンの背景画像を設定します。
*/
/*~struct~OpenedImage:
@param EnableOpenedImage
@type boolean
@default false
@desc
trueを設定すると、習得済みスキルに画像を追加します。
@param FileName
@type file
@dir img
@desc
習得済みスキルに追加する画像のファイル名を指定します。
@param XOfs
@type number
@default 0
@desc
習得済みスキルに追加する画像のX座標オフセットを指定します。
@param YOfs
@type number
@default 0
@desc
習得済みスキルに追加する画像のY座標オフセットを指定します。
*/
/*~struct~BackgroundImage:
@param FileName
@type file
@dir img
@desc
スキルツリーシーンの背景画像のファイル名を指定します。
@param BackgroundImage2
@type struct<BackgroundImage2>[]
@default []
@dir img
@desc
スキルツリーシーンの背景画像に追加する画像のファイル名を指定します。
@param BackgroundImage2XOfs
@type number
@default 240
@desc
スキルツリーシーンの背景画像に追加する画像のX座標オフセットを指定します。
@param BackgroundImage2YOfs
@type number
@default 300
@desc
スキルツリーシーンの背景画像に追加する画像のY座標オフセットを指定します。
*/
/*~struct~BackgroundImage2:
@param FileName
@type file
@dir img
@desc
スキルツリーシーンの背景画像のファイル名を指定します。
@param ActorId
@type actor
@desc
アクターIDを指定します。
*/
const SkillTree_LayoutExPluginName = document.currentScript.src.match(/^.*\/(.+)\.js$/)[1];
(() => {
"use strict";
class PluginParamsParser {
static parse(params, typeData, predictEnable = true) {
return new PluginParamsParser(predictEnable).parse(params, typeData);
}
constructor(predictEnable = true) {
this._predictEnable = predictEnable;
}
parse(params, typeData, loopCount = 0) {
if (++loopCount > 255) throw new Error("endless loop error");
const result = {};
for (const name in typeData) {
result[name] = this.convertParam(params[name], typeData[name], loopCount);
}
if (!this._predictEnable) return result;
if (typeof params === "object" && !(params instanceof Array)) {
for (const name in params) {
if (result[name]) continue;
const param = params[name];
const type = this.predict(param);
result[name] = this.convertParam(param, type, loopCount);
}
}
return result;
}
convertParam(param, type, loopCount) {
if (typeof type === "string") {
return this.cast(param, type);
} else if (typeof type === "object" && type instanceof Array) {
const aryParam = JSON.parse(param);
if (type[0] === "string") {
return aryParam.map(strParam => this.cast(strParam, type[0]));
} else {
return aryParam.map(strParam => this.parse(JSON.parse(strParam), type[0]), loopCount);
}
} else if (typeof type === "object") {
return this.parse(JSON.parse(param), type, loopCount);
} else {
throw new Error(`${type} is not string or object`);
}
}
cast(param, type) {
switch(type) {
case "any":
if (!this._predictEnable) throw new Error("Predict mode is disable");
return this.cast(param, this.predict(param));
case "string":
return param;
case "number":
if (param.match(/\d+\.\d+/)) return parseFloat(param);
return parseInt(param);
case "boolean":
return param === "true";
default:
throw new Error(`Unknow type: ${type}`);
}
}
predict(param) {
if (param.match(/^\d+$/) || param.match(/^\d+\.\d+$/)) {
return "number";
} else if (param === "true" || param === "false") {
return "boolean";
} else {
return "string";
}
}
}
const typeDefine = {
OpenedImage: {},
BackgroundImage: {
BackgroundImage2: [{}]
},
};
const params = PluginParamsParser.parse(PluginManager.parameters(SkillTree_LayoutExPluginName), typeDefine);
const OpenedImage = params.OpenedImage;
const BackgroundImage = params.BackgroundImage;
const ChangeOpenedTextColor = params.ChangeOpenedTextColor;
const IconXOfs = params.IconXOfs;
const IconFontSize = params.IconFontSize;
const skillTreeParams = PluginParamsParser.parse(PluginManager.parameters(SkillTreePluginName), {});
const IconWidth = skillTreeParams.IconWidth;
const IconHeight = skillTreeParams.IconHeight;
const ViewRectColor = skillTreeParams.ViewRectColor;
const ViewRectOfs = skillTreeParams.ViewRectOfs;
const SkillTreeNodeInfo = SkillTreeClassAlias.SkillTreeNodeInfo;
const SkillTreeNode = SkillTreeClassAlias.SkillTreeNode;
const SkillTreeTopNode = SkillTreeClassAlias.SkillTreeTopNode;
const SkillDataType = SkillTreeClassAlias.SkillDataType;
const SkillTreeMapLoader = SkillTreeClassAlias.SkillTreeMapLoader;
const SkillTreeConfigLoadError = SkillTreeClassAlias.SkillTreeConfigLoadError;
const SkillTreeConfigLoader = SkillTreeClassAlias.SkillTreeConfigLoader;
const SkillTreeData = SkillTreeClassAlias.SkillTreeData;
const SkillTreeManager = SkillTreeClassAlias.SkillTreeManager;
const Scene_SkillTree = SkillTreeClassAlias.Scene_SkillTree;
const Window_TypeSelect = SkillTreeClassAlias.Window_TypeSelect;
const Window_ActorInfo = SkillTreeClassAlias.Window_ActorInfo;
const Window_SkillTreeNodeInfo = SkillTreeClassAlias.Window_SkillTreeNodeInfo;
const Window_SkillTree = SkillTreeClassAlias.Window_SkillTree;
const Window_NodeOpen = SkillTreeClassAlias.Window_NodeOpen;
const SkillTreeView = SkillTreeClassAlias.SkillTreeView;
const _Scene_SkillTree_isReady = Scene_SkillTree.prototype.isReady;
Scene_SkillTree.prototype.isReady = function() {
let ready = true;
if (!_Scene_SkillTree_isReady.call(this)) ready = false;
if (OpenedImage.FileName) {
const openedImage = ImageManager.loadBitmap("img/", OpenedImage.FileName);
if (!openedImage.isReady()) ready = false;
}
if (BackgroundImage.FileName) {
const backgroundImage1 = ImageManager.loadBitmap("img/", BackgroundImage.FileName);
if (!backgroundImage1.isReady()) ready = false;
}
for (const img2 of BackgroundImage.BackgroundImage2) {
if (img2.FileName) {
const backgroundImage2 = ImageManager.loadBitmap("img/", img2.FileName);
if (!backgroundImage2.isReady()) ready = false;
}
}
return ready;
};
SkillTreeNodeInfo.prototype.iconBitmap = function(opened) {
if (this._iconData[0] === "img") {
return ImageManager.loadPicture(this._iconData[1]);
} else if (this._iconData[0] === "icon") {
let iconIndex;
if (this._iconData.length >= 2) {
iconIndex = this._iconData[1];
} else {
iconIndex = this.skill().iconIndex;
}
return this.trimIconset(iconIndex);
} else if (this._iconData[0] === "icon_ex") {
return this.iconExBitmap(opened);
}
throw new Error(`Unknown ${this._iconData[0]}`);
};
SkillTreeNodeInfo.prototype.iconExBitmap = function(opened) {
let iconIndex;
if (this._iconData.length >= 3) {
iconIndex = this._iconData[2];
} else {
iconIndex = this.skill().iconIndex;
}
const iconBitmap = this.trimIconset(iconIndex);
const dstBitmap = new Bitmap(IconWidth, IconHeight);
const dx = IconXOfs;
let dy = (IconHeight - 32) / 2;
if (IconHeight % 2 !== 0) dy -= 1;
if (this._iconData.length >= 2 && this._iconData[1]) {
if (typeof this._iconData[1] === "string") {
const backBitmap = ImageManager.loadPicture(this._iconData[1]);
if (!backBitmap.isReady()) return backBitmap;
dstBitmap.blt(backBitmap, 0, 0, IconWidth, IconHeight, 0, 0);
} else {
const backBitmap = ImageManager.loadPicture(this._iconData[1][0]);
if (!backBitmap.isReady()) return backBitmap;
const x = this._iconData[1][1] * IconWidth;
const y = this._iconData[1][2] * IconHeight;
dstBitmap.blt(backBitmap, x, y, IconWidth, IconHeight, 0, 0);
}
}
dstBitmap.blt(iconBitmap, 0, 0, 32, 32, dx, dy);
const textWidth = IconWidth - 32 - dx - IconXOfs;
if (Utils.RPGMAKER_NAME === "MZ") {
dstBitmap.fontFace = $gameSystem.mainFontFace();
}
dstBitmap.fontSize = IconFontSize;
const iconTextSpace = 5;
if (ChangeOpenedTextColor && opened) {
const tmpTextColor = dstBitmap.textColor;
dstBitmap.textColor = this.crisisColor();
dstBitmap.drawText(this.skill().name, 32 + dx + iconTextSpace, dy, textWidth, 32, "left");
dstBitmap.textColor = tmpTextColor;
} else {
dstBitmap.drawText(this.skill().name, 32 + dx + iconTextSpace, dy, textWidth, 32, "left");
}
return dstBitmap;
};
SkillTreeNodeInfo.prototype.crisisColor = function() {
if (Utils.RPGMAKER_NAME === "MZ") return ColorManager.crisisColor();
const dummyWindow = new Window_Base(0, 0, 0, 0);
return dummyWindow.crisisColor();
}
SkillTreeNode.prototype.iconBitmap = function() {
return this._info.iconBitmap(this.isOpened());
}
SkillTreeView.prototype.viewDrawNode = function(bitmap) {
for (const node of Object.values(this._skillTreeManager.getAllNodes())) {
let [px, py] = SkillTreeView.getPixelXY(node.point);
if (node.isSelectable() || node.isOpened()) {
this.drawIcon(bitmap, node.iconBitmap(), px, py);
} else {
this.drawIcon(bitmap, node.iconBitmap(), px, py, 96);
}
if (node.isOpened()) {
if (OpenedImage.EnableOpenedImage) {
const x = px + OpenedImage.XOfs;
const y = py + OpenedImage.YOfs;
const openedImage = ImageManager.loadBitmap("img/", OpenedImage.FileName);
bitmap.blt(openedImage, 0, 0, openedImage.width, openedImage.height, x, y);
} else {
const x = px - ViewRectOfs;
const y = py - ViewRectOfs;
const width = IconWidth + ViewRectOfs * 2;
const height = IconHeight + ViewRectOfs * 2;
this.drawRect(bitmap, ViewRectColor, x, y, width, height);
}
}
}
}
SkillTreeConfigLoader.prototype.loadTypes = function(actorId) {
let cfgTypes = null;
let typesArray = [];
for (let cfg of this._configData.skillTreeTypes) {
if (cfg.actorId === actorId) {
cfgTypes = cfg.types;
break;
}
}
// if (!cfgTypes) throw new SkillTreeConfigLoadError(`Missing types from actorId:${actorId}`);
if (!cfgTypes) return [];
for (let cfgType of cfgTypes) {
const enabled = (cfgType.length === 3 ? true : cfgType[3]);
const type = new SkillDataType(cfgType[0], actorId, cfgType[1], cfgType[2], enabled);
type.setIconIndex(cfgType[4] ? cfgType[4] : null);
typesArray.push(type);
}
return typesArray;
};
SkillDataType.prototype.setIconIndex = function(iconIndex) {
this._iconIndex = iconIndex;
};
SkillDataType.prototype.iconIndex = function() {
return this._iconIndex;
};
Window_TypeSelect.prototype.drawItem = function(index) {
let rect;
if (Utils.RPGMAKER_NAME === "MZ") {
rect = this.itemLineRect(index);
} else {
rect = this.itemRectForText(index);
}
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
const iconIndex = this._types[index].iconIndex();
if (iconIndex) {
this.drawItemName({ name: this.commandName(index), iconIndex: iconIndex }, rect.x, rect.y);
} else {
this.drawText(this.commandName(index), rect.x, rect.y, rect.width, this.itemTextAlign());
}
};
Scene_SkillTree.prototype.createBackground = function() {
this._backgroundSprite = new Sprite();
if (BackgroundImage.FileName) {
const bitmap1 = ImageManager.loadBitmap("img/", BackgroundImage.FileName);
this._backgroundSprite.bitmap = bitmap1;
const sprite = new Sprite();
sprite.x = BackgroundImage.BackgroundImage2XOfs;
sprite.y = BackgroundImage.BackgroundImage2YOfs;
this._backgroundSprite.addChild(sprite);
this._backgroundSprite2 = sprite;
this.addChild(this._backgroundSprite);
} else {
this._backgroundFilter = new PIXI.filters.BlurFilter();
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this._backgroundSprite.filters = [this._backgroundFilter];
this.addChild(this._backgroundSprite);
this.setBackgroundOpacity(192);
}
};
Scene_SkillTree.prototype.getBackgroundImage2 = function(actorId) {
const img2 = BackgroundImage.BackgroundImage2.find(img2 => img2.ActorId === actorId);
if (img2) return ImageManager.loadBitmap("img/", img2.FileName);
return null;
};
const _Scene_SkillTree_updateActor = Scene_SkillTree.prototype.updateActor;
Scene_SkillTree.prototype.updateActor = function() {
_Scene_SkillTree_updateActor.call(this);
this.updateBackgroundImage2();
};
Scene_SkillTree.prototype.updateBackgroundImage2 = function() {
if (!this._backgroundSprite2) return;
const backgroundImage2 = this.getBackgroundImage2($gameParty.menuActor().actorId());
this._backgroundSprite2.bitmap = backgroundImage2;
};
})();