properly handle empty text entry fields (including transformations)

This commit is contained in:
kepler155c@gmail.com
2019-11-13 14:24:54 -07:00
parent 7e520744a2
commit 64ec8c82d3
13 changed files with 64 additions and 51 deletions

View File

@@ -5,13 +5,13 @@ local Util = require('opus.util')
local peripheral = _G.peripheral
if not peripheral.find('speaker') then
error('No speaker attached')
error('No speaker attached')
end
local rawSounds = Util.readLines('packages/games/etc/sounds.txt') or error('Unable to read sounds file')
local sounds = { }
for _, s in pairs(rawSounds) do
table.insert(sounds, { name = s })
table.insert(sounds, { name = s })
end
UI:configure('SoundPlayer', ...)
@@ -25,21 +25,21 @@ local page = UI.Page {
x = 10, y = 2, ex = -3,
limit = 32,
},
grid = UI.ScrollingGrid {
grid = UI.ScrollingGrid {
y = 4,
columns = {
{ heading = 'Name', key = 'name' },
},
values = sounds,
},
columns = {
{ heading = 'Name', key = 'name' },
},
values = sounds,
},
}
function page:eventHandler(event)
if event.type == 'grid_select' then
Sound.play(event.selected.name)
if event.type == 'grid_select' then
Sound.play(event.selected.name)
elseif event.type == 'text_change' then
if #event.text == 0 then
if not event.text then
self.grid.values = sounds
else
self.grid.values = { }
@@ -51,12 +51,12 @@ function page:eventHandler(event)
end
self.grid:update()
self.grid:setIndex(1)
self.grid:draw()
self.grid:draw()
else
return UI.Page.eventHandler(self, event)
end
return true
else
return UI.Page.eventHandler(self, event)
end
return true
end
UI:setPage(page)