diff --git a/include/arm9/console.h b/include/arm9/console.h index 9cfc256..e7deca8 100644 --- a/include/arm9/console.h +++ b/include/arm9/console.h @@ -181,6 +181,8 @@ void drawConsoleWindow(PrintConsole* console, int thickness, u8 colorIndex); +u16 consoleGetRGB565Color(u8 colorIndex); + #ifdef __cplusplus } #endif diff --git a/include/arm9/ui.h b/include/arm9/ui.h index d6b4931..1f3c102 100644 --- a/include/arm9/ui.h +++ b/include/arm9/ui.h @@ -18,12 +18,12 @@ void clearConsole(int which); void uiSetVerboseMode(bool verb); bool uiGetVerboseMode(); -bool uiDialogYesNo(const char *textYes, const char *textNo, const char *const format, ...); +bool uiDialogYesNo(int screen, const char *textYes, const char *textNo, const char *const format, ...); void uiPrintIfVerbose(const char *const format, ...); void uiPrint(const char *const format, unsigned int color, bool centered, ...); void uiPrintCenteredInLine(unsigned int y, const char *const format, ...); void uiPrintTextAt(unsigned int x, unsigned int y, const char *const format, ...); -u32 uiShowMessageWindow(const char *const format, const char *const lastLine, u32 waitKeys, +u32 uiDialog(const char *const format, const char *const lastLine, u32 waitKeys, int screen, unsigned int x, unsigned int y, bool centered, ...); void uiPrintProgressBar(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int cur, unsigned int max); diff --git a/source/arm9/console.c b/source/arm9/console.c index a4e6aa4..e3d8120 100644 --- a/source/arm9/console.c +++ b/source/arm9/console.c @@ -3,6 +3,7 @@ #include #include "types.h" #include "gfx.h" +#include "util.h" #include "arm9/console.h" #include "default_font_bin.h" @@ -772,3 +773,9 @@ console->cursorX = x; console->cursorY = y; } + +u16 consoleGetRGB565Color(u8 colorIndex) { + if(colorIndex >= arrayEntries(colorTable)) + return 0; + return colorTable[colorIndex]; +} diff --git a/source/arm9/menu_firmloader.c b/source/arm9/menu_firmloader.c index bc26702..d2dc4d1 100644 --- a/source/arm9/menu_firmloader.c +++ b/source/arm9/menu_firmloader.c @@ -107,7 +107,7 @@ bool tryLoadFirmwareFromSettings(bool fromMenu) { const char *path; - int keyBootOption, keyBootMode, keyPad; + int keyBootOption, bootMode, keyPad; int i; u32 padValue, expectedPadValue; @@ -136,7 +136,7 @@ } const u32 *temp = configGetData(KBootMode); - keyBootMode = temp? *temp : BootModeNormal; + bootMode = temp? *temp : BootModeNormal; keyBootOption = KBootOption1; keyPad = KBootOption1Buttons; @@ -199,7 +199,7 @@ break; else { - if(keyBootMode == BootModeNormal) + if(bootMode != BootModeQuiet) uiPrintBootWarning(); } } @@ -219,7 +219,7 @@ { if(fromMenu) menuSetReturnToState(STATE_PREVIOUS); - else if(keyBootMode == BootModeNormal) + else if(bootMode != BootModeQuiet) uiPrintBootFailure(); return false; } diff --git a/source/arm9/menu_nand.c b/source/arm9/menu_nand.c index 7dd50c5..b8017e6 100644 --- a/source/arm9/menu_nand.c +++ b/source/arm9/menu_nand.c @@ -25,9 +25,6 @@ UINT bytesWritten; u64 bytesFree; - uiClearConsoles(); - consoleSelect(&con_top); - u8 *buf = (u8*)malloc(sectorBlkSize<<9); if(!buf) { // this should never happen. @@ -35,6 +32,9 @@ return false; } + uiClearConsoles(); + consoleSelect(&con_top); + uiPrintCenteredInLine(1, "NAND Backup"); uiPrintTextAt(0, 3, "Checking free space on SD card...\n"); @@ -124,7 +124,7 @@ f_close(&file); free(buf); - uiShowMessageWindow("Finished!\nPress any key to return.", NULL, HID_KEY_MASK_ALL, 1, 0, 0, true); + uiDialog("Finished!\nPress any key to return.", NULL, HID_KEY_MASK_ALL, 1, 0, 0, true); menuSetReturnToState(STATE_PREVIOUS); @@ -146,19 +146,18 @@ const u32 sectorBlkSize = 0x400; // 512 KB in sectors FIL file; UINT bytesRead; - - uiClearConsoles(); - consoleSelect(&con_top); - uiPrintCenteredInLine(1, "NAND Restore"); - u8 *buf = (u8*)malloc(sectorBlkSize<<9); if(!buf) { // this should never happen. uiPrintIfVerbose("Out of memory!"); return false; } - + + uiClearConsoles(); + consoleSelect(&con_top); + + uiPrintCenteredInLine(1, "NAND Restore"); uiPrintTextAt(0, 3, "Checking backup file...\n"); @@ -312,7 +311,7 @@ partitionGetSectorOffset(index, §or); - if(!uiDialogYesNo("Proceed", "Cancel", "Flash firmware to %s?", partName)) + if(!uiDialogYesNo(1, "Proceed", "Cancel", "Flash firmware to %s?", partName)) { goto fail; } diff --git a/source/arm9/ui.c b/source/arm9/ui.c index 841f026..42396e8 100644 --- a/source/arm9/ui.c +++ b/source/arm9/ui.c @@ -93,9 +93,10 @@ } /* TODO: Should look similar to uiShowMessageWindow */ -bool uiDialogYesNo(const char *textYes, const char *textNo, const char *const format, ...) +bool uiDialogYesNo(int screen, const char *textYes, const char *textNo, const char *const format, ...) { char tmp[256]; + char lastline[256]; u32 keys; va_list args; @@ -103,19 +104,17 @@ vsnprintf(tmp, 256, format, args); va_end(args); - /* Print dialog */ - uiPrintInfo("\n%s\n", tmp); - uiPrintInfo("\t(A): %s\n\t(B): %s\n", textYes, textNo); + snprintf(lastline, 256, "(A): %s (B): %s", textYes, textNo); - /* Get user input */ - do { - hidScanInput(); - keys = hidKeysDown() & HID_KEY_MASK_ALL; - if(keys == KEY_A) - return true; - if(keys & KEY_B) - return false; - } while(1); + /* Print dialog */ + keys = uiDialog(tmp, lastline, KEY_A | KEY_B, screen, 0, 0, true); + + /* Evaluate user input */ + if(keys == KEY_A) + return true; + + // KEY_B + return false; } void uiPrintIfVerbose(const char *const format, ...) @@ -188,8 +187,8 @@ /* centered in the middle of the screen. */ /* Waits for the user to press any button, after that the */ /* original framebuffer gets restored */ -u32 uiShowMessageWindow(const char *const format, const char *const lastLine, u32 waitKeys, - int screen, unsigned int x, unsigned int y, bool centered, ...) +u32 uiDialog(const char *const format, const char *const lastLine, u32 waitKeys, + int screen, unsigned int x, unsigned int y, bool centered, ...) { char tmp[256]; @@ -199,7 +198,7 @@ va_end(args); char *ptr = tmp; - unsigned int lines = 5, longestLine = 2, curLen = 2; + unsigned int lines = lastLine ? 5 : 3, longestLine = 2, curLen = 2; while(*ptr) { switch(*ptr) @@ -251,7 +250,7 @@ if(lastLine) printf("\x1b[%u;%uH%s", lines - 2, (longestLine - strlen(lastLine)) / 2, lastLine); - const u16 color = consoleGetFgColor(); + const u16 color = consoleGetRGB565Color(randomColor); for(u32 xx = x * 8 + 1; xx < x * 8 + (longestLine * 8) - 1; xx++) { fb[xx * SCREEN_HEIGHT_SUB + (y * 8)] = color;