-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathAkeaAnimatedCursor.js
385 lines (361 loc) · 14.8 KB
/
AkeaAnimatedCursor.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
//==========================================================================
// Akea Animated Cursor
//----------------------------------------------------------------------------
// 09/11/20 | Version: 1.0.1
// This software is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc Akea Animated Cursor version: 1.0.1
* @author Reisen (Mauricio Pastana)
* @url https://www.patreon.com/raizen884
* @orderAfter AkeaAnimatedBattleSystem
* @orderBefore AkeaBattleCamera
*
* @help Akea Animated Cursor - this plugins is under zlib license
* For support and new plugins join our discord server! https://discord.gg/Kh9XXZ2
* Want to support new creations? be a patreon!
* For this plugin, you will only need to configure its parameters and what it is asking,
* for each item. Do remember to configure all of them!
*
* @param defaultWindow
* @type boolean
* @text Default Windows
* @desc Check here if you want to still display actor/enemy windows.
*
* @param MainCursor
* @type struct<CursorConfig>
* @text Main Cursor Configuration
* @desc Configure here the main Cursor.
*
* @param SecondCursor
* @type struct<CursorConfig>
* @text Main Cursor Configuration
* @desc Configure here the secondary Cursor, you can leave it blank if you use only 1 image.
*
* @param actorText
* @type struct<TextConfig>
* @text Actor Names Configuration
* @desc Configure here the text of the actor.
*
* @param enemyText
* @type struct<TextConfig>
* @text Enemy Names Configuration
* @desc Configure here the text of the enemy.
*/
/*~struct~TextConfig:
* @param textColor
* @type text
* @text Text Color
* @default FFFFFF
* @desc The text color in hexadecimal
* @param outlineColor
* @type text
* @text Outline Color
* @default 000000
* @desc The outline color in hexadecimal
* @param outlineWidth
* @type number
* @text Outline Width
* @default 3
* @decimals 0
* @desc The outline width of the font
* @param fontSize
* @type number
* @text Font Size
* @decimals 0
* @default 20
* @desc The size of the font, 0 to disable names.
* @param x
* @type number
* @text X Position
* @decimals 0
* @default 0
* @min -1000
* @desc The position of the text for correction in X.
* @param y
* @type number
* @text Y Position
* @decimals 0
* @default 0
* @min -1000
* @desc The position of the text for correction in Y.
*/
/*~struct~CursorConfig:
* @param cursorImage
* @type file
* @dir img/akea/
* @text Cursor Image
* @desc Image of the Cursor
* @param maxMotion
* @type number
* @text Maximum motion
* @default 6
* @min 0
* @decimals 0
* @desc How much the cursor will move in pixels
* @param motionSpeed
* @type number
* @decimals 2
* @min 0
* @text Speed of the movement
* @default 0.5
* @desc How fast will the movement be
* @param y
* @type number
* @text y offset
* @default 25
* @min -1000
* @decimals 0
* @desc Correction value for the cursor
* @param rotation
* @type number
* @decimals 2
* @min 0
* @default 0.05
* @desc Rotation speed of the cursor on its axis, 0 for none.
*/
// DON'T MODIFY THIS PART!!!
var Akea = Akea || {};
Akea.AnimatedCursor = Akea.AnimatedCursor || {};
Akea.AnimatedCursor.VERSION = [1, 0, 1];
ImageManager.loadAkea = function (filename) {
return this.loadBitmap("img/akea/", filename);
};
//////////////////////////////////////////////////////////////////////////////////////////////////
// Akea Animated Cursor
//////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
(() => {
const pluginName = "AkeaAnimatedCursor";
const parameters = PluginManager.parameters('AkeaAnimatedCursor');
Akea.AnimatedCursor.MainCursor = JSON.parse(parameters.MainCursor);
Akea.AnimatedCursor.SecondCursor = JSON.parse(parameters.SecondCursor);
Akea.AnimatedCursor.DefaultWindow = parameters.defaultWindow == "true" ? true : false;
Akea.AnimatedCursor.ActorFont = JSON.parse(parameters.actorText);
Akea.AnimatedCursor.EnemyFont = JSON.parse(parameters.enemyText);
const _Sprite_Battler_initialize = Sprite_Battler.prototype.initialize;
Sprite_Battler.prototype.initialize = function (battler) {
_Sprite_Battler_initialize.call(this, ...arguments);
this.createCursorControls();
};
Sprite_Battler.prototype.createCursorControls = function () {
this._cursor1Control = {
directionUp: true,
directionRotation: true,
maxMotion: parseInt(Akea.AnimatedCursor.MainCursor.maxMotion),
motionSpeed: parseFloat(Akea.AnimatedCursor.MainCursor.motionSpeed),
y: parseInt(Akea.AnimatedCursor.MainCursor.y),
rotation: parseFloat(Akea.AnimatedCursor.MainCursor.rotation)
};
this._cursor2Control = {
directionUp: true,
directionRotation: true,
maxMotion: parseInt(Akea.AnimatedCursor.SecondCursor.maxMotion),
motionSpeed: parseFloat(Akea.AnimatedCursor.SecondCursor.motionSpeed),
y: parseInt(Akea.AnimatedCursor.SecondCursor.y),
rotation: parseFloat(Akea.AnimatedCursor.SecondCursor.rotation)
};
};
const _Sprite_Battler_updateBitmap = Sprite_Battler.prototype.updateBitmap;
Sprite_Battler.prototype.updateBitmap = function () {
_Sprite_Battler_updateBitmap.call(this, ...arguments);
const name = this._battler.battlerName();
if (this._battlerName !== name) {
if (!this._cursorMainSprite) {
this.createAkeaAnimatedCursor();
this.createAkeaTargetName();
}
this._akeaCursors._zIndex = 1000;
this._akeaCursors.anchor.x = this._akeaCursors.anchor.y = 0.5;
}
this.updateAkeaCursor();
};
Sprite_Battler.prototype.createAkeaTargetName = function () {
this._akeaTargetName = new Sprite();
this._akeaTargetName.bitmap = new Bitmap(360, 120)
this._akeaTargetName.anchor.x = this._akeaTargetName.anchor.y = 0.5;
if (this._battler.isEnemy()) {
this._akeaTargetName.bitmap.textColor = "#".concat(Akea.AnimatedCursor.EnemyFont.textColor);
this._akeaTargetName.bitmap.outlineColor = "#".concat(Akea.AnimatedCursor.EnemyFont.outlineColor);
this._akeaTargetName.bitmap.outlineWidth = parseInt(Akea.AnimatedCursor.EnemyFont.outlineWidth);
this._akeaTargetName.bitmap.fontSize = parseInt(Akea.AnimatedCursor.EnemyFont.fontSize);
} else {
this._akeaTargetName.bitmap.textColor = "#".concat(Akea.AnimatedCursor.ActorFont.textColor);
this._akeaTargetName.bitmap.outlineColor = "#".concat(Akea.AnimatedCursor.ActorFont.outlineColor);
this._akeaTargetName.bitmap.outlineWidth = parseInt(Akea.AnimatedCursor.ActorFont.outlineWidth);
this._akeaTargetName.bitmap.fontSize = parseInt(Akea.AnimatedCursor.ActorFont.fontSize);
}
this._akeaTargetName.bitmap.drawText(this._battler.name(), 0, 0, 360, 120, "center")
this._akeaTargetName.opacity = 0;
this.addChild(this._akeaTargetName);
};
Sprite_Battler.prototype.createAkeaAnimatedCursor = function () {
this._akeaCursors = new Sprite();
this._akeaCursors.bitmap = new Bitmap(500, 500)
this._akeaCursors.opacity = 0;
this._akeaCursors.anchor.x = this._akeaCursors.anchor.y = 0.5;
this._akeaCursors.scale.x = -1;
this.addChild(this._akeaCursors);
this._cursorMainSpriteMain = new Sprite();
this._cursorMainSpriteMain.bitmap = ImageManager.loadAkea(Akea.AnimatedCursor.MainCursor.cursorImage)
this._akeaCursors.addChild(this._cursorMainSpriteMain);
this._cursorMainSpriteMain.anchor.x = this._cursorMainSpriteMain.anchor.y = 0.5;
this._cursorMainSpriteExtra = new Sprite();
this._cursorMainSpriteExtra.bitmap = ImageManager.loadAkea(Akea.AnimatedCursor.SecondCursor.cursorImage)
this._cursorMainSpriteExtra.anchor.x = this._cursorMainSpriteExtra.anchor.y = 0.5;
this._cursorMainSpriteExtra.y = this._cursor2Control.y;
this._akeaCursors.addChild(this._cursorMainSpriteExtra);
};
Sprite_Battler.prototype.positionAkeaTargetsName = function () {
if (this._battler.isEnemy()) {
if (Akea.BattleSystem)
this._akeaTargetName.x = -parseInt(Akea.AnimatedCursor.EnemyFont.x);
else
this._akeaTargetName.x = parseInt(Akea.AnimatedCursor.EnemyFont.x);
this._akeaTargetName.y = -this.height + parseInt(Akea.AnimatedCursor.EnemyFont.y);
} else {
this._akeaTargetName.x = parseInt(Akea.AnimatedCursor.ActorFont.x);
this._akeaTargetName.y = -this.height + parseInt(Akea.AnimatedCursor.ActorFont.y);
}
};
Sprite_Battler.prototype.updateAkeaCursor = function () {
if (this._battler.isSelected()) {
this.positionAkeaTargetsName();
this._akeaTargetName.opacity += 10;
this._cursorMainSpriteExtra.anchor.y = (this.height) / this._cursorMainSpriteExtra.height;
this._cursorMainSpriteMain.anchor.y = (this.height) / this._cursorMainSpriteMain.height;
this._akeaCursors.y = -this.height / 2;
this.updateAkeaMainCursor(this._cursorMainSpriteMain, this._cursor1Control);
this.updateAkeaMainCursor(this._cursorMainSpriteExtra, this._cursor2Control);
this.updateAkeaCursorRotation();
} else {
this._akeaTargetName.opacity -= 10;
this.updateAkeaCursorReturnRotation();
}
};
Sprite_Battler.prototype.updateAkeaCursorReturnRotation = function () {
this._akeaCursors.opacity -= 10;
if (this._battler.isEnemy()) {
if (this._akeaCursors.rotation < Math.PI) {
this._akeaCursors.rotation += 0.05;
}
}
else {
if (this._akeaCursors.rotation > -Math.PI) {
this._akeaCursors.rotation -= 0.05;
}
}
};
Sprite_Battler.prototype.updateAkeaCursorRotation = function () {
this._akeaCursors.opacity += 10;
if (this._battler.isEnemy()) {
if (this._akeaCursors.rotation > Math.PI * 1 / 4)
this._akeaCursors.rotation += (Math.PI * 1 / 4 - this._akeaCursors.rotation) / 10;
}
else {
if (this._akeaCursors.rotation < -Math.PI * 1 / 4)
this._akeaCursors.rotation += (-Math.PI * 1 / 4 - this._akeaCursors.rotation) / 10;
}
};
Sprite_Battler.prototype.updateAkeaMainCursor = function (sprite, controller) {
if (controller.directionRotation) {
sprite.scale.x -= controller.rotation;
if (sprite.scale.x <= -1) {
controller.directionRotation = false;
}
} else {
sprite.scale.x += controller.rotation;
if (sprite.scale.x >= 1) {
controller.directionRotation = true;
}
}
if (controller.directionUp) {
sprite.y -= controller.motionSpeed;
if (sprite.y <= controller.y - controller.maxMotion) {
controller.directionUp = false;
}
} else {
sprite.y += controller.motionSpeed;
if (sprite.y >= controller.y + controller.maxMotion) {
controller.directionUp = true;
}
}
};
const _Scene_Battle_startActorSelection = Scene_Battle.prototype.startActorSelection;
Scene_Battle.prototype.startActorSelection = function () {
this._actorWindow.selectSingle();
_Scene_Battle_startActorSelection.call(this, ...arguments);
if (!_Game_Action_needsSelection.call(BattleManager.inputtingAction()))
this._actorWindow.selectAll();
};
const _Scene_Battle_startEnemySelection = Scene_Battle.prototype.startEnemySelection;
Scene_Battle.prototype.startEnemySelection = function () {
if (Akea.AnimatedCursor.DefaultWindow)
_Scene_Battle_startEnemySelection.call(this, ...arguments);
else {
this._enemyWindow.refresh();
this._enemyWindow.show();
if (_Game_Action_needsSelection.call(BattleManager.inputtingAction())) {
this._enemyWindow.selectSingle();
this._enemyWindow.select(0);
}
this._enemyWindow.activate();
if (!_Game_Action_needsSelection.call(BattleManager.inputtingAction())) {
this._enemyWindow.selectAll();
if (BattleManager.inputtingAction().isForEveryone())
$gameParty.selectAll()
}
}
};
const _Scene_Battle_onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
Scene_Battle.prototype.onEnemyCancel = function () {
this._actorWindow.hide();
_Scene_Battle_onEnemyCancel.call(this, ...arguments);
};
const _Window_BattleEnemy_initialize = Window_BattleEnemy.prototype.initialize;
Window_BattleEnemy.prototype.initialize = function (rect) {
if (!Akea.AnimatedCursor.DefaultWindow)
rect = new Rectangle(0, 0, 0, 0);
_Window_BattleEnemy_initialize.call(this, rect);
};
const _Window_BattleActor_initialize = Window_BattleActor.prototype.initialize;
Window_BattleActor.prototype.initialize = function (rect) {
if (!Akea.AnimatedCursor.DefaultWindow)
rect = new Rectangle(0, 0, 0, 0);
_Window_BattleActor_initialize.call(this, rect);
};
const _Game_Action_needsSelection = Game_Action.prototype.needsSelection;
Game_Action.prototype.needsSelection = function () {
return this.checkItemScope([1, 2, 3, 4, 5, 7, 8, 9, 10, 6, 12, 13, 14]);
};
Game_Unit.prototype.selectAll = function () {
for (const member of this.members()) {
member.select();
}
};
const _Window_BattleActor_select = Window_BattleActor.prototype.select;
Window_BattleActor.prototype.select = function (index) {
if (this._allSelection) { return };
_Window_BattleActor_select.call(this, ...arguments);
};
Window_BattleActor.prototype.selectSingle = function () {
this._allSelection = false;
};
Window_BattleActor.prototype.selectAll = function () {
this._allSelection = true;
$gameParty.selectAll();
};
const _Window_BattleEnemy_select = Window_BattleEnemy.prototype.select;
Window_BattleEnemy.prototype.select = function (index) {
if (this._allSelection) { return };
_Window_BattleEnemy_select.call(this, ...arguments);
};
Window_BattleEnemy.prototype.selectSingle = function () {
this._allSelection = false;
};
Window_BattleEnemy.prototype.selectAll = function () {
this._allSelection = true;
$gameTroop.selectAll();
};
})();