mirror of
https://gitlab.com/lunovox/computing.git
synced 2025-03-15 06:31:22 +00:00
[feat] Adding app pagination functionality.
This commit is contained in:
parent
1d1e2c274e
commit
fa3fbe3602
4 changed files with 165 additions and 71 deletions
2
api.lua
2
api.lua
|
@ -138,7 +138,7 @@ modComputing.add_test_apps = function()
|
||||||
icon_image = "icon_smartphone_128x128.png",
|
icon_image = "icon_smartphone_128x128.png",
|
||||||
--on_iconclick = modComputing.show_smartphone_config,
|
--on_iconclick = modComputing.show_smartphone_config,
|
||||||
on_iconclick = function()
|
on_iconclick = function()
|
||||||
core.chat_send_all("Button 'btnMastodon' pressed!")
|
core.chat_send_all("Button 'btnLockPhone' pressed!")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
3
init.lua
3
init.lua
|
@ -8,7 +8,6 @@ dofile(modComputing.modpath.."/api.lua")
|
||||||
dofile(modComputing.modpath.."/functions.lua")
|
dofile(modComputing.modpath.."/functions.lua")
|
||||||
dofile(modComputing.modpath.."/item_smartphone.lua")
|
dofile(modComputing.modpath.."/item_smartphone.lua")
|
||||||
|
|
||||||
|
modComputing.add_test_apps() --only work if debug activate
|
||||||
--modComputing.add_test_apps()
|
|
||||||
|
|
||||||
core.log('action',"[MOD] "..modComputing.modname.." loaded!")
|
core.log('action',"[MOD] "..modComputing.modname.." loaded!")
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
|
modComputing.smartphone = {
|
||||||
|
maxCol = 2,
|
||||||
|
maxRow = 3,
|
||||||
|
offSetX = 1.00,
|
||||||
|
offSetY = 2.25,
|
||||||
|
marginConteinerX = 0.50,
|
||||||
|
marginConteinerY = 0.25,
|
||||||
|
sizeButtonX = 1.50,
|
||||||
|
sizeButtonY = 1.50,
|
||||||
|
}
|
||||||
|
|
||||||
modComputing.getTextClockBar = function()
|
modComputing.getTextClockBar = function()
|
||||||
--return modComputing.getTextNowWeekDay3S()..", "..modComputing.getTextNowDate().." "..modComputing.getTextNowTime()
|
--return modComputing.getTextNowWeekDay3S()..", "..modComputing.getTextNowDate().." "..modComputing.getTextNowTime()
|
||||||
|
@ -11,6 +20,7 @@ modComputing.getTextClockBar = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
modComputing.getFormSmartphone = function(player)
|
modComputing.getFormSmartphone = function(player)
|
||||||
|
local playername = player:get_player_name()
|
||||||
local formspec = ""
|
local formspec = ""
|
||||||
.."formspec_version[6]"
|
.."formspec_version[6]"
|
||||||
.."size["..(10*271/484)..",10.0,true]"
|
.."size["..(10*271/484)..",10.0,true]"
|
||||||
|
@ -22,18 +32,33 @@ modComputing.getFormSmartphone = function(player)
|
||||||
.."image[0,0;"..(10*271/484)..",10.0;text_smartphone_271x484.png;true]"
|
.."image[0,0;"..(10*271/484)..",10.0;text_smartphone_271x484.png;true]"
|
||||||
.."style_type[label;font=mono;font_size=10;textcolor=#FFFFFF]"
|
.."style_type[label;font=mono;font_size=10;textcolor=#FFFFFF]"
|
||||||
.."label[0.75,1.975;"..core.formspec_escape(modComputing.getTextClockBar()).."]"
|
.."label[0.75,1.975;"..core.formspec_escape(modComputing.getTextClockBar()).."]"
|
||||||
|
.."style_type[container;font=normal;font_size=7;textcolor=#FFFFFF]"
|
||||||
--.."button_exit[0.75,2.50;1.5,1.5;btnClose;"..core.formspec_escape(modComputing.translate("Banana\nStore")).."]"
|
--.."button_exit[0.75,2.50;1.5,1.5;btnClose;"..core.formspec_escape(modComputing.translate("Banana\nStore")).."]"
|
||||||
|
|
||||||
|
if type(modComputing.show_page)~="table" then
|
||||||
|
modComputing.show_page = { }
|
||||||
|
end
|
||||||
|
if type(modComputing.show_page[playername])~="number"
|
||||||
|
or modComputing.show_page[playername] < 0
|
||||||
|
then
|
||||||
|
modComputing.show_page[playername] = 0
|
||||||
|
end
|
||||||
|
|
||||||
local appsCount = 0
|
local appsCount = 0
|
||||||
local appnames = modComputing.get_appnames()
|
local appnames = modComputing.get_appnames()
|
||||||
local apps = modComputing.get_apps()
|
local maxCol = modComputing.smartphone.maxCol
|
||||||
--modComputing.debug("apps = "..dump(apps) --[[, playername--]])
|
local maxRow = modComputing.smartphone.maxRow
|
||||||
--apps = table.sort(apps)
|
local offSetX = modComputing.smartphone.offSetX
|
||||||
|
local offSetY = modComputing.smartphone.offSetY
|
||||||
|
local marginConteinerX = modComputing.smartphone.marginConteinerX
|
||||||
|
local marginConteinerY = modComputing.smartphone.marginConteinerY
|
||||||
|
local sizeButtonX = modComputing.smartphone.sizeButtonX
|
||||||
|
local sizeButtonY = modComputing.smartphone.sizeButtonY
|
||||||
|
|
||||||
for k,v in pairs(appnames) do
|
for k,v in pairs(appnames) do
|
||||||
appsCount = appsCount + 1
|
appsCount = appsCount + 1
|
||||||
local appname = v
|
local apps = modComputing.get_apps()
|
||||||
|
--modComputing.debug("apps = "..dump(apps) --[[, playername--]])
|
||||||
local icon_name = apps[v].icon_name
|
local icon_name = apps[v].icon_name
|
||||||
local icon_title = apps[v].icon_title
|
local icon_title = apps[v].icon_title
|
||||||
local icon_descryption = apps[v].icon_descryption
|
local icon_descryption = apps[v].icon_descryption
|
||||||
|
@ -41,70 +66,103 @@ modComputing.getFormSmartphone = function(player)
|
||||||
local icon_image = apps[v].icon_image
|
local icon_image = apps[v].icon_image
|
||||||
local on_iconclick = apps[v].on_iconclick
|
local on_iconclick = apps[v].on_iconclick
|
||||||
|
|
||||||
local maxCol = 2
|
local page = math.floor((appsCount - 1) / (maxRow * maxCol)) --math.floor : arredonda sempre para menos
|
||||||
local maxRow = 3
|
if page == modComputing.show_page[playername] then
|
||||||
local offSetX = 1.10
|
local iconInPage = appsCount - math.floor(page * maxRow * maxCol)
|
||||||
local offSetY = 2.50
|
local iconRow = math.floor((iconInPage - 1) / maxCol)
|
||||||
local sizeButtonX = 1.75
|
local iconCol = (iconInPage - 1) % maxCol
|
||||||
local sizeButtonY = 1.75
|
|
||||||
local page = math.floor(appsCount / (maxRow * maxCol)) --math.floor : arredonda sempre para menos
|
--SAMPLE: image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]
|
||||||
local iconInPage = appsCount - math.floor(page * maxRow * maxCol)
|
--SAMPLE: image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
|
||||||
local iconRow = math.floor((iconInPage - 1) / maxCol)
|
local newToolTip = "tooltip["..core.formspec_escape(icon_name)..";"
|
||||||
local iconCol = (iconInPage - 1) % maxCol
|
..core.formspec_escape(
|
||||||
--local iconRow = (iconInPage - 1) % maxRow
|
core.colorize("#00FF00", icon_title).."\n"
|
||||||
--local iconCol = 0
|
.."* "..icon_descryption
|
||||||
--local iconRow = iconInPage - 1
|
)
|
||||||
|
..";#004400;#FFFFFF"
|
||||||
--SAMPLE: image_button[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>;<noclip>;<drawborder>;<pressed texture name>]
|
.."]"
|
||||||
--SAMPLE: image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
|
|
||||||
local newToolTip = "tooltip["..core.formspec_escape(icon_name)..";"
|
local newAppButton = core.formspec_escape("image_"..icon_type).."["
|
||||||
..core.formspec_escape(
|
.."0.10,0"
|
||||||
core.colorize("#00FF00", icon_title).."\n"
|
..";1.35,1.35;"
|
||||||
.."* "..icon_descryption
|
..core.formspec_escape(icon_image)..";" --texture name
|
||||||
)
|
..core.formspec_escape(icon_name)..";" --button name
|
||||||
..";#004400;#FFFFFF"
|
--..";" --label empty
|
||||||
.."]"
|
--..core.formspec_escape(appname).." "..iconRow.."/"..iconCol.."\n"..core.formspec_escape("page:"..page.."\ninpg:"..iconInPage)..";" --label
|
||||||
|
..";" --empty label
|
||||||
local newButton = core.formspec_escape("image_"..icon_type).."["
|
.."false;" --NOCLIP
|
||||||
..(offSetX + (iconCol * sizeButtonX))..","
|
.."false;" --drawborder
|
||||||
..(offSetY + (iconRow * sizeButtonY))
|
..core.formspec_escape(icon_image.."^[invert:rgb") --pressed texture name
|
||||||
..";1.5,1.5;"
|
.."]"
|
||||||
..core.formspec_escape(icon_image)..";" --texture name
|
|
||||||
..core.formspec_escape(icon_name)..";" --button name
|
local newAppLabel = "label[0.10,1.50;"
|
||||||
--..";" --label empty
|
..core.formspec_escape(icon_title)
|
||||||
--..core.formspec_escape(appname).." "..iconRow.."/"..iconCol.."\n"..core.formspec_escape("page:"..page.."\ninpg:"..iconInPage)..";" --label
|
.."]"
|
||||||
..core.formspec_escape(icon_title)..";" --label
|
|
||||||
.."true;" --NOCLIP
|
--modComputing.debug("newAppButton = "..dump(newAppButton) --[[, playername--]])
|
||||||
.."false;" --drawborder
|
|
||||||
..core.formspec_escape(icon_image.."^[invert:rgb") --pressed texture name
|
formspec = formspec
|
||||||
.."]"
|
.."container["
|
||||||
|
..(offSetX + (iconCol * marginConteinerX) + (iconCol * sizeButtonX))..","
|
||||||
--modComputing.debug("newButton = "..dump(newButton) --[[, playername--]])
|
..(offSetY + (iconRow * marginConteinerY) + (iconRow * sizeButtonY))
|
||||||
|
.."]"
|
||||||
formspec = formspec..newToolTip..newButton
|
--.."box[0,0;1.45,1.65;#00000088]"
|
||||||
|
..newToolTip..newAppButton..newAppLabel
|
||||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
.."container_end[]"
|
||||||
--[[
|
end --Final of: if page == modComputing.show_page[playername] then
|
||||||
local playername = player:get_player_name()
|
|
||||||
modComputing.debug(
|
|
||||||
"modComputing.debug()\n"
|
|
||||||
.." > playername ="..dump(playername)
|
|
||||||
.." > formname ="..dump(formname)
|
|
||||||
.." > fields ="..dump(fields)
|
|
||||||
)
|
|
||||||
--[[ ]]
|
|
||||||
if type(formname)=="string" and formname=="frmSmartphone" then
|
|
||||||
if type(fields)=="table" and type(fields[icon_name])=="string" then
|
|
||||||
on_iconclick(player)
|
|
||||||
return true --If function returns true, remaining functions are not called
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
end --FONAL OF: for k,v in pairs(appnames) do
|
end --FONAL OF: for k,v in pairs(appnames) do
|
||||||
|
|
||||||
|
local maxPages = math.floor((appsCount - 1) / (maxRow * maxCol)) --math.floor : arredonda sempre para menos
|
||||||
|
if maxPages > 0 then
|
||||||
|
formspec = formspec
|
||||||
|
.."container[0,7.5]"
|
||||||
|
.."tooltip[btnPageBack;"
|
||||||
|
..core.formspec_escape(modComputing.translate("BACK PAGE"))
|
||||||
|
..";#004400;#FFFFFF"
|
||||||
|
.."]"
|
||||||
|
.."image_button[1.0,0;0.5,0.5;"
|
||||||
|
..core.formspec_escape("btn_page_change.png") --texture name
|
||||||
|
..";"..core.formspec_escape("btnPageBack") --button name
|
||||||
|
..";" --Empty Label
|
||||||
|
..";false" --NOCLIP
|
||||||
|
..";false" --drawborder
|
||||||
|
..";"..core.formspec_escape(
|
||||||
|
"btn_page_change.png"
|
||||||
|
.."^[invert:rgb"
|
||||||
|
) --pressed texture name
|
||||||
|
.."]"
|
||||||
|
|
||||||
|
.."label[1.75,0.25;"
|
||||||
|
..core.formspec_escape(
|
||||||
|
modComputing.translate("Page")..": "
|
||||||
|
..("%02d"):format(modComputing.show_page[playername] + 1)
|
||||||
|
.." / "
|
||||||
|
..("%02d"):format(maxPages + 1)
|
||||||
|
)
|
||||||
|
.."]"
|
||||||
|
|
||||||
|
.."tooltip[btnPageNext;"
|
||||||
|
..core.formspec_escape(modComputing.translate("NEXT PAGE"))
|
||||||
|
..";#004400;#FFFFFF"
|
||||||
|
.."]"
|
||||||
|
.."image_button[4.0,0;0.5,0.5;"
|
||||||
|
..core.formspec_escape(
|
||||||
|
"btn_page_change.png"
|
||||||
|
.."^[transformFX"
|
||||||
|
) --texture name
|
||||||
|
..";"..core.formspec_escape("btnPageNext") --button name
|
||||||
|
..";" --Empty Label
|
||||||
|
..";false" --NOCLIP
|
||||||
|
..";false" --drawborder
|
||||||
|
..";"..core.formspec_escape(
|
||||||
|
"btn_page_change.png"
|
||||||
|
.."^[transformFX"
|
||||||
|
.."^[invert:rgb"
|
||||||
|
) --texture name
|
||||||
|
.."]"
|
||||||
|
.."container_end[]"
|
||||||
|
end
|
||||||
|
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
@ -114,6 +172,43 @@ modComputing.show_smartphone = function(player)
|
||||||
core.show_formspec(playername, "frmSmartphone", modComputing.getFormSmartphone(player))
|
core.show_formspec(playername, "frmSmartphone", modComputing.getFormSmartphone(player))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if type(formname)=="string" and formname=="frmSmartphone" then
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
local appnames = modComputing.get_appnames()
|
||||||
|
local appsCount = table.getn(appnames)
|
||||||
|
local maxCol = modComputing.smartphone.maxCol
|
||||||
|
local maxRow = modComputing.smartphone.maxRow
|
||||||
|
local maxPages = math.floor((appsCount - 1) / (maxRow * maxCol)) --math.floor : arredonda sempre para menos
|
||||||
|
--modComputing.debug("apps = "..dump(apps) --[[, playername--]])
|
||||||
|
|
||||||
|
if type(fields.btnPageBack)~="nil" then
|
||||||
|
if modComputing.show_page[playername] > 0 then
|
||||||
|
modComputing.show_page[playername] = modComputing.show_page[playername] - 1
|
||||||
|
modComputing.show_smartphone(player)
|
||||||
|
end
|
||||||
|
return true --If function returns true, remaining functions are not called
|
||||||
|
elseif type(fields.btnPageNext)~="nil" then
|
||||||
|
if modComputing.show_page[playername] < maxPages then
|
||||||
|
modComputing.show_page[playername] = modComputing.show_page[playername] + 1
|
||||||
|
modComputing.show_smartphone(player)
|
||||||
|
end
|
||||||
|
return true --If function returns true, remaining functions are not called
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
for k,v in pairs(appnames) do
|
||||||
|
local apps = modComputing.get_apps()
|
||||||
|
local icon_name = apps[v].icon_name
|
||||||
|
local on_iconclick = apps[v].on_iconclick
|
||||||
|
if type(fields)=="table" and type(fields[icon_name])=="string" then
|
||||||
|
on_iconclick(player)
|
||||||
|
return true --If function returns true, remaining functions are not called
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
core.register_craftitem("computing:smartphone", {
|
core.register_craftitem("computing:smartphone", {
|
||||||
description = core.colorize(
|
description = core.colorize(
|
||||||
|
@ -135,7 +230,7 @@ core.register_craftitem("computing:smartphone", {
|
||||||
},
|
},
|
||||||
on_use = function(itemstack, player, pointed_thing)
|
on_use = function(itemstack, player, pointed_thing)
|
||||||
modComputing.show_smartphone(player)
|
modComputing.show_smartphone(player)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
modComputing.is_allow_smartphone_recipe = function(player)
|
modComputing.is_allow_smartphone_recipe = function(player)
|
||||||
|
|
BIN
textures/btn_page_change.png
Normal file
BIN
textures/btn_page_change.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Loading…
Add table
Reference in a new issue