Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _mon = peripheral.wrap("monitor_0")
- local _w, _h = _mon.getSize()
- local _back = peripheral.wrap("back")
- local _top = peripheral.wrap("top")
- local _front = peripheral.wrap("front")
- local _bottom = peripheral.wrap("bottom")
- local _right = peripheral.wrap("right")
- local _left = peripheral.wrap("left")
- local _Save = false
- CCInterfaceEntities = {
- List = {},
- ListSave = {},
- Add = function(_entity)
- table.insert(CCInterfaceEntities.List, _entity)
- end,
- Remove = function(_entity)
- for k, v in pairs(CCInterfaceEntities.List) do
- if tostring(v) == tostring(_entity) then
- table.remove(CCInterfaceEntities.List, tonumber(k))
- break
- end
- end
- end,
- Toggle = function(_entity)
- local remove = false
- for _l, _v in ipairs(CCInterfaceEntities.List) do
- if tostring(_v) == tostring(_entity) then
- table.remove(CCInterfaceEntities.List, _l)
- remove = true
- break
- end
- end
- if remove == false then
- table.insert(CCInterfaceEntities.List, _entity)
- end
- end,
- RemoveAll = function(_List)
- local k = next(_List)
- while k do
- _List[k] = nil
- k = next(_List)
- end
- end,
- Save = function()
- for k, v in pairs(CCInterfaceEntities.List) do
- table.insert(CCInterfaceEntities.ListSave, v)
- end
- CCInterfaceArea.RemoveAll(CCInterfaceEntities.List)
- _Save = true
- end,
- Load = function()
- if _Save == true then
- CCInterfaceArea.RemoveAll(CCInterfaceEntities.List)
- for k, v in pairs(CCInterfaceEntities.ListSave) do
- table.insert(CCInterfaceEntities.List, v)
- end
- CCInterfaceArea.RemoveAll(CCInterfaceEntities.ListSave)
- end
- _Save = false
- end
- }
- CCInterfaceArea = {
- List = {},
- ListSave = {},
- Add = function(_area)
- table.insert(CCInterfaceArea.List, _area)
- end,
- Remove = function(_area)
- for k, v in pairs(CCInterfaceArea.List) do
- if tostring(v) == tostring(_area) then
- table.remove(CCInterfaceArea.List, tonumber(k))
- break
- end
- end
- end,
- Toggle = function(_area)
- local remove = true
- for _l, _v in pairs(CCInterfaceArea.List) do
- if tostring(_v) == tostring(_area) then
- table.remove(CCInterfaceArea.List, tonumber(_l))
- remove = false
- break
- end
- end
- if remove == true then
- table.insert(CCInterfaceArea.List, _entity)
- end
- end,
- RemoveAll = function(_List)
- local k = next(_List)
- while k do
- _List[k] = nil
- k = next(_List)
- end
- end,
- Save = function()
- for k, v in pairs(CCInterfaceArea.List) do
- table.insert(CCInterfaceArea.ListSave, v)
- end
- CCInterfaceArea.RemoveAll(CCInterfaceArea.List)
- end,
- Load = function()
- CCInterfaceArea.RemoveAll(CCInterfaceArea.List)
- for k, v in pairs(CCInterfaceArea.ListSave) do
- table.insert(CCInterfaceArea.List, v)
- end
- CCInterfaceArea.RemoveAll(CCInterfaceArea.ListSave)
- end
- }
- Screen = {
- Width = _w,
- Height = _h,
- }
- Peripherals = {
- Back = _back,
- Front = _front,
- Right = _right,
- Left = _left,
- Top = _top,
- Bottom = _bottom,
- }
- CCDrawing = {
- DrawCharacters = function (_x,_y,_string,_textColour,_backgroundColour)
- _mon.setBackgroundColour(_backgroundColour)
- _mon.setTextColour(_textColour)
- _mon.setCursorPos(_x,_y)
- _mon.write(_string)
- end,
- DrawArea = function (_x,_y,_w,_h,_character,_textColour,_bgColour)
- --width must be greater than 1, other wise we get a stack overflow
- if _w > 0 then
- _w = _w * 1
- elseif _w == 0 then
- _w = 1
- end
- if _h > 0 then
- _h = _h * 1
- elseif _h == 0 then
- _h = 1
- end
- local sRow = " "
- for ix = 1, _w do
- sRow = sRow .. _character
- end
- for iy = 1, _h do
- local currY = _y + iy - 1
- CCDrawing.DrawCharacters(_x, currY, sRow, _textColour, _bgColour)
- end
- end
- }
- CCObject = {
- Type = "CCObject",
- ID = 0,
- }
- CCEntity = {
- __index = CCObject,
- X = 0,
- Y = 0,
- Width = 0,
- Height = 0,
- Title = " ";
- }
- CCControl = {
- __index = CCEntity,
- Action = nil,
- Enabled = true,
- }
- CCButton = {
- __index = CCControl,
- Type = "CCButton",
- Height = 1,
- New = function(self, _x, _y, _textColour, _bgColour, _title, _action)
- local new = {} --the new instance
- setmetatable( new, {__index = self} )
- new.Width = string.len(_title)
- new.X = _x
- new.Y = _y
- new.TextColour = _textColour
- new.BackgroundColour = _bgColour
- new.Title = _title
- new.Action = _action
- new.Enabled = true
- return new
- end,
- Draw = function(self)
- CCDrawing.DrawCharacters(self.X, self.Y,""..self.Title.."", self.TextColour, self.BackgroundColour)
- end
- }
- CCArea = {
- __index = CCControl,
- Type = "CCArea",
- New = function(self, _x, _y,_w,_h, _character, _textColour, _bgColour)
- local new = {} --the new instance
- setmetatable( new, {__index = self} )
- new.X = _x
- new.Y = _y
- new.W = _w
- new.H = _h
- new.Character = _character
- new.TextColour = _textColour
- new.BackgroundColour = _bgColour
- new.Enabled = true
- return new
- end,
- Draw = function(self)
- CCDrawing.DrawArea(self.X, self.Y, self.W, self.H, self.Character, self.TextColour, self.BackgroundColour)
- end
- }
- CCPrintTable = function(_name)
- local X = 4
- local Y = 4
- for _, v in pairs(_name) do
- CCDrawing.DrawCharacters(4, Y, tostring(_), colors.black,colors.lightGray)
- CCDrawing.DrawCharacters(15, Y, tostring(v), colors.black, colors.lightGray)
- Y = Y+1
- end
- end
- CCMenuSite = {
- New = function(self, _SiteName)
- local new = {} --the new instance
- new.Name = _SiteName
- return new
- end,
- AddButton = function(self, _x, _y, _CBack, _CText, _String, _Func)
- end
- }
- CCDebug = function()
- for k, l in pairs(CCInterfaceEntities.List) do
- print("NR: ",k," Entity: ",textutils.tabulate(l))
- end
- end
- CCCustomEvent = {
- __index = CCControl,
- Type = "CCCustomEvent",
- Call = function(_EventName, _Param1, _Param2, _Param3)
- os.queueEvent(_EventName, _Param1, _Param2, _Param3)
- end
- }
- function DrawButtons()
- for _,entity in ipairs(CCInterfaceEntities.List) do
- entity:Draw()
- end
- end
- function DrawScreens()
- for _,area in ipairs(CCInterfaceArea.List) do
- area:Draw()
- end
- end
- function EventHandler()
- while true do
- local event, arg, x, y = os.pullEventRaw()
- if event == "mouse_click" or "monitor_touch" or "CustomEvent_touch" then
- for _,entity in pairs(CCInterfaceEntities.List) do
- --check if the click overlaps an entities
- --if x >= entity.X and x <=entity.X + entity.Width - 1 and y >= entity.Y and y <=entity.Y + entity.Height then
- if x >= entity.X and x <= entity.X + entity.Width and y >= entity.Y and y <= entity.Y + entity.Height then
- print("Button clicked: Name=",_," x=",x," y=",y," Event=",event)
- if entity.Action then
- entity:Action()
- break
- end
- end
- end
- end
- end
- end
- function init()
- local Background1 = CCArea:New(1,1,Screen.Width,Screen.Height," ", colors.white,colors.cyan)
- local Background2 = CCArea:New(1,1,Screen.Width,1," ", colors.white,colors.lightGray)
- local Background3 = CCArea:New(1,Screen.Height,Screen.Width,1," ", colors.white,colors.lightGray)
- local Background4 = CCArea:New(0,1,1,1,"Test Bildschirm", colors.black,colors.lightGray)
- local Background5 = CCArea:New(0,1,1,1,"Items", colors.black,colors.lightGray)
- CCInterfaceArea.Add(Background1)
- CCInterfaceArea.Add(Background3)
- CCInterfaceArea.Add(Background2)
- CCInterfaceArea.Add(Background4)
- local Beenden = CCButton:New(Screen.Width, 1,colors.white,colors.red,"X", function() os.reboot() end)
- local Items = CCButton:New(1,Screen.Height-1,colors.black,colors.lightGray,"Items ", function() CCInterfaceArea.Remove(Background4) CCInterfaceArea.Add(Background5) CCCustomEvent.Call("CustomEvent_touch", 1, 1, Screen.Height) DrawScreens() DrawButtons() end)
- local Options = CCButton:New(1,Screen.Height-4,colors.black,colors.lightGray,"Options ",function() CCInterfaceEntities.Load() end)
- local Crafting = CCButton:New(1,Screen.Height-2,colors.black,colors.lightGray,"Crafting", function() end)
- local Energy = CCButton:New(1,Screen.Height-3,colors.black,colors.lightGray,"Energy ",CCPrintTable(CCInterfaceEntities.List) end)
- local Machines = CCButton:New(1,Screen.Height-5,colors.black,colors.lightGray,"Machines", function() CCInterfaceEntities.Save() CCInterfaceEntities.Add(Options) end)
- local Home = CCButton:New(1,Screen.Height,colors.black,colors.lightGray,"Home", function() CCInterfaceEntities.Toggle(Items) CCInterfaceEntities.Toggle(Options) CCInterfaceEntities.Toggle(Machines) CCInterfaceEntities.Toggle(Crafting) CCInterfaceEntities.Toggle(Energy) DrawScreens() DrawButtons() end)
- CCInterfaceEntities.Add(Beenden)
- CCInterfaceEntities.Add(Home)
- DrawScreens()
- DrawButtons()
- --CCDrawing.DrawArea(10, 7, 20, 7, " ", colors.white, colors.red)
- EventHandler()
- end
Advertisement
Add Comment
Please, Sign In to add comment