Skip to content

Commit 788f297

Browse files
author
Maksim
authoredAug 27, 2020
Android: drop simple MainMenu (#10227)
The default (PC-style) MainMenu works great on Android. Provides access to ContentDB and allows players to create many worlds in a few clicks. Makes the interface consistent and eliminates player confusion.
1 parent b262184 commit 788f297

File tree

5 files changed

+33
-363
lines changed

5 files changed

+33
-363
lines changed
 

‎builtin/mainmenu/init.lua

+30-72
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mt_color_dark_green = "#25C191"
2222

2323
local menupath = core.get_mainmenu_path()
2424
local basepath = core.get_builtin_path()
25-
local menustyle = core.settings:get("main_menu_style")
2625
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
2726
DIR_DELIM .. "pack" .. DIR_DELIM
2827

@@ -39,24 +38,18 @@ dofile(menupath .. DIR_DELIM .. "textures.lua")
3938
dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
4039
dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
4140
dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
42-
if menustyle ~= "simple" then
43-
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
44-
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
45-
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
46-
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
47-
end
41+
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
42+
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
43+
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
44+
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
4845

4946
local tabs = {}
5047

5148
tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
5249
tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
5350
tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
54-
if menustyle == "simple" then
55-
tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
56-
else
57-
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
58-
tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
59-
end
51+
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
52+
tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
6053

6154
--------------------------------------------------------------------------------
6255
local function main_event_handler(tabview, event)
@@ -71,68 +64,35 @@ local function init_globals()
7164
-- Init gamedata
7265
gamedata.worldindex = 0
7366

74-
if menustyle == "simple" then
75-
local world_list = core.get_worlds()
76-
local world_index
77-
78-
local found_singleplayerworld = false
79-
for i, world in ipairs(world_list) do
80-
if world.name == "singleplayerworld" then
81-
found_singleplayerworld = true
82-
world_index = i
83-
break
84-
end
85-
end
86-
87-
if not found_singleplayerworld then
88-
core.create_world("singleplayerworld", 1)
89-
90-
world_list = core.get_worlds()
91-
92-
for i, world in ipairs(world_list) do
93-
if world.name == "singleplayerworld" then
94-
world_index = i
95-
break
96-
end
97-
end
67+
menudata.worldlist = filterlist.create(
68+
core.get_worlds,
69+
compare_worlds,
70+
-- Unique id comparison function
71+
function(element, uid)
72+
return element.name == uid
73+
end,
74+
-- Filter function
75+
function(element, gameid)
76+
return element.gameid == gameid
9877
end
78+
)
9979

100-
gamedata.worldindex = world_index
101-
else
102-
menudata.worldlist = filterlist.create(
103-
core.get_worlds,
104-
compare_worlds,
105-
-- Unique id comparison function
106-
function(element, uid)
107-
return element.name == uid
108-
end,
109-
-- Filter function
110-
function(element, gameid)
111-
return element.gameid == gameid
112-
end
113-
)
114-
115-
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
116-
menudata.worldlist:set_sortmode("alphabetic")
117-
118-
if not core.settings:get("menu_last_game") then
119-
local default_game = core.settings:get("default_game") or "minetest"
120-
core.settings:set("menu_last_game", default_game)
121-
end
80+
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
81+
menudata.worldlist:set_sortmode("alphabetic")
12282

123-
mm_texture.init()
83+
if not core.settings:get("menu_last_game") then
84+
local default_game = core.settings:get("default_game") or "minetest"
85+
core.settings:set("menu_last_game", default_game)
12486
end
12587

88+
mm_texture.init()
89+
12690
-- Create main tabview
12791
local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
12892

129-
if menustyle == "simple" then
130-
tv_main:add(tabs.simple_main)
131-
else
132-
tv_main:set_autosave_tab(true)
133-
tv_main:add(tabs.local_game)
134-
tv_main:add(tabs.play_online)
135-
end
93+
tv_main:set_autosave_tab(true)
94+
tv_main:add(tabs.local_game)
95+
tv_main:add(tabs.play_online)
13696

13797
tv_main:add(tabs.content)
13898
tv_main:add(tabs.settings)
@@ -141,11 +101,9 @@ local function init_globals()
141101
tv_main:set_global_event_handler(main_event_handler)
142102
tv_main:set_fixed_size(false)
143103

144-
if menustyle ~= "simple" then
145-
local last_tab = core.settings:get("maintab_LAST")
146-
if last_tab and tv_main.current_tab ~= last_tab then
147-
tv_main:set_tab(last_tab)
148-
end
104+
local last_tab = core.settings:get("maintab_LAST")
105+
if last_tab and tv_main.current_tab ~= last_tab then
106+
tv_main:set_tab(last_tab)
149107
end
150108
ui.set_default("maintab")
151109
tv_main:show()

‎builtin/mainmenu/tab_settings.lua

+3-64
Original file line numberDiff line numberDiff line change
@@ -122,56 +122,6 @@ local function antialiasing_fname_to_name(fname)
122122
return 0
123123
end
124124

125-
local function dlg_confirm_reset_formspec(data)
126-
return "size[8,3]" ..
127-
"label[1,1;" .. fgettext("Are you sure to reset your singleplayer world?") .. "]" ..
128-
"button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;" .. fgettext("Yes") .. "]" ..
129-
"button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;" .. fgettext("No") .. "]"
130-
end
131-
132-
local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)
133-
134-
if fields["dlg_reset_singleplayer_confirm"] ~= nil then
135-
local worldlist = core.get_worlds()
136-
local found_singleplayerworld = false
137-
138-
for i = 1, #worldlist do
139-
if worldlist[i].name == "singleplayerworld" then
140-
found_singleplayerworld = true
141-
gamedata.worldindex = i
142-
end
143-
end
144-
145-
if found_singleplayerworld then
146-
core.delete_world(gamedata.worldindex)
147-
end
148-
149-
core.create_world("singleplayerworld", 1)
150-
worldlist = core.get_worlds()
151-
152-
for i = 1, #worldlist do
153-
if worldlist[i].name == "singleplayerworld" then
154-
gamedata.worldindex = i
155-
end
156-
end
157-
end
158-
159-
this.parent:show()
160-
this:hide()
161-
this:delete()
162-
return true
163-
end
164-
165-
local function showconfirm_reset(tabview)
166-
local new_dlg = dialog_create("reset_spworld",
167-
dlg_confirm_reset_formspec,
168-
dlg_confirm_reset_btnhandler,
169-
nil)
170-
new_dlg:set_parent(tabview)
171-
tabview:hide()
172-
new_dlg:show()
173-
end
174-
175125
local function formspec(tabview, name, tabdata)
176126
local tab_string =
177127
"box[0,0;3.75,4.5;#999999]" ..
@@ -218,16 +168,9 @@ local function formspec(tabview, name, tabdata)
218168
fgettext("Shaders (unavailable)")) .. "]"
219169
end
220170

221-
if core.settings:get("main_menu_style") == "simple" then
222-
-- 'Reset singleplayer world' only functions with simple menu
223-
tab_string = tab_string ..
224-
"button[8,4.75;3.95,1;btn_reset_singleplayer;"
225-
.. fgettext("Reset singleplayer world") .. "]"
226-
else
227-
tab_string = tab_string ..
228-
"button[8,4.75;3.95,1;btn_change_keys;"
229-
.. fgettext("Change Keys") .. "]"
230-
end
171+
tab_string = tab_string ..
172+
"button[8,4.75;3.95,1;btn_change_keys;"
173+
.. fgettext("Change Keys") .. "]"
231174

232175
tab_string = tab_string ..
233176
"button[0,4.75;3.95,1;btn_advanced_settings;"
@@ -359,10 +302,6 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
359302
core.settings:set("touchtarget", fields["cb_touchscreen_target"])
360303
return true
361304
end
362-
if fields["btn_reset_singleplayer"] then
363-
showconfirm_reset(this)
364-
return true
365-
end
366305

367306
--Note dropdowns have to be handled LAST!
368307
local ddhandled = false

‎builtin/mainmenu/tab_simple_main.lua

-220
This file was deleted.

‎builtin/settingtypes.txt

-6
Original file line numberDiff line numberDiff line change
@@ -1446,12 +1446,6 @@ curl_file_download_timeout (cURL file download timeout) int 300000
14461446
# Makes DirectX work with LuaJIT. Disable if it causes troubles.
14471447
high_precision_fpu (High-precision FPU) bool true
14481448

1449-
# Changes the main menu UI:
1450-
# - Full: Multiple singleplayer worlds, game choice, texture pack chooser, etc.
1451-
# - Simple: One singleplayer world, no game or texture pack choosers. May be
1452-
# necessary for smaller screens.
1453-
main_menu_style (Main menu style) enum full full,simple
1454-
14551449
# Replaces the default main menu with a custom one.
14561450
main_menu_script (Main menu script) string
14571451

‎src/defaultsettings.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ void set_default_settings(Settings *settings)
290290
settings->setDefault("joystick_frustum_sensitivity", "170");
291291

292292
// Main menu
293-
settings->setDefault("main_menu_style", "full");
294293
settings->setDefault("main_menu_path", "");
295294
settings->setDefault("serverlist_file", "favoriteservers.txt");
296295

0 commit comments

Comments
 (0)
Please sign in to comment.