DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
memcard.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 2
4
5#include "memcard.hpp"
6
7#include <cmath>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11
12#include "battle_globals.hpp"
13#include "clsmes.hpp"
14#include "dataread.hpp"
15#include "eastking.hpp"
16#include "editatra.hpp"
17#include "editground.hpp"
18#include "editloop.hpp"
19#include "editmenu.hpp"
20#include "editpartsinfo.hpp"
21#include "gamepad.hpp"
22#include "gameutil.hpp"
23#include "mainselect.hpp"
24#include "memorycardaccess.hpp"
25#include "menu_draw.hpp"
26#include "menu_inventory.hpp"
27#include "menu_save.hpp"
28#include "mglib.hpp"
29#include "rect.hpp"
30#include "savedata.hpp"
31#include "snd.hpp"
32#include "sound.hpp"
33#include "texture.hpp"
34#include "userstatus.hpp"
35
40#ifdef PAL
41 s16 mode;
42 s16 buttons;
43 s16 cursor;
44 s16 unk_06;
45#else
46 s32 mode;
47 s32 buttons;
48 u8 unk_08[4];
49 s32 cursor;
50#endif
51 s32 step;
53 float cursor_x;
54 float cursor_y;
55 float page_x;
56#ifdef PAL
57 s32 flag[13];
58 s32 prev_flag[13];
59 s32 prev_screen_pos[2];
60 u8 texture_ready;
61 s16 block_no;
62#else
63 s32 flag[12];
64 s32 prev_flag[12];
67#endif
68};
69
70#ifdef PAL
71STATIC_ASSERT(sizeof(OPTION_MENU_STATE) == 0x90);
72#else
73STATIC_ASSERT(sizeof(OPTION_MENU_STATE) == 0x88);
74#endif
75
77CEditPartsInfo BtEditPartsInfo;
78
79MENU_ATORA_SEL MenuAtoraSel;
80CMemoryCardAccess McAccess;
81
83OPTION_MENU_STATE OptionMenu;
84
86CTexture *StayTex;
87
89CTexture *AttachIcon;
90
92CTexture *ItemIcon;
93
95CTexture *ItemIcon2;
96
98CTexture *WepIcon;
99
100CTexture *Sozai;
101CTexture *HoleGray;
102CTexture *HoleGold;
103CTexture *ObTip;
104CTexture *ObPerson;
105CTexture *CompleteTex;
106CTexture *VillageBar;
107CTexture *VillageName;
108
110CTexture *SaveBoard;
111
113CTexture *MenuOption;
114
115CEditPartsInfo *CommonMenuAtoraInfo;
116short *GetAtraMsgReadBuf;
117
119ATORA_TIP_HAVE *NowTipHavePt;
120
122int AtoraTextureEnterFlag;
123
125int AtoraTextureBaseBlock;
126
128int AtoraTextureReadBlock;
129
131u_long128 *AtoraOffsetBuf;
132
133s32 CursorVibeCnt;
134
142static void DrawAtoraSelect(int fade);
143
152static int AtoraBoardKey();
153
162static int AtoraTipKey();
163
171static void AtoraMenuTipCancel();
172
180static void AtoraBoardFadeEffect();
181
190static int SaveMenuKeyFadeIn();
191
200static int SaveMenuKeyFadeOut();
201
210static int SaveMenuKeyModeSelect();
211
220static int SaveMenuKeyMcSelect();
221
230static int SaveMenuKeyCheckMcType();
231
240static int SaveMenuKeyCheckMc();
241
250static int SaveMenuKeyLoadConfig();
251
260static int SaveMenuKeyFileSelect();
261
262int McCheckMCPs2(MC_CARD_INFO *card) {
263 if (!card->present || card->type != sceMcTypePS2) {
264 return 0;
265 }
266
267 return 1;
268}
269
270void DrawObjectVibe(int x, int y, CTexture *texture, CRect_i_ src_rect, unsigned char alpha, int flag) {
271 float dest_x = (float) x + 7.0f * cosf(0.08055365830659866f * (float) CursorVibeCnt);
272 float dest_y = (float) y + 5.0f * sinf(0.1163552850484848f * (float) CursorVibeCnt);
273 CRect_i_ dest_rect((s32) dest_x, (s32) dest_y, src_rect.width, src_rect.height);
274 DrawMenu2DSprite(texture, dest_rect, src_rect, alpha, alpha, alpha, flag);
275}
276
277void DrawObjectVibe(int x, int y, CTexture *texture, RECT src_rect, unsigned char alpha, int flag) {
278 CRect_i_ src(src_rect.x, src_rect.y, src_rect.width, src_rect.height);
279 DrawObjectVibe(x, y, texture, src, alpha, flag);
280}
281
285void DrawMenuObjectVibe(int x, int y, int shadow, int icon_u) {
286 CTexture *texture = TexManager.GetTexture(AtoraVibeTextureName, -1);
287 CRect_i_ src(icon_u, 0x28, 0x20, 0x20);
288
289 if (shadow != 0) {
290 DrawObjectVibe(x + 5, y + 3, texture, src, 0, 100);
291 }
292
293 DrawObjectVibe(x, y, texture, src, 0x80, 0x80);
294}
295
296void DrawMenuHelpWindow(CTexture *texture, int style, int x, int y, float width, float height, int alpha) {
297 int corner_u;
298 float middle_width;
299 float middle_height;
300 int middle_y;
301 int bottom_y;
302
303 if (style == 0) {
304 corner_u = 24;
305 } else if (style == 1) {
306 corner_u = 0;
307 } else {
308 corner_u = 48;
309 }
310
311 middle_width = 24.0f * width;
312 middle_height = 24.0f * height;
313 middle_y = y + 24;
314 bottom_y = middle_y + middle_height;
315
316 if (texture == NULL) {
317 return;
318 }
319
320 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 24), CRect_i_(corner_u, 0, 24, 24), alpha);
321 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(24, 24, 24, 24), alpha);
322 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 24), CRect_i_(24, 48, 24, 24), alpha);
323 x += 24;
324 DrawMenu2DSprite(texture, CRect_i_(x, y, middle_width, 24), CRect_i_(48, 0, 24, 24), alpha);
325 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, middle_width, middle_height), CRect_i_(48, 24, 24, 24), alpha);
326 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, middle_width, 24), CRect_i_(48, 48, 24, 24), alpha);
327 x += middle_width;
328 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 24), CRect_i_(72, 0, 24, 24), alpha);
329 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(72, 24, 24, 24), alpha);
330 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 24), CRect_i_(72, 48, 24, 24), alpha);
331}
332
333void MenuHelpWinDraw(int x, int y, float width, float height, int alpha, int u, int v, CTexture *texture) {
334 int middle_width;
335 int middle_height;
336 int middle_y;
337 int bottom_y;
338
339 middle_width = width * 16.0f;
340 middle_height = height * 22.0f;
341 middle_y = y + 22;
342 bottom_y = middle_y + middle_height;
343
344 if (texture == NULL) {
345 return;
346 }
347
348 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 22), CRect_i_(u, v, 24, 22), (alpha * 100) >> 7);
349 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(u, v + 22, 24, 20), (alpha * 100) >> 7);
350 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 22), CRect_i_(u, v + 42, 24, 22), (alpha * 100) >> 7);
351 x += 24;
352 DrawMenu2DSprite(texture, CRect_i_(x, y, middle_width, 22), CRect_i_(u + 22, v, 16, 22), (alpha * 100) >> 7);
353 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, middle_width, middle_height), CRect_i_(u + 22, v + 22, 16, 20), (alpha * 100) >> 7);
354 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, middle_width, 22), CRect_i_(u + 22, v + 42, 16, 22), (alpha * 100) >> 7);
355 x += middle_width;
356 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 22), CRect_i_(u + 38, v, 24, 22), (alpha * 100) >> 7);
357 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(u + 38, v + 22, 24, 20), (alpha * 100) >> 7);
358 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 22), CRect_i_(u + 38, v + 42, 24, 22), (alpha * 100) >> 7);
359}
360
361void MenuHelpWinDraw2(int x, int y, float width, float height, int alpha, int u, int v, CTexture *texture) {
362 int middle_width;
363 int middle_height;
364 int middle_y;
365 int bottom_y;
366
367 middle_width = width;
368 middle_height = height;
369 middle_y = y + 22;
370 bottom_y = middle_y + middle_height;
371
372 if (texture == NULL) {
373 return;
374 }
375
376 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 22), CRect_i_(u, v, 24, 22), (alpha * 100) >> 7);
377 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(u, v + 22, 24, 20), (alpha * 100) >> 7);
378 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 22), CRect_i_(u, v + 42, 24, 22), (alpha * 100) >> 7);
379 x += 24;
380 DrawMenu2DSprite(texture, CRect_i_(x, y, middle_width, 22), CRect_i_(u + 22, v, 16, 22), (alpha * 100) >> 7);
381 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, middle_width, middle_height), CRect_i_(u + 22, v + 22, 16, 20), (alpha * 100) >> 7);
382 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, middle_width, 22), CRect_i_(u + 22, v + 42, 16, 22), (alpha * 100) >> 7);
383 x += middle_width;
384 DrawMenu2DSprite(texture, CRect_i_(x, y, 24, 22), CRect_i_(u + 38, v, 24, 22), (alpha * 100) >> 7);
385 DrawMenu2DSprite(texture, CRect_i_(x, middle_y, 24, middle_height), CRect_i_(u + 38, v + 22, 24, 20), (alpha * 100) >> 7);
386 DrawMenu2DSprite(texture, CRect_i_(x, bottom_y, 24, 22), CRect_i_(u + 38, v + 42, 24, 22), (alpha * 100) >> 7);
387}
388
392void MenuHelpWinDraw(int x, int y, float width, float height, int alpha) {
393 StayTex = TexManager.GetTexture(AtoraVibeTextureName, -1);
394 MenuHelpWinDraw(x, y, width, height, alpha, 0, 0, StayTex);
395}
396
397void DrawMenuWaku(float x, float y, int width, int height, int type, CTexture *texture, int alpha) {
398 RECT *src;
399 float offset;
400 int left;
401 int top;
402 int right;
403 int bottom;
404
405 if (texture != NULL) {
406 static int MenuWakuCnt = 0;
407
408 offset = 0.2f * MenuWakuCnt;
409 left = x + offset;
410 top = y + offset;
411 right = (x + width) - offset;
412 bottom = (y + height) - offset;
413 RECT corner[2] = {
414 {74, 72, 16, 16},
415 {106, 72, 27, 24}
416 };
417 src = &corner[type];
418 DrawMenu2DSprite(texture, CRect_i_(left, top, src->width, src->height), CRect_i_(src->x, src->y, src->width, src->height), alpha);
419 DrawMenu2DSprite(texture, CRect_i_(right, top, src->width, src->height), CRect_i_(src->x + src->width, src->y, src->width, src->height), alpha);
420 DrawMenu2DSprite(texture, CRect_i_(left, bottom, src->width, src->height), CRect_i_(src->x, src->y + src->height, src->width, src->height), alpha);
421 DrawMenu2DSprite(texture, CRect_i_(right, bottom, src->width, src->height), CRect_i_(src->x + src->width, src->y + src->height, src->width, src->height), alpha);
422 MenuWakuCnt++;
423
424 if (MenuWakuCnt < 0 || MenuWakuCnt >= 30) {
425 MenuWakuCnt = 0;
426 }
427 }
428}
429
430int DrawMenuNumber(int number, int x, int y, CTexture *texture, RECT rect, int overlap, int flag) {
431 return DrawMenuNumber(number, x, y, rect, texture, overlap, 0, SCREEN_HEIGHT, flag);
432}
433
434int DrawMenuNumber(int number, int x, int y, RECT rect, CTexture *texture, int overlap, unsigned char r, unsigned char g, unsigned char b, int flag) {
435 int digits;
436 int digit;
437 int width;
438 int src_x;
439 int dest_y;
440 int dest_height;
441 int clip_y;
442 int src_y;
443 int height;
444
445 if (texture == NULL) {
446 return 0;
447 }
448
449 for (digits = GetNumberKeta(number); 0 < digits; digits--) {
450 clip_y = y;
451 digit = number % 10;
452 width = rect.width;
453 x -= width - overlap;
454 src_x = rect.x + width * digit;
455 src_y = rect.y;
456 height = rect.height;
457 MenuTextureClip(clip_y, src_y, height, 0, SCREEN_HEIGHT);
458 CRect_i_ dest;
459 CRect_i_ src(src_x, src_y, width, height);
460 dest_height = height - 1;
461 dest_y = clip_y;
462 dest.x = x;
463 dest.y = dest_y;
464 dest.width = width;
465 dest.height = dest_height;
466 DrawMenu2DSprite(texture, dest, src, r, g, b, flag);
467 number /= 10;
468 }
469
470 return x;
471}
472
473int DrawMenuNumber(int number, int x, int y, RECT rect, CTexture *texture, int overlap, int top, int bottom, int flag) {
474 int digits;
475 int digit;
476 int width;
477 int src_x;
478 int dest_y;
479 int dest_height;
480 int clip_y;
481 int src_y;
482 int height;
483
484 if (texture == NULL) {
485 return 0;
486 }
487
488 for (digits = GetNumberKeta(number); 0 < digits; digits--) {
489 clip_y = y;
490 digit = number % 10;
491 width = rect.width;
492 x -= width - overlap;
493 src_x = rect.x + width * digit;
494 src_y = rect.y;
495 height = rect.height;
496 MenuTextureClip(clip_y, src_y, height, top, bottom);
497 CRect_i_ dest;
498 CRect_i_ src(src_x, src_y, width, height);
499 dest_height = height - 1;
500 dest_y = clip_y;
501 dest.x = x;
502 dest.y = dest_y;
503 dest.width = width;
504 dest.height = dest_height;
505 DrawMenu2DSprite(texture, dest, src, flag);
506 number /= 10;
507 }
508
509 return x;
510}
511
512int GetMsgLengthMenu(ClsMes *mes, int mes_no) {
513 int length = 0;
514 short *code = mes->GetTextLineDataTop_system(mes_no);
515
516 if (code != NULL) {
517 while (1) {
518 short c = *code++;
519
520 if ((unsigned int) (c + 0x100) <= 1U || code == NULL) {
521 break;
522 }
523
524 length++;
525 }
526 }
527
528 return length;
529}
530
538static CTexture *RetCTexAtora(int tip_no, int &x, int &y) {
539 CTexture *texture;
540 int tex_no;
541
542 tex_no = GetEditAtraChipData(MenuAtoraSel.map_no, tip_no)->tex_no;
543 x = ((tex_no + 7) % 7) * 36;
544 y = (tex_no / 7) * 36;
545
546 if (tip_no < 40) {
547 texture = ObTip;
548 } else if (tip_no >= 40) {
549 texture = ObPerson;
550 }
551
552 return texture;
553}
554
555void DrawAtoraParts(int x, int y, int tip_no, int top, int bottom, int alpha) {
556 CTexture *texture;
557 int src_x;
558 int src_y;
559 int height;
560
561 if (x < 340 || x > 600) {
562 return;
563 }
564
565 if (y < 80 || y > 300) {
566 return;
567 }
568
569 if (y < top - 35 || bottom <= y) {
570 return;
571 }
572
573 if (tip_no < 0) {
574 return;
575 }
576
577 texture = RetCTexAtora(tip_no, src_x, src_y);
578
579 if (texture == NULL) {
580 return;
581 }
582
583 height = 36;
584 MenuTextureClip(y, src_y, height, top, bottom);
585 CRect_i_ src(src_x, src_y, 36, height);
586 CRect_i_ shadow(x + 2, y + 1, 36, height);
587 DrawMenu2DSprite(texture, shadow, src, 0, 0, 0, (alpha * 80) >> 7);
588 CRect_i_ dest(x, y, 36, height);
589 DrawMenu2DSprite(texture, dest, src, alpha);
590}
591
600static EDITPARTS_INFO *SearchAtoraInfo(int index) {
601 int parts;
602 int count;
603
604 parts = CommonMenuAtoraInfo->GetNextParts(-1);
605 count = -1;
606
607 while (parts != -1) {
608 count++;
609
610 if (index == count) {
611 return CommonMenuAtoraInfo->GetPartsInfo(parts);
612 }
613
614 parts = CommonMenuAtoraInfo->GetNextParts(parts);
615 }
616
617 return NULL;
618}
619
627static int AtoraAllTipGet(int parts_no) {
628 EDITPARTS_INFO *info;
629 int result;
630 int i;
631 EDITPARTS_ELEMENT *element;
632
633 info = CommonMenuAtoraInfo->GetPartsInfo(parts_no);
634
635 if (info == NULL) {
636 return 0;
637 }
638
639 result = 1;
640
641 for (i = 0; i < 6; i++) {
642 element = &info->elements[i];
643
644 if (element == NULL) {
645 break;
646 }
647
648 if (0 <= element->id && element->enabled == 0) {
649 result = 0;
650 break;
651 }
652 }
653
654 return result;
655}
656
664static int AlreadyPeopleTalk(int map_no, int chip_no) {
665 SV_GRD_NPC *npc;
666
667 npc = SaveData->GetGrdNPCData(map_no, chip_no - 40);
668
669 if (npc == NULL || chip_no - 40 < 0) {
670 return 1;
671 }
672
673 return npc->talk_message;
674}
675
684static int AtoraCompOrEvent(EDITPARTS_INFO *info) {
685 EDIT_PARTS_ATRA *atra;
686 EDITPARTS_ELEMENT *element;
687 int complete;
688 int filled;
689 int talked;
690 int done;
691 int result;
692 int i;
693
694 atra = GetEditAtraPartsData(MenuAtoraSel.map_no, info->parts_no);
695
696 if (atra == NULL) {
697 return 0;
698 }
699
700 if (atra->kind == 0) {
701 return 0;
702 }
703
704 complete = CommonMenuAtoraInfo->CheckComplete(info->parts_no);
705 filled = 0;
706 talked = 1;
707 done = 0;
708
709 if (info != NULL) {
710 if (info->placed == info->stock) {
711 filled = 1;
712 }
713
714 for (i = 0; i < 6; i++) {
715 element = &info->elements[i];
716
717 if (element->id >= 40) {
718 if (element->npc_no >= 0) {
719 if (AlreadyPeopleTalk(MenuAtoraSel.map_no, element->id) == 0) {
720 talked = 0;
721 }
722 }
723 }
724 }
725
726 if (info->completion_flags & 1) {
727 done = 1;
728 }
729 }
730
731 result = 0;
732
733 if (complete && filled && talked && !done) {
734 result = 1;
735 }
736
737 return result;
738}
739
748static int AtraBoardMaxNum(int ground) {
749 EDIT_PARTS_ATRA *parts;
750 int count;
751
752 if (ground < 0 || ground >= 6) {
753 return 0;
754 }
755
756 parts = GetEditAtraPartsData(ground, 0);
757
758 if (parts == NULL) {
759 return 0;
760 }
761
762 for (count = 0; count < 40 && parts->max > 0; count++) {
763 parts++;
764 }
765
766 return count;
767}
768
777static int AtoraTipStatusSearch(EDITPARTS_INFO *info, int slot) {
778 int next;
779 int link;
780 int code;
781
782 if (info == NULL) {
783 return ATORA_LINK_NONE;
784 }
785
786 if (info->elements[slot].id < 0) {
787 return -1;
788 }
789
790 link = info->elements[slot].required_element;
791
792 if (link < 0 || info->elements[slot].enabled != 0) {
793 return ATORA_LINK_NONE;
794 }
795
796 if (link < 3 && slot >= 3) {
797 code = ATORA_LINK_ABOVE;
798 } else {
799 code = ATORA_LINK_BESIDE;
800 }
801
802 if (info->elements[link].enabled == 0) {
803 code += 10;
804 }
805
806 next = info->elements[link].required_element;
807
808 if (next >= 0 && info->elements[next].enabled == 0) {
809 code += 10;
810 }
811
812 return code;
813}
814
819static int AtraTipCanDisplay(EDIT_CHIP_ATTACH_DATA *attach) {
820 int display;
821
822 display = 1;
823
824 if (attach != NULL && attach->id < 40 && attach->npc_no >= 0 && (SaveData->GetGrdNPCData(MenuAtoraSel.map_no, attach->npc_no)->flags & 2) == 0) {
825 display = 0;
826 }
827
828 return display;
829}
830
839static void AtoraTipRelationDraw(int x, int y, EDITPARTS_INFO *info, int slot, int link, int alpha) {
840 int dx;
841 int dy;
842 int u;
843 int v;
844 int height;
845
846 if (info != NULL) {
847 static int tipcurCnt = 0;
848
849 u = 172;
850 v = 390;
851 height = 14;
852
853 // Only link codes ending in 1 or 2 give the arrow an offset.
854 if (link > 0) {
855 switch (link % 10) {
856 case ATORA_LINK_BESIDE:
857 dx = -10;
858 dy = 8;
859 u += 12;
860 break;
861 case ATORA_LINK_ABOVE:
862 dx = 12;
863 dy = -12;
864 break;
865 }
866 }
867
868 if (tipcurCnt % 460 > 200) {
869 dy += 3;
870 v += 14;
871 height = 10;
872 }
873
874 if (link < 49 && link >= 20) {
875 return;
876 }
877
878 if (link < 50 && link > 0) {
879 DrawMenu2DSprite(Sozai, CRect_i_(x + dx, y + dy, 12, height), CRect_i_(u, v, 12, height), alpha);
880 }
881
882 if (link >= 10) {
883 DrawMenu2DSprite(Sozai, CRect_i_(x, y, 36, 35), CRect_i_(220, 346, 36, 37), alpha);
884 }
885
886 tipcurCnt++;
887
888 if (tipcurCnt < 0 || tipcurCnt > 999999) {
889 tipcurCnt = 0;
890 }
891 }
892}
893
895int AtoraHeyCnt;
896
898int CompMsgCt;
899
901s32 *OpConfigPt;
902
910static void AtoraBoardEnableMovePos(int parts_no, int *enable) {
911 EDITPARTS_INFO *info;
912 int link;
913 int i;
914
915 info = SearchAtoraInfo(parts_no);
916
917 if (info == NULL) {
918 for (int j = 0; j < 6; j++) {
919 enable[j] = 0;
920 }
921
922 return;
923 }
924
925 for (i = 0; i < 6; i++) {
926 enable[i] = 1;
927
928 if (info->elements[i].id < 0) {
929 enable[i] = 0;
930 } else {
931 link = info->elements[i].required_element;
932
933 if (link < 0) {
934 enable[i] = 1;
935 } else {
936 link = info->elements[link].required_element;
937
938 if (link < 0) {
939 enable[i] = 1;
940 } else if (info->elements[link].enabled != 0) {
941 enable[i] = 1;
942 } else {
943 enable[i] = 0;
944 }
945 }
946 }
947 }
948}
949
958static int AtoraBoardGoToPos(int *enable, int pos, int min) {
959 while (min < pos) {
960 if (enable[pos] != 0) {
961 return pos;
962 }
963
964 pos--;
965 }
966
967 return pos;
968}
969
970int GetAtraMsgNo(int map_no, int element) {
971 int mes_no;
972
973 if (element < 0 || element >= 100) {
974 mes_no = 999;
975 } else {
976 EDIT_ELEMENT_ATRA *atra = GetEditAtraData(map_no, element);
977 mes_no = atra->msg_no + (map_no * 200 + 1000);
978
979 switch (map_no) {
980 case TOWN_QUEENS:
981 if (element == 1) {
982 int count = SaveData->GetGameIntFlag(1);
983
984 if (count > 0) {
985 mes_no += count + 0x1C;
986 }
987 }
988
989 break;
990 }
991
992 if (element >= 40) {
993 mes_no += 40;
994 }
995
996 if (element >= 80) {
997 mes_no += 40;
998 }
999 }
1000
1001 return mes_no;
1002}
1003
1012static int AtoraMsgNoGet(int map_no, int board_pos, int slot) {
1013 EDITPARTS_INFO *info;
1014 EDIT_PARTS_ATRA *parts;
1015 int msg_no;
1016 EDIT_CHIP_ATTACH_DATA *attach;
1017 EDIT_CHIP_ATTACH_DATA *elements;
1018 EDIT_ELEMENT_ATRA *chip;
1019 EDIT_CHIP_ATTACH_DATA *shown;
1020 int link;
1021 int flag;
1022
1023 info = SearchAtoraInfo(board_pos);
1024
1025 if (info == NULL) {
1026 return -1;
1027 }
1028
1029 parts = GetEditAtraPartsData(map_no, info->parts_no);
1030
1031 if (parts == NULL) {
1032 return -1;
1033 }
1034
1035 switch (slot) {
1036 case 0:
1037 if (info->parts_no < 0) {
1038 msg_no = -1000;
1039 break;
1040 }
1041
1042 msg_no = parts->msg_no + map_no * 200;
1043
1044 switch (map_no) {
1045 case TOWN_QUEENS:
1046 if (info->parts_no == 1) {
1047 flag = SaveData->GetGameIntFlag(1);
1048
1049 if (flag > 0) {
1050 msg_no += flag + 28;
1051 }
1052 }
1053
1054 break;
1055 }
1056
1057 break;
1058 default:
1059 elements = parts->elements;
1060 attach = &elements[slot] - 1;
1061 chip = GetEditAtraChipData(map_no, attach->id);
1062 shown = &GetEditAtraPartsData(MenuAtoraSel.map_no, info->parts_no)->elements[slot - 1];
1063 msg_no = chip->msg_no + (map_no * 200 + 40);
1064
1065 if (attach->id >= 40) {
1066 msg_no += 40;
1067 }
1068
1069 if (info->elements[slot - 1].enabled == 0) {
1070 msg_no += 60;
1071 }
1072
1073 link = info->elements[slot - 1].required_element;
1074
1075 if ((link >= 0 && info->elements[link].enabled == 0) || AtraTipCanDisplay(shown) == 0) {
1076 msg_no = -788;
1077 }
1078
1079 break;
1080 }
1081
1082 return msg_no;
1083}
1084
1093static int AtoraTipOnlyMsgNoGet(int map_no, int number) {
1094 EDIT_ELEMENT_ATRA *chip;
1095 int msg_no;
1096
1097 chip = GetEditAtraChipData(map_no, number);
1098
1099 if (chip == NULL) {
1100 return -1;
1101 }
1102
1103 msg_no = chip->msg_no + 40;
1104
1105 if (number >= 40) {
1106 msg_no += 40;
1107 }
1108
1109 return msg_no;
1110}
1111
1119static void AtoraTipGetTexPos(int tip_no, int &x, int &y) {
1120 int tex_no;
1121
1122 tex_no = GetEditAtraChipData(MenuAtoraSel.map_no, tip_no)->tex_no;
1123
1124 if (tip_no >= 40) {
1125 x = 144;
1126 y = 180;
1127 } else if (0 <= tex_no && tex_no < 40) {
1128 x = (tex_no % 7) * 36;
1129 y = (tex_no / 7) * 36;
1130 }
1131}
1132
1140static void AtoraTipObjectOrPerson(int x, int y, int tip_no, int dark, int alpha) {
1141 int u;
1142 int v;
1143 CTexture *texture = RetCTexAtora(tip_no, u, v);
1144 CRect_i_ source(u, v, 0x24, 0x24);
1145 int red, green, blue;
1146 blue = green = red = 0x80;
1147
1148 if (dark != 0) {
1149 red = 0x80;
1150 green = 0x44;
1151 blue = 0;
1152 }
1153
1154 DrawMenu2DSprite(texture, CRect_i_(x, y, source.width, source.height - 1), source, red, green, blue, alpha);
1155}
1156
1165static CTexture *AtoraTipHoleTexInfoGet(int gold, unsigned char *color) {
1166 if (gold) {
1167 color[0] = 0x8C;
1168 color[1] = 0x80;
1169 color[2] = 0x50;
1170 return HoleGold;
1171 }
1172
1173 color[0] = 0x80;
1174 color[1] = 0x80;
1175 color[2] = 0x80;
1176 return HoleGray;
1177}
1178
1187static void AtoraPlateDrawHaichiBar(EDITPARTS_INFO *info, int x, int y, int flag) {
1188 int empty = 83 - info->placed * 83 / info->stock;
1189 CRect_i_ dest;
1190 CRect_i_ src(244, 323 - empty, 12, empty);
1191
1192 dest.x = x + 12;
1193 dest.y = y + 107 - empty;
1194 dest.width = 12;
1195 dest.height = empty;
1196 DrawMenu2DSprite(Sozai, dest, src, flag);
1197 DrawAtraBuildNum(info, x, y, flag);
1198}
1199
1200void DrawAtraBuildNum(EDITPARTS_INFO *info, int x, int y, int alpha) {
1201 RECT digit = {0, 212, 12, 12};
1202 int num_x;
1203
1204 num_x = x + 8;
1205
1206 if ((info->stock - info->placed) / 10 > 0) {
1207 num_x += 24;
1208 } else {
1209 num_x += 12;
1210 }
1211
1212 if (info->stock / 10 > 0) {
1213 num_x += 24;
1214 } else {
1215 num_x += 12;
1216 }
1217
1218 num_x = DrawMenuNumber(info->stock, num_x, y + 5, StayTex, digit, 1, alpha);
1219 DrawMenu2DSprite(StayTex, CRect_i_(num_x - 10, y + 5, 12, 12), CRect_i_(120, digit.y, 12, 12), alpha);
1220 DrawMenuNumber(info->stock - info->placed, num_x - 7, y + 5, StayTex, digit, 1, alpha);
1221}
1222
1223void DrawAtora(int x, int y, int parts_index, int alpha) {
1224 int u;
1225 int v;
1226 unsigned char colour[4];
1227
1228 if (y < -100 || y > 0x1CC) {
1229 return;
1230 }
1231
1232 EDITPARTS_INFO *info = CommonMenuAtoraInfo->GetPartsInfo(parts_index);
1233
1234 if (info == NULL) {
1235 return;
1236 }
1237
1238 EDIT_PARTS_ATRA *parts = GetEditAtraPartsData(MenuAtoraSel.map_no, info->parts_no);
1239 int complete = CommonMenuAtoraInfo->CheckComplete(parts_index);
1240 int all_tips = AtoraAllTipGet(parts_index);
1241 int event = AtoraCompOrEvent(info);
1242 u = 0;
1243 v = 0;
1244
1245 if (all_tips != 0 || (info->obtained != 0 && info->elements[0].id < 0)) {
1246 v = 0x78;
1247 }
1248
1249 DrawMenu2DSprite(Sozai, CRect_i_(x, y, 0x100, 0x78), CRect_i_(0, v, 0x100, 0x79), alpha);
1250
1251 if (0 < info->stock && MenuAtoraSel.map_no != 5) {
1252 AtoraPlateDrawHaichiBar(info, x, y, alpha);
1253 }
1254
1255 int picture_x = x + 0x20;
1256 int picture_y = y + 8;
1257 int draw_picture = 1;
1258 int tex_no = parts->tex_no;
1259 u = (tex_no / 6) * 0x54 + 0x104;
1260 v = (tex_no + 6) % 6 * 0x54;
1261
1262 if (MenuAtoraSel.map_no == 5) {
1263 if (complete == 0) {
1264 draw_picture = 0;
1265 } else {
1266 picture_x = x + 0x14;
1267 picture_y = y + 0xC;
1268 }
1269 }
1270
1271 if (draw_picture != 0) {
1272 DrawMenu2DSprite(Sozai, CRect_i_(picture_x, picture_y, 0x54, 0x54), CRect_i_(u, v, 0x54, 0x54), alpha);
1273 }
1274
1275 u = 0;
1276 v = 0;
1277 int slot_x = 0x78;
1278 int slot_y = 8;
1279
1280 if (parts->elements[0].id < 0) {
1281 DrawMenu2DSprite(Sozai, CRect_i_(x + 0x88, y - 1, 0x78, 0x5D), CRect_i_(0, 0xF0, 0x78, 0x5C), alpha);
1282 DrawMenu2DSprite(Sozai, CRect_i_(x + 0x88, y + 7, 0x64, 0x1C), CRect_i_(0, 0x164, 0x64, 0x1C), alpha);
1283 } else if (event == 0) {
1284 for (int i = 0; i < 6; i++) {
1285 GetEditAtraChipData(MenuAtoraSel.map_no, parts->elements[i].id);
1286 EDIT_CHIP_ATTACH_DATA *chip = &parts->elements[i];
1287
1288 if (chip->id >= 0) {
1289 int status = AtoraTipStatusSearch(info, i);
1290
1291 if (AtraTipCanDisplay(chip) == 0) {
1292 status = ATORA_LINK_HIDDEN;
1293 }
1294
1295 int tip_x = x + slot_x;
1296 int tip_y = y + slot_y;
1297 AtoraTipRelationDraw(tip_x, tip_y, info, i, status, alpha);
1298
1299 if ((chip->required_element < 0 || status < 3) && status != ATORA_LINK_HIDDEN) {
1300 AtoraTipGetTexPos(chip->id, u, v);
1301 CTexture *hole = AtoraTipHoleTexInfoGet(all_tips, colour);
1302 DrawMenu2DSprite(hole, CRect_i_(tip_x, tip_y, 0x24, 0x24), CRect_i_(u, v, 0x24, 0x25), colour[0], colour[1], colour[2], alpha);
1303 }
1304
1305 if (info->elements[i].enabled != 0) {
1306 AtoraTipObjectOrPerson(tip_x, tip_y, info->elements[i].id, all_tips, alpha);
1307
1308 if (complete == 0 && chip->npc_no >= 0 && AlreadyPeopleTalk(MenuAtoraSel.map_no, chip->id) == 0 && AtoraHeyCnt % (chip->id + 0x4B) < 0x46) {
1309 DrawMenu2DSprite(CompleteTex, CRect_i_(tip_x - 9, tip_y - 7, 0x20, 0x15), CRect_i_(0xE2, 0, 0x20, 0x16), alpha);
1310 }
1311 }
1312 }
1313
1314 slot_x += 0x2C;
1315
1316 if (i == 2) {
1317 slot_x = 0x78;
1318 slot_y = 0x35;
1319 }
1320 }
1321 } else {
1322 int base_x = x + 0x70;
1323 int base_y = y + 6;
1324 int count = 0;
1325
1326 for (int i = 0; i < 6; i++) {
1327 if (info->elements[i].id < 0) {
1328 break;
1329 }
1330
1331 if (0 <= info->elements[i].id) {
1332 count++;
1333 }
1334 }
1335
1336 float wave = cosf(PI * CompMsgCt / (160.0f + (count >> 1)));
1337 base_x = (int) ((float) (base_x - 6) + 6.0f * wave);
1338 base_y = (int) ((float) base_y + 2.0f * wave);
1339 float width = 128.0f + 6.0f * wave;
1340 (int) width;
1341 float height = 88.0f + 3.0f * wave;
1342 (int) height;
1343 base_x = (int) ((float) base_x + 8.0f * cosf(PI * CompMsgCt / (180.0f + count)));
1344 base_y = (int) ((float) base_y + 4.0f * sinf(PI * CompMsgCt / (140.0f + count)));
1345 DrawMenu2DSprite(CompleteTex, CRect_i_(base_x, base_y, (int) width, (int) height), CRect_i_(0, 0x28, 0x80, 0x58), alpha);
1346 }
1347
1348 CompMsgCt++;
1349
1350 if (CompMsgCt >= 320000 || CompMsgCt < 0) {
1351 CompMsgCt = 0;
1352 }
1353}
1354
1362static void DrawAtoraNothing(int x, int y, int alpha) {
1363 DrawMenu2DSprite(Sozai, CRect_i_(x, y, 18, 18), CRect_i_(184, 346, 18, 18), alpha);
1364 DrawMenu2DSprite(Sozai, CRect_i_(x + 18, y, 220, 18), CRect_i_(200, 346, 4, 18), alpha);
1365 DrawMenu2DSprite(Sozai, CRect_i_(x + 238, y, 18, 18), CRect_i_(202, 346, 18, 18), alpha);
1366 DrawMenu2DSprite(Sozai, CRect_i_(x, y + 18, 18, 84), CRect_i_(184, 360, 18, 4), alpha);
1367 DrawMenu2DSprite(Sozai, CRect_i_(x + 238, y + 18, 18, 84), CRect_i_(202, 360, 18, 4), alpha);
1368 DrawMenu2DSprite(Sozai, CRect_i_(x, y + 102, 18, 18), CRect_i_(184, 364, 18, 18), alpha);
1369 DrawMenu2DSprite(Sozai, CRect_i_(x + 18, y + 102, 220, 18), CRect_i_(200, 364, 4, 18), alpha);
1370 DrawMenu2DSprite(Sozai, CRect_i_(x + 238, y + 102, 18, 18), CRect_i_(202, 364, 18, 18), alpha);
1371#ifdef PAL
1372 int lang = GetMenuLangFlag();
1373 // Horizontal offset of the message, by menu language.
1374 s8 message_x[7] = {64, 64, 64, 64, 54, 64, 64};
1375 DrawMenu2DSprite(Sozai, CRect_i_(x + message_x[lang], y + 44, 132, 30), CRect_i_(124, 418, 132, 30), alpha);
1376#else
1377 DrawMenu2DSprite(Sozai, CRect_i_(x + 64, y + 44, 132, 30), CRect_i_(124, 418, 132, 30), alpha);
1378#endif
1379}
1380
1388static void DrawMsgAtraWarning(ClsMes *mes, int x, int y) {
1389 if (mes == NULL) {
1390 return;
1391 }
1392
1393 if (mes->mes_made != 200) {
1394 mes->MakeMesWin(200);
1395 }
1396
1397 mes->MakeMesWin(200);
1398 MenuTextureReload(mes->tex_block);
1399 mes->stay_frame = true;
1400 mes->text_x = x;
1401 mes->text_y = y;
1402 mes->Step();
1403 mes->DrawMesWin();
1404}
1405
1413static void AtoraTipInfoInit() {
1414 NowTipHavePt->mode = ATORA_SIDE_BOARD;
1415 NowTipHavePt->parts_no = -1;
1416 NowTipHavePt->slot = -1;
1417 NowTipHavePt->tip_no = -1;
1418}
1419
1420int GetMenuAtraEventFlag() {
1421 return MenuAtoraSel.event_flag;
1422}
1423
1431static void SetMenuAtraEventFlag(int flag) {
1432 MenuAtoraSel.event_flag = flag;
1433}
1434
1442static void MenuAtoraAfterFadeIn() {
1443 int msg_no;
1444
1445 CommonMenuMes2.SetBuff(GetAtraMsgReadBuf);
1446 CommonMenuMes2.mes_made = -1;
1447 msg_no = AtoraMsgNoGet(MenuAtoraSel.map_no, MenuAtoraSel.board_pos, 0);
1448 CommonMenuMes2.MakeMesWin(msg_no >= 0 ? msg_no + 1000 : 0);
1449}
1450
1451void InitMenuAtora1(int open_mode, int edit_map, int *texture_blocks, u_long128 *buffer) {
1452 MenuAtoraSel.open_mode = open_mode;
1453 InitPersonalBoardMode((CUserStatus *) SaveData->GetDngStatus(), &MenuAtoraSel.board, PERSONAL_BOARD_ATLA, edit_map + BOARD_PAGE_ATLA_VILLAGE);
1454 MenuAtoraSel.prev_mes_buff = CommonMenuMes2.buff;
1455 AtoraTextureBaseBlock = texture_blocks[0];
1456 AtoraTextureReadBlock = texture_blocks[1];
1457 AtoraOffsetBuf = buffer;
1458 AtoraOffsetBuf = MenuCalcBufAlignment(buffer);
1459 AtoraTextureEnterFlag = 0;
1460 MenuAtoraSel.edit_map = edit_map;
1461 CommonMenuMes3.Preset(MES_PRESET_NAME);
1462 CommonMenuMes3.style = MES_EDGE_NONE;
1463 CommonMenuMes3.end_mark = false;
1464 CommonMenuMes3.auto_pos = MES_POS_NONE;
1465 CommonMenuMes3.mes_made = -1;
1466 AtoraNameMes.Preset(MES_PRESET_NAME);
1467 AtoraNameMes.tex_buff = MesWinTexBuff_12;
1468 memset(AtoraNameMes.tex_buff, 0, 0x100);
1469 AtoraNameMes.rows = 4;
1470 s8 widths[7] = {0x10, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C};
1471 AtoraNameMes.char_width = widths[GetMenuLangFlag()];
1472 AtoraNameMes.narrow_gaiji_set = 2;
1473
1474 for (int i = 0; i < 10; i++) {
1475 AtoraNameMes.mes_no[i] = 999;
1476 AtoraNameMes.values[i] = -1;
1477 }
1478
1479 AtoraNameMes.mes_made = -1;
1480 AtoraNameMes.narrow_gaiji = true;
1481 NowTipHavePt = (ATORA_TIP_HAVE *) &MenuAtoraSel.board.held_item;
1482 MenuAtoraSel.last_board_pos = 0;
1483 MenuAtoraSel.board.cursor = 0;
1484 MenuAtoraSel.step = ATORA_STEP_FADE_IN;
1485 MenuAtoraSel.step_count = 0;
1486 SetMenuAtraEventFlag(0);
1487 CMenuCursor *cursor = SaveData->GetMenuCursor();
1488
1489 if (cursor->reset_pos == 0) {
1490 MenuAtoraSel.mode = cursor->mode[3];
1491
1492 if (MenuAtoraSel.mode < 0 || MenuAtoraSel.mode > 1) {
1493 MenuAtoraSel.mode = ATORA_SIDE_BOARD;
1494 }
1495
1496 int pos = cursor->pos[3];
1497
1498 switch (MenuAtoraSel.mode) {
1499 case ATORA_SIDE_BOARD:
1500 MenuAtoraSel.board_pos = pos;
1501 break;
1502 case ATORA_SIDE_CHIP_LIST:
1503 MenuAtoraSel.board.cursor = pos;
1504 MenuAtoraSel.board.top_row = MenuAtoraSel.board.cursor / 5 - 2;
1505
1506 if (MenuAtoraSel.board.top_row < 0) {
1507 MenuAtoraSel.board.top_row = 0;
1508 }
1509
1510 break;
1511 }
1512 } else {
1513 MenuAtoraSel.mode = ATORA_SIDE_BOARD;
1514 MenuAtoraSel.board_pos = 0;
1515 MenuAtoraSel.board.cursor = 0;
1516 }
1517
1518 if (GetMenuAtraEventFlag() != 0) {
1519 MenuAtoraSel.board_pos = MenuAtoraSel.event_board_pos;
1520 }
1521}
1522
1523void InitMenuAtoraSelect(int map_no) {
1524 int place;
1525 char path[64];
1526 int map;
1527 int next;
1528 int count;
1529 EDITPARTS_INFO *info;
1530 int pos;
1531 int y;
1532 int i;
1533
1534 MenuAtoraSel.map_no = map_no;
1535 map = MenuAtoraSel.map_no;
1536
1537 if (AtoraTextureEnterFlag == 0) {
1538 GetPathReadDifferntLang(path);
1539 strcat(path, "a%d.pak");
1540 sprintf(path, path, map + 1);
1541
1542 if (ReadBGSync()) {
1543 BreakReadBG();
1544 }
1545
1546 StartReadBG();
1547 LoadFileBG(path, AtoraOffsetBuf, NULL);
1548 MenuAtoraSel.load_state = 0;
1549
1550 if ((MenuAtoraSel.open_mode == ATORA_OPEN_PLACE || MenuAtoraSel.open_mode == ATORA_OPEN_WARN) && MenuAtoraSel.map_no == MapNo) {
1551 CommonMenuAtoraInfo = &EditPartsInfo;
1552 } else {
1553 CommonMenuAtoraInfo = &BtEditPartsInfo;
1554 CommonMenuAtoraInfo->Load(MenuAtoraSel.map_no, SaveData, 1);
1555 }
1556 }
1557
1558 MenuAtoraSel.board.atla_elements = SaveData->GetElemData(map);
1559 next = CommonMenuAtoraInfo->GetNextPartsNum(-1);
1560 AtoraTipInfoInit();
1561 count = AtraBoardMaxNum(MenuAtoraSel.map_no);
1562
1563 if (MenuAtoraSel.board_pos > count - 1) {
1564 MenuAtoraSel.board_pos = count - 1;
1565 }
1566
1567 info = SearchAtoraInfo(MenuAtoraSel.board_pos);
1568
1569 if (MenuAtoraSel.mode == ATORA_SIDE_BOARD) {
1570 if (info != NULL) {
1571 if (MenuAtoraSel.board.cursor > 0 && info->elements[MenuAtoraSel.board.cursor - 1].id < 0) {
1572 MenuAtoraSel.board.cursor = 0;
1573 }
1574 } else {
1575 MenuAtoraSel.board.cursor = 0;
1576 }
1577 }
1578
1579 MenuAtoraSel.scroll_y = 146.0f - 130.0f * MenuAtoraSel.board_pos;
1580
1581 if (0 < next) {
1582 MenuAtoraSel.cursor_x = 38.0f;
1583 MenuAtoraSel.cursor_y = 175.0f;
1584 } else {
1585 place = MenuAtoraSel.board.cursor % 4;
1586 MenuAtoraSel.cursor_x = place * 58 + 334;
1587 place = (MenuAtoraSel.board.cursor >> 2) - MenuAtoraSel.board.top_row;
1588
1589 if (place < 0) {
1590 place = 0;
1591 }
1592
1593 if (place > 3) {
1594 place = 3;
1595 }
1596
1597 MenuAtoraSel.cursor_y = place * 50 + 118;
1598 }
1599
1600 if (next > 0) {
1601 pos = MenuAtoraSel.board_pos - 1;
1602 y = MenuAtoraSel.scroll_y + 80 + 130.0f * pos;
1603
1604 for (i = 0; i < 3; i++) {
1605 info = SearchAtoraInfo(pos);
1606
1607 if (info != NULL) {
1608 AtoraNameMes.mes_no[i] = info->parts_no + (MenuAtoraSel.map_no * 200 + 1000);
1609 AtoraNameMes.line_pos[0].x = 134;
1610 AtoraNameMes.line_pos[0].y = y;
1611 y += 130.0f;
1612 } else {
1613 AtoraNameMes.mes_no[i] = 999;
1614 }
1615
1616 pos++;
1617 }
1618
1619 AtoraNameMes.mes_made = -1;
1620 AtoraNameMes.MakeMesWin(210);
1621 }
1622}
1623
1627static inline void SetCursorMode(CMenuCursor *cursor, int menu, int mode) {
1628 cursor->mode[menu] = mode;
1629}
1630
1635static void ExitAtoraSelect() {
1636 CMenuCursor *cursor;
1637 int pos;
1638
1639 cursor = SaveData->GetMenuCursor();
1640
1641 if (cursor->reset_pos == 0) {
1642 SetCursorMode(cursor, 3, MenuAtoraSel.mode);
1643
1644 switch (MenuAtoraSel.mode) {
1645 case ATORA_SIDE_BOARD:
1646 pos = MenuAtoraSel.board_pos;
1647 break;
1648 case ATORA_SIDE_CHIP_LIST:
1649 pos = MenuAtoraSel.board.cursor;
1650 break;
1651 }
1652
1653 cursor->pos[3] = pos;
1654 }
1655
1656 CommonMenuMes2.SetBuff(MenuAtoraSel.prev_mes_buff);
1657 CommonMenuMes3.auto_pos = MES_POS_NONE;
1658 CommonMenuMes3.Preset(MES_PRESET_SYSTEM);
1659 AtoraNameMes.narrow_gaiji = false;
1660}
1661
1669static void AtoraTexInfoGet() {
1670 CompleteTex = TexManager.GetTexture("complete", -1);
1671 Sozai = TexManager.GetTexture("sozai", AtoraTextureReadBlock);
1672 HoleGray = TexManager.GetTexture("holegray", AtoraTextureReadBlock);
1673 HoleGold = TexManager.GetTexture("holegold", AtoraTextureReadBlock);
1674 ObTip = TexManager.GetTexture("obtip", AtoraTextureReadBlock);
1675 ObPerson = TexManager.GetTexture("obperson", AtoraTextureReadBlock);
1676 VillageBar = TexManager.GetTexture("viltag", AtoraTextureBaseBlock);
1677 VillageName = TexManager.GetTexture("vilname", AtoraTextureBaseBlock);
1678}
1679
1680void DrawMenuAtoraSelect() {
1681 int alpha;
1682 int tint;
1683 int fade;
1684
1685 alpha = 0x80;
1686
1687 switch (MenuAtoraSel.step) {
1688 case ATORA_STEP_FADE_IN:
1689 alpha = MenuAtoraSel.step_count * 8;
1690 break;
1691 case ATORA_STEP_FADE_OUT:
1692 alpha = 0x80 - MenuAtoraSel.step_count * 8;
1693 break;
1694 }
1695
1696 if (alpha < 0) {
1697 alpha = 0;
1698 }
1699
1700 if (alpha > 0x80) {
1701 alpha = 0x80;
1702 }
1703
1704 if (MenuAtoraSel.step != ATORA_STEP_EVENT_PLAY) {
1705 DrawAtoraSelect(alpha);
1706
1707 if (MenuAtoraSel.step == ATORA_STEP_RUN) {
1708 DrawMenuObjectVibe(MenuAtoraSel.cursor_x, MenuAtoraSel.cursor_y, 1, MenuAtoraSel.cursor_icon_u);
1709 }
1710
1711 if (MenuAtoraSel.step != ATORA_STEP_RUN && AtoraTextureEnterFlag != 0) {
1712 MenuAtoraSel.step_count++;
1713 } else {
1714 MenuAtoraSel.step_count = 0;
1715 }
1716
1717 CTexture frame = *TexManager.GetTexture("frame_image", -1);
1718 ((sceGsTex0 *) &frame.tex0)->bits.tcc = 0;
1719 sceGsTexa texa = mgTexa;
1720 texa.AEM = 1;
1721 texa.TA0 = 0x80;
1722 MGSetGsTEXA(&texa);
1723 tint = 0;
1724 fade = 0;
1725
1726 switch (MenuAtoraSel.step) {
1727 case ATORA_STEP_FADE_IN:
1728 tint = 0x80 - MenuAtoraSel.step_count * 7;
1729 break;
1730 case ATORA_STEP_EVENT_FADE_OUT:
1731 fade = MenuAtoraSel.step_count * 2;
1732 break;
1733 case ATORA_STEP_EVENT_FADE_IN:
1734 fade = 0x80 - MenuAtoraSel.step_count * 2;
1735 break;
1736 case ATORA_STEP_FADE_OUT:
1737 tint = MenuAtoraSel.step_count * 5 + 0x40;
1738 break;
1739 }
1740
1741 if (tint < 0) {
1742 tint = 0;
1743 }
1744
1745 if (tint > 0x80) {
1746 tint = 0x80;
1747 }
1748
1749 if (fade < 0) {
1750 fade = 0;
1751 }
1752
1753 if (fade > 0x80) {
1754 fade = 0x80;
1755 }
1756
1757 CRect_i_ rect(320, 0, 320, SCREEN_HEIGHT);
1758 DrawMenu2DSprite(&frame, rect, rect, 0x40, 0x40, 0x40, tint);
1759 MGSetGsTEXA(NULL);
1760
1761 if (MenuAtoraSel.step == ATORA_STEP_EVENT_FADE_OUT || MenuAtoraSel.step == ATORA_STEP_EVENT_FADE_IN) {
1762 AllFadeForMenu(fade);
1763 }
1764
1765 if (MenuAtoraSel.step == ATORA_STEP_WARNING) {
1766 CommonMenuMes3.auto_pos = MES_POS_CENTRE;
1767 CommonMenuMes3.edge_alpha = 0x80;
1768 DrawMsgAtraWarning(&CommonMenuMes3, 184, 150);
1769 } else {
1770 CommonMenuMes3.mes_made = -1;
1771 }
1772 }
1773
1774 if (MenuAtoraSel.step == ATORA_STEP_EVENT_PLAY) {
1775 EastKingEventDraw();
1776 }
1777}
1778
1786static void DrawAtoraSelect(int fade) {
1787 int open_mode;
1788 int event;
1789 int alpha;
1790 EDITPARTS_INFO *info;
1791 int settled;
1792 int remaining;
1793 int all_tips;
1794 int parts;
1795 float target;
1796 float y;
1797 float cursor_x;
1798 float cursor_y;
1799 float step;
1800 int waku_size;
1801 int waku_x;
1802 int waku_y;
1803 int odd;
1804 int count;
1805 int board_y;
1806 int u;
1807 int v;
1808
1809 AtoraTexInfoGet();
1810 alpha = 0x80;
1811
1812 switch (MenuAtoraSel.step) {
1813 case ATORA_STEP_FADE_IN:
1814 case ATORA_STEP_FADE_OUT:
1815 alpha = fade;
1816 break;
1817 case ATORA_STEP_CHANGE_MAP:
1818 alpha = MenuAtoraSel.step_count * 5;
1819 break;
1820 }
1821
1822 if (alpha > 0x80) {
1823 alpha = 0x80;
1824 }
1825
1826 open_mode = MenuAtoraSel.open_mode;
1827 MenuAtoraSel.name_alpha = alpha;
1828 info = SearchAtoraInfo(MenuAtoraSel.board_pos);
1829 event = 0;
1830 all_tips = 0;
1831
1832 if (info != NULL) {
1833 event = AtoraCompOrEvent(info);
1834 all_tips = AtoraAllTipGet(info->parts_no);
1835 }
1836
1837 MenuTextureReload(AtoraTextureReadBlock);
1838 target = 146.0f - 130.0f * MenuAtoraSel.board_pos;
1839 step = (target - MenuAtoraSel.scroll_y) / 2.0f;
1840 odd = (int) step % 2;
1841 step /= 2.0f;
1842 step += odd;
1843 MenuAtoraSel.scroll_y += step;
1844 settled = 1;
1845
1846 if (!((float) abs((int) ((float) MenuAtoraSel.scroll_y - target)) <= 4.0f)) {
1847 settled = 0;
1848 event = 0;
1849 all_tips = 0;
1850 }
1851
1852 if (MenuAtoraSel.mode != ATORA_SIDE_BOARD || open_mode != ATORA_OPEN_PLACE) {
1853 settled = 0;
1854 }
1855
1856 if (NowEditMap != MenuAtoraSel.map_no) {
1857 settled = 0;
1858 }
1859
1860 if (info != NULL) {
1861 if (info->placed == info->stock) {
1862 settled = 0;
1863 }
1864 } else {
1865 settled = 0;
1866 }
1867
1868 remaining = AtraBoardMaxNum(MenuAtoraSel.map_no);
1869 parts = CommonMenuAtoraInfo->GetNextParts(-1);
1870 y = MenuAtoraSel.scroll_y;
1871
1872 if (AtoraTextureEnterFlag != 0) {
1873 AtoraHeyCnt++;
1874
1875 while (0 <= parts) {
1876 DrawAtora(0x38, (int) y, parts, alpha);
1877 parts = CommonMenuAtoraInfo->GetNextParts(parts);
1878 y += 130.0f;
1879 remaining--;
1880 }
1881
1882 while (remaining > 0) {
1883 DrawAtoraNothing(0x38, (int) y, alpha);
1884 y += 130.0f;
1885 remaining--;
1886 }
1887
1888 if (AtoraHeyCnt > 10000000) {
1889 AtoraHeyCnt = 0;
1890 }
1891
1892 if (settled != 0 || (MenuAtoraSel.map_no == 5 && all_tips != 0)) {
1893 float phase = CursorVibeCnt % 89;
1894 phase -= 45.0f;
1895 float sign_y = 208.0f + 8.0f * sinf(PI * phase / 45.0f);
1896 CRect_i_ source(0, 0, 0x50, 0x20);
1897
1898 if (MenuAtoraSel.map_no == 5 && all_tips != 0) {
1899 source.x += 0x50;
1900 }
1901
1902 DrawMenu2DSprite(CompleteTex, CRect_i_(0x83, (int) (1.0f + sign_y), source.width, source.height), source, 6, 6, 6, (alpha * 0x50) >> 7);
1903 DrawMenu2DSprite(CompleteTex, CRect_i_(0x80, (int) sign_y, source.width, source.height), source, alpha);
1904 }
1905
1906 if (MenuAtoraSel.step == ATORA_STEP_COMPLETE_FLASH) {
1907 sceGsAlpha blend = mgAlpha;
1908 blend.bits.a = 0;
1909 blend.bits.b = 2;
1910 blend.bits.c = 0;
1911 blend.bits.d = 1;
1912 MGSetGsALPHA(&blend);
1913 int flash = (int) (128.0f - 3.0f * MenuAtoraSel.step_count);
1914
1915 if (flash < 5) {
1916 flash = 0;
1917 MenuAtoraSel.step = ATORA_STEP_RUN;
1918 }
1919
1920 DrawMenu2DSprite(Sozai, CRect_i_(0x34, 0x8B, 0x10C, 0x82), CRect_i_(0x8C, 0x1C0, 0x74, 0x40), flash);
1921 MGSetGsALPHA(NULL);
1922 }
1923
1924 AtoraBoardFadeEffect();
1925 }
1926
1927 count = PersonalRetMax(MenuAtoraSel.board.page);
1928 board_y = 0x7F - MenuAtoraSel.board.top_row * 0x28;
1929 board_y = (int) ((MenuAtoraSel.board.y += (board_y - MenuAtoraSel.board.y) / 4.0f), MenuAtoraSel.board.y);
1930 MenuTextureReload(PerBoardTex->block);
1931 DrawPerBoardDraw(0, count, 0x168, board_y, 0x81, 0x121, PerBoardTex, 0x80);
1932
1933 if (AtoraTextureEnterFlag != 0) {
1934 MenuTextureReload(AtoraTextureReadBlock);
1935 CommonIconDraw(MenuAtoraSel.board.page, count, 0x168, board_y + 1, 0x81, 0x121, alpha);
1936 }
1937
1938 MenuTextureReload(PerBoardTex->block);
1939 PersonalBoardTagDraw(MenuAtoraSel.board.page, 0x154, 0x78, PerBoardTex, 0, 0x80);
1940
1941 if (PerBoardTex != NULL) {
1942 MenuTextureReload(PerBoardTex->block);
1943 PersonalBoardDrawWaku(0x154, 0x78, PerBoardTex, 0x80);
1944 PersonalBoardScrlBarDraw(count, 0x154, 0x78, MenuAtoraSel.board.scroll, MenuAtoraSel.board.top_row, PerBoardTex, 0x80);
1945 PersonalBoardMaxDraw(count, 0x154, 0x78, PerBoardTex, 0x80);
1946 }
1947
1948 AtoraNameDraw(0);
1949
1950 if (0 < GetAtoraMaxVillage() - 3) {
1951 int arrow_y = (int) (66.0f + 4.0f * sinf(PI * (float) (CursorVibeCnt % 79 - 40) / 40.0f));
1952 DrawMenu2DSprite(PerBoardTex, CRect_i_(0x146, arrow_y, 0x1A, 0x18), CRect_i_(0x62, 0x14, 0x1A, 0x18), 0x80);
1953 DrawMenu2DSprite(PerBoardTex, CRect_i_(0x20C, arrow_y, 0x1A, 0x18), CRect_i_(0x7C, 0x14, 0x1A, 0x18), 0x80);
1954 }
1955
1956 if (PerBoardTex != NULL) {
1957 MenuTextureReload(PerBoardTex->block);
1958 }
1959
1960 switch (MenuAtoraSel.mode) {
1961 case ATORA_SIDE_BOARD:
1962 if (info == NULL) {
1963 cursor_x = 76.0f;
1964 cursor_y = 176.0f;
1965 } else if (MenuAtoraSel.board.cursor == 0) {
1966 cursor_x = 56.0f;
1967 cursor_y = 176.0f;
1968 waku_x = (int) (cursor_x + 2.0f);
1969 waku_y = (int) (cursor_y - 15.0f);
1970 waku_size = 0x56;
1971 } else {
1972 waku_size = 0x24;
1973 cursor_x = (MenuAtoraSel.board.cursor + 2) % 3 * 0x2C + 0x92;
1974
1975 if (MenuAtoraSel.board.cursor > 0 && MenuAtoraSel.board.cursor < 4) {
1976 cursor_y = 167.0f;
1977 } else {
1978 cursor_y = 210.0f;
1979 }
1980
1981 waku_x = (int) (3.0f + cursor_x);
1982 waku_y = (int) (cursor_y - 5.0f);
1983 }
1984
1985 break;
1986 case ATORA_SIDE_CHIP_LIST: {
1987 cursor_x = MenuAtoraSel.board.cursor % 5 * 0x28 + 0x14E;
1988 int row = MenuAtoraSel.board.cursor / 5 - MenuAtoraSel.board.top_row;
1989
1990 if (row < 0) {
1991 row = 0;
1992 }
1993
1994 if (row > 3) {
1995 row = 3;
1996 }
1997
1998 cursor_y = row * 0x28 + 0x8A;
1999 waku_x = (int) cursor_x;
2000 waku_y = (int) cursor_y;
2001 waku_size = 0x24;
2002 break;
2003 }
2004 }
2005
2006 MenuAtoraSel.cursor_icon_u = 0x40;
2007
2008 if (NowTipHavePt->tip_no > -1) {
2009 MenuAtoraSel.cursor_icon_u = 0x80;
2010 cursor_x += 25.0f;
2011 cursor_y += 12.0f;
2012 } else {
2013 switch (MenuAtoraSel.mode) {
2014 case ATORA_SIDE_BOARD:
2015 if (info != NULL) {
2016 if (0 < MenuAtoraSel.board.cursor && info->elements[MenuAtoraSel.board.cursor - 1].enabled != 0) {
2017 cursor_x += 27.0f;
2018 cursor_y += 12.0f;
2019 MenuAtoraSel.cursor_icon_u = 0x60;
2020 } else {
2021 MenuAtoraSel.cursor_icon_u = 0x40;
2022 }
2023 }
2024
2025 break;
2026 case ATORA_SIDE_CHIP_LIST:
2027 if (MenuAtoraSel.board.cursor > -1 && MenuAtoraSel.board.atla_elements[MenuAtoraSel.board.cursor] > -1) {
2028 cursor_x += 25.0f;
2029 cursor_y += 12.0f;
2030 MenuAtoraSel.cursor_icon_u = 0x60;
2031 }
2032
2033 break;
2034 }
2035 }
2036
2037 MenuAtoraSel.cursor_x += (cursor_x - MenuAtoraSel.cursor_x) / 4.0f;
2038 MenuAtoraSel.cursor_y += (cursor_y - MenuAtoraSel.cursor_y) / 4.0f;
2039
2040 if (MenuAtoraSel.step == ATORA_STEP_RUN) {
2041 MenuTextureReload(AtoraTextureReadBlock);
2042 int tip_no = NowTipHavePt->tip_no;
2043
2044 if (tip_no > -1) {
2045 CTexture *texture = RetCTexAtora(tip_no, u, v);
2046
2047 if (texture != NULL) {
2048 float sway_x = 7.0f * cosf(0.0805536583f * CursorVibeCnt);
2049 float sway_y = 5.0f * sinf(0.116355285f * CursorVibeCnt);
2050 int tip_x = (int) (2.0f + (MenuAtoraSel.cursor_x + sway_x));
2051 int tip_y = (int) (MenuAtoraSel.cursor_y + sway_y - 14.0f);
2052 CRect_i_ source(u, v, 0x24, 0x24);
2053 DrawMenu2DSprite(texture, CRect_i_(tip_x + 5, tip_y + 3, 0x24, 0x24), source, 10, 10, 10, 0x50);
2054 float hand_x = MenuAtoraSel.cursor_x + sway_x;
2055 int hand_ix = (int) hand_x;
2056 float hand_y = MenuAtoraSel.cursor_y + sway_y;
2057 int hand_iy = (int) hand_y;
2058 DrawMenu2DSprite(StayTex, CRect_i_((int) hand_x + 6, (int) hand_y + 3, 0x20, 0x20), CRect_i_(0x80, 0x28, 0x20, 0x20), 10, 10, 10, 0x50);
2059 DrawMenu2DSprite(texture, CRect_i_(tip_x, tip_y, 0x24, 0x24), source, 0x80);
2060 }
2061 }
2062
2063 int draw_waku = 1;
2064
2065 switch (MenuAtoraSel.mode) {
2066 case ATORA_SIDE_BOARD:
2067 if (info == NULL) {
2068 draw_waku = 0;
2069 }
2070
2071 if (open_mode == ATORA_OPEN_PLACE && 0 < MenuAtoraSel.board.cursor && event != 0) {
2072 draw_waku = 0;
2073 }
2074
2075 break;
2076 }
2077
2078 if (MenuAtoraSel.step == ATORA_STEP_EVENT_START || (MenuAtoraSel.mode == ATORA_SIDE_BOARD && MenuAtoraSel.board.cursor == 0 && MenuAtoraSel.map_no == 5)) {
2079 draw_waku = 0;
2080 }
2081
2082 if (draw_waku != 0) {
2083 DrawMenuWaku(waku_x + 0x15, waku_y - 0xE, waku_size, waku_size, 0, StayTex, 0x80);
2084 }
2085 }
2086}
2087
2095static int AtoraTextureEnter() {
2096 LOADTEXTURE_INFO2 tex[3] = {
2097 {"#frame_image3#640#" SCREEN_HEIGHT_STR "#4", 0, 0},
2098 {NULL, 0, 0},
2099 {NULL, 0, 0}
2100 };
2101 BG_READ_INFO *bg;
2102
2103 tex[1].block_no = tex[0].block_no = AtoraTextureReadBlock;
2104 bg = GetReadBGFile(0);
2105 char name[16] = "a%d.img";
2106 sprintf(name, name, MenuAtoraSel.map_no + 1);
2107 tex[1].name = (char *) GetPackFile((u_int *) bg->buffer, name, NULL);
2108 TexManager.DeleteTextureBlock(AtoraTextureReadBlock);
2109 TexManager.LoadTextureBlockEX(-1, tex);
2110 CompleteTex = TexManager.GetTexture("complete", -1);
2111 Sozai = TexManager.GetTexture("sozai", AtoraTextureReadBlock);
2112 HoleGray = TexManager.GetTexture("holegray", AtoraTextureReadBlock);
2113 HoleGold = TexManager.GetTexture("holegold", AtoraTextureReadBlock);
2114 ObTip = TexManager.GetTexture("obtip", AtoraTextureReadBlock);
2115 ObPerson = TexManager.GetTexture("obperson", AtoraTextureReadBlock);
2116 return 1;
2117}
2118
2122int tip_sort_type = 1;
2123
2125int tip_table[3] = {3, 1, 2};
2126
2134static int GetTipKind(int tip_no) {
2135 if (tip_no < 0 || tip_no >= 100) {
2136 return 0;
2137 }
2138
2139 if (0 <= tip_no && tip_no < 40) {
2140 return 1;
2141 }
2142
2143 if (tip_no >= 40) {
2144 return 2;
2145 }
2146
2147#ifdef PAL
2148 return 0;
2149#endif
2150}
2151
2160static int CompTip(int tip_a, int tip_b) {
2161 int rank_a;
2162 int rank_b;
2163
2164 rank_a = tip_table[GetTipKind(tip_a)];
2165 rank_b = tip_table[GetTipKind(tip_b)];
2166
2167 if (tip_a < 0) {
2168 rank_a = 3;
2169 }
2170
2171 if (tip_b < 0) {
2172 rank_b = 3;
2173 }
2174
2175 if (rank_a > rank_b) {
2176 return 1;
2177 }
2178
2179 if (rank_a < rank_b) {
2180 return -1;
2181 }
2182
2183 if (tip_a > tip_b) {
2184 return 1;
2185 }
2186
2187 return (tip_a < tip_b) ? -1 : 0;
2188}
2189
2198static int SeitonAtoraTipBoardSub() {
2199 int rank;
2200 int kind;
2201 s16 *list;
2202 int i;
2203 int j;
2204 int moved;
2205
2206 kind = tip_sort_type;
2207
2208 for (rank = 0; rank < 3; rank++) {
2209 tip_table[kind] = rank;
2210 kind++;
2211
2212 if (kind >= 3) {
2213 kind = 0;
2214 }
2215 }
2216
2217 tip_table[0] = 3;
2218 moved = 0;
2219 list = MenuAtoraSel.board.atla_elements;
2220
2221 for (i = 0; i < 119; i++) {
2222 for (j = i + 1; j < 120; j++) {
2223 if (CompTip(list[i], list[j]) > 0) {
2224 MenuDataSwap(&list[i], &list[j]);
2225 moved = 1;
2226 }
2227 }
2228 }
2229
2230 return moved;
2231}
2232
2241static void SeitonAtoraTipBoard() {
2242 int i;
2243
2244 for (i = 0; i < 3; i++) {
2245 if (SeitonAtoraTipBoardSub()) {
2246 break;
2247 }
2248
2249 tip_sort_type++;
2250
2251 if (tip_sort_type >= 3) {
2252 tip_sort_type = 1;
2253 }
2254 }
2255}
2256
2257int MenuAtoraSelectKey() {
2258 int result;
2259 int max_village;
2260 int prev_village;
2261 int msg_no;
2262 int msg_base;
2263 int max_pos;
2264 int event_no;
2265 int tip_no;
2266 int held;
2267 EDITPARTS_INFO *info;
2268
2269 result = ATORA_SELECT_NONE;
2270
2271 if (ReadBGSync() == 0 && AtoraTextureEnterFlag == 0) {
2272 AtoraTextureEnterFlag = AtoraTextureEnter();
2273 }
2274
2275 switch (MenuAtoraSel.step) {
2276 case ATORA_STEP_FADE_IN:
2277 if (MenuAtoraSel.step_count > 15 && AtoraTextureEnterFlag) {
2278 MenuAtoraSel.step = ATORA_STEP_RUN;
2279 MenuAtoraAfterFadeIn();
2280 }
2281
2282 break;
2283 case ATORA_STEP_FADE_OUT:
2284 if (MenuAtoraSel.step_count > 18) {
2285 ExitAtoraSelect();
2286 MenuAtoraSel.step = ATORA_STEP_RUN;
2287 }
2288
2289 break;
2290 case ATORA_STEP_EVENT_START:
2291 if (MenuAtoraSel.map_no != 5) {
2292 switch (MenuAtoraSel.open_mode) {
2293 case ATORA_OPEN_PLACE:
2294 CommonMenuAtoraInfo->GetPartsInfo(MenuAtoraSel.board_pos);
2295 MenuAtoraSel.step = ATORA_STEP_RUN;
2296 EditMenuStatus.mode = EDIT_MENU_MODE_EVENT;
2297 MenuAtoraSel.last_board_pos = EditMenuStatus.event_no = MenuAtoraSel.board_pos;
2298 ExitAtoraSelect();
2299 GamePad.AutoRepeatOff();
2300 GamePad.MenuModeOff();
2301 return ATORA_SELECT_PLACE_EXIT;
2302 }
2303 } else {
2304 SetMenuAtraEventFlag(1);
2305 MenuAtoraSel.step = ATORA_STEP_EVENT_FADE_OUT;
2306 GetPrevEastKingSndVol();
2307 SndBgmFadeOut(45, 0);
2308 }
2309
2310 break;
2311 case ATORA_STEP_EVENT_FADE_OUT:
2312 if (MenuAtoraSel.step_count < 50) {
2313 SndStep();
2314 }
2315
2316 if (MenuAtoraSel.step_count == 50) {
2317 SndBgmStop();
2318 }
2319
2320 if (MenuAtoraSel.step_count > 70) {
2321 CommonMenuAtoraInfo->Save(MenuAtoraSel.map_no, SaveData);
2322 MenuAtoraSel.step = ATORA_STEP_EVENT_PLAY;
2323 int block[1] = {0};
2324 block[0] = AtoraTextureReadBlock;
2325 event_no = SearchAtoraInfo(MenuAtoraSel.board_pos)->parts_no;
2326 MenuAtoraSel.event_board_pos = MenuAtoraSel.board_pos;
2327 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2328 InitEastKingEvent(event_no, block, AtoraOffsetBuf);
2329 }
2330
2331 break;
2332 case ATORA_STEP_EVENT_PLAY:
2333 if (EastKingEventKey() == 1) {
2334 MenuAtoraSel.step = ATORA_STEP_EVENT_FADE_IN;
2335 AtoraTextureEnterFlag = 0;
2336 InitMenuAtoraSelect(MenuAtoraSel.map_no);
2337 SetMenuAtraEventFlag(0);
2338 MenuAtoraSel.step_count = 0;
2339 }
2340
2341 break;
2342 case ATORA_STEP_EVENT_FADE_IN:
2343 SndStep();
2344
2345 if (MenuAtoraSel.step_count > 64) {
2346 MenuAtoraSel.step = ATORA_STEP_RUN;
2347 }
2348
2349 break;
2350 case ATORA_STEP_COMPLETE_FLASH:
2351 if (MenuAtoraSel.step_count > 40) {
2352 MenuAtoraSel.step = ATORA_STEP_RUN;
2353 }
2354
2355 break;
2356 case ATORA_STEP_WARNING:
2357 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS)) {
2358 MenuAtoraSel.step = ATORA_STEP_RUN;
2359 }
2360
2361 break;
2362 case ATORA_STEP_CHANGE_MAP:
2363 if (MenuAtoraSel.step_count > 24 && AtoraTextureEnterFlag) {
2364 MenuAtoraSel.step = ATORA_STEP_RUN;
2365 }
2366 case ATORA_STEP_RUN:
2367 switch (MenuAtoraSel.mode) {
2368 case ATORA_SIDE_BOARD:
2369 result = AtoraBoardKey();
2370 break;
2371 case ATORA_SIDE_CHIP_LIST:
2372 result = AtoraTipKey();
2373 break;
2374 }
2375
2376 max_village = GetAtoraMaxVillage();
2377 prev_village = MenuAtoraSel.board.page;
2378
2379 if (GamePad.Down(PAD_R2 | PAD_R1)) {
2380 if (NowTipHavePt->tip_no < 0) {
2381 MenuAtoraSel.board.page++;
2382
2383 if (MenuAtoraSel.board.page > max_village) {
2384 MenuAtoraSel.board.page = BOARD_PAGE_ATLA_VILLAGE;
2385 }
2386 } else {
2387 ComMenuSePlay(MENU_SOUND_REFUSE);
2388 }
2389 }
2390
2391 if (GamePad.Down(PAD_L2 | PAD_L1)) {
2392 if (NowTipHavePt->tip_no < 0) {
2393 MenuAtoraSel.board.page--;
2394
2395 if (MenuAtoraSel.board.page < BOARD_PAGE_ATLA_VILLAGE) {
2396 MenuAtoraSel.board.page = max_village;
2397 }
2398 } else {
2399 ComMenuSePlay(MENU_SOUND_REFUSE);
2400 }
2401 }
2402
2403 if (prev_village != MenuAtoraSel.board.page) {
2404 result = ATORA_SELECT_CHANGE_PAGE;
2405 }
2406
2407 switch (result) {
2408 case ATORA_SELECT_PLACE:
2409 info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2410 EditMenuStatus.mode = EDIT_MENU_MODE_PLACE;
2411 EditMenuStatus.parts = info->parts_no;
2412 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2413 ExitAtoraSelect();
2414 ComMenuSePlay(MENU_SOUND_CONFIRM);
2415 break;
2416 case ATORA_SELECT_CHANGE_PAGE:
2417 if (NowTipHavePt->tip_no >= 0) {
2418 ComMenuSePlay(MENU_SOUND_REFUSE);
2419 break;
2420 }
2421
2422 CommonMenuAtoraInfo->Save(MenuAtoraSel.map_no, SaveData);
2423 MenuAtoraSel.map_no = MenuAtoraSel.board.page - BOARD_PAGE_ATLA_VILLAGE;
2424 AtoraTextureEnterFlag = 0;
2425 max_pos = AtraBoardMaxNum(MenuAtoraSel.map_no);
2426
2427 if (max_pos <= MenuAtoraSel.board_pos) {
2428 MenuAtoraSel.board_pos = max_pos;
2429 }
2430
2431 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2432 InitMenuAtoraSelect(MenuAtoraSel.map_no);
2433 MenuAtoraSel.step = ATORA_STEP_CHANGE_MAP;
2434 MenuAtoraSel.step_count = 0;
2435 MenuAtoraSel.name_alpha = 0;
2436 ComMenuSePlay(MENU_SOUND_CONFIRM);
2437 break;
2438 case ATORA_SELECT_CLOSE:
2439 MenuAtoraSel.step = ATORA_STEP_FADE_OUT;
2440 MenuAtoraSel.step_count = 0;
2441 CommonMenuAtoraInfo->Save(MenuAtoraSel.map_no, SaveData);
2442 ExitAtoraSelect();
2443 break;
2444 }
2445
2446 break;
2447 }
2448
2449 msg_no = 0;
2450
2451 switch (MenuAtoraSel.mode) {
2452 case ATORA_SIDE_BOARD:
2453 tip_no = AtoraMsgNoGet(MenuAtoraSel.map_no, MenuAtoraSel.board_pos, MenuAtoraSel.board.cursor);
2454 msg_no = tip_no + 1000;
2455
2456 if (tip_no < 0) {
2457 msg_no = 0;
2458 }
2459
2460 if (tip_no == -788) {
2461 msg_no = 212;
2462 }
2463
2464 break;
2465 case ATORA_SIDE_CHIP_LIST:
2466 held = MenuAtoraSel.board.atla_elements[MenuAtoraSel.board.cursor];
2467 msg_base = MenuAtoraSel.map_no * 200 + 1000;
2468
2469 if (held > -1) {
2470 msg_no = msg_base + AtoraTipOnlyMsgNoGet(MenuAtoraSel.map_no, held);
2471 } else if (NowTipHavePt->tip_no > -1) {
2472 msg_no = msg_base + AtoraTipOnlyMsgNoGet(MenuAtoraSel.map_no, NowTipHavePt->tip_no);
2473 }
2474
2475 if (msg_no < 0) {
2476 msg_no = 0;
2477 }
2478
2479 break;
2480 }
2481
2482 if (AtoraTextureEnterFlag == 0 || MenuAtoraSel.step == ATORA_STEP_FADE_IN) {
2483 msg_no = 0;
2484 }
2485
2486 if (CommonMenuMes2.mes_made != msg_no) {
2487 CommonMenuMes2.MakeMesWin(msg_no);
2488 }
2489
2490 return result;
2491}
2492
2493static int AtoraBoardKey() {
2494 int movable[8];
2495 int open_mode = MenuAtoraSel.open_mode;
2496 int max = AtraBoardMaxNum(MenuAtoraSel.map_no);
2497 int old_cursor = MenuAtoraSel.board.cursor;
2498 int old_pos = MenuAtoraSel.board_pos;
2499 int moved = 0;
2500 int result = ATORA_SELECT_NONE;
2501 int se = -1;
2502 int to;
2503
2504 if (GamePad.Down(PAD_UP) != 0) {
2505 moved = 1;
2506
2507 if (MenuAtoraSel.board.cursor == 0) {
2508 if (0 < MenuAtoraSel.board_pos) {
2509 MenuAtoraSel.board_pos--;
2510 }
2511
2512 MenuAtoraSel.board.cursor = 0;
2513 } else if (MenuAtoraSel.board.cursor >= 4 && MenuAtoraSel.board.cursor < 7) {
2514 MenuAtoraSel.board.cursor -= 3;
2515 } else if (0 < MenuAtoraSel.board_pos) {
2516 MenuAtoraSel.board_pos--;
2517 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2518 MenuAtoraSel.board.cursor += 3;
2519 to = MenuAtoraSel.board.cursor - 1;
2520 to = AtoraBoardGoToPos(movable, to, 3);
2521
2522 if (movable[to] != 0) {
2523 MenuAtoraSel.board.cursor = to + 1;
2524 } else {
2525 MenuAtoraSel.board.cursor -= 3;
2526 to = MenuAtoraSel.board.cursor - 1;
2527 to = AtoraBoardGoToPos(movable, to, 0);
2528
2529 if (movable[to] != 0) {
2530 MenuAtoraSel.board.cursor = to + 1;
2531 } else {
2532 MenuAtoraSel.board.cursor = 0;
2533 }
2534 }
2535 }
2536 } else if (GamePad.Down(PAD_DOWN) != 0) {
2537 moved = 1;
2538
2539 if (MenuAtoraSel.board.cursor == 0) {
2540 if (MenuAtoraSel.board_pos < max - 1) {
2541 MenuAtoraSel.board_pos++;
2542 }
2543 } else if (MenuAtoraSel.board.cursor >= 4 && MenuAtoraSel.board.cursor < 7) {
2544 if (MenuAtoraSel.board_pos < max - 1) {
2545 MenuAtoraSel.board_pos++;
2546 MenuAtoraSel.board.cursor -= 3;
2547 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2548 to = MenuAtoraSel.board.cursor - 1;
2549 to = AtoraBoardGoToPos(movable, to, 0);
2550
2551 if (movable[to] != 0) {
2552 MenuAtoraSel.board.cursor = to + 1;
2553 } else {
2554 MenuAtoraSel.board.cursor = 0;
2555 }
2556 }
2557 } else {
2558 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2559 MenuAtoraSel.board.cursor += 3;
2560 to = MenuAtoraSel.board.cursor - 1;
2561 to = AtoraBoardGoToPos(movable, to, 3);
2562
2563 if (movable[to] != 0) {
2564 MenuAtoraSel.board.cursor = to + 1;
2565 } else if (MenuAtoraSel.board_pos < max - 1) {
2566 MenuAtoraSel.board_pos++;
2567 MenuAtoraSel.board.cursor -= 3;
2568 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2569 to = MenuAtoraSel.board.cursor - 1;
2570 to = AtoraBoardGoToPos(movable, to, 0);
2571
2572 if (movable[to] != 0) {
2573 MenuAtoraSel.board.cursor = to + 1;
2574 } else {
2575 MenuAtoraSel.board.cursor = 0;
2576 }
2577 }
2578 }
2579 } else if (GamePad.Down(PAD_LEFT) != 0) {
2580 moved = 1;
2581 MenuAtoraSel.board.cursor--;
2582
2583 if (MenuAtoraSel.board.cursor <= 0 || MenuAtoraSel.board.cursor == 3) {
2584 MenuAtoraSel.board.cursor = 0;
2585 }
2586 } else if (GamePad.Down(PAD_RIGHT) != 0) {
2587 moved = 1;
2588 EDITPARTS_INFO *info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2589 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2590 int event = 0;
2591
2592 if (info != NULL) {
2593 event = AtoraCompOrEvent(info);
2594 }
2595
2596 int to_list = 0;
2597
2598 if (info == NULL || event != 0) {
2599 to_list = 1;
2600 } else if (movable[MenuAtoraSel.board.cursor] != 0) {
2601 MenuAtoraSel.board.cursor++;
2602
2603 if (MenuAtoraSel.board.cursor == 4 || MenuAtoraSel.board.cursor == 7) {
2604 to_list = 1;
2605 }
2606 } else {
2607 to_list = 1;
2608 }
2609
2610 if (to_list != 0) {
2611 MenuAtoraSel.mode = ATORA_SIDE_CHIP_LIST;
2612 MenuAtoraSel.board.cursor = MenuAtoraSel.board.top_row * 5 + 5;
2613 }
2614
2615 if (MenuAtoraSel.mode == ATORA_SIDE_CHIP_LIST) {
2616 MenuAtoraSel.board.cursor_area = PERSONAL_BOARD_AREA_CELLS;
2617 }
2618 }
2619
2620 if (MenuAtoraSel.mode == ATORA_SIDE_BOARD) {
2621 EDITPARTS_INFO *info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2622 int event = 0;
2623
2624 if (info != NULL) {
2625 event = AtoraCompOrEvent(info);
2626 }
2627
2628 if (event != 0) {
2629 MenuAtoraSel.board.cursor = 0;
2630 }
2631 }
2632
2633 if (moved == 0) {
2634 if (GamePad.Down(PAD_CROSS) != 0) {
2635 EDITPARTS_INFO *info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2636
2637 if (info != NULL) {
2638 int full = 0;
2639
2640 if (info->placed == info->stock) {
2641 full = 1;
2642 }
2643
2644 AtoraCompOrEvent(info);
2645 int all_tips = AtoraAllTipGet(info->parts_no);
2646
2647 if (MenuAtoraSel.open_mode == ATORA_OPEN_WARN) {
2648 MenuAtoraSel.step = ATORA_STEP_WARNING;
2649 se = 2;
2650 } else if (MenuAtoraSel.board.cursor == 0) {
2651 int held = NowTipHavePt->tip_no;
2652
2653 if (0 <= held) {
2654 se = 2;
2655 } else if (full == 0 && held < 0 && open_mode == ATORA_OPEN_PLACE && NowEditMap == MenuAtoraSel.map_no) {
2656 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2657 ComMenuSePlay(MENU_SOUND_CONFIRM);
2658 return ATORA_SELECT_PLACE;
2659 } else if (all_tips != 0 && MenuAtoraSel.map_no == 5) {
2660 MenuAtoraSel.step = ATORA_STEP_EVENT_START;
2661 MenuAtoraSel.step_count = 0;
2662 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2663 } else {
2664 se = 2;
2665 }
2666 } else if (all_tips != 0) {
2667 ComMenuSePlay(MENU_SOUND_REFUSE);
2668 return ATORA_SELECT_NONE;
2669 } else {
2670 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, movable);
2671 int slot = MenuAtoraSel.board.cursor - 1;
2672
2673 if (NowTipHavePt->tip_no < 0) {
2674 if (info->elements[slot].enabled == 0) {
2675 se = 2;
2676 } else {
2677 int free = 1;
2678
2679 for (int i = slot; i < 6; i++) {
2680 if (slot == info->elements[i].required_element && info->elements[i].enabled != 0) {
2681 free = 0;
2682 }
2683 }
2684
2685 if (free != 0) {
2686 NowTipHavePt->tip_no = info->elements[slot].id;
2687 info->elements[slot].enabled = false;
2688 NowTipHavePt->slot = slot;
2689 NowTipHavePt->mode = ATORA_SIDE_BOARD;
2690 NowTipHavePt->parts_no = MenuAtoraSel.board_pos;
2691 se = 6;
2692 } else {
2693 se = 2;
2694 }
2695 }
2696 } else {
2697 EDITPARTS_ELEMENT *element = &info->elements[slot];
2698 EDIT_CHIP_ATTACH_DATA *chip = &GetEditAtraPartsData(MenuAtoraSel.map_no, info->parts_no)->elements[slot];
2699 int fits = 1;
2700
2701 if (NowTipHavePt->tip_no != element->id) {
2702 fits = 0;
2703 }
2704
2705 if (element->enabled != 0) {
2706 fits = 0;
2707 }
2708
2709 int linked = element->required_element;
2710
2711 if (linked >= 0 && info->elements[linked].enabled == 0) {
2712 fits = 0;
2713 }
2714
2715 if (AtraTipCanDisplay(chip) == 0) {
2716 fits = 0;
2717 }
2718
2719 if (fits != 0) {
2720 element->enabled = true;
2721
2722 if (info == NULL) {
2723 return ATORA_SELECT_NONE;
2724 }
2725
2726 if (AtoraAllTipGet(info->parts_no) != 0) {
2727 ComMenuSePlay(SE_SPARKLE);
2728 MenuAtoraSel.step = ATORA_STEP_COMPLETE_FLASH;
2729 MenuAtoraSel.board.cursor = 0;
2730 MenuAtoraSel.step_count = 0;
2731 } else {
2732 se = 5;
2733 }
2734
2735 AtoraTipInfoInit();
2736 } else {
2737 se = 2;
2738 }
2739 }
2740 }
2741 }
2742 } else if (GamePad.Down(PAD_CIRCLE) != 0) {
2743 se = 2;
2744
2745 if (NowTipHavePt->tip_no < 0) {
2746 MenuAtoraSel.last_board_pos = MenuAtoraSel.board_pos;
2747 result = ATORA_SELECT_CLOSE;
2748 } else {
2749 AtoraMenuTipCancel();
2750 }
2751 }
2752 }
2753
2754#ifdef PAL
2755 // Debug shortcuts that fill, empty, dump or complete the parts of the board.
2756 if (DebugMode) {
2757 EDITPARTS_INFO *parts = CommonMenuAtoraInfo->GetPartsInfo(MenuAtoraSel.board_pos);
2758
2759 if (GamePad.Down2(PAD_CROSS)) {
2760 if (parts != NULL) {
2761 for (int i = 0; i < 6; i++) {
2762 if (parts->elements[i].id >= 0) {
2763 parts->elements[i].enabled = true;
2764 }
2765 }
2766
2767 parts->completion_flags = 1;
2768 }
2769
2770 MenuAtoraSel.board.cursor = 0;
2771 }
2772
2773 if (GamePad.Down2(PAD_CIRCLE)) {
2774 if (parts != NULL) {
2775 for (int i = 0; i < 6; i++) {
2776 if (parts->elements[i].id >= 0) {
2777 parts->elements[i].enabled = false;
2778
2779 for (int j = 0; j < 100; j++) {
2780 if (MenuAtoraSel.board.atla_elements[j] < 0) {
2781 MenuAtoraSel.board.atla_elements[j] = parts->elements[i].id;
2782 break;
2783 }
2784 }
2785 }
2786 }
2787 }
2788
2789 parts->completion_flags = 0;
2790 }
2791
2792 if (GamePad.Down2(PAD_R1) && parts != NULL) {
2793 printf("info----------,,,\tID \t\t%d\n", parts->parts_no);
2794 printf("\t\tcomplete_event\t\t%d\n", parts->kind);
2795
2796 for (int i = 0; i < 6; i++) {
2797 if (parts->elements[i].id < 0) {
2798 break;
2799 }
2800
2801 if (parts->elements[i].enabled != 0) {
2802 for (int j = 0; j < 120; j++) {
2803 if (MenuAtoraSel.board.atla_elements[j] < 0) {
2804 MenuAtoraSel.board.atla_elements[j] = parts->elements[i].id;
2805 parts->elements[i].enabled = false;
2806 break;
2807 }
2808 }
2809 }
2810 }
2811
2812 parts->completion_flags = 0;
2813 }
2814
2815 if (GamePad.Down2(PAD_L1)) {
2816 if (parts != NULL) {
2817 for (int i = 0; i < 6; i++) {
2818 if (parts->elements[i].id >= 0) {
2819 parts->elements[i].enabled = true;
2820 int npc_no = parts->elements[i].npc_no;
2821
2822 if (npc_no >= 0) {
2823 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(MapNo, npc_no);
2824
2825 if (npc != NULL) {
2826 npc->talk_message++;
2827 }
2828 }
2829 }
2830 }
2831
2832 parts->completion_flags = 0;
2833 }
2834
2835 MenuAtoraSel.board.cursor = 0;
2836 }
2837
2838 if (GamePad.Down2(PAD_TRIANGLE)) {
2839 EDITPARTS_INFO *info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2840
2841 if (info != NULL) {
2842 for (int i = 0; i < 6; i++) {
2843 EDITPARTS_ELEMENT *element = &info->elements[i];
2844
2845 if (info->elements[i].id >= 0) {
2846 if (info->elements[i].id >= 0) {
2847 element->enabled = true;
2848 }
2849
2850 int npc_no = element->npc_no;
2851
2852 if (npc_no >= 0) {
2853 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(MapNo, npc_no);
2854
2855 if (npc != NULL) {
2856 npc->talk_message++;
2857 }
2858 }
2859 }
2860 }
2861
2862 if (AtoraCompOrEvent(info) != 0 && open_mode == ATORA_OPEN_PLACE && NowEditMap == MenuAtoraSel.map_no) {
2863 MenuAtoraSel.step = ATORA_STEP_EVENT_START;
2864 }
2865
2866 ComMenuSePlay(MENU_SOUND_CONFIRM);
2867 }
2868 }
2869
2870 if (GamePad.Down2(PAD_CROSS) && GamePad.Down2(PAD_CIRCLE)) {
2871 for (int k = 0; k < max; k++) {
2872 EDITPARTS_INFO *info = CommonMenuAtoraInfo->GetPartsInfo(k);
2873
2874 if (info != NULL) {
2875 info->obtained = 1;
2876
2877 for (int i = 0; i < 6; i++) {
2878 EDITPARTS_ELEMENT *element = &info->elements[i];
2879
2880 if (info->elements[i].id >= 0) {
2881 if (info->elements[i].id >= 0) {
2882 element->enabled = true;
2883 }
2884
2885 int npc_no = element->npc_no;
2886
2887 if (npc_no >= 0) {
2888 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(MapNo, npc_no);
2889
2890 if (npc != NULL) {
2891 npc->talk_message++;
2892 }
2893 }
2894 }
2895 }
2896 }
2897 }
2898
2899 ComMenuSePlay(MENU_SOUND_CONFIRM);
2900 }
2901
2902 if (GamePad.Down2(PAD_CROSS) && GamePad.Down2(PAD_DOWN)) {
2903 for (int k = 0; k < max; k++) {
2904 EDITPARTS_INFO *info = CommonMenuAtoraInfo->GetPartsInfo(k);
2905
2906 if (info != NULL) {
2907 for (int i = 0; i < 6; i++) {
2908 EDITPARTS_ELEMENT *element = &info->elements[i];
2909
2910 if (info->elements[i].id >= 0) {
2911 int npc_no = element->npc_no;
2912
2913 if (npc_no >= 0) {
2914 SV_GRD_NPC *npc = SaveData->GetGrdNPCData(MapNo, npc_no);
2915
2916 if (npc != NULL) {
2917 npc->flags |= 2;
2918 }
2919 }
2920 }
2921 }
2922 }
2923 }
2924 }
2925 }
2926
2927#endif
2928 if (old_cursor != MenuAtoraSel.board.cursor || old_pos != MenuAtoraSel.board_pos) {
2929 se = 0;
2930 }
2931
2932 ComMenuSePlay(se);
2933 return result;
2934}
2935
2936static int AtoraTipKey() {
2937 int result = ATORA_SELECT_NONE;
2938 int pos = MenuAtoraSel.board.cursor;
2939 int mode = MenuAtoraSel.mode;
2940 int page = MenuAtoraSel.board.page;
2941
2942 switch (PersonalBoardKey()) {
2943 case 1: {
2944 EDITPARTS_INFO *info = SearchAtoraInfo(MenuAtoraSel.board_pos);
2945 int event = 0;
2946
2947 if (info != NULL) {
2948 event = AtoraCompOrEvent(info);
2949 }
2950
2951 int enable[6];
2952 AtoraBoardEnableMovePos(MenuAtoraSel.board_pos, enable);
2953 MenuAtoraSel.mode = ATORA_SIDE_BOARD;
2954
2955 if (info == NULL || event != 0) {
2956 MenuAtoraSel.board.cursor = 0;
2957 } else {
2958 int slot = AtoraBoardGoToPos(enable, MenuAtoraSel.board.cursor < MenuAtoraSel.board.top_row * 5 + 10 ? 2 : 5, 0);
2959
2960 if (enable[slot]) {
2961 MenuAtoraSel.board.cursor = slot + 1;
2962 } else {
2963 MenuAtoraSel.board.cursor = 0;
2964 }
2965 }
2966
2967 ComMenuSePlay(MENU_SOUND_CURSOR);
2968 break;
2969 }
2970 }
2971
2972 if (MenuAtoraSel.mode == ATORA_SIDE_CHIP_LIST) {
2973 if (pos != MenuAtoraSel.board.cursor || mode != MenuAtoraSel.mode || page != MenuAtoraSel.board.page) {
2974 ComMenuSePlay(MENU_SOUND_CURSOR);
2975 }
2976
2977 if (GamePad.Down(PAD_CROSS)) {
2978 s16 *tip = &MenuAtoraSel.board.atla_elements[MenuAtoraSel.board.cursor];
2979
2980 if (NowTipHavePt->tip_no == *tip) {
2981 ComMenuSePlay(MENU_SOUND_REFUSE);
2982 } else {
2983 ComMenuSePlay(MENU_SOUND_CONFIRM);
2984 s16 tip_no = *tip;
2985 *tip = NowTipHavePt->tip_no;
2986 NowTipHavePt->tip_no = tip_no;
2987 NowTipHavePt->slot = MenuAtoraSel.board.cursor;
2988 NowTipHavePt->mode = ATORA_SIDE_CHIP_LIST;
2989 NowTipHavePt->parts_no = -1;
2990 }
2991
2992 return ATORA_SELECT_NONE;
2993 } else if (GamePad.Down(PAD_CIRCLE)) {
2994 ComMenuSePlay(MENU_SOUND_REFUSE);
2995
2996 if (NowTipHavePt->tip_no < 0) {
2997 result = ATORA_SELECT_CLOSE;
2998 } else {
2999 AtoraMenuTipCancel();
3000 }
3001 } else if (GamePad.Down(PAD_SQUARE)) {
3002 ComMenuSePlay(MENU_SOUND_CONFIRM);
3003 SeitonAtoraTipBoard();
3004 }
3005 }
3006
3007 return result;
3008}
3009
3010static void AtoraMenuTipCancel() {
3011 EDITPARTS_INFO *info;
3012 EDITPARTS_ELEMENT *element;
3013 s16 tip_no;
3014
3015 switch (NowTipHavePt->mode) {
3016 case ATORA_SIDE_CHIP_LIST:
3017 tip_no = MenuAtoraSel.board.atla_elements[NowTipHavePt->slot];
3018 MenuAtoraSel.board.atla_elements[NowTipHavePt->slot] = NowTipHavePt->tip_no;
3019 NowTipHavePt->tip_no = tip_no;
3020 break;
3021 case ATORA_SIDE_BOARD:
3022 info = SearchAtoraInfo(NowTipHavePt->parts_no);
3023 element = &info->elements[NowTipHavePt->slot];
3024
3025 if (element->id == NowTipHavePt->tip_no && element->enabled == 0) {
3026 element->enabled = true;
3027 }
3028
3029 MenuAtoraSel.board_pos = NowTipHavePt->parts_no;
3030 NowTipHavePt->tip_no = -1;
3031 break;
3032 }
3033}
3034
3035static void AtoraBoardFadeEffect() {
3036 CTexture frame = *TexManager.GetTexture("frame_image", -1);
3037
3038 if (&frame == NULL) {
3039 return;
3040 }
3041
3042 ((sceGsTex0 *) &frame.tex0)->bits.tcc = 0;
3043 sceGsTexa texa = mgTexa;
3044 texa.AEM = 1;
3045 texa.TA0 = 0x80;
3046 MGSetGsTEXA(&texa);
3047 spRGBA top;
3048 spRGBA bottom;
3049 bottom.r = bottom.g = bottom.b = 0x40;
3050 top.r = top.g = top.b = 0x40;
3051 bottom.a = 0x80;
3052 top.a = 0x80;
3053 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 0, 320, 1), CRect_i_(0, 0, 320, 1), &top, &top, &bottom, &bottom, 1);
3054 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 1, 320, 60), CRect_i_(0, 0, 320, 61), &top, &top, &bottom, &bottom, 1);
3055 top.a = 0x80;
3056 bottom.a = 0;
3057 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 61, 320, 59), CRect_i_(0, 60, 320, 60), &top, &top, &bottom, &bottom, 1);
3058 top.a = 0;
3059 bottom.a = 0x80;
3060 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 277, 320, 89), CRect_i_(0, 276, 320, 90), &top, &top, &bottom, &bottom, 1);
3061 bottom.a = 0x80;
3062 top.a = 0x80;
3063 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 366, 320, 1), CRect_i_(0, 366, 320, 1), &top, &top, &bottom, &bottom, 1);
3064#ifdef PAL
3065 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 367, 320, 113), CRect_i_(0, 366, 320, 114), &top, &top, &bottom, &bottom, 1);
3066#else
3067 set2DSprite(Vif1Packet, &frame, CRect_i_(0, 367, 320, 81), CRect_i_(0, 366, 320, 82), &top, &top, &bottom, &bottom, 1);
3068#endif
3069 MGSetGsTEXA(NULL);
3070}
3071
3072void AtoraNameDraw(int unused) {
3073 int prev_mes_no[3];
3074 int pos;
3075 int y;
3076 int i;
3077 int mes_no;
3078 int x;
3079 int alpha;
3080 EDITPARTS_INFO *info;
3081
3082 MenuTextureReload(AtoraNameMes.tex_block);
3083 pos = MenuAtoraSel.board_pos - 1;
3084
3085 for (int j = 0; j < 3; j++) {
3086 prev_mes_no[j] = AtoraNameMes.mes_no[j];
3087 }
3088
3089 y = MenuAtoraSel.scroll_y + 92 + 130.0f * pos;
3090
3091 for (i = 0; i < 3; i++) {
3092 if (y < 96 || y > 341) {
3093 mes_no = 999;
3094 } else {
3095 info = SearchAtoraInfo(pos);
3096
3097 if (info != NULL) {
3098 mes_no = GetAtraMsgNo(MenuAtoraSel.map_no, info->parts_no);
3099 } else {
3100 mes_no = 999;
3101 }
3102 }
3103
3104 AtoraNameMes.mes_no[i] = mes_no;
3105 x = GetMsgLengthMenu(&AtoraNameMes, mes_no);
3106
3107 if (GetMenuLangFlag() == LANG_JAPANESE && mes_no == 1000) {
3108 x = GetMsgLengthCharaName(0) + 3;
3109 }
3110
3111 x = 186.0f - 58.0f * (x / 10.0f);
3112
3113 if (GetMenuLangFlag() > LANG_JAPANESE) {
3114 if (mes_no == 2001) {
3115 x += 6;
3116 }
3117
3118 if (mes_no == 2002) {
3119 x += 8;
3120 }
3121 }
3122
3123 if (i >= 0 && i < 10) {
3124 AtoraNameMes.line_pos[i].x = x;
3125 AtoraNameMes.line_pos[i].y = y;
3126 }
3127
3128 y += 130.0f;
3129 pos++;
3130 }
3131
3132 for (int k = 0; k < 3; k++) {
3133 if (AtoraNameMes.mes_no[k] != prev_mes_no[k]) {
3134 AtoraNameMes.mes_made = -1;
3135 AtoraNameMes.MakeMesWin(210);
3136 break;
3137 }
3138 }
3139
3140 alpha = MenuAtoraSel.name_alpha;
3141
3142 switch (MenuAtoraSel.step) {
3143 case ATORA_STEP_EVENT_FADE_OUT:
3144 alpha = 0x80 - MenuAtoraSel.step_count * 2;
3145
3146 if (alpha < 0) {
3147 alpha = 0;
3148 }
3149
3150 break;
3151 case ATORA_STEP_EVENT_FADE_IN:
3152 alpha = MenuAtoraSel.step_count * 2;
3153
3154 if (alpha > 0x80) {
3155 alpha = 0x80;
3156 }
3157
3158 break;
3159 case ATORA_STEP_EVENT_PLAY:
3160 alpha = 0;
3161 break;
3162 }
3163
3164 AtoraNameMes.edge_alpha = alpha;
3165 AtoraNameMes.Step();
3166 AtoraNameMes.DrawMesWin();
3167
3168 if (GetMenuAtraEventFlag() == 0) {
3169 AtoraBoardFadeEffect();
3170 }
3171}
3172
3181#ifdef PAL
3182static void OptionMenuDraw(int x, int y, int arrow_x, int arrow_y, int alpha) {
3183 int label[13] = {10, 8, 4, 5, 2, 3, 14, 9, 11, 12, 13, 6, 7};
3184 int kind[13] = {0, 0, 1, 2, 0, 1, 4, 3, 0, 0, 0, 0, 0};
3185 int u;
3186 int v;
3187 int i;
3188 int row_x;
3189 int row_y;
3190 int cell_x;
3191 int setting;
3192
3193 row_x = x;
3194 row_y = y;
3195
3196 for (i = 0; i < 13; i++) {
3197 CRect_i_ dst(0, 0, 210, 24);
3198 CRect_i_ src(0, 0, 210, 24);
3199
3200 if (label[i] < 7) {
3201 src.x = 0;
3202 src.y = label[i] * 24;
3203 } else {
3204 src.x = src.width;
3205 src.y = (label[i] - 7) * 24;
3206 }
3207
3208 dst.x = row_x;
3209 dst.y = row_y + 1;
3210 DrawMenu2DSprite(MenuOption, dst, src, alpha);
3211 int row_kind = kind[i];
3212 // Source position of the first cell of the row, by row kind.
3213 int cell_uv[5][2] = {
3214 {OptionMenu.flag[i] << 6, row_kind * 48 + 176},
3215 {OptionMenu.flag[i] << 6, row_kind * 48 + 176},
3216 {OptionMenu.flag[i] << 6, row_kind * 48 + 176},
3217 {128, 176 },
3218 {192, 200 }
3219 };
3220 u = cell_uv[row_kind][0];
3221 v = cell_uv[row_kind][1];
3222
3223 switch (row_kind) {
3224 case 0:
3225 case 1:
3226 case 2:
3227 DrawMenu2DSprite(MenuOption, CRect_i_(row_x + 238, row_y + 1, 64, 23), CRect_i_(u, v + 1, 64, 24), alpha);
3228
3229 if (u < 64) {
3230 u = 64;
3231 } else {
3232 u = 0;
3233 }
3234
3235 v = (row_kind * 2 + 1) * 24 + 176;
3236 DrawMenu2DSprite(MenuOption, CRect_i_(row_x + 310, row_y + 1, 64, 23), CRect_i_(u, v + 1, 64, 24), alpha);
3237 break;
3238 case 3:
3239 cell_x = row_x + 238;
3240 setting = OptionMenu.flag[i];
3241
3242 for (int j = 0; j < 3; j++) {
3243 u = 160;
3244
3245 if (j == setting) {
3246 u -= 32;
3247 }
3248
3249 DrawMenu2DSprite(MenuOption, CRect_i_(cell_x, row_y + 1, 32, 23), CRect_i_(u, v + 1, 32, 24), alpha);
3250 v += 24;
3251 cell_x += 36;
3252 }
3253
3254 int off_u;
3255 off_u = 0;
3256
3257 if (setting != 3) {
3258 off_u += 64;
3259 }
3260
3261 DrawMenu2DSprite(MenuOption, CRect_i_(cell_x, row_y + 1, 64, 23), CRect_i_(off_u, 199, 64, 24), alpha);
3262 break;
3263 case 4:
3264 DrawMenu2DSprite(MenuOption, CRect_i_(row_x + 238, row_y + 1, 64, 23), CRect_i_(u, v, 64, 24), alpha);
3265 break;
3266 }
3267
3268 row_y += 30;
3269
3270 if (i == 6) {
3271 row_x += 560;
3272 row_y = y;
3273 }
3274 }
3275
3276 DrawMenu2DSprite(MenuOption, CRect_i_(arrow_x, arrow_y, 60, 29), CRect_i_(452, 224, 60, 29), alpha);
3277}
3278#else
3279static void OptionMenuDraw(int x, int y, int arrow_x, int arrow_y, int alpha) {
3280 int label[12] = {10, 8, 4, 5, 2, 3, 9, 11, 12, 13, 6, 7};
3281 int kind[12] = {0, 0, 1, 2, 0, 1, 3, 0, 0, 0, 0, 0};
3282 int u;
3283 int v;
3284 int j;
3285 int i;
3286 int row_x;
3287 int row_y;
3288 int cell_x;
3289 int setting;
3290
3291 row_x = x;
3292 row_y = y;
3293
3294 for (i = 0; i < 12; i++) {
3295 CRect_i_ dst(0, 0, 210, 24);
3296 CRect_i_ src(0, 0, 210, 24);
3297
3298 if (label[i] < 7) {
3299 src.x = 0;
3300 src.y = label[i] * 24;
3301 } else {
3302 src.x = src.width;
3303 src.y = (label[i] - 7) * 24;
3304 }
3305
3306 dst.x = row_x;
3307 dst.y = row_y + 1;
3308 DrawMenu2DSprite(MenuOption, dst, src, alpha);
3309
3310 switch (kind[i]) {
3311 case 0:
3312 case 1:
3313 case 2:
3314 u = OptionMenu.flag[i] << 6;
3315 v = kind[i] * 48 + 176;
3316 DrawMenu2DSprite(MenuOption, CRect_i_(row_x + 238, row_y + 1, 64, 23), CRect_i_(u, v + 1, 64, 24), alpha);
3317
3318 if (u < 64) {
3319 u = 64;
3320 } else {
3321 u = 0;
3322 }
3323
3324 v = (kind[i] * 2 + 1) * 24 + 176;
3325 DrawMenu2DSprite(MenuOption, CRect_i_(row_x + 310, row_y + 1, 64, 23), CRect_i_(u, v + 1, 64, 24), alpha);
3326 break;
3327 case 3:
3328 v = 176;
3329 cell_x = row_x + 238;
3330 setting = OptionMenu.flag[i];
3331
3332 for (j = 0; j < 3; j++) {
3333 u = 160;
3334
3335 if (j == setting) {
3336 u -= 32;
3337 }
3338
3339 DrawMenu2DSprite(MenuOption, CRect_i_(cell_x, row_y + 1, 32, 23), CRect_i_(u, v + 1, 32, 24), alpha);
3340 v += 24;
3341 cell_x += 36;
3342 }
3343
3344 int off_u;
3345 off_u = 0;
3346
3347 if (setting != 3) {
3348 off_u += 64;
3349 }
3350
3351 DrawMenu2DSprite(MenuOption, CRect_i_(cell_x, row_y + 1, 64, 23), CRect_i_(off_u, 199, 64, 24), alpha);
3352 break;
3353 }
3354
3355 row_y += 30;
3356
3357 if (i == 5) {
3358 row_x += 560;
3359 row_y = y;
3360 }
3361 }
3362
3363 DrawMenu2DSprite(MenuOption, CRect_i_(arrow_x, arrow_y, 60, 29), CRect_i_(452, 226, 60, 29), alpha);
3364}
3365#endif
3366
3374static void DrawOptionLRCur(int side, int alpha) {
3375#ifdef PAL
3376 s16 cursor_x[2] = {32, 520};
3377#else
3378 int cursor_x[2] = {32, 520};
3379#endif
3380 int v;
3381
3382 v = side * 32 + 256;
3383 DrawMenu2DSprite(MenuOption, CRect_i_(cursor_x[side], 180, 96, 32), CRect_i_(416, v, 96, 32), alpha);
3384}
3385
3386#ifdef PAL
3394static void DrawOptionScreenWaku() {
3395 int center_x = 320;
3396 int center_y = 240;
3397
3398 DrawMenu2DSprite(MenuOption, CRect_i_(288, 208, 64, 64), CRect_i_(448, 0, 64, 64), 0x80);
3399 // Screen corners that the frame corner pieces sit in.
3400 s16 corner[4][2] = {
3401 {4, 4 },
3402 {604, 4 },
3403 {4, 444},
3404 {604, 444}
3405 };
3406 // Positions of the four arrows around the centre piece.
3407 s16 arrow[4][2] = {
3408 {center_x - 16, center_y - 96},
3409 {center_x + 64, center_y - 16},
3410 {center_x - 16, center_y + 64},
3411 {center_x - 96, center_y - 16}
3412 };
3413 // Source offset of each corner's piece within its group.
3414 u8 piece_uv[4][2] = {
3415 {0, 0 },
3416 {32, 0 },
3417 {0, 32},
3418 {32, 32}
3419 };
3420
3421 for (int i = 0; i < 4; i++) {
3422 DrawMenu2DSprite(MenuOption, CRect_i_(corner[i][0], corner[i][1], 32, 32), CRect_i_(piece_uv[i][0] + 448, piece_uv[i][1] + 64, 32, 32), 0x80);
3423 DrawMenu2DSprite(MenuOption, CRect_i_(arrow[i][0], arrow[i][1], 32, 32), CRect_i_(piece_uv[i][0] + 448, piece_uv[i][1] + 128, 32, 32), 0x80);
3424 }
3425}
3426#endif
3427
3428int InitMenuOption(int mode, int block_no, u_long128 *buffer) {
3429 u_long128 *data;
3430 CUserStatus *status;
3431 int i;
3432
3433 switch ((int) buffer) {
3434 case 0:
3435 buffer = (u_long128 *) read_buffer;
3436 }
3437
3438 data = MenuCalcBufAlignment(buffer);
3439 StartReadBG();
3440
3441 if (LoadFileBGMenuData("option.pac", data) <= 0) {
3442 return 0;
3443 }
3444
3445 OptionMenu.mode = mode;
3446 OptionMenu.block_no = block_no;
3447
3448 switch (OptionMenu.mode) {
3449 case OPTION_OPEN_TITLE:
3450 GamePad.SetAutoRepeat(PAD_DPAD, 30, 5);
3451 GamePad.MenuModeOn(120);
3452 }
3453
3454 OptionMenu.texture_ready = false;
3455 OptionMenu.step = OPTION_STEP_FADE_IN;
3456 OptionMenu.step_count = 0;
3457 OptionMenu.cursor = 10;
3458 OptionMenu.cursor_x = (OptionMenu.cursor % 10) * 70 + 316;
3459#ifdef PAL
3460 OptionMenu.cursor_y = ((OptionMenu.cursor - 10) / 10) * 30 + 86;
3461#else
3462 OptionMenu.cursor_y = ((OptionMenu.cursor - 10) / 10) * 30 + 90;
3463#endif
3464 OptionMenu.page_x = 136.0f;
3465 OpConfigPt = (s32 *) SaveData->GetConfigData();
3466 status = (CUserStatus *) SaveData->GetDngStatus();
3467 OptionMenu.flag[0] = SaveData->GetMenuCursor()->reset_pos;
3468 OptionMenu.flag[1] = OpConfigPt[7];
3469 OptionMenu.flag[2] = OpConfigPt[4];
3470 OptionMenu.flag[3] = OpConfigPt[5];
3471 OptionMenu.flag[4] = OpConfigPt[2];
3472 OptionMenu.flag[5] = OpConfigPt[3];
3473#ifdef PAL
3474 OptionMenu.flag[7] = status->minimap_status;
3475 OptionMenu.flag[8] = OpConfigPt[10];
3476 OptionMenu.flag[9] = OpConfigPt[9];
3477 OptionMenu.flag[10] = OpConfigPt[11];
3478 OptionMenu.flag[11] = OpConfigPt[8];
3479 OptionMenu.flag[12] = OpConfigPt[6];
3480 OptionMenu.prev_screen_pos[0] = OpConfigPt[12];
3481 OptionMenu.prev_screen_pos[1] = OpConfigPt[13];
3482
3483 // Runs one past the rows, into the first saved screen offset.
3484 for (i = 0; i < 14; i++) {
3485 OptionMenu.prev_flag[i] = OptionMenu.flag[i];
3486 }
3487
3488#else
3489 OptionMenu.flag[6] = status->minimap_status;
3490 OptionMenu.flag[7] = OpConfigPt[10];
3491 OptionMenu.flag[8] = OpConfigPt[9];
3492 OptionMenu.flag[9] = OpConfigPt[11];
3493 OptionMenu.flag[10] = OpConfigPt[8];
3494 OptionMenu.flag[11] = OpConfigPt[6];
3495
3496 for (i = 0; i < 12; i++) {
3497 OptionMenu.prev_flag[i] = OptionMenu.flag[i];
3498 }
3499
3500#endif
3501 return 1;
3502}
3503
3508static inline void SetCursorResetPos(CMenuCursor *cursor, int reset) {
3509 cursor->reset_pos = reset;
3510}
3511
3516static void ExitMenuOption() {
3517 CUserStatus *status;
3518 CMenuCursor *cursor;
3519
3520 if (OptionMenu.mode == OPTION_OPEN_TITLE) {
3521 GamePad.AutoRepeatOff();
3522 GamePad.MenuModeOff();
3523 GamePad.SetAutoRepeat(PAD_UP | PAD_DOWN, 30, 9);
3524 GamePad.MenuModeOn(120);
3525 }
3526
3527 status = (CUserStatus *) SaveData->GetDngStatus();
3528 cursor = SaveData->GetMenuCursor();
3529 SetCursorResetPos(cursor, OptionMenu.flag[0]);
3530
3531 if (cursor->reset_pos) {
3532 cursor->InitPos();
3533 }
3534
3535 OpConfigPt[7] = OptionMenu.flag[1];
3536 OpConfigPt[4] = OptionMenu.flag[2];
3537 OpConfigPt[5] = OptionMenu.flag[3];
3538 CSnd.SetStereoMode(OpConfigPt[5] ? 0 : 1);
3539 OpConfigPt[2] = OptionMenu.flag[4];
3540 OpConfigPt[3] = OptionMenu.flag[5];
3541#ifdef PAL
3542 status->minimap_status = OptionMenu.flag[7];
3543 OpConfigPt[10] = OptionMenu.flag[8];
3544 OpConfigPt[9] = OptionMenu.flag[9];
3545 OpConfigPt[11] = OptionMenu.flag[10];
3546 OpConfigPt[8] = OptionMenu.flag[11];
3547 OpConfigPt[6] = OptionMenu.flag[12];
3548#else
3549 status->minimap_status = OptionMenu.flag[6];
3550 OpConfigPt[10] = OptionMenu.flag[7];
3551 OpConfigPt[9] = OptionMenu.flag[8];
3552 OpConfigPt[11] = OptionMenu.flag[9];
3553 OpConfigPt[8] = OptionMenu.flag[10];
3554 OpConfigPt[6] = OptionMenu.flag[11];
3555#endif
3556}
3557
3565static void InitOptionFlag() {
3566 int i;
3567
3568#ifdef PAL
3569 for (i = 0; i < 13; i++) {
3570 OptionMenu.flag[i] = 0;
3571 }
3572
3573 OptionMenu.flag[7] = 1;
3574 OpConfigPt[13] = 0;
3575 OpConfigPt[12] = 0;
3576#else
3577 for (i = 0; i < 12; i++) {
3578 OptionMenu.flag[i] = 0;
3579 }
3580
3581 OptionMenu.flag[6] = 1;
3582#endif
3583}
3584
3592static void PrevOptionSetFunc() {
3593 int i;
3594
3595 for (i = 0; i < 12; i++) {
3596 OptionMenu.flag[i] = OptionMenu.prev_flag[i];
3597 }
3598
3599#ifdef PAL
3600 OpConfigPt[12] = OptionMenu.prev_screen_pos[0];
3601 OpConfigPt[13] = OptionMenu.prev_screen_pos[1];
3602#endif
3603}
3604
3605#ifdef PAL
3606int MenuOptionKey() {
3607 int result = 0;
3608
3609 switch (OptionMenu.step) {
3610 case OPTION_STEP_FADE_IN:
3611 if (OptionMenu.texture_ready == 0) {
3612 ReadBG();
3613
3614 if (ReadBGSync() == 0) {
3615 LOADTEXTURE_INFO2 textures[3] = {
3616 {"#frame_image_option#640#" SCREEN_HEIGHT_STR "#4", 0, 0},
3617 {NULL, 0, 0},
3618 {NULL, 0, 0}
3619 };
3620 textures[0].block_no = OptionMenu.block_no;
3621 textures[1].block_no = OptionMenu.block_no;
3622 BG_READ_INFO *file = GetReadBGFile(0);
3623 textures[1].name = (char *) GetPackFile((u_int *) file->buffer, "option.img", NULL);
3624 TexManager.DeleteTextureBlock(OptionMenu.block_no);
3625 TexManager.CleanUpTextureList();
3626 TexManager.LoadTextureBlockEX(-1, textures);
3627 MenuOption = TexManager.GetTexture("option2", -1);
3628
3629 if (OptionMenu.mode == OPTION_OPEN_TITLE) {
3630 InitMenuMesSet(MENU_MES_SET_ALLMENU, (short *) GetPackFile((u_int *) file->buffer, "allmenu.mes", NULL));
3631 CommonMenuMes2.MakeMesWin(0x15E);
3632 }
3633
3634 OptionMenu.texture_ready = true;
3635 }
3636 }
3637
3638 if (OptionMenu.texture_ready != 0 && OptionMenu.step_count > 12) {
3639 OptionMenu.step = OPTION_STEP_RUN;
3640 OptionMenu.step_count = 0;
3641 }
3642
3643 break;
3644 case OPTION_STEP_FADE_OUT:
3645 if (OptionMenu.step_count > 24) {
3646 ExitMenuOption();
3647 CommonMenuMes2.mes_made = -1;
3648 result = 1;
3649 }
3650
3651 break;
3652 default: {
3653 int old_cursor = OptionMenu.cursor;
3654 int old_buttons = OptionMenu.buttons;
3655
3656 if (OptionMenu.buttons != OPTION_AREA_SCREEN_POS && GamePad.Down(PAD_L2 | PAD_R2 | PAD_L1 | PAD_R1) != 0) {
3657 if (OptionMenu.cursor / 10 - 1 < 7) {
3658 OptionMenu.cursor += 70;
3659 } else {
3660 OptionMenu.cursor -= 70;
3661 }
3662
3663 if (OptionMenu.cursor / 10 - 1 >= 13) {
3664 OptionMenu.cursor -= 10;
3665 }
3666 }
3667
3668 switch (OptionMenu.buttons) {
3669 case OPTION_AREA_SCREEN_POS:
3670 // Moves the picture, clamped to 32 in each direction.
3671 if (GamePad.Down(PAD_UP) != 0) {
3672 OpConfigPt[13] -= 2;
3673 }
3674
3675 if (GamePad.Down(PAD_DOWN) != 0) {
3676 OpConfigPt[13] += 2;
3677 }
3678
3679 if (GamePad.Down(PAD_LEFT) != 0) {
3680 OpConfigPt[12] -= 4;
3681 }
3682
3683 if (GamePad.Down(PAD_RIGHT) != 0) {
3684 OpConfigPt[12] += 4;
3685 }
3686
3687 if (OpConfigPt[13] < -32) {
3688 OpConfigPt[13] = -32;
3689 }
3690
3691 if (OpConfigPt[13] > 32) {
3692 OpConfigPt[13] = 32;
3693 }
3694
3695 if (OpConfigPt[12] < -32) {
3696 OpConfigPt[12] = -32;
3697 }
3698
3699 if (OpConfigPt[12] > 32) {
3700 OpConfigPt[12] = 32;
3701 }
3702
3703 if (GamePad.Down(PAD_SQUARE) != 0) {
3704 OpConfigPt[13] = 0;
3705 OpConfigPt[12] = 0;
3706 }
3707
3708 if (GamePad.Down(PAD_CIRCLE | PAD_CROSS) != 0) {
3709 OptionMenu.buttons = OPTION_AREA_ROWS;
3710 }
3711
3712 break;
3713 case OPTION_AREA_ROWS:
3714 if (GamePad.Down(PAD_DOWN) != 0) {
3715 if (OptionMenu.cursor / 10 - 1 == 7 && OptionMenu.cursor % 10 > 1) {
3716 OptionMenu.cursor -= 2;
3717 }
3718
3719 switch (OptionMenu.cursor / 10 - 1) {
3720 case 6:
3721 case 12:
3722 OptionMenu.buttons = OPTION_AREA_EXIT_BUTTON;
3723 break;
3724 default:
3725 OptionMenu.cursor += 10;
3726 break;
3727 }
3728 }
3729
3730 if (GamePad.Down(PAD_UP) != 0) {
3731 switch (OptionMenu.cursor / 10 - 1) {
3732 case 0:
3733 case 7:
3734 OptionMenu.buttons = OPTION_AREA_EXIT_BUTTON;
3735 break;
3736 default:
3737 OptionMenu.cursor -= 10;
3738 break;
3739 }
3740 }
3741
3742 if (GamePad.Down(PAD_RIGHT) != 0) {
3743 if (OptionMenu.cursor / 10 - 1 == 6) {
3744 OptionMenu.cursor = 130;
3745 } else {
3746 OptionMenu.cursor++;
3747
3748 switch (OptionMenu.cursor / 10 - 1) {
3749 case 7:
3750 if (OptionMenu.cursor % 10 == 4) {
3751 OptionMenu.cursor -= 74;
3752 }
3753
3754 break;
3755 default:
3756 if (OptionMenu.cursor % 10 == 2) {
3757 OptionMenu.cursor -= 2;
3758 OptionMenu.cursor += 70;
3759
3760 if (OptionMenu.cursor / 10 - 1 >= 13) {
3761 OptionMenu.cursor -= 140;
3762 }
3763
3764 if (OptionMenu.cursor / 10 - 1 > 13) {
3765 OptionMenu.cursor -= 10;
3766 }
3767 }
3768
3769 break;
3770 }
3771 }
3772 }
3773
3774 if (GamePad.Down(PAD_LEFT) != 0) {
3775 if (OptionMenu.cursor % 10 != 0) {
3776 OptionMenu.cursor--;
3777 } else {
3778 int row = OptionMenu.cursor / 10 - 1;
3779
3780 switch (row) {
3781 case 0:
3782 OptionMenu.cursor = 0x53;
3783 break;
3784 default:
3785 if (row < 7) {
3786 OptionMenu.cursor += 70;
3787
3788 if (OptionMenu.cursor / 10 - 1 >= 13) {
3789 OptionMenu.cursor -= 10;
3790 }
3791 } else {
3792 OptionMenu.cursor -= 70;
3793 }
3794
3795 OptionMenu.cursor++;
3796 break;
3797 }
3798 }
3799 }
3800
3801 if (OptionMenu.cursor / 10 - 1 != 7) {
3802 if (OptionMenu.cursor % 10 >= 2) {
3803 OptionMenu.cursor--;
3804 }
3805
3806 if (OptionMenu.cursor / 10 - 1 == 6) {
3807 OptionMenu.cursor = OptionMenu.cursor - OptionMenu.cursor % 10;
3808 }
3809 }
3810
3811 if (GamePad.Down(PAD_CROSS) != 0) {
3812 ComMenuSePlay(MENU_SOUND_CONFIRM);
3813
3814 if (OptionMenu.cursor / 10 - 1 == 6) {
3815 OptionMenu.buttons = OPTION_AREA_SCREEN_POS;
3816 } else {
3817 OptionMenu.flag[OptionMenu.cursor / 10 - 1] = OptionMenu.cursor % 10;
3818 }
3819 } else if (GamePad.Down(PAD_CIRCLE) != 0) {
3820 OptionMenu.step = OPTION_STEP_FADE_OUT;
3821 OptionMenu.step_count = 0;
3822 ComMenuSePlay(MENU_SOUND_REFUSE);
3823 }
3824
3825 break;
3826 case OPTION_AREA_EXIT_BUTTON:
3827 if (GamePad.Down(PAD_DOWN) != 0) {
3828 OptionMenu.buttons = OPTION_AREA_ROWS;
3829
3830 if (OptionMenu.cursor / 10 - 1 < 7) {
3831 OptionMenu.cursor = 10;
3832 } else {
3833 OptionMenu.cursor = 70;
3834 }
3835 }
3836
3837 if (GamePad.Down(PAD_UP) != 0) {
3838 OptionMenu.buttons = OPTION_AREA_ROWS;
3839
3840 if (OptionMenu.cursor / 10 - 1 < 7) {
3841 OptionMenu.cursor = 70;
3842 } else {
3843 OptionMenu.cursor = 130;
3844 }
3845 }
3846
3847 if (GamePad.Down(PAD_CROSS) != 0) {
3848 OptionMenu.step = OPTION_STEP_FADE_OUT;
3849 OptionMenu.step_count = 0;
3850 ComMenuSePlay(MENU_SOUND_REFUSE);
3851 } else if (GamePad.Down(PAD_SQUARE) != 0) {
3852 InitOptionFlag();
3853 } else if (GamePad.Down(PAD_TRIANGLE) != 0) {
3854 PrevOptionSetFunc();
3855 } else if (GamePad.Down(PAD_CIRCLE) != 0) {
3856 OptionMenu.step = OPTION_STEP_FADE_OUT;
3857 OptionMenu.step_count = 0;
3858 ComMenuSePlay(MENU_SOUND_REFUSE);
3859 }
3860
3861 break;
3862 }
3863
3864 if (old_cursor != OptionMenu.cursor || old_buttons != OptionMenu.buttons) {
3865 ComMenuSePlay(MENU_SOUND_CURSOR);
3866 }
3867
3868 // Help message by cursor area: a row's own, the buttons', the picture position's.
3869 int mes_nos[3] = {OptionMenu.cursor / 10 + 0x15D, 0x171, 0x16C};
3870 int mes_no = mes_nos[OptionMenu.buttons];
3871
3872 if (OptionMenu.buttons == OPTION_AREA_ROWS) {
3873 int row = OptionMenu.cursor / 10 - 1;
3874
3875 if (row >= 6) {
3876 mes_no--;
3877
3878 if (row == 6) {
3879 mes_no = 0x16A;
3880 }
3881 }
3882 }
3883
3884 if (CommonMenuMes2.mes_made != mes_no) {
3885 CommonMenuMes2.MakeMesWin(mes_no);
3886 }
3887
3888 break;
3889 }
3890 }
3891
3892 return result;
3893}
3894#else
3895int MenuOptionKey() {
3896 int result = 0;
3897
3898 switch (OptionMenu.step) {
3899 case OPTION_STEP_FADE_IN:
3900 if (OptionMenu.texture_ready == 0) {
3901 ReadBG();
3902
3903 if (ReadBGSync() == 0) {
3904 LOADTEXTURE_INFO2 textures[3] = {
3905 {"#frame_image_option#640#448#4", 0, 0},
3906 {NULL, 0, 0},
3907 {NULL, 0, 0}
3908 };
3909 textures[0].block_no = OptionMenu.block_no;
3910 textures[1].block_no = OptionMenu.block_no;
3911 BG_READ_INFO *file = GetReadBGFile(0);
3912 textures[1].name = (char *) GetPackFile((u_int *) file->buffer, "option.img", NULL);
3913 TexManager.DeleteTextureBlock(OptionMenu.block_no);
3914 TexManager.CleanUpTextureList();
3915 TexManager.LoadTextureBlockEX(-1, textures);
3916 MenuOption = TexManager.GetTexture("option2", -1);
3917
3918 if (OptionMenu.mode == OPTION_OPEN_TITLE) {
3919 InitMenuMesSet(MENU_MES_SET_ALLMENU, (short *) GetPackFile((u_int *) file->buffer, "allmenu.mes", NULL));
3920 CommonMenuMes2.MakeMesWin(0x15E);
3921 }
3922
3923 OptionMenu.texture_ready = true;
3924 }
3925 }
3926
3927 if (OptionMenu.texture_ready != 0 && OptionMenu.step_count > 12) {
3928 OptionMenu.step = OPTION_STEP_RUN;
3929 OptionMenu.step_count = 0;
3930 }
3931
3932 break;
3933 case OPTION_STEP_FADE_OUT:
3934 if (OptionMenu.step_count > 24) {
3935 ExitMenuOption();
3936 CommonMenuMes2.mes_made = -1;
3937 result = 1;
3938 }
3939
3940 break;
3941 default: {
3942 int old_cursor = OptionMenu.cursor;
3943 int old_buttons = OptionMenu.buttons;
3944
3945 if (GamePad.Down(PAD_L2 | PAD_R2 | PAD_L1 | PAD_R1) != 0) {
3946 if (OptionMenu.cursor / 10 - 1 < 6) {
3947 OptionMenu.cursor += 60;
3948 } else {
3949 OptionMenu.cursor -= 60;
3950 }
3951 }
3952
3953 switch (OptionMenu.buttons) {
3954 case OPTION_AREA_ROWS:
3955 if (GamePad.Down(PAD_DOWN) != 0) {
3956 switch (OptionMenu.cursor / 10 - 1) {
3957 case 5:
3958 case 11:
3959 OptionMenu.buttons = OPTION_AREA_EXIT_BUTTON;
3960 break;
3961 default:
3962 OptionMenu.cursor += 10;
3963 break;
3964 }
3965 }
3966
3967 if (GamePad.Down(PAD_UP) != 0) {
3968 switch (OptionMenu.cursor / 10 - 1) {
3969 case 0:
3970 case 6:
3971 OptionMenu.buttons = OPTION_AREA_EXIT_BUTTON;
3972 break;
3973 default:
3974 OptionMenu.cursor -= 10;
3975 break;
3976 }
3977 }
3978
3979 if (GamePad.Down(PAD_RIGHT) != 0) {
3980 OptionMenu.cursor++;
3981
3982 switch (OptionMenu.cursor / 10 - 1) {
3983 case 6:
3984 if (OptionMenu.cursor % 10 == 4) {
3985 OptionMenu.cursor -= 64;
3986 }
3987
3988 break;
3989 default:
3990 if (OptionMenu.cursor % 10 == 2) {
3991 OptionMenu.cursor -= 2;
3992 OptionMenu.cursor += 60;
3993
3994 if (OptionMenu.cursor / 10 - 1 >= 12) {
3995 OptionMenu.cursor -= 120;
3996 }
3997 }
3998
3999 break;
4000 }
4001 }
4002
4003 if (GamePad.Down(PAD_LEFT) != 0) {
4004 if (OptionMenu.cursor % 10 != 0) {
4005 OptionMenu.cursor--;
4006 } else {
4007 int row = OptionMenu.cursor / 10 - 1;
4008
4009 switch (row) {
4010 case 0:
4011 OptionMenu.cursor = 0x49;
4012 break;
4013 default:
4014 if (row < 6) {
4015 OptionMenu.cursor += 60;
4016 } else {
4017 OptionMenu.cursor -= 60;
4018 }
4019
4020 OptionMenu.cursor++;
4021 break;
4022 }
4023 }
4024 }
4025
4026 if (OptionMenu.cursor / 10 - 1 != 6 && OptionMenu.cursor % 10 >= 2) {
4027 OptionMenu.cursor--;
4028 }
4029
4030 if (GamePad.Down(PAD_CROSS) != 0) {
4031 ComMenuSePlay(MENU_SOUND_CONFIRM);
4032 OptionMenu.flag[OptionMenu.cursor / 10 - 1] = OptionMenu.cursor % 10;
4033 }
4034
4035 break;
4036 case OPTION_AREA_EXIT_BUTTON:
4037 if (GamePad.Down(PAD_DOWN) != 0) {
4038 OptionMenu.buttons = OPTION_AREA_ROWS;
4039
4040 if (OptionMenu.cursor / 10 - 1 < 6) {
4041 OptionMenu.cursor = 10;
4042 } else {
4043 OptionMenu.cursor = 60;
4044 }
4045 }
4046
4047 if (GamePad.Down(PAD_UP) != 0) {
4048 OptionMenu.buttons = OPTION_AREA_ROWS;
4049
4050 if (OptionMenu.cursor / 10 - 1 < 6) {
4051 OptionMenu.cursor = 60;
4052 } else {
4053 OptionMenu.cursor = 120;
4054 }
4055 }
4056
4057 if (GamePad.Down(PAD_CROSS) != 0) {
4058 OptionMenu.step = OPTION_STEP_FADE_OUT;
4059 OptionMenu.step_count = 0;
4060 ComMenuSePlay(MENU_SOUND_REFUSE);
4061 } else if (GamePad.Down(PAD_SQUARE) != 0) {
4062 InitOptionFlag();
4063 } else if (GamePad.Down(PAD_TRIANGLE) != 0) {
4064 PrevOptionSetFunc();
4065 }
4066
4067 break;
4068 }
4069
4070 if (old_cursor != OptionMenu.cursor || old_buttons != OptionMenu.buttons) {
4071 ComMenuSePlay(MENU_SOUND_CURSOR);
4072 }
4073
4074 if (GamePad.Down(PAD_CIRCLE) != 0) {
4075 OptionMenu.step = OPTION_STEP_FADE_OUT;
4076 OptionMenu.step_count = 0;
4077 ComMenuSePlay(MENU_SOUND_REFUSE);
4078 }
4079
4080 int mes_no = OptionMenu.cursor / 10 + 0x15D;
4081
4082 if (OptionMenu.buttons == OPTION_AREA_EXIT_BUTTON) {
4083 mes_no = 0x171;
4084 }
4085
4086 if (CommonMenuMes2.mes_made != mes_no) {
4087 CommonMenuMes2.MakeMesWin(mes_no);
4088 }
4089
4090 break;
4091 }
4092 }
4093
4094 return result;
4095}
4096#endif
4097
4098#ifdef PAL
4099void DrawMenuOption() {
4100 setbilinear(0);
4101
4102 if (OptionMenu.texture_ready == 0) {
4103 return;
4104 }
4105
4106 MenuTextureReload(OptionMenu.block_no);
4107 int alpha = 0x80;
4108
4109 switch (OptionMenu.step) {
4110 case OPTION_STEP_FADE_IN:
4111 alpha = OptionMenu.step_count * 7;
4112 break;
4113 case OPTION_STEP_FADE_OUT:
4114 alpha = 0x80 - OptionMenu.step_count * 7;
4115 break;
4116 case OPTION_STEP_RUN:
4117 alpha = 0x80;
4118 break;
4119 }
4120
4121 if (alpha >= 0x80) {
4122 alpha = 0x80;
4123 }
4124
4125 if (alpha <= 0) {
4126 alpha = 0;
4127 }
4128
4129 int row = OptionMenu.cursor / 10 - 1;
4130 int column = OptionMenu.cursor % 10;
4131 int page_x;
4132
4133 if (row < 7) {
4134 page_x = 0x88;
4135 } else {
4136 page_x = -0x1A8;
4137 }
4138
4139 OptionMenu.page_x += ((float) page_x - OptionMenu.page_x) / 4.0f;
4140 int x = (int) OptionMenu.page_x;
4141
4142 if (OptionMenu.buttons != OPTION_AREA_SCREEN_POS) {
4143 OptionMenuDraw(x, 0x56, 0x1AE, 0x128, alpha);
4144 int right = 1;
4145
4146 if (x < -0x90) {
4147 right = 0;
4148 }
4149
4150 DrawOptionLRCur(right, alpha);
4151 }
4152
4153 int target_x;
4154 int target_y;
4155
4156 switch (OptionMenu.buttons) {
4157 case OPTION_AREA_EXIT_BUTTON:
4158 target_x = 0x192;
4159 target_y = 0x12C;
4160 break;
4161 default:
4162 target_x = column * 0x47 + 0x15C;
4163
4164 if (row == 7) {
4165 if (column != 3) {
4166 target_x = column * 0x24 + 0x15C;
4167 } else {
4168 target_x = 0x1C8;
4169 }
4170 }
4171
4172 if (row < 7) {
4173 target_y = row * 0x1E + 0x56;
4174 } else {
4175 target_y = (row - 7) * 0x1E + 0x56;
4176 }
4177
4178 break;
4179 }
4180
4181 OptionMenu.cursor_x += ((float) target_x - OptionMenu.cursor_x) / 4.0f;
4182 OptionMenu.cursor_y += ((float) target_y - OptionMenu.cursor_y) / 4.0f;
4183 int width;
4184
4185 switch (OptionMenu.buttons) {
4186 case OPTION_AREA_EXIT_BUTTON:
4187 width = 0x40;
4188 break;
4189 default:
4190 width = 0x3C;
4191
4192 if (row == 7 && column != 3) {
4193 width = 0x24;
4194 }
4195
4196 break;
4197 }
4198
4199 switch (OptionMenu.step) {
4200 case OPTION_STEP_FADE_IN:
4201 case OPTION_STEP_FADE_OUT:
4202 break;
4203 default: {
4204 static int OpMenuWakuCnt = 0;
4205 static int OptionCurCnt = 0;
4206 int left = (int) ((float) (target_x + 0x14) + 0.2f * OpMenuWakuCnt);
4207 int top = (int) ((float) (target_y - 9) + 0.2f * OpMenuWakuCnt);
4208 int right_x = (int) ((float) (target_x + 0x14 + width) - 0.2f * OpMenuWakuCnt);
4209 int bottom = (int) ((float) (target_y + 0x11) - 0.2f * OpMenuWakuCnt);
4210 RECT corner = {0xB2, 0xF8, 0x10, 0x10};
4211
4212 if (OptionMenu.buttons != OPTION_AREA_SCREEN_POS) {
4213 DrawMenu2DSprite(MenuOption, CRect_i_(left, top, corner.width, corner.height), CRect_i_(corner.x, corner.y, corner.width, corner.height), alpha);
4214 DrawMenu2DSprite(MenuOption, CRect_i_(right_x, top, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y, corner.width, corner.height), alpha);
4215 DrawMenu2DSprite(MenuOption, CRect_i_(left, bottom, corner.width, corner.height), CRect_i_(corner.x, corner.y + corner.height, corner.width, corner.height), alpha);
4216 DrawMenu2DSprite(MenuOption, CRect_i_(right_x, bottom, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y + corner.height, corner.width, corner.height), alpha);
4217 OpMenuWakuCnt++;
4218
4219 if (OpMenuWakuCnt < 0 || OpMenuWakuCnt >= 30) {
4220 OpMenuWakuCnt = 0;
4221 }
4222
4223 float hand_x = OptionMenu.cursor_x + 7.0f * cosf(0.0805536583f * OptionCurCnt);
4224 float hand_y = OptionMenu.cursor_y + 5.0f * sinf(0.116355285f * OptionCurCnt);
4225 CRect_i_ hand(0xD2, 0xF8, 0x20, 0x20);
4226 DrawMenu2DSprite(MenuOption, CRect_i_((int) (5.0f + hand_x), (int) (3.0f + hand_y), 0x20, 0x20), hand, 0, 0, 0, (alpha * 100) >> 7);
4227 DrawMenu2DSprite(MenuOption, CRect_i_((int) hand_x, (int) hand_y, 0x20, 0x20), hand, alpha);
4228 }
4229
4230 OptionCurCnt++;
4231
4232 if (OptionCurCnt > 0x107AC0 || OptionCurCnt < 0) {
4233 OptionCurCnt = 0;
4234 }
4235
4236 break;
4237 }
4238 }
4239
4240 if (OptionMenu.buttons == OPTION_AREA_SCREEN_POS) {
4241 AllFadeForMenu(0x20);
4242 DrawOptionScreenWaku();
4243 }
4244
4245 if (OptionMenu.step != OPTION_STEP_RUN) {
4246 OptionMenu.step_count++;
4247 } else {
4248 OptionMenu.step_count = 0;
4249 }
4250
4251 switch (OptionMenu.mode) {
4252 case OPTION_OPEN_TITLE: {
4253 float win_x;
4254 float win_y;
4255 float win_w;
4256 float win_h;
4257 int text_x;
4258 int text_y;
4259 DrawMenu2DSprite(MenuOption, CRect_i_(0x50, 0x28, 0xAA, 0x28), CRect_i_(0xB3, 0x118, 0xAA, 0x28), alpha);
4260 GetMainMenuRightHelpWinLangOffset(win_x, win_y, win_w, win_h);
4261 MenuHelpWinDraw((int) win_x, (int) win_y, win_w, win_h, alpha);
4262 GetMainMenuRightHelpMsgLangOffset(text_x, text_y);
4263 CommonMenuMes2.edge_alpha = alpha;
4264 MenuTextureReload(CommonMenuMes2.tex_block);
4265 DrawMenuClsMes(&CommonMenuMes2, (int) (win_x + text_x), (int) (win_y + text_y));
4266 break;
4267 }
4268 }
4269
4270 setbilinear(1);
4271}
4272#else
4273void DrawMenuOption() {
4274 setbilinear(0);
4275
4276 if (OptionMenu.texture_ready == 0) {
4277 return;
4278 }
4279
4280 MenuTextureReload(OptionMenu.block_no);
4281 int alpha = 0x80;
4282
4283 switch (OptionMenu.step) {
4284 case OPTION_STEP_FADE_IN:
4285 alpha = OptionMenu.step_count * 7;
4286 break;
4287 case OPTION_STEP_FADE_OUT:
4288 alpha = 0x80 - OptionMenu.step_count * 7;
4289 break;
4290 case OPTION_STEP_RUN:
4291 alpha = 0x80;
4292 break;
4293 }
4294
4295 if (alpha >= 0x80) {
4296 alpha = 0x80;
4297 }
4298
4299 if (alpha <= 0) {
4300 alpha = 0;
4301 }
4302
4303 int row = OptionMenu.cursor / 10 - 1;
4304 int column = OptionMenu.cursor % 10;
4305 int page_x;
4306
4307 if (row < 6) {
4308 page_x = 0x88;
4309 } else {
4310 page_x = -0x1A8;
4311 }
4312
4313 OptionMenu.page_x += ((float) page_x - OptionMenu.page_x) / 4.0f;
4314 int x = (int) OptionMenu.page_x;
4315 OptionMenuDraw(x, 0x5A, 0x1AE, 0x122, alpha);
4316 int right = 1;
4317
4318 if (x < -0x90) {
4319 right = 0;
4320 }
4321
4322 DrawOptionLRCur(right, alpha);
4323 int target_x;
4324 int target_y;
4325
4326 switch (OptionMenu.buttons) {
4327 case OPTION_AREA_EXIT_BUTTON:
4328 target_x = 0x192;
4329 target_y = 0x126;
4330 break;
4331 default:
4332 target_x = column * 0x47 + 0x15C;
4333
4334 if (row == 6) {
4335 if (column != 3) {
4336 target_x = column * 0x24 + 0x15C;
4337 } else {
4338 target_x = 0x1C8;
4339 }
4340 }
4341
4342 if (row < 6) {
4343 target_y = row * 0x1E + 0x5A;
4344 } else {
4345 target_y = (row - 6) * 0x1E + 0x5A;
4346 }
4347
4348 break;
4349 }
4350
4351 OptionMenu.cursor_x += ((float) target_x - OptionMenu.cursor_x) / 4.0f;
4352 OptionMenu.cursor_y += ((float) target_y - OptionMenu.cursor_y) / 4.0f;
4353 int width;
4354
4355 switch (OptionMenu.buttons) {
4356 case OPTION_AREA_EXIT_BUTTON:
4357 width = 0x40;
4358 break;
4359 default:
4360 width = 0x3C;
4361
4362 if (row == 6 && column != 3) {
4363 width = 0x24;
4364 }
4365
4366 break;
4367 }
4368
4369 switch (OptionMenu.step) {
4370 case OPTION_STEP_FADE_IN:
4371 case OPTION_STEP_FADE_OUT:
4372 break;
4373 default: {
4374 static int OpMenuWakuCnt = 0;
4375 static int OptionCurCnt = 0;
4376 int left = (int) ((float) (target_x + 0x14) + 0.2f * OpMenuWakuCnt);
4377 int top = (int) ((float) (target_y - 9) + 0.2f * OpMenuWakuCnt);
4378 int right_x = (int) ((float) (target_x + 0x14 + width) - 0.2f * OpMenuWakuCnt);
4379 int bottom = (int) ((float) (target_y + 0x11) - 0.2f * OpMenuWakuCnt);
4380 RECT corner = {0xB2, 0xF8, 0x10, 0x10};
4381 DrawMenu2DSprite(MenuOption, CRect_i_(left, top, corner.width, corner.height), CRect_i_(corner.x, corner.y, corner.width, corner.height), alpha);
4382 DrawMenu2DSprite(MenuOption, CRect_i_(right_x, top, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y, corner.width, corner.height), alpha);
4383 DrawMenu2DSprite(MenuOption, CRect_i_(left, bottom, corner.width, corner.height), CRect_i_(corner.x, corner.y + corner.height, corner.width, corner.height), alpha);
4384 DrawMenu2DSprite(MenuOption, CRect_i_(right_x, bottom, corner.width, corner.height), CRect_i_(corner.x + corner.width, corner.y + corner.height, corner.width, corner.height), alpha);
4385 OpMenuWakuCnt++;
4386
4387 if (OpMenuWakuCnt < 0 || OpMenuWakuCnt >= 30) {
4388 OpMenuWakuCnt = 0;
4389 }
4390
4391 float hand_x = OptionMenu.cursor_x + 7.0f * cosf(0.0805536583f * OptionCurCnt);
4392 float hand_y = OptionMenu.cursor_y + 5.0f * sinf(0.116355285f * OptionCurCnt);
4393 CRect_i_ hand(0xD2, 0xF8, 0x20, 0x20);
4394 DrawMenu2DSprite(MenuOption, CRect_i_((int) (5.0f + hand_x), (int) (3.0f + hand_y), 0x20, 0x20), hand, 0, 0, 0, (alpha * 100) >> 7);
4395 DrawMenu2DSprite(MenuOption, CRect_i_((int) hand_x, (int) hand_y, 0x20, 0x20), hand, alpha);
4396 OptionCurCnt++;
4397
4398 if (OptionCurCnt > 0x107AC0 || OptionCurCnt < 0) {
4399 OptionCurCnt = 0;
4400 }
4401
4402 break;
4403 }
4404 }
4405
4406 if (OptionMenu.step != OPTION_STEP_RUN) {
4407 OptionMenu.step_count++;
4408 } else {
4409 OptionMenu.step_count = 0;
4410 }
4411
4412 switch (OptionMenu.mode) {
4413 case OPTION_OPEN_TITLE: {
4414 float win_x;
4415 float win_y;
4416 float win_w;
4417 float win_h;
4418 int text_x;
4419 int text_y;
4420 DrawMenu2DSprite(MenuOption, CRect_i_(0x50, 0x28, 0xAA, 0x28), CRect_i_(0xB3, 0x118, 0xAA, 0x28), alpha);
4421 GetMainMenuRightHelpWinLangOffset(win_x, win_y, win_w, win_h);
4422 MenuHelpWinDraw((int) win_x, (int) win_y, win_w, win_h, alpha);
4423 GetMainMenuRightHelpMsgLangOffset(text_x, text_y);
4424 CommonMenuMes2.edge_alpha = alpha;
4425 MenuTextureReload(CommonMenuMes2.tex_block);
4426 DrawMenuClsMes(&CommonMenuMes2, (int) (win_x + text_x), (int) (win_y + text_y));
4427 break;
4428 }
4429 }
4430
4431 setbilinear(1);
4432}
4433#endif
4434
4435int OptionMenuFadeOutStart() {
4436 int result = 0;
4437
4438 if (OptionMenu.step == OPTION_STEP_FADE_OUT) {
4439 result = 1;
4440 }
4441
4442 return result;
4443}
4444
4445int InitMenuSave(int mode, int block_no, u_long128 *buffer) {
4446 u_long128 *data;
4447 int clear;
4448
4449 data = buffer;
4450
4451 if (buffer == NULL) {
4452 data = (u_long128 *) read_buffer;
4453 }
4454
4455 data = MenuCalcBufAlignment(data);
4456 SaveMenu.mode = mode;
4457 SaveMenu.block_no = block_no;
4458 SaveMenu.result = MENU_SAVE_RUNNING;
4459 SaveMenu.step_time = 0;
4460 SaveMenu.texture_ready = false;
4461 SaveMenu.file_no = 0;
4462 SaveMenu.loaded = false;
4463 StartReadBG();
4464 LoadFileBGMenuData("savetex.pak", data);
4465
4466 if (McAccess.InitForMC()) {
4467 return 0;
4468 }
4469
4470 switch (SaveMenu.mode) {
4471 case SAVE_MENU_MODE_LOAD:
4472 GamePad.SetAutoRepeat(PAD_RIGHT | PAD_LEFT, 30, 5);
4473 GamePad.MenuModeOn(120);
4474 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
4475 SaveMenu.access_kind = SAVE_ACCESS_LOAD;
4476 break;
4477 case SAVE_MENU_MODE_SAVE:
4478 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
4479 SaveMenu.access_kind = SAVE_ACCESS_SAVE;
4480 EditSave();
4481 break;
4482 case SAVE_MENU_MODE_ENDING:
4483 case SAVE_MENU_MODE_ENDING_NO_CLEAR:
4484 clear = SaveMenu.mode == SAVE_MENU_MODE_ENDING;
4485 *(s32 *) &((SV_CONFIG_SYS *) SaveData->GetConfigData())->game_clear_area[2] = clear;
4486 printf("SaveData clear flag = %d\n", *(s32 *) &((SV_CONFIG_SYS *) SaveData->GetConfigData())->game_clear_area[2]);
4487 GameClearFlag = SaveMenu.mode == SAVE_MENU_MODE_ENDING;
4488 SaveMenu.mode = SAVE_MENU_MODE_ENDING;
4489 GamePad.SetAutoRepeat(PAD_RIGHT | PAD_LEFT, 30, 5);
4490 GamePad.MenuModeOn(120);
4491 SaveMenu.key_no = SAVE_KEY_AFTER_ENDING;
4492 SaveMenu.access_kind = SAVE_ACCESS_SAVE;
4493 break;
4494 }
4495
4496 SaveMenu.return_key_no = -1;
4497 CommonMenuMes2.stay_frame = true;
4498 CommonMenuMes2.value_show = true;
4499 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4500 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4501 CommonMenuMes2.cursor_lit = true;
4502 return 1;
4503}
4504
4513static void ExitSaveSelect() {
4514 s32 *config;
4515
4516 CommonMenuMes2.stay_frame = false;
4517 CommonMenuMes2.value_show = false;
4518 CommonMenuMes2.value_signed = true;
4519 CommonMenuMes2.auto_pos = MES_POS_NONE;
4520
4521 switch (SaveMenu.mode) {
4522 case SAVE_MENU_MODE_LOAD:
4523 GamePad.AutoRepeatOff();
4524 GamePad.MenuModeOff();
4525 GamePad.SetAutoRepeat(PAD_UP | PAD_DOWN, 30, 9);
4526 GamePad.MenuModeOn(120);
4527
4528 if (SaveMenu.loaded) {
4529 config = (s32 *) SaveData->GetConfigData();
4530
4531 if (config != NULL) {
4532 if (config[5]) {
4533 CSnd.SetStereoMode(0);
4534 } else {
4535 CSnd.SetStereoMode(1);
4536 }
4537 }
4538 }
4539
4540 break;
4541 case SAVE_MENU_MODE_SAVE:
4542 break;
4543 case SAVE_MENU_MODE_ENDING:
4544 GamePad.AutoRepeatOff();
4545 GamePad.MenuModeOff();
4546 break;
4547 }
4548
4549 CommonMenuMes2.cursor_lit = false;
4550}
4551
4552// The save menu's steps that menu_save.cpp defines.
4553int SaveMenuKeySaveCheck();
4554int SaveMenuKeySaveDecide();
4555int SaveMenuKeySave();
4556int SaveMenuKeyEndSave();
4557int SaveMenuKeyLoadDecide();
4558int SaveMenuKeyLoad();
4559int SaveMenuKeyArart();
4560int SaveMenuKeyNewDir();
4561int SaveMenuKeyNewDirSelect();
4562int SaveMenuKeyFormat();
4563int SaveMenuKeyUnFormat();
4564int SaveMenuKeyDifVersion();
4565int SaveMenuKeyDelete();
4566int SaveMenuKeyCopy();
4567int SaveMenuKeyAfterEnding();
4568int SaveMenuKeySaveEnding();
4569int SaveMenuKeySaveDecideEnding();
4570int SaveMenuKeyEndSaveEnding();
4571
4573int (*SaveMenuFunc[26])() = {
4574 SaveMenuKeyFadeIn,
4575 SaveMenuKeyFadeOut,
4576 SaveMenuKeyModeSelect,
4577 SaveMenuKeyMcSelect,
4578 SaveMenuKeyCheckMcType,
4579 SaveMenuKeyCheckMc,
4580 SaveMenuKeyLoadConfig,
4581 SaveMenuKeyFileSelect,
4582 SaveMenuKeySaveCheck,
4583 SaveMenuKeySaveDecide,
4584 SaveMenuKeySave,
4585 SaveMenuKeyEndSave,
4586 SaveMenuKeyLoadDecide,
4587 SaveMenuKeyLoad,
4588 SaveMenuKeyArart,
4589 SaveMenuKeyNewDir,
4590 SaveMenuKeyNewDirSelect,
4591 SaveMenuKeyFormat,
4592 SaveMenuKeyUnFormat,
4593 SaveMenuKeyDifVersion,
4594 SaveMenuKeyDelete,
4595 SaveMenuKeyCopy,
4596 SaveMenuKeyAfterEnding,
4597 SaveMenuKeySaveEnding,
4598 SaveMenuKeySaveDecideEnding,
4599 SaveMenuKeyEndSaveEnding,
4600};
4601
4602int MenuSaveKey() {
4603 int prev_func_no;
4604 int result;
4605 int now_func_no;
4606 int msg_no;
4607 int mes_value;
4608 MC_ERROR_INFO *error;
4609 MC_ERROR_INFO *last_error;
4610
4611 if (!SaveMenu.texture_ready) {
4612 SaveMenu.texture_ready = SaveMenuTextureEnter();
4613 }
4614
4615 prev_func_no = McAccess.GetFuncNo();
4616 result = McAccess.Step();
4617 now_func_no = McAccess.GetFuncNo();
4618
4619 if (prev_func_no == now_func_no) {
4620 last_error = &McAccess.error;
4621
4622 switch (now_func_no) {
4623 case MC_OPERATION_FORMAT:
4624 if (result < 0) {
4625 SaveMenu.key_no = SAVE_KEY_ALERT;
4626 SaveMenu.alert_no = SAVE_ALERT_FORMAT_FAILED;
4627 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4628 }
4629
4630 break;
4631 case MC_OPERATION_MAKE_DIR:
4632 case MC_OPERATION_SAVE:
4633 if (result < 0) {
4634 SaveMenu.key_no = SAVE_KEY_ALERT;
4635 SaveMenu.alert_no = SAVE_ALERT_SAVE_FAILED;
4636 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4637 }
4638
4639 break;
4640 case MC_OPERATION_LOAD:
4641 if (result < 0) {
4642 SaveMenu.key_no = SAVE_KEY_ALERT;
4643 SaveMenu.alert_no = SAVE_ALERT_LOAD_FAILED;
4644 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4645 }
4646
4647 break;
4648 case MC_OPERATION_GET_DIR:
4649 last_error->code = MC_ERROR_NONE;
4650 case MC_OPERATION_GET_ALL_SAVE_FILE_INFO:
4651 if (result < 0) {
4652 SaveMenu.key_no = SAVE_KEY_ALERT;
4653 SaveMenu.alert_no = SAVE_ALERT_CARD_ERROR;
4654 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4655 break;
4656 }
4657
4658 switch (last_error->code) {
4659 case MC_ERROR_NONE:
4660 break;
4661 case MC_ERROR_VERSION:
4662 SaveMenu.return_key_no = SaveMenu.key_no;
4663 SaveMenu.key_no = SAVE_KEY_DIF_VERSION;
4664 McAccess.SetFuncNo(MC_OPERATION_IDLE);
4665 break;
4666 case MC_ERROR_UNK_2:
4667 case MC_ERROR_SHORT_READ:
4668 break;
4669 case MC_ERROR_FULL:
4670 SaveMenu.key_no = SAVE_KEY_ALERT;
4671 SaveMenu.alert_no = SAVE_ALERT_CARD_FULL;
4672 break;
4673 }
4674
4675 break;
4676 }
4677 } else {
4678 switch (prev_func_no) {
4679 case MC_OPERATION_GET_ALL_SAVE_FILE_INFO:
4680 break;
4681 case MC_OPERATION_LOAD:
4682 switch (SaveMenu.mode) {
4683 case SAVE_MENU_MODE_LOAD:
4684 SaveMenu.key_no = SAVE_KEY_FADE_OUT;
4685 SaveMenu.loaded = true;
4686 McAccess.DmySync();
4687 break;
4688 case SAVE_MENU_MODE_SAVE:
4689 EditLoad();
4690 break;
4691 case SAVE_MENU_MODE_ENDING:
4692 break;
4693 }
4694
4695 break;
4696 case MC_OPERATION_DELETE:
4697 error = &McAccess.error;
4698
4699 switch (error->code) {
4700 case MC_ERROR_VERSION:
4701 McAccess.SetFuncNo(MC_OPERATION_GET_ALL_SAVE_FILE_INFO);
4702 McAccess.step = error->step;
4703
4704 if (SaveMenu.return_key_no >= 0) {
4705 SaveMenu.key_no = SaveMenu.return_key_no;
4706 }
4707
4708 if (McAccess.step > 49) {
4709 McAccess.step = 0;
4710 }
4711
4712 error->code = MC_ERROR_NONE;
4713 error->retry_count = 0;
4714 break;
4715 case MC_ERROR_NONE:
4716 McAccess.SetFuncNo(MC_OPERATION_GET_ALL_SAVE_FILE_INFO);
4717 break;
4718 }
4719
4720 break;
4721 case MC_OPERATION_SAVE:
4722 ComMenuSePlay(SE_SAVE_START);
4723 McAccess.SetFuncNo(MC_OPERATION_GET_ALL_SAVE_FILE_INFO);
4724 break;
4725 }
4726 }
4727
4728 switch (McAccess.GetFuncNo()) {
4729 case MC_OPERATION_IDLE:
4730 SaveMenuFunc[SaveMenu.key_no]();
4731
4732#ifdef PAL
4733 // Debug shortcuts that jump the card access to one of its steps.
4734 if (DebugMode) {
4735 if (GamePad.Down2(PAD_R1)) {
4736 McAccess.SetFuncNo(MC_OPERATION_UNFORMAT);
4737 ComMenuSePlay(MENU_SOUND_CONFIRM);
4738 }
4739
4740 if (GamePad.Down2(PAD_TRIANGLE)) {
4741 McAccess.SetFuncNo(MC_OPERATION_FORMAT);
4742 ComMenuSePlay(MENU_SOUND_CONFIRM);
4743 }
4744
4745 if (GamePad.Down2(PAD_CROSS)) {
4746 McAccess.SetFuncNo(MC_OPERATION_WRITE_TEST);
4747 ComMenuSePlay(MENU_SOUND_CONFIRM);
4748 McAccess.Step();
4749 }
4750
4751 if (GamePad.Down2(PAD_L3)) {
4752 McAccess.SetFuncNo(MC_OPERATION_CONVERT);
4753 ComMenuSePlay(MENU_SOUND_CONFIRM);
4754 McAccess.Step();
4755 }
4756 }
4757
4758#endif
4759 break;
4760 }
4761
4762 msg_no = GetSaveMenuMsgNo();
4763
4764 if (CommonMenuMes2.mes_made != msg_no) {
4765 mes_value = SaveMenu.file_no + 1;
4766
4767 switch (msg_no - 250) {
4768 case 3:
4769 case 6:
4770 case 7:
4771 case 17:
4772 case 29:
4773 case 30:
4774 mes_value = McAccess.port + 1;
4775 break;
4776 }
4777
4778 CommonMenuMes2.value = mes_value;
4779
4780 if (msg_no == 299) {
4781 CommonMenuMes2.value = McAccess.error.file_no;
4782 }
4783
4784 printf("msgno = %d\n", msg_no);
4785 CommonMenuMes2.MakeMesWin(msg_no);
4786 }
4787
4788 return SaveMenu.result;
4789}
4790
4791void DrawMenuSave(char *frame_name) {
4792 if (SaveMenu.texture_ready == 0) {
4793 return;
4794 }
4795
4796 setbilinear(0);
4797
4798 switch (SaveMenu.mode) {
4799 case SAVE_MENU_MODE_LOAD:
4800 case SAVE_MENU_MODE_SAVE:
4801 break;
4802 case SAVE_MENU_MODE_ENDING:
4803 AllFillBoxForMenu(0, 0, 0, 0x80);
4804 break;
4805 }
4806
4807 int alpha = 0x80;
4808
4809 switch (SaveMenu.key_no) {
4810 case SAVE_KEY_FADE_IN:
4811 alpha = SaveMenu.step_time * 6;
4812
4813 if (alpha > 0x80) {
4814 alpha = 0x80;
4815 }
4816
4817 break;
4818 case SAVE_KEY_FADE_OUT:
4819 alpha = 0x80 - SaveMenu.step_time * 4;
4820
4821 if (alpha < 0) {
4822 alpha = 0;
4823 }
4824
4825 break;
4826 }
4827
4828 MenuTextureReload(SaveMenu.block_no);
4829 float y = 150.0f - 150.0f * SaveMenu.file_no;
4830 SaveMenu.board_y += (y - SaveMenu.board_y) / 4.0f;
4831 y = SaveMenu.board_y;
4832 float board_x = 140.0f;
4833 int bright = 0x80;
4834
4835 switch (SaveMenu.key_no) {
4836 case SAVE_KEY_SAVE_DECIDE:
4837 case SAVE_KEY_LOAD_DECIDE:
4838 case SAVE_KEY_LOAD:
4839 case SAVE_KEY_ALERT:
4840 case SAVE_KEY_FORMAT:
4841 case SAVE_KEY_DIF_VERSION:
4842 bright = 0x40;
4843 break;
4844 }
4845
4846 int show = 0;
4847
4848 switch (SaveMenu.key_no) {
4849 case SAVE_KEY_FILE_SELECT:
4850 case SAVE_KEY_SAVE_CHECK:
4851 case SAVE_KEY_SAVE_DECIDE:
4852 case SAVE_KEY_LOAD_DECIDE:
4853 case SAVE_KEY_LOAD:
4854 show = 1;
4855 break;
4856 }
4857
4858 if (SaveMenu.key_no == SAVE_KEY_FADE_OUT && SaveMenu.mode == SAVE_MENU_MODE_LOAD && SaveMenu.loaded != 0) {
4859 show = 1;
4860 }
4861
4862 if (show != 0 && (unsigned int) (McAccess.GetFuncNo() - MC_OPERATION_GET_ALL_SAVE_FILE_INFO) > 1U) {
4863 MC_CARD_INFO *cards = McAccess.card;
4864
4865 if (cards != NULL) {
4866 for (int i = 0; i < 12; i++) {
4867 SAVEDATA_INFO *file = &McAccess.file_info[i];
4868
4869 if (file != NULL) {
4870 if (file->state == 0) {
4871 DrawNewFileTemplete((int) board_x, (int) y, alpha);
4872 } else {
4873 DrawSaveBoard(file, SaveMenuMojiTextbl, (int) board_x, (int) y, bright, alpha);
4874 }
4875
4876 y += 150.0f;
4877 }
4878 }
4879 } else {
4880 printf("mcinfo is NULL\n");
4881 }
4882 }
4883
4884 float text_pos[2] = {-20.0f, -20.0f};
4885 CommonMenuMes2.auto_pos = MES_POS_NONE;
4886
4887 switch (McAccess.GetFuncNo()) {
4888 case MC_OPERATION_IDLE:
4889 switch (SaveMenu.key_no) {
4890 case SAVE_KEY_MODE_SELECT:
4891 text_pos[0] = 240.0f;
4892 text_pos[1] = 154.0f;
4893 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4894 break;
4895 case SAVE_KEY_NEW_DIR:
4896 case SAVE_KEY_NEW_DIR_SELECT:
4897 case SAVE_KEY_MC_SELECT:
4898 case SAVE_KEY_FORMAT:
4899 text_pos[0] = 184.0f;
4900 text_pos[1] = 152.0f;
4901 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4902 break;
4903 case SAVE_KEY_SAVE_DECIDE:
4904 case SAVE_KEY_LOAD_DECIDE:
4905 text_pos[0] = 246.0f;
4906 text_pos[1] = 156.0f;
4907 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4908 break;
4909 case SAVE_KEY_DIF_VERSION:
4910 text_pos[0] = 196.0f;
4911 text_pos[1] = 140.0f;
4912 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4913 break;
4914 case SAVE_KEY_ALERT:
4915 text_pos[0] = 230.0f;
4916 text_pos[1] = 140.0f;
4917 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4918 case SAVE_KEY_AFTER_ENDING:
4919 text_pos[0] = 196.0f;
4920 text_pos[1] = 140.0f;
4921 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4922 case SAVE_KEY_END_SAVE_ENDING:
4923 case SAVE_KEY_END_SAVE:
4924 text_pos[0] = 196.0f;
4925 text_pos[1] = 140.0f;
4926 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4927 break;
4928 }
4929
4930 break;
4931 case MC_OPERATION_DELETE:
4932 text_pos[0] = 216.0f;
4933 text_pos[1] = 180.0f;
4934 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4935 break;
4936 default:
4937 text_pos[0] = 184.0f;
4938 text_pos[1] = 152.0f;
4939 CommonMenuMes2.auto_pos = MES_POS_CENTRE;
4940 break;
4941 }
4942
4943 MenuTextureReload(CommonMenuMes2.tex_block);
4944 CommonMenuMes2.edge_alpha = alpha;
4945
4946 if (CommonMenuMes2.edge_alpha > 0x80) {
4947 CommonMenuMes2.edge_alpha = 0x80;
4948 }
4949
4950 if (CommonMenuMes2.edge_alpha < 0) {
4951 CommonMenuMes2.edge_alpha = 0;
4952 }
4953
4954 DrawMenuClsMes(&CommonMenuMes2, (int) text_pos[0], (int) text_pos[1]);
4955 int hand_x = -1;
4956 int hand_y = -1;
4957 CommonMenuMes2.cursor_row = -1;
4958
4959 switch (SaveMenu.key_no) {
4960 case SAVE_KEY_MODE_SELECT:
4961 case SAVE_KEY_MC_SELECT:
4962 CommonMenuMes2.cursor_row = SaveMenu.file_no + 2;
4963 break;
4964 case SAVE_KEY_FILE_SELECT:
4965 if (McAccess.GetFuncNo() != MC_OPERATION_GET_ALL_SAVE_FILE_INFO && McAccess.GetFuncNo() != MC_OPERATION_SAVE) {
4966 hand_x = 0x78;
4967 hand_y = 0xBC;
4968 }
4969
4970 break;
4971 }
4972
4973 if (0 < hand_x && 0 < hand_y) {
4974 static int ct = 0;
4975 RECT hand = {0x160, 0xD6, 0x20, 0x20};
4976 float draw_x = (float) hand_x + 7.0f * cosf(0.0805536583f * ct);
4977 float draw_y = (float) hand_y + 5.0f * sinf(0.116355285f * ct);
4978 CRect_i_ source(0x160, 0xD6, 0x20, 0x20);
4979 DrawMenu2DSprite(SaveBoard, CRect_i_((int) (5.0f + draw_x), (int) (3.0f + draw_y), hand.width, hand.height), source, 0, 0, 0, alpha);
4980 DrawMenu2DSprite(SaveBoard, CRect_i_((int) draw_x, (int) draw_y, hand.width, hand.height), source, alpha);
4981 ct++;
4982
4983 if (!((float) ct < 105299.0f)) {
4984 ct = 0;
4985 }
4986 }
4987
4988 switch (SaveMenu.key_no) {
4989 case SAVE_KEY_FADE_OUT:
4990 case SAVE_KEY_MC_SELECT:
4991 case SAVE_KEY_FADE_IN:
4992 SaveMenu.step_time++;
4993 break;
4994 default:
4995 SaveMenu.step_time = 0;
4996 break;
4997 }
4998
4999 switch (SaveMenu.mode) {
5000 case SAVE_MENU_MODE_LOAD:
5001 DrawMenu2DSprite(SaveBoard, CRect_i_(0x46, 0x32, 0x3A, 0x27), CRect_i_(0x110, 0xD8, 0x3A, 0x28), alpha);
5002#ifdef PAL
5003 DrawMenu2DSprite(SaveBoard, CRect_i_(0x86, 0x37, 0x50, 0x1E), CRect_i_(0x110, 0x100, 0x50, 0x1E), alpha);
5004#else
5005 DrawMenu2DSprite(SaveBoard, CRect_i_(0x86, 0x37, 0x4A, 0x1E), CRect_i_(0x110, 0x100, 0x4A, 0x1E), alpha);
5006#endif
5007 return;
5008 case SAVE_MENU_MODE_ENDING:
5009 DrawMainMenuIcon(0x46, 0x32, 5, 1, 0x80, alpha);
5010 break;
5011 }
5012}
5013
5014static int SaveMenuKeyFadeIn() {
5015 if (SaveMenu.step_time > 14) {
5016 SaveMenu.key_no = SAVE_KEY_FILE_SELECT;
5017 SaveMenu.step_time = 0;
5018 }
5019
5020 return 1;
5021}
5022
5023static int SaveMenuKeyFadeOut() {
5024 if (SaveMenu.step_time > 32) {
5025 ExitSaveSelect();
5026
5027 if (SaveMenu.loaded) {
5028 SaveMenu.result = MENU_SAVE_LOADED;
5029 } else {
5030 SaveMenu.result = MENU_SAVE_CLOSED;
5031 }
5032 }
5033
5034 return 1;
5035}
5036
5037static int SaveMenuKeyModeSelect() {
5038 if (GamePad.Down(PAD_UP | PAD_DOWN)) {
5039 if (SaveMenu.file_no) {
5040 SaveMenu.file_no = 0;
5041 } else {
5042 SaveMenu.file_no = 1;
5043 }
5044 }
5045
5046 if (GamePad.Down(PAD_CROSS)) {
5047 if (SaveMenu.file_no) {
5048 SaveMenu.access_kind = SAVE_ACCESS_LOAD;
5049 } else {
5050 SaveMenu.access_kind = SAVE_ACCESS_SAVE;
5051 }
5052
5053 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
5054 SaveMenu.file_no = 0;
5055 ComMenuSePlay(MENU_SOUND_CONFIRM);
5056 return 1;
5057 }
5058
5059 if (GamePad.Down(PAD_CIRCLE)) {
5060 SaveMenu.key_no = SAVE_KEY_FADE_OUT;
5061 ExitSaveSelect();
5062 SaveMenu.step_time = 0;
5063 ComMenuSePlay(MENU_SOUND_REFUSE);
5064 return 1;
5065 }
5066
5067 return 1;
5068}
5069
5070static int SaveMenuKeyMcSelect() {
5071 int prev_slot;
5072
5073 prev_slot = SaveMenu.file_no;
5074
5075 if (GamePad.Down(PAD_UP | PAD_DOWN)) {
5076 if (SaveMenu.file_no) {
5077 SaveMenu.file_no = 0;
5078 } else {
5079 SaveMenu.file_no = 1;
5080 }
5081 }
5082
5083 if (prev_slot != SaveMenu.file_no) {
5084 ComMenuSePlay(MENU_SOUND_CURSOR);
5085 }
5086
5087 if (GamePad.Down(PAD_CIRCLE)) {
5088 switch (SaveMenu.mode) {
5089 case SAVE_MENU_MODE_LOAD:
5090 SaveMenu.key_no = SAVE_KEY_FADE_OUT;
5091 ExitSaveSelect();
5092 break;
5093 case SAVE_MENU_MODE_SAVE:
5094 SaveMenu.key_no = SAVE_KEY_FADE_OUT;
5095 CommonMenuMes2.stay_frame = false;
5096 break;
5097 case SAVE_MENU_MODE_ENDING:
5098 SaveMenu.key_no = SAVE_KEY_FADE_OUT;
5099 ExitSaveSelect();
5100 break;
5101 }
5102
5103 SaveMenu.step_time = 0;
5104 ComMenuSePlay(MENU_SOUND_REFUSE);
5105 return 1;
5106 }
5107
5108 if (GamePad.Down(PAD_CROSS) && SaveMenu.texture_ready) {
5109 SaveMenu.key_no = SAVE_KEY_CHECK_MC_TYPE;
5110 McAccess.port = SaveMenu.file_no;
5111 McAccess.SetFuncNo(MC_OPERATION_SEARCH_TYPE);
5112 ComMenuSePlay(MENU_SOUND_CONFIRM);
5113 return 1;
5114 }
5115
5116 if (GamePad.Down2(PAD_CROSS) && GamePad.Down2(PAD_CIRCLE)) {
5117 SaveMenu.key_no = SAVE_KEY_UNFORMAT;
5118 McAccess.SetFuncNo(MC_OPERATION_UNFORMAT);
5119 McAccess.port = SaveMenu.file_no;
5120 ComMenuSePlay(MENU_SOUND_CONFIRM);
5121 }
5122
5123 return 1;
5124}
5125
5126static int SaveMenuKeyCheckMcType() {
5127 MC_CARD_INFO *card;
5128
5129 card = &McAccess.card[McAccess.port];
5130
5131 if (card->present) {
5132 switch (card->type) {
5133 case sceMcTypePS2:
5134 McAccess.SetFuncNo(MC_OPERATION_GET_DIR);
5135 SaveMenu.key_no = SAVE_KEY_CHECK_MC;
5136 break;
5137 default:
5138 SaveMenu.key_no = SAVE_KEY_ALERT;
5139 SaveMenu.alert_no = SAVE_ALERT_NO_CARD;
5140 break;
5141 }
5142 } else {
5143 SaveMenu.key_no = SAVE_KEY_ALERT;
5144 SaveMenu.alert_no = SAVE_ALERT_NO_CARD;
5145 }
5146
5147 return 1;
5148}
5149
5150static int SaveMenuKeyCheckMc() {
5151 MC_CARD_INFO *card;
5152
5153 printf("check end !!\n");
5154 card = &McAccess.card[McAccess.port];
5155 SaveMenu.alert_no = SAVE_ALERT_NONE;
5156
5157 if (card->present == 0) {
5158 printf("not \n");
5159 SaveMenu.alert_no = SAVE_ALERT_CARD_MISSING;
5160 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
5161 SaveMenu.file_no = McAccess.port;
5162 return 0;
5163 }
5164
5165 if (card->type != sceMcTypePS2) {
5166 printf("type is not PS2\n");
5167 SaveMenu.alert_no = SAVE_ALERT_CARD_MISSING;
5168 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
5169 SaveMenu.file_no = McAccess.port;
5170 return 0;
5171 }
5172
5173 if ((SaveMenu.access_kind == SAVE_ACCESS_LOAD || SaveMenu.mode == SAVE_MENU_MODE_ENDING) && (card->dir_exists == 0 || card->formatted == 0)) {
5174 SaveMenu.alert_no = SAVE_ALERT_NO_SAVE_DATA;
5175 SaveMenu.key_no = SAVE_KEY_ALERT;
5176 return 1;
5177 }
5178
5179 if (SaveMenu.access_kind == SAVE_ACCESS_SAVE && card->dir_exists == 0 && card->free_size < 400 && card->formatted != 0) {
5180 SaveMenu.alert_no = SAVE_ALERT_NO_SPACE_DIR;
5181 SaveMenu.key_no = SAVE_KEY_ALERT;
5182 return 1;
5183 }
5184
5185 if (SaveMenu.mode == SAVE_MENU_MODE_ENDING) {
5186 SaveMenu.key_no = SAVE_KEY_SAVE_ENDING;
5187 } else if (SaveMenu.access_kind == SAVE_ACCESS_LOAD) {
5188 SaveMenu.key_no = SAVE_KEY_LOAD_CONFIG;
5189 McAccess.SetFuncNo(MC_OPERATION_LOAD_CONFIG);
5190 } else {
5191 McAccess.SetFuncNo(MC_OPERATION_GET_ALL_SAVE_FILE_INFO);
5192 SaveMenu.key_no = SAVE_KEY_FILE_SELECT;
5193 SaveMenu.file_no = ((s32 *) SaveData->GetConfigData())[17];
5194 }
5195
5196 return 1;
5197}
5198
5199static int SaveMenuKeyLoadConfig() {
5200 McAccess.SetFuncNo(MC_OPERATION_GET_ALL_SAVE_FILE_INFO);
5201 SaveMenu.key_no = SAVE_KEY_FILE_SELECT;
5202
5203 if (*(s32 *) &((SV_CONFIG_SYS *) SaveData->GetConfigData())->game_clear_area[2] != 0) {
5204 GameClearFlag = 1;
5205 }
5206
5207 SaveMenu.file_no = ((s32 *) SaveData->GetConfigData())[17];
5208 return 1;
5209}
5210
5211static int SaveMenuKeyFileSelect() {
5212 int prev_file;
5213 SAVEDATA_INFO *info;
5214
5215 prev_file = SaveMenu.file_no;
5216
5217 if (GamePad.Down(PAD_DOWN)) {
5218 SaveMenu.file_no++;
5219
5220 if (SaveMenu.file_no >= 12) {
5221 SaveMenu.file_no--;
5222 }
5223 }
5224
5225 if (GamePad.Down(PAD_UP) && 0 < SaveMenu.file_no) {
5226 SaveMenu.file_no--;
5227 }
5228
5229 if (prev_file != SaveMenu.file_no) {
5230 ComMenuSePlay(MENU_SOUND_CURSOR);
5231 }
5232
5233 if (GamePad.Down(PAD_CIRCLE)) {
5234 SaveMenu.key_no = SAVE_KEY_MC_SELECT;
5235 SaveMenu.file_no = McAccess.port;
5236 SaveMenu.step_time = 0;
5237 ComMenuSePlay(MENU_SOUND_REFUSE);
5238 return 1;
5239 }
5240
5241 if (GamePad.Down(PAD_CROSS)) {
5242 switch (SaveMenu.access_kind) {
5243 case SAVE_ACCESS_SAVE:
5244 SaveMenu.key_no = SAVE_KEY_SAVE_CHECK;
5245 McAccess.SetFuncNo(MC_OPERATION_SEARCH_TYPE);
5246 break;
5247 case SAVE_ACCESS_LOAD:
5248 info = &McAccess.file_info[SaveMenu.file_no];
5249
5250 if (info->state) {
5251 SaveMenu.key_no = SAVE_KEY_LOAD_DECIDE;
5252 } else {
5253 ComMenuSePlay(MENU_SOUND_REFUSE);
5254 }
5255
5256 break;
5257 }
5258
5259 ComMenuSePlay(MENU_SOUND_CONFIRM);
5260 return 1;
5261 }
5262
5263 return 1;
5264}
void Save(int georama_no, CSaveData *save_data)
int GetNextParts(int index)
int GetNextPartsNum(int index)
int CheckComplete(int index)
EDITPARTS_INFO * GetPartsInfo(int index)
void Load(int georama_no, CSaveData *save_data, int load_requests)
int Down2(int mask)
Definition gamepad.cpp:601
int Down(int mask)
Definition gamepad.cpp:583
void MenuModeOff()
Definition gamepad.cpp:617
void MenuModeOn(int threshold)
Definition gamepad.cpp:613
void SetAutoRepeat(int mask, int initial_delay, int repeat_delay)
Definition gamepad.cpp:485
void AutoRepeatOff()
Definition gamepad.cpp:609
void SetFuncNo(int func_no)
SAVEDATA_INFO file_info[MC_SAVE_FILE_MAX]
MC_CARD_INFO card[MC_CARD_MAX]
s16 mode[10]
Definition savedata.hpp:22
void InitPos()
Definition savedata.cpp:610
s16 pos[10]
Definition savedata.hpp:21
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
SV_GRD_NPC * GetGrdNPCData(int map_no, int npc_no)
Definition savedata.cpp:215
CMenuCursor * GetMenuCursor()
Definition savedata.cpp:37
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
s16 * GetElemData(int georama_no)
Definition savedata.cpp:242
void * GetConfigData()
Definition savedata.cpp:33
int GetGameIntFlag(int flag_no)
Definition savedata.cpp:310
void SetStereoMode(int mode)
Definition sound.cpp:987
short block
Definition texture.hpp:52
char name[32]
Definition texture.hpp:56
u_long tex0
Definition texture.hpp:57
s32 auto_pos
Definition clsmes.hpp:172
s32 text_y
Definition clsmes.hpp:152
s32 text_x
Definition clsmes.hpp:151
short * buff
Definition clsmes.hpp:229
void DrawMesWin()
Definition clsmes.cpp:2619
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
s32 narrow_gaiji_set
Definition clsmes.hpp:214
s32 end_mark
Definition clsmes.hpp:210
s32 char_width
Definition clsmes.hpp:153
s32 value
Definition clsmes.hpp:218
s32 cursor_lit
Definition clsmes.hpp:226
s32 narrow_gaiji
Definition clsmes.hpp:215
void * tex_buff
Definition clsmes.hpp:233
s32 cursor_row
Definition clsmes.hpp:224
void SetBuff(short *buff)
Definition clsmes.cpp:456
s32 mes_made
Definition clsmes.hpp:207
s32 values[8]
Definition clsmes.hpp:217
short * GetTextLineDataTop_system(int line)
Definition clsmes.cpp:1252
s32 style
Definition clsmes.hpp:208
s32 tex_block
Definition clsmes.hpp:227
s32 value_signed
Definition clsmes.hpp:219
s32 stay_frame
Definition clsmes.hpp:189
s32 edge_alpha
Definition clsmes.hpp:213
MES_LINE_POS line_pos[10]
Definition clsmes.hpp:228
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
s32 value_show
Definition clsmes.hpp:220
void Preset(int style)
Definition clsmes.cpp:468
s32 rows
Definition clsmes.hpp:156
u_long128 * buffer
Definition dataread.hpp:29
EDITPARTS_ELEMENT elements[6]
EDIT_CHIP_ATTACH_DATA elements[6]
PERSONAL_BOARD board
Definition memcard.hpp:157
s16 * prev_mes_buff
Definition memcard.hpp:170
s32 prev_flag[12]
Definition memcard.cpp:64
IHAVEITEM held_item
Definition title.cpp:61
s32 width
Definition rect.hpp:36
s32 height
Definition rect.hpp:37
int y
Definition title.cpp:63
int x
Definition title.cpp:62
s32 talk_message
Definition savedata.hpp:89
u8 b
Definition rect.hpp:48
u8 g
Definition rect.hpp:47
u8 a
Definition rect.hpp:49
u8 r
Definition rect.hpp:46