From f5a2d0e57fc609ac5d453e81fdc8b3789f3b6f3c Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Sun, 24 Dec 2023 10:58:59 -0500 Subject: [PATCH] Implement & link m_choice.c --- config/assets.yml | 5 + config/rel_slices.yml | 5 + include/m_choice.h | 72 ++-- include/m_msg.h | 149 ++++---- src/m_choice.c | 121 +++++++ src/m_choice_draw.c_inc | 168 +++++++++ src/m_choice_main.c_inc | 583 ++++++++++++++++++++++++++++++ src/m_choice_main_appear.c_inc | 48 +++ src/m_choice_main_disappear.c_inc | 56 +++ src/m_choice_main_hide.c_inc | 7 + src/m_choice_main_normal.c_inc | 162 +++++++++ src/m_choice_sound.c_inc | 19 + 12 files changed, 1303 insertions(+), 92 deletions(-) create mode 100644 src/m_choice.c create mode 100644 src/m_choice_draw.c_inc create mode 100644 src/m_choice_main.c_inc create mode 100644 src/m_choice_main_appear.c_inc create mode 100644 src/m_choice_main_disappear.c_inc create mode 100644 src/m_choice_main_hide.c_inc create mode 100644 src/m_choice_main_normal.c_inc create mode 100644 src/m_choice_sound.c_inc diff --git a/config/assets.yml b/config/assets.yml index e4843890..cc8d6a49 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -142,6 +142,11 @@ config/dol.yml: addrs: [0x800ab260, 0x800af3c0] config/rel.yml: + con_waku_swaku3_tex: # m_choice + addrs: [0x8064F880, 0x80650880] + con_sentaku2_v: + addrs: [0x80650880, 0x806508C0] + type: vtx wipe1_v: addrs: [0x80652AD0, 0x80652C60] type: vtx diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 58dfe84e..c97f4f07 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -51,6 +51,11 @@ m_camera2.c: .text: [0x8037DA54, 0x8038344C] .rodata: [0x80641438, 0x80641828] .data: [0x8064F818, 0x8064F860] +m_choice.c: + .text: [0x8038344C, 0x80385404] + .rodata: [0x80641828, 0x80641A90] + .data: [0x8064F860, 0x80650960] + .bss: [0x812633A0, 0x81263410] m_cockroach.c: .text: [0x80385430, 0x80385A80] m_collision_obj.c: diff --git a/include/m_choice.h b/include/m_choice.h index a70f0ab0..3d29970c 100644 --- a/include/m_choice.h +++ b/include/m_choice.h @@ -9,6 +9,7 @@ extern "C" { #endif #define mChoice_CHOICE_STRING_LEN 16 +#define mChoice_SELECT_STR_NUM 607 typedef struct choice_s mChoice_c; typedef struct choice_data_s mChoice_Data_c; @@ -54,58 +55,71 @@ struct choice_data_s { struct choice_s { /* Current XY position (centered) */ - f32 center_x; - f32 center_y; + /* 0x00 */ f32 center_x; + /* 0x04 */ f32 center_y; /* Initial XY position */ - f32 center_x_begin; - f32 center_y_begin; + /* 0x08 */ f32 center_x_begin; + /* 0x0C */ f32 center_y_begin; /* Target XY position */ - f32 center_x_target; - f32 center_y_target; + /* 0x10 */ f32 center_x_target; + /* 0x14 */ f32 center_y_target; /* Text settings */ - rgba_t text_color; - f32 text_scale_x; - f32 text_scale_y; - f32 text_x; - f32 text_y; + /* 0x18 */ rgba_t text_color; + /* 0x1C */ f32 text_scale_x; + /* 0x20 */ f32 text_scale_y; + /* 0x24 */ f32 text_x; + /* 0x28 */ f32 text_y; /* Window scaling XY */ - f32 scale_x; - f32 scale_y; + /* 0x2C */ f32 scale_x; + /* 0x30 */ f32 scale_y; /* Text related data */ - mChoice_Data_c data; + /* 0x34 */ mChoice_Data_c data; - int selected_choice_idx; - rgba_t selected_choice_text_color; + /* 0xC8 */ int selected_choice_idx; + /* 0xCC */ rgba_t selected_choice_text_color; - rgba_t background_color; + /* 0xD0 */ rgba_t background_color; - f32 _D4; - f32 _D8; + /* 0xD4 */ f32 _D4; + /* 0xD8 */ f32 _D8; - f32 scale; // total choice window scaling percentage + /* 0xDC */ f32 scale; // total choice window scaling percentage - int main_index; - int requested_main_index; + /* 0xE0 */ int main_index; + /* 0xE4 */ int requested_main_index; - int window_visible_flag; - int font_visible_flag; + /* 0xE8 */ int window_visible_flag; + /* 0xEC */ int font_visible_flag; - int choice_automove_type; - f32 choice_automove_timer; + /* 0xF0 */ int choice_automove_type; + /* 0xF4 */ f32 choice_automove_timer; - f32 timer; + /* 0xF8 */ f32 timer; - u8 no_b_flag; // can't press B to select last option - u8 no_close_flag; // pressing B won't auto-cancel the choice selection? + /* 0xFC */ u8 no_b_flag; // can't press B to select last option + /* 0xFD */ u8 no_close_flag; // pressing B won't auto-cancel the choice selection? }; +extern void mChoice_Main(mChoice_c* choice, GAME* game); +extern void mChoice_Draw(mChoice_c* choice, GAME* game, int mode); +extern void mChoice_aram_init(); +extern void mChoice_ct(mChoice_c* choice, GAME* game); +extern void mChoice_dt(mChoice_c* choice, GAME* game); extern mChoice_c* mChoice_Get_base_window_p(); +extern void mChoice_Change_request_main_index(mChoice_c* choice, int request_main_index); +extern int mChoice_check_main_index(mChoice_c* choice); +extern int mChoice_check_main_normal(mChoice_c* choice); +extern void mChoice_Set_choice_data( mChoice_c* choice, u8* str0, int str0_len, u8* str1, int str1_len, u8* str2, int str2_len, u8* str3, int str3_len, u8* str4, int str4_len, u8* str5, int str5_len); extern int mChoice_Get_ChoseNum(mChoice_c* choice); +extern void mChoice_Clear_ChoseNum(mChoice_c* choice); +extern void mChoice_Load_ChoseStringFromRom(mChoice_c* choice, u8* str, int str_no, ACTOR* actor); +extern void mChoice_no_b_set(mChoice_c* choice); +extern void mChoice_no_b_close_set(mChoice_c* choice); #ifdef __cplusplus } diff --git a/include/m_msg.h b/include/m_msg.h index 31948de9..9c172d23 100644 --- a/include/m_msg.h +++ b/include/m_msg.h @@ -4,6 +4,7 @@ #include "types.h" #include "libu64/gfxprint.h" #include "m_choice.h" +#include "m_item_name.h" #ifdef __cplusplus extern "C" { @@ -67,6 +68,9 @@ enum { mMsg_MAIL_STR_NUM }; +#define mMsg_STATUS_FLAG_ZOOMDOWN_LONG (1 << 11) /* When set, mMsg_sound_ZOOMDOWN_SHORT() sfx will not play */ +#define mMsg_STATUS_FLAG_USE_AM (1 << 17) /* 'AM' when set, 'PM' when not set */ + typedef struct message_window_s mMsg_Window_c; typedef struct message_data_s mMsg_Data_c; @@ -144,88 +148,89 @@ struct message_data_s { }; struct message_window_s { - int data_loaded; - int msg_no; - int _008; - mMsg_Data_c* msg_data; - f32 center_x; - f32 center_y; - f32 width; - f32 height; + /* 0x000 */ int data_loaded; + /* 0x004 */ int msg_no; + /* 0x008 */ int _008; + /* 0x00C */ mMsg_Data_c* msg_data; + /* 0x010 */ f32 center_x; + /* 0x014 */ f32 center_y; + /* 0x018 */ f32 width; + /* 0x01C */ f32 height; - ACTOR* talk_actor; - int show_actor_name; - int actor_name_len; - int nameplate_x; - int nameplay_y; + /* 0x020 */ ACTOR* talk_actor; + /* 0x024 */ int show_actor_name; + /* 0x028 */ int actor_name_len; + /* 0x02C */ int nameplate_x; + /* 0x030 */ int nameplay_y; - int show_continue_button; + /* 0x034 */ int show_continue_button; - u8 free_str[mMsg_FREE_STR_NUM][mMsg_FREE_STRING_LEN]; - int free_str_article[mMsg_FREE_STR_NUM]; + /* 0x038 */ u8 free_str[mMsg_FREE_STR_NUM][mMsg_FREE_STRING_LEN]; + /* 0x178 */ int free_str_article[mMsg_FREE_STR_NUM]; - u8 item_str[mMsg_ITEM_STR_NUM][mMsg_FREE_STRING_LEN]; - int item_str_article[mMsg_ITEM_STR_NUM]; + /* 0x1C8 */ u8 item_str[mMsg_ITEM_STR_NUM][mMsg_FREE_STRING_LEN]; + /* 0x218 */ int item_str_article[mMsg_ITEM_STR_NUM]; - u8 mail_str[mMsg_MAIL_STR_NUM][mMsg_MAIL_STRING_LEN]; + /* 0x22C */ u8 mail_str[mMsg_MAIL_STR_NUM][mMsg_MAIL_STRING_LEN]; - rgba_t name_text_color; - rgba_t name_background_color; + /* 0x2B0 */ rgba_t name_text_color; + /* 0x2B4 */ rgba_t name_background_color; - rgba_t window_background_color; - rgba_t font_color[4]; + /* 0x2B8 */ rgba_t window_background_color; + /* 0x2BC */ rgba_t font_color[4]; - rgba_t continue_button_color; + /* 0x2CC */ rgba_t continue_button_color; - f32 font_scale_x; - f32 font_scale_y; + /* 0x2D0 */ f32 font_scale_x; + /* 0x2D4 */ f32 font_scale_y; - int _2D8; - int _2DC; + /* 0x2D8 */ int _2D8; + /* 0x2DC */ int _2DC; - int text_lines; - int current_line; + /* 0x2E0 */ int text_lines; + /* 0x2E4 */ int current_line; - mChoice_c choice_window; + /* 0x2E8 */ mChoice_c choice_window; - int _3E8; + /* 0x3E8 */ int _3E8; - u16 end_timer; - s16 animal_voice_idx; - int voice_sfx_idx; - u8 voice_idx; - u8 voice2_idx; - u8 voice3_idx; - s8 hide_choice_window_timer; - int spec; - u8 free_str_color_idx[4]; - u8 _404[8]; // unused? - u32 status_flags; + /* 0x3EC */ u16 end_timer; + /* 0x3EE */ s16 animal_voice_idx; + /* 0x3F0 */ int voice_sfx_idx; + /* 0x3F4 */ u8 voice_idx; + /* 0x3F5 */ u8 voice2_idx; + /* 0x3F6 */ u8 voice3_idx; + /* 0x3F7 */ s8 hide_choice_window_timer; + /* 0x3F8 */ u8 force_voice_enable_flag; + /* 0x3FC */ int spec; + /* 0x400 */ u8 free_str_color_idx[4]; + /* 0x408 */ u8 _404[8]; // unused? + /* 0x40C */ u32 status_flags; - f32 timer; - f32 cursor_timer; - f32 continue_button_timer; + /* 0x410 */ f32 timer; + /* 0x414 */ f32 cursor_timer; + /* 0x418 */ f32 continue_button_timer; - int start_text_cursor_idx; - int end_text_cursor_idx; - f32 window_scale; - f32 text_scale; + /* 0x41C */ int start_text_cursor_idx; + /* 0x420 */ int end_text_cursor_idx; + /* 0x424 */ f32 window_scale; + /* 0x428 */ f32 text_scale; - int requested_main_index; - int requested_priority; + /* 0x42C */ int requested_main_index; + /* 0x430 */ int requested_priority; - int main_index; - int draw_flag; - int cancel_flag; - int cancelable_flag; - int continue_msg_no; - int continue_cancel_flag; - int force_next; - int lock_continue; - s8 now_utter; + /* 0x434 */ int main_index; + /* 0x438 */ int draw_flag; + /* 0x43C */ int cancel_flag; + /* 0x440 */ int cancelable_flag; + /* 0x444 */ int continue_msg_no; + /* 0x448 */ int continue_cancel_flag; + /* 0x44C */ int force_next; + /* 0x450 */ int lock_continue; + /* 0x454 */ s8 now_utter; - mMsg_Main_Data_c main_data; - mMsg_Request_Data_c request_data; + /* 0x458 */ mMsg_Main_Data_c main_data; + /* 0x460 */ mMsg_Request_Data_c request_data; }; extern int mMsg_Get_Length_String(u8* buf, size_t buf_size); @@ -262,6 +267,24 @@ extern int mMsg_Check_main_hide(mMsg_Window_c* msg_win); extern int mMsg_sound_voice_get_for_editor(int code); extern int mMsg_sound_spec_change_voice(mMsg_Window_c* msg_win); extern void mMsg_request_main_forceoff(); +extern int mMsg_CopyPlayerName(u8* data, int idx, int max_size, int capitalize); +extern int mMsg_CopyTalkName(ACTOR* actor, u8* data, int idx, int max_size, int capitalize); +extern int mMsg_CopyTail(ACTOR* actor, u8* data, int idx, int max_size, int capitalize); +extern int mMsg_CopyYear(u8* data, int idx, int max_size); +extern int mMsg_CopyMonth(u8* data, int idx, int max_size); +extern int mMsg_CopyWeek(u8* data, int idx, int max_size); +extern int mMsg_CopyDay(u8* data, int idx, int max_size); +extern int mMsg_CopyHour(u8* data, int idx, int max_size); +extern int mMsg_CopyMin(u8* data, int idx, int max_size); +extern int mMsg_CopySec(u8* data, int idx, int max_size); +extern int mMsg_CopyFree(mMsg_Window_c* msg_win, int free_idx, u8* data, int idx, int max_size, int article, int capitalize); +extern int mMsg_CopyDetermination(mMsg_Window_c* msg_win, u8* data, int idx, int max_size); +extern int mMsg_CopyCountryName(u8* data, int idx, int max_size, int capitalize); +extern int mMsg_CopyRamdomNumber2(u8* data, int idx, int max_size); +extern int mMsg_CopyItem(mMsg_Window_c* msg_win, int item_idx, u8* data, int idx, int max_size, int article, int capitalize); +extern int mMsg_CopyMail(mMsg_Window_c* msg_win, int mail_idx, u8* data, int idx, int max_size); +extern int mMsg_CopyIslandName(u8* data, int idx, int max_size, int capitalize); +extern int mMsg_CopyAmPm(mMsg_Window_c* msg_win, u8* data, int idx, int max_size); #ifdef __cplusplus } diff --git a/src/m_choice.c b/src/m_choice.c new file mode 100644 index 00000000..ab0123b0 --- /dev/null +++ b/src/m_choice.c @@ -0,0 +1,121 @@ +#include "m_choice.h" + +#include "audio.h" +#include "jsyswrap.h" +#include "libultra/libultra.h" +#include "m_common_data.h" +#include "m_font.h" +#include "m_msg.h" +#include "sys_matrix.h" + +typedef void (*mChoice_MAIN_PROC)(mChoice_c*, GAME*); + +static void mChoice_MainSetup(mChoice_c* choice, GAME* game); + +static u32 Choice_table_rom_start = 0; +static u32 Choice_rom_start = 0; + +#ifdef MUST_MATCH +/* Force assetrip to detect these assets. They're used in a .c_inc file. */ +static u8 unused_con_waku_swaku3_tex[] = { + #ifndef __INTELLISENSE__ + #include "assets/con_waku_swaku3_tex.inc" + #endif +}; + +static Vtx unused_con_sentaku2_v[] = { + #ifndef __INTELLISENSE__ + #include "assets/con_sentaku2_v.inc" + #endif +}; +#endif + +static void mChoice_MainSetup_Hide(mChoice_c*, GAME*); +static void mChoice_MainSetup_Appear(mChoice_c*, GAME*); +static void mChoice_MainSetup_Normal(mChoice_c*, GAME*); +static void mChoice_MainSetup_Disappear(mChoice_c*, GAME*); + +static void mChoice_init(mChoice_c* choice, GAME* game); +static void mChoice_check_ct(mChoice_c* choice); +static void mChoice_SetMatrix(mChoice_c* choice, GAME* game, int type); +static void mChoice_SetMatrixDisplay(mChoice_c* choice, GAME* game, int type); +static void mChoice_UnSetMatrix(); +static void mChoice_UnSetMatrixDisplay(GAME* game, int type); +static void mChoice_DrawWindowBody(mChoice_c* choice, GAME* game, int type); +static void mChoice_DrawFont(mChoice_c* choice, GAME* game, int type); + +static void mChoice_Main_Hide(mChoice_c*, GAME*); +static void mChoice_Main_Appear(mChoice_c*, GAME*); +static void mChoice_Main_Normal(mChoice_c*, GAME*); +static void mChoice_Main_Disappear(mChoice_c*, GAME*); + +static void mChoice_MainSetup(mChoice_c* choice, GAME* game) { + static mChoice_MAIN_PROC proc[mChoice_MAIN_INDEX_NUM] = { + &mChoice_MainSetup_Hide, + &mChoice_MainSetup_Appear, + &mChoice_MainSetup_Normal, + &mChoice_MainSetup_Disappear + }; + + int index = choice->requested_main_index; + + /* This is necessary lol */ + if (index < 0) { + return; + } + else if (index < 0 || index >= mChoice_MAIN_INDEX_NUM || proc[index] == NULL) { + return; + } + + (*proc[index])(choice, game); +} + +extern void mChoice_Main(mChoice_c* choice, GAME* game) { + static mChoice_MAIN_PROC proc[mChoice_MAIN_INDEX_NUM] = { + &mChoice_Main_Hide, + &mChoice_Main_Appear, + &mChoice_Main_Normal, + &mChoice_Main_Disappear + }; + + int index = choice->main_index; + + if (index < 0 || index >= mChoice_MAIN_INDEX_NUM || proc[index] == NULL) { + return; + } + + (*proc[index])(choice, game); +} + +extern void mChoice_Draw(mChoice_c* choice, GAME* game, int mode) { + if (choice->window_visible_flag) { + mFont_SetMatrix(game->graph, mode); + mChoice_SetMatrix(choice, game, mode); + mChoice_SetMatrixDisplay(choice, game, mode); + mChoice_DrawWindowBody(choice, game, mode); + mChoice_UnSetMatrixDisplay(game, mode); + mChoice_DrawFont(choice, game, mode); + mChoice_UnSetMatrix(); + mFont_UnSetMatrix(game->graph, mode); + } +} + +extern void mChoice_aram_init() { + Choice_table_rom_start = JW_GetAramAddress(RESOURCE_SELECT_TABLE); + Choice_rom_start = JW_GetAramAddress(RESOURCE_SELECT); +} + +extern void mChoice_ct(mChoice_c* choice, GAME* game) { + mChoice_check_ct(choice); + mChoice_init(choice, game); +} + +extern void mChoice_dt(mChoice_c* choice, GAME* game) { } + +#include "../src/m_choice_main.c_inc" +#include "../src/m_choice_sound.c_inc" +#include "../src/m_choice_main_hide.c_inc" +#include "../src/m_choice_main_appear.c_inc" +#include "../src/m_choice_main_normal.c_inc" +#include "../src/m_choice_main_disappear.c_inc" +#include "../src/m_choice_draw.c_inc" diff --git a/src/m_choice_draw.c_inc b/src/m_choice_draw.c_inc new file mode 100644 index 00000000..b65b574c --- /dev/null +++ b/src/m_choice_draw.c_inc @@ -0,0 +1,168 @@ +static void mChoice_SetMatrix(mChoice_c* choice, GAME* game, int type) { + GRAPH* graph = game->graph; + f32 scale = choice->scale; + f32 x = ( choice->center_x - 160.0f) * 16.0f; + f32 y = (-choice->center_y + 120.0f) * 16.0f; + + Matrix_push(); + Matrix_translate(x, y, 0.0f, 1); + Matrix_scale(scale, scale, 1.0f, 1); + + OPEN_DISP(graph); + + if (type == mFont_MODE_FONT) { + gSPMatrix(NOW_FONT_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + else { + gSPMatrix(NOW_POLY_OPA_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + + CLOSE_DISP(graph); +} + +static void mChoice_SetMatrixDisplay(mChoice_c* choice, GAME* game, int type) { + GRAPH* graph = game->graph; + f32 scale_x = choice->scale_x; + f32 scale_y = choice->scale_y; + + Matrix_push(); + Matrix_scale(scale_x, scale_y, 1.0f, 1); + + OPEN_DISP(graph); + + if (type == mFont_MODE_FONT) { + gSPMatrix(NOW_FONT_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + else { + gSPMatrix(NOW_POLY_OPA_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + + CLOSE_DISP(graph); +} + +static void mChoice_UnSetMatrix() { + Matrix_pull(); +} + +static void mChoice_UnSetMatrixDisplay(GAME* game, int type) { + GRAPH* graph = game->graph; + + Matrix_pull(); + + OPEN_DISP(graph); + + if (type == mFont_MODE_FONT) { + gSPMatrix(NOW_FONT_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + else { + gSPMatrix(NOW_POLY_OPA_DISP++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + + CLOSE_DISP(graph); +} + +static u8 con_waku_swaku3_tex[] ATTRIBUTE_ALIGN(32) = { + #ifndef __INTELLISENSE__ + #include "assets/con_waku_swaku3_tex.inc" + #endif +}; + +static Vtx con_sentaku2_v[] = { + #ifndef __INTELLISENSE__ + #include "assets/con_sentaku2_v.inc" + #endif +}; + +static Gfx con_sentaku2_modelT[] = { + gsSPTexture(0, 0, 0, 0, G_ON), + gsDPSetPrimColor(0, 255, 255, 255, 155, 255), + gsDPLoadTextureBlock_4b_Dolphin(con_waku_swaku3_tex, G_IM_FMT_I, 128, 64, 15, GX_MIRROR, GX_MIRROR, 0, 0), + gsSPVertex(&con_sentaku2_v[0], 4, 0), + gsSPNTrianglesInit_5b( + 2, // tri count + 0, 1, 2, // tri0 + 0, 2, 3, // tri1 + 0, 0, 0 // tri2 + ), + gsSPEndDisplayList() +}; + +static Gfx mChoice_init_disp[] = { + gsDPPipeSync(), + gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH), + gsDPSetTextureLOD(G_TL_TILE), + gsDPSetTextureConvert(G_TC_FILT), + gsDPSetTextureFilter(G_TF_BILERP), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetTexturePersp(G_TP_PERSP), + gsDPSetAlphaDither(G_AD_DISABLE), + gsDPSetColorDither(G_CD_DISABLE), + gsDPSetCombineKey(G_CK_NONE), + gsDPSetCombineLERP(0, 0, 0, PRIMITIVE, 0, 0, 0, TEXEL0, 0, 0, 0, PRIMITIVE, 0, 0, 0, TEXEL0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsSPEndDisplayList() +}; + +static void mChoice_DrawWindowBody(mChoice_c* choice, GAME* game, int type) { + GRAPH* graph = game->graph; + + OPEN_DISP(graph); + + if (type == mFont_MODE_FONT) { + gSPDisplayList(NOW_FONT_DISP++, mChoice_init_disp); + gSPDisplayList(NOW_FONT_DISP++, con_sentaku2_modelT); + } + else { + gSPDisplayList(NOW_POLY_OPA_DISP++, mChoice_init_disp); + gSPDisplayList(NOW_POLY_OPA_DISP++, con_sentaku2_modelT); + } + + CLOSE_DISP(graph); +} + +static void mChoice_DrawFont(mChoice_c* choice, GAME* game, int type) { + int i; + int choice_num = choice->data.choice_num; + f32 x = choice->text_x; + f32 y = choice->text_y; + int selected_idx = choice->selected_choice_idx; + int r; + int g; + int b; + + for (i = 0; i < choice_num; i++) { + if (i == selected_idx) { + r = choice->selected_choice_text_color.r; + g = choice->selected_choice_text_color.g; + b = choice->selected_choice_text_color.b; + mFont_SetMarkChar( + game, + mFont_MARKTYPE_CHOICE, + x - 16.0f, y, + choice->background_color.r, choice->background_color.g, choice->background_color.b, 255, + FALSE, + 1.0f, 1.0f, + type + ); + } + else { + r = choice->text_color.r; + g = choice->text_color.g; + b = choice->text_color.b; + } + + mFont_SetLineStrings_AndSpace( + game, + choice->data.strings[i], choice->data.string_lens[i], + x, y, + r, g, b, 255, + FALSE, + TRUE, + 0, + 1.0f, 1.0f, + type + ); + + y += 16.0f; + } +} diff --git a/src/m_choice_main.c_inc b/src/m_choice_main.c_inc new file mode 100644 index 00000000..b47f0657 --- /dev/null +++ b/src/m_choice_main.c_inc @@ -0,0 +1,583 @@ +extern mChoice_c* mChoice_Get_base_window_p() { + return &mMsg_Get_base_window_p()->choice_window; +} + +static void mChoice_init(mChoice_c* choice, GAME* game) { + choice->center_x = 191.0f; + choice->center_y = 83.0f; + choice->text_color.r = 180; + choice->text_color.g = 150; + choice->text_color.b = 110; + choice->text_color.a = 255; + choice->text_scale_x = 1.0f; + choice->text_scale_y = 1.0f; + choice->text_x = 104.0f; + choice->text_y = 96.0f; + choice->scale_x = 1.0f; + choice->scale_y = 1.0f; + choice->data.choice_num = mChoice_CHOICE_NUM; + choice->selected_choice_idx = mChoice_CHOICE0; + choice->selected_choice_text_color.r = 120; + choice->selected_choice_text_color.g = 50; + choice->selected_choice_text_color.b = 50; + choice->selected_choice_text_color.a = 255; + choice->background_color.r = 0; + choice->background_color.g = 195; + choice->background_color.b = 185; + choice->background_color.a = 255; + choice->choice_automove_timer = 0.0f; + choice->_D4 = 232.0f; + choice->_D8 = 104.0f; + choice->scale = 0.0f; + choice->main_index = mChoice_MAIN_HIDE; + choice->requested_main_index = -1; + choice->window_visible_flag = FALSE; + choice->font_visible_flag = FALSE; + choice->choice_automove_type = mChoice_AUTOMOVE_STOPPED; + choice->choice_automove_timer = 0.0f; // duplicate set + choice->timer = 0.0f; + choice->no_b_flag = FALSE; + choice->no_close_flag = FALSE; +} + +extern void mChoice_Change_request_main_index(mChoice_c* choice, int request_main_index) { + choice->requested_main_index = request_main_index; +} + +extern int mChoice_check_main_index(mChoice_c* choice) { + return choice->main_index; +} + +extern int mChoice_check_main_normal(mChoice_c* choice) { + if (mChoice_check_main_index(choice) == mChoice_MAIN_NORMAL) { + return TRUE; + } + + return FALSE; +} + +static void mChoice_Init_choice_data(mChoice_c* choice) { + choice->data.choice_num = 0; +} + +static int mChoice_Add_choice_data(mChoice_c* choice, u8* str, int max_len) { + if (str != NULL && max_len > 0 && max_len <= mChoice_CHOICE_STRING_LEN) { + int num = choice->data.choice_num; + + if (num < mChoice_CHOICE_NUM) { + int len = mMsg_Get_Length_String(str, max_len); + u8* dst = choice->data.strings[num]; + int i; + + for (i = 0; i < len; i++) { + *dst++ = *str++; + } + + choice->data.string_lens[num] = len; + choice->data.choice_num++; + return num; + } + } + + return -1; +} + +extern void mChoice_Set_choice_data( + mChoice_c* choice, + u8* str0, int str0_len, + u8* str1, int str1_len, + u8* str2, int str2_len, + u8* str3, int str3_len, + u8* str4, int str4_len, + u8* str5, int str5_len +) { + mChoice_Init_choice_data(choice); + + if (str0 != NULL && str0_len > 0 && str0_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str0, str0_len); + } + + if (str1 != NULL && str1_len > 0 && str1_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str1, str1_len); + } + + if (str2 != NULL && str2_len > 0 && str2_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str2, str2_len); + } + + if (str3 != NULL && str3_len > 0 && str3_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str3, str3_len); + } + + if (str4 != NULL && str4_len > 0 && str4_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str4, str4_len); + } + + if (str5 != NULL && str5_len > 0 && str5_len <= mChoice_CHOICE_STRING_LEN) { + mChoice_Add_choice_data(choice, str5, str5_len); + } +} + +static int mChoice_Get_MaxStringDotWidth(mChoice_c* choice) { + int i; + int choice_num = choice->data.choice_num; + int max_width = 0; + + for (i = 0; i < choice_num; i++) { + u8* str = choice->data.strings[i]; + int len = choice->data.string_lens[i]; + int width = mFont_GetStringWidth(str, len, TRUE); + + if (width > max_width) { + max_width = width; + } + } + + return max_width; +} + +static int mChoice_Get_MaxStringDotHeight(mChoice_c* choice) { + return choice->data.choice_num * 16; +} + +static void mChoice_Set_DisplayScaleAndDisplayPos(mChoice_c* choice) { + int dw = mChoice_Get_MaxStringDotWidth(choice); + f32 dotW = ((f32)dw - 24.0f) / 96.0f; + int dh = mChoice_Get_MaxStringDotHeight(choice); + f32 dotH = ((f32)dh - 32.0f) / 32.0f; + f32 scaleX = (dotW * 0.5833333730697632f) + (1.0f/2.4f); + f32 scaleY = (dotH * 0.3142857f) + (0.6857143f); + int choice_num = choice->data.choice_num; + f32 tempDotH; + + choice->scale_x = scaleX; + choice->scale_y = scaleY; + tempDotH = dotH * -20.057144f; + choice->text_x = (dotW * -48.0f) + 152.0f; + + if (choice_num > 4) { + choice->text_y = tempDotH + 105.0f + (f32)(choice_num - 3) * 2.0f; + } + else { + choice->text_y = tempDotH + 105.0f; + } + + tempDotH = dotH * 20.057144f; + choice->center_x = 242.0f; + choice->center_x_begin = 242.0f; + choice->center_x_target = 242.0f + (dotW * -35.0f); + + choice->center_y = 169.0f; + choice->center_y_begin = 169.0f; + + if (choice_num > 4) { + choice->center_y_target = (169.0f + tempDotH) - (f32)(choice_num - 4) * 16.0f; + } + else { + choice->center_y_target = 169.0f + tempDotH; + } +} + +extern int mChoice_Get_ChoseNum(mChoice_c* choice) { + return choice->data.selected_choice_idx; +} + +extern void mChoice_Clear_ChoseNum(mChoice_c* choice) { + choice->data.selected_choice_idx = -1; +} + +static void mChoice_check_ct(mChoice_c* choice) { } + +static void mChoice_Get_StringDataAddressAndSize(int idx, u32* addr, u32* size) { + mMsg_Get_BodyParam(Choice_table_rom_start, Choice_rom_start, idx, addr, size); +} + +static int mChoice_Put_String_PLAYER_NAME(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyPlayerName(data, idx, max_size, FALSE); +} + +static int mChoice_Put_String_TALK_NAME(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyTalkName(actor, data, idx, max_size, FALSE); +} + +static int mChoice_Put_String_TAIL(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyTail(actor, data, idx, max_size, FALSE); +} + +static int mChoice_Put_String_YEAR(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyYear(data, idx, max_size); +} + +static int mChoice_Put_String_MONTH(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyMonth(data, idx, max_size); +} + +static int mChoice_Put_String_WEEK(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyWeek(data, idx, max_size); +} + +static int mChoice_Put_String_DAY(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyDay(data, idx, max_size); +} + +static int mChoice_Put_String_HOUR(u8* data, int idx, int max_size, ACTOR* actor) { + mMsg_Window_c* msg_p = mMsg_Get_base_window_p(); + int hour = Common_Get(time.rtc_time.hour); + + if (hour < 12) { + msg_p->status_flags |= mMsg_STATUS_FLAG_USE_AM; + } + else { + msg_p->status_flags &= ~mMsg_STATUS_FLAG_USE_AM; + } + + return mMsg_CopyHour(data, idx, max_size); +} + +static int mChoice_Put_String_MIN(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyMin(data, idx, max_size); +} + +static int mChoice_Put_String_SEC(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopySec(data, idx, max_size); +} + +static int mChoice_Put_String_FREE(u8* data, int idx, int max_size, ACTOR* actor, int free_idx) { + return mMsg_CopyFree(mMsg_Get_base_window_p(), free_idx, data, idx, max_size, mIN_ARTICLE_NUM, FALSE); +} + +static int mChoice_Put_String_FREE0(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR0); +} + +static int mChoice_Put_String_FREE1(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR1); +} + +static int mChoice_Put_String_FREE2(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR2); +} + +static int mChoice_Put_String_FREE3(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR3); +} + +static int mChoice_Put_String_FREE4(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR4); +} + +static int mChoice_Put_String_FREE5(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR5); +} + +static int mChoice_Put_String_FREE6(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR6); +} + +static int mChoice_Put_String_FREE7(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR7); +} + +static int mChoice_Put_String_FREE8(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR8); +} + +static int mChoice_Put_String_FREE9(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR9); +} + +static int mChoice_Put_String_FREE10(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR10); +} + +static int mChoice_Put_String_FREE11(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR11); +} + +static int mChoice_Put_String_FREE12(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR12); +} + +static int mChoice_Put_String_FREE13(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR13); +} + +static int mChoice_Put_String_FREE14(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR14); +} + +static int mChoice_Put_String_FREE15(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR15); +} + +static int mChoice_Put_String_FREE16(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR16); +} + +static int mChoice_Put_String_FREE17(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR17); +} + +static int mChoice_Put_String_FREE18(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR18); +} + +static int mChoice_Put_String_FREE19(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_FREE(data, idx, max_size, actor, mMsg_FREE_STR19); +} + +static int mChoice_Put_String_DETERMINATION(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyDetermination(mMsg_Get_base_window_p(), data, idx, max_size); +} + +static int mChoice_Put_String_COUNTRY_NAME(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyCountryName(data, idx, max_size, FALSE); +} + +static int mChoice_Put_String_RAMDOM_NUMBER2(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyRamdomNumber2(data, idx, max_size); +} + +static int mChoice_Put_String_ITEM(u8* data, int idx, int max_size, ACTOR* actor, int item_idx) { + return mMsg_CopyItem(mMsg_Get_base_window_p(), item_idx, data, idx, max_size, mIN_ARTICLE_NUM, FALSE); +} + +static int mChoice_Put_String_ITEM0(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_ITEM(data, idx, max_size, actor, mMsg_ITEM_STR0); +} + +static int mChoice_Put_String_ITEM1(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_ITEM(data, idx, max_size, actor, mMsg_ITEM_STR1); +} + +static int mChoice_Put_String_ITEM2(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_ITEM(data, idx, max_size, actor, mMsg_ITEM_STR2); +} + +static int mChoice_Put_String_ITEM3(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_ITEM(data, idx, max_size, actor, mMsg_ITEM_STR3); +} + +static int mChoice_Put_String_ITEM4(u8* data, int idx, int max_size, ACTOR* actor) { + return mChoice_Put_String_ITEM(data, idx, max_size, actor, mMsg_ITEM_STR4); +} + +static int mChoice_Put_String_ISLAND_NAME(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyIslandName(data, idx, max_size, FALSE); +} + +static int mChoice_Put_String_AMPM(u8* data, int idx, int max_size, ACTOR* actor) { + return mMsg_CopyAmPm(mMsg_Get_base_window_p(), data, idx, max_size); +} + +typedef int (*mChoice_PUT_STRING_PROC)(u8*, int, int, ACTOR*); + +static int mChoice_Put_String(u8* data, int idx, int max_size, ACTOR* actor) { + static const mChoice_PUT_STRING_PROC proc[mFont_CONT_CODE_NUM] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &mChoice_Put_String_PLAYER_NAME, + &mChoice_Put_String_TALK_NAME, + &mChoice_Put_String_TAIL, + &mChoice_Put_String_YEAR, + &mChoice_Put_String_MONTH, + &mChoice_Put_String_WEEK, + &mChoice_Put_String_DAY, + &mChoice_Put_String_HOUR, + &mChoice_Put_String_MIN, + &mChoice_Put_String_SEC, + &mChoice_Put_String_FREE0, + &mChoice_Put_String_FREE1, + &mChoice_Put_String_FREE2, + &mChoice_Put_String_FREE3, + &mChoice_Put_String_FREE4, + &mChoice_Put_String_FREE5, + &mChoice_Put_String_FREE6, + &mChoice_Put_String_FREE7, + &mChoice_Put_String_FREE8, + &mChoice_Put_String_FREE9, + &mChoice_Put_String_DETERMINATION, + &mChoice_Put_String_COUNTRY_NAME, + &mChoice_Put_String_RAMDOM_NUMBER2, + &mChoice_Put_String_ITEM0, + &mChoice_Put_String_ITEM1, + &mChoice_Put_String_ITEM2, + &mChoice_Put_String_ITEM3, + &mChoice_Put_String_ITEM4, + &mChoice_Put_String_FREE10, + &mChoice_Put_String_FREE11, + &mChoice_Put_String_FREE12, + &mChoice_Put_String_FREE13, + &mChoice_Put_String_FREE14, + &mChoice_Put_String_FREE15, + &mChoice_Put_String_FREE16, + &mChoice_Put_String_FREE17, + &mChoice_Put_String_FREE18, + &mChoice_Put_String_FREE19, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &mChoice_Put_String_ISLAND_NAME, + NULL, + NULL, + NULL, + NULL, + &mChoice_Put_String_AMPM, + NULL, + NULL, + NULL, + NULL + }; + + int type = data[idx + 1]; + + if (type >= 0 && type < mFont_CONT_CODE_NUM && proc[type] != NULL) { + return (*proc[type])(data, idx, max_size, actor); + } + + return max_size; +} + +static void mChoice_Change_ControlCode(u8* data, int max_size, ACTOR* actor) { + u8* src_p = data; + int new_max_size = max_size; + int idx = 0; + u8 code; + + while (idx < new_max_size) { + code = *src_p; + + if (code == CHAR_CONTROL_CODE) { + new_max_size = mChoice_Put_String(data, idx, new_max_size, actor); + } + else { + idx++; + src_p++; + } + } +} + +extern void mChoice_Load_ChoseStringFromRom(mChoice_c* choice, u8* str, int str_no, ACTOR* actor) { + if (str_no >= 0 && str_no < mChoice_SELECT_STR_NUM) { + u32 addr; + u32 size; + + mChoice_Get_StringDataAddressAndSize(str_no, &addr, &size); + + if (size == 0) { + mem_clear(str, mChoice_CHOICE_STRING_LEN, CHAR_SPACE); + } + else if (addr != 0) { + static u8 buff[80] ATTRIBUTE_ALIGN(32); + u32 align_addr = ALIGN_PREV(addr, 32); + u32 ofs = addr - align_addr; + u32 align_size = ALIGN_NEXT(ofs + size, 32); + int max; + int i; + u8* src_p; + u8* dst_p; + + _JW_GetResourceAram(align_addr, buff, align_size); + + max = mChoice_CHOICE_STRING_LEN; + if (size < mChoice_CHOICE_STRING_LEN) { + max = size; + } + + src_p = &buff[ofs]; + dst_p = str; + + /* Copy string from the temp aligned buffer to the destination */ + for (i = 0; i < max; i++) { + *dst_p++ = *src_p++; + } + + /* Fill remaining space with space characters */ + for (i; i < mChoice_CHOICE_STRING_LEN; i++) { + *dst_p++ = CHAR_SPACE; + } + + /* Process any control codes */ + mChoice_Change_ControlCode(str, mChoice_CHOICE_STRING_LEN, actor); + } + } +} + +extern void mChoice_no_b_set(mChoice_c* choice) { + choice->no_b_flag = TRUE; +} + +extern void mChoice_no_b_close_set(mChoice_c* choice) { + choice->no_b_flag = TRUE; + choice->no_close_flag = TRUE; +} diff --git a/src/m_choice_main_appear.c_inc b/src/m_choice_main_appear.c_inc new file mode 100644 index 00000000..7d18642f --- /dev/null +++ b/src/m_choice_main_appear.c_inc @@ -0,0 +1,48 @@ +static int mChoice_Main_Appear_SetScale(mChoice_c* choice, GAME* game) { + int res; + const f32 max = 10.2f; + + if (choice->timer < max) { + f32 scale; + + choice->timer += 1.0f; + scale = get_percent_forAccelBrake(choice->timer, 0.0f, max, 0.0f, 0.0f); + choice->scale = scale; + choice->center_x = choice->center_x_begin + scale * (choice->center_x_target - choice->center_x_begin); + choice->center_y = choice->center_y_begin + scale * (choice->center_y_target - choice->center_y_begin); + res = FALSE; + } + else { + choice->timer = 0.0f; + choice->scale = 1.0f; + choice->center_x = choice->center_x_target; + choice->center_y = choice->center_y_target; + res = TRUE; + } + + return res; +} + +static void mChoice_request_main_index_fromAppear(mChoice_c* choice, GAME* game, int open_flag) { + if (open_flag) { + mChoice_Change_request_main_index(choice, mChoice_MAIN_NORMAL); + } +} + +static void mChoice_Main_Appear(mChoice_c* choice, GAME* game) { + int open_flag = mChoice_Main_Appear_SetScale(choice, game); + + mChoice_request_main_index_fromAppear(choice, game, open_flag); + mChoice_MainSetup(choice, game); +} + +static void mChoice_MainSetup_Appear(mChoice_c* choice, GAME* game) { + choice->scale = 0.0f; + choice->main_index = mChoice_MAIN_APPEAR; + choice->requested_main_index = -1; + choice->window_visible_flag = TRUE; + choice->timer = 0.0f; + mChoice_Clear_ChoseNum(choice); + mChoice_sound_SENTAKU_OPEN(); + mChoice_Set_DisplayScaleAndDisplayPos(choice); +} diff --git a/src/m_choice_main_disappear.c_inc b/src/m_choice_main_disappear.c_inc new file mode 100644 index 00000000..4fcc7bee --- /dev/null +++ b/src/m_choice_main_disappear.c_inc @@ -0,0 +1,56 @@ +static int mChoice_Main_Disappear_SetScale(mChoice_c* choice, GAME* game) { + const f32 max = 10.2f; + + if (choice->timer < max) { + f32 scale; + + choice->timer += 1.0f; + scale = 1.0f - get_percent_forAccelBrake(choice->timer, 0.0f, max, 0.0f, 0.0f); + choice->scale = scale; + choice->center_x = choice->center_x_begin + scale * (choice->center_x_target - choice->center_x_begin); + choice->center_y = choice->center_y_begin + scale * (choice->center_y_target - choice->center_y_begin); + return FALSE; + } + else { + choice->timer = 0.0f; + choice->scale = 0.0f; + choice->center_x = choice->center_x_begin; + choice->center_y = choice->center_y_begin; + return TRUE; + } +} + +static void mChoice_request_main_index_fromDisappear(mChoice_c* choice, GAME* game, int closed_flag) { + if (closed_flag) { + mChoice_Change_request_main_index(choice, mChoice_MAIN_HIDE); + } +} + +static void mChoice_Main_Disappear(mChoice_c* choice, GAME* game) { + int closed_flag = mChoice_Main_Disappear_SetScale(choice, game); + + mChoice_request_main_index_fromDisappear(choice, game, closed_flag); + mChoice_MainSetup(choice, game); +} + +static void mChoice_MainSetup_Disappear(mChoice_c* choice, GAME* game) { + if (choice->no_b_flag && choice->selected_choice_idx == (choice->data.choice_num - 1)) { + if (choice->no_close_flag) { + mChoice_sound_ZOOMDOWN_LONG(); + mMsg_Get_base_window_p()->status_flags |= mMsg_STATUS_FLAG_ZOOMDOWN_LONG; + } + else { + mChoice_sound_ZOOMDOWN_SHORT(); + } + } + else { + mChoice_sound_SENTAKU_KETTEI(); + } + + choice->scale = 1.0f; + choice->main_index = mChoice_MAIN_DISAPPEAR; + choice->requested_main_index = -1; + choice->window_visible_flag = TRUE; + choice->timer = 0.0f; + choice->font_visible_flag = FALSE; +} diff --git a/src/m_choice_main_hide.c_inc b/src/m_choice_main_hide.c_inc new file mode 100644 index 00000000..94a1a79d --- /dev/null +++ b/src/m_choice_main_hide.c_inc @@ -0,0 +1,7 @@ +static void mChoice_Main_Hide(mChoice_c* choice, GAME* game) { + mChoice_MainSetup(choice, game); +} + +static void mChoice_MainSetup_Hide(mChoice_c* choice, GAME* game) { + mChoice_init(choice, game); +} diff --git a/src/m_choice_main_normal.c_inc b/src/m_choice_main_normal.c_inc new file mode 100644 index 00000000..4f2850dd --- /dev/null +++ b/src/m_choice_main_normal.c_inc @@ -0,0 +1,162 @@ +static void mChoice_determimation_set(mChoice_c* choice) { + mChoice_Data_c* choice_data = &choice->data; + int idx = choice->selected_choice_idx; + + bcopy(choice_data->strings[idx], choice_data->determination_string, mChoice_CHOICE_STRING_LEN); + choice_data->determination_len = choice_data->string_lens[idx]; + choice_data->selected_choice_idx = idx; +} + +static int mChoice_Main_Normal_SetChoice(mChoice_c* choice, GAME* game) { + int res = FALSE; + + if (chkTrigger(BUTTON_A)) { + mChoice_determimation_set(choice); + res = TRUE; + } + else if (choice->no_b_flag && chkTrigger(BUTTON_B)) { + choice->selected_choice_idx = choice->data.choice_num - 1; + mChoice_determimation_set(choice); + res = TRUE; + } + else { + f32 percent = gamePT->mcon.adjusted_pY; + int* choice_automove_p = &choice->choice_automove_type; + f32* choice_automove_timer_p = &choice->choice_automove_timer; + int* selected_idx_p = &choice->selected_choice_idx; + int cursor_sfx = FALSE; + + switch (*choice_automove_p) { + case mChoice_AUTOMOVE_INCREMENT_WAIT: + { + if (percent < 0.0f || chkButton(BUTTON_CDOWN)) { + (*choice_automove_timer_p) += 1.0f; + + if (*choice_automove_timer_p >= 18.0f) { + *choice_automove_timer_p = 0.0f; + *choice_automove_p = mChoice_AUTOMOVE_INCREMENT; + (*selected_idx_p)++; + cursor_sfx = TRUE; + } + } + else { + *choice_automove_p = mChoice_AUTOMOVE_STOPPED; + *choice_automove_timer_p = 0.0f; + } + + break; + } + + case mChoice_AUTOMOVE_INCREMENT: + { + if (percent < 0.0f || chkButton(BUTTON_CDOWN)) { + (*choice_automove_timer_p) += 1.0f; + + if (*choice_automove_timer_p >= 9.0f) { + *choice_automove_timer_p = 0.0f; + (*selected_idx_p)++; + cursor_sfx = TRUE; + } + } + else { + *choice_automove_p = mChoice_AUTOMOVE_STOPPED; + *choice_automove_timer_p = 0.0f; + } + + break; + } + + case mChoice_AUTOMOVE_DECREMENT_WAIT: + { + if (percent > 0.0f || chkButton(BUTTON_CUP)) { + (*choice_automove_timer_p) += 1.0f; + + if (*choice_automove_timer_p >= 18.0f) { + *choice_automove_timer_p = 0.0f; + *choice_automove_p = mChoice_AUTOMOVE_DECREMENT; + (*selected_idx_p)--; + cursor_sfx = TRUE; + } + } + else { + *choice_automove_p = mChoice_AUTOMOVE_STOPPED; + *choice_automove_timer_p = 0.0f; + } + + break; + } + + case mChoice_AUTOMOVE_DECREMENT: + { + if (percent > 0.0f || chkButton(BUTTON_CUP)) { + (*choice_automove_timer_p) += 1.0f; + + if (*choice_automove_timer_p >= 9.0f) { + *choice_automove_timer_p = 0.0f; + (*selected_idx_p)--; + cursor_sfx = TRUE; + } + } + else { + *choice_automove_p = mChoice_AUTOMOVE_STOPPED; + *choice_automove_timer_p = 0.0f; + } + + break; + } + + default: + { + if (percent > 0.0f || chkTrigger(BUTTON_CUP)) { + *choice_automove_p = mChoice_AUTOMOVE_DECREMENT_WAIT; + *choice_automove_timer_p = 0.0f; + (*selected_idx_p)--; + cursor_sfx = TRUE; + } + else if (percent < 0.0f || chkTrigger(BUTTON_CDOWN)) { + *choice_automove_p = mChoice_AUTOMOVE_INCREMENT_WAIT; + *choice_automove_timer_p = 0.0f; + (*selected_idx_p)++; + cursor_sfx = TRUE; + } + + break; + } + } + + if ((*selected_idx_p) < 0) { + *selected_idx_p = 0; + } + else if ((*selected_idx_p) >= choice->data.choice_num) { + *selected_idx_p = choice->data.choice_num - 1; + } + else { + if (cursor_sfx) { + mChoice_sound_CURSOL(); + } + } + } + + return res; +} + +static void mChoice_request_main_index_fromNormal(mChoice_c* choice, GAME* game, int close_flag) { + if (close_flag) { + mChoice_Change_request_main_index(choice, mChoice_MAIN_DISAPPEAR); + } +} + +static void mChoice_Main_Normal(mChoice_c* choice, GAME* game) { + int close_flag = mChoice_Main_Normal_SetChoice(choice, game); + + mChoice_request_main_index_fromNormal(choice, game, close_flag); + mChoice_MainSetup(choice, game); +} + +static void mChoice_MainSetup_Normal(mChoice_c* choice, GAME* game) { + choice->scale = 1.0f; + choice->timer = 0.0f; + choice->requested_main_index = -1; + choice->main_index = mChoice_MAIN_NORMAL; + choice->font_visible_flag = TRUE; +} diff --git a/src/m_choice_sound.c_inc b/src/m_choice_sound.c_inc new file mode 100644 index 00000000..978a0bf8 --- /dev/null +++ b/src/m_choice_sound.c_inc @@ -0,0 +1,19 @@ +static void mChoice_sound_SENTAKU_KETTEI() { + sAdo_SysTrgStart(0xD); +} + +static void mChoice_sound_SENTAKU_OPEN() { + sAdo_SysTrgStart(0xC); +} + +static void mChoice_sound_CURSOL() { + sAdo_SysTrgStart(0x1); +} + +static void mChoice_sound_ZOOMDOWN_SHORT() { + sAdo_SysTrgStart(0x8005); +} + +static void mChoice_sound_ZOOMDOWN_LONG() { + sAdo_SysTrgStart(0x8015); +}