Ui enhancements 2.0 (#31)

* canvas overhaul

* minor tweaks

* list mode for overview

* bugfixes + tweaks for editor 2.0

* minor tweaks

* more editor work

* refactor + new transitions

* use layout() where appropriate and cleanup

* mouse triple click + textEntry scroll ind

* cleanup

* cleanup + theme editor

* color rework + cleanup

* changes for deprecated ui methods

* can now use named colors
This commit was merged in pull request #31.
This commit is contained in:
kepler155c
2020-04-21 22:40:59 -06:00
committed by GitHub
parent cdd0b6c4d2
commit 7224d441ca
92 changed files with 2471 additions and 1773 deletions

View File

@@ -4,36 +4,34 @@ local Sound = require('opus.sound')
local UI = require('opus.ui')
local Util = require('opus.util')
local colors = _G.colors
UI.Notification = class(UI.Window)
UI.Notification.defaults = {
UIElement = 'Notification',
backgroundColor = colors.gray,
backgroundColor = 'gray',
closeInd = UI.extChars and '\215' or '*',
height = 3,
timeout = 3,
anchor = 'bottom',
}
function UI.Notification:draw()
function UI.Notification.draw()
end
function UI.Notification:enable()
function UI.Notification.enable()
end
function UI.Notification:error(value, timeout)
self.backgroundColor = colors.red
self.backgroundColor = 'red'
Sound.play('entity.villager.no', .5)
self:display(value, timeout)
end
function UI.Notification:info(value, timeout)
self.backgroundColor = colors.lightGray
self.backgroundColor = 'lightGray'
self:display(value, timeout)
end
function UI.Notification:success(value, timeout)
self.backgroundColor = colors.green
self.backgroundColor = 'green'
self:display(value, timeout)
end
@@ -43,32 +41,34 @@ function UI.Notification:cancel()
self.timer = nil
end
if self.canvas then
self.enabled = false
self.canvas:removeLayer()
self.canvas = nil
end
self:disable()
end
function UI.Notification:display(value, timeout)
self:cancel()
self.enabled = true
local lines = Util.wordWrap(value, self.width - 3)
self.enabled = true
self.height = #lines
if self.anchor == 'bottom' then
self.y = self.parent.height - self.height + 1
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
self:addTransition('expandUp', { ticks = self.height })
else
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
self.y = 1
end
self.canvas:setVisible(true)
self:reposition(self.x, self.y, self.width, self.height)
self:raise()
self:clear()
for k,v in pairs(lines) do
self:write(2, k, v)
end
self:write(self.width, 1, self.closeInd)
if self.timer then
Event.off(self.timer)
self.timer = nil
end
timeout = timeout or self.timeout
if timeout > 0 then
@@ -77,7 +77,6 @@ function UI.Notification:display(value, timeout)
self:sync()
end)
else
self:write(self.width, 1, self.closeInd)
self:sync()
end
end
@@ -92,7 +91,7 @@ function UI.Notification:eventHandler(event)
end
function UI.Notification.example()
return UI.ActiveLayer {
return UI.Window {
notify1 = UI.Notification {
anchor = 'top',
},
@@ -111,7 +110,9 @@ function UI.Notification.example()
if event.type == 'test_success' then
self.notify1:success('Example text')
elseif event.type == 'test_error' then
self.notify2:error('Example text', 0)
self.notify2:error([[Example text test test
test test test test test
test test test]], 0)
end
end,
}