mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-04-04 15:12:46 +02:00
Переходим на MineOS Standalone #1
This commit is contained in:
92
Applications/Control.app/Modules/1.lua
Normal file
92
Applications/Control.app/Modules/1.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
local args = {...}
|
||||
local workspace, window, localization = args[1], args[2], args[3]
|
||||
|
||||
local GUI = require("GUI")
|
||||
local screen = require("Screen")
|
||||
local image = require("Image")
|
||||
local paths = require("Paths")
|
||||
local text = require("Text")
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local module = {}
|
||||
module.name = localization.moduleLua
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
module.onTouch = function()
|
||||
window.contentContainer:removeChildren()
|
||||
|
||||
local textBox = window.contentContainer:addChild(GUI.textBox(1, 1, window.contentContainer.width, window.contentContainer.height - 3, nil, 0x444444, localization.luaInfo, 1, 2, 1))
|
||||
textBox.scrollBarEnabled = true
|
||||
|
||||
local placeholder = localization.luaType
|
||||
local input = window.contentContainer:addChild(GUI.input(1, window.contentContainer.height - 2, window.contentContainer.width, 3, 0x2D2D2D, 0xE1E1E1, 0x666666, 0x2D2D2D, 0xE1E1E1, "", placeholder, true))
|
||||
|
||||
input.textDrawMethod = function(x, y, color, text)
|
||||
if text == placeholder then
|
||||
screen.drawText(x, y, color, text)
|
||||
else
|
||||
GUI.highlightString(x, y, input.width - 2, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text)
|
||||
end
|
||||
end
|
||||
|
||||
local function add(data, color)
|
||||
for line in data:gmatch("[^\n]+") do
|
||||
local wrappedLine = text.wrap(line, textBox.textWidth)
|
||||
for i = 1, #wrappedLine do
|
||||
table.insert(textBox.lines, color and {color = color, text = wrappedLine[i]} or wrappedLine[i])
|
||||
end
|
||||
end
|
||||
|
||||
textBox:scrollToEnd()
|
||||
-- local abc = " "; for i = 1, 30 do abc = abc .. "p " end; print(abc)
|
||||
end
|
||||
|
||||
input.historyEnabled = true
|
||||
|
||||
input.onInputFinished = function()
|
||||
if input.text:len() > 0 then
|
||||
local oldPrint = print
|
||||
|
||||
print = function(...)
|
||||
local args = {...}
|
||||
for i = 1, #args do
|
||||
if type(args[i]) == "table" then
|
||||
args[i] = text.serialize(args[i], true, 2, false, 2)
|
||||
else
|
||||
args[i] = tostring(args[i])
|
||||
end
|
||||
end
|
||||
add(table.concat(args, " "))
|
||||
end
|
||||
|
||||
add("> " .. input.text, 0xAAAAAA)
|
||||
|
||||
if input.text:match("^%=") then
|
||||
input.text = "return " .. unicode.sub(input.text, 2, -1)
|
||||
end
|
||||
|
||||
local result, reason = load(input.text)
|
||||
if result then
|
||||
local data = {xpcall(result, debug.traceback)}
|
||||
if data[1] then
|
||||
print(table.unpack(data, 2))
|
||||
else
|
||||
add(tostring(data[2]), 0x880000)
|
||||
end
|
||||
else
|
||||
add(tostring(reason), 0x880000)
|
||||
end
|
||||
|
||||
print = oldPrint
|
||||
|
||||
input.text = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
return module
|
||||
104
Applications/Control.app/Modules/2.lua
Normal file
104
Applications/Control.app/Modules/2.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
local args = {...}
|
||||
local workspace, window, localization = args[1], args[2], args[3]
|
||||
|
||||
local GUI = require("GUI")
|
||||
local screen = require("Screen")
|
||||
local image = require("Image")
|
||||
local paths = require("Paths")
|
||||
local number = require("Number")
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local module = {}
|
||||
module.name = localization.moduleDisk
|
||||
|
||||
local HDDImage = image.load(paths.system.icons .. "HDD.pic")
|
||||
local floppyImage = image.load(paths.system.icons .. "Floppy.pic")
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
module.onTouch = function()
|
||||
window.contentContainer:removeChildren()
|
||||
local container = window.contentContainer:addChild(GUI.container(1, 1, window.contentContainer.width, window.contentContainer.height))
|
||||
|
||||
local eeprom = component.proxy(component.list("eeprom")())
|
||||
|
||||
local y = 2
|
||||
for address in component.list("filesystem") do
|
||||
local proxy = component.proxy(address)
|
||||
local isBoot = eeprom.getData() == proxy.address
|
||||
local isReadOnly = proxy.isReadOnly()
|
||||
|
||||
local diskContainer = container:addChild(GUI.container(1, y, container.width, 4))
|
||||
|
||||
local button = diskContainer:addChild(GUI.adaptiveRoundedButton(1, 3, 2, 0, 0x2D2D2D, 0xE1E1E1, 0x0, 0xE1E1E1, localization.options))
|
||||
button.onTouch = function()
|
||||
local container = system.addBackgroundContainer(workspace, localization.options)
|
||||
local inputField = container.layout:addChild(GUI.input(1, 1, 36, 3, 0xE1E1E1, 0x666666, 0x666666, 0xE1E1E1, 0x2D2D2D, proxy.getLabel() or "", localization.diskLabel))
|
||||
inputField.onInputFinished = function()
|
||||
if inputField.text and inputField.text:len() > 0 then
|
||||
proxy.setLabel(inputField.text)
|
||||
|
||||
container:remove()
|
||||
module.onTouch()
|
||||
end
|
||||
end
|
||||
|
||||
local formatButton = container.layout:addChild(GUI.button(1, 1, 36, 3, 0xC3C3C3, 0x2D2D2D, 0x666666, 0xE1E1E1, localization.format))
|
||||
formatButton.onTouch = function()
|
||||
local list = proxy.list("/")
|
||||
for i = 1, #list do
|
||||
proxy.remove(list[i])
|
||||
end
|
||||
|
||||
container:remove()
|
||||
module.onTouch()
|
||||
end
|
||||
formatButton.disabled = isReadOnly
|
||||
|
||||
local switch = container.layout:addChild(GUI.switchAndLabel(1, 1, 36, 8, 0x66DB80, 0x1E1E1E, 0xE1E1E1, 0xBBBBBB, localization.bootable .. ":", isBoot)).switch
|
||||
switch.onStateChanged = function()
|
||||
if switch.state then
|
||||
eeprom.setData(proxy.address)
|
||||
|
||||
container:remove()
|
||||
module.onTouch()
|
||||
end
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
button.localX = diskContainer.width - button.width - 1
|
||||
|
||||
local width = diskContainer.width - button.width - 17
|
||||
local x = 13
|
||||
local spaceTotal = proxy.spaceTotal()
|
||||
local spaceUsed = proxy.spaceUsed()
|
||||
|
||||
diskContainer:addChild(GUI.image(3, 1, isReadOnly and floppyImage or HDDImage))
|
||||
diskContainer:addChild(GUI.label(x, 1, width, 1, 0x2D2D2D, (proxy.getLabel() or "Unknown") .. " (" .. (isBoot and (localization.bootable .. ", ") or "") .. proxy.address .. ")"))
|
||||
diskContainer:addChild(GUI.progressBar(x, 3, width, 0x66DB80, 0xD2D2D2, 0xD2D2D2, spaceUsed / spaceTotal * 100, true))
|
||||
diskContainer:addChild(GUI.label(x, 4, width, 1, 0xBBBBBB, localization.free .. " " .. number.roundToDecimalPlaces((spaceTotal - spaceUsed) / 1024 / 1024, 2) .. " MB " .. localization.of .. " " .. number.roundToDecimalPlaces(spaceTotal / 1024 / 1024, 2) .. " MB")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
|
||||
|
||||
y = y + diskContainer.height + 1
|
||||
end
|
||||
|
||||
container.eventHandler = function(workspace, object, e1, e2, e3, e4, e5)
|
||||
if e1 == "scroll" then
|
||||
if e5 < 0 or container.children[1].localY < 2 then
|
||||
for i = 1, #container.children do
|
||||
container.children[i].localY = container.children[i].localY + e5
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
elseif e1 == "component_added" or e1 == "component_removed" and e3 == "filesystem" then
|
||||
module.onTouch()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
return module
|
||||
141
Applications/Control.app/Modules/3.lua
Normal file
141
Applications/Control.app/Modules/3.lua
Normal file
@@ -0,0 +1,141 @@
|
||||
|
||||
local args = {...}
|
||||
local workspace, window, localization = args[1], args[2], args[3]
|
||||
|
||||
local GUI = require("GUI")
|
||||
local screen = require("Screen")
|
||||
local image = require("Image")
|
||||
local paths = require("Paths")
|
||||
local text = require("Text")
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local module = {}
|
||||
module.name = localization.moduleRAM
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
module.onTouch = function()
|
||||
window.contentContainer:removeChildren()
|
||||
|
||||
local cykaPanel = window.contentContainer:addChild(GUI.panel(1, 1, 1, 1, 0xE1E1E1))
|
||||
|
||||
local mainLayout = window.contentContainer:addChild(GUI.layout(1, 1, window.contentContainer.width, window.contentContainer.height, 2, 1))
|
||||
mainLayout:setColumnWidth(1, GUI.SIZE_POLICY_RELATIVE, 0.3)
|
||||
mainLayout:setColumnWidth(2, GUI.SIZE_POLICY_RELATIVE, 0.7)
|
||||
mainLayout:setFitting(1, 1, true, true)
|
||||
mainLayout:setFitting(2, 1, true, true)
|
||||
|
||||
local tree = mainLayout:setPosition(1, 1, mainLayout:addChild(GUI.tree(1, 1, 1, 1, 0xE1E1E1, 0x3C3C3C, 0x3C3C3C, 0xAAAAAA, 0x3C3C3C, 0xFFFFFF, 0xBBBBBB, 0xAAAAAA, 0xC3C3C3, 0x444444, GUI.IO_MODE_BOTH, GUI.IO_MODE_FILE)))
|
||||
|
||||
local itemsLayout = mainLayout:setPosition(2, 1, mainLayout:addChild(GUI.layout(1, 1, 1, 1, 1, 2)))
|
||||
itemsLayout:setRowHeight(1, GUI.SIZE_POLICY_RELATIVE, 0.6)
|
||||
itemsLayout:setRowHeight(2, GUI.SIZE_POLICY_RELATIVE, 0.4)
|
||||
itemsLayout:setFitting(1, 1, true, false, 4, 0)
|
||||
itemsLayout:setFitting(1, 2, true, true)
|
||||
|
||||
local infoLabel = itemsLayout:setPosition(1, 1, itemsLayout:addChild(GUI.label(1, 1, 1, 1, 0x3C3C3C, "nil")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP))
|
||||
local argumentsInputField = itemsLayout:setPosition(1, 1, itemsLayout:addChild(GUI.input(1, 1, 1, 3, 0xFFFFFF, 0x666666, 0x888888, 0xFFFFFF, 0x262626, nil, localization.arguments)))
|
||||
local executeButton = itemsLayout:setPosition(1, 1, itemsLayout:addChild(GUI.button(1, 1, 1, 3, 0x3C3C3C, 0xFFFFFF, 0x0, 0xFFFFFF, localization.execute)))
|
||||
local outputTextBox = itemsLayout:setPosition(1, 2, itemsLayout:addChild(GUI.textBox(1, 1, 1, 1, 0xFFFFFF, 0x888888, {"nil"}, 1, 1, 0)))
|
||||
|
||||
local function updateList(tree, t, definitionName, offset)
|
||||
local list = {}
|
||||
for key in pairs(t) do
|
||||
table.insert(list, key)
|
||||
end
|
||||
|
||||
local i, expandables = 1, {}
|
||||
while i <= #list do
|
||||
if type(t[list[i]]) == "table" then
|
||||
table.insert(expandables, list[i])
|
||||
table.remove(list, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(expandables, function(a, b) return unicode.lower(tostring(a)) < unicode.lower(tostring(b)) end)
|
||||
table.sort(list, function(a, b) return unicode.lower(tostring(a)) < unicode.lower(tostring(b)) end)
|
||||
|
||||
for i = 1, #expandables do
|
||||
local definition = definitionName .. expandables[i]
|
||||
|
||||
tree:addItem(tostring(expandables[i]), definition, offset, true)
|
||||
if tree.expandedItems[definition] then
|
||||
updateList(tree, t[expandables[i]], definition, offset + 2)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #list do
|
||||
tree:addItem(tostring(list[i]), {key = list[i], value = t[list[i]]}, offset, false)
|
||||
end
|
||||
end
|
||||
|
||||
local function out(t)
|
||||
local wrappedLines = text.wrap(t, outputTextBox.width - 2)
|
||||
for i = 1, #wrappedLines do
|
||||
table.insert(outputTextBox.lines, wrappedLines[i])
|
||||
end
|
||||
end
|
||||
|
||||
tree.onItemExpanded = function()
|
||||
tree.items = {}
|
||||
updateList(tree, _G, "_G", 1)
|
||||
end
|
||||
|
||||
tree.onItemSelected = function()
|
||||
local valueType = type(tree.selectedItem.value)
|
||||
local valueIsFunction = valueType == "function"
|
||||
|
||||
executeButton.disabled = not valueIsFunction
|
||||
argumentsInputField.disabled = executeButton.disabled
|
||||
|
||||
infoLabel.text = tostring(tree.selectedItem.key) .. " (" .. valueType .. ")"
|
||||
outputTextBox.lines = {}
|
||||
|
||||
if valueIsFunction then
|
||||
out("nil")
|
||||
else
|
||||
out(tostring(tree.selectedItem.value))
|
||||
end
|
||||
end
|
||||
|
||||
executeButton.onTouch = function()
|
||||
outputTextBox.lines = {}
|
||||
|
||||
local data = "local method = ({...})[1]; return method(" .. (argumentsInputField.text or "") .. ")"
|
||||
local success, reason = load(data)
|
||||
if success then
|
||||
local success, reason = pcall(success, tree.selectedItem.value)
|
||||
if success then
|
||||
if type(reason) == "table" then
|
||||
local serialized = text.serialize(reason, true, 2, false, 3)
|
||||
for line in serialized:gmatch("[^\n]+") do
|
||||
out(line)
|
||||
end
|
||||
else
|
||||
out(tostring(reason))
|
||||
end
|
||||
else
|
||||
out("Failed to pcall loaded string \"" .. data .. "\": " .. reason)
|
||||
end
|
||||
else
|
||||
out("Failed to load string \"" .. data .. "\": " .. reason)
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
|
||||
|
||||
executeButton.disabled = true
|
||||
argumentsInputField.disabled = true
|
||||
executeButton.colors.disabled.background = 0x777777
|
||||
executeButton.colors.disabled.text = 0xD2D2D2
|
||||
|
||||
tree.onItemExpanded()
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
return module
|
||||
47
Applications/Control.app/Modules/4.lua
Normal file
47
Applications/Control.app/Modules/4.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
local args = {...}
|
||||
local workspace, window, localization = args[1], args[2], args[3]
|
||||
|
||||
local GUI = require("GUI")
|
||||
local screen = require("Screen")
|
||||
local image = require("Image")
|
||||
local paths = require("Paths")
|
||||
local text = require("Text")
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local module = {}
|
||||
module.name = localization.moduleEvent
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
module.onTouch = function()
|
||||
window.contentContainer:removeChildren()
|
||||
|
||||
local container = window.contentContainer:addChild(GUI.container(1, 1, window.contentContainer.width, window.contentContainer.height))
|
||||
|
||||
local layout = container:addChild(GUI.layout(1, 1, container.width, window.contentContainer.height, 1, 1))
|
||||
layout:setAlignment(1, 1, GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
|
||||
layout:setMargin(1, 1, 0, 1)
|
||||
|
||||
local textBox = layout:addChild(GUI.textBox(1, 1, container.width - 4, container.height - 4, nil, 0x888888, {localization.waitingEvents .. "..."}, 1, 0, 0))
|
||||
local switch = layout:addChild(GUI.switchAndLabel(1, 1, 27, 6, 0x66DB80, 0x1E1E1E, 0xFFFFFF, 0x2D2D2D, localization.processingEnabled .. ": ", true)).switch
|
||||
|
||||
textBox.eventHandler = function(workspace, object, ...)
|
||||
local eventData = {...}
|
||||
if switch.state and eventData[1] then
|
||||
local lines = table.concat(eventData, " ")
|
||||
lines = text.wrap(lines, textBox.width)
|
||||
for i = 1, #lines do
|
||||
table.insert(textBox.lines, lines[i])
|
||||
end
|
||||
textBox:scrollToEnd()
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
return module
|
||||
Reference in New Issue
Block a user