Poke_Transporter_GB/source/box_menu.cpp
easyaspi314 e4ef25e20e Compress the graphics (mostly), fix potential vram memcpy issue
This greatly decreases the ROM size, from 245 KB to 198 KB with no visual
changes (that I am aware of)

Changes:
- Enable compression on every graphic but the Pokemon sprites (which are
  too large for the GBA to decompress).
- Change grit from emitting .s files to .c files so GCC can strip unused
  palettes and maps
- Fix the empty tiles
- Trim down the font to skip 00-1F and 80-FF which were all zeroes
  - needs a slight workaround because the Pokemon name display was printing
    an invisible FF byte
- Switch memcpy to tonccpy which is vram safe
- Limit palette sizes.

Signed-off-by: easyaspi314 <6258309+easyaspi314@users.noreply.github.com>
2025-01-17 19:32:48 -05:00

142 lines
4.3 KiB
C++

#include <tonc.h>
#include "button_menu.h"
#include "button_handler.h"
#include "save_data_manager.h"
#include "global_frame_controller.h"
#include "string"
#include "sprite_data.h"
#include "box_menu.h"
#include "pokemon_data.h"
Box_Menu::Box_Menu() {};
int Box_Menu::box_main(Pokemon_Party party_data)
{
tte_erase_screen();
load_flex_background(BG_FENNEL, 3);
REG_BG2VOFS = BG2VOF_LARGE_TEXTBOX;
REG_BG2VOFS = 0;
load_temp_box_sprites(party_data);
Button cancel_button(button_cancel_left, button_cancel_right, 64);
Button confirm_button(button_confirm_left, button_confirm_right, 64);
cancel_button.set_location(32, 112);
confirm_button.set_location(136, 112);
cancel_button.show();
confirm_button.show();
curr_button = 0;
x = 0;
y = 0;
bool update_pos = true;
obj_unhide(box_select, 0);
while (true)
{
if (curr_button == 0)
{
if (key_hit(KEY_LEFT) && (x > 0))
{
x--;
update_pos = true;
}
else if (key_hit(KEY_RIGHT) && (x < 9))
{
x++;
update_pos = true;
}
else if (key_hit(KEY_UP) && y > 0)
{
y--;
update_pos = true;
}
else if (key_hit(KEY_DOWN) && (y < 2))
{
y++;
update_pos = true;
}
else if (key_hit(KEY_DOWN) && (y == 2))
{
obj_hide(box_select);
if (x < 5)
{
cancel_button.set_highlight(true);
curr_button = CANCEL_BUTTON;
}
else
{
confirm_button.set_highlight(true);
curr_button = CONFIRM_BUTTON;
}
}
}
else
{
if (key_hit(KEY_LEFT) && (curr_button == CONFIRM_BUTTON))
{
curr_button = CANCEL_BUTTON;
cancel_button.set_highlight(true);
confirm_button.set_highlight(false);
x -= 5;
}
else if (key_hit(KEY_RIGHT) && (curr_button == CANCEL_BUTTON))
{
curr_button = CONFIRM_BUTTON;
cancel_button.set_highlight(false);
confirm_button.set_highlight(true);
x += 5;
}
else if (key_hit(KEY_UP))
{
curr_button = 0;
cancel_button.set_highlight(false);
confirm_button.set_highlight(false);
obj_unhide(box_select, 0);
update_pos = true;
}
else if (key_hit(KEY_A))
{
cancel_button.hide();
confirm_button.hide();
for (int i = 0; i < 30; i++)
{
obj_hide(party_sprites[i]);
}
tte_erase_screen();
load_flex_background(BG_FENNEL, 2);
REG_BG2VOFS = BG2VOF_SMALL_TEXTBOX;
global_next_frame();
return curr_button;
}
}
if (update_pos)
{
int index = x + (y * 10);
obj_set_pos(box_select, 40 + (x * 16), 24 + (y * 16));
tte_erase_rect(40, 72, 220, 88);
Simplified_Pokemon curr_pkmn = party_data.get_simple_pkmn(index);
if (curr_pkmn.is_valid)
{
tte_set_pos(40, 72);
for (int i = 0; i < 10; i++)
{
if (curr_pkmn.nickname[i] == 0xFF)
{
break;
}
tte_putc(gen_3_Intern_char_array[curr_pkmn.nickname[i]]);
}
if (curr_pkmn.is_shiny)
{
tte_set_pos(40, 80);
tte_write("*");
}
tte_set_pos(48, 80);
tte_write(curr_pkmn.is_missingno ? "MissingNo" : NAMES[curr_pkmn.dex_number].data());
tte_set_pos(146, 80);
tte_write("Lv: ");
tte_write(std::to_string(curr_pkmn.met_level).c_str());
update_pos = false;
}
}
global_next_frame();
}
}