mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 05:32:47 +00:00
Allow game icons as preview for scripting
This commit is contained in:
parent
0e701ea719
commit
1633961707
@ -376,8 +376,9 @@ void FormatBytes(char* str, u64 bytes) { // str should be 32 byte in size, just
|
||||
}
|
||||
}
|
||||
|
||||
void ShowString(const char *format, ...)
|
||||
void ShowStringF(u16* screen, const char *format, ...)
|
||||
{
|
||||
ClearScreen(MAIN_SCREEN, COLOR_STD_BG);
|
||||
if (format && *format) { // only if there is something in there
|
||||
char str[STRBUF_SIZE];
|
||||
va_list va;
|
||||
@ -385,18 +386,31 @@ void ShowString(const char *format, ...)
|
||||
vsnprintf(str, STRBUF_SIZE, format, va);
|
||||
va_end(va);
|
||||
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||
} else ClearScreenF(true, false, COLOR_STD_BG);
|
||||
DrawStringCenter(screen, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowIconString(u16* icon, int w, int h, const char *format, ...)
|
||||
void ShowString(const char *format, ...)
|
||||
{
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
if (format && *format) { // only if there is something in there
|
||||
char str[STRBUF_SIZE];
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vsnprintf(str, STRBUF_SIZE, format, va);
|
||||
va_end(va);
|
||||
|
||||
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowIconStringF(u16* screen, u16* icon, int w, int h, const char *format, ...)
|
||||
{
|
||||
static const u32 icon_offset = 10;
|
||||
u32 str_width, str_height, tot_height;
|
||||
u32 x_str, y_str, x_bmp, y_bmp;
|
||||
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
ClearScreen(screen, COLOR_STD_BG);
|
||||
if (!format || !*format) return; // only if there is something in there
|
||||
|
||||
char str[STRBUF_SIZE];
|
||||
@ -408,13 +422,24 @@ void ShowIconString(u16* icon, int w, int h, const char *format, ...)
|
||||
str_width = GetDrawStringWidth(str);
|
||||
str_height = GetDrawStringHeight(str);
|
||||
tot_height = h + icon_offset + str_height;
|
||||
x_str = (str_width >= SCREEN_WIDTH_MAIN) ? 0 : (SCREEN_WIDTH_MAIN - str_width) / 2;
|
||||
x_str = (str_width >= SCREEN_WIDTH(screen)) ? 0 : (SCREEN_WIDTH(screen) - str_width) / 2;
|
||||
y_str = (str_height >= SCREEN_HEIGHT) ? 0 : h + icon_offset + (SCREEN_HEIGHT - tot_height) / 2;
|
||||
x_bmp = (w >= SCREEN_WIDTH_MAIN) ? 0 : (SCREEN_WIDTH_MAIN - w) / 2;
|
||||
x_bmp = (w >= SCREEN_WIDTH(screen)) ? 0 : (SCREEN_WIDTH(screen) - w) / 2;
|
||||
y_bmp = (tot_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - tot_height) / 2;
|
||||
|
||||
DrawBitmap(MAIN_SCREEN, x_bmp, y_bmp, w, h, icon);
|
||||
DrawStringF(MAIN_SCREEN, x_str, y_str, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||
DrawBitmap(screen, x_bmp, y_bmp, w, h, icon);
|
||||
DrawStringF(screen, x_str, y_str, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
|
||||
}
|
||||
|
||||
void ShowIconString(u16* icon, int w, int h, const char *format, ...)
|
||||
{
|
||||
char str[STRBUF_SIZE];
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vsnprintf(str, STRBUF_SIZE, format, va);
|
||||
va_end(va);
|
||||
|
||||
ShowIconStringF(MAIN_SCREEN, icon, w, h, str);
|
||||
}
|
||||
|
||||
bool ShowPrompt(bool ask, const char *format, ...)
|
||||
|
@ -74,7 +74,9 @@ void FormatNumber(char* str, u64 number);
|
||||
void FormatBytes(char* str, u64 bytes);
|
||||
|
||||
void ShowString(const char *format, ...);
|
||||
void ShowStringF(u16* screen, const char *format, ...);
|
||||
void ShowIconString(u16* icon, int w, int h, const char *format, ...);
|
||||
void ShowIconStringF(u16* screen, u16* icon, int w, int h, const char *format, ...);
|
||||
bool ShowPrompt(bool ask, const char *format, ...);
|
||||
u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...);
|
||||
u32 ShowFileScrollPrompt(u32 n, const DirEntry** entries, bool hide_ext, const char *format, ...);
|
||||
|
@ -1908,7 +1908,7 @@ u32 LoadSmdhFromGameFile(const char* path, Smdh* smdh) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 ShowSmdhTitleInfo(Smdh* smdh) {
|
||||
u32 ShowSmdhTitleInfo(Smdh* smdh, u16* screen) {
|
||||
const u8 smdh_magic[] = { SMDH_MAGIC };
|
||||
const u32 lwrap = 24;
|
||||
u16 icon[SMDH_SIZE_ICON_BIG / sizeof(u16)];
|
||||
@ -1924,13 +1924,11 @@ u32 ShowSmdhTitleInfo(Smdh* smdh) {
|
||||
WordWrapString(desc_l, lwrap);
|
||||
WordWrapString(desc_s, lwrap);
|
||||
WordWrapString(pub, lwrap);
|
||||
ShowIconString(icon, SMDH_DIM_ICON_BIG, SMDH_DIM_ICON_BIG, "%s\n%s\n%s", desc_l, desc_s, pub);
|
||||
while(!(InputWait(0) & (BUTTON_A | BUTTON_B)));
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
ShowIconStringF(screen, icon, SMDH_DIM_ICON_BIG, SMDH_DIM_ICON_BIG, "%s\n%s\n%s", desc_l, desc_s, pub);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 ShowTwlIconTitleInfo(TwlIconData* twl_icon) {
|
||||
u32 ShowTwlIconTitleInfo(TwlIconData* twl_icon, u16* screen) {
|
||||
const u32 lwrap = 24;
|
||||
u16 icon[TWLICON_SIZE_ICON / sizeof(u16)];
|
||||
char desc[TWLICON_SIZE_DESC+1];
|
||||
@ -1938,24 +1936,19 @@ u32 ShowTwlIconTitleInfo(TwlIconData* twl_icon) {
|
||||
(GetTwlTitle(desc, twl_icon) != 0))
|
||||
return 1;
|
||||
WordWrapString(desc, lwrap);
|
||||
ShowIconString(icon, TWLICON_DIM_ICON, TWLICON_DIM_ICON, "%s", desc);
|
||||
while(!(InputWait(0) & (BUTTON_A | BUTTON_B)));
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
ShowIconStringF(screen, icon, TWLICON_DIM_ICON, TWLICON_DIM_ICON, "%s", desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 ShowGbaFileTitleInfo(const char* path) {
|
||||
u32 ShowGbaFileTitleInfo(const char* path, u16* screen) {
|
||||
AgbHeader agb;
|
||||
if ((fvx_qread(path, &agb, 0, sizeof(AgbHeader), NULL) != FR_OK) ||
|
||||
(ValidateAgbHeader(&agb) != 0)) return 1;
|
||||
ShowString("%.12s (AGB-%.4s)\n%s", agb.game_title, agb.game_code, AGB_DESTSTR(agb.game_code));
|
||||
while(!(InputWait(0) & (BUTTON_A | BUTTON_B)));
|
||||
ClearScreenF(true, false, COLOR_STD_BG);
|
||||
ShowStringF(screen, "%.12s (AGB-%.4s)\n%s", agb.game_title, agb.game_code, AGB_DESTSTR(agb.game_code));
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
u32 ShowGameFileTitleInfo(const char* path) {
|
||||
u32 ShowGameFileTitleInfoF(const char* path, u16* screen, bool clear) {
|
||||
char path_content[256];
|
||||
u64 itype = IdentifyFileType(path); // initial type
|
||||
if (itype & GAME_TMD) {
|
||||
@ -1970,16 +1963,25 @@ u32 ShowGameFileTitleInfo(const char* path) {
|
||||
// try loading SMDH, then try NDS / GBA
|
||||
u32 ret = 1;
|
||||
if (LoadSmdhFromGameFile(path, smdh) == 0)
|
||||
ret = ShowSmdhTitleInfo(smdh);
|
||||
ret = ShowSmdhTitleInfo(smdh, screen);
|
||||
else if ((LoadTwlMetaData(path, NULL, twl_icon) == 0) ||
|
||||
((itype & GAME_TAD) && (fvx_qread(path, twl_icon, TAD_BANNER_OFFSET, sizeof(TwlIconData), NULL) == FR_OK)))
|
||||
ret = ShowTwlIconTitleInfo(twl_icon);
|
||||
else ret = ShowGbaFileTitleInfo(path);
|
||||
ret = ShowTwlIconTitleInfo(twl_icon, screen);
|
||||
else ret = ShowGbaFileTitleInfo(path, screen);
|
||||
|
||||
if (clear) {
|
||||
while(!(InputWait(0) & (BUTTON_A | BUTTON_B)));
|
||||
ClearScreen(screen, COLOR_STD_BG);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 ShowGameFileTitleInfo(const char* path) {
|
||||
return ShowGameFileTitleInfoF(path, MAIN_SCREEN, true);
|
||||
}
|
||||
|
||||
u32 ShowCiaCheckerInfo(const char* path) {
|
||||
CiaStub* cia = (CiaStub*) malloc(sizeof(CiaStub));
|
||||
if (!cia) return 1;
|
||||
|
@ -11,6 +11,7 @@ u32 ExtractCodeFromCxiFile(const char* path, const char* path_out, char* extstr)
|
||||
u32 CompressCode(const char* path, const char* path_out);
|
||||
u64 GetGameFileTrimmedSize(const char* path);
|
||||
u32 TrimGameFile(const char* path);
|
||||
u32 ShowGameFileTitleInfoF(const char* path, u16* screen, bool clear);
|
||||
u32 ShowGameFileTitleInfo(const char* path);
|
||||
u32 ShowCiaCheckerInfo(const char* path);
|
||||
u32 GetTmdContentPath(char* path_content, const char* path_tmd);
|
||||
|
@ -1858,7 +1858,7 @@ bool ExecuteGM9Script(const char* path_script) {
|
||||
if (bitmap) {
|
||||
DrawBitmap(TOP_SCREEN, -1, -1, bitmap_width, bitmap_height, bitmap);
|
||||
free(bitmap);
|
||||
} else {
|
||||
} else if (ShowGameFileTitleInfoF(preview_str, TOP_SCREEN, false) != 0) {
|
||||
if (strncmp(preview_str, "off", _VAR_CNT_LEN) == 0) preview_str = "(preview disabled)";
|
||||
DrawStringCenter(TOP_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s", preview_str);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user