diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index 38be6ec..56b2535 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -145,6 +145,22 @@ void DrawStringF(u8* screen, int x, int y, int color, int bgcolor, const char *f DrawString(screen, text, x, y, color, bgcolor); } +void DrawStringCenter(u8* screen, int color, int bgcolor, const char *format, ...) +{ + char str[STRBUF_SIZE] = { 0 }; + va_list va; + va_start(va, format); + vsnprintf(str, STRBUF_SIZE, format, va); + va_end(va); + + u32 w = GetDrawStringWidth(str); + u32 h = GetDrawStringHeight(str); + int x = (w >= SCREEN_WIDTH(screen)) ? 0 : (SCREEN_WIDTH(screen) - w) >> 1; + int y = (h >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - h) >> 1; + + DrawStringF(screen, x, y, color, bgcolor, str); +} + u32 GetDrawStringHeight(const char* str) { u32 height = FONT_HEIGHT; for (char* lf = strchr(str, '\n'); (lf != NULL); lf = strchr(lf + 1, '\n')) @@ -238,22 +254,14 @@ void FormatBytes(char* str, u64 bytes) { // str should be 32 byte in size, just void ShowString(const char *format, ...) { if (format && *format) { // only if there is something in there - u32 str_width, str_height; - u32 x, y; - char str[STRBUF_SIZE] = { 0 }; va_list va; va_start(va, format); vsnprintf(str, STRBUF_SIZE, format, va); va_end(va); - str_width = GetDrawStringWidth(str); - str_height = GetDrawStringHeight(str); - x = (str_width >= SCREEN_WIDTH_MAIN) ? 0 : (SCREEN_WIDTH_MAIN - str_width) / 2; - y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2; - ClearScreenF(true, false, COLOR_STD_BG); - DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); + DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, str); } else ClearScreenF(true, false, COLOR_STD_BG); } @@ -286,8 +294,6 @@ void ShowIconString(u8* icon, int w, int h, const char *format, ...) bool ShowPrompt(bool ask, const char *format, ...) { - u32 str_width, str_height; - u32 x, y; bool ret = true; char str[STRBUF_SIZE] = { 0 }; @@ -296,15 +302,9 @@ bool ShowPrompt(bool ask, const char *format, ...) vsnprintf(str, STRBUF_SIZE, format, va); va_end(va); - str_width = GetDrawStringWidth(str); - str_height = GetDrawStringHeight(str) + (2 * 10); - if (str_width < 18 * FONT_WIDTH) str_width = 18 * FONT_WIDTH; - x = (str_width >= SCREEN_WIDTH_MAIN) ? 0 : (SCREEN_WIDTH_MAIN - str_width) / 2; - y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2; - ClearScreenF(true, false, COLOR_STD_BG); - DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); - DrawStringF(MAIN_SCREEN, x, y + str_height - (1*10), COLOR_STD_FONT, COLOR_STD_BG, (ask) ? "( yes, no)" : "( to continue)"); + DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s\n \n%s", str, + (ask) ? "( yes, no)" : "( to continue)"); while (true) { u32 pad_state = InputWait(0); @@ -483,7 +483,7 @@ bool ShowInputPrompt(char* inputstr, u32 max_size, u32 resize, const char* alpha char str[STRBUF_SIZE] = { 0 }; vsnprintf(str, STRBUF_SIZE, format, va); - // check / fix up the inputstring if required + // check / fix up the input string if required if (max_size < 2) return false; // catching this, too if ((*inputstr == '\0') || (resize && (strnlen(inputstr, max_size - 1) % resize))) { memset(inputstr, alphabet[0], resize); // set the string if it is not set or invalid diff --git a/arm9/source/common/ui.h b/arm9/source/common/ui.h index 9598d29..ee66126 100644 --- a/arm9/source/common/ui.h +++ b/arm9/source/common/ui.h @@ -58,6 +58,7 @@ void DrawQrCode(u8* screen, u8* qrcode); void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor); void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor); void DrawStringF(unsigned char *screen, int x, int y, int color, int bgcolor, const char *format, ...); +void DrawStringCenter(u8* screen, int color, int bgcolor, const char *format, ...); u32 GetDrawStringHeight(const char* str); u32 GetDrawStringWidth(const char* str); diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index 73398f5..d921c7f 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -12,6 +12,7 @@ #include "sha.h" #include "hid.h" #include "ui.h" +#include "pcx.h" #define _MAX_ARGS 4 @@ -255,9 +256,9 @@ static inline u32 get_lno(const char* text, u32 len, const char* line) { void set_preview(const char* name, const char* content) { if (strncmp(name, "PREVIEW_MODE", _VAR_NAME_LEN) == 0) { - if (strncasecmp(content, "off", _VAR_CNT_LEN) == 0) preview_mode = 0; - else if (strncasecmp(content, "quick", _VAR_CNT_LEN) == 0) preview_mode = 1; + if (strncasecmp(content, "quick", _VAR_CNT_LEN) == 0) preview_mode = 1; else if (strncasecmp(content, "full", _VAR_CNT_LEN) == 0) preview_mode = 2; + else preview_mode = 0xFF; // unknown preview mode } else if (strncmp(name, "PREVIEW_COLOR_ACTIVE", _VAR_NAME_LEN) == 0) { u8 rgb[4] = { 0 }; if (strntohex(content, rgb, 3)) @@ -1327,21 +1328,33 @@ bool ExecuteGM9Script(const char* path_script) { // update script viewer if (MAIN_SCREEN != TOP_SCREEN) { - bool show_preview = preview_mode; if (preview_mode != preview_mode_local) { - if (!preview_mode || !preview_mode_local) ClearScreen(TOP_SCREEN, COLOR_STD_BG); - if (!preview_mode) DrawString(TOP_SCREEN, "(preview disabled)", - (SCREEN_WIDTH_TOP - (18*FONT_WIDTH_EXT)) / 2, - (SCREEN_HEIGHT - FONT_HEIGHT_EXT) / 2, - COLOR_STD_FONT, COLOR_STD_BG); + if (!preview_mode || (preview_mode > 2) || !preview_mode_local) + ClearScreen(TOP_SCREEN, COLOR_STD_BG); + if (preview_mode > 2) { + char* preview_str = get_var("PREVIEW_MODE", NULL); + u8* pcx = TEMP_BUFFER + TEMP_BUFFER_SIZE / 2; + u32 pcx_size = FileGetData(preview_str, pcx, TEMP_BUFFER_SIZE / 2, 0); + if ((pcx_size > 0) && (pcx_size < TEMP_BUFFER_SIZE / 2) && + (PCX_Decompress(TEMP_BUFFER, TEMP_BUFFER_SIZE / 2, pcx, pcx_size))) { + PCXHdr* hdr = (PCXHdr*) (void*) pcx; + DrawBitmap(TOP_SCREEN, -1, -1, PCX_Width(hdr), PCX_Height(hdr), TEMP_BUFFER); + } else { + if (strncmp(preview_str, "off", _VAR_CNT_LEN) == 0) preview_str = "(preview disabled)"; + DrawStringCenter(TOP_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, preview_str); + } + preview_mode = 0; + } preview_mode_local = preview_mode; } + + bool show_preview = preview_mode; if (preview_mode == 1) { show_preview = false; for (char* c = ptr; (c < line_end) && !show_preview; c++) { - // check for comments + // check for comments / labels if (IS_WHITESPACE(*c)) continue; - else if (*c == '#') break; + else if ((*c == '#') || (*c == '@')) break; else show_preview = true; } }