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 activeKey, frames, monFrames, monGroups, variables, schedules = {}, {}, {}, {}, {}, {}
|
||||
local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {}
|
||||
local mainFrame, activeFrame, focusedObject, updaterActive
|
||||
|
||||
local basalt = {}
|
||||
@@ -191,10 +191,6 @@ local function drawFrames()
|
||||
v:render()
|
||||
v:updateTerm()
|
||||
end
|
||||
for _,v in pairs(monGroups)do
|
||||
v[1]:render()
|
||||
v[1]:updateTerm()
|
||||
end
|
||||
end
|
||||
|
||||
local stopped, moveX, moveY = nil, nil, nil
|
||||
@@ -270,13 +266,9 @@ local function basaltUpdateEvent(event, ...)
|
||||
end
|
||||
|
||||
if(event == "monitor_touch") then
|
||||
if(monFrames[a[2]]~=nil)then
|
||||
monFrames[a[2]]:mouseHandler(1, a[2], a[3], true)
|
||||
activeFrame = monFrames[a[2]]
|
||||
end
|
||||
if(count(monGroups)>0)then
|
||||
for k,v in pairs(monGroups)do
|
||||
v[1]:mouseHandler(1, a[2], a[3], true, a[1])
|
||||
for k,v in pairs(monFrames)do
|
||||
if(v:mouseHandler(1, a[2], a[3], true, a[1]))then
|
||||
activeFrame = v
|
||||
end
|
||||
end
|
||||
handleSchedules(event, ...)
|
||||
@@ -319,11 +311,26 @@ local function basaltUpdateEvent(event, ...)
|
||||
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 = {
|
||||
logging = false,
|
||||
dynamicValueEvents = false,
|
||||
setTheme = setTheme,
|
||||
getTheme = getTheme,
|
||||
drawFrames = drawFrames,
|
||||
log = log,
|
||||
getVersion = function()
|
||||
@@ -449,20 +456,20 @@ basalt = {
|
||||
|
||||
schedule = schedule,
|
||||
|
||||
createFrame = function(name)
|
||||
addFrame = createFrame,
|
||||
createFrame = createFrame,
|
||||
|
||||
addMonitor = function(name)
|
||||
for _, v in pairs(frames) do
|
||||
if (v:getName() == name) then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
local newFrame = _OBJECTS["BaseFrame"](name, bInstance)
|
||||
local newFrame = _OBJECTS["MonitorFrame"](name, bInstance)
|
||||
newFrame:init()
|
||||
newFrame:load()
|
||||
newFrame:draw()
|
||||
table.insert(frames, newFrame)
|
||||
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
|
||||
newFrame:show()
|
||||
end
|
||||
table.insert(monFrames, newFrame)
|
||||
return newFrame
|
||||
end,
|
||||
|
||||
|
||||
@@ -142,12 +142,18 @@ return function(name, basalt)
|
||||
end,
|
||||
|
||||
updateTerm = function(self)
|
||||
basaltDraw.update()
|
||||
if(basaltDraw~=nil)then
|
||||
basaltDraw.update()
|
||||
end
|
||||
end,
|
||||
|
||||
setTerm = function(self, newTerm)
|
||||
termObject = newTerm
|
||||
basaltDraw = drawSystem(termObject)
|
||||
if(newTerm==nil)then
|
||||
basaltDraw = nil
|
||||
else
|
||||
basaltDraw = drawSystem(termObject)
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -187,6 +193,14 @@ return function(name, basalt)
|
||||
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
|
||||
object[v] = function(self, x, y, width, height, symbol)
|
||||
local obx, oby = self:getPosition()
|
||||
|
||||
@@ -351,8 +351,8 @@ return function(name, basalt)
|
||||
if(v[2])then
|
||||
self:removeFocusedObject()
|
||||
end
|
||||
return true
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,7 +56,7 @@ return function(name, basalt)
|
||||
return dropdownW, dropdownH
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
mouseHandler = function(self, button, x, y, isMon)
|
||||
if (isOpened) then
|
||||
local obx, oby = self:getAbsolutePosition()
|
||||
if(button==1)then
|
||||
@@ -69,6 +69,12 @@ return function(name, basalt)
|
||||
self:updateDraw()
|
||||
local val = self:sendEvent("mouse_click", self, "mouse_click", dir, x, y)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
local basaltMon = require("basaltMon")
|
||||
local max,min,sub,rep = math.max,math.min,string.sub,string.rep
|
||||
|
||||
|
||||
return function(name, basalt)
|
||||
local base = basalt.getObject("BaseFrame")(name, basalt)
|
||||
local objectType = "MonitorFrame"
|
||||
|
||||
base:hide()
|
||||
|
||||
base:setTerm(nil)
|
||||
local isMonitorGroup = false
|
||||
local monGroup
|
||||
|
||||
local object = {
|
||||
|
||||
getType = function()
|
||||
return objectType
|
||||
end,
|
||||
@@ -19,22 +24,58 @@ return function(name, basalt)
|
||||
return base
|
||||
end,
|
||||
|
||||
setMonitor = function(self, name)
|
||||
local mon = peripheral.wrap(name)
|
||||
if(mon~=nil)then
|
||||
self:setTerm(mon)
|
||||
setMonitor = function(self, newMon)
|
||||
if(type(newMon)=="string")then
|
||||
local mon = peripheral.wrap(newMon)
|
||||
if(mon~=nil)then
|
||||
self:setTerm(mon)
|
||||
end
|
||||
elseif(type(newMon)=="table")then
|
||||
self:setTerm(newMon)
|
||||
end
|
||||
return self
|
||||
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)
|
||||
if(basalt.getTerm()~=self:getTerm())then
|
||||
base.show()
|
||||
base:getBase().show(self)
|
||||
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
|
||||
return self
|
||||
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
|
||||
return setmetatable(object, base)
|
||||
end
|
||||
@@ -11,6 +11,7 @@
|
||||
- [ChangeableObject](objects/ChangeableObject.md)
|
||||
- [Container](objects/Container.md)
|
||||
- [BaseFrame](objects/BaseFrame.md)
|
||||
- [BaseFrame](objects/MonitorFrame.md)
|
||||
- [Frame](objects/Frame.md)
|
||||
- [Flexbox](objects/Flexbox.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