Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
--Tutorial menu
--Copyright (C) 2014 sapier
--Copyright (C) 2016 celeron55
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
local function current_game()
local last_game_id = core.setting_get("menu_last_game")
local game, index = gamemgr.find_by_gameid(last_game_id)
return game
end
local function get_formspec(tabview, name, tabdata)
local retval = "size[12,5.2]"
retval = retval .. "bgcolor[#0000;true]"
local index = filterlist.get_current_index(menudata.worldlist,
tonumber(core.setting_get("mainmenu_last_selected_world"))
)
retval = retval ..
"button[0,4.95;2.6,0.5;back;< ".. fgettext("Back") .. "]" ..
"button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]"
return retval
end
local function on_change(type, old_tab, new_tab)
if (type == "ENTER") then
local game = current_game()
if game then
menudata.worldlist:set_filtercriteria(game.id)
core.set_topleft_text(game.name)
mm_texture.update("singleplayer",game)
end
--buttonbar:show()
else
menudata.worldlist:set_filtercriteria(nil)
--buttonbar:hide()
core.set_topleft_text("")
mm_texture.update(new_tab, nil)
end
end
local function main_button_handler(this, fields, name, tabdata)
if fields["play"] ~= nil or fields["key_enter"] then
local game = current_game()
menudata.worldlist:set_filtercriteria(game.id)
if menudata.worldlist:size() == 0 then
local game, gameidx = gamemgr.find_by_gameid(game.id)
local message = core.create_world("automatic_tutorial_world", gameidx)
if message ~= nil then
gamedata.errormessage = message
return true
end
end
menudata.worldlist:refresh()
-- Select some tutorial world
local current_worldlist = menudata.worldlist:get_list()
for i, v in ipairs(current_worldlist) do
gamedata.selected_world = menudata.worldlist:get_raw_index(i)
break
end
core.setting_set("creative_mode", "false")
core.setting_set("enable_damage", "true")
gamedata.singleplayer = true
core.start()
return true
end
if fields["back"] ~= nil then
this:delete()
return true
end
end
function create_menu()
local dlg = dialog_create("singleplayer",
get_formspec,
main_button_handler,
nil)
on_change("ENTER", nil, nil)
local delete_cb_old = dlg.delete
dlg.delete = function(self)
delete_cb_old(self)
on_change("LEAVE", nil, nil)
end
return dlg
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.