Small Update
- Fixed MonitorFrame - Added MonitorFrame Docs
This commit is contained in:
@@ -15,7 +15,7 @@ local version = "1.7.0"
|
|||||||
|
|
||||||
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
||||||
|
|
||||||
local activeKey, frames, monFrames, monGroups, variables, schedules = {}, {}, {}, {}, {}, {}
|
local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {}
|
||||||
local mainFrame, activeFrame, focusedObject, updaterActive
|
local mainFrame, activeFrame, focusedObject, updaterActive
|
||||||
|
|
||||||
local basalt = {}
|
local basalt = {}
|
||||||
@@ -191,10 +191,6 @@ local function drawFrames()
|
|||||||
v:render()
|
v:render()
|
||||||
v:updateTerm()
|
v:updateTerm()
|
||||||
end
|
end
|
||||||
for _,v in pairs(monGroups)do
|
|
||||||
v[1]:render()
|
|
||||||
v[1]:updateTerm()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local stopped, moveX, moveY = nil, nil, nil
|
local stopped, moveX, moveY = nil, nil, nil
|
||||||
@@ -270,13 +266,9 @@ local function basaltUpdateEvent(event, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if(event == "monitor_touch") then
|
if(event == "monitor_touch") then
|
||||||
if(monFrames[a[2]]~=nil)then
|
for k,v in pairs(monFrames)do
|
||||||
monFrames[a[2]]:mouseHandler(1, a[2], a[3], true)
|
if(v:mouseHandler(1, a[2], a[3], true, a[1]))then
|
||||||
activeFrame = monFrames[a[2]]
|
activeFrame = v
|
||||||
end
|
|
||||||
if(count(monGroups)>0)then
|
|
||||||
for k,v in pairs(monGroups)do
|
|
||||||
v[1]:mouseHandler(1, a[2], a[3], true, a[1])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
handleSchedules(event, ...)
|
handleSchedules(event, ...)
|
||||||
@@ -319,11 +311,26 @@ local function basaltUpdateEvent(event, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function createFrame(name)
|
||||||
|
for _, v in pairs(frames) do
|
||||||
|
if (v:getName() == name) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local newFrame = _OBJECTS["BaseFrame"](name, bInstance)
|
||||||
|
newFrame:init()
|
||||||
|
newFrame:load()
|
||||||
|
newFrame:draw()
|
||||||
|
table.insert(frames, newFrame)
|
||||||
|
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
|
||||||
|
newFrame:show()
|
||||||
|
end
|
||||||
|
return newFrame
|
||||||
|
end
|
||||||
|
|
||||||
basalt = {
|
basalt = {
|
||||||
logging = false,
|
logging = false,
|
||||||
dynamicValueEvents = false,
|
dynamicValueEvents = false,
|
||||||
setTheme = setTheme,
|
|
||||||
getTheme = getTheme,
|
|
||||||
drawFrames = drawFrames,
|
drawFrames = drawFrames,
|
||||||
log = log,
|
log = log,
|
||||||
getVersion = function()
|
getVersion = function()
|
||||||
@@ -449,20 +456,20 @@ basalt = {
|
|||||||
|
|
||||||
schedule = schedule,
|
schedule = schedule,
|
||||||
|
|
||||||
createFrame = function(name)
|
addFrame = createFrame,
|
||||||
|
createFrame = createFrame,
|
||||||
|
|
||||||
|
addMonitor = function(name)
|
||||||
for _, v in pairs(frames) do
|
for _, v in pairs(frames) do
|
||||||
if (v:getName() == name) then
|
if (v:getName() == name) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local newFrame = _OBJECTS["BaseFrame"](name, bInstance)
|
local newFrame = _OBJECTS["MonitorFrame"](name, bInstance)
|
||||||
newFrame:init()
|
newFrame:init()
|
||||||
newFrame:load()
|
newFrame:load()
|
||||||
newFrame:draw()
|
newFrame:draw()
|
||||||
table.insert(frames, newFrame)
|
table.insert(monFrames, newFrame)
|
||||||
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
|
|
||||||
newFrame:show()
|
|
||||||
end
|
|
||||||
return newFrame
|
return newFrame
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
@@ -142,12 +142,18 @@ return function(name, basalt)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
updateTerm = function(self)
|
updateTerm = function(self)
|
||||||
basaltDraw.update()
|
if(basaltDraw~=nil)then
|
||||||
|
basaltDraw.update()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
setTerm = function(self, newTerm)
|
setTerm = function(self, newTerm)
|
||||||
termObject = newTerm
|
termObject = newTerm
|
||||||
basaltDraw = drawSystem(termObject)
|
if(newTerm==nil)then
|
||||||
|
basaltDraw = nil
|
||||||
|
else
|
||||||
|
basaltDraw = drawSystem(termObject)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -187,6 +193,14 @@ return function(name, basalt)
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k,v in pairs({mouse_click={"mouseHandler", true},mouse_up={"mouseUpHandler", false},mouse_drag={"dragHandler", false},mouse_scroll={"scrollHandler", true},mouse_hover={"hoverHandler", false}})do
|
||||||
|
object[v[1]] = function(self, btn, x, y, ...)
|
||||||
|
if(base[v[1]](self, btn, x, y, ...))then
|
||||||
|
basalt.setActiveFrame(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for k,v in pairs({"drawBackgroundBox", "drawForegroundBox", "drawTextBox"})do
|
for k,v in pairs({"drawBackgroundBox", "drawForegroundBox", "drawTextBox"})do
|
||||||
object[v] = function(self, x, y, width, height, symbol)
|
object[v] = function(self, x, y, width, height, symbol)
|
||||||
local obx, oby = self:getPosition()
|
local obx, oby = self:getPosition()
|
||||||
|
|||||||
@@ -351,8 +351,8 @@ return function(name, basalt)
|
|||||||
if(v[2])then
|
if(v[2])then
|
||||||
self:removeFocusedObject()
|
self:removeFocusedObject()
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ return function(name, basalt)
|
|||||||
return dropdownW, dropdownH
|
return dropdownW, dropdownH
|
||||||
end,
|
end,
|
||||||
|
|
||||||
mouseHandler = function(self, button, x, y)
|
mouseHandler = function(self, button, x, y, isMon)
|
||||||
if (isOpened) then
|
if (isOpened) then
|
||||||
local obx, oby = self:getAbsolutePosition()
|
local obx, oby = self:getAbsolutePosition()
|
||||||
if(button==1)then
|
if(button==1)then
|
||||||
@@ -69,6 +69,12 @@ return function(name, basalt)
|
|||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
local val = self:sendEvent("mouse_click", self, "mouse_click", dir, x, y)
|
local val = self:sendEvent("mouse_click", self, "mouse_click", dir, x, y)
|
||||||
if(val==false)then return val end
|
if(val==false)then return val end
|
||||||
|
if(isMon)then
|
||||||
|
basalt.schedule(function()
|
||||||
|
sleep(0.1)
|
||||||
|
self:mouseUpHandler(button, x, y)
|
||||||
|
end)()
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
|
local basaltMon = require("basaltMon")
|
||||||
local max,min,sub,rep = math.max,math.min,string.sub,string.rep
|
local max,min,sub,rep = math.max,math.min,string.sub,string.rep
|
||||||
|
|
||||||
|
|
||||||
return function(name, basalt)
|
return function(name, basalt)
|
||||||
local base = basalt.getObject("BaseFrame")(name, basalt)
|
local base = basalt.getObject("BaseFrame")(name, basalt)
|
||||||
local objectType = "MonitorFrame"
|
local objectType = "MonitorFrame"
|
||||||
|
|
||||||
base:hide()
|
base:setTerm(nil)
|
||||||
|
local isMonitorGroup = false
|
||||||
|
local monGroup
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
|
|
||||||
getType = function()
|
getType = function()
|
||||||
return objectType
|
return objectType
|
||||||
end,
|
end,
|
||||||
@@ -19,22 +24,58 @@ return function(name, basalt)
|
|||||||
return base
|
return base
|
||||||
end,
|
end,
|
||||||
|
|
||||||
setMonitor = function(self, name)
|
setMonitor = function(self, newMon)
|
||||||
local mon = peripheral.wrap(name)
|
if(type(newMon)=="string")then
|
||||||
if(mon~=nil)then
|
local mon = peripheral.wrap(newMon)
|
||||||
self:setTerm(mon)
|
if(mon~=nil)then
|
||||||
|
self:setTerm(mon)
|
||||||
|
end
|
||||||
|
elseif(type(newMon)=="table")then
|
||||||
|
self:setTerm(newMon)
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
setMonitorGroup = function(self, monGrp)
|
||||||
|
monGroup = basaltMon(monGrp)
|
||||||
|
self:setTerm(monGroup)
|
||||||
|
isMonitorGroup = true
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
render = function(self)
|
||||||
|
if(self:getTerm()~=nil)then
|
||||||
|
base.render(self)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
show = function(self)
|
show = function(self)
|
||||||
if(basalt.getTerm()~=self:getTerm())then
|
base:getBase().show(self)
|
||||||
base.show()
|
basalt.setActiveFrame(self)
|
||||||
|
for k,v in pairs(colors)do
|
||||||
|
if(type(v)=="number")then
|
||||||
|
termObject.setPaletteColor(v, colors.packRGB(term.nativePaletteColor((v))))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for k,v in pairs(colorTheme)do
|
||||||
|
if(type(v)=="number")then
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
|
||||||
|
else
|
||||||
|
local r,g,b = table.unpack(v)
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object.mouseHandler = function(self, btn, x, y, isMon, monitor, ...)
|
||||||
|
if(isMonitorGroup)then
|
||||||
|
x, y = monGroup.calculateClick(monitor, x, y)
|
||||||
|
end
|
||||||
|
base.mouseHandler(self, btn, x, y, isMon, monitor, ...)
|
||||||
|
end
|
||||||
|
|
||||||
object.__index = object
|
object.__index = object
|
||||||
return setmetatable(object, base)
|
return setmetatable(object, base)
|
||||||
end
|
end
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
- [ChangeableObject](objects/ChangeableObject.md)
|
- [ChangeableObject](objects/ChangeableObject.md)
|
||||||
- [Container](objects/Container.md)
|
- [Container](objects/Container.md)
|
||||||
- [BaseFrame](objects/BaseFrame.md)
|
- [BaseFrame](objects/BaseFrame.md)
|
||||||
|
- [BaseFrame](objects/MonitorFrame.md)
|
||||||
- [Frame](objects/Frame.md)
|
- [Frame](objects/Frame.md)
|
||||||
- [Flexbox](objects/Flexbox.md)
|
- [Flexbox](objects/Flexbox.md)
|
||||||
- [MovableFrame](objects/MovableFrame.md)
|
- [MovableFrame](objects/MovableFrame.md)
|
||||||
|
|||||||
10
docs/objects/MonitorFrame.md
Normal file
10
docs/objects/MonitorFrame.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
MonitorFrame is a subclass of the BaseFrame class. It is specifically designed for use with in-game monitors, allowing you to display content on monitors and manage multiple monitor groups. MonitorFrame inherits all methods from BaseFrame and provides additional functionality for working with in-game monitors.
|
||||||
|
|
||||||
|
To create a MonitorFrame, you can use the basalt.addMonitor() function.
|
||||||
|
|
||||||
|
In addition to the Object, VisualObject, Container, and BaseFrame methods, MonitorFrame also has the following methods:
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
|[setMonitor](objects/MonitorFrame/setMonitor.md)|Sets the in-game monitor to display the MonitorFrame content
|
||||||
|
|[setMonitorGroup](objects/MonitorFrame/setMonitorGroup.md)|Sets the monitor group for managing multiple monitors
|
||||||
38
docs/objects/MonitorFrame/setMonitor.md
Normal file
38
docs/objects/MonitorFrame/setMonitor.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
## setMonitor
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
Associates the MonitorFrame with an in-game monitor. The content of the MonitorFrame will be displayed on the specified monitor.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
1. `string|table` the monitor object or name
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
1. `object` The object in use
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
* Creates a MonitorFrame and associates it with a monitor:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local basalt = require("basalt")
|
||||||
|
|
||||||
|
local monitor = peripheral.wrap("top") -- Assuming a monitor is on the top side
|
||||||
|
local monitorFrame = basalt.addMonitor()
|
||||||
|
monitorFrame:setMonitor(monitor)
|
||||||
|
|
||||||
|
basalt.autoUpdate()
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local basalt = require("basalt")
|
||||||
|
|
||||||
|
local monitorFrame = basalt.addMonitor()
|
||||||
|
monitorFrame:setMonitor("top")
|
||||||
|
|
||||||
|
basalt.autoUpdate()
|
||||||
|
```
|
||||||
41
docs/objects/MonitorFrame/setMonitorGroup.md
Normal file
41
docs/objects/MonitorFrame/setMonitorGroup.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
## setMonitorGroup
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
Sets the monitor group for the MonitorFrame. This can be used to combine multiple in-game monitors into a single large monitor. The content of the MonitorFrame will be displayed across all monitors in the group.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
1. `table` A table containing monitor names connected to the computer, organized by their position in the group.
|
||||||
|
|
||||||
|
Table Layout:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
[y1] = {"x1", "x2", "x3"}
|
||||||
|
[y2] = {"x1", "x2", "x3"}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
1. `object` The object in use
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
* Creates a MonitorFrame and combines two monitors into a single large monitor:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local basalt = require("basalt")
|
||||||
|
|
||||||
|
local monitorFrame = basalt.addMonitor()
|
||||||
|
|
||||||
|
local monitorGroup = {
|
||||||
|
[1] = {"monitor_1", "monitor_2"},
|
||||||
|
[2] = {"monitor_3", "monitor_4"}
|
||||||
|
}
|
||||||
|
|
||||||
|
monitorFrame:setMonitorGroup(monitorGroup)
|
||||||
|
|
||||||
|
basalt.autoUpdate()
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user