Added hazard gate prompt
This commit is contained in:
10
display.lua
10
display.lua
@ -16,6 +16,7 @@ local localGateAddress
|
||||
local buttonXY = {}
|
||||
local computerAddresses = {}
|
||||
local computerNames = {}
|
||||
local hazardReasons = {}
|
||||
local x, y = 0, 0
|
||||
|
||||
function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
||||
@ -27,13 +28,14 @@ function display.init(monitor, cfg, addr, utilsModule, localAddr)
|
||||
end
|
||||
|
||||
function display.getButtonData()
|
||||
return buttonXY, computerAddresses, computerNames
|
||||
return buttonXY, computerAddresses, computerNames, hazardReasons
|
||||
end
|
||||
|
||||
function display.clearButtonData()
|
||||
buttonXY = {}
|
||||
computerAddresses = {}
|
||||
computerNames = {}
|
||||
hazardReasons = {}
|
||||
end
|
||||
|
||||
---------------------------------------------
|
||||
@ -116,6 +118,12 @@ function display.screenWrite(list, fcount, fy)
|
||||
table.insert(buttonXY, { x1, x2, fy })
|
||||
table.insert(computerNames, list[i][1])
|
||||
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
|
||||
|
||||
|
||||
62
startup.lua
62
startup.lua
@ -538,19 +538,71 @@ local function dialGate(address)
|
||||
end
|
||||
end
|
||||
|
||||
local function selectGateFromList()
|
||||
local function selectGateFromList(isHazardGate)
|
||||
local state = getState()
|
||||
local selecting = true
|
||||
while dialing == false and selecting == true do
|
||||
selx, sely = GetClick()
|
||||
local buttonXY, computerAddresses, computerNames = display.getButtonData()
|
||||
local buttonXY, computerAddresses, computerNames, hazardReasons = display.getButtonData()
|
||||
|
||||
for i = 1, #buttonXY do
|
||||
if (sely == buttonXY[i][3]) and ((selx >= buttonXY[i][1]) and (selx <= buttonXY[i][2])) then
|
||||
local shouldDial = true
|
||||
|
||||
-- If this is a hazard gate, show confirmation prompt
|
||||
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
|
||||
selx = 0
|
||||
break
|
||||
@ -586,7 +638,7 @@ local function selectCategory()
|
||||
mon.setBackgroundColor(colors.purple)
|
||||
count, y = display.screenWrite(addresses.MainGates, count, y)
|
||||
|
||||
local returnstate = selectGateFromList()
|
||||
local returnstate = selectGateFromList(false)
|
||||
if returnstate == true then
|
||||
state = false
|
||||
end
|
||||
@ -604,7 +656,7 @@ local function selectCategory()
|
||||
mon.setBackgroundColor(colors.green)
|
||||
count, y = display.screenWrite(addresses.playerGates, count, y)
|
||||
|
||||
local returnstate = selectGateFromList()
|
||||
local returnstate = selectGateFromList(false)
|
||||
if returnstate == true then
|
||||
state = false
|
||||
end
|
||||
@ -622,7 +674,7 @@ local function selectCategory()
|
||||
mon.setBackgroundColor(colors.red)
|
||||
count, y = display.screenWrite(addresses.hazardGates, count, y)
|
||||
|
||||
local returnstate = selectGateFromList()
|
||||
local returnstate = selectGateFromList(true)
|
||||
if returnstate == true then
|
||||
state = false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user