mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-20 15:21:29 +00:00
195 lines
6.3 KiB
Plaintext
195 lines
6.3 KiB
Plaintext
// Operates NanoUI
|
|
/obj/item/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
|
|
if(!enabled)
|
|
if(ui)
|
|
ui.close()
|
|
return 0
|
|
if(!use_power())
|
|
if(ui)
|
|
ui.close()
|
|
return 0
|
|
|
|
// Robots don't really need to see the screen, their wireless connection works as long as computer is on.
|
|
if(!screen_on && !issilicon(user))
|
|
if(ui)
|
|
ui.close()
|
|
return 0
|
|
|
|
// If we have an active program switch to it now.
|
|
if(active_program)
|
|
if(ui) // This is the main laptop screen. Since we are switching to program's UI close it for now.
|
|
ui.close()
|
|
active_program.ui_interact(user)
|
|
return
|
|
|
|
// We are still here, that means there is no program loaded. Load the BIOS/ROM/OS/whatever you want to call it.
|
|
// This screen simply lists available programs and user may select them.
|
|
var/obj/item/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
|
|
if(!hard_drive || !hard_drive.stored_files || !hard_drive.stored_files.len)
|
|
to_chat(user, "<span class='danger'>\The [src] beeps three times, it's screen displaying a \"DISK ERROR\" warning.</span>")
|
|
return // No HDD, No HDD files list or no stored files. Something is very broken.
|
|
|
|
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
|
|
if(!ui)
|
|
var/datum/asset/assets = get_asset_datum(/datum/asset/simple/headers)
|
|
assets.send(user)
|
|
ui = new(user, src, ui_key, "computer_main.tmpl", "NTOS Main menu", 400, 500)
|
|
ui.set_auto_update(1)
|
|
ui.set_layout_key("program")
|
|
ui.open()
|
|
|
|
|
|
/obj/item/modular_computer/ui_data(mob/user)
|
|
var/list/data = get_header_data()
|
|
data["programs"] = list()
|
|
var/obj/item/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
|
|
for(var/datum/computer_file/program/P in hard_drive.stored_files)
|
|
var/running = 0
|
|
if(P in idle_threads)
|
|
running = 1
|
|
|
|
data["programs"] += list(list("name" = P.filename, "desc" = P.filedesc, "running" = running))
|
|
|
|
return data
|
|
|
|
// Function used by NanoUI's to obtain data for header. All relevant entries begin with "PC_"
|
|
/obj/item/modular_computer/proc/get_header_data()
|
|
var/list/data = list()
|
|
|
|
var/obj/item/computer_hardware/battery/battery_module = all_components[MC_CELL]
|
|
var/obj/item/computer_hardware/recharger/recharger = all_components[MC_CHARGE]
|
|
|
|
if(battery_module && battery_module.battery)
|
|
switch(battery_module.battery.percent())
|
|
if(80 to 200) // 100 should be maximal but just in case..
|
|
data["PC_batteryicon"] = "batt_100.gif"
|
|
if(60 to 80)
|
|
data["PC_batteryicon"] = "batt_80.gif"
|
|
if(40 to 60)
|
|
data["PC_batteryicon"] = "batt_60.gif"
|
|
if(20 to 40)
|
|
data["PC_batteryicon"] = "batt_40.gif"
|
|
if(5 to 20)
|
|
data["PC_batteryicon"] = "batt_20.gif"
|
|
else
|
|
data["PC_batteryicon"] = "batt_5.gif"
|
|
data["PC_batterypercent"] = "[round(battery_module.battery.percent())] %"
|
|
data["PC_showbatteryicon"] = 1
|
|
else
|
|
data["PC_batteryicon"] = "batt_5.gif"
|
|
data["PC_batterypercent"] = "N/C"
|
|
data["PC_showbatteryicon"] = battery_module ? 1 : 0
|
|
|
|
if(recharger && recharger.enabled && recharger.check_functionality() && recharger.use_power(0))
|
|
data["PC_apclinkicon"] = "charging.gif"
|
|
|
|
switch(get_ntnet_status())
|
|
if(0)
|
|
data["PC_ntneticon"] = "sig_none.gif"
|
|
if(1)
|
|
data["PC_ntneticon"] = "sig_low.gif"
|
|
if(2)
|
|
data["PC_ntneticon"] = "sig_high.gif"
|
|
if(3)
|
|
data["PC_ntneticon"] = "sig_lan.gif"
|
|
|
|
if(idle_threads.len)
|
|
var/list/program_headers = list()
|
|
for(var/I in idle_threads)
|
|
var/datum/computer_file/program/P = I
|
|
if(!P.ui_header)
|
|
continue
|
|
program_headers.Add(list(list(
|
|
"icon" = P.ui_header
|
|
)))
|
|
|
|
data["PC_programheaders"] = program_headers
|
|
|
|
data["PC_stationtime"] = station_time_timestamp()
|
|
data["PC_showexitprogram"] = active_program ? 1 : 0 // Hides "Exit Program" button on mainscreen
|
|
return data
|
|
|
|
|
|
// Handles user's GUI input
|
|
/obj/item/modular_computer/Topic(href, list/href_list)
|
|
if(..())
|
|
return
|
|
var/obj/item/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
|
|
switch(href_list["action"])
|
|
if("PC_exit")
|
|
kill_program()
|
|
return 1
|
|
if("PC_shutdown")
|
|
shutdown_computer()
|
|
return 1
|
|
if("PC_minimize")
|
|
var/mob/user = usr
|
|
if(!active_program || !all_components[MC_CPU])
|
|
return 1
|
|
|
|
idle_threads.Add(active_program)
|
|
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
|
|
|
|
active_program = null
|
|
update_icon()
|
|
if(user && istype(user))
|
|
ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
|
|
|
|
if("PC_killprogram")
|
|
var/prog = href_list["name"]
|
|
var/datum/computer_file/program/P = null
|
|
var/mob/user = usr
|
|
if(hard_drive)
|
|
P = hard_drive.find_file_by_name(prog)
|
|
|
|
if(!istype(P) || P.program_state == PROGRAM_STATE_KILLED)
|
|
return 1
|
|
|
|
P.kill_program(forced = TRUE)
|
|
to_chat(user, "<span class='notice'>Program [P.filename].[P.filetype] with PID [rand(100,999)] has been killed.</span>")
|
|
|
|
if("PC_runprogram")
|
|
var/prog = href_list["name"]
|
|
var/datum/computer_file/program/P = null
|
|
var/mob/user = usr
|
|
if(hard_drive)
|
|
P = hard_drive.find_file_by_name(prog)
|
|
|
|
if(!P || !istype(P)) // Program not found or it's not executable program.
|
|
to_chat(user, "<span class='danger'>\The [src]'s screen shows \"I/O ERROR - Unable to run program\" warning.</span>")
|
|
return 1
|
|
|
|
P.computer = src
|
|
|
|
if(!P.is_supported_by_hardware(hardware_flag, 1, user))
|
|
return 1
|
|
|
|
// The program is already running. Resume it.
|
|
if(P in idle_threads)
|
|
P.program_state = PROGRAM_STATE_ACTIVE
|
|
active_program = P
|
|
idle_threads.Remove(P)
|
|
update_icon()
|
|
return
|
|
|
|
var/obj/item/computer_hardware/processor_unit/PU = all_components[MC_CPU]
|
|
|
|
if(idle_threads.len > PU.max_idle_programs)
|
|
to_chat(user, "<span class='danger'>\The [src] displays a \"Maximal CPU load reached. Unable to run another program.\" error.</span>")
|
|
return 1
|
|
|
|
if(P.requires_ntnet && !get_ntnet_status(P.requires_ntnet_feature)) // The program requires NTNet connection, but we are not connected to NTNet.
|
|
to_chat(user, "<span class='danger'>\The [src]'s screen shows \"Unable to connect to NTNet. Please retry. If problem persists contact your system administrator.\" warning.</span>")
|
|
return 1
|
|
if(P.run_program(user))
|
|
active_program = P
|
|
update_icon()
|
|
return 1
|
|
else
|
|
return
|
|
|
|
/obj/item/modular_computer/nano_host()
|
|
if(physical)
|
|
return physical
|
|
return src
|