diff --git a/addresses.lua b/addresses.lua index c973079..15ca3cd 100644 --- a/addresses.lua +++ b/addresses.lua @@ -19,8 +19,7 @@ addresses.MainGates = { { "Unitas", { 2, 27, 8, 34, 24, 15, 0 } }, { "Lantea", { 18, 20, 1, 15, 14, 7, 19, 0 } }, { "Rima", { 33, 20, 10, 22, 3, 17, 0 } }, - { "Athos", { 18, 21, 14, 24, 1, 26, 28, 0 } }, - { "Moon", { 33, 11, 17, 27, 12, 13, 3, 24, 0 } } + { "Athos", { 18, 21, 14, 24, 1, 26, 28, 0 } } } --------------------------------------------- @@ -42,7 +41,8 @@ addresses.playerGates = { -- Dangerous destinations addresses.hazardGates = { - { "Cavum Tenebrae", { 18, 7, 3, 36, 25, 15, 0 }, "Weird Gravity" } + { "Cavum Tenebrae", { 18, 7, 3, 36, 25, 15, 0 }, "Weird Gravity" }, + { "Moon", { 33, 11, 17, 27, 12, 13, 3, 24, 0 }, "No Oxygen" } } return addresses diff --git a/display.lua b/display.lua index c37bf24..fa49f2b 100644 --- a/display.lua +++ b/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 diff --git a/startup.lua b/startup.lua index 8175c30..11a9b60 100644 --- a/startup.lua +++ b/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 - dialGate(computerAddresses[i]) - state.destAddressname = computerNames[i] - state.destAddress = computerAddresses[i] - dialing = true + 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 (use direct os.pullEvent to bypass handlers) + local confirmed = false + while true do + local event, side, cx, cy = os.pullEvent("monitor_touch") + 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