Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Nova GUI API lightweight edition. By alakazard12
- -- Feel free to use this as long as you give me credit.
- local LGW, LGH = term.getSize()
- local VColors = {}
- local VClasses = {
- ["TextButton"] = true;
- ["TextLabel"] = true;
- ["TextBox"] = true;
- ["ImageButton"] = true;
- ["ImageLabel"] = true;
- }
- for _,Color in pairs(colors) do
- if type(Color) == "number" then
- VColors[Color] = true
- end
- end
- local function Round(Number)
- return math.floor(Number + 0.5)
- end
- local Check
- function Check(Object, BG, PX, PY, ChangeP)
- if Object.Visible == true then
- if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" or Object.Class == "ImageButton" or Object.Class == "ImageLabel" then
- -- if ChangeP ~= true then
- PX = PX + Object.Position[1] - 1
- PY = PY + Object.Position[2] - 1
- -- end
- if Object.ShowBackground == true then
- BG = Object.BackgroundColor
- end
- if Object.Class == "TextBox" and Object.Focused == true then
- BG = Object.ActiveTextColor
- end
- term.setBackgroundColor(BG)
- for Y = 1, Object.Size[2] do
- term.setCursorPos(PX, PY + Y - 1)
- term.write(string.rep(" ", Object.Size[1]))
- end
- if Object.Class == "ImageButton" or Object.Class == "ImageLabel" and Object.Image then
- paintutils.drawImage(Object.Image, PX, PY)
- end
- if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" then
- if Object.ShowText == true then
- term.setTextColor(Object.TextColor)
- local Text = Object.Text
- if Object.TextChar then
- Text = string.rep(Object.TextChar, #Text)
- end
- if Object.Focused == true then
- Text = Text .. " "
- end
- if Object.MultiLine == true then
- local LastP = 1
- local LastS
- local Lines = {}
- local DidBreak = false
- local RPassed = false
- local ROnLine = false
- local ROnNum
- local RLine
- for On = 1, #Text do
- if Text:sub(On, On) == " " then
- LastS = On
- end
- if On - LastP + 2 > Object.Size[1] then
- if #Lines == Object.Size[2] then
- break
- end
- if LastS then
- table.insert(Lines, Text:sub(LastP, LastS))
- LastP = LastS + 1
- else
- table.insert(Lines, Text:sub(LastP, On))
- LastP = On + 1
- end
- LastS = nil
- if #Lines == Object.Size[2] then
- if Object.Focused == false then
- DidBreak = true
- break
- else
- table.remove(Lines, 1)
- end
- end
- end
- end
- if DidBreak == false then
- table.insert(Lines, Text:sub(LastP))
- elseif Object.Focused == true then
- table.remove(Lines, 1)
- table.insert(Lines, Text:sub(LastP))
- end
- local TextCount = 0
- for _,Line in pairs(Lines) do
- local XA = 0
- local YA = 0
- if Object.TextXAlignment == 0 then
- XA = PX
- elseif Object.TextXAlignment == 1 then
- XA = PX + Round((Object.Size[1] - #Line) / 2)
- else
- XA = PX + Round(Object.Size[1] - #Line)
- end
- if Object.TextYAlignment == 0 then
- YA = PY + _ - 1
- elseif Object.TextYAlignment == 1 then
- YA = PY + Round((Object.Size[2] - #Lines) / 2) + _ - 1
- else
- YA = PY + Round(Object.Size[2] - #Lines) + _ - 1
- end
- term.setCursorPos(XA, YA)
- term.write(Line)
- end
- else
- if #Text > Object.Size[1] then
- if Object.Focused == false then
- Text = string.sub(Text, 1, Object.Size[1])
- -- elseif Object.RTextPos then
- -- Text = string.sub(Text, Object.RTextPos, Object.RTextPos + Object.Size[1] - 1)
- else
- Text = string.sub(Text, #Text - Object.Size[1] + 1, #Text)
- end
- end
- local XA = 0
- local YA = 0
- if Object.TextXAlignment == 0 then
- XA = PX
- elseif Object.TextXAlignment == 1 then
- XA = PX + Round((Object.Size[1] - #Text) / 2)
- else
- XA = PX + Round(Object.Size[1] - #Text)
- end
- if Object.TextYAlignment == 0 then
- YA = PY
- elseif Object.TextYAlignment == 1 then
- YA = PY + Round((Object.Size[2] - 1) / 2)
- else
- YA = PY + Round(Object.Size[2] - 1)
- end
- term.setCursorPos(XA, YA)
- term.write(Text)
- end
- -- if Object.RTextPos == nil then
- Object.TextPos = {term.getCursorPos()}
- Object.TextPos[1] = Object.TextPos[1] - 1
- -- end
- end
- end
- for _,Obj in pairs(Object.Children) do
- Check(Obj, BG, PX, PY)
- end
- end
- end
- end
- local function SortListen(Tbl)
- local Clone = {}
- for _,Item in pairs(Tbl) do
- Clone[_] = Item
- end
- table.sort(Clone, function(A, B)
- return A.ZIndex > B.ZIndex
- end)
- return Clone
- end
- local function NewClass(Par, Class, Main)
- if type(Class) ~= "string" then
- error("bad argument #1: string expected, got " .. type(Class), 2)
- end
- if not VClasses[Class] then
- error("Invalid class name.", 2)
- end
- local PublicTable = {}
- local LocalTable = {}
- LocalTable.Parent = Par
- LocalTable.Class = Class
- function PublicTable:ClearChildren()
- LocalTable.Children = {}
- end
- if Class == "ImageButton" or Class == "ImageLabel" then
- LocalTable.Size = {2, 2}
- LocalTable.Position = {1, 1}
- LocalTable.Visible = true
- LocalTable.Active = true
- LocalTable.Children = {}
- LocalTable.ZIndex = 0
- LocalTable.ShowBackground = true
- function PublicTable:Size(X, Y)
- if type(X) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- if type(Y) ~= "number" then
- error("bad argument #2: number expected, got " .. type(Y), 2)
- end
- LocalTable.Size = {X, Y}
- end
- function PublicTable:Image(Image)
- if type(Image) ~= "table" then
- error("bad argument #1: table expected, got " .. type(Image), 2)
- end
- LocalTable.Image = Image
- end
- function PublicTable:GetSize()
- return unpack(LocalTable.Size)
- end
- function PublicTable:ShowBackground(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.ShowBackground = Bool
- end
- function PublicTable:GetShowBackground()
- return LocalTable.ShowBackground
- end
- function PublicTable:ZIndex(Number)
- if type(Number) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Number), 2)
- end
- LocalTable.ZIndex = Number
- table.sort(Par.Children, function(A, B)
- return A.ZIndex < B.ZIndex
- end)
- end
- function PublicTable:GetZIndex()
- return LocalTable.ZIndex
- end
- function PublicTable:Position(X, Y)
- if type(X) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- if type(Y) ~= "number" then
- error("bad argument #2: number expected, got " .. type(Y), 2)
- end
- LocalTable.Position = {X, Y}
- end
- function PublicTable:GetPosition()
- return unpack(LocalTable.Position)
- end
- function PublicTable:Visible(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.Visible = Bool
- end
- function PublicTable:GetVisible()
- return LocalTable.Visible
- end
- function PublicTable:Active(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.Active = Bool
- end
- function PublicTable:GetActive()
- return LocalTable.Active
- end
- function PublicTable:BackgroundColor(Color)
- if type(Color) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Color), 2)
- end
- if VColors[Color] ~= true then
- error("Invalid color.", 2)
- end
- LocalTable.BackgroundColor = Color
- end
- function PublicTable:GetBackgroundColor()
- return LocalTable.BackgroundColor
- end
- if Class == "ImageButton" then
- function PublicTable:Button1Click(Function)
- if Function == nil then
- LocalTable.Button1Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button1Click = Function
- end
- end
- function PublicTable:GetButton1Click()
- return LocalTable.Button1Click
- end
- function PublicTable:MouseScroll(Function)
- if Function == nil then
- LocalTable.MouseScroll = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseScroll = Function
- end
- end
- function PublicTable:GetMouseScroll()
- return LocalTable.MouseScroll
- end
- function PublicTable:MouseDrag1(Function)
- if Function == nil then
- LocalTable.MouseDrag1 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag1 = Function
- end
- end
- function PublicTable:GetMouseDrag1()
- return LocalTable.MouseDrag1
- end
- function PublicTable:MouseDrag2(Function)
- if Function == nil then
- LocalTable.MouseDrag2 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag2 = Function
- end
- end
- function PublicTable:GetMouseDrag2()
- return LocalTable.MouseDrag2
- end
- function PublicTable:MouseDrag3(Function)
- if Function == nil then
- LocalTable.MouseDrag3 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag3 = Function
- end
- end
- function PublicTable:GetMouseDrag3()
- return LocalTable.MouseDrag3
- end
- function PublicTable:Button2Click(Function)
- if Function == nil then
- LocalTable.Button2Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button2Click = Function
- end
- end
- function PublicTable:GetButton2Click()
- return LocalTable.Button2Click
- end
- function PublicTable:Button3Click(Function)
- if Function == nil then
- LocalTable.Button3Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button3Click = Function
- end
- end
- function PublicTable:GetButton3Click()
- return LocalTable.Button3Click
- end
- end
- function PublicTable:New(Class)
- return NewClass(LocalTable, Class, Main)
- end
- function PublicTable:Draw()
- local BG = Main.BackgroundColor
- local FoundBG = false
- local PX, PY = 1, 1
- local On = LocalTable.Parent
- while On ~= Main do
- PX = PX + On.Position[1] - 1
- PY = PY + On.Position[2] - 1
- if On.ShowBackground and FoundBG == false then
- BG = On.BackgroundColor
- FoundBG = true
- end
- On = On.Parent
- end
- Check(LocalTable, BG, PX, PY)
- end
- elseif Class == "TextButton" or Class == "TextLabel" or Class == "TextBox" then
- LocalTable.Size = {2, 2}
- LocalTable.Position = {1, 1}
- LocalTable.RawText = ""
- LocalTable.Text = ""
- LocalTable.BackgroundColor = colors.cyan
- LocalTable.TextColor = colors.white
- LocalTable.Visible = true
- LocalTable.Active = true
- LocalTable.Children = {}
- LocalTable.ZIndex = 0
- LocalTable.ShowBackground = true
- LocalTable.ShowText = true
- LocalTable.TextXAlignment = 1
- LocalTable.TextYAlignment = 1
- LocalTable.MultiLine = false
- if Class == "TextBox" then
- LocalTable.ActiveTextColor = colors.blue
- LocalTable.Overlap = false
- LocalTable.Focused = false
- LocalTable.ClearTextOnFocus = false
- LocalTable.RTextPos = 8
- end
- function PublicTable:TextXAlignment(Num)
- if type(Num) == "string" then
- if Num:lower() == "left" then
- Num = 0
- elseif Num:lower() == "center" then
- Num = 1
- elseif Num:lower() == "right" then
- Num = 2
- else
- error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
- end
- end
- if type(Num) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- LocalTable.TextXAlignment = Num
- end
- function PublicTable:GetTextXAlignment()
- return LocalTable.TextXAlignment
- end
- function PublicTable:TextYAlignment(Num)
- if type(Num) == "string" then
- if Num:lower() == "top" then
- Num = 0
- elseif Num:lower() == "center" then
- Num = 1
- elseif Num:lower() == "bottom" then
- Num = 2
- else
- error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
- end
- end
- if type(Num) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- LocalTable.TextYAlignment = Num
- end
- function PublicTable:GetTextYAlignment()
- return LocalTable.TextYAlignment
- end
- function PublicTable:Size(X, Y)
- if type(X) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- if type(Y) ~= "number" then
- error("bad argument #2: number expected, got " .. type(Y), 2)
- end
- LocalTable.Size = {X, Y}
- end
- function PublicTable:GetSize()
- return unpack(LocalTable.Size)
- end
- function PublicTable:ShowBackground(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.ShowBackground = Bool
- end
- function PublicTable:GetShowBackground()
- return LocalTable.ShowBackground
- end
- function PublicTable:ShowText(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.ShowText = Bool
- end
- function PublicTable:GetShowText()
- return LocalTable.ShowText
- end
- function PublicTable:MultiLine(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.MultiLine = Bool
- end
- function PublicTable:GetMultiLine()
- return LocalTable.MultiLine
- end
- function PublicTable:ZIndex(Number)
- if type(Number) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Number), 2)
- end
- LocalTable.ZIndex = Number
- table.sort(Par.Children, function(A, B)
- return A.ZIndex < B.ZIndex
- end)
- end
- function PublicTable:GetZIndex()
- return LocalTable.ZIndex
- end
- function PublicTable:Position(X, Y)
- if type(X) ~= "number" then
- error("bad argument #1: number expected, got " .. type(X), 2)
- end
- if type(Y) ~= "number" then
- error("bad argument #2: number expected, got " .. type(Y), 2)
- end
- LocalTable.Position = {X, Y}
- end
- function PublicTable:GetPosition()
- return unpack(LocalTable.Position)
- end
- function PublicTable:Visible(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.Visible = Bool
- end
- function PublicTable:GetVisible()
- return LocalTable.Visible
- end
- function PublicTable:Active(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.Active = Bool
- end
- function PublicTable:GetActive()
- return LocalTable.Active
- end
- function PublicTable:Text(Text)
- if Text == nil then
- Text = ""
- end
- if type(Text) ~= "string" then
- error("bad argument #1: string expected, got " .. type(Text), 2)
- end
- LocalTable.Text = Text
- end
- function PublicTable:GetText()
- return LocalTable.Text
- end
- function PublicTable:BackgroundColor(Color)
- if type(Color) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Color), 2)
- end
- if VColors[Color] ~= true then
- error("Invalid color.", 2)
- end
- LocalTable.BackgroundColor = Color
- end
- function PublicTable:GetBackgroundColor()
- return LocalTable.BackgroundColor
- end
- function PublicTable:TextColor(Color)
- if type(Color) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Color), 2)
- end
- if VColors[Color] ~= true then
- error("Invalid color.", 2)
- end
- LocalTable.TextColor = Color
- end
- function PublicTable:GetTextColor()
- return LocalTable.TextColor
- end
- function PublicTable:MouseScroll(Function)
- if Function == nil then
- LocalTable.MouseScroll = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseScroll = Function
- end
- end
- if Class == "TextButton" then
- function PublicTable:Button1Click(Function)
- if Function == nil then
- LocalTable.Button1Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button1Click = Function
- end
- end
- function PublicTable:GetButton1Click()
- return LocalTable.Button1Click
- end
- function PublicTable:GetMouseScroll()
- return LocalTable.MouseScroll
- end
- function PublicTable:MouseDrag1(Function)
- if Function == nil then
- LocalTable.MouseDrag1 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag1 = Function
- end
- end
- function PublicTable:GetMouseDrag1()
- return LocalTable.MouseDrag1
- end
- function PublicTable:MouseDrag2(Function)
- if Function == nil then
- LocalTable.MouseDrag2 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag2 = Function
- end
- end
- function PublicTable:GetMouseDrag2()
- return LocalTable.MouseDrag2
- end
- function PublicTable:MouseDrag3(Function)
- if Function == nil then
- LocalTable.MouseDrag3 = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.MouseDrag3 = Function
- end
- end
- function PublicTable:GetMouseDrag3()
- return LocalTable.MouseDrag3
- end
- function PublicTable:Button2Click(Function)
- if Function == nil then
- LocalTable.Button2Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button2Click = Function
- end
- end
- function PublicTable:GetButton2Click()
- return LocalTable.Button2Click
- end
- function PublicTable:Button3Click(Function)
- if Function == nil then
- LocalTable.Button3Click = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Button3Click = Function
- end
- end
- function PublicTable:GetButton3Click()
- return LocalTable.Button3Click
- end
- elseif Class == "TextBox" then
- function PublicTable:ActiveTextColor(Color)
- if type(Color) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Color), 2)
- end
- if VColors[Color] ~= true then
- error("Invalid color.", 2)
- end
- LocalTable.ActiveTextColor = Color
- end
- function PublicTable:EnterPress(Function)
- if Function == nil then
- LocalTable.EnterPress = nil
- else
- if type(Function) ~= "function" then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.EnterPress = Function
- end
- end
- function PublicTable:GetEnterPress()
- return LocalTable.EnterPress
- end
- function PublicTable:Overlap(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.Overlap = Bool
- end
- function PublicTable:GetOverlap()
- return LocalTable.Overlap
- end
- function PublicTable:ClearTextOnFocus(Bool)
- if type(Bool) ~= "boolean" then
- error("bad argument #1: boolean expected, got " .. type(Bool), 2)
- end
- LocalTable.ClearTextOnFocus = Bool
- end
- function PublicTable:GetClearTextOnFocus()
- return LocalTable.ClearTextOnFocus
- end
- function PublicTable:Focus()
- Main.MakeFocus = LocalTable
- os.queueEvent("")
- end
- function PublicTable:StopFocus()
- Main.StopFocus = true
- os.queueEvent("")
- end
- function PublicTable:TextChar(Char)
- if Char == nil then
- LocalTable.TextChar = nil
- else
- if type(Char) ~= "string" then
- error("bad argument #1: string expected, got " .. type(Char), 2)
- end
- LocalTable.TextChar = Char
- end
- end
- function PublicTable:GetTextChar()
- return LocalTable.TextChar
- end
- end
- function PublicTable:New(Class)
- return NewClass(LocalTable, Class, Main)
- end
- function PublicTable:Draw()
- local BG = Main.BackgroundColor
- local FoundBG = false
- local PX, PY = 1, 1
- local On = LocalTable.Parent
- while On ~= Main do
- PX = PX + On.Position[1] - 1
- PY = PY + On.Position[2] - 1
- if On.ShowBackground and FoundBG == false then
- BG = On.BackgroundColor
- FoundBG = true
- end
- On = On.Parent
- end
- Check(LocalTable, BG, PX, PY , true)
- end
- end
- LocalTable.Pub = PublicTable
- table.insert(Par.Children, LocalTable)
- function PublicTable:Destroy()
- for _,Object in pairs(Par.Children) do
- if LocalTable == Object then
- table.remove(Par.Children, _)
- break
- end
- end
- LocalTable = nil
- PublicTable = nil
- end
- return PublicTable
- end
- local function NewUI()
- local LocalTable = {}
- local PublicTable = {}
- LocalTable.BackgroundColor = colors.red
- LocalTable.Visible = true
- LocalTable.Active = true
- LocalTable.Children = {}
- LocalTable.Listening = false
- function PublicTable:BackgroundColor(Color)
- if type(Color) ~= "number" then
- error("bad argument #1: number expected, got " .. type(Color), 2)
- end
- if not VColors[Color] then
- error("Invalid color.", 2)
- end
- LocalTable.BackgroundColor = Color
- end
- function PublicTable:New(Class)
- return NewClass(LocalTable, Class, LocalTable)
- end
- function PublicTable:ClearChildren()
- LocalTable.Children = {}
- end
- function PublicTable:ErrorHandle(Function)
- if type(Function) ~= "function" and Function ~= nil then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.ErrorHandle = Function
- end
- function PublicTable:Output(Function)
- if type(Function) ~= "function" and Function ~= nil then
- error("bad argument #1: function expected, got " .. type(Function), 2)
- end
- LocalTable.Output = Function
- end
- function PublicTable:Listen()
- LocalTable.Listening = true
- local ActiveBox
- local LastClick1
- local LastClick2
- local LastClick3
- while LocalTable.Listening == true do
- local Event, P1, P2, P3, P4, P5 = os.pullEvent()
- if LocalTable.Listening == false then
- break
- end
- if LocalTable.MakeFocus then
- if ActiveBox then
- ActiveBox.Focused = false
- ActiveBox.StopFocus = nil
- term.setCursorBlink(false)
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- end
- ActiveBox = LocalTable.MakeFocus
- LocalTable.MakeFocus = nil
- ActiveBox.Focused = true
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- term.setCursorBlink(true)
- term.setTextColor(ActiveBox.TextColor)
- term.setCursorPos(unpack(ActiveBox.TextPos))
- end
- if ActiveBox and ActiveBox.StopFocus then
- ActiveBox.Focused = false
- ActiveBox.StopFocus = nil
- term.setCursorBlink(false)
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- if ActiveBox.EnterPress then
- ActiveBox.EnterPress()
- end
- ActiveBox = nil
- end
- if LocalTable.Output then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(LocalTable.Output, Event, P1, P2, P3, P4, P5)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- LocalTable.Output(Event, P1, P2, P3, P4, P5)
- end
- end
- if Event == "char" then
- if ActiveBox then
- ActiveBox.Text = ActiveBox.Text .. P1
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- term.setTextColor(ActiveBox.TextColor)
- term.setCursorPos(unpack(ActiveBox.TextPos))
- end
- elseif Event == "key" then
- if ActiveBox then
- if P1 == 14 then
- if #ActiveBox.Text > 0 then
- ActiveBox.Text = string.sub(ActiveBox.Text, 1, #ActiveBox.Text - 1)
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- term.setTextColor(ActiveBox.TextColor)
- term.setCursorPos(unpack(ActiveBox.TextPos))
- end
- elseif P1 == 28 then
- ActiveBox.Focused = false
- term.setCursorBlink(false)
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- if ActiveBox.EnterPress then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(ActiveBox.EnterPress)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- ActiveBox.EnterPress()
- end
- end
- ActiveBox = nil
- end
- end
- elseif Event == "mouse_scroll" then
- local PStop = false
- local Check
- function Check(Object, Par, PX, PY)
- if Object.Active == true then
- if PStop == true then return end
- if Object.Class == "TextLabel" or Object.Class == "TextButton" or Object.Class == "ImageButton" then
- if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
- if Object.MouseScroll then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.MouseScroll, P1)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.MouseScroll(P1)
- end
- PStop = true
- end
- end
- end
- for _,Object in pairs(SortListen(Object.Children)) do
- Check(Object, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
- end
- end
- end
- for _,Object in pairs(SortListen(LocalTable.Children)) do
- Check(Object, LocalTable, 1, 1)
- end
- elseif Event == "mouse_drag" then
- if P1 == 1 and LastClick1 then
- if LastClick1.MouseDrag1 then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(LastClick1.MouseDrag1, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- LastClick1.MouseDrag1(P2, P3)
- end
- end
- elseif P1 == 2 and LastClick2 then
- if LastClick2.MouseDrag2 then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.MouseDrag2, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.MouseDrag2(P2, P3)
- end
- end
- elseif P1 == 3 and LastClick3 then
- if LastClick3.MouseDrag3 then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.MouseDrag3, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.MouseDrag3(P2, P3)
- end
- end
- end
- elseif Event == "mouse_click" then
- LastClick1 = nil
- LastClick2 = nil
- LastClick3 = nil
- local PStop = false
- local StopFocus = true
- local Check
- function Check(Object, Par, PX, PY)
- if Object.Active == true then
- if PStop == true then return end
- if Object.Class == "TextButton" or Object.Class == "ImageButton" or Object.Class == "TextBox" then
- if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
- if ActiveBox and Object ~= ActiveBox then
- ActiveBox.Focused = false
- ActiveBox.StopFocus = nil
- term.setCursorBlink(false)
- if ActiveBox.Overlap == true then
- ActiveBox.Pub:Draw()
- else
- PublicTable:Draw()
- end
- if ActiveBox.EnterPress then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(ActiveBox.EnterPress)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- ActiveBox.EnterPress()
- end
- end
- ActiveBox = nil
- end
- if P1 == 1 then
- LastClick1 = Object
- if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button1Click then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.Button1Click, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.Button1Click(P2, P3)
- end
- elseif Object.Class == "TextBox" then
- ActiveBox = Object
- Object.Focused = true
- if Object.ClearTextOnFocus == true then
- Object.Text = ""
- end
- Object.RawText = ""
- Object.RTextPos = 6
- if Object.Overlap == true then
- Object.Pub:Draw()
- else
- PublicTable:Draw()
- end
- term.setCursorBlink(true)
- term.setTextColor(ActiveBox.TextColor)
- term.setCursorPos(unpack(Object.TextPos))
- end
- elseif P1 == 2 then
- LastClick2 = Object
- if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button2Click then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.Button2Click, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.Button2Click(P2, P3)
- end
- end
- elseif P1 == 3 then
- LastClick3 = Object
- if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button3Click then
- if LocalTable.ErrorHandle then
- local Success, Err = pcall(Object.Button3Click, P2, P3)
- if not Success then
- LocalTable.ErrorHandle(Err)
- end
- else
- Object.Button3Click(P2, P3)
- end
- end
- end
- PStop = true
- end
- end
- for _,Object2 in pairs(SortListen(Object.Children)) do
- Check(Object2, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
- end
- end
- end
- for _,Object in pairs(SortListen(LocalTable.Children)) do
- Check(Object, LocalTable, 1, 1)
- end
- end
- end
- end
- function PublicTable:StopListen()
- LocalTable.Listening = false
- end
- function PublicTable:Draw()
- term.setBackgroundColor(LocalTable.BackgroundColor)
- term.clear()
- for _,Item in ipairs(LocalTable.Children) do
- Check(Item, LocalTable.BackgroundColor, 1, 1)
- end
- end
- return PublicTable
- end
- -- End of alakazard12's Nova GUI API
- local tArgs = {...}
- local FilePath = table.concat(tArgs, " ")
- if FilePath then
- FilePath = shell.resolve(FilePath)
- end
- if FilePath == "" then
- FilePath = nil
- end
- local Debug = true
- local function LogText(Text)
- if Debug == true then
- if fs.exists("NCLog") then
- local File = fs.open("NCLog", "r")
- Text = File.readAll() .. "\n" .. Text
- File.close()
- end
- local File = fs.open("NCLog", "w")
- File.write(Text)
- File.close()
- end
- end
- local Logo = {[1]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[2]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[3]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=2,[19]=2,[20]=2,[21]=2,[22]=2,[23]=2,[24]=2,[25]=2,[26]=2,[27]=2,[28]=2,[29]=2,[30]=2,[31]=2,[32]=2,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[4]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=2,[18]=2,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=2,[33]=2,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[5]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=2,[18]=256,[19]=1,[20]=32768,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=32768,[31]=1,[32]=256,[33]=2,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[6]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[7]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=32768,[23]=32768,[24]=32768,[25]=32768,[26]=32768,[27]=32768,[28]=32768,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[8]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=16384,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=16384,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[9]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=16384,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=16384,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[10]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=2,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=2,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[11]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=2,[18]=2,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=2,[33]=2,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[12]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=2,[19]=2,[20]=2,[21]=2,[22]=2,[23]=2,[24]=2,[25]=2,[26]=2,[27]=2,[28]=2,[29]=2,[30]=2,[31]=2,[32]=2,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[13]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[14]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[15]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[16]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[17]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[18]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},}
- local plainColour = colors.white
- local syntaxColour = colors.cyan
- local stringColour = colors.red
- local backgroundColour = colors.gray
- local booleanColour = colors.blue
- local functionColour = colors.lightGray
- local ccColour = colors.yellow
- local commentColour = colors.lime
- term.setBackgroundColor(colors.gray)
- term.clear()
- paintutils.drawImage(Logo, 1, 1)
- term.setCursorPos(21, 17)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.gray)
- term.write("Nova Code")
- sleep(0.5)
- local MainUI = NewUI()
- MainUI:BackgroundColor(backgroundColour)
- local DDraw = MainUI:New("TextLabel")
- DDraw:Text("")
- DDraw:ShowBackground(false)
- DDraw:Size(51, 17)
- DDraw:Position(1, 2)
- local TBar = MainUI:New("TextLabel")
- TBar:Text("")
- TBar:Size(51, 1)
- TBar:Position(1, 1)
- TBar:BackgroundColor(colors.red)
- local Num = DDraw:New("TextLabel")
- Num:Text("")
- Num:Size(2, 18)
- Num:Position(1, 1)
- Num:BackgroundColor(colors.lightGray)
- local FileB = TBar:New("TextButton")
- FileB:Size(4, 1)
- FileB:Text("File")
- FileB:TextColor(colors.white)
- FileB:Position(2, 1)
- FileB:ShowBackground(false)
- local EditB = TBar:New("TextButton")
- EditB:Size(4, 1)
- EditB:Text("Edit")
- EditB:TextColor(colors.white)
- EditB:Position(8, 1)
- EditB:ShowBackground(false)
- local RunDB = TBar:New("TextButton")
- RunDB:Size(3, 1)
- RunDB:Text("Run")
- RunDB:TextColor(colors.white)
- RunDB:Position(14, 1)
- RunDB:ShowBackground(false)
- local FileM = MainUI:New("TextLabel")
- FileM:Size(20, 3)
- FileM:Position(2, 2)
- FileM:Text("")
- FileM:BackgroundColor(colors.white)
- FileM:ZIndex(5)
- FileM:Visible(false)
- FileM:Active(false)
- local SaveB = FileM:New("TextButton")
- SaveB:Size(20, 1)
- SaveB:ShowBackground(false)
- SaveB:TextColor(colors.black)
- SaveB:Text(" Save S")
- SaveB:TextXAlignment(0)
- local SaveAB = FileM:New("TextButton")
- SaveAB:Size(20, 1)
- SaveAB:ShowBackground(false)
- SaveAB:TextColor(colors.black)
- SaveAB:Text(" Save As")
- SaveAB:TextXAlignment(0)
- SaveAB:Position(1, 2)
- local ExitB = FileM:New("TextButton")
- ExitB:Size(20, 1)
- ExitB:ShowBackground(false)
- ExitB:TextColor(colors.black)
- ExitB:Text(" Exit Q")
- ExitB:TextXAlignment(0)
- ExitB:Position(1, 3)
- local EditM = MainUI:New("TextLabel")
- EditM:Size(20, 3)
- EditM:Position(8, 2)
- EditM:Text("")
- EditM:BackgroundColor(colors.white)
- EditM:ZIndex(5)
- EditM:Active(false)
- EditM:Visible(false)
- local CopyLB = EditM:New("TextButton")
- CopyLB:Size(20, 1)
- CopyLB:ShowBackground(false)
- CopyLB:TextColor(colors.black)
- CopyLB:Text(" Copy Line C")
- CopyLB:TextXAlignment(0)
- local PasteB = EditM:New("TextButton")
- PasteB:Size(20, 1)
- PasteB:ShowBackground(false)
- PasteB:TextColor(colors.black)
- PasteB:Text(" Paste P")
- PasteB:TextXAlignment(0)
- PasteB:Position(1, 2)
- local DeleteB = EditM:New("TextButton")
- DeleteB:Size(20, 1)
- DeleteB:ShowBackground(false)
- DeleteB:TextColor(colors.black)
- DeleteB:Text(" Delete Line D")
- DeleteB:TextXAlignment(0)
- DeleteB:Position(1, 3)
- local RunM = MainUI:New("TextLabel")
- RunM:Size(20, 2)
- RunM:Position(14, 2)
- RunM:Text("")
- RunM:BackgroundColor(colors.white)
- RunM:ZIndex(5)
- RunM:Active(false)
- RunM:Visible(false)
- local RunB = RunM:New("TextButton")
- RunB:Size(20, 1)
- RunB:ShowBackground(false)
- RunB:TextColor(colors.black)
- RunB:Text(" Run R")
- RunB:TextXAlignment(0)
- local RunAB = RunM:New("TextButton")
- RunAB:Size(20, 1)
- RunAB:ShowBackground(false)
- RunAB:TextColor(colors.black)
- RunAB:Text(" Run With Args A")
- RunAB:TextXAlignment(0)
- RunAB:Position(1, 2)
- local SaveAM = MainUI:New("TextLabel")
- SaveAM:Size(41, 9)
- SaveAM:Position(5, 5)
- SaveAM:Text("Save As")
- SaveAM:TextYAlignment(0)
- SaveAM:BackgroundColor(colors.white)
- SaveAM:TextColor(colors.black)
- local PathT = SaveAM:New("TextLabel")
- PathT:Text("Path:")
- PathT:Size(5, 1)
- PathT:TextColor(colors.black)
- PathT:ShowBackground(false)
- PathT:Position(2, 4)
- local PathInput = SaveAM:New("TextBox")
- PathInput:Text(FilePath or "")
- PathInput:Position(8, 4)
- PathInput:Size(32, 1)
- PathInput:BackgroundColor(colors.gray)
- PathInput:ActiveTextColor(colors.lightGray)
- PathInput:TextColor(colors.white)
- PathInput:Overlap(true)
- PathInput:TextXAlignment(0)
- local SavePT = SaveAM:New("TextButton")
- SavePT:Text("Save")
- SavePT:Size(6, 1)
- SavePT:BackgroundColor(colors.lightGray)
- SavePT:TextColor(colors.black)
- SavePT:Position(15, 7)
- local CancelPT = SaveAM:New("TextButton")
- CancelPT:Text("Cancel")
- CancelPT:Size(8, 1)
- CancelPT:BackgroundColor(colors.lightGray)
- CancelPT:TextColor(colors.black)
- CancelPT:Position(22, 7)
- SaveAM:Visible(false)
- SaveAM:Active(false)
- local RunAM = MainUI:New("TextLabel")
- RunAM:Size(41, 9)
- RunAM:Position(5, 5)
- RunAM:Text("Run With Args")
- RunAM:TextYAlignment(0)
- RunAM:BackgroundColor(colors.white)
- RunAM:TextColor(colors.black)
- local ArgT = RunAM:New("TextLabel")
- ArgT:Text("Args:")
- ArgT:Size(5, 1)
- ArgT:TextColor(colors.black)
- ArgT:ShowBackground(false)
- ArgT:Position(2, 4)
- local ArgInput = RunAM:New("TextBox")
- ArgInput:Text(FilePath or "")
- ArgInput:Position(8, 4)
- ArgInput:Size(32, 1)
- ArgInput:BackgroundColor(colors.gray)
- ArgInput:ActiveTextColor(colors.lightGray)
- ArgInput:TextColor(colors.white)
- ArgInput:Overlap(true)
- ArgInput:TextXAlignment(0)
- local RunPT = RunAM:New("TextButton")
- RunPT:Text("Run")
- RunPT:Size(6, 1)
- RunPT:BackgroundColor(colors.lightGray)
- RunPT:TextColor(colors.black)
- RunPT:Position(15, 7)
- local CancelPRT = RunAM:New("TextButton")
- CancelPRT:Text("Cancel")
- CancelPRT:Size(8, 1)
- CancelPRT:BackgroundColor(colors.lightGray)
- CancelPRT:TextColor(colors.black)
- CancelPRT:Position(22, 7)
- RunAM:Visible(false)
- RunAM:Active(false)
- local ErrorM = MainUI:New("TextLabel")
- ErrorM:Size(35, 6)
- ErrorM:Text("")
- ErrorM:BackgroundColor(colors.white)
- ErrorM:ShowText(false)
- ErrorM:Position(8, 7)
- local ErrorTitle = ErrorM:New("TextLabel")
- ErrorTitle:TextColor(colors.white)
- ErrorTitle:Size(35, 1)
- ErrorTitle:BackgroundColor(colors.lightGray)
- local EMessage = ErrorM:New("TextLabel")
- EMessage:Size(33, 2)
- EMessage:ShowBackground(false)
- EMessage:TextColor(colors.red)
- EMessage:Text("")
- EMessage:MultiLine(true)
- EMessage:Position(2, 3)
- local DoneB = ErrorM:New("TextButton")
- DoneB:Text("Done")
- DoneB:Size(6, 1)
- DoneB:Position(15, 5)
- DoneB:BackgroundColor(colors.lightGray)
- DoneB:TextColor(colors.black)
- ErrorM:Visible(false)
- ErrorM:Active(false)
- --[[
- local VBar = MainUI:New("TextLabel")
- VBar:Size(1, 16)
- VBar:Position(51, 2)
- VBar:BackgroundColor(colors.lightGray)
- VBar:Text("")
- local VScroll = VBar:New("TextButton")
- VScroll:Size(1, 5)
- VScroll:Position(1, 2)
- VScroll:BackgroundColor(colors.black)
- VScroll:Text("")
- local VUp = VBar:New("TextButton")
- VUp:Size(1, 1)
- VUp:Position(1, 1)
- VUp:BackgroundColor(colors.black)
- VUp:Text("^")
- local VDown = VBar:New("TextButton")
- VDown:Size(1, 1)
- VDown:Position(1, 17)
- VDown:BackgroundColor(colors.black)
- VDown:Text("v")
- local HBar = MainUI:New("TextLabel")
- HBar:Size(50, 1)
- HBar:Position(1, 19)
- HBar:BackgroundColor(colors.lightGray)
- HBar:Text("")
- local HScroll = HBar:New("TextButton")
- HScroll:Size(8, 1)
- HScroll:Position(2, 1)
- HScroll:BackgroundColor(colors.black)
- HScroll:Text("")
- local HLeft = HBar:New("TextButton")
- HLeft:Size(1, 1)
- HLeft:Position(1, 1)
- HLeft:BackgroundColor(colors.black)
- HLeft:Text("<")
- local HRight = HBar:New("TextButton")
- HRight:Size(1, 1)
- HRight:Position(50, 1)
- HRight:BackgroundColor(colors.black)
- HRight:Text(">")]]
- local NLines = {}
- for i = 1, 18 do
- local NewLine = Num:New("TextLabel")
- NewLine:Text("")
- NewLine:Size(2, 1)
- NewLine:ShowBackground(false)
- NewLine:TextColor(colors.black)
- NewLine:Position(1, i)
- NewLine:TextXAlignment(0)
- NLines[i] = NewLine
- end
- local TLines = {}
- local NWidth = 2
- local TWidth = 48
- local VWidth = 18
- local ScrollV = 1
- local ScrollH = 1
- local EditLine = 1
- local EditX = 0
- local EditNLine = 1
- local EditNX = 0
- local EditText = ""
- local CursorPosX = 1
- local CursorPosY = 1
- local Format = {
- ["Seclude"] = {
- ["end"] = syntaxColour;
- ["while"] = syntaxColour;
- ["true"] = booleanColour;
- ["false"] = booleanColour;
- ["if"] = syntaxColour;
- ["do"] = syntaxColour;
- ["for"] = syntaxColour;
- ["in"] = syntaxColour;
- ["function"] = syntaxColour;
- ["local"] = syntaxColour;
- ["and"] = syntaxColour;
- ["or"] = syntaxColour;
- ["else"] = syntaxColour;
- ["elseif"] = syntaxColour;
- ["break"] = syntaxColour;
- ["nil"] = booleanColour;
- ["not"] = syntaxColour;
- ["repeat"] = syntaxColour;
- ["return"] = syntaxColour;
- ["then"] = syntaxColour;
- ["until"] = syntaxColour;
- ["print"] = functionColour;
- ["table.insert"] = functionColour;
- ["table.remove"] = functionColour;
- }
- }
- local function FormText(Text)
- local New = {}
- local LastM = 0
- local stringStart1
- local stringStart2
- local commentStart1
- for i = 1, #Text do
- if Text:sub(i, i) == '"' and Text:sub(i - 1, i - 1) ~= "\\" and not ((stringStart2 and not stringStart1) or commentStart1) then
- if stringStart1 then
- table.insert(New, {Text:sub(stringStart1, i), stringColour})
- LastM = i
- stringStart1 = nil
- else
- stringStart1 = i
- if LastM and i ~= 1 then
- table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
- end
- LastM = i - 1
- end
- end
- if Text:sub(i, i) == "'" and Text:sub(i - 1, i - 1) ~= "\\" and not ((stringStart1 and not stringStart2) or commentStart1) then
- if stringStart2 then
- table.insert(New, {Text:sub(stringStart2, i), stringColour})
- LastM = i
- stringStart2 = nil
- else
- stringStart2 = i
- if LastM and i ~= 1 then
- table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
- end
- LastM = i - 1
- end
- end
- if Text:sub(i, i) == "-" and Text:sub(i - 1, i - 1) == "-" and not (stringStart2 or stringStart1) then
- commentStart1 = i - 1
- if LastM and i ~= 1 then
- table.insert(New, {Text:sub(LastM + 1, i - 2), plainColour})
- end
- LastM = i - 2
- end
- if not stringStart1 and not stringStart2 and not commentStart1 then
- for r,v in pairs(Format["Seclude"]) do
- if Text:sub(i, #r + i - 1) == r then
- if i == 1 or Text:sub(i - 1, i - 1) == " " or Text:sub(i - 1, i - 1) == ")" or Text:sub(i - 1, i - 1) == "(" or Text:sub(i - 1, i - 1) == "]" or Text:sub(i - 1, i - 1) == "[" then
- if i + #r - 1 == #Text or Text:sub(i + #r, i + #r) == " " or Text:sub(i + #r, i + #r) == "(" or Text:sub(i + #r, i + #r) == ")" or Text:sub(i + #r, i + #r) == "[" or Text:sub(i + #r, i + #r) == "]" then
- if LastM and i ~= 1 then
- table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
- end
- table.insert(New, {Text:sub(i, #r + i - 1), v})
- LastM = i + #r - 1
- end
- end
- end
- end
- end
- end
- if LastM then
- if commentStart1 then
- table.insert(New, {Text:sub(LastM + 1, #Text), commentColour})
- elseif stringStart1 or stringStart2 then
- table.insert(New, {Text:sub(LastM + 1, #Text), stringColour})
- else
- table.insert(New, {Text:sub(LastM + 1, #Text), plainColour})
- end
- end
- return New
- end
- local function DisplayLine(FormatTextT, Line)
- term.setCursorPos(1, Line + 1)
- term.setBackgroundColor(backgroundColour)
- term.clearLine()
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(NWidth + 1, Line + 1)
- local LWrote = 0
- local NewT = {}
- local MWrote = 0
- for i,v in pairs(FormatTextT) do
- if MWrote >= ScrollH - 1 then
- table.insert(NewT, {v[1], v[2]})
- elseif #v[1] + MWrote >= ScrollH - 1 then
- if #v[1] + MWrote > ScrollH - 1 then
- table.insert(NewT, {v[1]:sub(ScrollH - MWrote, #v[1]), v[2]})
- end
- MWrote = MWrote + #v[1]
- else
- MWrote = MWrote + #v[1]
- end
- end
- for i,v in pairs(NewT) do
- if LWrote + #v[1] > TWidth then
- if LWrote < TWidth then
- v[1] = v[1]:sub(1, TWidth - LWrote)
- term.setTextColor(v[2])
- term.write(v[1])
- LWrote = LWrote + #v[1]
- end
- else
- term.setTextColor(v[2])
- term.write(v[1])
- LWrote = LWrote + #v[1]
- end
- end
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- term.setCursorBlink(true)
- end
- local function DisplayLines()
- for i = 0, 17 do
- local v = TLines[i + ScrollV]
- if not v then
- for m = i + 1, 18 do
- NLines[m]:Text("")
- end
- break
- end
- NLines[i + 1]:Text(tostring(i + ScrollV))
- local TempT = v
- DisplayLine(FormText(TempT), i + 1)
- end
- Num:Draw()
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- term.setCursorBlink(true)
- end
- local function CheckScroll()
- local DT = false
- if EditNX > TWidth then
- EditNX = EditNX - 1
- ScrollH = ScrollH + 1
- if not CheckScroll() then
- DisplayLines()
- end
- DT = true
- elseif EditNX < 0 then
- EditNX = EditNX + 1
- ScrollH = ScrollH - 1
- if not CheckScroll() then
- DisplayLines()
- end
- DT = true
- end
- if EditNLine < 1 then
- EditNLine = EditNLine + 1
- ScrollV = ScrollV - 1
- --[[local Line = TLines[EditLine]
- local Ratio = (ScrollV - 1) / (#Line - VWidth)
- VScroll:Position((14-5) * Ratio + 2, 1)
- HBar:Draw()]]
- if not CheckScroll() then
- DisplayLines()
- end
- DT = true
- elseif EditNLine > VWidth then
- EditNLine = EditNLine - 1
- ScrollV = ScrollV + 1
- if not CheckScroll() then
- DisplayLines()
- end
- DT = true
- end
- if NWidth ~= #tostring(#TLines)+ 1 then
- NWidth = #tostring(#TLines) + 1
- TWidth = 51 - NWidth
- Num:Size(NWidth, 18)
- for i,v in pairs(NLines) do
- v:Size(NWidth, 1)
- end
- MainUI:Draw()
- DisplayLines()
- DT = true
- end
- return DT
- end
- local ActiveMenu
- local function CloseMenu()
- ActiveMenu:Visible(false)
- ActiveMenu:Active(false)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveMenu = nil
- end
- local function OpenMenu(Menu)
- if Menu == ActiveMenu then
- CloseMenu()
- else
- if ActiveMenu then
- ActiveMenu:Visible(false)
- ActiveMenu:Active(false)
- end
- Menu:Visible(true)
- Menu:Active(true)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- Menu:Draw()
- term.setCursorBlink(false)
- ActiveMenu = Menu
- end
- end
- local ActiveSave
- local SaveTog
- local function SaveATog()
- PathInput:Text(FilePath or "")
- FileB:Active(false)
- EditB:Active(false)
- RunDB:Active(false)
- SaveAM:Visible(true)
- SaveAM:Active(true)
- ActiveSave = true
- CloseMenu()
- term.setCursorBlink(false)
- SaveAM:Draw()
- end
- local function ErrorT(Title, Text)
- if ActiveMenu then
- CloseMenu()
- ErrorM:Draw()
- end
- ErrorTitle:Text(Title)
- EMessage:Text(Text)
- ErrorM:Visible(true)
- ErrorM:Active(true)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- ErrorM:Draw()
- ActiveSave = true
- FileB:Active(false)
- EditB:Active(false)
- RunDB:Active(false)
- term.setCursorBlink(false)
- end
- function SaveTog()
- if not FilePath then
- SaveATog()
- else
- local File = fs.open(FilePath, "w")
- for i,v in pairs(TLines) do
- File.writeLine(v)
- end
- File.close()
- end
- if ActiveMenu then
- CloseMenu()
- end
- end
- MainUI:ErrorHandle(function(Err) ErrorT("Error", Err) end)
- SavePT:Button1Click(function()
- FilePath = fs.combine(PathInput:GetText(), "")
- if FilePath and FilePath ~= "" then
- SaveAM:Visible(false)
- SaveAM:Active(false)
- FileB:Active(true)
- EditB:Active(true)
- RunDB:Active(true)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveSave = false
- SaveTog()
- else
- FilePath = nil
- end
- end)
- CancelPT:Button1Click(function()
- SaveAM:Visible(false)
- SaveAM:Active(false)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveSave = false
- FileB:Active(true)
- EditB:Active(true)
- RunDB:Active(true)
- end)
- DoneB:Button1Click(function()
- ErrorM:Visible(false)
- ErrorM:Active(false)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveSave = false
- FileB:Active(true)
- EditB:Active(true)
- RunDB:Active(true)
- end)
- local Clip
- local function Copy()
- local Line = TLines[EditLine]
- Clip = Line
- CloseMenu()
- end
- local function Delete()
- CloseMenu()
- if #TLines == 1 then
- TLines[1] = ""
- else
- table.remove(TLines, EditLine)
- end
- EditX = 0
- EditNX = 0
- ScrollH = 1
- if not TLines[EditLine] then
- EditLine = EditLine - 1
- EditNLine = EditNLine - 1
- end
- MainUI:Draw()
- if not (CheckScroll()) then
- DisplayLines()
- Num:Draw()
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- term.setCursorBlink(true)
- end
- end
- local function Paste()
- CloseMenu()
- if Clip then
- local Line = TLines[EditLine]
- if Line == "" then
- Line = Clip
- elseif EditX == 0 then
- Line = Clip .. Line
- elseif EditX == #Line then
- Line = Line .. Clip
- else
- Line = Line:sub(0, EditX) .. Clip .. Line:sub(EditX + 1, #Line)
- end
- EditX = EditX + #Clip
- EditNX = EditNX + #Clip
- TLines[EditLine] = Line
- DisplayLine(FormText(Line), EditNLine)
- Num:Draw()
- CheckScroll()
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- term.setCursorBlink(true)
- end
- end
- local function Run(...)
- if ActiveMenu then
- CloseMenu()
- end
- local Str = TLines[1]
- for i,v in pairs(TLines) do
- if i > 1 then
- Str = Str .. "\n" .. v
- end
- end
- local Func, Err = loadstring(Str, FilePath or "Untitled")
- if not Func then
- ErrorT("Error", Err)
- else
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
- local Success, Err = pcall(Func, ...)
- print("Press any key to continue...")
- os.pullEvent("key")
- sleep(0)
- if not Success then
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- ErrorT("Error", Err)
- else
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- end
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- end
- end
- RunPT:Button1Click(function()
- RunAM:Visible(false)
- RunAM:Active(false)
- FileB:Active(true)
- EditB:Active(true)
- RunDB:Active(true)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveSave = false
- local Args = {}
- for Arg in ArgInput:GetText():gmatch("([^ ]+)") do
- table.insert(Args, Arg)
- end
- Run(unpack(Args))
- end)
- CancelPRT:Button1Click(function()
- RunAM:Visible(false)
- RunAM:Active(false)
- MainUI:Draw()
- DisplayLines()
- Num:Draw()
- term.setCursorBlink(true)
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- ActiveSave = false
- FileB:Active(true)
- EditB:Active(true)
- RunDB:Active(true)
- end)
- local function RunA()
- ArgInput:Text("")
- FileB:Active(false)
- EditB:Active(false)
- RunDB:Active(false)
- RunAM:Visible(true)
- RunAM:Active(true)
- ActiveSave = true
- CloseMenu()
- term.setCursorBlink(false)
- RunAM:Draw()
- end
- RunB:Button1Click(function() Run() end)
- RunAB:Button1Click(RunA)
- CopyLB:Button1Click(Copy)
- DeleteB:Button1Click(Delete)
- PasteB:Button1Click(Paste)
- FileB:Button1Click(function() OpenMenu(FileM) end)
- EditB:Button1Click(function() OpenMenu(EditM) end)
- RunDB:Button1Click(function() OpenMenu(RunM) end)
- SaveB:Button1Click(function() SaveTog() end)
- SaveAB:Button1Click(function() SaveATog() end)
- local function Quit()
- MainUI:StopListen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- sleep(0.1)
- end
- local function OutputF(Event, P1, P2, P3)
- if not ActiveSave then
- if not ActiveMenu then
- if Event == "char" then
- local Line = TLines[EditLine]
- if Line == "" then
- Line = P1
- elseif EditX == 0 then
- Line = P1 .. Line
- elseif EditX == #Line then
- Line = Line .. P1
- else
- Line = Line:sub(0, EditX) .. P1 .. Line:sub(EditX + 1, #Line)
- end
- EditX = EditX + 1
- EditNX = EditNX + 1
- TLines[EditLine] = Line
- DisplayLine(FormText(Line), EditNLine)
- CheckScroll()
- elseif Event == "key" then
- if P1 == 15 then
- local Line = TLines[EditLine]
- if Line == "" then
- Line = " "
- elseif EditX == 0 then
- Line = " " .. Line
- elseif EditX == #Line then
- Line = Line .. " "
- else
- Line = Line:sub(0, EditX) .. " " .. Line:sub(EditX + 1, #Line)
- end
- EditX = EditX + 2
- EditNX = EditNX + 2
- TLines[EditLine] = Line
- DisplayLine(FormText(Line), EditNLine)
- CheckScroll()
- elseif P1 == 14 then
- if EditX ~= 0 then
- local Line = TLines[EditLine]
- Line = Line:sub(1, EditX - 1) .. Line:sub(EditX + 1, #Line)
- TLines[EditLine] = Line
- EditX = EditX - 1
- EditNX = EditNX - 1
- DisplayLine(FormText(Line), EditNLine)
- CheckScroll()
- elseif EditLine ~= 1 then
- local Line = TLines[EditLine]
- local Line2 = TLines[EditLine - 1]
- EditNX = #Line2 - ScrollH + 1
- EditX = #Line2
- Line2 = Line2 .. Line
- TLines[EditLine - 1] = Line2
- table.remove(TLines, EditLine)
- EditLine = EditLine - 1
- EditNLine = EditNLine - 1
- --[[if #TLines < VWidth then
- VWidth = VWidth - 1
- end ]]
- term.clear()
- MainUI:Draw()
- CheckScroll()
- DisplayLines()
- end
- elseif P1 == 28 then
- local Line = TLines[EditLine]
- local Amount = 0
- if Line:sub(1, 1) == " " then
- local On = 1
- repeat
- Amount = Amount + 1
- On = On + 1
- until Line:sub(On, On) ~= " "
- end
- local New = Line:sub(EditX + 1)
- if EditX >= Amount then
- New = string.rep(" ", Amount) .. Line:sub(EditX + 1)
- end
- Line = Line:sub(1, EditX)
- TLines[EditLine] = Line
- table.insert(TLines, EditLine + 1, New)
- if EditX >= Amount then
- EditX = Amount
- EditNX = Amount
- else
- EditX = 0
- EditNX = 0
- end
- ScrollH = 1
- EditNLine = EditNLine + 1
- EditLine = EditLine + 1
- --[[if VWidth ~= 17 then
- VWidth = VWidth + 1
- end ]]
- term.clear()
- MainUI:Draw()
- CheckScroll()
- DisplayLines()
- elseif P1 == 203 then
- if EditX ~= 0 then
- EditX = EditX - 1
- EditNX = EditNX - 1
- CheckScroll()
- end
- elseif P1 == 205 then
- if EditX ~= #TLines[EditLine] then
- EditX = EditX + 1
- EditNX = EditNX + 1
- CheckScroll()
- end
- elseif P1 == 200 then
- if EditLine ~= 1 then
- EditLine = EditLine - 1
- EditNLine = EditNLine - 1
- if EditX > #TLines[EditLine] then
- local Dif = EditX - #TLines[EditLine]
- EditX = #TLines[EditLine]
- EditNX = EditNX - Dif
- end
- CheckScroll()
- end
- elseif P1 == 208 then
- if EditLine ~= #TLines then
- EditLine = EditLine + 1
- EditNLine = EditNLine + 1
- if EditX > #TLines[EditLine] then
- local Dif = EditX - #TLines[EditLine]
- EditX = #TLines[EditLine]
- EditNX = EditNX - Dif
- end
- CheckScroll()
- end
- elseif P1 == 29 then
- OpenMenu(FileM)
- return
- elseif P1 == 209 then
- if EditLine ~= #TLines then
- local Push = 35
- if #TLines - EditLine < 35 then
- Push = #TLines - EditLine
- end
- EditLine = EditLine + Push
- EditNLine = EditNLine + Push
- CheckScroll()
- end
- elseif P1 == 207 and EditX ~= #TLines[EditLine] then
- EditNX = EditNX + (#TLines[EditLine] - EditX)
- EditX = #TLines[EditLine]
- CheckScroll()
- elseif P1 == 201 and EditLine ~= 1 then
- local Push = 35
- if EditLine <= 35 then
- Push = EditLine - 1
- end
- EditLine = EditLine - Push
- EditNLine = EditNLine - Push
- CheckScroll()
- elseif P1 == 199 then
- EditNX = 0
- ScrollH = 1
- EditX = 0
- if not CheckScroll() then
- DisplayLines()
- end
- elseif P1 == 211 then
- if EditX ~= #TLines[EditLine] then
- local Line = TLines[EditLine]
- Line = Line:sub(1, EditX) .. Line:sub(EditX + 2, #Line)
- TLines[EditLine] = Line
- EditX = EditX
- EditNX = EditNX
- DisplayLine(FormText(Line), EditNLine)
- CheckScroll()
- elseif EditLine ~= #TLines then
- local Line = TLines[EditLine]
- local Line2 = TLines[EditLine + 1]
- --EditNX = #Line2 - ScrollH + 1
- --EditX = #Line2
- Line = Line .. Line2
- TLines[EditLine] = Line
- table.remove(TLines, EditLine + 1)
- --[[if #TLines < VWidth then
- VWidth = VWidth - 1
- end ]]
- term.clear()
- MainUI:Draw()
- CheckScroll()
- DisplayLines()
- end
- end
- elseif Event == "mouse_click" and P3 > 1 then
- local NewLine = ScrollV + P3 - 2
- local NewNLine = P3 - 1
- if NewLine > #TLines then
- NewNLine = NewNLine - (NewLine - #TLines)
- NewLine = #TLines
- end
- EditLine = NewLine
- EditNLine = NewNLine
- local NewX = P2 + ScrollH - NWidth - 2
- local NewNX = P2 - 1 - NWidth
- if NewX < 1 then
- NewX = 0
- NewNX = 0
- end
- if #TLines[EditLine] < NewX then
- NewNX = NewNX - (NewX - #TLines[EditLine])
- NewX = #TLines[EditLine]
- end
- EditX = NewX
- EditNX = NewNX
- CheckScroll()
- end
- Num:Draw()
- term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
- term.setCursorBlink(true)
- elseif Event == "key" then
- if P1 == 29 then
- CloseMenu()
- elseif P1 == 205 then
- if ActiveMenu == FileM then
- OpenMenu(EditM)
- elseif ActiveMenu == EditM then
- OpenMenu(RunM)
- elseif ActiveMenu == RunM then
- OpenMenu(FileM)
- end
- elseif P1 == 203 then
- if ActiveMenu == FileM then
- OpenMenu(RunM)
- elseif ActiveMenu == EditM then
- OpenMenu(FileM)
- elseif ActiveMenu == RunM then
- OpenMenu(EditM)
- end
- elseif ActiveMenu == FileM then
- if P1 == 31 then
- SaveTog()
- elseif P1 == 16 then
- Quit()
- end
- elseif ActiveMenu == EditM then
- if P1 == 46 then
- Copy()
- sleep(0)
- elseif P1 == 25 then
- Paste()
- sleep(0)
- elseif P1 == 32 then
- Delete()
- sleep(0)
- end
- end
- end
- end
- end
- MainUI:Output(OutputF)
- MainUI:Draw()
- TLines[1] = ""
- if FilePath and fs.exists(FilePath) and not fs.isDir(FilePath) then
- TLines = {}
- local File = fs.open(FilePath, "r")
- local Line
- repeat
- Line = File.readLine()
- if Line then
- table.insert(TLines, Line)
- end
- until Line == nil
- end
- DisplayLines()
- MainUI:Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement