Added maximum length for dialogs

This commit is contained in:
cxziaho 2017-09-19 14:37:43 +12:00
parent c8ec848b15
commit e3f52ccac7
3 changed files with 28 additions and 6 deletions

1
main.h
View File

@ -155,6 +155,7 @@
#define MAX_NAME_WIDTH 500.0f
// Uncommon dialog
#define UNCOMMON_DIALOG_MAX_WIDTH 800
#define UNCOMMON_DIALOG_PROGRESS_BAR_BOX_WIDTH 420.0f
#define UNCOMMON_DIALOG_PROGRESS_BAR_HEIGHT 8.0f
#define MSG_DIALOG_MODE_QR_SCAN 10

4
qr.c
View File

@ -264,8 +264,8 @@ NETWORK_FAILURE:
sceKernelDelayThread(10 * 1000);
}
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_OK, language_container[QR_SHOW_CONTENTS], data);
setDialogStep(DIALOG_STEP_QR_SHOW_CONTENTS);
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[QR_OPEN_WEBSITE], data);
setDialogStep(DIALOG_STEP_QR_OPEN_WEBSITE);
return sceKernelExitDeleteThread(0);
}

View File

@ -45,7 +45,9 @@ static UncommonDialog uncommon_dialog;
static void calculateDialogBoxSize() {
int len = strlen(uncommon_dialog.msg);
char *string = uncommon_dialog.msg;
char *tempstr = "";
float text_width = 0;
// Get width and height
uncommon_dialog.width = 0.0f;
uncommon_dialog.height = 0.0f;
@ -58,22 +60,41 @@ static void calculateDialogBoxSize() {
float width = vita2d_pgf_text_width(font, FONT_SIZE, string);
if (width > uncommon_dialog.width)
uncommon_dialog.width = width;
uncommon_dialog.msg[i] = '\n';
string = uncommon_dialog.msg + i;
uncommon_dialog.height += FONT_Y_SPACE;
}
if (uncommon_dialog.msg[i] == '\0') {
float width = vita2d_pgf_text_width(font, FONT_SIZE, string);
if (width > uncommon_dialog.width)
uncommon_dialog.width = width;
}
uncommon_dialog.height += FONT_Y_SPACE;
tempstr = strdup(uncommon_dialog.msg);
tempstr[i+1] = '\0';
text_width = vita2d_pgf_text_width(font, FONT_SIZE, tempstr);
if (text_width > UNCOMMON_DIALOG_MAX_WIDTH) {
int lastSpace = i - 1;
while (uncommon_dialog.msg[lastSpace] != ' ' && uncommon_dialog.msg[lastSpace] != '\n' && lastSpace > 0) lastSpace--;
if (lastSpace == 0 || uncommon_dialog.msg[lastSpace] == '\n') {
memmove(uncommon_dialog.msg+i+1, uncommon_dialog.msg+i, strlen(uncommon_dialog.msg)-(i + 1));
uncommon_dialog.msg[i] = '\n';
} else {
uncommon_dialog.msg[lastSpace] = '\n';
}
uncommon_dialog.width = text_width;
string = uncommon_dialog.msg + i;
}
}
uncommon_dialog.height += FONT_Y_SPACE;
for (i = 0; uncommon_dialog.msg[i]; i++)
uncommon_dialog.height += FONT_Y_SPACE * (uncommon_dialog.msg[i] == '\n');
// Margin
uncommon_dialog.width += 2.0f*SHELL_MARGIN_X;
uncommon_dialog.height += 2.0f*SHELL_MARGIN_Y;