@@ -20,6 +20,17 @@ menu = {}
20
20
local tabbuilder = {}
21
21
local worldlist = nil
22
22
23
+ ---- ----------------------------------------------------------------------------
24
+ local function filterTP (TPlist )
25
+ TPlist2 = {" None" }
26
+ for _ ,i in ipairs (TPlist ) do
27
+ if i ~= " base" then
28
+ table.insert (TPlist2 , i )
29
+ end
30
+ end
31
+ return TPlist2
32
+ end
33
+
23
34
---- ----------------------------------------------------------------------------
24
35
function menu .render_favorite (spec ,render_details )
25
36
local text = " "
@@ -162,6 +173,23 @@ function menu.render_world_list()
162
173
return retval
163
174
end
164
175
176
+ ---- ----------------------------------------------------------------------------
177
+ function menu .render_TP_list (TPlist )
178
+ local retval = " "
179
+
180
+ -- local current_TP = filterlist.get_list(TPlist)
181
+
182
+ for i ,v in ipairs (TPlist ) do
183
+ if retval ~= " " then
184
+ retval = retval .. " ,"
185
+ end
186
+
187
+ retval = retval .. v
188
+ end
189
+
190
+ return retval
191
+ end
192
+
165
193
---- ----------------------------------------------------------------------------
166
194
function menu .init ()
167
195
-- init menu data
@@ -179,8 +207,7 @@ function menu.init()
179
207
menu .favorites = engine .get_favorites (" local" )
180
208
end
181
209
182
- menu .defaulttexturedir = engine .get_gamepath () .. DIR_DELIM .. " .." ..
183
- DIR_DELIM .. " textures" .. DIR_DELIM .. " base" ..
210
+ menu .defaulttexturedir = engine .get_texturepath () .. DIR_DELIM .. " base" ..
184
211
DIR_DELIM .. " pack" .. DIR_DELIM
185
212
end
186
213
@@ -307,6 +334,10 @@ function tabbuilder.gettab()
307
334
retval = retval .. tabbuilder .tab_settings ()
308
335
end
309
336
337
+ if tabbuilder .current_tab == " texture_packs" then
338
+ retval = retval .. tabbuilder .tab_TP ()
339
+ end
340
+
310
341
if tabbuilder .current_tab == " credits" then
311
342
retval = retval .. tabbuilder .tab_credits ()
312
343
end
@@ -734,6 +765,23 @@ function tabbuilder.handle_singleplayer_buttons(fields)
734
765
end
735
766
end
736
767
768
+ ---- ----------------------------------------------------------------------------
769
+ function tabbuilder .handle_TP_buttons (fields )
770
+ if fields [" TPs" ] ~= nil then
771
+ local event = explode_textlist_event (fields [" TPs" ])
772
+ if event .typ == " CHG" or event .typ == " DCL" then
773
+ local index = engine .get_textlist_index (" TPs" )
774
+ engine .setting_set (" mainmenu_last_selected_TP" ,
775
+ index )
776
+ local TPlist = filterTP (engine .get_dirlist (engine .get_texturepath (), true ))
777
+ local TPname = TPlist [engine .get_textlist_index (" TPs" )]
778
+ local TPpath = engine .get_texturepath ().. DIR_DELIM .. TPname
779
+ if TPname == " None" then TPpath = " " end
780
+ engine .setting_set (" texture_path" , TPpath )
781
+ end
782
+ end
783
+ end
784
+
737
785
---- ----------------------------------------------------------------------------
738
786
function tabbuilder .tab_header ()
739
787
@@ -798,6 +846,7 @@ function tabbuilder.init()
798
846
table.insert (tabbuilder .current_buttons ,{name = " multiplayer" , caption = " Client" })
799
847
table.insert (tabbuilder .current_buttons ,{name = " server" , caption = " Server" })
800
848
table.insert (tabbuilder .current_buttons ,{name = " settings" , caption = " Settings" })
849
+ table.insert (tabbuilder .current_buttons ,{name = " texture_packs" , caption = " Texture Packs" })
801
850
802
851
if engine .setting_getbool (" main_menu_game_mgr" ) then
803
852
table.insert (tabbuilder .current_buttons ,{name = " game_mgr" , caption = " Games" })
@@ -946,6 +995,49 @@ function tabbuilder.tab_singleplayer()
946
995
menubar .formspec
947
996
end
948
997
998
+ ---- ----------------------------------------------------------------------------
999
+ function tabbuilder .tab_TP ()
1000
+ local TPpath = engine .setting_get (" texture_path" )
1001
+ local TPlist = filterTP (engine .get_dirlist (engine .get_texturepath (), true ))
1002
+ local index = tonumber (engine .setting_get (" mainmenu_last_selected_TP" ))
1003
+ if index == nil then index = 1 end
1004
+ if TPpath == " " then
1005
+ return " label[4,-0.25;Select texture pack:]" ..
1006
+ " vertlabel[0,-0.25;TEXTURE PACKS]" ..
1007
+ " textlist[4,0.25;7.5,5.0;TPs;" ..
1008
+ menu .render_TP_list (TPlist ) ..
1009
+ " ;" .. index .. " ]" ..
1010
+ menubar .formspec
1011
+ end
1012
+ local TPinfofile = TPpath .. DIR_DELIM .. " info.txt"
1013
+ local f = io.open (TPinfofile , " r" )
1014
+ if f == nil then
1015
+ menu .TPinfo = " No information available"
1016
+ else
1017
+ menu .TPinfo = f :read (" *all" )
1018
+ f :close ()
1019
+ end
1020
+ local TPscreenfile = TPpath .. DIR_DELIM .. " screenshot.png"
1021
+ local f = io.open (TPscreenfile , " r" )
1022
+ if f == nil then
1023
+ menu .TPscreen = nil
1024
+ else
1025
+ menu .TPscreen = TPscreenfile
1026
+ f :close ()
1027
+ end
1028
+
1029
+ local no_screenshot = engine .get_texturepath ().. DIR_DELIM .. " base" .. DIR_DELIM .. " pack" .. DIR_DELIM .. " no_screenshot.png"
1030
+
1031
+ return " label[4,-0.25;Select texture pack:]" ..
1032
+ " vertlabel[0,-0.25;TEXTURE PACKS]" ..
1033
+ " textlist[4,0.25;7.5,5.0;TPs;" ..
1034
+ menu .render_TP_list (TPlist ) ..
1035
+ " ;" .. index .. " ]" ..
1036
+ " image[0.65,0.25;4.0,3.7;" .. (menu .TPscreen or no_screenshot ).. " ]" ..
1037
+ " textarea[1.0,3.25;3.7,1.5;;" .. (menu .TPinfo or " " ).. " ;]" ..
1038
+ menubar .formspec
1039
+ end
1040
+
949
1041
---- ----------------------------------------------------------------------------
950
1042
function tabbuilder .tab_credits ()
951
1043
return " vertlabel[0,-0.5;CREDITS]" ..
@@ -1039,6 +1131,10 @@ engine.button_handler = function(fields)
1039
1131
tabbuilder .handle_singleplayer_buttons (fields )
1040
1132
end
1041
1133
1134
+ if tabbuilder .current_tab == " texture_packs" then
1135
+ tabbuilder .handle_TP_buttons (fields )
1136
+ end
1137
+
1042
1138
if tabbuilder .current_tab == " multiplayer" then
1043
1139
tabbuilder .handle_multiplayer_buttons (fields )
1044
1140
end
0 commit comments