7357b4a5df
Replaces the last hardcoded English strings (initial-scene modals, game menu save status messages) with locale-loaded text, adds a shared LOCALE_LIST so the settings dropdown and locale manager stay in sync, and persists the chosen language into savemeta_t across all platforms. Also fixes two message buffers that were too small for their longest translations. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
109 lines
2.6 KiB
C
109 lines
2.6 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "uisettingsgeneral.h"
|
|
#include "uisettings.h"
|
|
#include "assert/assert.h"
|
|
#include "util/memory.h"
|
|
#include "locale/localemanager.h"
|
|
#include "locale/localeinfo.h"
|
|
#include "asset/loader/locale/assetlocaleloader.h"
|
|
#include "save/save.h"
|
|
#include "error/error.h"
|
|
|
|
static void uiSettingsGeneralSaveComplete(errorret_t result, void *user) {
|
|
if(errorIsNotOk(result)) errorCatch(errorPrint(result));
|
|
}
|
|
|
|
void uiSettingsGeneralSelected(
|
|
const uimenu_t *menu,
|
|
const uint8_t index,
|
|
const uimenuitem_t *item
|
|
) {
|
|
switch(index) {
|
|
case UI_SETTINGS_GENERAL_INDEX_APPLY:
|
|
uiSettingsGeneralApply();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
errorret_t uiSettingsGeneralInit(uisettingsdata_t *data) {
|
|
uisettingsgeneral_t *general = &data->general;
|
|
memoryZero(general, sizeof(uisettingsgeneral_t));
|
|
|
|
for(uint8_t i = 0; i < LOCALE_LIST_COUNT; i++) {
|
|
general->localeNames[i] = LOCALE_LIST[i]->name;
|
|
}
|
|
|
|
errorChain(assetLocaleGetString(
|
|
&LOCALE.entry->data.locale,
|
|
"ui.settings.general.language",
|
|
0,
|
|
general->languageLabel,
|
|
UI_SETTINGS_GENERAL_LABEL_MAX
|
|
));
|
|
errorChain(assetLocaleGetString(
|
|
&LOCALE.entry->data.locale,
|
|
"ui.settings.general.language_detail",
|
|
0,
|
|
general->labelInfo,
|
|
UI_SETTINGS_GENERAL_INFO_MAX
|
|
));
|
|
|
|
MENU_BEGIN(
|
|
&general->menu, general->items,
|
|
uiSettingsGeneralSelected, uiSettingsDiscardMenuClosed, NULL
|
|
);
|
|
|
|
MENU_DROPDOWN(
|
|
general->languageLabel, general->localeNames,
|
|
LOCALE_LIST_COUNT, 0
|
|
);
|
|
MENU_LABEL(general->labelInfo);
|
|
|
|
MENU_BUTTON(UI_SETTINGS.applyLabel);
|
|
MENU_END(general->items, 1);
|
|
|
|
errorOk();
|
|
}
|
|
|
|
void uiSettingsGeneralLoad(void) {
|
|
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
|
|
|
uint8_t index = localeManagerGetIndex(LOCALE.locale);
|
|
|
|
uiDropdownSetSelectedIndex(
|
|
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown, index
|
|
);
|
|
}
|
|
|
|
void uiSettingsGeneralApply(void) {
|
|
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
|
|
|
uint8_t index = uiDropdownGetSelectedIndex(
|
|
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown
|
|
);
|
|
errorCatch(localeManagerSetLocale(LOCALE_LIST[index]));
|
|
|
|
saveGetMeta()->language = index;
|
|
saveWriteMeta(uiSettingsGeneralSaveComplete, NULL);
|
|
|
|
uiMenuClose(&general->menu);
|
|
}
|
|
|
|
bool_t uiSettingsGeneralHasChanges(void) {
|
|
uisettingsgeneral_t *general = &UI_SETTINGS.data.general;
|
|
|
|
uint8_t index = uiDropdownGetSelectedIndex(
|
|
&general->items[UI_SETTINGS_GENERAL_INDEX_LANGUAGE].dropdown
|
|
);
|
|
return localeManagerGetIndex(LOCALE.locale) != index;
|
|
}
|