diff --git a/api.lua b/api.lua index f54fd13..df00258 100644 --- a/api.lua +++ b/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 diff --git a/init.lua b/init.lua index e19a4fc..9a90ebe 100644 --- a/init.lua +++ b/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!") diff --git a/item_smartphone.lua b/item_smartphone.lua index 4a8a085..dbe18fa 100644 --- a/item_smartphone.lua +++ b/item_smartphone.lua @@ -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[,;,;;;