Updating buttons and implementing offset rows

This commit is contained in:
Remnants of Forgotten Disney 2024-03-29 19:33:10 -05:00
parent 0b041caf75
commit 0a27d23ba5
23 changed files with 133 additions and 82 deletions

BIN
graphics/btn_lang_jpn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 B

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 B

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 B

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 251 B

View File

Before

Width:  |  Height:  |  Size: 881 B

After

Width:  |  Height:  |  Size: 881 B

View File

@ -7,7 +7,7 @@ class Button
{
public:
Button();
Button(OBJ_ATTR *L, OBJ_ATTR *R); // wide buttons
Button(OBJ_ATTR *L, OBJ_ATTR *R, int nLeft_button_width); // wide buttons
Button(OBJ_ATTR *B); // short button
bool isWide;
void set_location(int x, int y);
@ -18,6 +18,7 @@ public:
int y;
private:
int left_button_width;
bool highlighted;
OBJ_ATTR *button_L;
OBJ_ATTR *button_R;

View File

@ -1,7 +1,7 @@
#ifndef DEBUG_MODE_H
#define DEBUG_MODE_H
#define DEBUG_MODE false
#define DEBUG_MODE true
#define IGNORE_GAME_PAK true
#define IGNORE_LINK_CABLE true
#define IGNORE_MG_E4_FLAGS true

View File

@ -11,28 +11,12 @@
#define BTN_POKEDEX 2
#define BTN_LANGUAGE 3
#define BTN_CREDITS 4
#define WIDE_BUTTON_ARRAY_SIZE 5
#define BTN_ENG 0
#define BTN_FRE 1
#define BTN_ITA 2
#define BTN_GER 3
#define BTN_SPA 4
#define BTN_KOR 5
#define LANG_ARROW 6
#define LANG_BUTTON_ARRAY_SIZE 7
#define NO_ANI 0
#define ENTERING -1
#define EXITING -2
#define DISABLE -3
#define BUTTON_CANCEL -1
class Button_Menu
{
public:
Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height);
Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height, bool enable_cancel);
int button_main();
void add_button(Button btn, int return_val);
void hide_buttons();
@ -42,6 +26,9 @@ public:
unsigned int get_x_from_pos(int nPos);
unsigned int get_y_from_pos(int nPos);
void set_xy_min_max(int nX_min, int nX_max, int nY_min, int nY_max);
void set_rows_and_columns(int nRows, int nColumns);
void set_bottom_row_offset(int nBottom_offset);
void clear_vector();
private:
std::vector<Button> button_vector;
@ -55,5 +42,7 @@ private:
int x_max;
int y_min;
int y_max;
int bottom_offset;
bool cancel_enabled;
};
#endif

View File

@ -16,7 +16,7 @@ public:
bool get_has_new_pkmn();
void set_game(int nGame);
void set_lang(int nLang);
int get_lang();
private:
byte box_data_array[0x462];

View File

@ -81,7 +81,8 @@ extern rom_data curr_rom;
void populate_script();
void populate_dialogue();
void populate_buttons();
void populate_lang_buttons();
void populate_game_buttons();
bool run_conditional(int index);
#endif

View File

@ -38,6 +38,8 @@ extern OBJ_ATTR *btn_d_r;
extern OBJ_ATTR *dex_sprites[3][6];
#define SPRITE_BATCH_LANG 1
#include "btn_lang_jpn.h"
extern OBJ_ATTR *btn_lang_jpn;
#include "btn_lang_eng.h"
extern OBJ_ATTR *btn_lang_eng;
#include "btn_lang_fre.h"

View File

@ -2,11 +2,12 @@
Button::Button() {}
Button::Button(OBJ_ATTR *L, OBJ_ATTR *R)
Button::Button(OBJ_ATTR *L, OBJ_ATTR *R, int nLeft_button_width)
{
button_L = L;
button_R = R;
isWide = true;
left_button_width = nLeft_button_width;
hide();
}
@ -24,7 +25,7 @@ void Button::set_location(int nx, int ny)
obj_set_pos(button_L, x, y);
if (isWide)
{
obj_set_pos(button_R, x + 48, y);
obj_set_pos(button_R, x + left_button_width, y);
}
}
void Button::set_highlight(bool highlight)

View File

@ -57,7 +57,7 @@ TODO:
int delay_counter = 0;
bool skip = true;
rom_data curr_rom;
Button_Menu main_menu(3, 1, 96, 32);
Button_Menu main_menu(3, 1, 96, 32, false);
/*
int test_main(void) Music
@ -98,10 +98,10 @@ void load_graphics()
load_eternal_sprites();
// Set up main menu
main_menu.add_button(Button(btn_t_l, btn_t_r), BTN_TRANSFER);
main_menu.add_button(Button(btn_p_l, btn_p_r), BTN_POKEDEX);
main_menu.add_button(Button(btn_t_l, btn_t_r, 48), BTN_TRANSFER);
main_menu.add_button(Button(btn_p_l, btn_p_r, 48), BTN_POKEDEX);
//main_menu.add_button(Button(btn_d_l, btn_d_r), BTN_LANGUAGE);
main_menu.add_button(Button(btn_c_l, btn_c_r), BTN_CREDITS);
main_menu.add_button(Button(btn_c_l, btn_c_r, 48), BTN_CREDITS);
}
void initalization_script(void)
@ -129,7 +129,6 @@ void initalization_script(void)
// Prepare dialouge
populate_dialogue();
populate_script();
populate_buttons();
init_text_engine();
// Set the random seed

View File

@ -3,8 +3,9 @@
#include "button_handler.h"
#include "save_data_manager.h"
#include "global_frame_controller.h"
#include "string"
Button_Menu::Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height)
Button_Menu::Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height, bool enable_cancel)
{
columns = nColumns;
rows = nRows;
@ -15,9 +16,12 @@ Button_Menu::Button_Menu(int nRows, int nColumns, int nButton_width, int nButton
x_max = 240;
y_min = 0;
y_max = 160;
bottom_offset = 0;
cancel_enabled = enable_cancel;
}
void Button_Menu::set_xy_min_max(int nX_min, int nX_max, int nY_min, int nY_max){
void Button_Menu::set_xy_min_max(int nX_min, int nX_max, int nY_min, int nY_max)
{
x_min = nX_min;
x_max = nX_max;
y_min = nY_min;
@ -43,10 +47,18 @@ int Button_Menu::button_main()
if (key_hit(KEY_RIGHT) && (curr_x < (columns - 1)))
{
curr_x++;
if (get_pos_from_xy(curr_x, curr_y) >= button_vector.size())
{
curr_y--;
}
}
else if (key_hit(KEY_DOWN) && (curr_y < (rows - 1)))
{
curr_y++;
if (get_pos_from_xy(curr_x, curr_y) >= button_vector.size())
{
curr_x--;
}
}
else if (key_hit(KEY_LEFT) && (curr_x > 0))
{
@ -61,6 +73,11 @@ int Button_Menu::button_main()
hide_buttons();
return return_values.at(curr_position);
}
else if (cancel_enabled && key_hit(KEY_B))
{
hide_buttons();
return BUTTON_CANCEL;
}
if (get_pos_from_xy(curr_x, curr_y) != curr_position)
{
@ -99,14 +116,16 @@ void Button_Menu::organize_buttons()
{
// Total space, minus the space taken up by the buttons, divided by the spaces between the buttons.
int vertical_space =
((y_max - y_min) - ((button_vector.size() / columns) * button_height)) / ((button_vector.size() / columns) + 1);
int horizonal_space =
((x_max - x_min) - ((button_vector.size() / rows) * button_width)) / ((button_vector.size() / rows) + 1);
((y_max - y_min) - (rows * button_height)) / (rows + 1);
int horizontal_space =
((x_max - x_min) - (columns * button_width)) / (columns + 1);
int bottom_offset = ((horizontal_space + button_width) * ((rows * columns) - button_vector.size()) / 2);
for (unsigned int i = 0; i < button_vector.size(); i++)
{
button_vector.at(i).set_location(
((horizonal_space + button_width) * get_x_from_pos(i)) + horizonal_space + x_min,
((horizontal_space + button_width) * get_x_from_pos(i)) + horizontal_space + x_min +
(get_y_from_pos(i) == (unsigned int)(rows - 1) ? bottom_offset : 0),
((vertical_space + button_height) * get_y_from_pos(i)) + vertical_space + y_min);
}
}
@ -124,4 +143,19 @@ unsigned int Button_Menu::get_x_from_pos(int nPos)
unsigned int Button_Menu::get_y_from_pos(int nPos)
{
return (nPos / columns);
}
void Button_Menu::set_rows_and_columns(int nRows, int nColumns)
{
rows = nRows;
columns = nColumns;
}
void Button_Menu::set_bottom_row_offset(int nBottom_offset)
{
bottom_offset = nBottom_offset;
}
void Button_Menu::clear_vector(){
button_vector.clear();
}

View File

@ -122,3 +122,7 @@ void Pokemon_Party::set_lang(int nLang)
{
lang = nLang;
}
int Pokemon_Party::get_lang(){
return lang;
}

View File

@ -40,27 +40,6 @@ void set_caught(int dex_num)
save_data_array[CAUGHT_DATA + (dex_num / 8)] = save_data_array[CAUGHT_DATA + (dex_num / 8)] | (1 << (dex_num % 8));
}
int get_def_lang()
{
switch (save_data_array[DEFAULT_LANGUAGE])
{
case BTN_ENG:
return ENG_ID;
case BTN_FRE:
return FRE_ID;
case BTN_ITA:
return ITA_ID;
case BTN_GER:
return GER_ID;
case BTN_SPA:
return SPA_ID;
case BTN_KOR:
return KOR_ID;
default:
return ENG_ID;
}
}
int get_def_lang_num()
{
return save_data_array[DEFAULT_LANGUAGE];

View File

@ -12,8 +12,8 @@
int last_error;
Pokemon_Party party_data = Pokemon_Party();
Button_Menu lang_select(2, 3, 40, 24);
Button_Menu game_select(2, 3, 40, 24);
Button_Menu lang_select(2, 4, 40, 24, false);
Button_Menu game_select(2, 2, 72, 32, true);
script_obj script[SCRIPT_SIZE];
std::string_view dialogue[DIA_SIZE];
@ -37,7 +37,7 @@ void populate_dialogue()
dialogue[DIA_PKMN_TO_COLLECT] = "Hi Trainer! It looks like\nyou still have Pok@mon to\npick up...|I can send in new ones, but do know that the Pok@mon you\nhaven't picked up yet will\nbe replaced.|Turn off the system now if\nyou want to recieve those\nPok@mon, but otherwise-";
dialogue[DIA_NO_VALID_PKMN] = "Sorry Trainer, it doesn't\nlook like you have any valid\nPok@mon in your party right\nnow.|Double check your party and we'll give it another shot!";
dialogue[DIA_ASK_QUEST] = "Hi trainer! Before we begin,\nI need to ask you a few\nquestions.";
dialogue[DIA_WHAT_GAME] = "First, which Game Boy\nPok@mon game are you\ntransfering from?";
dialogue[DIA_WHAT_GAME] = "And which Game Boy Pok@mon\ngame are you transfering\nfrom?";
dialogue[DIA_WHAT_LANG] = "What language is the Game\nBoy Pok@mon game that you're\ntransfering from?";
dialogue[DIA_ERROR_COLOSSEUM] = "It looks like you went to\nthe colosseum instead of the\ntrading room!|Let's try that again!";
@ -70,11 +70,11 @@ void populate_script()
script[DIA_START] = script_obj(dialogue[DIA_START], CMD_START_LINK);
script[CMD_START_LINK] = script_obj(CMD_START_LINK, COND_ERROR_TIMEOUT_ONE);
script[DIA_WHAT_GAME] = script_obj(dialogue[DIA_WHAT_GAME], CMD_GAME_MENU);
script[CMD_GAME_MENU] = script_obj(CMD_GAME_MENU, DIA_WHAT_LANG);
script[CMD_GAME_MENU] = script_obj(CMD_GAME_MENU, CMD_SLIDE_PROF_RIGHT, DIA_WHAT_LANG);
script[DIA_WHAT_LANG] = script_obj(dialogue[DIA_WHAT_LANG], CMD_LANG_MENU);
script[CMD_LANG_MENU] = script_obj(CMD_LANG_MENU, CMD_SLIDE_PROF_RIGHT);
script[CMD_LANG_MENU] = script_obj(CMD_LANG_MENU, DIA_WHAT_GAME);
script[DIA_ASK_QUEST] = script_obj(dialogue[DIA_ASK_QUEST], CMD_SLIDE_PROF_LEFT);
script[CMD_SLIDE_PROF_LEFT] = script_obj(CMD_SLIDE_PROF_LEFT, DIA_WHAT_GAME);
script[CMD_SLIDE_PROF_LEFT] = script_obj(CMD_SLIDE_PROF_LEFT, DIA_WHAT_LANG);
script[CMD_SLIDE_PROF_RIGHT] = script_obj(CMD_SLIDE_PROF_RIGHT, DIA_LETS_START);
// Initiate the transfer and check for errors
@ -106,28 +106,49 @@ void populate_script()
script[CMD_BACK_TO_MENU] = script_obj(CMD_BACK_TO_MENU, SCRIPT_START);
};
void populate_buttons()
void populate_lang_buttons()
{
lang_select.set_xy_min_max(48, 240, 0, 120);
lang_select.add_button(Button(btn_lang_eng), BTN_ENG);
lang_select.add_button(Button(btn_lang_fre), BTN_FRE);
lang_select.add_button(Button(btn_lang_ita), BTN_ITA);
lang_select.add_button(Button(btn_lang_ger), BTN_GER);
lang_select.add_button(Button(btn_lang_spa), BTN_SPA);
lang_select.add_button(Button(btn_lang_kor), BTN_KOR);
lang_select.set_xy_min_max(48, 240, 0, 112);
lang_select.clear_vector();
lang_select.add_button(Button(btn_lang_jpn), JPN_ID);
lang_select.add_button(Button(btn_lang_eng), ENG_ID);
lang_select.add_button(Button(btn_lang_fre), FRE_ID);
lang_select.add_button(Button(btn_lang_ita), ITA_ID);
lang_select.add_button(Button(btn_lang_ger), GER_ID);
lang_select.add_button(Button(btn_lang_spa), SPA_ID);
lang_select.add_button(Button(btn_lang_kor), KOR_ID);
}
void populate_game_buttons()
{
game_select.clear_vector();
switch (party_data.get_lang())
{
case JPN_ID:
game_select.set_rows_and_columns(3, 2);
game_select.add_button(Button(button_red_green_left, button_red_green_right, 64), 0);
game_select.add_button(Button(button_blue_left, button_blue_right, 64), 0);
game_select.add_button(Button(button_yellow_left, button_yellow_right, 64), 0);
game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0);
game_select.add_button(Button(button_crystal_left, button_crystal_right, 64), 0);
break;
case KOR_ID:
game_select.set_rows_and_columns(1, 1);
game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0);
break;
default:
game_select.set_rows_and_columns(2, 2);
game_select.add_button(Button(button_red_blue_left, button_red_blue_right, 64), 0);
game_select.add_button(Button(button_yellow_left, button_yellow_right, 64), 0);
game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0);
game_select.add_button(Button(button_crystal_left, button_crystal_right, 64), 0);
}
game_select.set_xy_min_max(48, 240, 0, 120);
game_select.add_button(Button(button_red_green_left, button_red_green_right), 0);
game_select.add_button(Button(button_blue_left, button_blue_right), 0);
game_select.add_button(Button(button_red_blue_left, button_red_blue_right), 0);
game_select.add_button(Button(button_yellow_left, button_yellow_right), 0);
game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right), 0);
game_select.add_button(Button(button_crystal_left, button_crystal_right), 0);
}
bool run_conditional(int index)
{
// Here is most of the logic that drives what lines show up where. It's probably not the best way to code it, but it works
int game;
switch (index)
{
@ -175,9 +196,9 @@ bool run_conditional(int index)
return true;
case CMD_IMPORT_POKEMON:
party_data.set_lang(ENG_ID);
party_data.set_game(RED_ID);
// REMOVE ME ^
// party_data.set_lang(ENG_ID);
// party_data.set_game(RED_ID);
// REMOVE ME ^
return inject_mystery(party_data);
case CMD_BACK_TO_MENU:
@ -203,12 +224,19 @@ bool run_conditional(int index)
case CMD_LANG_MENU:
load_temp_sprites(SPRITE_BATCH_LANG);
populate_lang_buttons();
party_data.set_lang(lang_select.button_main());
return true;
case CMD_GAME_MENU:
load_temp_sprites(SPRITE_BATCH_GAMES);
party_data.set_game(game_select.button_main());
populate_game_buttons();
game = game_select.button_main();
if (game == BUTTON_CANCEL)
{
return false;
}
party_data.set_game(game);
return true;
case CMD_SLIDE_PROF_LEFT:

View File

@ -80,6 +80,7 @@ OBJ_ATTR *dex_sprites[3][6] = { // Fills the dex sprites top to bottom, left to
{&obj_buffer[num_sprites++], &obj_buffer[num_sprites++], &obj_buffer[num_sprites++],
&obj_buffer[num_sprites++], &obj_buffer[num_sprites++], &obj_buffer[num_sprites++]}};
OBJ_ATTR *btn_lang_jpn = &obj_buffer[num_sprites++];
OBJ_ATTR *btn_lang_eng = &obj_buffer[num_sprites++];
OBJ_ATTR *btn_lang_fre = &obj_buffer[num_sprites++];
OBJ_ATTR *btn_lang_ita = &obj_buffer[num_sprites++];
@ -138,6 +139,7 @@ void load_temp_sprites(int sprite_batch_id)
break;
case SPRITE_BATCH_LANG:
load_sprite(btn_lang_jpn, btn_lang_jpnTiles, btn_lang_jpnTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1);
load_sprite(btn_lang_eng, btn_lang_engTiles, btn_lang_engTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1);
load_sprite(btn_lang_fre, btn_lang_freTiles, btn_lang_freTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1);
load_sprite(btn_lang_ita, btn_lang_itaTiles, btn_lang_itaTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1);

View File

@ -6,6 +6,7 @@
#include "global_frame_controller.h"
#include "pkmn_font.h"
#include "script_array.h"
#include "debug_mode.h"
#define TEXT_CBB 3
#define TEXT_SBB 28
@ -46,7 +47,17 @@ int text_loop()
{
if (get_frame_count() % 2 == 0 || key_held(KEY_B) || key_held(KEY_A))
{
char_index++;
if (DEBUG_MODE)
{
while (char_index < curr_text.length() && curr_text.substr(char_index, 1) != "|")
{
char_index++;
}
}
else
{
char_index++;
}
tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM);
tte_write(curr_text.substr(0, char_index).c_str());
}