mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Show localised names of mod settings in the web UI (#1181)
The mod pack page only looked up mod-setting-name.<name>, so settings with a localised_name showed the internal name, and rich text tags in the locale showed up as raw text. Resolve localised_name and localised_description from the exported settings prototypes against the exported locale, falling back to the mod-setting-name/mod-setting-description keys and then the internal name. The resolver handles parameters, the "" and "?" keys and __ITEM__/__ENTITY__/__TILE__/__FLUID__ references. Rich text formatting tags are removed and prototype icons are replaced with their name. Fixes #768 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6867de13d
commit
6d9a32d28b
5 files changed
+290
-4
No files matched your search
@@ -23,6 +23,7 @@ import { useMods } from "../model/mods";
|
||||
import { useClipboard } from "../util/clipboard";
|
||||
import { modSettingFields, ModSettingField, ModSettingScope } from "../util/mod_settings";
|
||||
import notify, { notifyErrorHandler } from "../util/notify";
|
||||
import { modSettingDescription, modSettingName, modSettingValueName } from "../util/locale";
|
||||
import useResourceState from "../util/useResourceState";
|
||||
import PageHeader from "./PageHeader";
|
||||
import PageLayout from "./PageLayout";
|
||||
@@ -901,6 +902,8 @@ type SettingsTableFieldProps = {
|
||||
type: string;
|
||||
scope: ModSettingScope;
|
||||
allowedValues: any;
|
||||
localisedName?: lib.FactorioLocalisedString;
|
||||
localisedDescription?: lib.FactorioLocalisedString;
|
||||
locale: Map<string, any>;
|
||||
changed: boolean;
|
||||
/** Saved value of the setting, used when the field is created and when the form is reset */
|
||||
@@ -917,6 +920,7 @@ const SettingsTableField = memo((props: SettingsTableFieldProps) => {
|
||||
const isColor = props.type === "color-setting";
|
||||
const isNumber = ["int-setting", "double-setting"].includes(props.type);
|
||||
const isSelect = Boolean(props.allowedValues);
|
||||
const prototype = { name, localised_name: props.localisedName, localised_description: props.localisedDescription };
|
||||
let input;
|
||||
if (isBoolean) {
|
||||
input = <Checkbox />;
|
||||
@@ -924,22 +928,22 @@ const SettingsTableField = memo((props: SettingsTableFieldProps) => {
|
||||
const PartialInputColor = InputColor as () => React.JSX.Element;
|
||||
input = <PartialInputColor />;
|
||||
} else if (isSelect) {
|
||||
const options = Object.values(props.allowedValues).map(value => ({
|
||||
const options = Object.values(props.allowedValues as (string | number)[]).map(value => ({
|
||||
value,
|
||||
label: props.locale.get(`string-mod-setting.${name}-${value}`) || value,
|
||||
label: modSettingValueName(props.locale, name, value),
|
||||
}));
|
||||
input = <Select options={options} />;
|
||||
} else {
|
||||
input = <Input />;
|
||||
}
|
||||
|
||||
const label = props.locale.get(`mod-setting-name.${name}`) || name;
|
||||
const label = modSettingName(props.locale, prototype);
|
||||
const change: ModChange = {
|
||||
type: "settings.delete", scope: props.scope, name, value: { value: props.initialValue! },
|
||||
};
|
||||
return <Form.Item
|
||||
label={props.removed ? <Text delete>{label}</Text> : label}
|
||||
tooltip={props.locale.get(`mod-setting-description.${name}`)}
|
||||
tooltip={modSettingDescription(props.locale, prototype)}
|
||||
labelCol={{ span: 8 }}
|
||||
wrapperCol={{ span: 16 }}
|
||||
className={props.changed ? "changed" : ""}
|
||||
@@ -999,6 +1003,8 @@ function SettingsTable(props: SettingsTableProps) {
|
||||
type={setting.type}
|
||||
scope={scope}
|
||||
allowedValues={setting.allowed_values}
|
||||
localisedName={setting.localised_name}
|
||||
localisedDescription={setting.localised_description}
|
||||
locale={props.locale}
|
||||
changed={hasChange(props.changes, { type: "settings.set", scope, name: setting.name })}
|
||||
initialValue={props.savedModPack.settings[scope].get(setting.name)?.value}
|
||||
|
||||
Reference in new issue
Block a user