Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("bapi")
- local mag = peripheral.wrap("bottom")
- local pim = peripheral.wrap("pim_1")
- local chest = peripheral.wrap("container_chest_1")
- -- Nova GUI API lightweight edition. By alakazard12
- -- Feel free to use this as long as you give me credit, but there's no documentation yet
- 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.pullEventRaw()
- 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 IsConnected = bapi.connect()
- local W, H = term.getSize()
- local MainUI = NewUI()
- MainUI:BackgroundColor(colors.white)
- local Title = MainUI:New("TextLabel")
- Title:Size(W, 1)
- Title:Text("Withdraw from YeuaBank")
- Title:BackgroundColor(colors.gray)
- Title:TextColor(colors.white)
- local Stat = MainUI:New("TextLabel")
- Stat:Size(W, 1)
- Stat:Text("")
- Stat:ShowBackground(false)
- Stat:Position(1, H)
- local BSizeX = math.floor((W - 2) / 5 - 2)
- local BSizeY = math.floor((H - 1) / 4 - 1)
- local TakeUpX = 5 * (BSizeX + 1) + 1
- local TakeUpY = 4 * (BSizeY + 1) + 2
- for i = 0, 19 do
- local But = MainUI:New("TextButton")
- But:Size(BSizeX, BSizeY)
- But:BackgroundColor(colors.gray)
- But:Text(tostring((i + 1) * 5))
- But:TextColor(colors.green)
- But:Position(((i % 5) * (BSizeX + 1)) + (W - TakeUpX) / 2 + 2, (math.floor(i / 5) * (BSizeY + 1) + 2) + (H - TakeUpY) / 2 + 1)
- But:Button1Click(function()
- local num = i + 1
- local am = num * 5
- Stat:TextColor(colors.green)
- Stat:Text("Please swipe your card")
- Stat:Draw()
- local _,Data = os.pullEvent("mag_swipe")
- if #Data == 16 and pim.getInventoryName() ~= "pim" then
- local chestAmount = 0
- local Stacks = {}
- for _,Item in pairs(chest.getAllStacks()) do
- chestAmount = chestAmount + Item.qty
- table.insert(Stacks, {_, Item})
- end
- table.sort(Stacks, function(f, l)
- return f[2].qty > l[2].qty
- end)
- local slotsUsedT = 0
- local slotsUsed
- local tempAmount = 0
- for _,Stack in pairs(Stacks) do
- tempAmount = tempAmount + Stack[2].qty
- slotsUsedT = slotsUsedT + 1
- if tempAmount >= num and slotsUsed == nil then
- slotsUsed = slotsUsedT
- end
- end
- if chestAmount < num then
- Stat:TextColor(colors.red)
- Stat:Text("I don't have enough money to give you")
- Stat:Draw()
- sleep(3)
- else
- local playerSlotsFree = {}
- for On = 1, pim.getInventorySize() do
- if not pim.getStackInSlot(On) then
- table.insert(playerSlotsFree, On)
- end
- end
- if #playerSlotsFree < slotsUsed then
- Stat:TextColor(colors.red)
- Stat:Text("You don't have enough slots empty (" .. #playerSlotsFree .. "/" .. slotsUsed .. ")")
- Stat:Draw()
- sleep(3)
- else
- local Suc, Err = bapi.transact(Data, "void", am)
- if not Suc then
- Stat:TextColor(colors.red)
- Stat:Text("Error: " .. Err)
- Stat:Draw()
- sleep(2)
- else
- for On = 1, num do
- -- pim.pullItem("down", playerSlotsFree[On], 0, Stacks[_][1])
- chest.pushItem("up", Stacks[On][1], 64, playerSlotsFree[On])
- end
- Stat:TextColor(colors.green)
- Stat:Text("Success")
- Stat:Draw()
- sleep(2)
- end
- end
- end
- end
- Stat:Text("")
- Stat:Draw()
- end)
- end
- MainUI:Draw()
- MainUI:Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement