diff options
author | sapier <Sapier at GMX dot net> | 2013-07-16 20:56:18 +0200 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-07-22 18:10:00 +0200 |
commit | e3827fbc23d91b65e33a64dc029ff1ab1bf1b48b (patch) | |
tree | e232b222a62a085be3f5d15ca98ec7e5ceab63e9 /builtin | |
parent | 5160be91ae6af23cabec5c7412a1c2c45fc46afb (diff) | |
download | minetest-e3827fbc23d91b65e33a64dc029ff1ab1bf1b48b.tar.gz minetest-e3827fbc23d91b65e33a64dc029ff1ab1bf1b48b.tar.bz2 minetest-e3827fbc23d91b65e33a64dc029ff1ab1bf1b48b.zip |
Fix background/overlay/footer/header handling
Add missing file headers
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/filterlist.lua | 17 | ||||
-rw-r--r-- | builtin/mainmenu.lua | 313 | ||||
-rw-r--r-- | builtin/mainmenu_helper.lua | 58 | ||||
-rw-r--r-- | builtin/mm_menubar.lua | 78 | ||||
-rw-r--r-- | builtin/mm_textures.lua | 145 | ||||
-rw-r--r-- | builtin/modmgr.lua | 41 |
6 files changed, 366 insertions, 286 deletions
diff --git a/builtin/filterlist.lua b/builtin/filterlist.lua index 391accee3..c9135d207 100644 --- a/builtin/filterlist.lua +++ b/builtin/filterlist.lua @@ -1,3 +1,20 @@ +--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. + -------------------------------------------------------------------------------- -- Generic implementation of a filter/sortable list -- -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu.lua b/builtin/mainmenu.lua index 90e10abca..52814589f 100644 --- a/builtin/mainmenu.lua +++ b/builtin/mainmenu.lua @@ -7,18 +7,21 @@ mt_color_blue = "#0000DD" mt_color_green = "#00DD00" mt_color_dark_green = "#003300" +--for all other colors ask sfan5 to complete his worK! + dofile(scriptpath .. DIR_DELIM .. "filterlist.lua") dofile(scriptpath .. DIR_DELIM .. "modmgr.lua") dofile(scriptpath .. DIR_DELIM .. "modstore.lua") dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua") +dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua") +dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua") -local menu = {} +menu = {} local tabbuilder = {} -local menubar = {} local worldlist = nil -------------------------------------------------------------------------------- -function render_favourite(spec,render_details) +function menu.render_favorite(spec,render_details) local text = "" if spec.name ~= nil then @@ -44,9 +47,6 @@ function render_favourite(spec,render_details) return text end - - - local details = "" if spec.password == true then details = details .. "*" @@ -101,171 +101,6 @@ os.tempfolder = function() end -------------------------------------------------------------------------------- -function cleanup_path(temppath) - - local parts = temppath:split("-") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "_" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split(".") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "_" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split("'") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split(" ") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath - end - temppath = temppath .. parts[i] - end - - return temppath -end - --------------------------------------------------------------------------------- - -function menu.set_texture(identifier,gamedetails) - local texture_set = false - if menu.texturepack ~= nil and gamedetails ~= nil then - local path = menu.basetexturedir .. - gamedetails.id .. "_menu_" .. identifier .. ".png" - - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set and gamedetails ~= nil then - local path = gamedetails.path .. DIR_DELIM .."menu" .. - DIR_DELIM .. identifier .. ".png" - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set then - local path = menu.basetexturedir .. DIR_DELIM .."menu_" .. - identifier .. ".png" - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set then - local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" .. - identifier .. ".png" - engine.set_background(identifier,path) - end -end - --------------------------------------------------------------------------------- -function menu.update_gametype() - - - - if (menu.game_last_check == nil or - menu.game_last_check ~= menu.last_game) and - tabbuilder.current_tab == "singleplayer" then - - local gamedetails = menu.lastgame() - engine.set_topleft_text(gamedetails.name) - filterlist.set_filtercriteria(worldlist,gamedetails.id) - - --background - local background_set = false - if menu.texturepack ~= nil then - local path_background_texture = menu.basetexturedir .. - gamedetails.id .. "_menu_background.png" - - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - end - end - - if not background_set then - local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" .. - DIR_DELIM .. "background.png" - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - end - end - - if not background_set then - engine.set_clouds(true) - end - - menu.set_texture("overlay",gamedetails) - menu.set_texture("header",gamedetails) - menu.set_texture("footer",gamedetails) - - menu.game_last_check = menu.last_game - else - if menu.game_last_check ~= menu.last_game then - menu.game_last_check = menu.last_game - menu.reset_gametype() - end - end -end - --------------------------------------------------------------------------------- -function menu.reset_gametype() - filterlist.set_filtercriteria(worldlist,nil) - menu.game_last_check = nil - - local path_background_texture = menu.basetexturedir .. "menu_background.png" - - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - else - engine.set_clouds(true) - end - - menu.set_texture("overlay",nil) - menu.set_texture("header",nil) - menu.set_texture("footer",nil) - engine.set_topleft_text("") -end - --------------------------------------------------------------------------------- -function get_last_folder(text,count) - local parts = text:split(DIR_DELIM) - - if count == nil then - return parts[#parts] - end - - local retval = "" - for i=1,count,1 do - retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM - end - - return retval -end - --------------------------------------------------------------------------------- function init_globals() --init gamedata gamedata.worldindex = 0 @@ -293,44 +128,6 @@ function init_globals() end -------------------------------------------------------------------------------- -function identify_filetype(name) - - if name:sub(-3):lower() == "zip" then - return { - name = name, - type = "zip" - } - end - - if name:sub(-6):lower() == "tar.gz" or - name:sub(-3):lower() == "tgz"then - return { - name = name, - type = "tgz" - } - end - - if name:sub(-6):lower() == "tar.bz2" then - return { - name = name, - type = "tbz" - } - end - - if name:sub(-2):lower() == "7z" then - return { - name = name, - type = "7z" - } - end - - return { - name = name, - type = "ukn" - } -end - --------------------------------------------------------------------------------- function update_menu() local formspec = "size[12,5.2]" @@ -384,17 +181,9 @@ function menu.init() menu.favorites = engine.get_favorites("local") end - menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." .. - DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. - DIR_DELIM .. "pack" .. DIR_DELIM - menu.basetexturedir = menu.defaulttexturedir - - menu.texturepack = engine.setting_get("texture_path") - - if menu.texturepack ~= nil then - menu.basetexturedir = menu.texturepack .. DIR_DELIM - end + DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. + DIR_DELIM .. "pack" .. DIR_DELIM end -------------------------------------------------------------------------------- @@ -456,67 +245,6 @@ function menu.handle_key_up_down(fields,textlist,settingname) end end - --------------------------------------------------------------------------------- -function menubar.handle_buttons(fields) - for i=1,#menubar.buttons,1 do - if fields[menubar.buttons[i].btn_name] ~= nil then - menu.last_game = menubar.buttons[i].index - engine.setting_set("main_menu_last_game_idx",menu.last_game) - menu.update_gametype() - end - end -end - --------------------------------------------------------------------------------- -function menubar.refresh() - menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" .. - "box[-0.3,5.6;12.4,0.05;FFFFFF]" - menubar.buttons = {} - - local button_base = -0.25 - - local maxbuttons = #gamemgr.games - - if maxbuttons > 10 then - maxbuttons = 10 - end - - for i=1,maxbuttons,1 do - - local btn_name = "menubar_btn_" .. gamemgr.games[i].id - local buttonpos = button_base + (i-1) * 1.245 - if gamemgr.games[i].menuicon_path ~= nil and - gamemgr.games[i].menuicon_path ~= "" then - - menubar.formspec = menubar.formspec .. - "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" .. - gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]" - 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) - - local text = part1 .. "\n" .. part2 - if part3 ~= nil and - part3 ~= "" then - text = text .. "\n" .. part3 - end - menubar.formspec = menubar.formspec .. - "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name .. - ";" .. text .. ";true;true]" - end - - local toadd = { - btn_name = btn_name, - index = i, - } - - table.insert(menubar.buttons,toadd) - end -end - -------------------------------------------------------------------------------- function tabbuilder.dialog_create_world() local mapgens = {"v6", "v7", "indev", "singlenode", "math"} @@ -1040,7 +768,7 @@ function tabbuilder.handle_tab_buttons(fields) --handle tab changes if tabbuilder.current_tab ~= tabbuilder.old_tab then if tabbuilder.current_tab ~= "singleplayer" then - menu.reset_gametype() + menu.update_gametype(true) end end @@ -1061,7 +789,6 @@ function tabbuilder.init() engine.setting_set("main_menu_tab",tabbuilder.current_tab) end - --initialize tab buttons tabbuilder.last_tab = nil tabbuilder.show_buttons = true @@ -1127,10 +854,10 @@ function tabbuilder.tab_multiplayer() local render_details = engine.setting_getbool("public_serverlist") if #menu.favorites > 0 then - retval = retval .. render_favourite(menu.favorites[1],render_details) + retval = retval .. menu.render_favorite(menu.favorites[1],render_details) for i=2,#menu.favorites,1 do - retval = retval .. "," .. render_favourite(menu.favorites[i],render_details) + retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details) end end @@ -1353,14 +1080,32 @@ engine.event_handler = function(event) end -------------------------------------------------------------------------------- +function menu.update_gametype(reset) + print("updating gametype: " .. dump(reset)) + if reset then + mm_texture.reset() + engine.set_topleft_text("") + filterlist.set_filtercriteria(worldlist,nil) + else + local game = menu.lastgame() + print("current_game = " .. dump(game)) + mm_texture.update(tabbuilder.current_tab,game) + engine.set_topleft_text(game.name) + filterlist.set_filtercriteria(worldlist,game.id) + end +end + +-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- menu startup -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- init_globals() +mm_texture.init() menu.init() tabbuilder.init() menubar.refresh() modstore.init() + update_menu() diff --git a/builtin/mainmenu_helper.lua b/builtin/mainmenu_helper.lua index 25ad072fd..1bdd33cc6 100644 --- a/builtin/mainmenu_helper.lua +++ b/builtin/mainmenu_helper.lua @@ -105,3 +105,61 @@ function explode_textlist_event(text) return retval end + +-------------------------------------------------------------------------------- +function get_last_folder(text,count) + local parts = text:split(DIR_DELIM) + + if count == nil then + return parts[#parts] + end + + local retval = "" + for i=1,count,1 do + retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM + end + + return retval +end + +-------------------------------------------------------------------------------- +function cleanup_path(temppath) + + local parts = temppath:split("-") + temppath = "" + for i=1,#parts,1 do + if temppath ~= "" then + temppath = temppath .. "_" + end + temppath = temppath .. parts[i] + end + + parts = temppath:split(".") + temppath = "" + for i=1,#parts,1 do + if temppath ~= "" then + temppath = temppath .. "_" + end + temppath = temppath .. parts[i] + end + + parts = temppath:split("'") + temppath = "" + for i=1,#parts,1 do + if temppath ~= "" then + temppath = temppath .. "" + end + temppath = temppath .. parts[i] + end + + parts = temppath:split(" ") + temppath = "" + for i=1,#parts,1 do + if temppath ~= "" then + temppath = temppath + end + temppath = temppath .. parts[i] + end + + return temppath +end
\ No newline at end of file diff --git a/builtin/mm_menubar.lua b/builtin/mm_menubar.lua new file mode 100644 index 000000000..faba92a8f --- /dev/null +++ b/builtin/mm_menubar.lua @@ -0,0 +1,78 @@ +--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. + +menubar = {} + +-------------------------------------------------------------------------------- +function menubar.handle_buttons(fields) + for i=1,#menubar.buttons,1 do + if fields[menubar.buttons[i].btn_name] ~= nil then + menu.last_game = menubar.buttons[i].index + engine.setting_set("main_menu_last_game_idx",menu.last_game) + menu.update_gametype() + end + end +end + +-------------------------------------------------------------------------------- +function menubar.refresh() + menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" .. + "box[-0.3,5.6;12.4,0.05;FFFFFF]" + menubar.buttons = {} + + local button_base = -0.25 + + local maxbuttons = #gamemgr.games + + if maxbuttons > 10 then + maxbuttons = 10 + end + + for i=1,maxbuttons,1 do + + local btn_name = "menubar_btn_" .. gamemgr.games[i].id + local buttonpos = button_base + (i-1) * 1.245 + if gamemgr.games[i].menuicon_path ~= nil and + gamemgr.games[i].menuicon_path ~= "" then + + menubar.formspec = menubar.formspec .. + "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" .. + gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]" + 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) + + local text = part1 .. "\n" .. part2 + if part3 ~= nil and + part3 ~= "" then + text = text .. "\n" .. part3 + end + menubar.formspec = menubar.formspec .. + "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name .. + ";" .. text .. ";true;true]" + end + + local toadd = { + btn_name = btn_name, + index = i, + } + + table.insert(menubar.buttons,toadd) + end +end
\ No newline at end of file diff --git a/builtin/mm_textures.lua b/builtin/mm_textures.lua new file mode 100644 index 000000000..60bb3eb31 --- /dev/null +++ b/builtin/mm_textures.lua @@ -0,0 +1,145 @@ +--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. + + +mm_texture = {} + +-------------------------------------------------------------------------------- +function mm_texture.init() + mm_texture.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." .. + DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. + DIR_DELIM .. "pack" .. DIR_DELIM + mm_texture.basetexturedir = mm_texture.defaulttexturedir + + mm_texture.texturepack = engine.setting_get("texture_path") + + mm_texture.gameid = nil +end + +-------------------------------------------------------------------------------- +function mm_texture.update(tab,gamedetails) + if tab ~= "singleplayer" then + mm_texture.reset() + return + end + + if gamedetails == nil then + return + end + + mm_texture.update_game(gamedetails) +end + +-------------------------------------------------------------------------------- +function mm_texture.reset() + mm_texture.gameid = nil + local have_bg = false + local have_overlay = mm_texture.set_generic("overlay") + + if not have_overlay then + have_bg = mm_texture.set_generic("background") + end + + mm_texture.clear("header") + mm_texture.clear("footer") + engine.set_clouds(false) + + mm_texture.set_generic("footer") + mm_texture.set_generic("header") + + if not have_bg and + engine.setting_getbool("enable_clouds") then + engine.set_clouds(true) + end +end + +-------------------------------------------------------------------------------- +function mm_texture.update_game(gamedetails) + if mm_texture.gameid == gamedetails.id then + return + end + + local have_bg = false + local have_overlay = mm_texture.set_game("overlay",gamedetails) + + if not have_overlay then + have_bg = mm_texture.set_game("background",gamedetails) + end + + mm_texture.clear("header") + mm_texture.clear("footer") + engine.set_clouds(false) + + if not have_bg and + engine.setting_getbool("enable_clouds") then + engine.set_clouds(true) + end + + mm_texture.gameid = gamedetails.id +end + +-------------------------------------------------------------------------------- +function mm_texture.clear(identifier) + engine.set_background(identifier,"") +end + +-------------------------------------------------------------------------------- +function mm_texture.set_generic(identifier) + --try texture pack first + if mm_texture.texturepack ~= nil then + local path = mm_texture.texturepack .. DIR_DELIM .."menu_" .. + identifier .. ".png" + if engine.set_background(identifier,path) then + return true + end + end + + if mm_texture.defaulttexturedir ~= nil then + local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" .. + identifier .. ".png" + if engine.set_background(identifier,path) then + return true + end + end + + return false +end + +-------------------------------------------------------------------------------- +function mm_texture.set_game(identifier,gamedetails) + + if gamedetails == nil then + return false + end + + if mm_texture.texturepack ~= nil then + local path = mm_texture.basetexturedir .. + gamedetails.id .. "_menu_" .. identifier .. ".png" + + if engine.set_background(identifier,path) then + return true + end + end + + local path = gamedetails.path .. DIR_DELIM .."menu" .. + DIR_DELIM .. identifier .. ".png" + if engine.set_background(identifier,path) then + return true + end + + return false +end diff --git a/builtin/modmgr.lua b/builtin/modmgr.lua index a01187504..bf71d8b1d 100644 --- a/builtin/modmgr.lua +++ b/builtin/modmgr.lua @@ -541,8 +541,7 @@ end -------------------------------------------------------------------------------- function modmgr.installmod(modfilename,basename) - local modfile = identify_filetype(modfilename) - + local modfile = modmgr.identify_filetype(modfilename) local modpath = modmgr.extract(modfile) if modpath == nil then @@ -1008,3 +1007,41 @@ function modmgr.refresh_globals() {} ) end + +-------------------------------------------------------------------------------- +function modmgr.identify_filetype(name) + + if name:sub(-3):lower() == "zip" then + return { + name = name, + type = "zip" + } + end + + if name:sub(-6):lower() == "tar.gz" or + name:sub(-3):lower() == "tgz"then + return { + name = name, + type = "tgz" + } + end + + if name:sub(-6):lower() == "tar.bz2" then + return { + name = name, + type = "tbz" + } + end + + if name:sub(-2):lower() == "7z" then + return { + name = name, + type = "7z" + } + end + + return { + name = name, + type = "ukn" + } +end |