Skip to content

Commit 04e311a

Browse files
kilbithparamat
authored andcommitted
Settings Tab: Regroup dropdown datas in tables
1 parent 24e8b0a commit 04e311a

File tree

1 file changed

+113
-129
lines changed

1 file changed

+113
-129
lines changed

builtin/mainmenu/tab_settings.lua

Lines changed: 113 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -17,121 +17,105 @@
1717

1818
--------------------------------------------------------------------------------
1919

20-
-- Dropdown labels : Leaves
21-
local leaves_style_labels = {
22-
fgettext("Opaque Leaves"),
23-
fgettext("Simple Leaves"),
24-
fgettext("Fancy Leaves")
20+
local labels = {
21+
leaves = {
22+
fgettext("Opaque Leaves"),
23+
fgettext("Simple Leaves"),
24+
fgettext("Fancy Leaves")
25+
},
26+
node_highlighting = {
27+
fgettext("Node Outlining"),
28+
fgettext("Node Highlighting")
29+
},
30+
filters = {
31+
fgettext("No Filter"),
32+
fgettext("Bilinear Filter"),
33+
fgettext("Trilinear Filter")
34+
},
35+
mipmap = {
36+
fgettext("No Mipmap"),
37+
fgettext("Mipmap"),
38+
fgettext("Mipmap + Aniso. Filter")
39+
},
40+
antialiasing = {
41+
fgettext("None"),
42+
fgettext("2x"),
43+
fgettext("4x"),
44+
fgettext("8x")
45+
}
2546
}
2647

27-
local leaves_style = {
28-
table.concat(leaves_style_labels, ","),
29-
{"opaque", "simple", "fancy"},
48+
local dd_options = {
49+
leaves = {
50+
table.concat(labels.leaves, ","),
51+
{"opaque", "simple", "fancy"}
52+
},
53+
node_highlighting = {
54+
table.concat(labels.node_highlighting, ","),
55+
{"box", "halo"}
56+
},
57+
filters = {
58+
table.concat(labels.filters, ","),
59+
{"", "bilinear_filter", "trilinear_filter"}
60+
},
61+
mipmap = {
62+
table.concat(labels.mipmap, ","),
63+
{"", "mip_map", "anisotropic_filter"}
64+
},
65+
antialiasing = {
66+
table.concat(labels.antialiasing, ","),
67+
{"0", "2", "4", "8"}
68+
}
3069
}
3170

32-
-- Dropdown labels : Node highlighting
33-
local node_highlighting_style_labels = {
34-
fgettext("Node Outlining"),
35-
fgettext("Node Highlighting")
36-
}
37-
38-
local node_highlighting_style = {
39-
table.concat(node_highlighting_style_labels, ","),
40-
{"box", "halo"},
41-
}
42-
43-
-- Dropdown labels : Textures filtering
44-
local dd_filter_labels = {
45-
fgettext("No Filter"),
46-
fgettext("Bilinear Filter"),
47-
fgettext("Trilinear Filter")
48-
}
49-
50-
local filters = {
51-
table.concat(dd_filter_labels, ","),
52-
{"", "bilinear_filter", "trilinear_filter"},
53-
}
54-
55-
-- Dropdown labels : Mip-mapping
56-
local dd_mipmap_labels = {
57-
fgettext("No Mipmap"),
58-
fgettext("Mipmap"),
59-
fgettext("Mipmap + Aniso. Filter")
60-
}
61-
62-
local mipmap = {
63-
table.concat(dd_mipmap_labels, ","),
64-
{"", "mip_map", "anisotropic_filter"},
65-
}
66-
67-
-- Dropdown labels : Anti-aliasing
68-
local dd_antialiasing_labels = {
69-
fgettext("None"),
70-
fgettext("2x"),
71-
fgettext("4x"),
72-
fgettext("8x"),
73-
}
74-
75-
local antialiasing = {
76-
table.concat(dd_antialiasing_labels, ","),
77-
{"0", "2", "4", "8"}
78-
}
79-
80-
-- Dropdown index getter : Leaves
81-
local function getLeavesStyleSettingIndex()
82-
local style = core.setting_get("leaves_style")
83-
for idx, name in pairs(leaves_style[2]) do
84-
if style == name then return idx end
85-
end
86-
return 1
87-
end
88-
89-
-- Dropdown index getter : Node highlighting
90-
local function getNodeHighlightingSettingIndex()
91-
local style = core.setting_get("node_highlighting")
92-
for idx, name in pairs(node_highlighting_style[2]) do
93-
if style == name then return idx end
94-
end
95-
return 1
96-
end
97-
98-
-- Dropdown index getter : Textures filtering
99-
local function getFilterSettingIndex()
100-
if core.setting_get(filters[2][3]) == "true" then
101-
return 3
102-
elseif core.setting_get(filters[2][3]) == "false" and
103-
core.setting_get(filters[2][2]) == "true" then
104-
return 2
105-
end
106-
return 1
107-
end
108-
109-
-- Dropdown index getter : Mip-mapping
110-
local function getMipmapSettingIndex()
111-
if core.setting_get(mipmap[2][3]) == "true" then
112-
return 3
113-
elseif core.setting_get(mipmap[2][3]) == "false" and
114-
core.setting_get(mipmap[2][2]) == "true" then
115-
return 2
116-
end
117-
return 1
118-
end
119-
120-
-- Dropdown index getter : Anti-aliasing
121-
local function getAntialiasingSettingIndex()
122-
local antialiasing_setting = core.setting_get("fsaa")
123-
for i = 1, #antialiasing[2] do
124-
if antialiasing_setting == antialiasing[2][i] then
125-
return i
71+
local getSettingIndex = {
72+
Leaves = function()
73+
local style = core.setting_get("leaves_style")
74+
for idx, name in pairs(dd_options.leaves[2]) do
75+
if style == name then return idx end
76+
end
77+
return 1
78+
end,
79+
NodeHighlighting = function()
80+
local style = core.setting_get("node_highlighting")
81+
for idx, name in pairs(dd_options.node_highlighting[2]) do
82+
if style == name then return idx end
83+
end
84+
return 1
85+
end,
86+
Filter = function()
87+
if core.setting_get(dd_options.filters[2][3]) == "true" then
88+
return 3
89+
elseif core.setting_get(dd_options.filters[2][3]) == "false" and
90+
core.setting_get(dd_options.filters[2][2]) == "true" then
91+
return 2
92+
end
93+
return 1
94+
end,
95+
Mipmap = function()
96+
if core.setting_get(dd_options.mipmap[2][3]) == "true" then
97+
return 3
98+
elseif core.setting_get(dd_options.mipmap[2][3]) == "false" and
99+
core.setting_get(dd_options.mipmap[2][2]) == "true" then
100+
return 2
126101
end
102+
return 1
103+
end,
104+
Antialiasing = function()
105+
local antialiasing_setting = core.setting_get("fsaa")
106+
for i = 1, #dd_options.antialiasing[2] do
107+
if antialiasing_setting == dd_options.antialiasing[2][i] then
108+
return i
109+
end
110+
end
111+
return 1
127112
end
128-
return 1
129-
end
113+
}
130114

131115
local function antialiasing_fname_to_name(fname)
132-
for i = 1, #dd_antialiasing_labels do
133-
if fname == dd_antialiasing_labels[i] then
134-
return antialiasing[2][i]
116+
for i = 1, #labels.antialiasing do
117+
if fname == labels.antialiasing[i] then
118+
return dd_options.antialiasing[2][i]
135119
end
136120
end
137121
return 0
@@ -202,19 +186,19 @@ local function formspec(tabview, name, tabdata)
202186
.. dump(core.setting_getbool("opaque_water")) .. "]" ..
203187
"checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
204188
.. dump(core.setting_getbool("connected_glass")) .. "]" ..
205-
"dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. node_highlighting_style[1] .. ";"
206-
.. getNodeHighlightingSettingIndex() .. "]" ..
207-
"dropdown[0.25,3.6;3.3;dd_leaves_style;" .. leaves_style[1] .. ";"
208-
.. getLeavesStyleSettingIndex() .. "]" ..
189+
"dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
190+
.. getSettingIndex.NodeHighlighting() .. "]" ..
191+
"dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
192+
.. getSettingIndex.Leaves() .. "]" ..
209193
"box[3.75,0;3.75,3.45;#999999]" ..
210194
"label[3.85,0.1;" .. fgettext("Texturing:") .. "]" ..
211-
"dropdown[3.85,0.55;3.85;dd_filters;" .. filters[1] .. ";"
212-
.. getFilterSettingIndex() .. "]" ..
213-
"dropdown[3.85,1.35;3.85;dd_mipmap;" .. mipmap[1] .. ";"
214-
.. getMipmapSettingIndex() .. "]" ..
195+
"dropdown[3.85,0.55;3.85;dd_filters;" .. dd_options.filters[1] .. ";"
196+
.. getSettingIndex.Filter() .. "]" ..
197+
"dropdown[3.85,1.35;3.85;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
198+
.. getSettingIndex.Mipmap() .. "]" ..
215199
"label[3.85,2.15;" .. fgettext("Antialiasing:") .. "]" ..
216-
"dropdown[3.85,2.6;3.85;dd_antialiasing;" .. antialiasing[1] .. ";"
217-
.. getAntialiasingSettingIndex() .. "]" ..
200+
"dropdown[3.85,2.6;3.85;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
201+
.. getSettingIndex.Antialiasing() .. "]" ..
218202
"box[7.75,0;4,4.4;#999999]" ..
219203
"checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";"
220204
.. dump(core.setting_getbool("enable_shaders")) .. "]"
@@ -349,40 +333,40 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
349333
--Note dropdowns have to be handled LAST!
350334
local ddhandled = false
351335

352-
for i = 1, #leaves_style_labels do
353-
if fields["dd_leaves_style"] == leaves_style_labels[i] then
354-
core.setting_set("leaves_style", leaves_style[2][i])
336+
for i = 1, #labels.leaves do
337+
if fields["dd_leaves_style"] == labels.leaves[i] then
338+
core.setting_set("leaves_style", dd_options.leaves[2][i])
355339
ddhandled = true
356340
end
357341
end
358-
for i = 1, #node_highlighting_style_labels do
359-
if fields["dd_node_highlighting"] == node_highlighting_style_labels[i] then
360-
core.setting_set("node_highlighting", node_highlighting_style[2][i])
342+
for i = 1, #labels.node_highlighting do
343+
if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
344+
core.setting_set("node_highlighting", dd_options.node_highlighting[2][i])
361345
ddhandled = true
362346
end
363347
end
364-
if fields["dd_filters"] == dd_filter_labels[1] then
348+
if fields["dd_filters"] == labels.filters[1] then
365349
core.setting_set("bilinear_filter", "false")
366350
core.setting_set("trilinear_filter", "false")
367351
ddhandled = true
368-
elseif fields["dd_filters"] == dd_filter_labels[2] then
352+
elseif fields["dd_filters"] == labels.filters[2] then
369353
core.setting_set("bilinear_filter", "true")
370354
core.setting_set("trilinear_filter", "false")
371355
ddhandled = true
372-
elseif fields["dd_filters"] == dd_filter_labels[3] then
356+
elseif fields["dd_filters"] == labels.filters[3] then
373357
core.setting_set("bilinear_filter", "false")
374358
core.setting_set("trilinear_filter", "true")
375359
ddhandled = true
376360
end
377-
if fields["dd_mipmap"] == dd_mipmap_labels[1] then
361+
if fields["dd_mipmap"] == labels.mipmap[1] then
378362
core.setting_set("mip_map", "false")
379363
core.setting_set("anisotropic_filter", "false")
380364
ddhandled = true
381-
elseif fields["dd_mipmap"] == dd_mipmap_labels[2] then
365+
elseif fields["dd_mipmap"] == labels.mipmap[2] then
382366
core.setting_set("mip_map", "true")
383367
core.setting_set("anisotropic_filter", "false")
384368
ddhandled = true
385-
elseif fields["dd_mipmap"] == dd_mipmap_labels[3] then
369+
elseif fields["dd_mipmap"] == labels.mipmap[3] then
386370
core.setting_set("mip_map", "true")
387371
core.setting_set("anisotropic_filter", "true")
388372
ddhandled = true

0 commit comments

Comments
 (0)