From c318e383e86352ab47ce65a72a22cf02e26ce1e0 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Sat, 14 Oct 2017 20:14:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D1=8C=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications.cfg | 38 +- Applications/Control/About/English.txt | 1 - Applications/Control/About/Russian.txt | 1 - Applications/Control/Control.lua | 287 ---------- Applications/Control/Icon.pic | Bin 173 -> 168 bytes .../Control/Localization/English.lang | 16 + .../Control/Localization/Russian.lang | 16 + Applications/Control/Main.lua | 68 +++ Applications/Control/Modules/1.lua | 110 ++++ Applications/Control/Modules/2.lua | 149 ++++++ Applications/Control/Modules/3.lua | 53 ++ Applications/Control2/Control2.lua | 54 -- Applications/Control2/Icon.pic | Bin 127 -> 0 bytes Applications/Control2/LuaLogo.pic | Bin 308 -> 0 bytes .../Control2/Modules/00_LuaConsole.lua | 118 ----- Icons/Floppy.pic | Bin 102 -> 222 bytes Icons/HDD.pic | Bin 170 -> 248 bytes lib/GUI.lua | 496 +++++++++--------- lib/MineOSInterface.lua | 2 +- 19 files changed, 693 insertions(+), 716 deletions(-) delete mode 100644 Applications/Control/About/English.txt delete mode 100644 Applications/Control/About/Russian.txt delete mode 100755 Applications/Control/Control.lua create mode 100755 Applications/Control/Localization/English.lang create mode 100755 Applications/Control/Localization/Russian.lang create mode 100644 Applications/Control/Main.lua create mode 100644 Applications/Control/Modules/1.lua create mode 100644 Applications/Control/Modules/2.lua create mode 100644 Applications/Control/Modules/3.lua delete mode 100755 Applications/Control2/Control2.lua delete mode 100644 Applications/Control2/Icon.pic delete mode 100644 Applications/Control2/LuaLogo.pic delete mode 100644 Applications/Control2/Modules/00_LuaConsole.lua diff --git a/Applications.cfg b/Applications.cfg index f873eb0e..3707e54d 100644 --- a/Applications.cfg +++ b/Applications.cfg @@ -141,13 +141,13 @@ path="/MineOS/System/Icons/HDD.pic", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Icons/HDD.pic", type="Icon", - version=1.0, + version=1.01, }, { path="/MineOS/System/Icons/Floppy.pic", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Icons/Floppy.pic", type="Icon", - version=1.0, + version=1.01, }, { path="/MineOS/System/Icons/Steve.pic", @@ -235,7 +235,7 @@ path="/lib/MineOSInterface.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/MineOSInterface.lua", type="Library", - version=1.05, + version=1.06, }, { path="/lib/MineOSPaths.lua", @@ -302,7 +302,7 @@ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/GUI.lua", type="Library", preloadFile=true, - version=1.83, + version=1.84, }, { path="/lib/rayEngine.lua", @@ -890,6 +890,36 @@ createShortcut=true, version=1.0, }, + { + path="/MineOS/Applications/Control", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Main.lua", + type="Application", + icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Icon.pic", + forceDownload=true, + version=5.00, + resources={ + { + path="/Localization/Russian.lang", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Localization/Russian.lang" + }, + { + path="/Localization/English.lang", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Localization/English.lang" + }, + { + path="/Modules/1.lua", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Modules/1.lua" + }, + { + path="/Modules/2.lua", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Modules/2.lua" + }, + { + path="/Modules/3.lua", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Control/Modules/3.lua" + }, + } + }, { path="/MineOS/Applications/Photoshop", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Photoshop/Photoshop.lua", diff --git a/Applications/Control/About/English.txt b/Applications/Control/About/English.txt deleted file mode 100644 index b9f73da8..00000000 --- a/Applications/Control/About/English.txt +++ /dev/null @@ -1 +0,0 @@ -Control - программа, позволяющая узнать всю необходимую информацию о данном компьютере, позволяет манипулировать жесткими дисками, форматировать их, изменять их имя и прочее. \ No newline at end of file diff --git a/Applications/Control/About/Russian.txt b/Applications/Control/About/Russian.txt deleted file mode 100644 index b9f73da8..00000000 --- a/Applications/Control/About/Russian.txt +++ /dev/null @@ -1 +0,0 @@ -Control - программа, позволяющая узнать всю необходимую информацию о данном компьютере, позволяет манипулировать жесткими дисками, форматировать их, изменять их имя и прочее. \ No newline at end of file diff --git a/Applications/Control/Control.lua b/Applications/Control/Control.lua deleted file mode 100755 index 95a9f337..00000000 --- a/Applications/Control/Control.lua +++ /dev/null @@ -1,287 +0,0 @@ - ---pastebin run 5whGf4Ns - -local c = require("component") -local unicode = require("unicode") -local computer = require("computer") -local event = require("event") -local context = require("context") -local screen = c.screen -local gpu = c.gpu -local image = require("image") - - -------------------------------------------------------------------------------------------------------------------------------- - -local colors = { - topBar = 0xdddddd, - main = 0xffffff, - closes = {cross = 0xCC4C4C, hide = 0xDEDE6C, full = 0x57A64E}, - topText = 0x262626, - topButtons = 0xffffff, - topButtonsText = 0x262626, -} - -local topButtons = {"О системе", "Диски"} -local spaceBetweenTopButtons, offsetTopButtons = 2, 2 -local currentMode = 1 - -local osIcon = image.load("MineOS/System/OS/Icons/OS_Logo.pic") -local hddIcon = image.load("MineOS/System/OS/Icons/HDD.pic") -local floppyIcon = image.load("MineOS/System/OS/Icons/Floppy.pic") -local updateIcon = image.load("MineOS/System/OS/Icons/Update.pic") - -local x, y = "auto", "auto" -local width, height = 84, 26 -x, y = ecs.correctStartCoords(x, y, width, height) -local heightOfTopBar = 3 - -local ram = {} -ram.free, ram.total, ram.used = ecs.getInfoAboutRAM() - -local drawHDDFrom = 1 -local HDDs -local bootAddress = computer.getBootAddress() - -local updates, oldApps -local drawUpdatesFrom = 1 -local xUpdatesList, yUpdatesList -local countOfChoses - -------------------------------------------------------------------------------------------------------------------------------- - ---СОЗДАНИЕ ОБЪЕКТОВ -local obj = {} -local function newObj(class, name, ...) - obj[class] = obj[class] or {} - obj[class][name] = {...} -end - ---Рисем цветные кружочки слева вверху -local function drawCloses() - local symbol = "⮾" - gpu.setBackground(colors.topBar) - local yPos = y - ecs.colorText(x + 1, yPos , colors.closes.cross, symbol) - ecs.colorText(x + 3, yPos , colors.closes.hide, symbol) - ecs.colorText(x + 5, yPos , colors.closes.full, symbol) - newObj("Closes", 1, x + 1, yPos, x + 1, yPos) - newObj("Closes", 2, x + 3, yPos, x + 3, yPos) - newObj("Closes", 3, x + 5, yPos, x + 5, yPos) -end - ---Рисуем верхнюю часть -local function drawTopBar() - --Рисуем сам бар - ecs.square(x, y, width, heightOfTopBar, colors.topBar) - --Рисуем кнопочки - drawCloses() - --Рисуем титл - --local text = topButtons[currentMode] - --ecs.colorText(x + math.floor(width / 2 - unicode.len(text) / 2), y, colors.topText, text) - --Рисуем кнопочки влево-вправо - local widthOfButtons = 0 - for i = 1, #topButtons do - widthOfButtons = widthOfButtons + unicode.len(topButtons[i]) + spaceBetweenTopButtons + offsetTopButtons * 2 - end - local xPos, yPos = x + math.floor(width / 2 - widthOfButtons / 2), y + 1 - for i = 1, #topButtons do - local color1, color2 = colors.topButtons, colors.topButtonsText - if i == currentMode then color1, color2 = ecs.colors.blue, 0xffffff end - newObj("TopButtons", i, ecs.drawAdaptiveButton(xPos, yPos, offsetTopButtons, 0, topButtons[i], color1, color2)) - xPos = xPos + unicode.len(topButtons[i]) + spaceBetweenTopButtons + offsetTopButtons * 2 - color1, color2 = nil, nil - end -end - -local function drawUpdatesList() - - local selectSymbol, nonSelectSymbol = "✔", " " - local limit = 40 - local xPos, yPos = xUpdatesList, yUpdatesList - - --ОЧИЩАЕМ ЭТУ ПИЗДУ, ЗАЕБАЛО, БЛЯДЬ - ecs.square(xPos, yPos, limit + 2, 15, colors.main) - - for i = drawUpdatesFrom, (drawUpdatesFrom + 4) do - if not updates[i] then break end - --Коробка для галочки - ecs.border(xPos, yPos, 5, 3, colors.main, 0x262626) - --Галочка - if updates[i].needToUpdate then - ecs.colorText(xPos + 2, yPos + 1, 0x880000, selectSymbol) - countOfChoses = countOfChoses + 1 - end - --Имя проги - local text = "§f" .. (fs.name(updates[i].name) or updates[i].name) .. (function() if updates[i].needToUpdate then return "§e, версия ".. updates[i].version .." (новее)" else return "§8, версия ".. updates[i].version end end)() - ecs.smartText(xPos + 6, yPos + 1, ecs.stringLimit("end", text, limit)) - text = nil - - yPos = yPos + 3 - end - - --Скроллбар - ecs.srollBar(x + width - 3, y + heightOfTopBar + 2, 1, 15, #updates, drawUpdatesFrom, 0xdddddd, ecs.colors.blue) - -end - -local function drawMain() - ecs.square(x, y + heightOfTopBar, width, height - heightOfTopBar, colors.main) - local xPos, yPos - if currentMode == 1 then - xPos, yPos = x + 3, y + heightOfTopBar + 3 - image.draw(xPos, yPos, osIcon) - xPos, yPos = x + 36, yPos + 3 - ecs.colorTextWithBack(xPos, yPos, 0x000000, colors.main, "MineOS"); yPos = yPos + 1 - ecs.colorText(xPos, yPos, ecs.colors.lightGray, "Публичная бета-версия 1.75"); yPos = yPos + 2 - - ecs.smartText(xPos, yPos, "§fСистемный блок §8(3 уровень, середина 2015 года)"); yPos = yPos + 1 - ecs.smartText(xPos, yPos, "§fПроцессор §8(3 уровень, дохуя GHz)"); yPos = yPos + 1 - ecs.smartText(xPos, yPos, "§fПамять §8(1333 МГц DDR3 "..ram.total.." KB)"); yPos = yPos + 1 - ecs.smartText(xPos, yPos, "§fГрафика §8(GTX Titan AnaloRazrivatel mk.3000)"); yPos = yPos + 1 - ecs.smartText(xPos, yPos, "§fСерийный номер §8"..ecs.stringLimit("end", computer.address(), 30)); yPos = yPos + 1 - - elseif currentMode == 2 then - obj["HDDControls"] = {} - yPos = y + heightOfTopBar + 1 - HDDs = ecs.getHDDs() - for i = drawHDDFrom, (drawHDDFrom + 3) do - if not HDDs[i] then break end - - xPos = x + 2 - --Рисуем правильную картинку диска - if HDDs[i].isFloppy == true then image.draw(xPos, yPos, floppyIcon) else image.draw(xPos, yPos, hddIcon) end - - --Рисуем тексты - xPos = xPos + 10 - gpu.setBackground(colors.main) - local load = "" - if bootAddress == HDDs[i].address then load = " §eзагрузочный§8," end - ecs.smartText(xPos, yPos, ecs.stringLimit("end", "§f" .. (HDDs[i].label or "Безымянный диск") .. "§8,"..load.." " .. HDDs[i].address, 58)); yPos = yPos + 2 - --Рисуем прогрессбар - local percent = math.ceil(HDDs[i].spaceUsed / HDDs[i].spaceTotal * 100) - ecs.progressBar(xPos, yPos, 50, 1, 0xdddddd, ecs.colors.blue, percent) - yPos = yPos + 1 - ecs.colorTextWithBack(xPos + 10, yPos, 0xaaaaaa, colors.main, HDDs[i].spaceUsed.." из "..HDDs[i].spaceTotal.." KB использовано"); yPos = yPos + 1 - - ecs.separator(x, yPos, width - 1, colors.main, 0xdddddd) - - --Рисуем кнопы - xPos, yPos = x + 67, yPos - 4 - newObj("HDDControls", i, ecs.drawButton(xPos, yPos, 14, 3, "Управление", ecs.colors.blue, 0xffffff)) - - yPos = yPos + 5 - end - - --Скроллбар - ecs.srollBar(x + width - 1, y + heightOfTopBar, 1, height - heightOfTopBar, #HDDs, drawHDDFrom, 0xdddddd, ecs.colors.blue) - end -end - - -------------------------------------------------------------------------------------------------------------------------------- - ---ecs.prepareToExit() - -local oldPixels = ecs.rememberOldPixels(x, y, x + width - 1, y + height - 1) -drawTopBar() -drawMain() - -while true do - local e = {event.pull()} - if e[1] == "touch" then - - if currentMode == 2 then - for key in pairs(obj["HDDControls"]) do - if ecs.clickedAtArea(e[3], e[4], obj["HDDControls"][key][1], obj["HDDControls"][key][2], obj["HDDControls"][key][3], obj["HDDControls"][key][4]) then - ecs.drawButton(obj["HDDControls"][key][1], obj["HDDControls"][key][2], 14, 3, "Управление", 0xdddddd, ecs.colors.blue) - local action = context.menu(obj["HDDControls"][key][1], obj["HDDControls"][key][2] + 3, {"Форматировать"}, {"Изменить имя"}, {"Установить как загрузочный"}, "-", {"Сдублировать OS на этот диск"}) - if action == "Форматировать" then - local data = ecs.universalWindow("auto", "auto", 38, ecs.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x880000, "Внимание!"}, {"EmptyLine"}, {"CenterText", 0x262626, "Данное действие очистит весь диск."}, {"CenterText", 0x262626, "Продолжить?"}, {"EmptyLine"}, {"Button", {0xbbbbbb, 0xffffff, "Да"}, {0x999999, 0xffffff, "Нет"}}) - if data[1] ~= "Нет" then - ecs.formatHDD(HDDs[key].address) - drawMain() - end - elseif action == "Изменить имя" then - local data = ecs.universalWindow("auto", "auto", 30, ecs.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x262626, "Изменить имя диска"}, {"EmptyLine"}, {"Input", 0x262626, 0x000000, HDDs[key].label or "Имя"}, {"EmptyLine"}, {"Button", {0xbbbbbb, 0xffffff, "OK!"}}) - if data[1] == "" or data[1] == " " then data[1] = "Untitled" end - ecs.setHDDLabel(HDDs[key].address, data[1]) - drawMain() - elseif action == "Сдублировать OS на этот диск" then - ecs.duplicateFileSystem(bootAddress, HDDs[key].address) - drawMain() - elseif action == "Установить как загрузочный" then - computer.setBootAddress(HDDs[key].address) - bootAddress = HDDs[key].address - drawMain() - end - ecs.drawButton(obj["HDDControls"][key][1], obj["HDDControls"][key][2], 14, 3, "Управление", ecs.colors.blue, 0xffffff) - break - end - end - end - - for key, val in pairs(obj["TopButtons"]) do - if ecs.clickedAtArea(e[3], e[4], obj["TopButtons"][key][1], obj["TopButtons"][key][2], obj["TopButtons"][key][3], obj["TopButtons"][key][4]) then - currentMode = key - drawTopBar() - drawMain() - break - end - end - - for key, val in pairs(obj["Closes"]) do - if ecs.clickedAtArea(e[3], e[4], obj["Closes"][key][1], obj["Closes"][key][2], obj["Closes"][key][3], obj["Closes"][key][4]) then - ecs.colorTextWithBack(obj["Closes"][key][1], obj["Closes"][key][2], ecs.colors.blue, colors.topBar, "⮾") - os.sleep(0.2) - if key == 1 then - ecs.drawOldPixels(oldPixels) - return - else - drawTopBar() - break - end - end - end - - elseif e[1] == "key_down" then - for i = 2, 5 do - if e[4] == i then - currentMode = i - 1 - drawTopBar() - drawMain() - break - end - end - - if e[4] == 28 then - ecs.prepareToExit() - return - end - - elseif e[1] == "scroll" then - if currentMode == 2 then - if e[5] == 1 then - if drawHDDFrom > 1 then drawHDDFrom = drawHDDFrom - 1; drawMain() end - else - if drawHDDFrom < #HDDs then drawHDDFrom = drawHDDFrom + 1; drawMain() end - end - elseif currentMode == 3 then - if e[5] == 1 then - if drawUpdatesFrom > 1 then drawUpdatesFrom = drawUpdatesFrom - 1; drawUpdatesList() end - else - if drawUpdatesFrom < #updates then drawUpdatesFrom = drawUpdatesFrom + 1; drawUpdatesList() end - end - end - - - end -end - - - - - - - - diff --git a/Applications/Control/Icon.pic b/Applications/Control/Icon.pic index e227b4ac4177255b47d35f6a6fe5ee843e5bfc83..748c38bbe4f53287434491ddf0d9e1bf37545432 100644 GIT binary patch literal 168 zcmXZTu?+$-425Ao$4)#;N>(@tiHhdNKz9;i03;ZK(y$0qus{}p9C7#A{(YPd`)tBr z(&i5kK9B?{&2MAil$&2cTp5YAr>p{jwdeg`U@KleyuA|Hf{Gdaq4~R`B3aKwbFp2V SY#m_E=UC|}P%Z(P0{8(gG8y9l literal 173 zcmYL?u?>Sj5Cm`U5B|z<=r#c9B?9DNqc6arWyzUSYM??I0fh9rY$w>6*EAP%8-Rn@ zx3%CHMWs5R$+|v!b!&4#7UEmLQ6LrC5$~WxEI~^Af_mZ;WYou9x-BT$gno&i)l(}H H|9IsS1sxa^ diff --git a/Applications/Control/Localization/English.lang b/Applications/Control/Localization/English.lang new file mode 100755 index 00000000..4a768d3e --- /dev/null +++ b/Applications/Control/Localization/English.lang @@ -0,0 +1,16 @@ +{ + moduleDisk = "Disk utility", + moduleRAM = "RAM control", + moduleEvent = "Event processing", + + diskLabel = "Disk label", + bootable = "Bootable", + of = "of", + free = "Free", + options = "Options", + arguments = "Arguments", + format = "Format", + execute = "Execute", + waitingEvents = "Waiting for events", + processingEnabled = "Event processing enabled", +} \ No newline at end of file diff --git a/Applications/Control/Localization/Russian.lang b/Applications/Control/Localization/Russian.lang new file mode 100755 index 00000000..d42310ea --- /dev/null +++ b/Applications/Control/Localization/Russian.lang @@ -0,0 +1,16 @@ +{ + moduleDisk = "Дисковая утилита", + moduleRAM = "Управление памятью", + moduleEvent = "Анализ событий", + + diskLabel = "Имя диска", + bootable = "Загрузочный", + of = "из", + free = "Свободно", + options = "Опции", + arguments = "Аргументы", + format = "Форматировать", + execute = "Выполнить", + waitingEvents = "Ожидание событий", + processingEnabled = "Обработка событий", +} \ No newline at end of file diff --git a/Applications/Control/Main.lua b/Applications/Control/Main.lua new file mode 100644 index 00000000..fc476f64 --- /dev/null +++ b/Applications/Control/Main.lua @@ -0,0 +1,68 @@ + +require("advancedLua") +local component = require("component") +local computer = require("computer") +local image = require("image") +local buffer = require("doubleBuffering") +local GUI = require("GUI") +local fs = require("filesystem") +local unicode = require("unicode") +local MineOSPaths = require("MineOSPaths") +local MineOSCore = require("MineOSCore") +local MineOSInterface = require("MineOSInterface") + +---------------------------------------------------------------------------------------------------------------- + +local resourcesPath = MineOSCore.getCurrentApplicationResourcesDirectory() +local modulesPath = resourcesPath .. "Modules/" +local localization = MineOSCore.getLocalization(resourcesPath .. "Localization/") + +local mainContainer, window = MineOSInterface.addWindow(GUI.tabbedWindow(nil, nil, 80, 25)) + +---------------------------------------------------------------------------------------------------------------- + +window.contentContainer = window:addChild(GUI.container(1, 4, window.width, window.height - 3)) + +local function loadModules() + local fileList = fs.sortedList(modulesPath, "name", false) + for i = 1, #fileList do + local success, reason = loadfile(modulesPath .. fileList[i]) + if success then + local success, reason = pcall(success, mainContainer, window, localization) + if success then + window.tabBar:addItem(reason.name).onTouch = function() + reason.onTouch() + end + else + error("Failed to call loaded module \"" .. tostring(fileList[i]) .. "\": " .. tostring(reason)) + end + else + error("Failed to load module \"" .. tostring(fileList[i]) .. "\": " .. tostring(reason)) + end + end +end + +window.onResize = function(width, height) + window.tabBar.width = width + window.backgroundPanel.width = width + window.backgroundPanel.height = height - 3 + window.contentContainer.width = width + window.contentContainer.height = window.backgroundPanel.height + + window.tabBar.children[window.tabBar.selectedItem + 1].onTouch() +end + +---------------------------------------------------------------------------------------------------------------- + +loadModules() +window.onResize(80, 25) + +mainContainer:draw() +buffer.draw() + + + + + + + diff --git a/Applications/Control/Modules/1.lua b/Applications/Control/Modules/1.lua new file mode 100644 index 00000000..af4072e8 --- /dev/null +++ b/Applications/Control/Modules/1.lua @@ -0,0 +1,110 @@ + +local args = {...} +local mainContainer, window, localization = args[1], args[2], args[3] + +require("advancedLua") +local component = require("component") +local computer = require("computer") +local GUI = require("GUI") +local buffer = require("doubleBuffering") +local image = require("image") +local MineOSPaths = require("MineOSPaths") +local MineOSInterface = require("MineOSInterface") + +---------------------------------------------------------------------------------------------------------------- + +local module = {} +module.name = localization.moduleDisk + +local HDDImage = image.load(MineOSPaths.icons .. "HDD.pic") +local floppyImage = image.load(MineOSPaths.icons .. "Floppy.pic") + +---------------------------------------------------------------------------------------------------------------- + +module.onTouch = function() + window.contentContainer:deleteChildren() + local container = window.contentContainer:addChild(GUI.container(1, 1, window.contentContainer.width, window.contentContainer.height)) + + local y = 2 + for address in component.list("filesystem") do + local proxy = component.proxy(address) + local isBoot = computer.getBootAddress() == 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 = MineOSInterface.addUniversalContainer(mainContainer, localization.options) + local inputField = container.layout:addChild(GUI.inputField(1, 1, 36, 3, 0xEEEEEE, 0x666666, 0x666666, 0xEEEEEE, 0x262626, proxy.getLabel(), localization.diskLabel)) + inputField.onInputFinished = function() + if inputField.text and inputField.text:len() > 0 then + proxy.setLabel(inputField.text) + + container:delete() + module.onTouch() + end + end + + local button = container.layout:addChild(GUI.roundedButton(1, 1, 36, 3, 0xEEEEEE, 0x666666, 0x666666, 0xEEEEEE, localization.format)) + button.onTouch = function() + local list = proxy.list("/") + for i = 1, #list do + proxy.remove(list[i]) + end + + container:delete() + module.onTouch() + end + button.disabled = isReadOnly + + local switch = container.layout:addChild(GUI.switchAndLabel(1, 1, 36, 8, 0x66DB80, 0x1E1E1E, 0xEEEEEE, 0xBBBBBB, localization.bootable .. ":", isBoot)).switch + switch.onStateChanged = function() + if switch.state then + computer.setBootAddress(proxy.address) + + container:delete() + module.onTouch() + end + end + + mainContainer:draw() + buffer.draw() + end + button.localPosition.x = 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 .. " " .. math.roundToDecimalPlaces((spaceTotal - spaceUsed) / 1024 / 1024, 2) .. " MB " .. localization.of .. " " .. math.roundToDecimalPlaces(spaceTotal / 1024 / 1024, 2) .. " MB")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top) + + y = y + diskContainer.height + 1 + end + + container.eventHandler = function(mainContainer, object, eventData) + if eventData[1] == "scroll" then + if eventData[5] < 0 or container.children[1].localPosition.y < 2 then + for i = 1, #container.children do + container.children[i].localPosition.y = container.children[i].localPosition.y + eventData[5] + end + + mainContainer:draw() + buffer.draw() + end + elseif eventData[1] == "component_added" or eventData[1] == "component_removed" and eventData[3] == "filesystem" then + module.onTouch() + end + end + + mainContainer:draw() + buffer.draw() +end + +---------------------------------------------------------------------------------------------------------------- + +return module \ No newline at end of file diff --git a/Applications/Control/Modules/2.lua b/Applications/Control/Modules/2.lua new file mode 100644 index 00000000..636a3b2a --- /dev/null +++ b/Applications/Control/Modules/2.lua @@ -0,0 +1,149 @@ + +local args = {...} +local mainContainer, window, localization = args[1], args[2], args[3] + +require("advancedLua") +local component = require("component") +local computer = require("computer") +local GUI = require("GUI") +local buffer = require("doubleBuffering") +local image = require("image") +local MineOSPaths = require("MineOSPaths") +local MineOSInterface = require("MineOSInterface") +local unicode = require("unicode") + +---------------------------------------------------------------------------------------------------------------- + +local module = {} +module.name = localization.moduleRAM + +---------------------------------------------------------------------------------------------------------------- + +module.onTouch = function() + window.contentContainer:deleteChildren() + + 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.sizePolicies.percentage, 0.3) + mainLayout:setColumnWidth(2, GUI.sizePolicies.percentage, 0.7) + mainLayout:setCellFitting(1, 1, true, true) + mainLayout:setCellFitting(2, 1, true, true) + + local tree = mainLayout:setCellPosition(1, 1, mainLayout:addChild(GUI.tree(1, 1, 1, 1, 0xE1E1E1, 0x3C3C3C, 0x3C3C3C, 0xAAAAAA, 0x3C3C3C, 0xFFFFFF, 0xBBBBBB, 0xAAAAAA, 0xC3C3C3, 0x444444, GUI.filesystemModes.both, GUI.filesystemModes.file))) + + local itemsLayout = mainLayout:setCellPosition(2, 1, mainLayout:addChild(GUI.layout(1, 1, 1, 1, 1, 2))) + itemsLayout:setRowHeight(1, GUI.sizePolicies.percentage, 0.6) + itemsLayout:setRowHeight(2, GUI.sizePolicies.percentage, 0.4) + itemsLayout:setCellFitting(1, 1, true, false, 4, 0) + itemsLayout:setCellFitting(1, 2, true, true) + + local infoLabel = itemsLayout:setCellPosition(1, 1, itemsLayout:addChild(GUI.label(1, 1, 1, 1, 0x3C3C3C, "nil")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top)) + local argumentsInputField = itemsLayout:setCellPosition(1, 1, itemsLayout:addChild(GUI.inputField(1, 1, 1, 3, 0xFFFFFF, 0x666666, 0x888888, 0xFFFFFF, 0x262626, nil, localization.arguments))) + local executeButton = itemsLayout:setCellPosition(1, 1, itemsLayout:addChild(GUI.button(1, 1, 1, 3, 0x3C3C3C, 0xFFFFFF, 0x0, 0xFFFFFF, localization.execute))) + local outputTextBox = itemsLayout:setCellPosition(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]) .. ": " .. type(t[list[i]]), {key = list[i], value = t[list[i]]}, offset, false) + end + end + + local function out(text) + local wrappedLines = string.wrap(text, 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 = table.toString(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 + + mainContainer:draw() + buffer.draw() + end + + + executeButton.disabled = true + argumentsInputField.disabled = true + executeButton.colors.disabled.background = 0x777777 + executeButton.colors.disabled.text = 0xD2D2D2 + + tree.onItemExpanded() + + mainContainer:draw() + buffer.draw() +end + +---------------------------------------------------------------------------------------------------------------- + +return module \ No newline at end of file diff --git a/Applications/Control/Modules/3.lua b/Applications/Control/Modules/3.lua new file mode 100644 index 00000000..8d01ccc8 --- /dev/null +++ b/Applications/Control/Modules/3.lua @@ -0,0 +1,53 @@ + +local args = {...} +local mainContainer, window, localization = args[1], args[2], args[3] + +require("advancedLua") +local component = require("component") +local computer = require("computer") +local GUI = require("GUI") +local buffer = require("doubleBuffering") +local image = require("image") +local MineOSPaths = require("MineOSPaths") +local MineOSInterface = require("MineOSInterface") + +---------------------------------------------------------------------------------------------------------------- + +local module = {} +module.name = localization.moduleEvent + +---------------------------------------------------------------------------------------------------------------- + +module.onTouch = function() + window.contentContainer:deleteChildren() + + 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:setCellAlignment(1, 1, GUI.alignment.horizontal.center, GUI.alignment.vertical.top) + layout:setCellMargin(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 + + container.eventHandler = function(mainContainer, object, eventData) + if switch.state and eventData[1] then + local lines = table.concat(eventData, " ") + lines = string.wrap(lines, textBox.width) + for i = 1, #lines do + table.insert(textBox.lines, lines[i]) + end + textBox:scrollDown(#lines) + + mainContainer:draw() + buffer.draw() + end + end + + mainContainer:draw() + buffer.draw() +end + +---------------------------------------------------------------------------------------------------------------- + +return module \ No newline at end of file diff --git a/Applications/Control2/Control2.lua b/Applications/Control2/Control2.lua deleted file mode 100755 index 46bdc7ce..00000000 --- a/Applications/Control2/Control2.lua +++ /dev/null @@ -1,54 +0,0 @@ - -local fs = require("filesystem") -local advancedLua = require("advancedLua") -local buffer = require("doubleBuffering") -local GUI = require("GUI") -local MineOSCore = require("MineOSCore") -local event = require("event") -local unicode = require("unicode") - ------------------------------------------------------------------------------------------------------------------------------ - -local window = {} - ------------------------------------------------------------------------------------------------------------------------------ - -local function createWindow() - window = GUI.window("auto", "auto", math.floor(buffer.screen.width * 0.8), math.floor(buffer.screen.height * 0.7), 78, 24) - window:addPanel(1, 1, window.width, window.height, 0xEEEEEE).disabled = true - - window.resourcesPath = MineOSCore.getCurrentApplicationResourcesDirectory() - window.modules = {} - local moduleNames = {} - for file in fs.list(window.resourcesPath .. "Modules/") do - local module, reason = dofile(window.resourcesPath .. "Modules/" .. file) - if module then - table.insert(window.modules, module) - table.insert(moduleNames, module.name) - else - error("Error due module execution: " .. reason) - end - end - - window.tabBar = window:addTabBar(1, 1, window.width, 3, 1, 0xDDDDDD, 0x262626, 0xCCCCCC, 0x262626, table.unpack(moduleNames)) - window.tabBar.onTabSwitched = function(object, eventData) - - end - window:addWindowActionButtons(2, 1, false).close.onTouch = function() - window:close() - end - window.drawingArea = window:addContainer(1, 4, window.width, window.height - 3, 0xEEEEEE) - - window.modules[1].execute(window) -end - ------------------------------------------------------------------------------------------------------------------------------ - -createWindow() -window.drawShadow = true -window:draw() -buffer.draw() -window.drawShadow = false -window:handleEvents() - - diff --git a/Applications/Control2/Icon.pic b/Applications/Control2/Icon.pic deleted file mode 100644 index 7072fb24b14d00c0fe75420ab780c5e518e4b4e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 127 zcmX}hF$#b%5Jb_;>?T<}g|&s3hzM3TUckcEN^HclYrw_seg0ggF_|KS=0b-8g1000 m6%R;_ZB-B$C>m2XDkPcwz1F`#kq1XQJ}}zmf}B3NJM;zBZ3_GV diff --git a/Applications/Control2/LuaLogo.pic b/Applications/Control2/LuaLogo.pic deleted file mode 100644 index 99d38a578d42f5ee2b6bdbdb29a62380c0248ad4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 308 zcmZWk%W=gp2oxY8BA77umGG30(;};xo z08AMva3@ct4Uaej!a9#1qd6L7Gyw7Y3}I)i!0zaU;-}WNSOJp2Zj?<*hWbFn8a5dx98lQNsOJ eOu3B7j1;xTw;d@jxk=LFR4#BB$jip$YySiFj1|!U diff --git a/Applications/Control2/Modules/00_LuaConsole.lua b/Applications/Control2/Modules/00_LuaConsole.lua deleted file mode 100644 index 57dacbf1..00000000 --- a/Applications/Control2/Modules/00_LuaConsole.lua +++ /dev/null @@ -1,118 +0,0 @@ - -local buffer = require("doubleBuffering") -local GUI = require("GUI") -local image = require("image") -local unicode = require("unicode") - -local module = { - name = "Интерпретатор Lua" -} - ----------------------------------------------------------------------------------------------------------------------------- - -function module.execute(window) - local luaConsoleCommandHistoryLimit = 20 - local luaConsoleHistoryLimit = 50 - - local colors, printColor = { - passive = 0x777777, - error = 0xFF4940, - } - - window.drawingArea:deleteChildren() - local logoPanelWidth = 20 - local consolePanelWidth = window.drawingArea.width - logoPanelWidth - local luaLogoPanel = window.drawingArea:addPanel(1, 1, logoPanelWidth, window.drawingArea.height, 0xEEEEEE) - local luaLogoImage = window.drawingArea:addImage(2, 1, image.load(window.resourcesPath .. "LuaLogo.pic")) - local luaCopyrightTextBox = window.drawingArea:addTextBox(2, luaLogoImage.height + 2, luaLogoPanel.width - 2, 5, nil, 0x999999, {_G._VERSION, "(C) 1994-2016", "Lua.org, PUC-Rio", "", "GUI-based by ECS"}, 1) - luaCopyrightTextBox:setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top) - local consolePanel = window.drawingArea:addPanel(logoPanelWidth + 1, 1, consolePanelWidth, window.drawingArea.height, 0x1E1E1E) - - local lines = { - {color = 0xFFDB40, text = "Система " .. _VERSION .. " инициализирована"}, - {color = colors.passive, text = "● Введите выражение и нажимте Enter для его "}, - {color = colors.passive, text = " исполнения в виде Lua-кода"}, - {color = colors.passive, text = "● Используйте Tab для автозаполнения названий"}, - {color = colors.passive, text = " переменных"}, - {color = colors.passive, text = "● Введите \"=переменная\", чтобы узнать значение"}, - {color = colors.passive, text = " конкретной переменной"}, - " " - } - local consoleTextBox = window.drawingArea:addTextBox(logoPanelWidth + 2, 1, consolePanelWidth - 2, window.drawingArea.height - 3, nil, 0xFFFFFF, lines, 1) - - local consoleCommandInputTextBox = window.drawingArea:addInputTextBox(logoPanelWidth + 1, consolePanel.height - 2, consolePanel.width, 3, 0x333333, 0x777777, 0x333333, 0x444444, "", "print(\"Hello, world!\")") - consoleCommandInputTextBox.eraseTextOnFocus = true - consoleCommandInputTextBox.highlightLuaSyntax = true - consoleCommandInputTextBox.autocompleteVariables = true - - local function addLines(lines, printColor) - for i = 1, #lines do - if #consoleTextBox.lines > luaConsoleHistoryLimit then table.remove(consoleTextBox.lines, 1) end - table.insert(consoleTextBox.lines, printColor and {color = printColor, text = lines[i]} or lines[i]) - end - consoleTextBox:scrollDown(#lines) - end - - local function getStringValueOfVariable(variable) - local type, value = type(variable) - if type == "table" then - value = table.serialize(variable, true, nil, nil, 1) - else - value = tostring(variable) - end - - return value - end - - local function reimplementedPrint(...) - local args = {...} - local resultText = {}; for i = 1, #args do table.insert(resultText, getStringValueOfVariable(args[i])) end - if #resultText > 0 then - local lines = {table.concat(resultText, " ")} - lines = string.wrap(lines, consoleTextBox.width - 2) - addLines(lines) - end - end - - -- Функцию стер - хуй проглотил! - -- abc = function(a, b, c) local d = b ^ 2 - 4 * a * c; if d < 0 then error("Сууука!!! D < 0") end; x1 = (-b + math.sqrt(d)) / (2 * a); x2 = (-b - math.sqrt(d)) / (2 * a); return x1, x2 end - - consoleCommandInputTextBox.onInputFinished = function() - -- Подменяем стандартный print() на мой пиздатый - local oldPrint = print - print = reimplementedPrint - -- Пишем, че мы вообще исполняли - addLines({"> " .. consoleCommandInputTextBox.text}, colors.passive) - - -- Ебашим поддержку = - consoleCommandInputTextBox.text = consoleCommandInputTextBox.text:gsub("^[%s+]?%=[%s+]?", "return ") - local loadSuccess, loadReason = load(consoleCommandInputTextBox.text) - if loadSuccess then - local xpcallResult = {xpcall(loadSuccess, debug.traceback)} - if xpcallResult[1] then - table.remove(xpcallResult, 1) - reimplementedPrint(table.unpack(xpcallResult)) - else - addLines({xpcallResult[2]}, colors.error) - end - else - addLines({loadReason}, colors.error) - end - - consoleCommandInputTextBox.text = "" - print = oldPrint - - window:draw() - buffer.draw() - end -end - ----------------------------------------------------------------------------------------------------------------------------- - -return module - - - - - - diff --git a/Icons/Floppy.pic b/Icons/Floppy.pic index 6b45d1c98ff4bfbb47c0835d293c0e90e7d0ac4f..3bfb5153b71dca78150f7f0df70afd132eb5312b 100644 GIT binary patch literal 222 zcmXX=F%H5o5R09($;3bCH;|B+_!SisBWv5NARz|S0f}Ga0rwGbLzg?>o$d2+ci6Wn z@atgL42KRta&BYOEW8DgZ0spW0v=j*YRQIKs}2DuDzyBnvp9udXngRYX>EE+QDoZM z(2KE<<06y8r=G$}eEjufEP6m2Pxb5(Z8+;`0juM9sljAv`Ca2slzdyElH6D5f80ne A$N&HU literal 102 zcmXYo%L#xm5JdNFHlH$b7OX-LJlT>}*g`NEyEE_x+vC za=mJz(8obj2gfZDz`z>4Jq}j7IYb zx8e}Z1mp Qw^Pmqwy$W~m8%5u1>$=;MgRZ+ literal 170 zcmX|(!3n}Z6hwFC&u+GioNYr8JlRqT5R$`!R^Tb^sP|uopr1|fFf$JZ-sN~cl`4J{ zMkFMGsEk-dk(BDFcU+Jumsb$U;TdbOYpiI++r;ft-ach-4V_^Jtb9PwCo21GW>@|N S9K0>)0)*?jqj|gUit+=MH5=6c diff --git a/lib/GUI.lua b/lib/GUI.lua index 3314d73c..e6a9b8b9 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -76,17 +76,17 @@ GUI.colors = { windows = { title = { background = 0xE1E1E1, - text = 0x3C3C3C + text = 0x2D2D2D }, - backgroundPanel = 0xFFFFFF, + backgroundPanel = 0xF0F0F0, tabBar = { default = { - background = 0xDDDDDD, - text = 0x3C3C3C + background = 0x2D2D2D, + text = 0xF0F0F0 }, selected = { - background = 0xCCCCCC, - text = 0x3C3C3C + background = 0xF0F0F0, + text = 0x2D2D2D } } } @@ -2009,7 +2009,7 @@ local function scrollToStartTextBox(object) end local function scrollToEndTextBox(object) - object.currentLine = #lines + object.currentLine = #object.lines return object end @@ -2264,10 +2264,10 @@ local function layoutUpdate(layout) if layout.children[i].layoutGridPosition.row >= 1 and layout.children[i].layoutGridPosition.row <= #layout.grid.rowSizes and layout.children[i].layoutGridPosition.column >= 1 and layout.children[i].layoutGridPosition.column <= #layout.grid.columnSizes then -- Авто-фиттинг объектов if layout.grid[layout.children[i].layoutGridPosition.row][layout.children[i].layoutGridPosition.column].fitting.horizontal then - layout.children[i].width = math.floor(layout.grid.columnSizes[layout.children[i].layoutGridPosition.column].calculatedSize) + layout.children[i].width = math.round(layout.grid.columnSizes[layout.children[i].layoutGridPosition.column].calculatedSize - layout.grid[layout.children[i].layoutGridPosition.row][layout.children[i].layoutGridPosition.column].fitting.horizontalRemove) end if layout.grid[layout.children[i].layoutGridPosition.row][layout.children[i].layoutGridPosition.column].fitting.vertical then - layout.children[i].height = math.floor(layout.grid.rowSizes[layout.children[i].layoutGridPosition.row].calculatedSize) + layout.children[i].height = math.round(layout.grid.rowSizes[layout.children[i].layoutGridPosition.row].calculatedSize - layout.grid[layout.children[i].layoutGridPosition.row][layout.children[i].layoutGridPosition.column].fitting.verticalRemove) end -- Алигнмент и расчет размеров @@ -2544,9 +2544,14 @@ local function layoutFitToChildrenSize(layout, column, row) return layout end -local function layoutSetCellFitting(layout, column, row, horizontalFitting, verticalFitting) +local function layoutSetCellFitting(layout, column, row, horizontal, vertical, horizontalRemove, verticalRemove ) layoutCheckCell(layout, column, row) - layout.grid[row][column].fitting = {horizontal = horizontalFitting, vertical = verticalFitting} + layout.grid[row][column].fitting = { + horizontal = horizontal, + vertical = vertical, + horizontalRemove = horizontalRemove or 0, + verticalRemove = verticalRemove or 0, + } return layout end @@ -2579,218 +2584,6 @@ function GUI.layout(x, y, width, height, columnCount, rowCount) return layout end ------------------------------------------ Color Selector object ----------------------------------------- - -local function updateFileList(treeView, directoriesToShowContent, xOffset, path) - local localFileList = {} - for file in fs.list(path) do - local element = {} - element.path = path .. file - element.xOffset = xOffset - element.isDirectory = fs.isDirectory(element.path) - element.extension = fs.extension(file, true) or "" - - if - treeView.showMode == GUI.filesystemModes.both or - element.isDirectory and treeView.showMode == GUI.filesystemModes.directory or - not element.isDirectory and treeView.showMode == GUI.filesystemModes.file - then - table.insert(localFileList, element) - end - end - - -- Sort file list alphabeitcally - table.sort(localFileList, function(a, b) return unicode.lower(a.path) < unicode.lower(b.path) end) - -- Move folders on top and recursively get their content if needed - local i, nextDirectoryIndex, nextLocalFileListIndex = 1, 1, 1 - while i <= #localFileList do - if localFileList[i].isDirectory then - table.insert(localFileList, nextDirectoryIndex, localFileList[i]) - table.remove(localFileList, i + 1) - - if directoriesToShowContent[localFileList[nextDirectoryIndex].path] then - local nextLocalFileList = updateFileList(treeView, directoriesToShowContent, xOffset + 2, localFileList[nextDirectoryIndex].path) - - nextLocalFileListIndex = nextDirectoryIndex + 1 - for j = 1, #nextLocalFileList do - table.insert(localFileList, nextLocalFileListIndex, nextLocalFileList[j]) - nextLocalFileListIndex = nextLocalFileListIndex + 1 - end - i, nextDirectoryIndex = i + #nextLocalFileList, nextDirectoryIndex + #nextLocalFileList - end - - nextDirectoryIndex = nextDirectoryIndex + 1 - end - - i = i + 1 - end - - return localFileList -end - -local function treeViewUpdateFileList(treeView) - treeView.updateFileListLater = true - return treeView -end - -local function treeViewDraw(treeView) - if treeView.updateFileListLater then - treeView.fileList = updateFileList(treeView, treeView.directoriesToShowContent, 1, treeView.workPath) - treeView.updateFileListLater = nil - end - - local y = treeView.y - local showScrollBar = #treeView.fileList > treeView.height - local textLimit = treeView.width - (showScrollBar and 2 or 1) - - if treeView.colors.default.background then - buffer.square(treeView.x, treeView.y, treeView.width, treeView.height, treeView.colors.default.background, treeView.colors.default.directory, " ") - end - - for fileIndex = treeView.fromFile, #treeView.fileList do - local textColor, arrowColor, text = treeView.colors.default.file, treeView.colors.default.arrow, treeView.fileList[fileIndex].isDirectory and "■ " or "□ " - - if treeView.fileList[fileIndex].path == treeView.selectedItem then - textColor, arrowColor = treeView.colors.selected.fileOrDirectory, treeView.colors.selected.arrow - buffer.square(treeView.x, y, treeView.width, 1, treeView.colors.selected.background, textColor, " ") - else - if treeView.fileList[fileIndex].isDirectory then - textColor = treeView.colors.default.directory - elseif treeView.extensionFilters and not treeView.extensionFilters[treeView.fileList[fileIndex].extension] then - textColor = treeView.colors.wrongExtension - end - end - - if treeView.fileList[fileIndex].isDirectory then - buffer.text(treeView.x + treeView.fileList[fileIndex].xOffset, y, arrowColor, treeView.directoriesToShowContent[treeView.fileList[fileIndex].path] and "▽" or "▷") - end - - buffer.text(treeView.x + treeView.fileList[fileIndex].xOffset + 2, y, textColor, unicode.sub(text .. fs.name(treeView.fileList[fileIndex].path), 1, textLimit - treeView.fileList[fileIndex].xOffset - 2)) - - y = y + 1 - if y > treeView.y + treeView.height - 1 then - break - end - end - - if showScrollBar then - GUI.scrollBar( - treeView.x + treeView.width - 1, - treeView.y, - 1, - treeView.height, - treeView.colors.scrollBar.background, - treeView.colors.scrollBar.foreground, - 1, - #treeView.fileList, - treeView.fromFile, - treeView.height - 2, - 1 - ):draw() - end - - return treeView -end - -local function treeViewEventHandler(mainContainer, treeView, eventData) - if eventData[1] == "touch" then - local fileIndex = eventData[4] - treeView.y + treeView.fromFile - if treeView.fileList[fileIndex] then - if - treeView.fileList[fileIndex].isDirectory and - ( - treeView.selectionMode == GUI.filesystemModes.file or - eventData[3] >= treeView.x + treeView.fileList[fileIndex].xOffset - 1 and eventData[3] <= treeView.x + treeView.fileList[fileIndex].xOffset + 1 - ) - then - if treeView.directoriesToShowContent[treeView.fileList[fileIndex].path] then - treeView.directoriesToShowContent[treeView.fileList[fileIndex].path] = nil - else - treeView.directoriesToShowContent[treeView.fileList[fileIndex].path] = true - end - - treeView:updateFileList() - mainContainer:draw() - buffer.draw() - else - if - ( - treeView.selectionMode == GUI.filesystemModes.both or - treeView.selectionMode == GUI.filesystemModes.directory and treeView.fileList[fileIndex].isDirectory or - treeView.selectionMode == GUI.filesystemModes.file and (not treeView.extensionFilters or treeView.extensionFilters[treeView.fileList[fileIndex].extension]) - ) - then - treeView.selectedItem = treeView.fileList[fileIndex].path - - mainContainer:draw() - buffer.draw() - GUI.callMethod(treeView.onItemSelected, treeView.selectedItem, eventData) - end - end - end - elseif eventData[1] == "scroll" then - if eventData[5] == 1 then - if treeView.fromFile > 1 then - treeView.fromFile = treeView.fromFile - 1 - mainContainer:draw() - buffer.draw() - end - else - if treeView.fromFile < #treeView.fileList then - treeView.fromFile = treeView.fromFile + 1 - mainContainer:draw() - buffer.draw() - end - end - end -end - -local function treeViewAddExtensionFilter(treeView, extensionFilter) - treeView.extensionFilters = treeView.extensionFilters or {} - treeView.extensionFilters[unicode.lower(extensionFilter)] = true -end - -function GUI.treeView(x, y, width, height, backgroundColor, directoryColor, fileColor, arrowColor, backgroundSelectionColor, textSelectedColor, arrowSelectionColor, wrongExtensionColor, scrollBarBackground, scrollBarForeground, workPath, showMode, selectionMode) - local treeView = GUI.container(x, y, width, height) - - treeView.eventHandler = treeViewEventHandler - treeView.colors = { - default = { - background = backgroundColor, - directory = directoryColor, - file = fileColor, - arrow = arrowColor, - }, - selected = { - background = backgroundSelectionColor, - fileOrDirectory = textSelectedColor, - arrow = arrowSelectionColor, - }, - scrollBar = { - background = scrollBarBackground, - foreground = scrollBarForeground - }, - wrongExtension = wrongExtensionColor - } - treeView.directoriesToShowContent = {} - treeView.fileList = {} - treeView.workPath = workPath - - treeView.extensionFilters = nil - treeView.selectedItem = nil - treeView.fromFile = 1 - treeView.showMode = showMode or GUI.filesystemModes.both - treeView.selectionMode = selectionMode or GUI.filesystemModes.file - - treeView.updateFileList = treeViewUpdateFileList - treeView.draw = treeViewDraw - treeView.addExtensionFilter = treeViewAddExtensionFilter - - treeView:updateFileList() - - return treeView -end - -------------------------------------------------------------------------------------------------------------------------------- local function filesystemDialogDraw(filesystemDialog) @@ -2803,8 +2596,8 @@ local function filesystemDialogDraw(filesystemDialog) if filesystemDialog.IOMode == GUI.filesystemModes.save then filesystemDialog.submitButton.disabled = not filesystemDialog.inputField.text else - filesystemDialog.inputField.text = filesystemDialog.treeView.selectedItem - filesystemDialog.submitButton.disabled = not filesystemDialog.treeView.selectedItem + filesystemDialog.inputField.text = filesystemDialog.filesystemTree.selectedItem + filesystemDialog.submitButton.disabled = not filesystemDialog.filesystemTree.selectedItem end GUI.drawContainerContent(filesystemDialog) @@ -2818,24 +2611,24 @@ local function filesystemDialogSetMode(filesystemDialog, IOMode, filesystemMode) filesystemDialog.filesystemMode = filesystemMode if filesystemDialog.IOMode == GUI.filesystemModes.save then - filesystemDialog.treeView.showMode = GUI.filesystemModes.directory - filesystemDialog.treeView.selectionMode = GUI.filesystemModes.directory + filesystemDialog.filesystemTree.showMode = GUI.filesystemModes.directory + filesystemDialog.filesystemTree.selectionMode = GUI.filesystemModes.directory filesystemDialog.inputField.eventHandler = inputFieldEventHandler filesystemDialog.extensionComboBox.hidden = not (filesystemDialog.filesystemMode == GUI.filesystemModes.file) else if filesystemDialog.filesystemMode == GUI.filesystemModes.file then - filesystemDialog.treeView.showMode = GUI.filesystemModes.both - filesystemDialog.treeView.selectionMode = GUI.filesystemModes.file + filesystemDialog.filesystemTree.showMode = GUI.filesystemModes.both + filesystemDialog.filesystemTree.selectionMode = GUI.filesystemModes.file else - filesystemDialog.treeView.showMode = GUI.filesystemModes.directory - filesystemDialog.treeView.selectionMode = GUI.filesystemModes.directory + filesystemDialog.filesystemTree.showMode = GUI.filesystemModes.directory + filesystemDialog.filesystemTree.selectionMode = GUI.filesystemModes.directory end filesystemDialog.inputField.eventHandler = nil filesystemDialog.extensionComboBox.hidden = true end - filesystemDialog.treeView:updateFileList() + filesystemDialog.filesystemTree:updateFileList() end local function filesystemDialogAddExtensionFilter(filesystemDialog, extension) @@ -2843,7 +2636,7 @@ local function filesystemDialogAddExtensionFilter(filesystemDialog, extension) filesystemDialog.extensionComboBox.width = math.max(filesystemDialog.extensionComboBox.width, unicode.len(extension) + 3) filesystemDialog.extensionComboBox.localPosition.x = filesystemDialog.cancelButton.localPosition.x - filesystemDialog.extensionComboBox.width - 2 - filesystemDialog.treeView:addExtensionFilter(extension) + filesystemDialog.filesystemTree:addExtensionFilter(extension) end function GUI.filesystemDialog(x, y, width, height, submitButtonText, cancelButtonText, placeholderText, path) @@ -2861,11 +2654,8 @@ function GUI.filesystemDialog(x, y, width, height, submitButtonText, cancelButto filesystemDialog.inputField = filesystemDialog:addChild(GUI.inputField(2, height - 1, 1, 1, 0xE1E1E1, 0x555555, 0x888888, 0xE1E1E1, 0x777777, nil, placeholderText)) - filesystemDialog.treeView = filesystemDialog:addChild(GUI.treeView( - 1, 1, width, height - 3, - 0xE1E1E1, 0x3C3C3C, 0x3C3C3C, 0xAAAAAA, 0x3C3C3C, 0xE1E1E1, 0xBBBBBB, 0xAAAAAA, 0xC3C3C3, 0x444444, - path - )) + filesystemDialog.filesystemTree = filesystemDialog:addChild(GUI.filesystemTree(1, 1, width, height - 3, 0xE1E1E1, 0x3C3C3C, 0x3C3C3C, 0xAAAAAA, 0x3C3C3C, 0xE1E1E1, 0xBBBBBB, 0xAAAAAA, 0xC3C3C3, 0x444444)) + filesystemDialog.filesystemTree.workPath = path filesystemDialog.draw = filesystemDialogDraw filesystemDialog.setMode = filesystemDialogSetMode @@ -2914,7 +2704,7 @@ function GUI.addFilesystemDialogToContainer(parentContainer, ...) filesystemDialog.submitButton.onTouch = function() onAnyTouch() - local path = filesystemDialog.treeView.selectedItem or filesystemDialog.treeView.workPath or "/" + local path = filesystemDialog.filesystemTree.selectedItem or filesystemDialog.filesystemTree.workPath or "/" if filesystemDialog.IOMode == GUI.filesystemModes.save then path = path .. filesystemDialog.inputField.text @@ -3196,28 +2986,234 @@ function GUI.scrollBar(x, y, width, height, backgroundColor, foregroundColor, mi return scrollBar end +----------------------------------------- Tree object ----------------------------------------- + +local function treeDraw(tree) + local y, yEnd, showScrollBar = tree.y, tree.y + tree.height - 1, #tree.items > tree.height + local textLimit = tree.width - (showScrollBar and 1 or 0) + + if tree.colors.default.background then + buffer.square(tree.x, tree.y, tree.width, tree.height, tree.colors.default.background, tree.colors.default.expandable, " ") + end + + for i = tree.fromItem, #tree.items do + local textColor, arrowColor, text = tree.colors.default.notExpandable, tree.colors.default.arrow, tree.items[i].expandable and "■ " or "□ " + + if tree.selectedItem == tree.items[i].definition then + textColor, arrowColor = tree.colors.selected.any, tree.colors.selected.arrow + buffer.square(tree.x, y, tree.width, 1, tree.colors.selected.background, textColor, " ") + else + if tree.items[i].expandable then + textColor = tree.colors.default.expandable + elseif tree.items[i].disabled then + textColor = tree.colors.disabled + end + end + + if tree.items[i].expandable then + buffer.text(tree.x + tree.items[i].offset, y, arrowColor, tree.expandedItems[tree.items[i].definition] and "▽" or "▷") + end + + buffer.text(tree.x + tree.items[i].offset + 2, y, textColor, unicode.sub(text .. fs.name(tree.items[i].name), 1, textLimit - tree.items[i].offset - 2)) + + y = y + 1 + if y > yEnd then break end + end + + if showScrollBar then + local scrollBar = tree.scrollBar + scrollBar.x = tree.x + tree.width - 1 + scrollBar.y = tree.y + scrollBar.width = 1 + scrollBar.height = tree.height + scrollBar.colors.background = tree.colors.scrollBar.background + scrollBar.colors.foreground = tree.colors.scrollBar.foreground + scrollBar.minimumValue = 1 + scrollBar.maximumValue = #tree.items + scrollBar.value = tree.fromItem + scrollBar.shownValueCount = tree.height + scrollBar.onScrollValueIncrement = 1 + scrollBar.thin = true + + scrollBar:draw() + end + + return tree +end + +local function treeEventHandler(mainContainer, tree, eventData) + if eventData[1] == "touch" then + local i = eventData[4] - tree.y + tree.fromItem + if tree.items[i] then + if + tree.items[i].expandable and + ( + tree.selectionMode == GUI.filesystemModes.file or + eventData[3] >= tree.x + tree.items[i].offset - 1 and eventData[3] <= tree.x + tree.items[i].offset + 1 + ) + then + if tree.expandedItems[tree.items[i].definition] then + tree.expandedItems[tree.items[i].definition] = nil + else + tree.expandedItems[tree.items[i].definition] = true + end + + GUI.callMethod(tree.onItemExpanded, tree.selectedItem, eventData) + else + if + ( + ( + tree.selectionMode == GUI.filesystemModes.both or + tree.selectionMode == GUI.filesystemModes.directory and tree.items[i].expandable or + tree.selectionMode == GUI.filesystemModes.file + ) and not tree.items[i].disabled + ) + then + tree.selectedItem = tree.items[i].definition + GUI.callMethod(tree.onItemSelected, tree.selectedItem, eventData) + end + end + + mainContainer:draw() + buffer.draw() + end + elseif eventData[1] == "scroll" then + if eventData[5] == 1 then + if tree.fromItem > 1 then + tree.fromItem = tree.fromItem - 1 + mainContainer:draw() + buffer.draw() + end + else + if tree.fromItem < #tree.items then + tree.fromItem = tree.fromItem + 1 + mainContainer:draw() + buffer.draw() + end + end + end +end + +local function treeAddItem(tree, name, definition, offset, expandable, disabled) + table.insert(tree.items, {name = name, expandable = expandable, offset = offset or 0, definition = definition, disabled = disabled}) + return tree +end + +function GUI.tree(x, y, width, height, backgroundColor, expandableColor, notExpandableColor, arrowColor, backgroundSelectionColor, anySelectionColor, arrowSelectionColor, disabledColor, scrollBarBackground, scrollBarForeground, showMode, selectionMode) + local tree = GUI.container(x, y, width, height) + + tree.eventHandler = treeEventHandler + tree.colors = { + default = { + background = backgroundColor, + expandable = expandableColor, + notExpandable = notExpandableColor, + arrow = arrowColor, + }, + selected = { + background = backgroundSelectionColor, + any = anySelectionColor, + arrow = arrowSelectionColor, + }, + scrollBar = { + background = scrollBarBackground, + foreground = scrollBarForeground + }, + disabled = disabledColor + } + tree.items = {} + tree.fromItem = 1 + tree.selectedItem = nil + tree.expandedItems = {} + + tree.scrollBar = GUI.scrollBar(1, 1, 1, 1, 0x0, 0x0, 1, 1, 1, 1, 1) + + tree.showMode = showMode + tree.selectionMode = selectionMode + tree.eventHandler = treeEventHandler + tree.addItem = treeAddItem + tree.draw = treeDraw + + return tree +end + +----------------------------------------- FilesystemTree object ----------------------------------------- + +local function filesystemTreeUpdateFileListRecursively(tree, path, offset) + local list = {} + for file in fs.list(path) do + table.insert(list, file) + end + + local i, expandables = 1, {} + while i <= #list do + if fs.isDirectory(path .. list[i]) 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(a) < unicode.lower(b) end) + table.sort(list, function(a, b) return unicode.lower(a) < unicode.lower(b) end) + + if tree.showMode == GUI.filesystemModes.both or tree.showMode == GUI.filesystemModes.directory then + for i = 1, #expandables do + tree:addItem(expandables[i], path .. expandables[i], offset, true) + + if tree.expandedItems[path .. expandables[i]] then + filesystemTreeUpdateFileListRecursively(tree, path .. expandables[i], offset + 2) + end + end + end + + if tree.showMode == GUI.filesystemModes.both or tree.showMode == GUI.filesystemModes.file then + for i = 1, #list do + tree:addItem(list[i], path .. list[i], offset, false,tree.extensionFilters and not tree.extensionFilters[fs.extension(path .. list[i], true)] or false) + end + end +end + +local function filesystemTreeUpdateFileList(tree) + tree.items = {} + filesystemTreeUpdateFileListRecursively(tree, tree.workPath, 1) +end + +local function filesystemTreeAddExtensionFilter(tree, extensionFilter) + tree.extensionFilters = tree.extensionFilters or {} + tree.extensionFilters[unicode.lower(extensionFilter)] = true +end + +function GUI.filesystemTree(...) + local tree = GUI.tree(...) + + tree.workPath = "/" + tree.updateFileList = filesystemTreeUpdateFileList + tree.addExtensionFilter = filesystemTreeAddExtensionFilter + tree.onItemExpanded = function() + tree:updateFileList() + end + + return tree +end + -------------------------------------------------------------------------------------------------------------------------------- -- buffer.flush() -- buffer.draw(true) - --- ------------------------------------------------------------------------------------------ +------------------------------------------------------------------------------------------ -- local mainContainer = GUI.fullScreenContainer() -- mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x0)) --- local codeView = mainContainer:addChild(GUI.codeView(2, 2, 130, 30, {}, 1, 1, 1, {}, {}, true, 2)) +-- local tree = mainContainer:addChild(GUI.filesystemTree(1, 1, 30, 30, 0xE1E1E1, 0x3C3C3C, 0x3C3C3C, 0xAAAAAA, 0x3C3C3C, 0xE1E1E1, 0xBBBBBB, 0xAAAAAA, 0xC3C3C3, 0x444444, GUI.filesystemModes.both, GUI.filesystemModes.file)) --- local file = io.open("/lib/color.lua", "r") --- for line in file:lines() do --- line = line:gsub("\t", " "):gsub("\r\n", "\n") --- table.insert(codeView.lines, line) --- codeView.maximumLineLength = math.max(codeView.maximumLineLength, unicode.len(line)) --- end --- file:close() +-- tree:addExtensionFilter(".pic") +-- tree:updateFileList() --- ------------------------------------------------------------------------------------------ +------------------------------------------------------------------------------------------ -- mainContainer:draw() -- buffer.draw(true) diff --git a/lib/MineOSInterface.lua b/lib/MineOSInterface.lua index 516d0ec8..0552728d 100755 --- a/lib/MineOSInterface.lua +++ b/lib/MineOSInterface.lua @@ -1236,7 +1236,7 @@ local function GUICopy(parentContainer, fileList, toPath) local container = MineOSInterface.addUniversalContainer(parentContainer, MineOSCore.localization.copying) local textBox = container.layout:addChild(GUI.textBox(1, 1, container.width, 1, nil, 0x777777, {}, 1, 0, 0, true, true):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top)) - local switchAndLabel = container.layout:addChild(GUI.switchAndLabel(1, 1, 37, 8, 0x66DB80, 0x2D2D2D, 0xEEEEEE, 0x777777, MineOSCore.localization.applyToAll .. ":", false)) + local switchAndLabel = container.layout:addChild(GUI.switchAndLabel(1, 1, 37, 8, 0x66DB80, 0x1E1E1E, 0xEEEEEE, 0x777777, MineOSCore.localization.applyToAll .. ":", false)) container.panel.eventHandler = nil local buttonsLayout = container.layout:addChild(GUI.layout(1, 1, 1, 1, 1, 1))