Skip to content

Commit

Permalink
Added padding to panic/alert/confirm dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ducalex committed Dec 26, 2020
1 parent e17fb26 commit 5994bbb
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 58 deletions.
15 changes: 11 additions & 4 deletions components/retro-go/rg_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ void rg_gui_draw_dialog(const char *header, dialog_choice_t *options, int sel)

for (int i = 0; i < options_count; i++)
{
if (options[i].label == NULL) {
options[i].label = "";
}
if (options[i].value[0]) {
len = strlen(options[i].label);
padding = (len > padding) ? len : padding;
Expand Down Expand Up @@ -450,23 +453,27 @@ int rg_gui_dialog(const char *header, dialog_choice_t *options, int selected)
return sel < 0 ? sel : options[sel].id;
}

int rg_gui_confirm(const char *text, bool yes_selected)
bool rg_gui_confirm(const char *title, const char *message, bool yes_selected)
{
dialog_choice_t choices[] = {
{0, message, "", -1, NULL},
{0, "", "", -1, NULL},
{1, "Yes", "", 1, NULL},
{0, "No ", "", 1, NULL},
RG_DIALOG_CHOICE_LAST
};
return rg_gui_dialog(text, choices, yes_selected ? 0 : 1);
return rg_gui_dialog(title, message ? choices : choices + 1, yes_selected ? -2 : -1) == 1;
}

void rg_gui_alert(const char *text)
void rg_gui_alert(const char *title, const char *message)
{
dialog_choice_t choices[] = {
{0, message, "", -1, NULL},
{0, "", "", -1, NULL},
{1, "OK", "", 1, NULL},
RG_DIALOG_CHOICE_LAST
};
rg_gui_dialog(text, choices, 0);
rg_gui_dialog(title, message ? choices : choices + 1, -1);
}

static bool volume_update_cb(dialog_choice_t *option, dialog_event_t event)
Expand Down
4 changes: 2 additions & 2 deletions components/retro-go/rg_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ void rg_gui_draw_image(int x, int y, int width, int height, const rg_image_t *im
void rg_gui_free_image(rg_image_t *img);

int rg_gui_dialog(const char *header, dialog_choice_t *options, int selected_initial);
int rg_gui_confirm(const char *text, bool yes_selected);
void rg_gui_alert(const char *text);
bool rg_gui_confirm(const char *title, const char *message, bool yes_selected);
void rg_gui_alert(const char *title, const char *message);

int rg_gui_settings_menu(dialog_choice_t *extra_options);
int rg_gui_game_settings_menu(dialog_choice_t *extra_options);
Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/rg_netplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bool rg_netplay_quick_start(void)
{
case NETPLAY_STATUS_CONNECTED:
return remote_player->game_id == local_player->game_id
|| rg_gui_confirm("ROMs not identical. Continue?", 1);
|| rg_gui_confirm("Netplay", "ROMs not identical. Continue?", 1);
break;

case NETPLAY_STATUS_HANDSHAKE:
Expand Down
50 changes: 15 additions & 35 deletions components/retro-go/rg_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
typedef struct
{
uint32_t magicWord;
char message[128];
char function[128];
char file[128];
char message[256];
char function[64];
char file[256];
} panic_trace_t;

// This is a direct pointer to rtc slow ram which isn't cleared on
Expand Down Expand Up @@ -102,7 +102,7 @@ static void system_monitor_task(void *arg)
// Applications should never stop polling input. If they do, they're probably unresponsive...
if (statistics.lastTickTime > 0 && rg_input_gamepad_last_read() > 5000000)
{
RG_PANIC("Application is unresponsive!");
RG_PANIC("Application unresponsive");
}

if (statistics.battery.percentage < 2)
Expand Down Expand Up @@ -243,9 +243,14 @@ void rg_system_init(int appId, int sampleRate)
if (esp_reset_reason() == ESP_RST_PANIC)
{
if (panicTrace->magicWord == PANIC_TRACE_MAGIC)
rg_system_panic_dialog(panicTrace->message);
else
rg_system_panic_dialog("Reason unknown");
printf(" *** PREVIOUS PANIC: %s *** \n", panicTrace->message);
else // Presumably abort()
strcpy(panicTrace->message, "Application crashed");
panicTrace->magicWord = 0;
rg_audio_deinit();
rg_display_clear(C_BLUE);
rg_gui_alert("System Panic!", panicTrace->message);
rg_system_switch_app(RG_APP_LAUNCHER);
}

if (esp_reset_reason() != ESP_RST_SW)
Expand Down Expand Up @@ -302,7 +307,7 @@ void rg_emu_init(state_handler_t load, state_handler_t save, netplay_callback_t
currentApp.romPath = rg_settings_RomFilePath_get();
if (!currentApp.romPath || strlen(currentApp.romPath) < 4)
{
RG_PANIC("Invalid ROM Path!");
RG_PANIC("Invalid ROM path!");
}

if (netplay_cb)
Expand Down Expand Up @@ -384,7 +389,7 @@ char* rg_emu_get_path(emu_path_type_t type, const char *_romPath)
break;

default:
RG_PANIC("Unknown Type");
RG_PANIC("Unknown path type");
}

return strdup(buffer);
Expand Down Expand Up @@ -457,7 +462,7 @@ bool rg_emu_save_state(int slot)
if (!success)
{
printf("%s: Save failed!\n", __func__);
rg_gui_alert("Save failed");
rg_gui_alert("Save failed", NULL);
}

free(saveName);
Expand Down Expand Up @@ -524,31 +529,6 @@ void rg_system_panic(const char *reason, const char *function, const char *file)
abort();
}

void rg_system_panic_dialog(const char *reason)
{
printf(" *** PREVIOUS PANIC: %s *** \n", reason);

// Clear the trace to avoid a boot loop
panicTrace->magicWord = 0;

rg_audio_deinit();

// In case we panicked from inside a dialog
rg_spi_lock_release(SPI_LOCK_ANY);

// Blue screen of death!
rg_display_clear(C_BLUE);

dialog_choice_t choices[] = {
{0, reason, "", -1, NULL},
{1, "OK", "", 1, NULL},
RG_DIALOG_CHOICE_LAST
};
rg_gui_dialog("The application crashed!", choices, 1);

rg_system_switch_app(RG_APP_LAUNCHER);
}

void rg_system_halt()
{
printf("%s: Halting system!\n", __func__);
Expand Down
1 change: 0 additions & 1 deletion components/retro-go/rg_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ typedef struct
} runtime_stats_t;

void rg_system_init(int app_id, int sampleRate);
void rg_system_panic_dialog(const char *reason);
void rg_system_panic(const char *reason, const char *function, const char *file) __attribute__((noreturn));
void rg_system_halt() __attribute__((noreturn));
void rg_system_sleep() __attribute__((noreturn));
Expand Down
2 changes: 1 addition & 1 deletion gnuboy-go/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void netplay_callback(netplay_event_t event, void *arg)

if (netplay && !new_netplay)
{
rg_gui_alert("Connection lost!");
rg_gui_alert("Netplay", "Connection lost!");
}
netplay = new_netplay;
break;
Expand Down
2 changes: 1 addition & 1 deletion huexpress-go/components/huexpress/engine/pce.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "pce.h"
#include "romdb.h"

struct host_machine host;
host_machine_t host;

const char SAVESTATE_HEADER[8] = "PCE_V004";

Expand Down
6 changes: 3 additions & 3 deletions huexpress-go/components/huexpress/engine/pce.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ShutdownPCE();
int InitPCE(const char *name);
int LoadCard(const char *name);

struct host_machine {
typedef struct {
bool paused;
bool netplay;

Expand All @@ -44,9 +44,9 @@ struct host_machine {
struct {
bool splatterhouse;
} hacks;
};
} host_machine_t;

extern struct host_machine host;
extern host_machine_t host;

typedef struct
{
Expand Down
2 changes: 1 addition & 1 deletion nofrendo-go/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void netplay_callback(netplay_event_t event, void *arg)

if (netplay && !new_netplay)
{
rg_gui_alert("Connection lost!");
rg_gui_alert("Netplay", "Connection lost!");
}
else if (!netplay && new_netplay)
{
Expand Down
2 changes: 1 addition & 1 deletion retro-go/main/emulators.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void emulator_show_file_menu(retro_emulator_file_t *file)
emulator_start(file, sel == 0);
}
else if (sel == 2) {
if (rg_gui_confirm("Delete save file?", false) == 1) {
if (rg_gui_confirm("Delete save file?", NULL, false)) {
if (has_save) {
rg_unlink(save_path);
}
Expand Down
13 changes: 6 additions & 7 deletions retro-go/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void retro_loop()
rg_system_switch_app(RG_APP_FACTORY);
}
else if (sel == 2) {
if (rg_gui_confirm("Reset all settings?", false) == 1) {
if (rg_gui_confirm("Reset all settings?", NULL, false)) {
rg_settings_reset();
rg_system_restart();
}
Expand All @@ -213,14 +213,13 @@ void retro_loop()
}
else if (last_key == GAMEPAD_KEY_VOLUME) {
dialog_choice_t choices[] = {
{0, "---", "", -1, NULL},
{0, "Color theme", "...", 1, &color_shift_cb},
{0, "Font size ", "...", 1, &font_size_cb},
{0, "---", "", -1, NULL},
{0, "Color theme", "...", 1, &color_shift_cb},
{0, "Font size ", "...", 1, &font_size_cb},
{0, "Empty tabs ", "...", 1, &show_empty_cb},
{0, "Preview ", "...", 1, &show_preview_cb},
{0, " Delay", "...", 1, &show_preview_speed_cb},
{0, "---", "", -1, NULL},
{0, "Startup app", "...", 1, &startup_app_cb},
{0, " - Delay", "...", 1, &show_preview_speed_cb},
{0, "Startup app", "...", 1, &startup_app_cb},
RG_DIALOG_CHOICE_LAST
};
rg_gui_settings_menu(choices);
Expand Down
2 changes: 1 addition & 1 deletion smsplusgx-go/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void netplay_callback(netplay_event_t event, void *arg)

if (netplay && !new_netplay)
{
rg_gui_alert("Connection lost!");
rg_gui_alert("Netplay", "Connection lost!");
}
else if (!netplay && new_netplay)
{
Expand Down

0 comments on commit 5994bbb

Please sign in to comment.