-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRingCommandMenu.js
1885 lines (1636 loc) · 57.7 KB
/
RingCommandMenu.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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*:
@target MV MZ
@plugindesc リングコマンドメニュー v1.4.1
@author うなぎおおとろ
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/RingCommandMenu.js
@help
リングコマンドメニューを導入するプラグインです。
【使用方法】
基本的に導入するだけで使用できますが、プラグインパラメータ「メインメニューコマンド」を編集することで
よりリングコマンドをカスタマイズすることができます。
■ メインメニューコマンドの編集について
メインメニューコマンドに一覧に表示するコマンドを登録します。
■ コマンドタイプについて
コマンドタイプではコマンドをどのように扱うかを指定します。
これを設定することでコマンド実行前にアクターの選択を行うか、またはサブコマンドの一覧を開くかを設定することができます。
commonEvent: コモンイベントを実行
script: スクリプトを実行する(主にシーンを開くために使用)
selectActor: アクターを選択してからスクリプトを実行((主にアクターを選択するシーンを開くために仕様)
subMenu: サブコマンドの一覧を開く
※v1.3.0以降より、コマンドタイプのnormalはscriptに変更になりました。
ただし互換性のためにnormalを指定した場合はscriptを指定したものとして扱います。
■ アクター選択コマンドの編集について
アクター選択画面のアイコンはキャラクターの歩行グラフィックスから自動的に生成されますが、
アクター選択コマンドを編集することで自由にアクターのアイコンを設定することが可能です。
【ライセンス】
このプラグインは、MITライセンスの条件の下で利用可能です。
@param MainMenuCommands
@text メインメニューコマンド
@type struct<MenuCommand>[]
@default ["{\"CommandType\":\"script\",\"Text\":\"アイテム\",\"IconIndex\":\"208\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Item);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"selectActor\",\"Text\":\"スキル\",\"IconIndex\":\"79\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Skill);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"selectActor\",\"Text\":\"装備\",\"IconIndex\":\"96\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Equip);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"selectActor\",\"Text\":\"ステータス\",\"IconIndex\":\"89\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Status);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"script\",\"Text\":\"オプション\",\"IconIndex\":\"129\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Options);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"script\",\"Text\":\"セーブ\",\"IconIndex\":\"121\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_Save);\",\"SubMenuCommands\":\"\"}","{\"CommandType\":\"script\",\"Text\":\"ゲーム終了\",\"IconIndex\":\"75\",\"Image\":\"\",\"Script\":\"SceneManager.push(Scene_GameEnd);\",\"SubMenuCommands\":\"\"}"]
@desc
メインメニューに表示するコマンドの一覧を指定します。
@param SelectActorCommands
@text アクター選択コマンド
@type struct<SelectActorCommand>[]
@default []
@desc
アクター選択のアクターコマンドを指定します。
@param EnableSubCommandRotation
@text サブコマンド回転有効
@type boolean
@default false
@desc
サブコマンド表示時の回転を有効にします。
@param SkipActorSelect
@text アクター選択スキップ
@type boolean
@default true
@desc
trueを設定するとパーティメンバーが1人しかいない場合はアクター選択画面をスキップします。
@param SaveCommandText
@text セーブコマンドテキスト
@type string
@default セーブ
@desc
セーブコマンドのテキストを指定します。このパラメータはコマンドがセーブコマンドか否かの判定に使用します。
@param OpenSe
@text 開始SE
@type struct<SE>
@default {"FileName":"Magic1","Volume":"90","Pitch":"100","Pan":"0"}
@desc
リングコマンドメニューを開始するときのSEを指定します。
@param CloseSe
@text 終了SE
@type struct<SE>
@default {"FileName":"Magic2","Volume":"90","Pitch":"100","Pan":"0"}
@desc
リングコマンドメニューを終了するときのSEを指定します。
@param SubOpenSe
@text サブ開始SE
@type struct<SE>
@default {"FileName":"Magic1","Volume":"90","Pitch":"150","Pan":"0"}
@desc
サブメニューまたはアクター選択を開始するときのSEを指定します。
@param SubCloseSe
@text サブ終了SE
@type struct<SE>
@default {"FileName":"Magic1","Volume":"90","Pitch":"150","Pan":"0"}
@desc
サブメニューまたはアクター選択を終了するときのSEを指定します。
@param BackGroundOpacity
@text 背景不透明度
@type number
@default 192
@desc
リングコマンドメニューの背景の不透明度を指定します。
@param InOutSpeed
@text 開閉スピード
@type number
@default 8
@desc
リングコマンドの開閉スピードを指定します。
@param RotationSpeed
@text 回転スピード
@type number
@default 11
@desc
リングコマンドの回転スピードを指定します。
@param StartFar
@text 開始距離
@type number
@default 300
@desc
リングコマンドのオープン開始距離を指定します。
@param EndFar
@text 終了距離
@type number
@default 70
@desc
リングコマンドのオープン終了距離を指定します。
*/
/*~struct~MenuCommand:
@param CommandType
@text コマンドタイプ
@type string
@default script
@desc
コマンドの用途(script, selectActor, subMenu)を指定します。
@param Text
@text テキスト
@type string
@desc
メニューに表示するテキストを指定します。
@param IconIndex
@text アイコン番号
@type number
@default 0
@desc
リングコマンドのアイコン番号を指定します。
@param Image
@text 画像
@type file
@dir img/pictures
@desc
リングコマンドの画像を指定します。
@param Script
@text スクリプト
@type multiline_string
@desc
リングコマンド選択時に実行するスクリプトを記述します。
@param CommonEventId
@text コモンイベントID
@type common_event
@default 0
@desc
リングコマンド選択時に実行するコモンイベントIDを設定します。0だとコモンイベントを実行しません。
@param SubMenuCommands
@text サブメニューコマンド
@type struct<MenuCommand>[]
@desc
サブメニューとして表示するコマンドの一覧を指定します。
*/
/*~struct~SE:
@param FileName
@type file
@dir audio/se
@desc
再生するSEのファイル名を指定します。
@param Volume
@type number
@default 90
@desc
再生するSEのvolumeを指定します。
@param Pitch
@type number
@default 100
@desc
再生するSEのpitchを指定します。
@param Pan
@type number
@default 0
@desc
再生するSEのpanを指定します。
*/
/*~struct~SelectActorCommand:
@param ActorId
@text アクターID
@type actor
@desc
アクター選択用のアクターIDを指定します。
@param Image
@text 画像
@type file
@dir img/pictures
@desc
アクター選択用のアクターの画像を指定します。
*/
const RingCommandMenuPluginName = document.currentScript.src.match(/.+\/(.+)\.js/)[1];
const RingCommandMenuClassAlias = (() => {
"use strict";
const RING_COMMAND_OFFSET_Y = -32;
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) {
if (params[name] === "" || params[name] === undefined) {
result[name] = null;
} else {
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";
}
}
}
// MV Compatible
if (Utils.RPGMAKER_NAME === "MV") {
TouchInput._onMouseMove = function(event) {
const x = Graphics.pageToCanvasX(event.pageX);
const y = Graphics.pageToCanvasY(event.pageY);
if (this._mousePressed) {
this._onMove(x, y);
} else if (Graphics.isInsideCanvas(x, y)) {
this._onHover(x, y);
}
};
TouchInput._onHover = function(x, y) {
this._events.hovered = true;
this._x = x;
this._y = y;
};
const _TouchInput_update = TouchInput.update;
TouchInput.update = function() {
_TouchInput_update.call(this);
this._hovered = this._events.hovered;
this._events.hovered = false;
};
TouchInput.isHovered = function() {
return this._hovered;
};
var Sprite_ClickableMV = function() {
this.initialize(...arguments);
};
Sprite_ClickableMV.prototype = Object.create(Sprite_Base.prototype);
Sprite_ClickableMV.prototype.constructor = Sprite_ClickableMV;
Sprite_ClickableMV.prototype.initialize = function() {
Sprite_Base.prototype.initialize.call(this);
this._pressed = false;
this._hovered = false;
};
Sprite_ClickableMV.prototype.update = function() {
Sprite_Base.prototype.update.call(this);
this.processTouch();
};
Sprite_ClickableMV.prototype.processTouch = function() {
if (this.isClickEnabled()) {
if (this.isBeingTouched()) {
if (!this._hovered && TouchInput.isHovered()) {
this._hovered = true;
this.onMouseEnter();
}
if (TouchInput.isTriggered()) {
this._pressed = true;
this.onPress();
}
} else {
if (this._hovered) {
this.onMouseExit();
}
this._pressed = false;
this._hovered = false;
}
if (this._pressed && TouchInput.isReleased()) {
this._pressed = false;
this.onClick();
}
} else {
this._pressed = false;
this._hovered = false;
}
};
Sprite_ClickableMV.prototype.isPressed = function() {
return this._pressed;
};
Sprite_ClickableMV.prototype.isClickEnabled = function() {
return this.worldVisible;
};
Sprite_ClickableMV.prototype.isBeingTouched = function() {
const touchPos = new Point(TouchInput.x, TouchInput.y);
const localPos = this.worldTransform.applyInverse(touchPos);
return this.hitTest(localPos.x, localPos.y);
};
Sprite_ClickableMV.prototype.hitTest = function(x, y) {
const rect = new Rectangle(
-this.anchor.x * this.width,
-this.anchor.y * this.height,
this.width,
this.height
);
return rect.contains(x, y);
};
Sprite_ClickableMV.prototype.onMouseEnter = function() {
//
};
Sprite_ClickableMV.prototype.onMouseExit = function() {
//
};
Sprite_ClickableMV.prototype.onPress = function() {
//
};
Sprite_ClickableMV.prototype.onClick = function() {
//
};
}
let SpriteMVMZ;
let Sprite_ClickableMVMZ;
if (Utils.RPGMAKER_NAME === "MZ") {
SpriteMVMZ = Sprite;
Sprite_ClickableMVMZ = Sprite_Clickable;
} else {
SpriteMVMZ = Sprite_Base;
Sprite_ClickableMVMZ = Sprite_ClickableMV;
}
const typeDefine = {
MainMenuCommands: [{}],
OpenSe: {},
CloseSe: {},
SubOpenSe: {},
SubCloseSe: {},
SelectActorCommands: [{}],
};
const PP = PluginParamsParser.parse(PluginManager.parameters(RingCommandMenuPluginName), typeDefine);
const $ringCommnadDatas = [];
class RingCommandUtils {
static needSkipActorSelect() {
return PP.SkipActorSelect && $gameParty.members().length === 1;
}
}
class RingCommandData {
get commandType() { return this._commandType; }
get text() { return this._text; }
get iconIndex() { return this._iconIndex; }
get image() { return this._image; }
get script() { return this._script; }
get subCommands() { return this._subCommands; }
get internalIndex() { return this._internalIndex; }
get commonEventId() { return this._commonEventId; }
static fromParam(param, internalIndex) {
if (param.CommandType === "subMenu") {
const subCommands = JSON.parse(param.SubMenuCommands).map((strSubMenuCommandParam, i) => {
if (strSubMenuCommandParam === "") return null;
const subMenuCommandParam = PluginParamsParser.parse(JSON.parse(strSubMenuCommandParam), {});
return RingCommandData.fromParam(subMenuCommandParam, i);
}).filter(command => !!command);
return new this(param.CommandType, param.Text, param.IconIndex, param.Image, param.Script, subCommands, param.CommonEventId, internalIndex);
} else {
return new this(param.CommandType, param.Text, param.IconIndex, param.Image, param.Script, null, param.CommonEventId, internalIndex);
}
}
constructor(...args) {
this.initialize(...args);
}
initialize(commandType, text, iconIndex, image, script, subCommands, commonEventId, internalIndex) {
this._commandType = commandType;
this._text = text;
this._iconIndex = iconIndex;
this._image = image;
this._script = script;
this._subCommands = subCommands;
this._internalIndex = internalIndex;
this._commonEventId = commonEventId;
}
isEnabled() {
if (this._text === PP.SaveCommandText) {
return $gameSystem.isSaveEnabled();
}
return true;
}
}
PP.MainMenuCommands.forEach((param, i) => {
const data = RingCommandData.fromParam(param, i++);
$ringCommnadDatas.push(data);
});
Game_Temp.prototype.setRingCommandManager = function(manager) {
this._ringCommandManager = manager;
};
Game_Temp.prototype.ringCommandManager = function() {
return this._ringCommandManager;
};
Game_Temp.prototype.setRingCommandCommonEventRunner = function(commonEventRunner) {
this._ringCommandCommonEventRunner = commonEventRunner;
};
Game_Temp.prototype.ringCommandCommonEventRunner = function() {
return this._ringCommandCommonEventRunner;
};
class Sprite_RingCommand extends Sprite_ClickableMVMZ {
get rotateSpeed() { return this._rotateSpeed; }
set rotateSpeed(_rotateSpeed) { this._rotateSpeed = _rotateSpeed; }
get homeX() { return this._homeX; }
set homeX(_homeX) { this._homeX = _homeX; }
get homeY() { return this._homeY; }
set homeY(_homeY) { this._homeY = _homeY; }
get deg() { return this._deg; }
set deg(_deg) {
this._deg = this.degNormalization(_deg);
this.move(this._deg, this._far);
}
get far() { return this._far; }
set far(_far) {
this._far = _far;
this.move(this._deg, this._far);
}
get data() { return this._data; }
initialize(homeX, homeY, data, opt = { mouseEnterCbk: null, mouseExitCbk: null, clickCbk: null }) {
super.initialize();
this._homeX = homeX;
this._homeY = homeY;
this._data = data;
this._mouseEnterCbk = opt.mouseEnterCbk;
this._mouseExitCbk = opt.mouseExitCbk;
this._clickCbk = opt.clickCbk;
this._deg = 0;
this._degPlused = 0;
this._baseDeg = 0;
this._far = 0;
this._targetDegPlus = null;
this._rotateSpeed = 4;
this._rotateWay = 1;
this.move(0, 0);
this.bitmap = new Bitmap(32, 32);
this.createBitmap(data);
this.hide();
}
createBitmap(data) {
if (data.image) {
this.bitmap = ImageManager.loadPicture(data.image);
} else {
if (data.commandType === "actorData") {
this.createActorIcon($gameParty.members()[data.internalIndex]);
} else {
const iconIndex = data.iconIndex;
this.bitmap = this.trimIconset(iconIndex);
}
}
}
trimIconset(iconIndex) {
const srcBitmap = ImageManager.loadSystem("IconSet");
const dstBitmap = new Bitmap(32, 32);
const sx = iconIndex % 16 * 32;
const sy = Math.floor(iconIndex / 16) * 32;
dstBitmap.blt(srcBitmap, sx, sy, 32, 32, 0, 0);
return dstBitmap;
}
createActorIcon(actor) {
this._actor = actor;
this.updateActorImage();
}
updateActorImage() {
if (!this._actor) return;
const characterName = this._actor.characterName();
const characterIndex = this._actor.characterIndex();
const characterBitmap = ImageManager.loadCharacter(characterName);
if (!characterBitmap.isReady()) return;
const dstBitmap = new Bitmap(48, 32);
this.actorImageDrawCharacter(dstBitmap, characterBitmap, characterName, characterIndex);
this.bitmap = dstBitmap;
}
actorImageDrawCharacter(dstBitmap, characterBitmap, characterName, characterIndex) {
const big = ImageManager.isBigCharacter(characterName);
const pw = characterBitmap.width / (big ? 3 : 12);
const ph = characterBitmap.height / (big ? 4 : 8);
const n = big ? 0: characterIndex;
const sx = ((n % 4) * 3 + 1) * pw;
const sy = Math.floor(n / 4) * 4 * ph;
dstBitmap.blt(characterBitmap, sx, sy, pw, ph, 0, 0);
}
update() {
super.update();
this.updateOpacity();
if (this._targetDegPlus != null) this.updateRotation();
}
updateOpacity() {
if (this._data.isEnabled()) {
this.opacity = 255;
} else {
this.opacity = 128;
}
}
updateRotation() {
this._degPlused += this._rotateSpeed * this._rotateWay;
let isEnd;
if (this._rotateWay > 0) {
isEnd = this._degPlused >= this._targetDegPlus;
} else {
isEnd = this._degPlused <= this._targetDegPlus;
}
if (isEnd) {
this._deg = this.degNormalization(this._baseDeg + this._targetDegPlus);
this._targetDegPlus = null;
} else {
this._deg = this.degNormalization(this._baseDeg + this._degPlused);
}
this.move(this._deg, this._far);
}
isBusy() {
return !!this._targetDegPlus;
}
// way: "left" or "right"
startRotationAbs(absDeg, way) {
let degPlus = 0;
if (way === "left") {
if (absDeg > this._deg) {
degPlus = absDeg - this._deg;
} else if (absDeg < this._deg) {
degPlus = 360 - this._deg + absDeg;
}
} else if (way === "right") {
if (this._deg > absDeg) {
degPlus = absDeg - this._deg;
} else if (this._deg < absDeg) {
degPlus = -(this._deg + 360 - absDeg);
}
}
this.startRotation(degPlus);
}
startRotation(degPlus) {
this._targetDegPlus = degPlus;
this._degPlused = 0;
this._baseDeg = this._deg;
if (degPlus > 0) {
this._rotateWay = 1;
} else {
this._rotateWay = -1;
}
}
stopRotation() {
this._rotateWay = null;
this._targetDegPlus = null;
}
move(deg, far) {
const rad = this.deg2rad(deg);
const disX = Math.round(far * Math.cos(rad));
const disY = Math.round(far * Math.sin(rad));
this.x = this._homeX + disX;
this.y = this._homeY + disY;
}
rad2deg(rad) {
return (rad * 180 / Math.PI) + 90;
}
deg2rad(deg) {
return (deg - 90) * Math.PI / 180;
}
degNormalization(deg) {
deg %= 360;
if (deg < 0) deg = 360 + deg;
return deg;
}
onMouseEnter() {
if (this._mouseEnterCbk && !this.isBusy()) this._mouseEnterCbk(this);
}
onMouseExit() {
if (this._mouseExitCbk && !this.isBusy()) this._mouseExitCbk(this);
}
onClick() {
if (this._clickCbk && !this.isBusy()) this._clickCbk(this);
}
}
class RingCommandSpriteController {
constructor(...args) {
this.initialize(...args);
}
initialize() {
this._sprites = null;
this._baseSprite = null;
this._baseMinFar = PP.EndFar;
this._baseMaxFar = PP.StartFar;
this._minFar = this._baseMinFar;
this._maxFar = this._baseMaxFar;
this._baseRotateSpeed = PP.RotationSpeed;
this._inOutSpeed = PP.InOutSpeed;
this._state = "none";
this._currentIndex = 0;
this._startDeg = 0;
this._marginFar = 0;
}
reset(sprites, index) {
this._sprites = sprites;
this._baseSprite = this._sprites[index];
this._state = "none";
this._currentIndex = index;
}
startOutCenterAndRotation() {
this.startInOutAndRotation("outCenterAndRotation", this._baseMinFar, this._baseMaxFar, this._baseMinFar, false);
}
startInCenterAndRotation() {
this.startInOutAndRotation("inCenterAndRotation", this._baseMinFar, this._baseMaxFar, this._baseMaxFar, true);
}
startSubOutCenterAndRotation() {
this.startInOutAndRotation("outCenterAndRotation", 0, this._baseMinFar, 0, true);
}
startSubInCenterAndRotation() {
this.startInOutAndRotation("inCenterAndRotation", 0, this._baseMinFar, this._baseMinFar, false);
}
startSubOutCenter() {
this.startInOut("outCenter", 0, this._baseMinFar, 0);
}
startSubInCenter() {
this.startInOut("inCenter", 0, this._baseMinFar, this._baseMinFar);
}
startInOutAndRotation(changeState, minFar, maxFar, startFar, lastCycleSync) {
this._state = changeState;
this._minFar = minFar;
this._maxFar = maxFar;
this._lastCycled = false;
this._lastCycleSync = lastCycleSync;
this._sprites.forEach((sprite, i) => {
sprite.deg = this.calcIndexDeg(i);
sprite.far = startFar;
});
}
startInOut(changeState, minFar, maxFar, startFar) {
this._state = changeState;
this._minFar = minFar;
this._maxFar = maxFar;
this._sprites.forEach((sprite, i) => {
sprite.deg = this.calcRelativeIndexDeg(i);
sprite.far = startFar;
});
}
update() {
switch (this._state) {
case "outCenterAndRotation":
this.updateOutCenterAndRotation();
break;
case "inCenterAndRotation":
this.updateInCenterAndRotation();
break;
case "outCenter":
this.updateOutCenter();
break;
case "inCenter":
this.updateInCenter();
break;
case "changeIndex":
this.updateChangeIndex();
break;
}
}
isBusy() {
return this._state != "none";
}
calcIndexDeg(index) {
const space = 360 / this._sprites.length;
const deg = space * index;
return deg;
}
calcRelativeIndexDeg(index) {
let relIndex = index - this._currentIndex;
if (relIndex >= this._sprites.length) {
relIndex = relIndex - this._sprites.length;
}
return this.calcIndexDeg(relIndex);
}
updateOutCenterAndRotation() {
if (this._baseSprite.far >= this._maxFar - this._marginFar) {
if (this._lastCycled) {
if (this._lastCycleSync) {
if (!this._baseSprite.isBusy()) {
this._state = "none";
}
} else {
this._state = "none";
}
} else {
this._lastCycled = true;
if (this._baseSprite.deg > 0) {
const rotationDeg = 360 - this._baseSprite.deg;
this._sprites.forEach((sprite, i) => {
sprite.startRotation(rotationDeg);
sprite.far = this._maxFar;
});
}
}
} else {
if (!this._baseSprite.isBusy()) {
const speedPer = (this._baseSprite.far - this._minFar) / (this._maxFar - this._minFar);
for (const sprite of this._sprites) {
sprite.rotateSpeed = this._baseRotateSpeed - (this._baseRotateSpeed / 2) * speedPer;
sprite.startRotation(360);
}
}
for (const sprite of this._sprites) {
if (this._baseSprite.far < this._maxFar) {
sprite.far += this._inOutSpeed;
} else {
sprite.far = this._maxFar;
}
}
}
}
updateInCenterAndRotation() {
if (this._baseSprite.far <= this._minFar + this._marginFar) {
if (this._lastCycled) {
if (this._lastCycleSync) {
if (!this._baseSprite.isBusy()) {
this._state = "none";
}
} else {
this._state = "none";
}
} else {
this._lastCycled = true;
if (this._baseSprite.deg > 0) {
const rotationDeg = 360 - this._baseSprite.deg;
this._sprites.forEach((sprite, i) => {
sprite.startRotation(rotationDeg);
sprite.far = this._minFar;
});
}
}
} else {
if (!this._baseSprite.isBusy()) {
const speedPer = (this._baseSprite.far - this._minFar) / (this._maxFar - this._minFar);
this._sprites.forEach((sprite, i) => {
sprite.rotateSpeed = (this._baseRotateSpeed / 2) + (this._baseRotateSpeed / 2) * speedPer;
sprite.startRotation(360);
});
}
for (const sprite of this._sprites) {
if (this._baseSprite.far > this._minFar) {
sprite.far -= this._inOutSpeed;
} else {
sprite.far = this._minFar;
}
}
}
}
updateOutCenter() {
if (this._baseSprite.far >= this._maxFar - this._marginFar) {
this._sprites.forEach((sprite, i) => {
sprite.far = this._maxFar;
});
this._state = "none";
} else {
for (const sprite of this._sprites) {
if (this._baseSprite.far < this._maxFar) {
sprite.far += this._inOutSpeed;
} else {
sprite.far = this._maxFar;
}
}
}
}
updateInCenter() {
if (this._baseSprite.far <= this._minFar + this._marginFar) {
this._sprites.forEach((sprite, i) => {
sprite.far = this._minFar;
});
this._state = "none";
} else {
for (const sprite of this._sprites) {
if (this._baseSprite.far > this._minFar) {
sprite.far -= this._inOutSpeed;
} else {
sprite.far = this._minFar;
}
}
}
}
startChangeNextCommand() {
if (this._sprites.length <= 1) return false;
let index = this._currentIndex + 1;
let rotationDeg;
if (index >= this._sprites.length) {
index = index - this._sprites.length;
rotationDeg = -this.calcIndexDeg(1);
} else {
rotationDeg = -this.calcRelativeIndexDeg(index);
}
this.startChangeCommand(index, rotationDeg);
return true;
}
startChangePrevCommand() {
if (this._sprites.length <= 1) return false;
let index = this._currentIndex - 1;
let rotationDeg;
if (index < 0) {
index = this._sprites.length + index;
rotationDeg = this.calcIndexDeg(1);
} else {
rotationDeg = -this.calcRelativeIndexDeg(index);
}
this.startChangeCommand(index, rotationDeg);
return true;
}
startChangeCommand(targetIndex, rotationDeg) {
this._baseSprite = this._sprites[this._currentIndex];
for (const sprite of this._sprites) {
sprite.rotateSpeed = this._baseRotateSpeed;
sprite.startRotation(rotationDeg);
}
this._currentIndex = targetIndex;
this._state = "changeIndex";
}
updateChangeIndex() {
const busySprite = this._sprites.find(sprite => sprite.isBusy());
if (!busySprite) {
this._state = "none";
}
}
}
class Sprite_RingCommandLabel extends SpriteMVMZ {
static get LABEL_WIDTH() { return 120; }
static get LABEL_HEIGHT() { return 32; }
initialize() {
super.initialize();
this.x = 0;
this.y = 0;