| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,273 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --self 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. | ||
| -- | ||
| --self 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 self program; if not, write to the Free Software Foundation, Inc., | ||
| --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
|
||
|
|
||
| -------------------------------------------------------------------------------- | ||
| -- A tabview implementation -- | ||
| -- Usage: -- | ||
| -- tabview.create: returns initialized tabview raw element -- | ||
| -- element.add(tab): add a tab declaration -- | ||
| -- element.handle_buttons() -- | ||
| -- element.handle_events() -- | ||
| -- element.getFormspec() returns formspec of tabview -- | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function add_tab(self,tab) | ||
| assert(tab.size == nil or (type(tab.size) == table and | ||
| tab.size.x ~= nil and tab.size.y ~= nil)) | ||
| assert(tab.cbf_formspec ~= nil and type(tab.cbf_formspec) == "function") | ||
| assert(tab.cbf_button_handler == nil or | ||
| type(tab.cbf_button_handler) == "function") | ||
| assert(tab.cbf_events == nil or type(tab.cbf_events) == "function") | ||
|
|
||
| local newtab = { | ||
| name = tab.name, | ||
| caption = tab.caption, | ||
| button_handler = tab.cbf_button_handler, | ||
| event_handler = tab.cbf_events, | ||
| get_formspec = tab.cbf_formspec, | ||
| tabsize = tab.tabsize, | ||
| on_change = tab.on_change, | ||
| tabdata = {}, | ||
| } | ||
|
|
||
| table.insert(self.tablist,newtab) | ||
|
|
||
| if self.last_tab_index == #self.tablist then | ||
| self.current_tab = tab.name | ||
| if tab.on_activate ~= nil then | ||
| tab.on_activate(nil,tab.name) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function get_formspec(self) | ||
| local formspec = "" | ||
|
|
||
| if not self.hidden and (self.parent == nil or not self.parent.hidden) then | ||
|
|
||
| if self.parent == nil then | ||
| local tsize = self.tablist[self.last_tab_index].tabsize or | ||
| {width=self.width, height=self.height} | ||
| formspec = formspec .. | ||
| string.format("size[%f,%f,%s]",tsize.width,tsize.height, | ||
| dump(self.fixed_size)) | ||
| end | ||
| formspec = formspec .. self:tab_header() | ||
| formspec = formspec .. | ||
| self.tablist[self.last_tab_index].get_formspec( | ||
| self, | ||
| self.tablist[self.last_tab_index].name, | ||
| self.tablist[self.last_tab_index].tabdata, | ||
| self.tablist[self.last_tab_index].tabsize | ||
| ) | ||
| end | ||
| return formspec | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function handle_buttons(self,fields) | ||
|
|
||
| if self.hidden then | ||
| return false | ||
| end | ||
|
|
||
| if self:handle_tab_buttons(fields) then | ||
| return true | ||
| end | ||
|
|
||
| if self.glb_btn_handler ~= nil and | ||
| self.glb_btn_handler(self,fields) then | ||
| return true | ||
| end | ||
|
|
||
| if self.tablist[self.last_tab_index].button_handler ~= nil then | ||
| return | ||
| self.tablist[self.last_tab_index].button_handler( | ||
| self, | ||
| fields, | ||
| self.tablist[self.last_tab_index].name, | ||
| self.tablist[self.last_tab_index].tabdata | ||
| ) | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function handle_events(self,event) | ||
|
|
||
| if self.hidden then | ||
| return false | ||
| end | ||
|
|
||
| if self.glb_evt_handler ~= nil and | ||
| self.glb_evt_handler(self,event) then | ||
| return true | ||
| end | ||
|
|
||
| if self.tablist[self.last_tab_index].evt_handler ~= nil then | ||
| return | ||
| self.tablist[self.last_tab_index].evt_handler( | ||
| self, | ||
| event, | ||
| self.tablist[self.last_tab_index].name, | ||
| self.tablist[self.last_tab_index].tabdata | ||
| ) | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function tab_header(self) | ||
|
|
||
| local toadd = "" | ||
|
|
||
| for i=1,#self.tablist,1 do | ||
|
|
||
| if toadd ~= "" then | ||
| toadd = toadd .. "," | ||
| end | ||
|
|
||
| toadd = toadd .. self.tablist[i].caption | ||
| end | ||
| return string.format("tabheader[%f,%f;%s;%s;%i;true;false]", | ||
| self.header_x, self.header_y, self.name, toadd, self.last_tab_index); | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function switch_to_tab(self, index) | ||
| --first call on_change for tab to leave | ||
| if self.tablist[self.last_tab_index].on_change ~= nil then | ||
| self.tablist[self.last_tab_index].on_change("LEAVE", | ||
| self.current_tab, self.tablist[index].name) | ||
| end | ||
|
|
||
| --update tabview data | ||
| self.last_tab_index = index | ||
| local old_tab = self.current_tab | ||
| self.current_tab = self.tablist[index].name | ||
|
|
||
| if (self.autosave_tab) then | ||
| core.setting_set(self.name .. "_LAST",self.current_tab) | ||
| end | ||
|
|
||
| -- call for tab to enter | ||
| if self.tablist[index].on_change ~= nil then | ||
| self.tablist[index].on_change("ENTER", | ||
| old_tab,self.current_tab) | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function handle_tab_buttons(self,fields) | ||
| --save tab selection to config file | ||
| if fields[self.name] then | ||
| local index = tonumber(fields[self.name]) | ||
| switch_to_tab(self, index) | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function set_tab_by_name(self, name) | ||
| for i=1,#self.tablist,1 do | ||
| if self.tablist[i].name == name then | ||
| switch_to_tab(self, i) | ||
| return true | ||
| end | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function hide_tabview(self) | ||
| self.hidden=true | ||
|
|
||
| --call on_change as we're not gonna show self tab any longer | ||
| if self.tablist[self.last_tab_index].on_change ~= nil then | ||
| self.tablist[self.last_tab_index].on_change("LEAVE", | ||
| self.current_tab, nil) | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function show_tabview(self) | ||
| self.hidden=false | ||
|
|
||
| -- call for tab to enter | ||
| if self.tablist[self.last_tab_index].on_change ~= nil then | ||
| self.tablist[self.last_tab_index].on_change("ENTER", | ||
| nil,self.current_tab) | ||
| end | ||
| end | ||
|
|
||
| local tabview_metatable = { | ||
| add = add_tab, | ||
| handle_buttons = handle_buttons, | ||
| handle_events = handle_events, | ||
| get_formspec = get_formspec, | ||
| show = show_tabview, | ||
| hide = hide_tabview, | ||
| delete = function(self) ui.delete(self) end, | ||
| set_parent = function(self,parent) self.parent = parent end, | ||
| set_autosave_tab = | ||
| function(self,value) self.autosave_tab = value end, | ||
| set_tab = set_tab_by_name, | ||
| set_global_button_handler = | ||
| function(self,handler) self.glb_btn_handler = handler end, | ||
| set_global_event_handler = | ||
| function(self,handler) self.glb_evt_handler = handler end, | ||
| set_fixed_size = | ||
| function(self,state) self.fixed_size = state end, | ||
| tab_header = tab_header, | ||
| handle_tab_buttons = handle_tab_buttons | ||
| } | ||
|
|
||
| tabview_metatable.__index = tabview_metatable | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function tabview_create(name, size, tabheaderpos) | ||
| local self = {} | ||
|
|
||
| self.name = name | ||
| self.type = "toplevel" | ||
| self.width = size.x | ||
| self.height = size.y | ||
| self.header_x = tabheaderpos.x | ||
| self.header_y = tabheaderpos.y | ||
|
|
||
| setmetatable(self, tabview_metatable) | ||
|
|
||
| self.fixed_size = true | ||
| self.hidden = true | ||
| self.current_tab = nil | ||
| self.last_tab_index = 1 | ||
| self.tablist = {} | ||
|
|
||
| self.autosave_tab = false | ||
|
|
||
| ui.add(self) | ||
| return self | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --self 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. | ||
| -- | ||
| --self 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 self program; if not, write to the Free Software Foundation, Inc., | ||
| --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
|
||
| ui = {} | ||
| ui.childlist = {} | ||
| ui.default = nil | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.add(child) | ||
| --TODO check child | ||
| ui.childlist[child.name] = child | ||
|
|
||
| return child.name | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.delete(child) | ||
|
|
||
| if ui.childlist[child.name] == nil then | ||
| return false | ||
| end | ||
|
|
||
| ui.childlist[child.name] = nil | ||
| return true | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.set_default(name) | ||
| ui.default = name | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.find_by_name(name) | ||
| return ui.childlist[name] | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| -------------------------------------------------------------------------------- | ||
| -- Internal functions not to be called from user | ||
| -------------------------------------------------------------------------------- | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.update() | ||
| local formspec = "" | ||
|
|
||
| -- handle errors | ||
| if gamedata ~= nil and gamedata.errormessage ~= nil then | ||
| formspec = "size[12,3.2]" .. | ||
| "textarea[1,1;10,2;;ERROR: " .. | ||
| core.formspec_escape(gamedata.errormessage) .. | ||
| ";]".. | ||
| "button[4.5,2.5;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]" | ||
| else | ||
| local active_toplevel_ui_elements = 0 | ||
| for key,value in pairs(ui.childlist) do | ||
| if (value.type == "toplevel") then | ||
| local retval = value:get_formspec() | ||
|
|
||
| if retval ~= nil and retval ~= "" then | ||
| active_toplevel_ui_elements = active_toplevel_ui_elements +1 | ||
| formspec = formspec .. retval | ||
| end | ||
| end | ||
| end | ||
|
|
||
| -- no need to show addons if there ain't a toplevel element | ||
| if (active_toplevel_ui_elements > 0) then | ||
| for key,value in pairs(ui.childlist) do | ||
| if (value.type == "addon") then | ||
| local retval = value:get_formspec() | ||
|
|
||
| if retval ~= nil and retval ~= "" then | ||
| formspec = formspec .. retval | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if (active_toplevel_ui_elements > 1) then | ||
| print("WARNING: ui manager detected more then one active ui element, self most likely isn't intended") | ||
| end | ||
|
|
||
| if (active_toplevel_ui_elements == 0) then | ||
| print("WARNING: not a single toplevel ui element active switching to default") | ||
| ui.childlist[ui.default]:show() | ||
| formspec = ui.childlist[ui.default]:get_formspec() | ||
| end | ||
| end | ||
| core.update_formspec(formspec) | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.handle_buttons(fields) | ||
|
|
||
| if fields["btn_error_confirm"] then | ||
| gamedata.errormessage = nil | ||
| update_menu() | ||
| return | ||
| end | ||
|
|
||
| for key,value in pairs(ui.childlist) do | ||
|
|
||
| local retval = value:handle_buttons(fields) | ||
|
|
||
| if retval then | ||
| ui.update() | ||
| return | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function ui.handle_events(event) | ||
|
|
||
| for key,value in pairs(ui.childlist) do | ||
|
|
||
| if value.handle_events ~= nil then | ||
| local retval = value:handle_events(event) | ||
|
|
||
| if retval then | ||
| print("event handled by: " .. key) | ||
| return retval | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| -------------------------------------------------------------------------------- | ||
| -- initialize callbacks | ||
| -------------------------------------------------------------------------------- | ||
| -------------------------------------------------------------------------------- | ||
| core.button_handler = function(fields) | ||
| if fields["btn_error_confirm"] then | ||
| gamedata.errormessage = nil | ||
| ui.update() | ||
| return | ||
| end | ||
|
|
||
| if ui.handle_buttons(fields) then | ||
| ui.update() | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| core.event_handler = function(event) | ||
| if ui.handle_events(event) then | ||
| ui.update() | ||
| return | ||
| end | ||
|
|
||
| if event == "Refresh" then | ||
| ui.update() | ||
| return | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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. | ||
| -------------------------------------------------------------------------------- | ||
| -- Global menu data | ||
| --------------------------------------------------------------------------------- | ||
| menudata = {} | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| -- Menu helper functions | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function render_favorite(spec,render_details) | ||
| local text = "" | ||
|
|
||
| if spec.name ~= nil then | ||
| text = text .. core.formspec_escape(spec.name:trim()) | ||
|
|
||
| -- if spec.description ~= nil and | ||
| -- core.formspec_escape(spec.description):trim() ~= "" then | ||
| -- text = text .. " (" .. core.formspec_escape(spec.description) .. ")" | ||
| -- end | ||
| else | ||
| if spec.address ~= nil then | ||
| text = text .. spec.address:trim() | ||
|
|
||
| if spec.port ~= nil then | ||
| text = text .. ":" .. spec.port | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if not render_details then | ||
| return text | ||
| end | ||
|
|
||
| local details = "" | ||
| if spec.password == true then | ||
| details = details .. "*" | ||
| else | ||
| details = details .. "_" | ||
| end | ||
|
|
||
| if spec.creative then | ||
| details = details .. "C" | ||
| else | ||
| details = details .. "_" | ||
| end | ||
|
|
||
| if spec.damage then | ||
| details = details .. "D" | ||
| else | ||
| details = details .. "_" | ||
| end | ||
|
|
||
| if spec.pvp then | ||
| details = details .. "P" | ||
| else | ||
| details = details .. "_" | ||
| end | ||
| details = details .. " " | ||
|
|
||
| local playercount = "" | ||
|
|
||
| if spec.clients ~= nil and | ||
| spec.clients_max ~= nil then | ||
| playercount = string.format("%03d",spec.clients) .. "/" .. | ||
| string.format("%03d",spec.clients_max) .. " " | ||
| end | ||
|
|
||
| return playercount .. core.formspec_escape(details) .. text | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| os.tempfolder = function() | ||
| if core.setting_get("TMPFolder") then | ||
| return core.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000) | ||
| end | ||
|
|
||
| local filetocheck = os.tmpname() | ||
| os.remove(filetocheck) | ||
|
|
||
| local randname = "MTTempModFolder_" .. math.random(0,10000) | ||
| if DIR_DELIM == "\\" then | ||
| local tempfolder = os.getenv("TEMP") | ||
| return tempfolder .. filetocheck | ||
| else | ||
| local backstring = filetocheck:reverse() | ||
| return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname | ||
| end | ||
|
|
||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function menu_render_worldlist() | ||
| local retval = "" | ||
|
|
||
| local current_worldlist = menudata.worldlist:get_list() | ||
|
|
||
| for i,v in ipairs(current_worldlist) do | ||
| if retval ~= "" then | ||
| retval = retval .."," | ||
| end | ||
|
|
||
| retval = retval .. core.formspec_escape(v.name) .. | ||
| " \\[" .. core.formspec_escape(v.gameid) .. "\\]" | ||
| end | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function menu_handle_key_up_down(fields,textlist,settingname) | ||
|
|
||
| if fields["key_up"] then | ||
| local oldidx = core.get_textlist_index(textlist) | ||
|
|
||
| if oldidx ~= nil and oldidx > 1 then | ||
| local newidx = oldidx -1 | ||
| core.setting_set(settingname, | ||
| menudata.worldlist:get_raw_index(newidx)) | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| if fields["key_down"] then | ||
| local oldidx = core.get_textlist_index(textlist) | ||
|
|
||
| if oldidx ~= nil and oldidx < menudata.worldlist:size() then | ||
| local newidx = oldidx + 1 | ||
| core.setting_set(settingname, | ||
| menudata.worldlist:get_raw_index(newidx)) | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function asyncOnlineFavourites() | ||
|
|
||
| menudata.favorites = {} | ||
| core.handle_async( | ||
| function(param) | ||
| return core.get_favorites("online") | ||
| end, | ||
| nil, | ||
| function(result) | ||
| menudata.favorites = result | ||
| core.event_handler("Refresh") | ||
| end | ||
| ) | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency) | ||
| local textlines = core.splittext(text,textlen) | ||
|
|
||
| local retval = "textlist[" .. xpos .. "," .. ypos .. ";" | ||
| .. width .. "," .. height .. ";" | ||
| .. tl_name .. ";" | ||
|
|
||
| for i=1, #textlines, 1 do | ||
| textlines[i] = textlines[i]:gsub("\r","") | ||
| retval = retval .. core.formspec_escape(textlines[i]) .. "," | ||
| end | ||
|
|
||
| retval = retval .. ";0;" | ||
|
|
||
| if transparency then | ||
| retval = retval .. "true" | ||
| end | ||
|
|
||
| retval = retval .. "]" | ||
|
|
||
| return retval | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,290 @@ | ||
| --Minetest | ||
| --Copyright (C) 2013 sapier | ||
| -- | ||
| --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 get_formspec(data) | ||
|
|
||
| local mod = data.list:get_list()[data.selected_mod] | ||
|
|
||
| local retval = | ||
| "size[11,6.5,true]" .. | ||
| "label[0.5,-0.25;" .. fgettext("World:") .. "]" .. | ||
| "label[1.75,-0.25;" .. data.worldspec.name .. "]" | ||
|
|
||
| if data.hide_gamemods then | ||
| retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]" | ||
| else | ||
| retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]" | ||
| end | ||
|
|
||
| if data.hide_modpackcontents then | ||
| retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]" | ||
| else | ||
| retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]" | ||
| end | ||
|
|
||
| if mod == nil then | ||
| mod = {name=""} | ||
| end | ||
|
|
||
| retval = retval .. | ||
| "label[0,0.45;" .. fgettext("Mod:") .. "]" .. | ||
| "label[0.75,0.45;" .. mod.name .. "]" .. | ||
| "label[0,1;" .. fgettext("Depends:") .. "]" .. | ||
| "textlist[0,1.5;5,4.25;world_config_depends;" .. | ||
| modmgr.get_dependencies(mod.path) .. ";0]" .. | ||
| "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. | ||
| "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" | ||
|
|
||
| if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then | ||
| if mod.is_modpack then | ||
| local rawlist = data.list:get_raw_list() | ||
|
|
||
| local all_enabled = true | ||
| for j=1,#rawlist,1 do | ||
| if rawlist[j].modpack == mod.name and | ||
| rawlist[j].enabled ~= true then | ||
| all_enabled = false | ||
| break | ||
| end | ||
| end | ||
|
|
||
| if all_enabled == false then | ||
| retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]" | ||
| else | ||
| retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]" | ||
| end | ||
| else | ||
| if mod.enabled then | ||
| retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]" | ||
| else | ||
| retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| retval = retval .. | ||
| "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" .. | ||
| "textlist[5.5,0.5;5.5,5.75;world_config_modlist;" | ||
|
|
||
| retval = retval .. modmgr.render_modlist(data.list) | ||
| retval = retval .. ";" .. data.selected_mod .."]" | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| local function enable_mod(this, toset) | ||
| local mod = this.data.list:get_list()[this.data.selected_mod] | ||
|
|
||
| if mod.typ == "game_mod" then | ||
| -- game mods can't be enabled or disabled | ||
| elseif not mod.is_modpack then | ||
| if toset == nil then | ||
| mod.enabled = not mod.enabled | ||
| else | ||
| mod.enabled = toset | ||
| end | ||
| else | ||
| local list = this.data.list:get_raw_list() | ||
| for i=1,#list,1 do | ||
| if list[i].modpack == mod.name then | ||
| if toset == nil then | ||
| toset = not list[i].enabled | ||
| end | ||
| list[i].enabled = toset | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| local function handle_buttons(this, fields) | ||
|
|
||
| if fields["world_config_modlist"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["world_config_modlist"]) | ||
| this.data.selected_mod = event.index | ||
|
|
||
| if event.type == "DCL" then | ||
| enable_mod(this) | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| if fields["key_enter"] ~= nil then | ||
| enable_mod(this) | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_mod_enable"] ~= nil then | ||
| local toset = core.is_yes(fields["cb_mod_enable"]) | ||
| enable_mod(this,toset) | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_mp_enable"] ~= nil or | ||
| fields["btn_mp_disable"] then | ||
| local toset = (fields["btn_mp_enable"] ~= nil) | ||
| enable_mod(this,toset) | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_hide_gamemods"] ~= nil or | ||
| fields["cb_hide_mpcontent"] ~= nil then | ||
| local current = this.data.list:get_filtercriteria() | ||
|
|
||
| if current == nil then | ||
| current = {} | ||
| end | ||
|
|
||
| if core.is_yes(fields["cb_hide_gamemods"]) then | ||
| current.hide_game = true | ||
| this.data.hide_gamemods = true | ||
| else | ||
| current.hide_game = false | ||
| this.data.hide_gamemods = false | ||
| end | ||
|
|
||
| if core.is_yes(fields["cb_hide_mpcontent"]) then | ||
| current.hide_modpackcontents = true | ||
| this.data.hide_modpackcontents = true | ||
| else | ||
| current.hide_modpackcontents = false | ||
| this.data.hide_modpackcontents = false | ||
| end | ||
|
|
||
| this.data.list:set_filtercriteria(current) | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_config_world_save"] then | ||
|
|
||
| local filename = this.data.worldspec.path .. | ||
| DIR_DELIM .. "world.mt" | ||
|
|
||
| local worldfile = Settings(filename) | ||
| local mods = worldfile:to_table() | ||
|
|
||
| local rawlist = this.data.list:get_raw_list() | ||
|
|
||
| local i,mod | ||
| for i,mod in ipairs(rawlist) do | ||
| if not mod.is_modpack and | ||
| mod.typ ~= "game_mod" then | ||
| if mod.enabled then | ||
| worldfile:set("load_mod_"..mod.name, "true") | ||
| else | ||
| worldfile:set("load_mod_"..mod.name, "false") | ||
| end | ||
| mods["load_mod_"..mod.name] = nil | ||
| end | ||
| end | ||
|
|
||
| -- Remove mods that are not present anymore | ||
| for key,value in pairs(mods) do | ||
| if key:sub(1,9) == "load_mod_" then | ||
| worldfile:remove(key) | ||
| end | ||
| end | ||
|
|
||
| if not worldfile:write() then | ||
| core.log("error", "Failed to write world config file") | ||
| end | ||
|
|
||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_config_world_cancel"] then | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_all_mods"] then | ||
| local list = this.data.list:get_raw_list() | ||
|
|
||
| for i=1,#list,1 do | ||
| if list[i].typ ~= "game_mod" and | ||
| not list[i].is_modpack then | ||
| list[i].enabled = true | ||
| end | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| function create_configure_world_dlg(worldidx) | ||
|
|
||
| local dlg = dialog_create("sp_config_world", | ||
| get_formspec, | ||
| handle_buttons, | ||
| nil) | ||
|
|
||
| --TODO read from settings | ||
| dlg.data.hide_gamemods = false | ||
| dlg.data.hide_modpackcontents = false | ||
| dlg.data.selected_mod = 0 | ||
|
|
||
| dlg.data.worldspec = core.get_worlds()[worldidx] | ||
| if dlg.data.worldspec == nil then dlg:delete() return nil end | ||
|
|
||
| dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path) | ||
|
|
||
| if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or | ||
| dlg.data.worldconfig.id == "" then | ||
|
|
||
| dlg:delete() | ||
| return nil | ||
| end | ||
|
|
||
| dlg.data.list = filterlist.create( | ||
| modmgr.preparemodlist, --refresh | ||
| modmgr.comparemod, --compare | ||
| function(element,uid) --uid match | ||
| if element.name == uid then | ||
| return true | ||
| end | ||
| end, | ||
| function(element,criteria) | ||
| if criteria.hide_game and | ||
| element.typ == "game_mod" then | ||
| return false | ||
| end | ||
|
|
||
| if criteria.hide_modpackcontents and | ||
| element.modpack ~= nil then | ||
| return false | ||
| end | ||
| return true | ||
| end, --filter | ||
| { worldpath= dlg.data.worldspec.path, | ||
| gameid = dlg.data.worldspec.gameid } | ||
| ) | ||
|
|
||
| dlg.data.list:set_filtercriteria( | ||
| { | ||
| hide_game=dlg.data.hide_gamemods, | ||
| hide_modpackcontents= dlg.data.hide_modpackcontents | ||
| }) | ||
| dlg.data.list:add_sort_mechanism("alphabetic", sort_mod_list) | ||
| dlg.data.list:set_sortmode("alphabetic") | ||
|
|
||
| return dlg | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 create_world_formspec(dialogdata) | ||
| local mapgens = {"v6", "v7", "indev", "singlenode", "math"} | ||
|
|
||
| local current_seed = core.setting_get("fixed_map_seed") or "" | ||
| local current_mg = core.setting_get("mg_name") | ||
|
|
||
| local mglist = "" | ||
| local selindex = 1 | ||
| local i = 1 | ||
| for k,v in pairs(mapgens) do | ||
| if current_mg == v then | ||
| selindex = i | ||
| end | ||
| i = i + 1 | ||
| mglist = mglist .. v .. "," | ||
| end | ||
| mglist = mglist:sub(1, -2) | ||
|
|
||
| local gameid = core.setting_get("menu_last_game") | ||
|
|
||
| local game, gameidx = nil , 0 | ||
| if gameid ~= nil then | ||
| game, gameidx = gamemgr.find_by_gameid(gameid) | ||
|
|
||
| if gameidx == nil then | ||
| gameidx = 0 | ||
| end | ||
| end | ||
|
|
||
| local retval = | ||
| "size[12,6,true]" .. | ||
| "label[2,0;" .. fgettext("World name") .. "]".. | ||
| "field[4.5,0.4;6,0.5;te_world_name;;]" .. | ||
|
|
||
| "label[2,1;" .. fgettext("Seed") .. "]".. | ||
| "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" .. | ||
|
|
||
| "label[2,2;" .. fgettext("Mapgen") .. "]".. | ||
| "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" .. | ||
|
|
||
| "label[2,3;" .. fgettext("Game") .. "]".. | ||
| "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() .. | ||
| ";" .. gameidx .. ";true]" .. | ||
|
|
||
| "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" .. | ||
| "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]" | ||
|
|
||
| return retval | ||
|
|
||
| end | ||
|
|
||
| local function create_world_buttonhandler(this, fields) | ||
|
|
||
| if fields["world_create_confirm"] or | ||
| fields["key_enter"] then | ||
|
|
||
| local worldname = fields["te_world_name"] | ||
| local gameindex = core.get_textlist_index("games") | ||
|
|
||
| if gameindex ~= nil and | ||
| worldname ~= "" then | ||
|
|
||
| local message = nil | ||
|
|
||
| if not menudata.worldlist:uid_exists_raw(worldname) then | ||
| core.setting_set("mg_name",fields["dd_mapgen"]) | ||
| message = core.create_world(worldname,gameindex) | ||
| else | ||
| message = fgettext("A world named \"$1\" already exists", worldname) | ||
| end | ||
|
|
||
| core.setting_set("fixed_map_seed", fields["te_seed"]) | ||
|
|
||
| if message ~= nil then | ||
| gamedata.errormessage = message | ||
| else | ||
| core.setting_set("menu_last_game",gamemgr.games[gameindex].id) | ||
| if this.data.update_worldlist_filter then | ||
| menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id) | ||
| mm_texture.update("singleplayer", gamemgr.games[gameindex].id) | ||
| end | ||
| menudata.worldlist:refresh() | ||
| core.setting_set("mainmenu_last_selected_world", | ||
| menudata.worldlist:raw_index_by_uid(worldname)) | ||
| end | ||
| else | ||
| gamedata.errormessage = | ||
| fgettext("No worldname given or no game selected") | ||
| end | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["games"] then | ||
| return true | ||
| end | ||
|
|
||
| if fields["world_create_cancel"] then | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
|
|
||
| function create_create_world_dlg(update_worldlistfilter) | ||
| local retval = dialog_create("sp_create_world", | ||
| create_world_formspec, | ||
| create_world_buttonhandler, | ||
| nil) | ||
| retval.update_worldlist_filter = update_worldlistfilter | ||
|
|
||
| return retval | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 delete_mod_formspec(dialogdata) | ||
|
|
||
| dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected] | ||
|
|
||
| local retval = | ||
| "size[12.4,5,true]" .. | ||
| "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. ";]".. | ||
| "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" .. | ||
| "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]" | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function delete_mod_buttonhandler(this, fields) | ||
| if fields["dlg_delete_mod_confirm"] ~= nil then | ||
|
|
||
| if this.data.mod.path ~= nil and | ||
| this.data.mod.path ~= "" and | ||
| this.data.mod.path ~= core.get_modpath() then | ||
| if not core.delete_dir(this.data.mod.path) then | ||
| gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path) | ||
| end | ||
| modmgr.refresh_globals() | ||
| else | ||
| gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path) | ||
| end | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["dlg_delete_mod_cancel"] then | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function create_delete_mod_dlg(selected_index) | ||
|
|
||
| local retval = dialog_create("dlg_delete_mod", | ||
| delete_mod_formspec, | ||
| delete_mod_buttonhandler, | ||
| nil) | ||
| retval.data.selected = selected_index | ||
| return retval | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 create_world_formspec(dialogdata) | ||
|
|
||
| local retval = | ||
| "size[12,6,true]" .. | ||
| "label[2,2;" .. | ||
| fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]".. | ||
| "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" .. | ||
| "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]" | ||
| return retval | ||
| end | ||
|
|
||
| local function create_world_buttonhandler(this, fields) | ||
| if fields["world_delete_confirm"] then | ||
|
|
||
| if this.data.delete_index > 0 and | ||
| this.data.delete_index <= #menudata.worldlist:get_raw_list() then | ||
| core.delete_world(this.data.delete_index) | ||
| menudata.worldlist:refresh() | ||
| end | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["world_delete_cancel"] then | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
|
|
||
| function create_delete_world_dlg(name_to_del,index_to_del) | ||
|
|
||
| assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "") | ||
| assert(index_to_del ~= nil and type(index_to_del) == "number") | ||
|
|
||
| local retval = dialog_create("sp_create_world", | ||
| create_world_formspec, | ||
| create_world_buttonhandler, | ||
| nil) | ||
| retval.data.delete_name = name_to_del | ||
| retval.data.delete_index = index_to_del | ||
|
|
||
| return retval | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 rename_modpack_formspec(dialogdata) | ||
|
|
||
| dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected] | ||
|
|
||
| local retval = | ||
| "size[12.4,5,true]" .. | ||
| "label[1.75,1;".. fgettext("Rename Modpack:") .. "]".. | ||
| "field[4.5,1.4;6,0.5;te_modpack_name;;" .. | ||
| dialogdata.mod.name .. | ||
| "]" .. | ||
| "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;".. | ||
| fgettext("Accept") .. "]" .. | ||
| "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;".. | ||
| fgettext("Cancel") .. "]" | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function rename_modpack_buttonhandler(this, fields) | ||
| if fields["dlg_rename_modpack_confirm"] ~= nil then | ||
| local oldpath = core.get_modpath() .. DIR_DELIM .. this.data.mod.name | ||
| local targetpath = core.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"] | ||
| core.copy_dir(oldpath,targetpath,false) | ||
| modmgr.refresh_globals() | ||
| modmgr.selected_mod = modmgr.global_mods:get_current_index( | ||
| modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"])) | ||
|
|
||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| if fields["dlg_rename_modpack_cancel"] then | ||
| this:delete() | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| function create_rename_modpack_dlg(selected_index) | ||
|
|
||
| local retval = dialog_create("dlg_delete_mod", | ||
| rename_modpack_formspec, | ||
| rename_modpack_buttonhandler, | ||
| nil) | ||
| retval.data.selected = selected_index | ||
| return retval | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| --Minetest | ||
| --Copyright (C) 2013 sapier | ||
| -- | ||
| --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. | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
|
|
||
| tab_credits = { | ||
| name = "credits", | ||
| caption = fgettext("Credits"), | ||
| cbf_formspec = function (tabview, name, tabdata) | ||
| local logofile = defaulttexturedir .. "logo.png" | ||
| return "vertlabel[0,-0.5;CREDITS]" .. | ||
| "label[0.5,3;Minetest " .. core.get_version() .. "]" .. | ||
| "label[0.5,3.3;http://minetest.net]" .. | ||
| "image[0.5,1;" .. core.formspec_escape(logofile) .. "]" .. | ||
| "textlist[3.5,-0.25;8.5,5.8;list_credits;" .. | ||
| "#FFFF00" .. fgettext("Core Developers") .."," .. | ||
| "Perttu Ahola (celeron55) <celeron55@gmail.com>,".. | ||
| "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,".. | ||
| "PilzAdam <pilzadam@minetest.net>," .. | ||
| "Ilya Zhuravlev (xyz) <xyz@minetest.net>,".. | ||
| "Lisa Milne (darkrose) <lisa@ltmnet.com>,".. | ||
| "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,".. | ||
| "proller <proler@gmail.com>,".. | ||
| "sfan5 <sfan5@live.de>,".. | ||
| "kahrl <kahrl@gmx.net>,".. | ||
| "sapier,".. | ||
| "ShadowNinja <shadowninja@minetest.net>,".. | ||
| "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,".. | ||
| "BlockMen,".. | ||
| ",".. | ||
| "#FFFF00" .. fgettext("Active Contributors") .. "," .. | ||
| "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,".. | ||
| "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,".. | ||
| "Jeija <jeija@mesecons.net>,".. | ||
| "MirceaKitsune <mirceakitsune@gmail.com>,".. | ||
| "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,".. | ||
| "0gb.us <0gb.us@0gb.us>,".. | ||
| "," .. | ||
| "#FFFF00" .. fgettext("Previous Contributors") .. "," .. | ||
| "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,".. | ||
| "Jonathan Neuschafer <j.neuschaefer@gmx.net>,".. | ||
| "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,".. | ||
| "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,".. | ||
| "matttpt <matttpt@gmail.com>,".. | ||
| "JacobF <queatz@gmail.com>,".. | ||
| ";0;true]" | ||
| end | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 get_formspec(tabview, name, tabdata) | ||
|
|
||
| if modmgr.global_mods == nil then | ||
| modmgr.refresh_globals() | ||
| end | ||
|
|
||
| if tabdata.selected_mod == nil then | ||
| tabdata.selected_mod = 1 | ||
| end | ||
|
|
||
| local retval = | ||
| "vertlabel[0,-0.25;".. fgettext("MODS") .. "]" .. | ||
| "label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" .. | ||
| "textlist[0.75,0.25;4.5,4;modlist;" .. | ||
| modmgr.render_modlist(modmgr.global_mods) .. | ||
| ";" .. tabdata.selected_mod .. "]" | ||
|
|
||
| retval = retval .. | ||
| "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" .. | ||
| -- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization | ||
| -- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" .. | ||
| "button[2.45,4.85;3.05,0.5;btn_modstore;".. fgettext("Online mod repository") .. "]" | ||
|
|
||
| local selected_mod = nil | ||
|
|
||
| if filterlist.size(modmgr.global_mods) >= tabdata.selected_mod then | ||
| selected_mod = modmgr.global_mods:get_list()[tabdata.selected_mod] | ||
| end | ||
|
|
||
| if selected_mod ~= nil then | ||
| local modscreenshot = nil | ||
|
|
||
| --check for screenshot beeing available | ||
| local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png" | ||
| local error = nil | ||
| local screenshotfile,error = io.open(screenshotfilename,"r") | ||
| if error == nil then | ||
| screenshotfile:close() | ||
| modscreenshot = screenshotfilename | ||
| end | ||
|
|
||
| if modscreenshot == nil then | ||
| modscreenshot = modstore.basetexturedir .. "no_screenshot.png" | ||
| end | ||
|
|
||
| retval = retval | ||
| .. "image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" | ||
| .. "label[8.25,0.6;" .. selected_mod.name .. "]" | ||
|
|
||
| local descriptionlines = nil | ||
| error = nil | ||
| local descriptionfilename = selected_mod.path .. "description.txt" | ||
| local descriptionfile,error = io.open(descriptionfilename,"r") | ||
| if error == nil then | ||
| local descriptiontext = descriptionfile:read("*all") | ||
|
|
||
| descriptionlines = core.splittext(descriptiontext,42) | ||
| descriptionfile:close() | ||
| else | ||
| descriptionlines = {} | ||
| table.insert(descriptionlines,fgettext("No mod description available")) | ||
| end | ||
|
|
||
| retval = retval .. | ||
| "label[5.5,1.7;".. fgettext("Mod information:") .. "]" .. | ||
| "textlist[5.5,2.2;6.2,2.4;description;" | ||
|
|
||
| for i=1,#descriptionlines,1 do | ||
| retval = retval .. core.formspec_escape(descriptionlines[i]) .. "," | ||
| end | ||
|
|
||
|
|
||
| if selected_mod.is_modpack then | ||
| retval = retval .. ";0]" .. | ||
| "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" .. | ||
| fgettext("Rename") .. "]" | ||
| retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;" | ||
| .. fgettext("Uninstall selected modpack") .. "]" | ||
| else | ||
| --show dependencies | ||
|
|
||
| retval = retval .. ",Depends:," | ||
|
|
||
| local toadd = modmgr.get_dependencies(selected_mod.path) | ||
|
|
||
| retval = retval .. toadd .. ";0]" | ||
|
|
||
| retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;" | ||
| .. fgettext("Uninstall selected mod") .. "]" | ||
| end | ||
| end | ||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function handle_buttons(tabview, fields, tabname, tabdata) | ||
| if fields["modlist"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["modlist"]) | ||
| tabdata.selected_mod = event.index | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_mod_mgr_install_local"] ~= nil then | ||
| core.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:")) | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_modstore"] ~= nil then | ||
| local modstore_ui = ui.find_by_name("modstore") | ||
| if modstore_ui ~= nil then | ||
| tabview:hide() | ||
| modstore.update_modlist() | ||
| modstore_ui:show() | ||
| else | ||
| print("modstore ui element not found") | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_mod_mgr_rename_modpack"] ~= nil then | ||
| local dlg_renamemp = create_rename_modpack_dlg(tabdata.selected_mod) | ||
| dlg_renamemp:set_parent(tabview) | ||
| tabview:hide() | ||
| dlg_renamemp:show() | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_mod_mgr_delete_mod"] ~= nil then | ||
| local dlg_delmod = create_delete_mod_dlg(tabdata.selected_mod) | ||
| dlg_delmod:set_parent(tabview) | ||
| tabview:hide() | ||
| dlg_delmod:show() | ||
| return true | ||
| end | ||
|
|
||
| if fields["mod_mgt_open_dlg_accepted"] ~= nil and | ||
| fields["mod_mgt_open_dlg_accepted"] ~= "" then | ||
| modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil) | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| tab_mods = { | ||
| name = "mods", | ||
| caption = fgettext("Mods"), | ||
| cbf_formspec = get_formspec, | ||
| cbf_button_handler = handle_buttons, | ||
| on_change = gamemgr.update_gamelist | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 get_formspec(tabview, name, tabdata) | ||
| local render_details = core.is_yes(core.setting_getbool("public_serverlist")) | ||
|
|
||
| local retval = | ||
| "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" .. | ||
| "label[1,-0.25;".. fgettext("Favorites:") .. "]".. | ||
| "label[1,4.25;".. fgettext("Address/Port") .. "]".. | ||
| "label[9,2.75;".. fgettext("Name/Password") .. "]" .. | ||
| "field[1.25,5.25;5.5,0.5;te_address;;" ..core.setting_get("address") .."]" .. | ||
| "field[6.75,5.25;2.25,0.5;te_port;;" ..core.setting_get("remote_port") .."]" .. | ||
| "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" .. | ||
| dump(core.setting_getbool("public_serverlist")) .. "]" | ||
|
|
||
| if not core.setting_getbool("public_serverlist") then | ||
| retval = retval .. | ||
| "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]" | ||
| end | ||
|
|
||
| retval = retval .. | ||
| "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" .. | ||
| "field[9.3,3.75;2.5,0.5;te_name;;" ..core.setting_get("name") .."]" .. | ||
| "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" .. | ||
| "textarea[9.3,0.25;2.5,2.75;;" | ||
|
|
||
| if menudata.fav_selected ~= nil and | ||
| menudata.favorites[menu.fav_selected].description ~= nil then | ||
| retval = retval .. | ||
| core.formspec_escape(menu.favorites[menu.fav_selected].description,true) | ||
| end | ||
|
|
||
| retval = retval .. | ||
| ";]" | ||
|
|
||
| --favourites | ||
| retval = retval .. | ||
| "textlist[1,0.35;7.5,3.35;favourites;" | ||
|
|
||
| if #menudata.favorites > 0 then | ||
| retval = retval .. render_favorite(menudata.favorites[1],render_details) | ||
|
|
||
| for i=2,#menudata.favorites,1 do | ||
| retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details) | ||
| end | ||
| end | ||
|
|
||
| if tabdata.fav_selected ~= nil then | ||
| retval = retval .. ";" .. tabdata.fav_selected .. "]" | ||
| else | ||
| retval = retval .. ";0]" | ||
| end | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function main_button_handler(tabview, fields, name, tabdata) | ||
|
|
||
| if fields["te_name"] ~= nil then | ||
| gamedata.playername = fields["te_name"] | ||
| core.setting_set("name", fields["te_name"]) | ||
| end | ||
|
|
||
| if fields["favourites"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["favourites"]) | ||
| if event.type == "DCL" then | ||
| if event.index <= #menudata.favorites then | ||
| gamedata.address = menudata.favorites[event.index].address | ||
| gamedata.port = menudata.favorites[event.index].port | ||
| gamedata.playername = fields["te_name"] | ||
| if fields["te_pwd"] ~= nil then | ||
| gamedata.password = fields["te_pwd"] | ||
| end | ||
| gamedata.selected_world = 0 | ||
|
|
||
| if menudata.favorites ~= nil then | ||
| gamedata.servername = menudata.favorites[event.index].name | ||
| gamedata.serverdescription = menudata.favorites[event.index].description | ||
| end | ||
|
|
||
| if gamedata.address ~= nil and | ||
| gamedata.port ~= nil then | ||
| core.setting_set("address",gamedata.address) | ||
| core.setting_set("remote_port",gamedata.port) | ||
| core.start() | ||
| end | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| if event.type == "CHG" then | ||
| if event.index <= #menudata.favorites then | ||
| local address = menudata.favorites[event.index].address | ||
| local port = menudata.favorites[event.index].port | ||
|
|
||
| if address ~= nil and | ||
| port ~= nil then | ||
| core.setting_set("address",address) | ||
| core.setting_set("remote_port",port) | ||
| end | ||
|
|
||
| tabdata.fav_selected = event.index | ||
| end | ||
|
|
||
| return true | ||
| end | ||
| end | ||
|
|
||
| if fields["key_up"] ~= nil or | ||
| fields["key_down"] ~= nil then | ||
|
|
||
| local fav_idx = core.get_textlist_index("favourites") | ||
|
|
||
| if fav_idx ~= nil then | ||
| if fields["key_up"] ~= nil and fav_idx > 1 then | ||
| fav_idx = fav_idx -1 | ||
| else if fields["key_down"] and fav_idx < #menudata.favorites then | ||
| fav_idx = fav_idx +1 | ||
| end end | ||
| else | ||
| fav_idx = 1 | ||
| end | ||
|
|
||
| local address = menudata.favorites[fav_idx].address | ||
| local port = menudata.favorites[fav_idx].port | ||
|
|
||
| if address ~= nil and | ||
| port ~= nil then | ||
| core.setting_set("address",address) | ||
| core.setting_set("remote_port",port) | ||
| end | ||
|
|
||
| tabdata.fav_selected = fav_idx | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_public_serverlist"] ~= nil then | ||
| core.setting_set("public_serverlist", fields["cb_public_serverlist"]) | ||
|
|
||
| if core.setting_getbool("public_serverlist") then | ||
| asyncOnlineFavourites() | ||
| else | ||
| menudata.favorites = core.get_favorites("local") | ||
| end | ||
| tabdata.fav_selected = nil | ||
| return true | ||
| end | ||
|
|
||
| if fields["btn_delete_favorite"] ~= nil then | ||
| local current_favourite = core.get_textlist_index("favourites") | ||
| if current_favourite == nil then return end | ||
| core.delete_favorite(current_favourite) | ||
| menudata.favorites = core.get_favorites() | ||
| tabdata.fav_selected = nil | ||
|
|
||
| core.setting_set("address","") | ||
| core.setting_set("remote_port","30000") | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| if fields["btn_mp_connect"] ~= nil or | ||
| fields["key_enter"] ~= nil then | ||
|
|
||
| gamedata.playername = fields["te_name"] | ||
| gamedata.password = fields["te_pwd"] | ||
| gamedata.address = fields["te_address"] | ||
| gamedata.port = fields["te_port"] | ||
|
|
||
| local fav_idx = core.get_textlist_index("favourites") | ||
|
|
||
| if fav_idx ~= nil and fav_idx <= #menudata.favorites and | ||
| menudata.favorites[fav_idx].address == fields["te_address"] and | ||
| menudata.favorites[fav_idx].port == fields["te_port"] then | ||
|
|
||
| gamedata.servername = menudata.favorites[fav_idx].name | ||
| gamedata.serverdescription = menudata.favorites[fav_idx].description | ||
| else | ||
| gamedata.servername = "" | ||
| gamedata.serverdescription = "" | ||
| end | ||
|
|
||
| gamedata.selected_world = 0 | ||
|
|
||
| core.setting_set("address", fields["te_address"]) | ||
| core.setting_set("remote_port",fields["te_port"]) | ||
|
|
||
| core.start() | ||
| return true | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| local function on_change(type,old_tab,new_tab) | ||
| if type == "LEAVE" then | ||
| return | ||
| end | ||
| if core.setting_getbool("public_serverlist") then | ||
| asyncOnlineFavourites() | ||
| else | ||
| menudata.favorites = core.get_favorites("local") | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| tab_multiplayer = { | ||
| name = "multiplayer", | ||
| caption = fgettext("Client"), | ||
| cbf_formspec = get_formspec, | ||
| cbf_button_handler = main_button_handler, | ||
| on_change = on_change | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 get_formspec(tabview, name, tabdata) | ||
|
|
||
| local index = menudata.worldlist:get_current_index( | ||
| tonumber(core.setting_get("mainmenu_last_selected_world")) | ||
| ) | ||
|
|
||
| local retval = | ||
| "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" .. | ||
| "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" .. | ||
| "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" .. | ||
| "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" .. | ||
| "label[4,-0.25;".. fgettext("Select World:") .. "]".. | ||
| "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" .. | ||
| "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. | ||
| dump(core.setting_getbool("creative_mode")) .. "]".. | ||
| "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. | ||
| dump(core.setting_getbool("enable_damage")) .. "]".. | ||
| "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" .. | ||
| dump(core.setting_getbool("server_announce")) .. "]".. | ||
| "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" .. | ||
| core.setting_get("name") .. "]" .. | ||
| "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]" | ||
|
|
||
| local bind_addr = core.setting_get("bind_address") | ||
| if bind_addr ~= nil and bind_addr ~= "" then | ||
| retval = retval .. | ||
| "field[0.8,5.2;2.25,0.5;te_serveraddr;".. fgettext("Bind Address") .. ";" .. | ||
| core.setting_get("bind_address") .."]" .. | ||
| "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" .. | ||
| core.setting_get("port") .."]" | ||
| else | ||
| retval = retval .. | ||
| "field[0.8,5.2;3.5,0.5;te_serverport;".. fgettext("Server Port") .. ";" .. | ||
| core.setting_get("port") .."]" | ||
| end | ||
|
|
||
| retval = retval .. | ||
| "textlist[4,0.25;7.5,3.7;srv_worlds;" .. | ||
| menu_render_worldlist() .. | ||
| ";" .. index .. "]" | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function main_button_handler(this, fields, name, tabdata) | ||
|
|
||
| local world_doubleclick = false | ||
|
|
||
| if fields["srv_worlds"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["srv_worlds"]) | ||
|
|
||
| if event.type == "DCL" then | ||
| world_doubleclick = true | ||
| end | ||
| if event.type == "CHG" then | ||
| core.setting_set("mainmenu_last_selected_world", | ||
| menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds"))) | ||
| end | ||
| end | ||
|
|
||
| if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_creative_mode"] then | ||
| core.setting_set("creative_mode", fields["cb_creative_mode"]) | ||
| end | ||
|
|
||
| if fields["cb_enable_damage"] then | ||
| core.setting_set("enable_damage", fields["cb_enable_damage"]) | ||
| end | ||
|
|
||
| if fields["cb_server_announce"] then | ||
| core.setting_set("server_announce", fields["cb_server_announce"]) | ||
| end | ||
|
|
||
| if fields["start_server"] ~= nil or | ||
| world_doubleclick or | ||
| fields["key_enter"] then | ||
| local selected = core.get_textlist_index("srv_worlds") | ||
| if selected ~= nil then | ||
| gamedata.playername = fields["te_playername"] | ||
| gamedata.password = fields["te_passwd"] | ||
| gamedata.port = fields["te_serverport"] | ||
| gamedata.address = "" | ||
| gamedata.selected_world = menudata.worldlist:get_raw_index(selected) | ||
|
|
||
| core.setting_set("port",gamedata.port) | ||
| if fields["te_serveraddr"] ~= nil then | ||
| core.setting_set("bind_address",fields["te_serveraddr"]) | ||
| end | ||
|
|
||
| --update last game | ||
| local world = menudata.worldlist:get_raw_element(gamedata.selected_world) | ||
| local game,index = gamemgr.find_by_gameid(world.gameid) | ||
| core.setting_set("menu_last_game",game.id) | ||
| core.start() | ||
| end | ||
| end | ||
|
|
||
| if fields["world_create"] ~= nil then | ||
| print("create world dialog") | ||
| local create_world_dlg = create_create_world_dlg(true) | ||
| create_world_dlg:set_parent(this) | ||
| create_world_dlg:show() | ||
| this:hide() | ||
| return true | ||
| end | ||
|
|
||
| if fields["world_delete"] ~= nil then | ||
| local selected = core.get_textlist_index("srv_worlds") | ||
| if selected ~= nil and | ||
| selected <= menudata.worldlist:size() then | ||
| local world = menudata.worldlist:get_list()[selected] | ||
| if world ~= nil and | ||
| world.name ~= nil and | ||
| world.name ~= "" then | ||
| local index = menudata.worldlist:get_raw_index(selected) | ||
| local delete_world_dlg = create_delete_world_dlg(world.name,index) | ||
| delete_world_dlg:set_parent(this) | ||
| delete_world_dlg:show() | ||
| this:hide() | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| if fields["world_configure"] ~= nil then | ||
| local selected = core.get_textlist_index("srv_worlds") | ||
| if selected ~= nil then | ||
| local configdialog = | ||
| create_configure_world_dlg( | ||
| menudata.worldlist:get_raw_index(selected)) | ||
|
|
||
| if (configdialog ~= nil) then | ||
| configdialog:set_parent(this) | ||
| configdialog:show() | ||
| this:hide() | ||
| end | ||
| end | ||
| return true | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| tab_server = { | ||
| name = "server", | ||
| caption = fgettext("Server"), | ||
| cbf_formspec = get_formspec, | ||
| cbf_button_handler = main_button_handler, | ||
| on_change = nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,247 @@ | ||
| --Minetest | ||
| --Copyright (C) 2013 sapier | ||
| -- | ||
| --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 dlg_confirm_reset_formspec(data) | ||
| local retval = | ||
| "size[8,3]" .. | ||
| "label[1,1;".. fgettext("Are you sure to reset your singleplayer world?") .. "]".. | ||
| "button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;".. | ||
| fgettext("Yes") .. "]" .. | ||
| "button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;".. | ||
| fgettext("No!!!") .. "]" | ||
| return retval | ||
| end | ||
|
|
||
| local function dlg_confirm_reset_btnhandler(this, fields, dialogdata) | ||
|
|
||
| if fields["dlg_reset_singleplayer_confirm"] ~= nil then | ||
|
|
||
| local worldlist = core.get_worlds() | ||
| local found_singleplayerworld = false | ||
|
|
||
| for i=1,#worldlist,1 do | ||
| if worldlist[i].name == "singleplayerworld" then | ||
| found_singleplayerworld = true | ||
| gamedata.worldindex = i | ||
| end | ||
| end | ||
|
|
||
| if found_singleplayerworld then | ||
| core.delete_world(gamedata.worldindex) | ||
| end | ||
|
|
||
| core.create_world("singleplayerworld", 1) | ||
|
|
||
| worldlist = core.get_worlds() | ||
|
|
||
| found_singleplayerworld = false | ||
|
|
||
| for i=1,#worldlist,1 do | ||
| if worldlist[i].name == "singleplayerworld" then | ||
| found_singleplayerworld = true | ||
| gamedata.worldindex = i | ||
| end | ||
| end | ||
| end | ||
|
|
||
| this.parent:show() | ||
| this:hide() | ||
| this:delete() | ||
| end | ||
|
|
||
| local function showconfirm_reset(tabview) | ||
| local new_dlg = dialog_create("reset_spworld", | ||
| dlg_confirm_reset_formspec, | ||
| dlg_confirm_reset_btnhandler, | ||
| nil, | ||
| tabview) | ||
| tabview:hide() | ||
| new_dlg:show() | ||
| end | ||
|
|
||
|
|
||
|
|
||
| local function formspec(tabview, name, tabdata) | ||
| local tab_string = | ||
| "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" .. | ||
| "box[0.75,0;3.25,4;#999999]" .. | ||
| "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";" | ||
| .. dump(core.setting_getbool("new_style_leaves")) .. "]".. | ||
| "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting") | ||
| .. ";".. dump(core.setting_getbool("smooth_lighting")) .. "]".. | ||
| "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";" | ||
| .. dump(core.setting_getbool("enable_3d_clouds")) .. "]".. | ||
| "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";" | ||
| .. dump(core.setting_getbool("opaque_water")) .. "]".. | ||
| "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";" | ||
| .. dump(core.setting_getbool("preload_item_visuals")) .. "]".. | ||
| "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";" | ||
| .. dump(core.setting_getbool("enable_particles")) .. "]".. | ||
| "checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";" | ||
| .. dump(core.setting_getbool("liquid_finite")) .. "]".. | ||
| "box[4.25,0;3.25,2.5;#999999]" .. | ||
| "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";" | ||
| .. dump(core.setting_getbool("mip_map")) .. "]".. | ||
| "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";" | ||
| .. dump(core.setting_getbool("anisotropic_filter")) .. "]".. | ||
| "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";" | ||
| .. dump(core.setting_getbool("bilinear_filter")) .. "]".. | ||
| "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";" | ||
| .. dump(core.setting_getbool("trilinear_filter")) .. "]".. | ||
| "box[7.75,0;4,3.5;#999999]" .. | ||
| "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";" | ||
| .. dump(core.setting_getbool("enable_shaders")) .. "]".. | ||
| "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]" | ||
|
|
||
| local android = false | ||
| if android then | ||
| tab_string = tab_string .. | ||
| "box[4.25,2.75;3.25,2.5;#999999]" .. | ||
| "checkbox[4.5,2.75;cb_touchscreen_target;".. fgettext("Touch free target") .. ";" | ||
| .. dump(core.setting_getbool("touchtarget")) .. "]" .. | ||
| "button[8,4.5;3.75,0.5;btn_reset_singleplayer;".. fgettext("Reset singleplayer world") .. "]" | ||
| end | ||
|
|
||
| if core.setting_get("touchscreen_threshold") ~= nil then | ||
| tab_string = tab_string .. | ||
| "label[4.5,3.5;" .. fgettext("Touchthreshold (px)") .. "]" .. | ||
| "dropdown[4.5,4;3;dd_touchthreshold;0,10,20,30,40,50;" .. | ||
| ((tonumber(core.setting_get("touchscreen_threshold"))/10)+1) .. "]" | ||
| end | ||
|
|
||
| if core.setting_getbool("enable_shaders") then | ||
| tab_string = tab_string .. | ||
| "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";" | ||
| .. dump(core.setting_getbool("enable_bumpmapping")) .. "]".. | ||
| "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";" | ||
| .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]".. | ||
| "checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";" | ||
| .. dump(core.setting_getbool("enable_waving_water")) .. "]".. | ||
| "checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";" | ||
| .. dump(core.setting_getbool("enable_waving_leaves")) .. "]".. | ||
| "checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";" | ||
| .. dump(core.setting_getbool("enable_waving_plants")) .. "]" | ||
| else | ||
| tab_string = tab_string .. | ||
| "textlist[8.33,0.7;3,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" .. | ||
| "textlist[8.33,1.2;3,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" .. | ||
| "textlist[8.33,1.7;3,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" .. | ||
| "textlist[8.33,2.2;3,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" .. | ||
| "textlist[8.33,2.7;3,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]" | ||
| end | ||
| return tab_string | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function handle_settings_buttons(this, fields, tabname, tabdata) | ||
| if fields["cb_fancy_trees"] then | ||
| core.setting_set("new_style_leaves", fields["cb_fancy_trees"]) | ||
| return true | ||
| end | ||
| if fields["cb_smooth_lighting"] then | ||
| core.setting_set("smooth_lighting", fields["cb_smooth_lighting"]) | ||
| return true | ||
| end | ||
| if fields["cb_3d_clouds"] then | ||
| core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"]) | ||
| return true | ||
| end | ||
| if fields["cb_opaque_water"] then | ||
| core.setting_set("opaque_water", fields["cb_opaque_water"]) | ||
| return true | ||
| end | ||
| if fields["cb_mipmapping"] then | ||
| core.setting_set("mip_map", fields["cb_mipmapping"]) | ||
| return true | ||
| end | ||
| if fields["cb_anisotrophic"] then | ||
| core.setting_set("anisotropic_filter", fields["cb_anisotrophic"]) | ||
| return true | ||
| end | ||
| if fields["cb_bilinear"] then | ||
| core.setting_set("bilinear_filter", fields["cb_bilinear"]) | ||
| return true | ||
| end | ||
| if fields["cb_trilinear"] then | ||
| core.setting_set("trilinear_filter", fields["cb_trilinear"]) | ||
| return true | ||
| end | ||
| if fields["cb_shaders"] then | ||
| if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then | ||
| core.setting_set("enable_shaders", "false") | ||
| gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.") | ||
| else | ||
| core.setting_set("enable_shaders", fields["cb_shaders"]) | ||
| end | ||
| return true | ||
| end | ||
| if fields["cb_pre_ivis"] then | ||
| core.setting_set("preload_item_visuals", fields["cb_pre_ivis"]) | ||
| return true | ||
| end | ||
| if fields["cb_particles"] then | ||
| core.setting_set("enable_particles", fields["cb_particles"]) | ||
| return true | ||
| end | ||
| if fields["cb_finite_liquid"] then | ||
| core.setting_set("liquid_finite", fields["cb_finite_liquid"]) | ||
| return true | ||
| end | ||
| if fields["cb_bumpmapping"] then | ||
| core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"]) | ||
| end | ||
| if fields["cb_parallax"] then | ||
| core.setting_set("enable_parallax_occlusion", fields["cb_parallax"]) | ||
| return true | ||
| end | ||
| if fields["cb_waving_water"] then | ||
| core.setting_set("enable_waving_water", fields["cb_waving_water"]) | ||
| return true | ||
| end | ||
| if fields["cb_waving_leaves"] then | ||
| core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"]) | ||
| end | ||
| if fields["cb_waving_plants"] then | ||
| core.setting_set("enable_waving_plants", fields["cb_waving_plants"]) | ||
| return true | ||
| end | ||
| if fields["btn_change_keys"] ~= nil then | ||
| core.show_keys_menu() | ||
| return true | ||
| end | ||
| if fields["cb_touchscreen_target"] then | ||
| core.setting_set("touchtarget", fields["cb_touchscreen_target"]) | ||
| return true | ||
| end | ||
| if fields["dd_touchthreshold"] then | ||
| core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"]) | ||
| return true | ||
| end | ||
| if fields["btn_reset_singleplayer"] then | ||
| showconfirm_reset(this) | ||
| return true | ||
| end | ||
| end | ||
|
|
||
| tab_settings = { | ||
| name = "settings", | ||
| caption = fgettext("Settings"), | ||
| cbf_formspec = formspec, | ||
| cbf_button_handler = handle_settings_buttons | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| --Minetest | ||
| --Copyright (C) 2013 sapier | ||
| -- | ||
| --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 get_formspec(tabview, name, tabdata) | ||
| local retval = "" | ||
|
|
||
| local render_details = dump(core.setting_getbool("public_serverlist")) | ||
|
|
||
| retval = retval .. | ||
| "label[0,3.0;".. fgettext("Address/Port") .. "]".. | ||
| "label[8,0.5;".. fgettext("Name/Password") .. "]" .. | ||
| "field[0.25,3.25;5.5,0.5;te_address;;" ..core.setting_get("address") .."]" .. | ||
| "field[5.75,3.25;2.25,0.5;te_port;;" ..core.setting_get("remote_port") .."]" .. | ||
| "checkbox[8,-0.25;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" .. | ||
| render_details .. "]" | ||
|
|
||
| retval = retval .. | ||
| "button[8,2.5;4,1.5;btn_mp_connect;".. fgettext("Connect") .. "]" .. | ||
| "field[8.75,1.5;3.5,0.5;te_name;;" ..core.setting_get("name") .."]" .. | ||
| "pwdfield[8.75,2.3;3.5,0.5;te_pwd;]" | ||
|
|
||
| --favourites | ||
| retval = retval .. | ||
| "textlist[-0.05,0.0;7.55,2.75;favourites;" | ||
|
|
||
| if #menudata.favorites > 0 then | ||
| retval = retval .. render_favorite(menudata.favorites[1],render_details) | ||
|
|
||
| for i=2,#menudata.favorites,1 do | ||
| retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details) | ||
| end | ||
| end | ||
|
|
||
| if tabdata.fav_selected ~= nil then | ||
| retval = retval .. ";" .. tabdata.fav_selected .. "]" | ||
| else | ||
| retval = retval .. ";0]" | ||
| end | ||
|
|
||
| -- separator | ||
| retval = retval .. | ||
| "box[-0.3,3.75;12.4,0.1;#FFFFFF]" | ||
|
|
||
| -- checkboxes | ||
| retval = retval .. | ||
| "checkbox[1.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" .. | ||
| dump(core.setting_getbool("creative_mode")) .. "]".. | ||
| "checkbox[5.0,3.9;cb_damage;".. fgettext("Enable Damage") .. ";" .. | ||
| dump(core.setting_getbool("enable_damage")) .. "]" .. | ||
| "checkbox[8,3.9;cb_fly_mode;".. fgettext("Fly mode") .. ";" .. | ||
| dump(core.setting_getbool("free_move")) .. "]" | ||
| -- buttons | ||
| retval = retval .. | ||
| "button[3.0,4.5;6,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" | ||
|
|
||
| return retval | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
|
|
||
| local function main_button_handler(tabview, fields, name, tabdata) | ||
| if fields["btn_start_singleplayer"] then | ||
| gamedata.selected_world = gamedata.worldindex | ||
| gamedata.singleplayer = true | ||
| core.start() | ||
| end | ||
|
|
||
| if fields["favourites"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["favourites"]) | ||
|
|
||
| if event.type == "CHG" then | ||
| if event.index <= #maintab_favorites then | ||
| local address = maintab_favorites[event.index].address | ||
| local port = maintab_favorites[event.index].port | ||
|
|
||
| if address ~= nil and | ||
| port ~= nil then | ||
| core.setting_set("address",address) | ||
| core.setting_set("remote_port",port) | ||
| end | ||
|
|
||
| tabdata.fav_selected = event.index | ||
| end | ||
| end | ||
| return | ||
| end | ||
|
|
||
| if fields["cb_public_serverlist"] ~= nil then | ||
| core.setting_set("public_serverlist", fields["cb_public_serverlist"]) | ||
|
|
||
| if core.setting_getbool("public_serverlist") then | ||
| asyncOnlineFavourites() | ||
| else | ||
| maintab_favorites = core.get_favorites("local") | ||
| end | ||
| return | ||
| end | ||
|
|
||
| if fields["cb_creative"] then | ||
| core.setting_set("creative_mode", fields["cb_creative"]) | ||
| end | ||
|
|
||
| if fields["cb_damage"] then | ||
| core.setting_set("enable_damage", fields["cb_damage"]) | ||
| end | ||
|
|
||
| if fields["cb_fly_mode"] then | ||
| core.setting_set("free_move", fields["cb_fly_mode"]) | ||
| end | ||
|
|
||
| if fields["btn_mp_connect"] ~= nil or | ||
| fields["key_enter"] ~= nil then | ||
|
|
||
| gamedata.playername = fields["te_name"] | ||
| gamedata.password = fields["te_pwd"] | ||
| gamedata.address = fields["te_address"] | ||
| gamedata.port = fields["te_port"] | ||
|
|
||
| local fav_idx = core.get_textlist_index("favourites") | ||
|
|
||
| if fav_idx ~= nil and fav_idx <= #menudata.favorites and | ||
| menudata.favorites[fav_idx].address == fields["te_address"] and | ||
| menudata.favorites[fav_idx].port == fields["te_port"] then | ||
|
|
||
| gamedata.servername = menudata.favorites[fav_idx].name | ||
| gamedata.serverdescription = menudata.favorites[fav_idx].description | ||
| else | ||
| gamedata.servername = "" | ||
| gamedata.serverdescription = "" | ||
| end | ||
|
|
||
| gamedata.selected_world = 0 | ||
|
|
||
| core.setting_set("address",fields["te_address"]) | ||
| core.setting_set("remote_port",fields["te_port"]) | ||
|
|
||
| core.start() | ||
| return | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| local function on_activate(type,old_tab,new_tab) | ||
| if type == "LEAVE" then | ||
| return | ||
| end | ||
| if core.setting_getbool("public_serverlist") then | ||
| asyncOnlineFavourites() | ||
| else | ||
| menudata.favorites = core.get_favorites("local") | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| tab_simple_main = { | ||
| name = "main", | ||
| caption = fgettext("Main"), | ||
| cbf_formspec = get_formspec, | ||
| cbf_button_handler = main_button_handler, | ||
| on_change = on_activate | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| --Minetest | ||
| --Copyright (C) 2014 sapier | ||
| -- | ||
| --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 singleplayer_refresh_gamebar() | ||
|
|
||
| local old_bar = ui.find_by_name("game_button_bar") | ||
|
|
||
| if old_bar ~= nil then | ||
| old_bar:delete() | ||
| end | ||
|
|
||
| local function game_buttonbar_button_handler(fields) | ||
| for key,value in pairs(fields) do | ||
| for j=1,#gamemgr.games,1 do | ||
| if ("game_btnbar_" .. gamemgr.games[j].id == key) then | ||
| mm_texture.update("singleplayer", gamemgr.games[j]) | ||
| core.setting_set("menu_last_game",gamemgr.games[j].id) | ||
| menudata.worldlist:set_filtercriteria(gamemgr.games[j].id) | ||
| return true | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local btnbar = buttonbar_create("game_button_bar", | ||
| game_buttonbar_button_handler, | ||
| {x=-0.3,y=5.65}, "horizontal", {x=12.4,y=1.15}) | ||
|
|
||
| for i=1,#gamemgr.games,1 do | ||
| local btn_name = "game_btnbar_" .. gamemgr.games[i].id | ||
|
|
||
| local image = nil | ||
| local text = nil | ||
|
|
||
| if gamemgr.games[i].menuicon_path ~= nil and | ||
| gamemgr.games[i].menuicon_path ~= "" then | ||
| image = core.formspec_escape(gamemgr.games[i].menuicon_path) | ||
| else | ||
|
|
||
| local part1 = gamemgr.games[i].id:sub(1,5) | ||
| local part2 = gamemgr.games[i].id:sub(6,10) | ||
| local part3 = gamemgr.games[i].id:sub(11) | ||
|
|
||
| text = part1 .. "\n" .. part2 | ||
| if part3 ~= nil and | ||
| part3 ~= "" then | ||
| text = text .. "\n" .. part3 | ||
| end | ||
| end | ||
| btnbar:add_button(btn_name, text, image) | ||
| end | ||
| end | ||
|
|
||
| local function get_formspec(tabview, name, tabdata) | ||
| local retval = "" | ||
|
|
||
| local index = filterlist.get_current_index(menudata.worldlist, | ||
| tonumber(core.setting_get("mainmenu_last_selected_world")) | ||
| ) | ||
|
|
||
| retval = retval .. | ||
| "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" .. | ||
| "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" .. | ||
| "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" .. | ||
| "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" .. | ||
| "label[4,-0.25;".. fgettext("Select World:") .. "]".. | ||
| "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" .. | ||
| "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. | ||
| dump(core.setting_getbool("creative_mode")) .. "]".. | ||
| "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. | ||
| dump(core.setting_getbool("enable_damage")) .. "]".. | ||
| "textlist[4,0.25;7.5,3.7;sp_worlds;" .. | ||
| menu_render_worldlist() .. | ||
| ";" .. index .. "]" | ||
| return retval | ||
| end | ||
|
|
||
| local function main_button_handler(this, fields, name, tabdata) | ||
|
|
||
| assert(name == "singleplayer") | ||
|
|
||
| local world_doubleclick = false | ||
|
|
||
| if fields["sp_worlds"] ~= nil then | ||
| local event = core.explode_textlist_event(fields["sp_worlds"]) | ||
|
|
||
| if event.type == "DCL" then | ||
| world_doubleclick = true | ||
| end | ||
|
|
||
| if event.type == "CHG" then | ||
| core.setting_set("mainmenu_last_selected_world", | ||
| menudata.worldlist:get_raw_index(core.get_textlist_index("sp_worlds"))) | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| if menu_handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") then | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_creative_mode"] then | ||
| core.setting_set("creative_mode", fields["cb_creative_mode"]) | ||
| return true | ||
| end | ||
|
|
||
| if fields["cb_enable_damage"] then | ||
| core.setting_set("enable_damage", fields["cb_enable_damage"]) | ||
| return true | ||
| end | ||
|
|
||
| if fields["play"] ~= nil or | ||
| world_doubleclick or | ||
| fields["key_enter"] then | ||
| local selected = core.get_textlist_index("sp_worlds") | ||
| if selected ~= nil then | ||
| gamedata.selected_world = menudata.worldlist:get_raw_index(selected) | ||
| gamedata.singleplayer = true | ||
| core.start() | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| if fields["world_create"] ~= nil then | ||
| print("create world dialog") | ||
| local create_world_dlg = create_create_world_dlg(true) | ||
| create_world_dlg:set_parent(this) | ||
| create_world_dlg:show() | ||
| this:hide() | ||
| return true | ||
| end | ||
|
|
||
| if fields["world_delete"] ~= nil then | ||
| local selected = core.get_textlist_index("sp_worlds") | ||
| if selected ~= nil and | ||
| selected <= menudata.worldlist:size() then | ||
| local world = menudata.worldlist:get_list()[selected] | ||
| if world ~= nil and | ||
| world.name ~= nil and | ||
| world.name ~= "" then | ||
| local index = menudata.worldlist:get_raw_index(selected) | ||
| local delete_world_dlg = create_delete_world_dlg(world.name,index) | ||
| delete_world_dlg:set_parent(this) | ||
| delete_world_dlg:show() | ||
| this:hide() | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| if fields["world_configure"] ~= nil then | ||
| local selected = core.get_textlist_index("sp_worlds") | ||
| if selected ~= nil then | ||
| local configdialog = | ||
| create_configure_world_dlg( | ||
| menudata.worldlist:get_raw_index(selected)) | ||
|
|
||
| if (configdialog ~= nil) then | ||
| configdialog:set_parent(this) | ||
| configdialog:show() | ||
| this:hide() | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
| end | ||
|
|
||
| local function on_change(type, old_tab, new_tab) | ||
| local buttonbar = ui.find_by_name("game_button_bar") | ||
|
|
||
| if ( buttonbar == nil ) then | ||
| singleplayer_refresh_gamebar() | ||
| buttonbar = ui.find_by_name("game_button_bar") | ||
| end | ||
|
|
||
| if (type == "ENTER") then | ||
| local last_game_id = core.setting_get("menu_last_game") | ||
| local game, index = gamemgr.find_by_gameid(last_game_id) | ||
|
|
||
| if game then | ||
| menudata.worldlist:set_filtercriteria(game.id) | ||
| core.set_topleft_text(game.name) | ||
| mm_texture.update(new_tab,game) | ||
| end | ||
| buttonbar:show() | ||
| else | ||
| menudata.worldlist:set_filtercriteria(nil) | ||
| buttonbar:hide() | ||
| core.set_topleft_text("") | ||
| mm_texture.update(new_tab,nil) | ||
| end | ||
| end | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| tab_singleplayer = { | ||
| name = "singleplayer", | ||
| caption = fgettext("Singleplayer"), | ||
| cbf_formspec = get_formspec, | ||
| cbf_button_handler = main_button_handler, | ||
| on_change = on_change | ||
| } |