From 0d13af3827797df37ba30a6cf7372a2ec40de65d Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Tue, 4 Dec 2018 01:33:17 -0500 Subject: [PATCH] milo: speaker setup --- milo/core/listing.lua | 2 +- milo/plugins/speakerView.lua | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 milo/plugins/speakerView.lua diff --git a/milo/core/listing.lua b/milo/core/listing.lua index 3e22299..5e01adb 100644 --- a/milo/core/listing.lua +++ b/milo/core/listing.lua @@ -178,7 +178,7 @@ function page:eject(amount) item.count = request.current - request.count if request.count + request.craft > 0 then self.grid:draw() - Sound.play('ui.button.click', .3) + Sound.play('ui.button.click') return true end end diff --git a/milo/plugins/speakerView.lua b/milo/plugins/speakerView.lua new file mode 100644 index 0000000..e51978c --- /dev/null +++ b/milo/plugins/speakerView.lua @@ -0,0 +1,73 @@ +local Milo = require('milo') +local Sound = require('sound') +local UI = require('ui') + +local colors = _G.colors +local context = Milo:getContext() +local device = _G.device + +local speakerNode = context.storage:getSingleNode('speaker') +if speakerNode then + Sound.setVolume(speakerNode.volume) +end + +local wizardPage = UI.Window { + title = 'Speaker', + index = 2, + backgroundColor = colors.cyan, + [1] = UI.Text { + x = 2, y = 2, + textColor = colors.yellow, + value = 'Set the volume for sound effects', + }, + form = UI.Form { + x = 2, ex = -2, y = 3, ey = -2, + manualControls = true, + volume = UI.TextEntry { + formLabel = 'Volume', formKey = 'volume', + width = 5, limit = 3, + validate = 'numeric', + help = 'A value from 0 (mute) to 1 (loud)', + }, + testSound = UI.Button { + x = 15, y = 2, + text = 'Test', event = 'test_sound', + help = 'Test sound volume', + }, + }, +} + +function wizardPage:setNode(node) + self.node = node + self.form:setValues(node) +end + +function wizardPage:validate() + if self.form:save() then + Sound.setVolume(self.node.volume) + return true + end +end + +function wizardPage:isValidType(node) + local m = device[node.name] + return m and m.type == 'speaker' and { + name = 'Speaker', + value = 'speaker', + category = 'custom', + help = 'Sound effects', + } +end + +function wizardPage:isValidFor(node) + return node.mtype == 'speaker' +end + +function wizardPage:eventHandler(event) + if event.type == 'test_sound' then + local vol = tonumber(self.form.volume.value) + Sound.play('entity.item.pickup', vol) + end +end + +UI:getPage('nodeWizard').wizard:add({ speaker = wizardPage })