113 lines
4.3 KiB
C
113 lines
4.3 KiB
C
#include "game.h"
|
|
|
|
struct SaveMenuState save_menu;
|
|
static int team_member, team_parent;
|
|
|
|
int save_menu_input(unsigned keys, int can_open, const struct Location *location)
|
|
{
|
|
unsigned pressed = keys & ~save_menu.previous;
|
|
save_menu.previous = keys;
|
|
if (save_menu.phase == SAVE_MENU_CLOSED) {
|
|
if (!can_open || !(pressed & (START | SELECT))) return 0;
|
|
save_menu.phase = pressed & START ? SAVE_MENU_OPTIONS : SAVE_MENU_TEAM;
|
|
team_parent = 0;
|
|
team_member = 0;
|
|
save_menu.selection = 0;
|
|
return 1;
|
|
}
|
|
if (pressed & START) {
|
|
save_menu.phase = SAVE_MENU_CLOSED;
|
|
return 1;
|
|
}
|
|
if (save_menu.phase == SAVE_MENU_TEAM || save_menu.phase == SAVE_MENU_BAG) {
|
|
if (pressed & (B | SELECT | A)) {
|
|
if (save_menu.phase == SAVE_MENU_TEAM && (pressed & A) &&
|
|
!(pressed & (B | SELECT)) && choose_partner(team_member))
|
|
reset_follower(location->x, location->y);
|
|
save_menu.phase = team_parent ? SAVE_MENU_OPTIONS : SAVE_MENU_CLOSED;
|
|
return 1;
|
|
}
|
|
unsigned direction = pressed & (LEFT | RIGHT);
|
|
if (save_menu.phase == SAVE_MENU_TEAM && partner_owned &&
|
|
(direction == LEFT || direction == RIGHT)) {
|
|
int members = caught_count + 1;
|
|
team_member = (team_member + (direction == RIGHT ? 1 : members - 1)) % members;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
if (pressed & B) {
|
|
save_menu.phase = SAVE_MENU_CLOSED;
|
|
return 1;
|
|
}
|
|
if (save_menu.phase != SAVE_MENU_OPTIONS) {
|
|
if (!(pressed & A)) return 0;
|
|
save_menu.phase = SAVE_MENU_CLOSED;
|
|
return 1;
|
|
}
|
|
if (pressed & A) {
|
|
if (save_menu.selection == MENU_CLOSE) save_menu.phase = SAVE_MENU_CLOSED;
|
|
else if (save_menu.selection == MENU_SAVE)
|
|
save_menu.phase = save_progress(location) ? SAVE_MENU_SAVED : SAVE_MENU_FAILED;
|
|
else {
|
|
team_parent = 1;
|
|
team_member = 0;
|
|
save_menu.phase = save_menu.selection == MENU_TEAM ? SAVE_MENU_TEAM : SAVE_MENU_BAG;
|
|
}
|
|
return 1;
|
|
}
|
|
unsigned direction = pressed & (UP | DOWN);
|
|
if (direction == UP || direction == DOWN) {
|
|
save_menu.selection = (save_menu.selection + (direction == DOWN ? 1 : MENU_COUNT - 1)) % MENU_COUNT;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void draw_menu_scene(int x, int y)
|
|
{
|
|
if (save_menu.phase == SAVE_MENU_TEAM) draw_team_member(team_member);
|
|
else if (save_menu.phase == SAVE_MENU_BAG) draw_bag();
|
|
else {
|
|
draw_scene(x, y);
|
|
if (save_menu.phase != SAVE_MENU_CLOSED) draw_save_menu();
|
|
}
|
|
}
|
|
|
|
int menu_redraw_is_panel(enum SaveMenuPhase before, enum SaveMenuPhase after)
|
|
{
|
|
return before >= SAVE_MENU_OPTIONS && before <= SAVE_MENU_FAILED &&
|
|
after >= SAVE_MENU_OPTIONS && after <= SAVE_MENU_FAILED;
|
|
}
|
|
|
|
void draw_save_menu(void)
|
|
{
|
|
u16 ink = RGB(5, 8, 11), cream = RGB(30, 30, 26);
|
|
int x = SAVE_MENU_X, y = SAVE_MENU_Y;
|
|
rectangle(x, y, SAVE_MENU_W, SAVE_MENU_H, ink);
|
|
rectangle(x + 2, y + 2, SAVE_MENU_W - 4, SAVE_MENU_H - 4, cream);
|
|
large_text(x + 16, y + 10, "MENU", ink);
|
|
rectangle(x + 6, y + 23, SAVE_MENU_W - 12, 1, RGB(15, 24, 20));
|
|
text(x + 8, y + 99, "SAVES TEAM", ink);
|
|
text(x + 8, y + 108, "ITEMS AND", ink);
|
|
text(x + 8, y + 117, "LOCATION", ink);
|
|
if (save_menu.phase == SAVE_MENU_OPTIONS) {
|
|
int selected_y = y + 28 + save_menu.selection * 16;
|
|
rectangle(x + 6, selected_y, SAVE_MENU_W - 12, 16, RGB(23, 28, 21));
|
|
rectangle(x + 10, selected_y + 5, 1, 5, ink);
|
|
rectangle(x + 11, selected_y + 6, 1, 3, ink);
|
|
rectangle(x + 12, selected_y + 7, 1, 1, ink);
|
|
static const char *const labels[] = {"TEAM", "BAG", "SAVE", "CLOSE"};
|
|
for (int i = 0; i < MENU_COUNT; ++i) large_text(x + 20, y + 33 + i * 16, labels[i], ink);
|
|
text(x + 8, y + 126, "UP DOWN", ink);
|
|
text(x + 8, y + 133, "A SELECT", ink);
|
|
text(x + 8, y + 142, "B START CLOSE", ink);
|
|
} else {
|
|
int saved = save_menu.phase == SAVE_MENU_SAVED;
|
|
large_text(x + 16, y + 37, saved ? "GAME" : "SAVE", ink);
|
|
large_text(x + 16, y + 55, saved ? "SAVED" : "FAILED", ink);
|
|
text(x + 8, y + 126, "A B START", ink);
|
|
text(x + 8, y + 136, "TO CLOSE", ink);
|
|
}
|
|
}
|