|
18 | 18 |
|
19 | 19 | local enable_gamebar = PLATFORM ~= "Android"
|
20 | 20 | local current_game, singleplayer_refresh_gamebar
|
| 21 | +local valid_disabled_settings = { |
| 22 | + ["enable_damage"]=true, |
| 23 | + ["creative_mode"]=true, |
| 24 | + ["enable_server"]=true, |
| 25 | +} |
21 | 26 |
|
22 | 27 | if enable_gamebar then
|
| 28 | + -- Currently chosen game in gamebar for theming and filtering |
23 | 29 | function current_game()
|
24 | 30 | local last_game_id = core.settings:get("menu_last_game")
|
25 | 31 | local game = pkgmgr.find_by_gameid(last_game_id)
|
@@ -102,37 +108,87 @@ if enable_gamebar then
|
102 | 108 | btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
|
103 | 109 | end
|
104 | 110 | else
|
| 111 | + -- Currently chosen game in gamebar: no gamebar -> no "current" game |
105 | 112 | function current_game()
|
106 | 113 | return nil
|
107 | 114 | end
|
108 | 115 | end
|
109 | 116 |
|
| 117 | +local function get_disabled_settings(game) |
| 118 | + if not game then |
| 119 | + return {} |
| 120 | + end |
| 121 | + |
| 122 | + local gameconfig = Settings(game.path .. "/game.conf") |
| 123 | + local disabled_settings = {} |
| 124 | + if gameconfig then |
| 125 | + local disabled_settings_str = (gameconfig:get("disabled_settings") or ""):split() |
| 126 | + for _, value in pairs(disabled_settings_str) do |
| 127 | + local state = false |
| 128 | + value = value:trim() |
| 129 | + if string.sub(value, 1, 1) == "!" then |
| 130 | + state = true |
| 131 | + value = string.sub(value, 2) |
| 132 | + end |
| 133 | + if valid_disabled_settings[value] then |
| 134 | + disabled_settings[value] = state |
| 135 | + else |
| 136 | + core.log("error", "Invalid disabled setting in game.conf: "..tostring(value)) |
| 137 | + end |
| 138 | + end |
| 139 | + end |
| 140 | + return disabled_settings |
| 141 | +end |
| 142 | + |
110 | 143 | local function get_formspec(tabview, name, tabdata)
|
111 | 144 | local retval = ""
|
112 | 145 |
|
113 | 146 | local index = filterlist.get_current_index(menudata.worldlist,
|
114 |
| - tonumber(core.settings:get("mainmenu_last_selected_world")) |
115 |
| - ) |
| 147 | + tonumber(core.settings:get("mainmenu_last_selected_world"))) |
| 148 | + local list = menudata.worldlist:get_list() |
| 149 | + local world = list and index and list[index] |
| 150 | + local gameid = world and world.gameid |
| 151 | + local game = gameid and pkgmgr.find_by_gameid(gameid) |
| 152 | + local disabled_settings = get_disabled_settings(game) |
| 153 | + |
| 154 | + local creative, damage, host = "", "", "" |
| 155 | + |
| 156 | + -- Y offsets for game settings checkboxes |
| 157 | + local y = -0.2 |
| 158 | + local yo = 0.45 |
| 159 | + |
| 160 | + if disabled_settings["creative_mode"] == nil then |
| 161 | + creative = "checkbox[0,"..y..";cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. |
| 162 | + dump(core.settings:get_bool("creative_mode")) .. "]" |
| 163 | + y = y + yo |
| 164 | + end |
| 165 | + if disabled_settings["enable_damage"] == nil then |
| 166 | + damage = "checkbox[0,"..y..";cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. |
| 167 | + dump(core.settings:get_bool("enable_damage")) .. "]" |
| 168 | + y = y + yo |
| 169 | + end |
| 170 | + if disabled_settings["enable_server"] == nil then |
| 171 | + host = "checkbox[0,"..y..";cb_server;".. fgettext("Host Server") ..";" .. |
| 172 | + dump(core.settings:get_bool("enable_server")) .. "]" |
| 173 | + y = y + yo |
| 174 | + end |
116 | 175 |
|
117 | 176 | retval = retval ..
|
118 | 177 | "button[3.9,3.8;2.8,1;world_delete;".. fgettext("Delete") .. "]" ..
|
119 | 178 | "button[6.55,3.8;2.8,1;world_configure;".. fgettext("Select Mods") .. "]" ..
|
120 | 179 | "button[9.2,3.8;2.8,1;world_create;".. fgettext("New") .. "]" ..
|
121 | 180 | "label[3.9,-0.05;".. fgettext("Select World:") .. "]"..
|
122 |
| - "checkbox[0,-0.20;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. |
123 |
| - dump(core.settings:get_bool("creative_mode")) .. "]".. |
124 |
| - "checkbox[0,0.25;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. |
125 |
| - dump(core.settings:get_bool("enable_damage")) .. "]".. |
126 |
| - "checkbox[0,0.7;cb_server;".. fgettext("Host Server") ..";" .. |
127 |
| - dump(core.settings:get_bool("enable_server")) .. "]" .. |
| 181 | + creative .. |
| 182 | + damage .. |
| 183 | + host .. |
128 | 184 | "textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
129 | 185 | menu_render_worldlist() ..
|
130 | 186 | ";" .. index .. "]"
|
131 | 187 |
|
132 |
| - if core.settings:get_bool("enable_server") then |
| 188 | + if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then |
133 | 189 | retval = retval ..
|
134 | 190 | "button[7.9,4.75;4.1,1;play;".. fgettext("Host Game") .. "]" ..
|
135 |
| - "checkbox[0,1.15;cb_server_announce;" .. fgettext("Announce Server") .. ";" .. |
| 191 | + "checkbox[0,"..y..";cb_server_announce;" .. fgettext("Announce Server") .. ";" .. |
136 | 192 | dump(core.settings:get_bool("server_announce")) .. "]" ..
|
137 | 193 | "field[0.3,2.85;3.8,0.5;te_playername;" .. fgettext("Name") .. ";" ..
|
138 | 194 | core.formspec_escape(core.settings:get("name")) .. "]" ..
|
@@ -227,9 +283,21 @@ local function main_button_handler(this, fields, name, tabdata)
|
227 | 283 |
|
228 | 284 | -- Update last game
|
229 | 285 | local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
| 286 | + local game_obj |
230 | 287 | if world then
|
231 |
| - local game = pkgmgr.find_by_gameid(world.gameid) |
232 |
| - core.settings:set("menu_last_game", game.id) |
| 288 | + game_obj = pkgmgr.find_by_gameid(world.gameid) |
| 289 | + core.settings:set("menu_last_game", game_obj.id) |
| 290 | + end |
| 291 | + |
| 292 | + local disabled_settings = get_disabled_settings(game_obj) |
| 293 | + for k, _ in pairs(valid_disabled_settings) do |
| 294 | + local v = disabled_settings[k] |
| 295 | + if v ~= nil then |
| 296 | + if k == "enable_server" and v == true then |
| 297 | + error("Setting 'enable_server' cannot be force-enabled! The game.conf needs to be fixed.") |
| 298 | + end |
| 299 | + core.settings:set_bool(k, disabled_settings[k]) |
| 300 | + end |
233 | 301 | end
|
234 | 302 |
|
235 | 303 | if core.settings:get_bool("enable_server") then
|
|
0 commit comments