Skip to content

Commit 0f9440f

Browse files
sapiersapier
sapier
authored and
sapier
committedNov 10, 2013
Fix "TODO read modinfo" in modmanager to improve ui usability
1 parent d75b171 commit 0f9440f

File tree

4 files changed

+129
-16
lines changed

4 files changed

+129
-16
lines changed
 

Diff for: ‎builtin/misc_helpers.lua

+56
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,62 @@ function tbl.formspec_escape(text)
205205
return text
206206
end
207207

208+
209+
function tbl.splittext(text,charlimit)
210+
local retval = {}
211+
212+
local current_idx = 1
213+
214+
local start,stop = string.find(text," ",current_idx)
215+
local nl_start,nl_stop = string.find(text,"\n",current_idx)
216+
local gotnewline = false
217+
if nl_start ~= nil and (start == nil or nl_start < start) then
218+
start = nl_start
219+
stop = nl_stop
220+
gotnewline = true
221+
end
222+
local last_line = ""
223+
while start ~= nil do
224+
if string.len(last_line) + (stop-start) > charlimit then
225+
table.insert(retval,last_line)
226+
last_line = ""
227+
end
228+
229+
if last_line ~= "" then
230+
last_line = last_line .. " "
231+
end
232+
233+
last_line = last_line .. string.sub(text,current_idx,stop -1)
234+
235+
if gotnewline then
236+
table.insert(retval,last_line)
237+
last_line = ""
238+
gotnewline = false
239+
end
240+
current_idx = stop+1
241+
242+
start,stop = string.find(text," ",current_idx)
243+
nl_start,nl_stop = string.find(text,"\n",current_idx)
244+
245+
if nl_start ~= nil and (start == nil or nl_start < start) then
246+
start = nl_start
247+
stop = nl_stop
248+
gotnewline = true
249+
end
250+
end
251+
252+
--add last part of text
253+
if string.len(last_line) + (string.len(text) - current_idx) > charlimit then
254+
table.insert(retval,last_line)
255+
table.insert(retval,string.sub(text,current_idx))
256+
else
257+
last_line = last_line .. " " .. string.sub(text,current_idx)
258+
table.insert(retval,last_line)
259+
end
260+
261+
return retval
262+
end
263+
208264
--------------------------------------------------------------------------------
209265

210266
if minetest then

Diff for: ‎builtin/modmgr.lua

+57-15
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ function modmgr.tab()
235235
local retval =
236236
"vertlabel[0,-0.25;".. fgettext("MODS") .. "]" ..
237237
"label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" ..
238-
"textlist[0.75,0.25;4.5,4.3;modlist;" ..
238+
"textlist[0.75,0.25;4.5,4;modlist;" ..
239239
modmgr.render_modlist(modmgr.global_mods) ..
240240
";" .. modmgr.selected_mod .. "]"
241241

242242
retval = retval ..
243-
"button[1,4.85;2,0.5;btn_mod_mgr_install_local;".. fgettext("Install") .. "]" ..
244-
"button[3,4.85;2,0.5;btn_mod_mgr_download;".. fgettext("Download") .. "]"
243+
"label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
244+
"button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
245+
"button[2.45,4.85;3.05,0.5;btn_mod_mgr_download;".. fgettext("Online mod repository") .. "]"
245246

246247
local selected_mod = nil
247248

@@ -250,25 +251,66 @@ function modmgr.tab()
250251
end
251252

252253
if selected_mod ~= nil then
254+
local modscreenshot = nil
255+
256+
--check for screenshot beeing available
257+
local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
258+
local error = nil
259+
screenshotfile,error = io.open(screenshotfilename,"r")
260+
if error == nil then
261+
screenshotfile:close()
262+
modscreenshot = screenshotfilename
263+
end
264+
265+
if modscreenshot == nil then
266+
modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
267+
end
268+
269+
retval = retval
270+
.. "image[5.5,0;3,2;" .. modscreenshot .. "]"
271+
.. "label[8.25,0.6;" .. selected_mod.name .. "]"
272+
273+
local descriptionlines = nil
274+
error = nil
275+
local descriptionfilename = selected_mod.path .. "description.txt"
276+
descriptionfile,error = io.open(descriptionfilename,"r")
277+
if error == nil then
278+
descriptiontext = descriptionfile:read("*all")
279+
280+
descriptionlines = engine.splittext(descriptiontext,42)
281+
descriptionfile:close()
282+
else
283+
descriptionlines = {}
284+
table.insert(descriptionlines,fgettext("No mod description available"))
285+
end
286+
287+
retval = retval ..
288+
"label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
289+
"textlist[5.5,2.2;6.2,2.4;description;"
290+
291+
for i=1,#descriptionlines,1 do
292+
retval = retval .. engine.formspec_escape(descriptionlines[i]) .. ","
293+
end
294+
295+
253296
if selected_mod.is_modpack then
254-
retval = retval
255-
.. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
256-
fgettext("Rename") .. "]"
297+
retval = retval .. ";0]" ..
298+
"button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
299+
fgettext("Rename") .. "]"
300+
retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
301+
.. fgettext("Uninstall selected modpack") .. "]"
257302
else
258-
--show dependencies
259-
retval = retval ..
260-
"label[6,1.9;".. fgettext("Depends:") .. "]" ..
261-
"textlist[6,2.4;5.7,2;deplist;"
303+
--show dependencies
304+
305+
retval = retval .. ",Depends:,"
262306

263307
toadd = modmgr.get_dependencies(selected_mod.path)
264308

265-
retval = retval .. toadd .. ";0;true,false]"
309+
retval = retval .. toadd .. ";0]"
266310

267-
--TODO read modinfo
311+
retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
312+
.. fgettext("Uninstall selected mod") .. "]"
268313
end
269-
--show delete button
270-
retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;"
271-
.. fgettext("Delete") .. "]"
272314
end
273315
return retval
274316
end

Diff for: ‎doc/lua_api.txt

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Mod directory structure
100100
mods
101101
|-- modname
102102
| |-- depends.txt
103+
| |-- screenshot.png
104+
| |-- description.txt
103105
| |-- init.lua
104106
| |-- textures
105107
| | |-- modname_stuff.png
@@ -121,6 +123,12 @@ depends.txt:
121123
to a single modname. Their meaning is that if the specified mod
122124
is missing, that does not prevent this mod from being loaded.
123125

126+
screenshot.png:
127+
A screenshot shown in modmanager within mainmenu.
128+
129+
description.txt:
130+
File containing desctiption to be shown within mainmenu.
131+
124132
optdepends.txt:
125133
An alternative way of specifying optional dependencies.
126134
Like depends.txt, a single line contains a single modname.

Diff for: ‎src/guiFormSpecMenu.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,15 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
721721
scrollbar->setPos(data->listbox_scroll[fname_w]);
722722
}
723723
}
724+
else {
725+
gui::IGUIScrollBar *scrollbar = getListboxScrollbar(e);
726+
if (scrollbar) {
727+
scrollbar->setPos(0);
728+
}
729+
}
724730

725-
if (str_initial_selection != "")
731+
if ((str_initial_selection != "") &&
732+
(str_initial_selection != "0"))
726733
e->setSelected(stoi(str_initial_selection.c_str())-1);
727734

728735
m_listboxes.push_back(std::pair<FieldSpec,gui::IGUIListBox*>(spec,e));

0 commit comments

Comments
 (0)
Please sign in to comment.