mirror of
https://github.com/kepler155c/opus
synced 2025-02-03 02:49:09 +00:00
mouse up events
This commit is contained in:
parent
e6ee432997
commit
10cd1509fb
@ -75,6 +75,7 @@ local Manager = class()
|
||||
function Manager:init(args)
|
||||
local control = false
|
||||
local shift = false
|
||||
local mouseDragged = false
|
||||
local pages = { }
|
||||
|
||||
Event.addHandler('term_resize', function(h, side)
|
||||
@ -117,11 +118,25 @@ function Manager:init(args)
|
||||
|
||||
Event.addHandler('mouse_click', function(h, button, x, y)
|
||||
|
||||
if button == 1 and shift and control then -- hack
|
||||
mouseDragged = false
|
||||
if button == 1 and shift and control then -- debug hack
|
||||
local event = self:pointToChild(self.target, x, y)
|
||||
multishell.openTab({ path = 'sys/apps/Lua.lua', args = { event.element }, focused = true })
|
||||
|
||||
elseif self.currentPage then
|
||||
if not self.currentPage.parent.device.side then
|
||||
local event = self:pointToChild(self.target, x, y)
|
||||
if event.element.focus then
|
||||
self.currentPage:setFocus(event.element)
|
||||
self.currentPage:sync()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.addHandler('mouse_up', function(h, button, x, y)
|
||||
|
||||
if self.currentPage and not mouseDragged then
|
||||
if not self.currentPage.parent.device.side then
|
||||
self:click(button, x, y)
|
||||
end
|
||||
@ -130,6 +145,7 @@ function Manager:init(args)
|
||||
|
||||
Event.addHandler('mouse_drag', function(h, button, x, y)
|
||||
|
||||
mouseDragged = true
|
||||
if self.target then
|
||||
local event = self:pointToChild(self.target, x, y)
|
||||
|
||||
@ -3334,7 +3350,7 @@ function UI.NftImage:setImage(image)
|
||||
end
|
||||
|
||||
UI:loadTheme('usr/config/ui.theme')
|
||||
if os.getVersion() >= 1.79 then
|
||||
if os.getVersion and os.getVersion() >= 1.79 then
|
||||
UI:loadTheme('sys/etc/ext.theme')
|
||||
end
|
||||
|
||||
|
@ -11,7 +11,7 @@ UI:configure('Turtles', ...)
|
||||
local options = {
|
||||
turtle = { arg = 'i', type = 'number', value = -1,
|
||||
desc = 'Turtle ID' },
|
||||
tab = { arg = 's', type = 'string', value = 'inventory',
|
||||
tab = { arg = 's', type = 'string', value = 'turtles',
|
||||
desc = 'Selected tab to display' },
|
||||
help = { arg = 'h', type = 'flag', value = false,
|
||||
desc = 'Displays the options' },
|
||||
@ -22,6 +22,7 @@ local SYS_SCRIPTS_PATH = 'sys/etc/scripts'
|
||||
|
||||
local nullTerm = Terminal.getNullTerm(term.current())
|
||||
local turtles = { }
|
||||
local socket
|
||||
local policies = {
|
||||
{ label = 'none' },
|
||||
{ label = 'digOnly' },
|
||||
@ -37,6 +38,67 @@ local itemInfoDB = TableDB({
|
||||
itemInfoDB:load()
|
||||
|
||||
local page = UI.Page {
|
||||
--[[
|
||||
policy = UI.Chooser {
|
||||
x = 2, y = 8,
|
||||
choices = {
|
||||
{ name = ' None ', value = 'none' },
|
||||
{ name = ' Safe ', value = 'turtleSafe' },
|
||||
},
|
||||
},
|
||||
]]
|
||||
coords = UI.Window {
|
||||
x = 2, y = 2, height = 3, rex = -2,
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
x = 1, y = 5, rey = -2,
|
||||
scripts = UI.Grid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
turtles = UI.Grid {
|
||||
tabTitle = 'Sel',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
inventory = UI.Grid {
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'qty', width = 2 },
|
||||
{ heading = 'Inventory', key = 'id', width = UI.term.width - 7 },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
},
|
||||
policy = UI.Grid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
action = UI.Window {
|
||||
tabTitle = 'Act',
|
||||
moveUp = UI.Button {
|
||||
x = 5, y = 2,
|
||||
text = '/\\',
|
||||
@ -67,63 +129,6 @@ local page = UI.Page {
|
||||
text = '->',
|
||||
fn = 'turtle.turnRight',
|
||||
},
|
||||
--[[
|
||||
policy = UI.Chooser {
|
||||
x = 2, y = 8,
|
||||
choices = {
|
||||
{ name = ' None ', value = 'none' },
|
||||
{ name = ' Safe ', value = 'turtleSafe' },
|
||||
},
|
||||
},
|
||||
]]
|
||||
coords = UI.Window {
|
||||
x = 14, y = 2, height = 5, rex = -2,
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
x = 1, y = 8, rey = -2,
|
||||
scripts = UI.Grid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
turtles = UI.Grid {
|
||||
tabTitle = 'Sel',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
inventory = UI.Grid {
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'qty', width = 2 },
|
||||
{ heading = 'Inventory', key = 'id', width = UI.term.width - 5 },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
},
|
||||
policy = UI.Grid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar(),
|
||||
@ -139,18 +144,18 @@ function page:enable(turtle)
|
||||
end
|
||||
|
||||
function page:runFunction(script, nowrap)
|
||||
|
||||
local socket = Socket.connect(self.turtle.id, 161)
|
||||
if not socket then
|
||||
socket = Socket.connect(self.turtle.id, 161)
|
||||
if not socket then
|
||||
self.notification:error('Unable to connect')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if not nowrap then
|
||||
script = 'turtle.run(' .. script .. ')'
|
||||
end
|
||||
socket:write({ type = 'script', args = script })
|
||||
socket:close()
|
||||
end
|
||||
|
||||
function page:runScript(scriptName)
|
||||
@ -167,8 +172,12 @@ function page.coords:draw()
|
||||
if t then
|
||||
self:clear()
|
||||
self:setCursorPos(1, 1)
|
||||
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\nFuel: %s\n',
|
||||
t.coordSystem, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
|
||||
local ind = 'GPS'
|
||||
if t.coordSystem ~= 'GPS' then
|
||||
ind = 'REL'
|
||||
end
|
||||
self:print(string.format('%s : %d,%d,%d\nFuel: %s\n',
|
||||
ind, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
|
||||
end
|
||||
end
|
||||
|
||||
@ -274,6 +283,10 @@ end
|
||||
function page.tabs.turtles:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
page.turtle = event.selected
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
|
@ -513,6 +513,8 @@ end
|
||||
|
||||
draw()
|
||||
|
||||
local lastClicked
|
||||
|
||||
while true do
|
||||
|
||||
-- Get the event
|
||||
@ -552,6 +554,7 @@ while true do
|
||||
|
||||
elseif sEvent == "mouse_click" then
|
||||
local button, x, y = tEventData[1], tEventData[2], tEventData[3]
|
||||
lastClicked = nil
|
||||
if y == 1 and os.locked then
|
||||
-- ignore
|
||||
elseif y == 1 then
|
||||
@ -575,6 +578,13 @@ while true do
|
||||
end
|
||||
elseif currentTab then
|
||||
-- Passthrough to current process
|
||||
lastClicked = currentTab
|
||||
resumeTab(currentTab, sEvent, { button, x, y-1 })
|
||||
end
|
||||
|
||||
elseif sEvent == "mouse_up" then
|
||||
if currentTab and lastClicked == currentTab then
|
||||
local button, x, y = tEventData[1], tEventData[2], tEventData[3]
|
||||
resumeTab(currentTab, sEvent, { button, x, y-1 })
|
||||
end
|
||||
|
||||
|
@ -52,7 +52,8 @@ ct.clear()
|
||||
ct.setCursorPos(1, 1)
|
||||
|
||||
local filter = Util.transpose({
|
||||
'char', 'paste', 'key', 'key_up', 'mouse_scroll', 'mouse_click', 'mouse_drag',
|
||||
'char', 'paste', 'key', 'key_up',
|
||||
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
|
||||
})
|
||||
|
||||
while true do
|
||||
|
@ -54,6 +54,11 @@ end)
|
||||
ct.clear()
|
||||
ct.setCursorPos(1, 1)
|
||||
|
||||
local filter = Util.transpose({
|
||||
'char', 'paste', 'key', 'key_up',
|
||||
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
|
||||
})
|
||||
|
||||
while true do
|
||||
local e = { process:pullEvent() }
|
||||
local event = e[1]
|
||||
@ -66,14 +71,7 @@ while true do
|
||||
break
|
||||
end
|
||||
|
||||
if event == 'char' or
|
||||
event == 'paste' or
|
||||
event == 'key' or
|
||||
event == 'key_up' or
|
||||
event == 'mouse_scroll' or
|
||||
event == 'mouse_click' or
|
||||
event == 'mouse_drag' then
|
||||
|
||||
if filter[event] then
|
||||
socket:write({
|
||||
type = 'shellRemote',
|
||||
event = e,
|
||||
|
Loading…
Reference in New Issue
Block a user