Skip to content

Commit

Permalink
Clean up menus some more
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightkingale committed May 5, 2024
1 parent 7761610 commit 8f078c7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
9 changes: 6 additions & 3 deletions source/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void handle_cleanup(FILE* account, FILE* backup, char* buffer, bool is_error = f
}


void write_backup(FILE* account, const std::string& backup_path, char* buffer) {
bool write_backup(FILE* account, const std::string& backup_path, char* buffer) {
// Create the directories if they don't exist.
std::filesystem::path dirPath = std::filesystem::path(backup_path).remove_filename();
std::filesystem::create_directories(dirPath);
Expand All @@ -58,7 +58,7 @@ void write_backup(FILE* account, const std::string& backup_path, char* buffer) {
if (backup == NULL) {
draw_error_menu("Error opening backup account.dat file!");
handle_cleanup(account, backup, buffer, true);
return;
return false;
}

// Open the backup file and write the account data to it.
Expand All @@ -72,6 +72,7 @@ void write_backup(FILE* account, const std::string& backup_path, char* buffer) {
fclose(backup);

draw_success_menu("backup");
return true;
}


Expand Down Expand Up @@ -142,7 +143,9 @@ bool backup_account() {
}
// Write the backup file.
if (backup_confirm) {
write_backup(account, backup_path, buffer);
if (write_backup(account, backup_path, buffer))
handle_cleanup(account, NULL, buffer, false);
return true;
}

handle_cleanup(account, NULL, buffer, !backup_confirm);
Expand Down
3 changes: 3 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ int main() {
draw_menu_screen(selected_option);

int button = read_input(); // Watch the controllers for input.
OSEnableHomeButtonMenu(1);

if (button == VPAD_BUTTON_UP) {
selected_option--;
Expand All @@ -181,6 +182,7 @@ int main() {
break;
case 2:
while (WHBProcIsRunning()) {
OSEnableHomeButtonMenu(0);
draw_backup_menu();
button = read_input();

Expand All @@ -192,6 +194,7 @@ int main() {
}
break;
case 3:
OSEnableHomeButtonMenu(0);
while (WHBProcIsRunning()) {
draw_unlink_menu();
button = read_input();
Expand Down
43 changes: 24 additions & 19 deletions source/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ void draw_screen_bars() {
}


void draw_confirm_button(const char* text) {
draw_rectangle(64, 760, 896, 100, 100, 100, 255, 255);
draw_rectangle(69, 765, 886, 90, 0, 0, 0, 255);
draw_text(text, 93, 780, 50);
void draw_confirm_button() {
int button_width = get_text_width("Confirm", 50) + 100;
int button_x = (1920 - button_width) / 2;

draw_rectangle(button_x, 760, button_width, 100, 100, 100, 255, 255);
draw_rectangle(button_x + 5, 765, button_width - 10, 90, 0, 0, 0, 255);
draw_text("Confirm", button_x + 50, 780, 50);
}


Expand All @@ -107,15 +110,18 @@ void draw_menu_screen(int selected_menu_item) {
"Switch to Nintendo Network ID",
"Switch to Pretendo Network ID",
"Backup Current Account",
"Unlink Network ID (Local-Only)"
"Unlink Account Locally"
};
const int NUM_MENU_ITEMS = sizeof(menu_options) / sizeof(menu_options[0]);

for (int i = 0; i < NUM_MENU_ITEMS; i++) {
if (i == selected_menu_item) {
// Draw black rectangle with blue border behind selected option
draw_rectangle(64, 135 + i * 120, 1797, 110, 100, 100, 255, 255); // blue border
draw_rectangle(69, 140 + i * 120, 1787, 100, 0, 0, 0, 255); // black rectangle
draw_rectangle(64, 135 + i * 120, 1797, 110, 100, 100, 255, 255); // Blue border.
draw_rectangle(69, 140 + i * 120, 1787, 100, 0, 0, 0, 255); // Black rectangle.

draw_text("A", 1800, 160 + i * 120, 50, {100, 100, 255, 255});
} else {
draw_rectangle(69, 140 + i * 120, 1787, 100, 25, 25, 25, 255); // Gray rectangle.
}
draw_text(menu_options[i], 93, 160 + i * 120, 50);
}
Expand All @@ -128,7 +134,7 @@ void draw_unlink_menu() {
draw_background(16, 16, 16, 255);
draw_screen_bars();

draw_text("Unlinking: Please read the following and confirm!", 64, 160, 50, {176, 176, 176, 255});
draw_text("Unlinking: Please read the following and confirm!", 64, 160, 50);

draw_text("This will unlink your Network ID from this user.", 64, 270, 50);
draw_text("You can reattach this account to any user on this Wii U,", 64, 330, 50);
Expand All @@ -137,7 +143,7 @@ void draw_unlink_menu() {
draw_text("However, this unlink will not take place on the server.", 64, 510, 50);
draw_text("You won't be able to use this account on any other Wii U.", 64, 570, 50);

draw_confirm_button("Confirm Unlink");
draw_confirm_button();

SDL_RenderPresent(renderer);
}
Expand All @@ -147,7 +153,7 @@ void draw_backup_menu() {
draw_background(16, 16, 16, 255);
draw_screen_bars();

draw_text("Backup: Please read the following and confirm!", 64, 160, 50, {176, 176, 176, 255});
draw_text("Backup: Please read the following and confirm!", 64, 160, 50);

draw_text("This will backup your current account.dat file.", 64, 270, 50);
draw_text("The account.dat may contain sensitive personal", 64, 330, 50);
Expand All @@ -156,7 +162,7 @@ void draw_backup_menu() {

draw_text("Please do not share these backups with anyone else!", 64, 560, 50);

draw_confirm_button("Confirm Backup");
draw_confirm_button();

SDL_RenderPresent(renderer);
}
Expand All @@ -173,31 +179,30 @@ void draw_overwrite_menu(const char* backup_path) {

draw_text("Are you sure you want to overwrite this file?", 64, 440, 50);

draw_confirm_button("Confirm Overwrite");
draw_confirm_button();

SDL_RenderPresent(renderer);
}


void draw_error_menu(const char* error_message) {
draw_background(0, 0, 30, 255);
draw_background(90, 10, 10, 255);
draw_screen_bars();

draw_text("Error: An error has occurred!", 64, 160, 50, {176, 176, 176, 255});
draw_text("An exception has occurred!", 64, 160, 50);

draw_text(error_message, 64, 270, 50);

draw_text("You will return to the main menu.", 64, 390, 50);
draw_text("You will return to the main menu.", 64, 330, 50);

SDL_RenderPresent(renderer);
OSSleepTicks(OSMillisecondsToTicks(5000));
}

void draw_success_menu(const char* type, bool inkay_configured = false) {
draw_background(0, 30, 0, 255);
draw_background(10, 60, 10, 255);
draw_screen_bars();

draw_text("Success: The operation was successful!", 64, 160, 50, {176, 176, 176, 255});
draw_text("The operation was successful!", 64, 160, 50);

if (strcmp(type, "backup") == 0) {
draw_text("Your account.dat file has been backed up.", 64, 270, 50);
Expand Down
1 change: 0 additions & 1 deletion source/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


void handle_cleanup(FILE* backup, const char* account_type, char* buffer, bool is_error = false) {
OSSleepTicks(OSMillisecondsToTicks(5000));
OSEnableHomeButtonMenu(1);

// Free the buffer.
Expand Down

0 comments on commit 8f078c7

Please sign in to comment.