Scroll galleries pagewise
This commit is contained in:
parent
330e83323c
commit
4d2b79732c
29
init.lua
29
init.lua
@ -524,6 +524,7 @@ doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width,
|
|||||||
|
|
||||||
local imageindex = doc.data.players[playername].galidx
|
local imageindex = doc.data.players[playername].galidx
|
||||||
doc.data.players[playername].maxgalidx = #imagedata
|
doc.data.players[playername].maxgalidx = #imagedata
|
||||||
|
doc.data.players[playername].galrows = rows
|
||||||
|
|
||||||
if aspect_ratio == nil then aspect_ratio = (2/3) end
|
if aspect_ratio == nil then aspect_ratio = (2/3) end
|
||||||
local pos = 0
|
local pos = 0
|
||||||
@ -535,10 +536,21 @@ doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width,
|
|||||||
iw = totalimagewidth / rows
|
iw = totalimagewidth / rows
|
||||||
ih = iw * aspect_ratio
|
ih = iw * aspect_ratio
|
||||||
formstring = formstring .. "button["..x..","..y..";"..bw..","..ih..";doc_button_gallery_prev;"..F("<").."]"
|
formstring = formstring .. "button["..x..","..y..";"..bw..","..ih..";doc_button_gallery_prev;"..F("<").."]"
|
||||||
formstring = formstring .. "tooltip[doc_button_gallery_prev;"..F("Show previous image").."]"
|
local tt
|
||||||
|
if rows == 1 then
|
||||||
|
tt = F("Show previous image")
|
||||||
|
else
|
||||||
|
tt = F("Show previous gallery page")
|
||||||
|
end
|
||||||
|
formstring = formstring .. "tooltip[doc_button_gallery_prev;"..tt.."]"
|
||||||
local rightx = buttonoffset + (x + rows * iw)
|
local rightx = buttonoffset + (x + rows * iw)
|
||||||
formstring = formstring .. "button["..rightx..","..y..";"..bw..","..ih..";doc_button_gallery_next;"..F(">").."]"
|
formstring = formstring .. "button["..rightx..","..y..";"..bw..","..ih..";doc_button_gallery_next;"..F(">").."]"
|
||||||
formstring = formstring .. "tooltip[doc_button_gallery_next;"..F("Show next image").."]"
|
if rows == 1 then
|
||||||
|
tt = F("Show next image")
|
||||||
|
else
|
||||||
|
tt = F("Show next gallery page")
|
||||||
|
end
|
||||||
|
formstring = formstring .. "tooltip[doc_button_gallery_next;"..tt.."]"
|
||||||
buttonoffset = bw
|
buttonoffset = bw
|
||||||
else
|
else
|
||||||
totalimagewidth = width
|
totalimagewidth = width
|
||||||
@ -1049,19 +1061,16 @@ function doc.process_form(player,formname,fields)
|
|||||||
end
|
end
|
||||||
elseif fields["doc_button_gallery_prev"] then
|
elseif fields["doc_button_gallery_prev"] then
|
||||||
local cid, eid = doc.get_selection(playername)
|
local cid, eid = doc.get_selection(playername)
|
||||||
doc.data.players[playername].galidx = doc.data.players[playername].galidx - 1
|
if doc.data.players[playername].galidx - doc.data.players[playername].galrows > 0 then
|
||||||
if doc.data.players[playername].galidx <= 0 then
|
doc.data.players[playername].galidx = doc.data.players[playername].galidx - doc.data.players[playername].galrows
|
||||||
doc.data.players[playername].galidx = 1
|
|
||||||
end
|
end
|
||||||
local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername)
|
local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername)
|
||||||
minetest.show_formspec(playername, "doc:entry", formspec)
|
minetest.show_formspec(playername, "doc:entry", formspec)
|
||||||
elseif fields["doc_button_gallery_next"] then
|
elseif fields["doc_button_gallery_next"] then
|
||||||
local cid, eid = doc.get_selection(playername)
|
local cid, eid = doc.get_selection(playername)
|
||||||
doc.data.players[playername].galidx = doc.data.players[playername].galidx + 1
|
if doc.data.players[playername].galidx + doc.data.players[playername].galrows <= doc.data.players[playername].maxgalidx then
|
||||||
if doc.data.players[playername].galidx > doc.data.players[playername].maxgalidx then
|
doc.data.players[playername].galidx = doc.data.players[playername].galidx + doc.data.players[playername].galrows
|
||||||
doc.data.players[playername].galidx = doc.data.players[playername].maxgalidx
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername)
|
local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername)
|
||||||
minetest.show_formspec(playername, "doc:entry", formspec)
|
minetest.show_formspec(playername, "doc:entry", formspec)
|
||||||
end
|
end
|
||||||
@ -1091,6 +1100,8 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
playerdata.galidx = 1
|
playerdata.galidx = 1
|
||||||
-- Maximum gallery index (index of last image in gallery)
|
-- Maximum gallery index (index of last image in gallery)
|
||||||
playerdata.maxgalidx = 1
|
playerdata.maxgalidx = 1
|
||||||
|
-- Number of rows in an gallery of the current entry
|
||||||
|
playerdata.galrows = 1
|
||||||
-- Table for persistant data
|
-- Table for persistant data
|
||||||
playerdata.stored_data = {}
|
playerdata.stored_data = {}
|
||||||
-- Contains viewed entries
|
-- Contains viewed entries
|
||||||
|
Loading…
x
Reference in New Issue
Block a user