1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Settings GUI: Use language names rather than codes (#13752)

This commit is contained in:
rubenwardy 2023-08-24 00:33:23 +01:00 committed by GitHub
parent 7b3ed32003
commit a65cdbe66e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 3 deletions

View file

@ -161,15 +161,17 @@ function make.enum(setting)
local value = core.settings:get(setting.name) or setting.default
self.resettable = core.settings:has(setting.name)
local labels = setting.option_labels or {}
local items = {}
for i, option in ipairs(setting.values) do
items[i] = core.formspec_escape(option)
items[i] = core.formspec_escape(labels[option] or option)
end
local selected_idx = table.indexof(setting.values, value)
local fs = "label[0,0.1;" .. get_label(setting) .. "]"
fs = fs .. ("dropdown[0,0.3;%f,0.8;%s;%s;%d]"):format(
fs = fs .. ("dropdown[0,0.3;%f,0.8;%s;%s;%d;true]"):format(
avail_w, setting.name, table.concat(items, ","), selected_idx, value)
return fs, 1.1
@ -177,7 +179,8 @@ function make.enum(setting)
on_submit = function(self, fields)
local old_value = core.settings:get(setting.name) or setting.default
local value = fields[setting.name]
local idx = tonumber(fields[setting.name]) or 0
local value = setting.values[idx]
if value == nil or value == old_value then
return false
end