-
Notifications
You must be signed in to change notification settings - Fork 54
/
StatPolygon.js
371 lines (326 loc) · 11.8 KB
/
StatPolygon.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
//==============================================================================
// StatPolygon.js
//==============================================================================
var Imported = Imported || {};
Imported.StatPolygon = true;
/*:
* @plugindesc A fancy radar chart for your stats!
* @author mjshi
*
* @param ---Configuration---
*
* @param Stats to Draw
* @desc See help for more info
* @default 2, 3, 4, 5, 6
*
* @param Max Stat Value
* @desc Arbitrary visual limit for each respective stat so that the graph looks prettier
* @default 30, 30, 30, 30, 50
*
* @param ---Points---
*
* @param Center X
* @desc X coordinate of the center.
* @default 100
*
* @param Center Y
* @desc Y coordinate of the center.
* @default 360
*
* @param Radius
* @desc Twice this is the width of the entire thing.
* @default 60
*
* @param ---Text Parameters---
*
* @param Text Parameters
* @desc Which text parameters to list on the side. See help for more info.
* @default 2, 3, 4, 5, 6, 7
*
* @param Text Param Y Shift
* @desc How much to shift up or down the text parameters by.
* @default 0
*
* @param Make Way!
* @desc How much to indent the text parameters by.
* @default 175
*
* @param Make Way, Part 2
* @desc How much to indent the text parameter values by.
* @default 100
*
* @param ---Colors---
*
* @param Primary Color
* @desc Color of the foreground (hex color, see colorpicker.com)
* @default #B0E0E6
*
* @param Secondary Color
* @desc Color of the background (hex color, see colorpicker.com)
* @default #84aaff
*
* @param ---Lines---
*
* @param Number of Segments
* @desc Number of ticks on the axes
* @default 4
*
* @param Line Weight
* @desc Thickness of the background lines
* @default 1
*
* @param Line Weight 2
* @desc Thickness of the foreground lines
* @default 1
*
* @param ---Fill---
*
* @param Fill foreground
* @desc (y/n) Should the plugin fill in the foreground shape?
* @default y
*
* @param Foreground Fill Opacity
* @desc Decimal value from 0 (transparent) to 1
* @default 0.5
*
* @param ---Text---
*
* @param Use Text Labels
* @desc (y/n) Show text labels for parameters
* @default y
*
* @param Text Color
* @desc Color of the text (hex color, see colorpicker.com)
* @default #84aaff
*
* @param Font Size Decrement
* @desc How much to decrement the font size by
* @default 7
*
* @param Radial Text Offset
* @desc How much to offset the text by from the center
* @default 20
*
* @param X/Y Text Offset
* @desc (x, y) How much to offset the text from its radial position
* @default -15, -15
*
* @param ---Icon---
*
* @param Use Icon Labels
* @desc (y/n) Show text labels for parameters
* @default n
*
* @param Icon Indexes
* @desc Indexes of the icons. Should correlate to the 'Stats to Draw' parameter.
* @default 76, 81, 79, 147, 82
*
* @param Radial Icon Offset
* @desc How much to offset the icon by from the center
* @default 23
*
* @param X/Y Icon Offset
* @desc (x, y) How much to offset the icon from its radial position
* @default -15, -15
*
* @param
* @help
* ------------------------------------------------------------------------------
* Stat Polygon v1.0 by mjshi
* Free for both commercial and non-commercial use, with credit.
* ------------------------------------------------------------------------------
* Valid Stats
* ------------------------------------------------------------------------------
* These will be drawn counterclockwise, starting from the top.
*
* 0 = MaxHP 2 = ATK 4 = MAT 6 = AGI
* 1 = MaxMP 3 = DEF 5 = MDF 7 = LUK
*
* ------------------------------------------------------------------------------
* ** This plugin IS compatible with Yanfly Status Core! **
* Place it below the Status Core plugin.
* ------------------------------------------------------------------------------
* You just need to change the Center X, Center Y, and Make Way! values a bit.
* Just so you can see the graph, I recommend setting both the centers to 100,
* and Make Way! to at LEAST 200. You'll need to make additional adjustments
* from there.
*
* ------------------------------------------------------------------------------
*
* > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
* try my best to help you!
*/
//Initialize global variables
(function () {
/* BEGIN */
var params = PluginManager.parameters("StatPolygon");
var stats = params["Stats to Draw"].split(", ").map(Number);
var maxStats = params["Max Stat Value"].split(", ").map(Number);
var textParams = params["Text Parameters"].split(", ").map(Number);
var textParamsY = Number(params["Text Param Y Shift"]);
var centerX = Number(params["Center X"]);
var centerY = Number(params["Center Y"]);
var radius = Number(params["Radius"]);
var indent = Number(params["Make Way!"]);
var indent2 = Number(params["Make Way, Part 2"]);
var primaryColor = params["Primary Color"];
var secondaryColor = params["Secondary Color"];
var numSegments = Number(params["Number of Segments"]);
var lineWeight = Number(params["Line Weight"]);
var lineWeight2 = Number(params["Line Weight 2"]);
var shouldFill = params["Fill foreground"] === "y";
var fillOpacity = Number(params["Foreground Fill Opacity"]);
var useText = params["Use Text Labels"] === "y";
var textOffset = {
radial: Number(params["Radial Text Offset"]),
x: Number((params["X/Y Text Offset"].split(", "))[0]),
y: Number((params["X/Y Text Offset"].split(", "))[1])
}
var fontDecrement = Number(params["Font Size Decrement"]);
var textColor = params["Text Color"];
var useIcon = params["Use Icon Labels"] === "y";
var iconIndexes = params["Icon Indexes"].split(", ").map(Number);
var iconOffset = {
radial: Number(params["Radial Icon Offset"]),
x: Number((params["X/Y Icon Offset"].split(", "))[0]),
y: Number((params["X/Y Icon Offset"].split(", "))[1])
}
var sides = stats.length;
Window_Status.prototype.drawParameters = function(x, y) {
x += indent;
y += textParamsY;
/* most compatibility errors will be in this segment */
var lineHeight = this.lineHeight();
for (var i = 0; i < textParams.length; i++) {
this.changeTextColor(this.systemColor());
this.drawText(TextManager.param(textParams[i]), x, y + lineHeight * i, 160);
this.resetTextColor();
this.drawText(this._actor.param(textParams[i]), x + indent2, y + lineHeight * i, 60, 'right');
}
/* Possible Error Segment End */
//Begin edits
//draw polygon
this.contents.SPolyDrawStatPolygon(this._actor);
//draw text
if (useText) {
this.changeTextColor(textColor);
this.contents.fontSize = this.standardFontSize() - fontDecrement;
for (var i = 0; i < stats.length; i++) {
this.drawText(TextManager.param(stats[i]), centerX + textOffset.x + (radius + textOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + textOffset.y - (radius + textOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides), 160);
}
this.resetFontSettings();
}
//draw icon
if (useIcon) {
for (var i = 0; i < stats.length; i++) {
this.drawIcon(iconIndexes[i], centerX + iconOffset.x + (radius + iconOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + iconOffset.y - (radius + iconOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides));
}
}
};
if (Imported.YEP_StatusMenuCore) {
Window_StatusInfo.prototype.drawParameters = function() {
var dx = indent;
var dy = this.lineHeight() / 2;
var dw = this.contents.width - indent;
var dh = this.lineHeight();
var dw2;
var text;
this.changeTextColor(this.systemColor());
this.drawText(Yanfly.Param.StatusGraphText, dx, dy, dw, 'center');
dy = this.lineHeight();
dx = indent;
dw -= this.standardPadding() * 2;
for (var i = 2; i < 8; ++i) {
dy += this.lineHeight();
var rate = this.drawParamGauge(dx, dy, dw, i);
this.changeTextColor(this.systemColor());
this.drawText(TextManager.param(i), dx + 4, dy, dw - 4);
text = Yanfly.Util.toGroup(this._actor.param(i))
this.changeTextColor(this.normalColor());
dw2 = dw * rate;
this.drawText(text, dx, dy, dw2 - 4, 'right');
}
this.contents.SPolyDrawStatPolygon(this._actor);
//draw text
if (useText) {
this.changeTextColor(textColor);
this.contents.fontSize = this.standardFontSize() - fontDecrement;
for (var i = 0; i < stats.length; i++) {
this.drawText(TextManager.param(stats[i]), centerX + textOffset.x + (radius + textOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + textOffset.y - (radius + textOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides), 160);
}
this.resetFontSettings();
}
//draw icon
if (useIcon) {
for (var i = 0; i < stats.length; i++) {
this.drawIcon(iconIndexes[i], centerX + iconOffset.x + (radius + iconOffset.radial) * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), centerY + iconOffset.y - (radius + iconOffset.radial) * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides));
}
}
};
}
Bitmap.prototype.SPolyDrawStatPolygon = function(actor) {
var cx = centerX, cy = centerY;
//draw graph background
for (var i = 0; i < numSegments; i++) this.SPolyDrawRegularPolygon(cx, cy, radius - (i * radius/numSegments), sides, secondaryColor, lineWeight);
//draw lines
for (var i = 0; i < sides; i++) this.SPolyDrawLine(cx, cy, cx + radius * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides), cy - radius * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides), secondaryColor, lineWeight);
//draw stat polygon
var points = [];
for (var i = 0; i < stats.length; i++) {
points.push(cx + Math.min(actor.param(stats[i]) / maxStats[i], 1) * radius * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides));
points.push(cy - Math.min(actor.param(stats[i]) / maxStats[i], 1) * radius * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides));
}
this.SPolyDrawPolygon(points, primaryColor, lineWeight2);
};
Bitmap.prototype.SPolyDrawRegularPolygon = function(cx, cy, radius, sides, color, weight) {
var context = this._context;
context.save();
context.beginPath();
context.moveTo(cx, cy - radius);
for (var i = 1; i <= sides; i++) {
context.lineTo(
cx + radius * Math.cos(Math.PI/2 + i * 2 * Math.PI / sides),
cy - radius * Math.sin(Math.PI/2 + i * 2 * Math.PI / sides)
);
}
context.strokeStyle = color;
context.lineWidth = weight;
context.stroke();
context.restore();
this._setDirty();
};
Bitmap.prototype.SPolyDrawPolygon = function(points, color, weight) {
var context = this._context;
context.save();
context.beginPath();
context.moveTo(points[0], points[1]);
for (var i = 2; i < points.length; i+=2) context.lineTo(points[i], points[i+1]);
context.lineTo(points[0], points[1]);
context.strokeStyle = color;
context.lineWidth = weight;
context.stroke();
if (shouldFill) {
context.globalAlpha = fillOpacity;
context.fillStyle = color;
context.fill();
context.globalAlpha = 1;
}
context.restore();
this._setDirty();
};
Bitmap.prototype.SPolyDrawLine = function(x1, y1, x2, y2, color, weight) {
if (weight === undefined) weight = 1;
if (color === undefined) color = "#000000";
var context = this._context;
context.save();
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.strokeStyle = color;
context.lineWidth = weight;
context.stroke();
context.restore();
this._setDirty();
};
/* END */
})();