Added hazard gate prompt
This commit is contained in:
10
display.lua
10
display.lua
@ -16,6 +16,7 @@ local localGateAddress
|
|||||||
local buttonXY = {}
|
local buttonXY = {}
|
||||||
local computerAddresses = {}
|
local computerAddresses = {}
|
||||||
local computerNames = {}
|
local computerNames = {}
|
||||||
|
local hazardReasons = {}
|
||||||
local x, y = 0, 0
|
local x, y = 0, 0
|
||||||
|
|
||||||
function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
||||||
@ -27,13 +28,14 @@ function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function display.getButtonData()
|
function display.getButtonData()
|
||||||
return buttonXY, computerAddresses, computerNames
|
return buttonXY, computerAddresses, computerNames, hazardReasons
|
||||||
end
|
end
|
||||||
|
|
||||||
function display.clearButtonData()
|
function display.clearButtonData()
|
||||||
buttonXY = {}
|
buttonXY = {}
|
||||||
computerAddresses = {}
|
computerAddresses = {}
|
||||||
computerNames = {}
|
computerNames = {}
|
||||||
|
hazardReasons = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
@ -116,6 +118,12 @@ function display.screenWrite(list, fcount, fy)
|
|||||||
table.insert(buttonXY, { x1, x2, fy })
|
table.insert(buttonXY, { x1, x2, fy })
|
||||||
table.insert(computerNames, list[i][1])
|
table.insert(computerNames, list[i][1])
|
||||||
table.insert(computerAddresses, list[i][2])
|
table.insert(computerAddresses, list[i][2])
|
||||||
|
-- Store hazard reason if present (third element in hazard gates)
|
||||||
|
if list[i][3] then
|
||||||
|
table.insert(hazardReasons, list[i][3])
|
||||||
|
else
|
||||||
|
table.insert(hazardReasons, nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
70
startup.lua
70
startup.lua
@ -538,19 +538,71 @@ local function dialGate(address)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function selectGateFromList()
|
local function selectGateFromList(isHazardGate)
|
||||||
local state = getState()
|
local state = getState()
|
||||||
local selecting = true
|
local selecting = true
|
||||||
while dialing == false and selecting == true do
|
while dialing == false and selecting == true do
|
||||||
selx, sely = GetClick()
|
selx, sely = GetClick()
|
||||||
local buttonXY, computerAddresses, computerNames = display.getButtonData()
|
local buttonXY, computerAddresses, computerNames, hazardReasons = display.getButtonData()
|
||||||
|
|
||||||
for i = 1, #buttonXY do
|
for i = 1, #buttonXY do
|
||||||
if (sely == buttonXY[i][3]) and ((selx >= buttonXY[i][1]) and (selx <= buttonXY[i][2])) then
|
if (sely == buttonXY[i][3]) and ((selx >= buttonXY[i][1]) and (selx <= buttonXY[i][2])) then
|
||||||
dialGate(computerAddresses[i])
|
local shouldDial = true
|
||||||
state.destAddressname = computerNames[i]
|
|
||||||
state.destAddress = computerAddresses[i]
|
-- If this is a hazard gate, show confirmation prompt
|
||||||
dialing = true
|
if isHazardGate and hazardReasons and hazardReasons[i] then
|
||||||
|
mon.setBackgroundColor(colors.black)
|
||||||
|
mon.clear()
|
||||||
|
mon.setBackgroundColor(colors.red)
|
||||||
|
mon.setTextScale(1)
|
||||||
|
mon.setCursorPos(5, 5)
|
||||||
|
mon.write("WARNING: HAZARD GATE")
|
||||||
|
mon.setBackgroundColor(colors.black)
|
||||||
|
mon.setCursorPos(2, 8)
|
||||||
|
mon.write("Destination:")
|
||||||
|
mon.setCursorPos(2, 9)
|
||||||
|
mon.write(computerNames[i])
|
||||||
|
mon.setCursorPos(2, 11)
|
||||||
|
mon.write("Hazard:")
|
||||||
|
mon.setCursorPos(2, 12)
|
||||||
|
mon.write(hazardReasons[i])
|
||||||
|
mon.setCursorPos(2, 15)
|
||||||
|
mon.write("Proceed with dialing?")
|
||||||
|
|
||||||
|
-- Draw YES and NO buttons
|
||||||
|
mon.setBackgroundColor(colors.green)
|
||||||
|
mon.setCursorPos(5, 17)
|
||||||
|
mon.write(" YES ")
|
||||||
|
mon.setBackgroundColor(colors.red)
|
||||||
|
mon.setCursorPos(18, 17)
|
||||||
|
mon.write(" NO ")
|
||||||
|
|
||||||
|
-- Wait for confirmation
|
||||||
|
local confirmed = false
|
||||||
|
while true do
|
||||||
|
local cx, cy = GetClick()
|
||||||
|
if cy == 17 then
|
||||||
|
if cx >= 5 and cx <= 10 then
|
||||||
|
-- YES clicked
|
||||||
|
confirmed = true
|
||||||
|
break
|
||||||
|
elseif cx >= 18 and cx <= 22 then
|
||||||
|
-- NO clicked
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shouldDial = confirmed
|
||||||
|
end
|
||||||
|
|
||||||
|
if shouldDial then
|
||||||
|
dialGate(computerAddresses[i])
|
||||||
|
state.destAddressname = computerNames[i]
|
||||||
|
state.destAddress = computerAddresses[i]
|
||||||
|
dialing = true
|
||||||
|
end
|
||||||
|
|
||||||
sely = 0
|
sely = 0
|
||||||
selx = 0
|
selx = 0
|
||||||
break
|
break
|
||||||
@ -586,7 +638,7 @@ local function selectCategory()
|
|||||||
mon.setBackgroundColor(colors.purple)
|
mon.setBackgroundColor(colors.purple)
|
||||||
count, y = display.screenWrite(addresses.MainGates, count, y)
|
count, y = display.screenWrite(addresses.MainGates, count, y)
|
||||||
|
|
||||||
local returnstate = selectGateFromList()
|
local returnstate = selectGateFromList(false)
|
||||||
if returnstate == true then
|
if returnstate == true then
|
||||||
state = false
|
state = false
|
||||||
end
|
end
|
||||||
@ -604,7 +656,7 @@ local function selectCategory()
|
|||||||
mon.setBackgroundColor(colors.green)
|
mon.setBackgroundColor(colors.green)
|
||||||
count, y = display.screenWrite(addresses.playerGates, count, y)
|
count, y = display.screenWrite(addresses.playerGates, count, y)
|
||||||
|
|
||||||
local returnstate = selectGateFromList()
|
local returnstate = selectGateFromList(false)
|
||||||
if returnstate == true then
|
if returnstate == true then
|
||||||
state = false
|
state = false
|
||||||
end
|
end
|
||||||
@ -622,7 +674,7 @@ local function selectCategory()
|
|||||||
mon.setBackgroundColor(colors.red)
|
mon.setBackgroundColor(colors.red)
|
||||||
count, y = display.screenWrite(addresses.hazardGates, count, y)
|
count, y = display.screenWrite(addresses.hazardGates, count, y)
|
||||||
|
|
||||||
local returnstate = selectGateFromList()
|
local returnstate = selectGateFromList(true)
|
||||||
if returnstate == true then
|
if returnstate == true then
|
||||||
state = false
|
state = false
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user