mirror of
https://gitlab.com/lunovox/computing.git
synced 2025-03-15 06:31:22 +00:00
[add][tested] Function of show icons in smartphone.
This commit is contained in:
parent
cc92d7c80e
commit
39b03a41fa
4 changed files with 140 additions and 22 deletions
69
api.lua
69
api.lua
|
@ -41,44 +41,87 @@ modComputing.log = function(text)
|
|||
end
|
||||
|
||||
modComputing.add_app = function(appname, def)
|
||||
--modComputing.debug("[debug] modComputing.add_app(appname="..dump(appname)..", def) : def="..dump(def))
|
||||
if type(appname)=="string" and appname~="" then
|
||||
if type(modComputing.apps[appname])~="table" then
|
||||
if type(def.iconname)=="string" and def.iconname~="" then
|
||||
if type(def.iconimage)=="string" and def.iconimage~="" then
|
||||
if type(def.on_iconclick)=="string" and def.on_iconclick~="" then
|
||||
modComputing.apps[appname] = {
|
||||
iconname = def.iconname,
|
||||
iconimage = def.iconimage,
|
||||
on_iconclick = def.on_iconclick,
|
||||
}
|
||||
return true
|
||||
if type(def.icon_name)=="string" and def.icon_name~="" then
|
||||
if type(def.icon_title)=="string" and def.icon_title~="" then
|
||||
if type(def.icon_descryption)=="string" and def.icon_descryption~="" then
|
||||
if type(def.icon_type)=="string" and def.icon_type~="" then
|
||||
if type(def.icon_image)=="string" and def.icon_image~="" then
|
||||
if type(def.on_iconclick)=="function" then
|
||||
modComputing.apps[appname] = {
|
||||
icon_name = def.icon_name,
|
||||
icon_title = def.icon_title,
|
||||
icon_descryption = def.icon_descryption,
|
||||
icon_type = def.icon_type,
|
||||
icon_image = def.icon_image,
|
||||
on_iconclick = def.on_iconclick,
|
||||
}
|
||||
return true
|
||||
else
|
||||
--modComputing.debug("[debug] modComputing.add_app() : H")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.on_iconclick' variable!")
|
||||
end
|
||||
else
|
||||
--modComputing.debug("[debug] modComputing.add_app() : G")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.icon_image' variable!")
|
||||
end
|
||||
else
|
||||
--modComputing.debug("[debug] modComputing.add_app() : F")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.icon_type' variable!")
|
||||
end
|
||||
else
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.on_iconclick' variable!")
|
||||
end
|
||||
--modComputing.debug("[debug] modComputing.add_app() : E")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.icon_descryption' variable!")
|
||||
end
|
||||
else
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.iconimage' variable!")
|
||||
--modComputing.debug("[debug] modComputing.add_app() : D")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.icon_title' variable!")
|
||||
end
|
||||
else
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.iconname' variable!")
|
||||
--modComputing.debug("[debug] modComputing.add_app() : C")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'def.icon_name' variable!")
|
||||
end
|
||||
else
|
||||
--modComputing.debug("[debug] modComputing.add_app() : B")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : "..
|
||||
("Unable to repeatedly add appname '%s'!"):format(appname)
|
||||
)
|
||||
end
|
||||
else
|
||||
--modComputing.debug("[debug] modComputing.add_app() : A")
|
||||
return false, modComputing.log("modComputing.add_app(appname, def) : Invalid 'appname' variable!")
|
||||
end
|
||||
end
|
||||
|
||||
modComputing.add_app_test = function(buttoname)
|
||||
modComputing.add_app(buttoname, {
|
||||
icon_name = buttoname,
|
||||
icon_type = "button_exit", --types: button/button_exit
|
||||
icon_title = buttoname,
|
||||
icon_descryption = "Exemplo de botão!",
|
||||
icon_image = "icon_smartphone_128x128.png",
|
||||
--on_iconclick = modComputing.show_smartphone_config,
|
||||
on_iconclick = function()
|
||||
core.chat_send_all("Button '"..icon_title.."' pressed!")
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
modComputing.get_appnames = function()
|
||||
local appnames = {}
|
||||
for k,v in pairs(modComputing.apps) do
|
||||
table.insert(appnames, k)
|
||||
end
|
||||
table.sort(appnames)
|
||||
return appnames
|
||||
end
|
||||
|
||||
modComputing.get_apps = function()
|
||||
return modComputing.apps
|
||||
end
|
||||
|
||||
modComputing.get_app = function(appname)
|
||||
if type(appname)=="string" and appname~="" then
|
||||
if type(modComputing.apps[appname])=="table" then
|
||||
|
|
17
init.lua
17
init.lua
|
@ -9,5 +9,22 @@ dofile(modComputing.modpath.."/functions.lua")
|
|||
dofile(modComputing.modpath.."/item_smartphone.lua")
|
||||
|
||||
|
||||
--[[
|
||||
local timeCount = 0
|
||||
core.register_globalstep(function(dtime)
|
||||
timeCount = timeCount + dtime
|
||||
--modComputing.debug("[debug] core.register_globalstep() timeCount = "..timeCount)
|
||||
if timeCount >= 5 then
|
||||
timeCount = 0
|
||||
--modComputing.debug("[debug] core.register_globalstep()")
|
||||
modComputing.add_app_test()
|
||||
end
|
||||
end)
|
||||
--]]
|
||||
modComputing.add_app_test("CAFÉ")
|
||||
modComputing.add_app_test("LEITE")
|
||||
modComputing.add_app_test("SUCO")
|
||||
modComputing.add_app_test("AÇUCAR")
|
||||
|
||||
|
||||
core.log('action',"[MOD] "..modComputing.modname.." loaded!")
|
||||
|
|
|
@ -16,11 +16,70 @@ modComputing.getFormSmartphone = function(player)
|
|||
.."size["..(10*271/484)..",10.0,true]"
|
||||
.."no_prepend[]"
|
||||
.."bgcolor[#08080844;true]" --Padrão: #080808BB | true = 100% transparente
|
||||
.."style_type[label;font=mono;font_size=11;textcolor=#FFFFFF]"
|
||||
.."style_type[image_button;font=normal;font_size=14;textcolor=#FFFFFF]"
|
||||
.."style_type[image_button_exit;font=normal;font_size=14;textcolor=#FFFFFF]"
|
||||
--.."background[-0.75,-2.00;"..(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=11;textcolor=#FFFFFF]"
|
||||
.."label[0.75,1.975;"..core.formspec_escape(modComputing.getTextClockBar()).."]"
|
||||
.."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")).."]"
|
||||
|
||||
|
||||
|
||||
local appsCount = 0
|
||||
local appnames = modComputing.get_appnames()
|
||||
local apps = modComputing.get_apps()
|
||||
--modComputing.debug("apps = "..dump(apps) --[[, playername--]])
|
||||
--apps = table.sort(apps)
|
||||
for k,v in pairs(appnames) do
|
||||
appsCount = appsCount + 1
|
||||
local appname = v
|
||||
local icon_name = apps[v].icon_name
|
||||
local icon_title = apps[v].icon_title
|
||||
local icon_descryption = apps[v].icon_descryption
|
||||
local icon_type = apps[v].icon_type
|
||||
local icon_image = apps[v].icon_image
|
||||
local on_iconclick = apps[v].on_iconclick
|
||||
|
||||
local maxCol = 2
|
||||
local maxRow = 3
|
||||
local offSetX = 1.10
|
||||
local offSetY = 2.50
|
||||
local sizeButtonX = 1.75
|
||||
local sizeButtonY = 1.75
|
||||
local page = math.floor(appsCount / (maxRow * maxCol)) --math.floor : arredonda sempre para menos
|
||||
local iconInPage = appsCount - math.floor(page * maxRow * maxCol)
|
||||
local iconRow = math.floor((iconInPage - 1) / maxCol)
|
||||
local iconCol = (iconInPage - 1) % maxCol
|
||||
--local iconRow = (iconInPage - 1) % maxRow
|
||||
--local iconCol = 0
|
||||
--local iconRow = iconInPage - 1
|
||||
|
||||
--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("btn_"..icon_name)..";"..core.formspec_escape(icon_title.."\n * "..icon_descryption)..";#008800;#FFFFFF]"
|
||||
|
||||
local newButton = core.formspec_escape("image_"..icon_type).."["
|
||||
..(offSetX + (iconCol * sizeButtonX))..","
|
||||
..(offSetY + (iconRow * sizeButtonY))
|
||||
..";1.5,1.5;"
|
||||
..core.formspec_escape(icon_image)..";" --texture name
|
||||
..core.formspec_escape("btn_"..icon_name)..";" --button name
|
||||
--..core.formspec_escape(appname).." "..iconRow.."/"..iconCol.."\n"..core.formspec_escape("page:"..page.."\ninpg:"..iconInPage)..";" --label
|
||||
--..core.formspec_escape(icon_title)..";" --label
|
||||
..";" --label empty
|
||||
.."false;" --NOCLIP
|
||||
.."true;" --drawborder
|
||||
..core.formspec_escape(icon_image.."^[invert:rgb") --pressed texture name
|
||||
.."]"
|
||||
|
||||
--modComputing.debug("newButton = "..dump(newButton) --[[, playername--]])
|
||||
|
||||
formspec = formspec..newToolTip..newButton
|
||||
end
|
||||
|
||||
|
||||
|
||||
return formspec
|
||||
end
|
||||
|
||||
|
@ -53,10 +112,3 @@ core.register_alias("smartphone", "computing:smartphone")
|
|||
|
||||
|
||||
|
||||
--[[
|
||||
modComputing.add_app("lib_computing:smartphone", {
|
||||
iconname = "SMARTPHONE",
|
||||
iconimage = "icon_smartphone.png",
|
||||
on_iconclick = modComputing.show_smartphone_config,
|
||||
})
|
||||
--]]
|
||||
|
|
6
settingtypes.txt
Normal file
6
settingtypes.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
# COMPUTING SETTINGS
|
||||
|
||||
# COMPUTING DEBUG:
|
||||
# Allows you to print the debug information of this mod on the screen.
|
||||
# Default: false
|
||||
computing.debug (Show Computing Debug) bool false
|
Loading…
Add table
Reference in a new issue