IT LIVES KUHAHAHAHAHA (made the gui work)
This commit is contained in:
+108
-55
@@ -5,10 +5,12 @@ thread = require("thread")
|
|||||||
term = require("term")
|
term = require("term")
|
||||||
redstone = component.redstone
|
redstone = component.redstone
|
||||||
gpu = component.gpu
|
gpu = component.gpu
|
||||||
|
reactor = component.reactor_chamber
|
||||||
|
|
||||||
|
|
||||||
isDown = false
|
isDown = true
|
||||||
w,h = gpu.getResolution()
|
cooldown = false
|
||||||
|
w,h = gpu.getResolution()
|
||||||
|
|
||||||
|
|
||||||
buttonName = {"power" , "redstone" }
|
buttonName = {"power" , "redstone" }
|
||||||
@@ -17,26 +19,62 @@ buttonX2 = {19 , 19 }
|
|||||||
buttonY1 = {3 , 10 }
|
buttonY1 = {3 , 10 }
|
||||||
buttonY2 = {8 , 15 }
|
buttonY2 = {8 , 15 }
|
||||||
|
|
||||||
function power()
|
|
||||||
text = "Test string on power button"
|
|
||||||
gpu.set(w-30,1, text)
|
|
||||||
end
|
|
||||||
|
|
||||||
buttonFunc = {power = power(), redstone = redstone() }
|
|
||||||
|
|
||||||
-- 0x13ba13 green
|
-- 0x13ba13 green
|
||||||
-- 0xeb1515 red
|
-- 0xeb1515 red
|
||||||
|
|
||||||
|
function powerFunc()
|
||||||
|
-- -- local textOutput = ""
|
||||||
|
if (isDown == true) then
|
||||||
|
-- Turn reactor off
|
||||||
|
gpu.setBackground(0xeb1515)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
gpu.fill(3,3,16,5," ")
|
||||||
|
gpu.set(3+5,5, "Power")
|
||||||
|
redstone.setOutput(0,0)
|
||||||
|
isDown = false
|
||||||
|
-- -- textOutput = "Stopped signal"
|
||||||
|
else
|
||||||
|
-- Turn reactor on
|
||||||
|
gpu.setBackground(0x13ba13)
|
||||||
|
gpu.setForeground(0x000000)
|
||||||
|
gpu.fill(3,3,16,5," ")
|
||||||
|
gpu.set(3+5,5, "Power")
|
||||||
|
redstone.setOutput(0,1)
|
||||||
|
isDown = true
|
||||||
|
-- -- textOutput = "Started signal"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -- Setting Backgroun to black and foreground to white again
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
end
|
||||||
|
function redstoneFunc()
|
||||||
|
-- text = "Test string on redstone button"
|
||||||
|
-- gpu.set(w-30,1, text)
|
||||||
|
-- print("My Output")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
buttonFunc = {power = powerFunc, redstone = redstoneFunc}
|
||||||
|
|
||||||
|
|
||||||
function startup()
|
function startup()
|
||||||
|
-- Doing some stuff on startup
|
||||||
|
redstone.setOutput(0,0)
|
||||||
term.clear()
|
term.clear()
|
||||||
-- gpu.setBackground(0xeb1515) -- Redstone area
|
|
||||||
-- gpu.fill(30,20,6,3," ")
|
|
||||||
|
|
||||||
|
|
||||||
|
-- General ui
|
||||||
gpu.setBackground(0xcccccc) -- Sidebar
|
gpu.setBackground(0xcccccc) -- Sidebar
|
||||||
gpu.fill(1,1,20,h," ")
|
gpu.fill(1,1,20,h," ")
|
||||||
|
|
||||||
|
gpu.setBackground(0xe6e6e6) -- Main area
|
||||||
|
gpu.fill(21,1,w-20,h," ")
|
||||||
|
|
||||||
|
-- Buttons
|
||||||
-- ----------------
|
-- ----------------
|
||||||
-- Power
|
-- Power
|
||||||
gpu.setBackground(0xeb1515)
|
gpu.setBackground(0xeb1515)
|
||||||
@@ -44,46 +82,68 @@ function startup()
|
|||||||
gpu.set(3+5,5, "Power")
|
gpu.set(3+5,5, "Power")
|
||||||
|
|
||||||
|
|
||||||
-- ----------------
|
-- -- ----------------
|
||||||
-- Redstone
|
-- -- Redstone
|
||||||
gpu.setBackground(0xeb1515)
|
-- gpu.setBackground(0xeb1515)
|
||||||
gpu.fill(3,10,16,5," ")
|
-- gpu.fill(3,10,16,5," ")
|
||||||
gpu.set(3+4,12, "Redstone")
|
-- gpu.set(3+4,12, "Redstone")
|
||||||
|
|
||||||
|
-- Display
|
||||||
|
-- ---------
|
||||||
|
-- 50%
|
||||||
|
gpu.setBackground(0x4d8ef7)
|
||||||
|
gpu.fill(23,3,11,5," ")
|
||||||
|
gpu.set(23+4,5, "0%")
|
||||||
end
|
end
|
||||||
|
|
||||||
function guiHandling()
|
function guiHandling()
|
||||||
while true do
|
while true do
|
||||||
local _,_,x,y = event.pull("touch")
|
local _,_,x,y = event.pull("touch")
|
||||||
for
|
local buttonFound = false
|
||||||
|
for i,o in pairs(buttonName) do
|
||||||
|
if(x >= buttonX1[i] and x <= buttonX2[i] and y >= buttonY1[i] and y <= buttonY2[i]) then
|
||||||
|
buttonFound = true
|
||||||
|
-- buttonFunc[o]()
|
||||||
|
local status,err = pcall(buttonFunc[o])
|
||||||
|
-- print(status)
|
||||||
|
-- print(err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- if(buttonFound == false) then -- Obsolete now, but i ll still keep it, who knows if it might kome in handy again at some point
|
||||||
|
-- gpu.setBackground(0x000000)
|
||||||
|
-- gpu.fill(40,10,50,1," ")
|
||||||
|
-- gpu.set(40,10,"No button pressed")
|
||||||
|
-- end
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- function updateGui()
|
|
||||||
-- while true do
|
|
||||||
-- if(redstone.getInput(3) ~= 0) then
|
|
||||||
-- gpu.setBackground(0x13ba13)
|
|
||||||
-- gpu.fill(3,10,16,5," ")
|
|
||||||
-- else
|
|
||||||
-- gpu.setBackground(0xeb1515)
|
|
||||||
-- gpu.fill(3,10,16,5," ")
|
|
||||||
-- end
|
|
||||||
-- gpu.set(3+4,12, "Redstone")
|
|
||||||
-- gpu.setBackground(0x000000)
|
|
||||||
-- -- print("Okay")
|
|
||||||
-- -- gpu.set(31,21,redstone.getInput(3).."")
|
|
||||||
|
|
||||||
-- os.sleep(1/2)
|
function reactorControl()
|
||||||
-- end
|
while true do
|
||||||
-- end
|
heat = reactor.getHeat()
|
||||||
|
heatp = heat / reactor.getMaxHeat() * 100
|
||||||
|
|
||||||
|
|
||||||
function powerButton()
|
gpu.setBackground(0x4d8ef7)
|
||||||
if(redstone.getInput(3) ~= 0) then
|
gpu.fill(23,3,11,5," ")
|
||||||
gpu.setBackground(0x13ba13)
|
gpu.set(23+4,5, heatp .. "%")
|
||||||
gpu.fill(3,10,16,5," ")
|
|
||||||
else
|
|
||||||
gpu.setBackground(0xeb1515)
|
|
||||||
gpu.fill(3,10,16,5," ")
|
-- print(heat .. " : " .. heatp)
|
||||||
|
|
||||||
|
if heatp > 60 then
|
||||||
|
if(isDown)then powerFunc() end
|
||||||
|
cooldown = true
|
||||||
|
-- redstone.setOutput(0,0)
|
||||||
|
end
|
||||||
|
if heatp < 1 and cooldown then
|
||||||
|
powerFunc()
|
||||||
|
cooldown = false
|
||||||
|
-- redstone.setOutput(0,1)
|
||||||
|
end
|
||||||
|
|
||||||
|
os.sleep(1/2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -91,25 +151,18 @@ end
|
|||||||
|
|
||||||
function cleanup()
|
function cleanup()
|
||||||
event.pull("interrupted")
|
event.pull("interrupted")
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
term.clear()
|
term.clear()
|
||||||
print("Ending process")
|
print("Ending threads")
|
||||||
t1:kill()
|
t1:kill()
|
||||||
t2:kill()
|
t2:kill()
|
||||||
os.sleep(1)
|
os.sleep(1/3)
|
||||||
print("Processes ended")
|
print("threads ended")
|
||||||
thread.current():kill()
|
thread.current():kill()
|
||||||
end
|
end
|
||||||
|
|
||||||
startup()
|
startup()
|
||||||
t1 = thread.create(updateGui)
|
t1 = thread.create(guiHandling)
|
||||||
t2 = thread.create(guiHandling)
|
t2 = thread.create(reactorControl)
|
||||||
t3 = thread.create(cleanup)
|
tCleanup = thread.create(cleanup)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- local test = {"a","b","c"}
|
|
||||||
-- for i=0,table.getn(test) do
|
|
||||||
-- print(test[i])
|
|
||||||
-- end
|
|
||||||
Reference in New Issue
Block a user