diff --git a/data/config.example.lua b/data/config.example.lua index 4f7da83..7fd3c19 100644 --- a/data/config.example.lua +++ b/data/config.example.lua @@ -27,6 +27,8 @@ sounds = { started = "minecraft:block.note_block.harp", purchase = "minecraft:entity.villager.yes", - error = "minecraft:block.anvil.land" + error = "minecraft:block.anvil.land", + click = "minecraft:block.wooden_button.click_on", + volume = 0.6 } } diff --git a/src/frontend.lua b/src/frontend.lua index f1e1cd0..3465a14 100644 --- a/src/frontend.lua +++ b/src/frontend.lua @@ -1,8 +1,9 @@ local ctx = ({ ... })[1] local storage = ctx.storage - +local speaker = ctx.speakerLib local basalt = ctx.basalt +-- Not needed becvause basalt has such a thing already but whatever local function searchObject(base, id) local obj = base:getObject(id) if not obj then @@ -21,41 +22,6 @@ -- Button functions local base ---[[ -local bubbles = {} -basalt.setVariable("openHelpDialog", function(self) - ctx.logger:info("Opening help dialog") - local nW = base:getSize() - local nX, nY = self:getPosition() - local nSubW = self:getSize() - - - local bubble = base:addLayout(fs.combine(ctx.path.page, "bubble.xml")) - bubble = searchObject(base, "_bubble") - bubbles[#bubbles + 1] = bubble - bubble.name = "_bubble" .. #bubble - - bubble:setSize(10, 2) - local nBSubW = bubble:getSize() - bubble - :setPosition(nX + ((nX > nW / 2) and (-(nBSubW + 1)) or (nSubW + 1)), nY) - :addThread("_lifetimeTask") - :start(function() - for _ = 1, 4 do - sleep(1) - end - base:removeObject(bubble) - for i, obj in pairs(bubbles) do - if obj == bubble then - table.remove(bubbles, i) - break - end - end - end - ) -end) -]] - local function smartLoadLayout(frame, path) local pathLUA = fs.combine(ctx.path.page, path..".lua") local pathXML = fs.combine(ctx.path.page, path..".xml") @@ -84,7 +50,7 @@ base = basalt.createFrame() --- Button events +-- Catalog refresh local tItems = {} local page = 1 local function updateCatalog() @@ -137,6 +103,7 @@ name:setForeground(colors[item.color]) end + -- Price local button = searchObject(widget, "_price") local _, h = button:getSize() local btnLabel = item.price .. "kst" @@ -144,6 +111,15 @@ :setText(btnLabel) :setSize(#btnLabel + 2, h) + -- Frame clicking + widget:onClick(function() + local info = searchObject(base, "_importantMSG") + if info then + info:setText("Pay to "..item.metaname.."@"..ctx.config.name..".kst for a purchase!") + speaker:play("click") + end + end) + widget:setPosition(nScreenX,nScreenY) -- Next Position nScreenX = nScreenX+nW @@ -155,9 +131,11 @@ end end +--Button events basalt.setVariable("navBack", function() local body = searchObject(base, "_body") if page > 1 then + speaker:play("click") local _,nH = body:getSize() local _,nY = body:getOffset() body:setOffset(0,nY-nH+1) @@ -175,6 +153,7 @@ local _,nY = body:getOffset() if nY > nMax then return end + speaker:play("click") body:setOffset(0,nY+nH-1) page = page+1 lblPage = searchObject(base, "_curPage") @@ -184,11 +163,16 @@ end) -- Create frame +ctx.logger:debug("Attatching monitor and loading layout.") +local mon = peripheral.wrap(ctx.config.monSide) +mon.setTextScale(0.5) + base:setMonitor(ctx.config.monSide) :setTheme(ctx.theme) smartLoadLayout(base, "index") -- Adjust theme +ctx.logger:debug("Adjust theme by config file") local title = searchObject(base, "_title") local nW,nX = 51,20 if title then @@ -254,7 +238,7 @@ -- Event basalt.onEvent(function(event) if event == "kstUpdateProducts" then - ctx.logger:debug("Received event: kstUpdateProducts. Will refresh cache") + ctx.logger:debug("Received event: kstUpdateProducts; Refresh cache") storage.refreshStorage(true) os.queueEvent("kristify:storageRefreshed") -- Sort diff --git a/src/init.lua b/src/init.lua index 3ab555f..5199771 100644 --- a/src/init.lua +++ b/src/init.lua @@ -115,6 +115,7 @@ ctx.utils = require("utils") ctx.webhooks = require("webhook") ctx.speakerLib = require("speaker") + ctx.speakerLib.config = ctx.config ctx.logger.debug("Loading in inv lib") ctx.logger.debug("Configured storage: " .. textutils.serialize(ctx.config.storage)) diff --git a/src/speaker.lua b/src/speaker.lua index 6af3db3..c7086cf 100644 --- a/src/speaker.lua +++ b/src/speaker.lua @@ -8,7 +8,7 @@ end ---Plays sounds! ----@param event string The event that happend +---@param event string The event that happend function speaker:play(event) if self.config.sounds[event] == nil then return @@ -23,8 +23,8 @@ end for _, sp in ipairs(self.config.speakers) do - pcall(peripheral.call(sp, "playSound", self.config.sounds[event])) + pcall(peripheral.call(sp, "playSound", self.config.sounds[event], self.config.sounds.volume or 1)) end end -return speaker +return speaker \ No newline at end of file