Last round of cleanup for settings for now.
This commit is contained in:
@@ -20,20 +20,10 @@
|
|||||||
#include "locale/localemanager.h"
|
#include "locale/localemanager.h"
|
||||||
#include "asset/loader/locale/assetlocaleloader.h"
|
#include "asset/loader/locale/assetlocaleloader.h"
|
||||||
|
|
||||||
#define UI_SETTINGS_DISCARD_TEXT_MAX 128
|
uisettings_t UI_SETTINGS;
|
||||||
|
|
||||||
typedef struct {
|
uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
||||||
const char_t *localeId;
|
{
|
||||||
errorret_t (*init)(void);
|
|
||||||
uimenu_t *menu;
|
|
||||||
void (*load)(void);
|
|
||||||
void (*apply)(void);
|
|
||||||
bool_t (*hasChanges)(void);
|
|
||||||
bool_t pendingDiscardConfirm;
|
|
||||||
} uisettingstabdef_t;
|
|
||||||
|
|
||||||
static uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
|
||||||
[UI_SETTINGS_TAB_GAMEPLAY] = {
|
|
||||||
.localeId = "ui.settings.tabs.gameplay",
|
.localeId = "ui.settings.tabs.gameplay",
|
||||||
.init = uiSettingsGameplayInit,
|
.init = uiSettingsGameplayInit,
|
||||||
.menu = &UI_SETTINGS_GAMEPLAY.menu,
|
.menu = &UI_SETTINGS_GAMEPLAY.menu,
|
||||||
@@ -42,7 +32,7 @@ static uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
|||||||
.hasChanges = uiSettingsGameplayHasChanges
|
.hasChanges = uiSettingsGameplayHasChanges
|
||||||
},
|
},
|
||||||
|
|
||||||
[UI_SETTINGS_TAB_INPUT] = {
|
{
|
||||||
.localeId = "ui.settings.tabs.input",
|
.localeId = "ui.settings.tabs.input",
|
||||||
.init = uiSettingsInputInit,
|
.init = uiSettingsInputInit,
|
||||||
.menu = &UI_SETTINGS_INPUT.menu,
|
.menu = &UI_SETTINGS_INPUT.menu,
|
||||||
@@ -51,7 +41,7 @@ static uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
|||||||
.hasChanges = uiSettingsInputHasChanges
|
.hasChanges = uiSettingsInputHasChanges
|
||||||
},
|
},
|
||||||
|
|
||||||
[UI_SETTINGS_TAB_DISPLAY] = {
|
{
|
||||||
.localeId = "ui.settings.tabs.display",
|
.localeId = "ui.settings.tabs.display",
|
||||||
.init = uiSettingsDisplayInit,
|
.init = uiSettingsDisplayInit,
|
||||||
.menu = &UI_SETTINGS_DISPLAY.menu,
|
.menu = &UI_SETTINGS_DISPLAY.menu,
|
||||||
@@ -60,7 +50,7 @@ static uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
|||||||
.hasChanges = uiSettingsDisplayHasChanges
|
.hasChanges = uiSettingsDisplayHasChanges
|
||||||
},
|
},
|
||||||
|
|
||||||
[UI_SETTINGS_TAB_AUDIO] = {
|
{
|
||||||
.localeId = "ui.settings.tabs.audio",
|
.localeId = "ui.settings.tabs.audio",
|
||||||
.init = uiSettingsAudioInit,
|
.init = uiSettingsAudioInit,
|
||||||
.menu = &UI_SETTINGS_AUDIO.menu,
|
.menu = &UI_SETTINGS_AUDIO.menu,
|
||||||
@@ -70,16 +60,13 @@ static uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uisettings_t UI_SETTINGS;
|
|
||||||
|
|
||||||
static uisettingstabdef_t UI_SETTINGS_TOP_DEF = {
|
static uisettingstabdef_t UI_SETTINGS_TOP_DEF = {
|
||||||
.menu = &UI_SETTINGS.tabsMenu,
|
.menu = &UI_SETTINGS.tabsMenu,
|
||||||
.load = uiSettingsLoad,
|
.load = uiSettingsLoad,
|
||||||
.hasChanges = uiSettingsHasChanges
|
.hasChanges = uiSettingsHasChanges
|
||||||
};
|
};
|
||||||
|
|
||||||
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def);
|
static uisettingstabdef_t *UI_SETTINGS_PENDING_DISCARD = NULL;
|
||||||
void uiSettingsDiscardConfirmResult(const bool_t result, void *user);
|
|
||||||
|
|
||||||
void uiSettingsTabSelected(
|
void uiSettingsTabSelected(
|
||||||
const uimenu_t *menu,
|
const uimenu_t *menu,
|
||||||
@@ -172,11 +159,12 @@ errorret_t uiSettingsDraw(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorret_t uiSettingsUpdate(void) {
|
errorret_t uiSettingsUpdate(void) {
|
||||||
for(uint8_t i = 0; i < UI_SETTINGS_TAB_COUNT; i++) {
|
if(!UI_SETTINGS_PENDING_DISCARD) errorOk();
|
||||||
errorChain(uiSettingsDiscardUpdate(&UI_SETTINGS_TAB_DEFS[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return uiSettingsDiscardUpdate(&UI_SETTINGS_TOP_DEF);
|
uisettingstabdef_t *def = UI_SETTINGS_PENDING_DISCARD;
|
||||||
|
UI_SETTINGS_PENDING_DISCARD = NULL;
|
||||||
|
|
||||||
|
return uiSettingsDiscardUpdate(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t uiSettingsIsOpen(void) {
|
bool_t uiSettingsIsOpen(void) {
|
||||||
@@ -217,13 +205,11 @@ bool_t uiSettingsHasChanges(void) {
|
|||||||
|
|
||||||
void uiSettingsDiscardMenuClosed(const uimenu_t *menu) {
|
void uiSettingsDiscardMenuClosed(const uimenu_t *menu) {
|
||||||
uisettingstabdef_t *def = (uisettingstabdef_t *)menu->user;
|
uisettingstabdef_t *def = (uisettingstabdef_t *)menu->user;
|
||||||
if(def->hasChanges()) def->pendingDiscardConfirm = true;
|
if(def->hasChanges()) UI_SETTINGS_PENDING_DISCARD = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def) {
|
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def) {
|
||||||
if(!def->pendingDiscardConfirm) errorOk();
|
#define UI_SETTINGS_DISCARD_TEXT_MAX 128
|
||||||
def->pendingDiscardConfirm = false;
|
|
||||||
|
|
||||||
char_t text[UI_SETTINGS_DISCARD_TEXT_MAX];
|
char_t text[UI_SETTINGS_DISCARD_TEXT_MAX];
|
||||||
errorChain(assetLocaleGetString(
|
errorChain(assetLocaleGetString(
|
||||||
&LOCALE.entry->data.locale,
|
&LOCALE.entry->data.locale,
|
||||||
@@ -232,6 +218,7 @@ errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def) {
|
|||||||
text,
|
text,
|
||||||
UI_SETTINGS_DISCARD_TEXT_MAX
|
UI_SETTINGS_DISCARD_TEXT_MAX
|
||||||
));
|
));
|
||||||
|
#undef UI_SETTINGS_DISCARD_TEXT_MAX
|
||||||
|
|
||||||
uiConfirmOpen(text, uiSettingsDiscardConfirmResult, def);
|
uiConfirmOpen(text, uiSettingsDiscardConfirmResult, def);
|
||||||
|
|
||||||
@@ -242,12 +229,9 @@ void uiSettingsDiscardConfirmResult(const bool_t result, void *user) {
|
|||||||
uisettingstabdef_t *def = (uisettingstabdef_t *)user;
|
uisettingstabdef_t *def = (uisettingstabdef_t *)user;
|
||||||
|
|
||||||
if(!result) {
|
if(!result) {
|
||||||
// Cancel means "keep editing" - reopen without reloading so the
|
|
||||||
// unsaved widget values the user had are preserved.
|
|
||||||
uiMenuOpen(def->menu);
|
uiMenuOpen(def->menu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirmed - reload the widgets back to the actual engine values.
|
|
||||||
def->load();
|
def->load();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "ui/widget/uimenu.h"
|
#include "ui/widget/uimenu.h"
|
||||||
|
|
||||||
#define UI_SETTINGS_TAB_GAMEPLAY 0
|
|
||||||
#define UI_SETTINGS_TAB_INPUT 1
|
|
||||||
#define UI_SETTINGS_TAB_DISPLAY 2
|
|
||||||
#define UI_SETTINGS_TAB_AUDIO 3
|
|
||||||
#define UI_SETTINGS_TAB_COUNT 4
|
#define UI_SETTINGS_TAB_COUNT 4
|
||||||
#define UI_SETTINGS_TAB_LABEL_MAX 32
|
#define UI_SETTINGS_TAB_LABEL_MAX 32
|
||||||
#define UI_SETTINGS_APPLY_LABEL_MAX 32
|
#define UI_SETTINGS_APPLY_LABEL_MAX 32
|
||||||
@@ -24,18 +20,50 @@ typedef struct {
|
|||||||
char_t applyLabel[UI_SETTINGS_APPLY_LABEL_MAX];
|
char_t applyLabel[UI_SETTINGS_APPLY_LABEL_MAX];
|
||||||
} uisettings_t;
|
} uisettings_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char_t *localeId;
|
||||||
|
errorret_t (*init)(void);
|
||||||
|
uimenu_t *menu;
|
||||||
|
void (*load)(void);
|
||||||
|
void (*apply)(void);
|
||||||
|
bool_t (*hasChanges)(void);
|
||||||
|
} uisettingstabdef_t;
|
||||||
|
|
||||||
extern uisettings_t UI_SETTINGS;
|
extern uisettings_t UI_SETTINGS;
|
||||||
|
extern uisettingstabdef_t UI_SETTINGS_TAB_DEFS[UI_SETTINGS_TAB_COUNT];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu closed callback that flags a pending discard-changes
|
* Menu closed callback that flags a pending discard-changes
|
||||||
* confirmation if the menu's settings page/panel reports unsaved
|
* confirmation if the menu's settings page/panel reports unsaved
|
||||||
* changes. Pass this directly as a settings page menu's closed
|
* changes. Pass this directly as a settings page menu's closed
|
||||||
* callback.
|
* callback. The pending def is picked up by uiSettingsUpdate on the
|
||||||
|
* next tick.
|
||||||
*
|
*
|
||||||
* @param menu The menu that was just closed.
|
* @param menu The menu that was just closed.
|
||||||
*/
|
*/
|
||||||
void uiSettingsDiscardMenuClosed(const uimenu_t *menu);
|
void uiSettingsDiscardMenuClosed(const uimenu_t *menu);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the discard-changes confirmation dialog for def. Called once
|
||||||
|
* by uiSettingsUpdate when uiSettingsDiscardMenuClosed has flagged a
|
||||||
|
* pending def.
|
||||||
|
*
|
||||||
|
* @param def The tab/panel def to show the confirmation for.
|
||||||
|
* @return Any error that occurs.
|
||||||
|
*/
|
||||||
|
errorret_t uiSettingsDiscardUpdate(uisettingstabdef_t *def);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback passed to uiConfirmOpen by uiSettingsDiscardUpdate. Reopens
|
||||||
|
* the menu if the user chose to keep editing, otherwise reloads the
|
||||||
|
* widgets back to the actual engine values.
|
||||||
|
*
|
||||||
|
* @param result True if the user confirmed discarding changes, false
|
||||||
|
* to keep editing.
|
||||||
|
* @param user The uisettingstabdef_t* this confirmation belongs to.
|
||||||
|
*/
|
||||||
|
void uiSettingsDiscardConfirmResult(const bool_t result, void *user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the settings panel and all of its category pages.
|
* Initializes the settings panel and all of its category pages.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ void uiSettingsAudioSelected(
|
|||||||
) {
|
) {
|
||||||
if(index != UI_SETTINGS_AUDIO_INDEX_APPLY) return;
|
if(index != UI_SETTINGS_AUDIO_INDEX_APPLY) return;
|
||||||
uiSettingsAudioApply();
|
uiSettingsAudioApply();
|
||||||
uiMenuClose(&UI_SETTINGS_AUDIO.menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t uiSettingsAudioInit(void) {
|
errorret_t uiSettingsAudioInit(void) {
|
||||||
@@ -40,6 +39,7 @@ void uiSettingsAudioLoad(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void uiSettingsAudioApply(void) {
|
void uiSettingsAudioApply(void) {
|
||||||
|
uiMenuClose(&UI_SETTINGS_AUDIO.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t uiSettingsAudioHasChanges(void) {
|
bool_t uiSettingsAudioHasChanges(void) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ void uiSettingsDisplaySelected(
|
|||||||
) {
|
) {
|
||||||
if(index != UI_SETTINGS_DISPLAY_INDEX_APPLY) return;
|
if(index != UI_SETTINGS_DISPLAY_INDEX_APPLY) return;
|
||||||
uiSettingsDisplayApply();
|
uiSettingsDisplayApply();
|
||||||
uiMenuClose(&UI_SETTINGS_DISPLAY.menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t uiSettingsDisplayInit(void) {
|
errorret_t uiSettingsDisplayInit(void) {
|
||||||
@@ -40,6 +39,7 @@ void uiSettingsDisplayLoad(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void uiSettingsDisplayApply(void) {
|
void uiSettingsDisplayApply(void) {
|
||||||
|
uiMenuClose(&UI_SETTINGS_DISPLAY.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t uiSettingsDisplayHasChanges(void) {
|
bool_t uiSettingsDisplayHasChanges(void) {
|
||||||
|
|||||||
@@ -13,26 +13,18 @@
|
|||||||
|
|
||||||
uisettingsgameplay_t UI_SETTINGS_GAMEPLAY;
|
uisettingsgameplay_t UI_SETTINGS_GAMEPLAY;
|
||||||
|
|
||||||
void uiSettingsGameplayShowConfirmResult(const bool_t result, void *user) {
|
|
||||||
consolePrint("Confirm dialog result: %s", result ? "confirmed" : "cancelled");
|
|
||||||
}
|
|
||||||
|
|
||||||
void uiSettingsGameplaySelected(
|
void uiSettingsGameplaySelected(
|
||||||
const uimenu_t *menu,
|
const uimenu_t *menu,
|
||||||
const uint8_t index,
|
const uint8_t index,
|
||||||
const uimenuitem_t *item
|
const uimenuitem_t *item
|
||||||
) {
|
) {
|
||||||
if(index == UI_SETTINGS_GAMEPLAY_INDEX_SHOW_CONFIRM) {
|
switch(index) {
|
||||||
uiConfirmOpen(
|
case UI_SETTINGS_GAMEPLAY_INDEX_APPLY:
|
||||||
"Are you sure?", uiSettingsGameplayShowConfirmResult, NULL
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(index == UI_SETTINGS_GAMEPLAY_INDEX_APPLY) {
|
|
||||||
uiSettingsGameplayApply();
|
uiSettingsGameplayApply();
|
||||||
uiMenuClose(&UI_SETTINGS_GAMEPLAY.menu);
|
break;
|
||||||
return;
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,48 +35,20 @@ errorret_t uiSettingsGameplayInit(void) {
|
|||||||
&UI_SETTINGS_GAMEPLAY.menu, UI_SETTINGS_GAMEPLAY.items,
|
&UI_SETTINGS_GAMEPLAY.menu, UI_SETTINGS_GAMEPLAY.items,
|
||||||
uiSettingsGameplaySelected, uiSettingsDiscardMenuClosed, NULL
|
uiSettingsGameplaySelected, uiSettingsDiscardMenuClosed, NULL
|
||||||
);
|
);
|
||||||
MENU_BUTTON("Do thing");
|
|
||||||
MENU_BUTTON("Do other thing");
|
|
||||||
MENU_CHECKBOX("Enable thing?");
|
|
||||||
MENU_SLIDER_FLOAT("test", 1.0f, 1.0f, 4.0f, 0.5f);
|
|
||||||
MENU_BUTTON("Show confirm");
|
|
||||||
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
|
||||||
|
|
||||||
|
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
||||||
MENU_END(UI_SETTINGS_GAMEPLAY.items, 1);
|
MENU_END(UI_SETTINGS_GAMEPLAY.items, 1);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiSettingsGameplayLoad(void) {
|
void uiSettingsGameplayLoad(void) {
|
||||||
UI_SETTINGS_GAMEPLAY.loadedEnableThing = uiCheckboxIsChecked(
|
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_ENABLE_THING].checkbox
|
|
||||||
);
|
|
||||||
UI_SETTINGS_GAMEPLAY.loadedTestValue = uiSliderGetFloat(
|
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_TEST_SLIDER].slider
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiSettingsGameplayApply(void) {
|
void uiSettingsGameplayApply(void) {
|
||||||
UI_SETTINGS_GAMEPLAY.loadedEnableThing = uiCheckboxIsChecked(
|
uiMenuClose(&UI_SETTINGS_GAMEPLAY.menu);
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_ENABLE_THING].checkbox
|
|
||||||
);
|
|
||||||
UI_SETTINGS_GAMEPLAY.loadedTestValue = uiSliderGetFloat(
|
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_TEST_SLIDER].slider
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t uiSettingsGameplayHasChanges(void) {
|
bool_t uiSettingsGameplayHasChanges(void) {
|
||||||
if(
|
|
||||||
uiCheckboxIsChecked(
|
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_ENABLE_THING].checkbox
|
|
||||||
) != UI_SETTINGS_GAMEPLAY.loadedEnableThing
|
|
||||||
) return true;
|
|
||||||
|
|
||||||
if(
|
|
||||||
uiSliderGetFloat(
|
|
||||||
&UI_SETTINGS_GAMEPLAY.items[UI_SETTINGS_GAMEPLAY_INDEX_TEST_SLIDER].slider
|
|
||||||
) != UI_SETTINGS_GAMEPLAY.loadedTestValue
|
|
||||||
) return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uimenu_t menu;
|
uimenu_t menu;
|
||||||
uimenuitem_t items[UI_SETTINGS_GAMEPLAY_ITEM_COUNT];
|
uimenuitem_t items[UI_SETTINGS_GAMEPLAY_ITEM_COUNT];
|
||||||
bool_t loadedEnableThing;
|
|
||||||
float_t loadedTestValue;
|
|
||||||
} uisettingsgameplay_t;
|
} uisettingsgameplay_t;
|
||||||
|
|
||||||
extern uisettingsgameplay_t UI_SETTINGS_GAMEPLAY;
|
extern uisettingsgameplay_t UI_SETTINGS_GAMEPLAY;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ void uiSettingsInputSelected(
|
|||||||
) {
|
) {
|
||||||
if(index != UI_SETTINGS_INPUT_INDEX_APPLY) return;
|
if(index != UI_SETTINGS_INPUT_INDEX_APPLY) return;
|
||||||
uiSettingsInputApply();
|
uiSettingsInputApply();
|
||||||
uiMenuClose(&UI_SETTINGS_INPUT.menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t uiSettingsInputInit(void) {
|
errorret_t uiSettingsInputInit(void) {
|
||||||
@@ -67,6 +66,7 @@ void uiSettingsInputApply(void) {
|
|||||||
&UI_SETTINGS_INPUT.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
&UI_SETTINGS_INPUT.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
uiMenuClose(&UI_SETTINGS_INPUT.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t uiSettingsInputHasChanges(void) {
|
bool_t uiSettingsInputHasChanges(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user