TGUI Engineering... and a bunch of other random things

This commit is contained in:
ShadowLarkens
2020-09-24 21:54:18 -07:00
parent aebfc19991
commit dad9020f9a
373 changed files with 15493 additions and 17584 deletions

View File

@@ -121,7 +121,7 @@
active_program = null
var/mob/user = usr
if(user && istype(user))
ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
tgui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
update_icon()
// Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on)
@@ -156,7 +156,7 @@
run_program(autorun.stored_data)
if(user)
ui_interact(user)
tgui_interact(user)
/obj/item/modular_computer/proc/minimize_program(mob/user)
if(!active_program || !processor_unit)
@@ -164,12 +164,11 @@
idle_threads.Add(active_program)
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
SSnanoui.close_uis(active_program.NM ? active_program.NM : active_program)
SStgui.close_uis(active_program.TM ? active_program.TM : active_program)
active_program = null
update_icon()
if(istype(user))
ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
tgui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
/obj/item/modular_computer/proc/run_program(prog)
@@ -209,12 +208,12 @@
return 1
/obj/item/modular_computer/proc/update_uis()
if(active_program) //Should we update program ui or computer ui?
SSnanoui.update_uis(active_program)
if(active_program.NM)
SSnanoui.update_uis(active_program.NM)
if(active_program)
SStgui.update_uis(active_program)
if(active_program.TM)
SStgui.update_uis(active_program.TM)
else
SSnanoui.update_uis(src)
SStgui.update_uis(src)
/obj/item/modular_computer/proc/check_update_ui_need()
var/ui_update_needed = 0

View File

@@ -99,7 +99,7 @@
/obj/item/modular_computer/attack_ghost(var/mob/observer/ghost/user)
if(enabled)
ui_interact(user)
tgui_interact(user)
else if(check_rights(R_ADMIN|R_EVENT, 0, user))
var/response = alert(user, "This computer is turned off. Would you like to turn it on?", "Admin Override", "Yes", "No")
if(response == "Yes")
@@ -116,7 +116,7 @@
// On-click handling. Turns on the computer if it's off and opens the GUI.
/obj/item/modular_computer/attack_self(var/mob/user)
if(enabled && screen_on)
ui_interact(user)
tgui_interact(user)
else if(!enabled && screen_on)
turn_on(user)

View File

@@ -1,5 +1,10 @@
// Operates NanoUI
/obj/item/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
// Operates TGUI
/obj/item/modular_computer/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/simple/headers)
)
/obj/item/modular_computer/tgui_interact(mob/user, datum/tgui/ui)
if(!screen_on || !enabled)
if(ui)
ui.close()
@@ -13,7 +18,7 @@
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)
active_program.tgui_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.
@@ -22,80 +27,100 @@
visible_message("\The [src] beeps three times, it's screen displaying \"DISK ERROR\" warning.")
return // No HDD, No HDD files list or no stored files. Something is very broken.
var/datum/computer_file/data/autorun = hard_drive.find_file_by_name("autorun")
var/list/data = get_header_data()
var/list/programs = list()
for(var/datum/computer_file/program/P in hard_drive.stored_files)
var/list/program = list()
program["name"] = P.filename
program["desc"] = P.filedesc
program["icon"] = P.program_menu_icon
program["autorun"] = (istype(autorun) && (autorun.stored_data == P.filename)) ? 1 : 0
if(P in idle_threads)
program["running"] = 1
programs.Add(list(program))
data["programs"] = programs
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "laptop_mainscreen.tmpl", "NTOS Main Menu", 400, 500)
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "NtosMain")
ui.set_autoupdate(TRUE)
ui.open()
ui.set_auto_update(1)
/obj/item/modular_computer/tgui_data(mob/user, datum/tgui/ui, datum/tgui_state/state)
var/list/data = get_header_data()
data["device_theme"] = device_theme
data["login"] = list()
var/obj/item/weapon/computer_hardware/card_slot/cardholder = card_slot
if(cardholder)
var/obj/item/weapon/card/id/stored_card = cardholder.stored_card
if(stored_card)
var/stored_name = stored_card.registered_name
var/stored_title = stored_card.assignment
if(!stored_name)
stored_name = "Unknown"
if(!stored_title)
stored_title = "Unknown"
data["login"] = list(
IDName = stored_name,
IDJob = stored_title,
)
data["removable_media"] = list()
var/datum/computer_file/data/autorun = hard_drive.find_file_by_name("autorun")
data["programs"] = list()
for(var/datum/computer_file/program/P in hard_drive.stored_files)
var/running = FALSE
if(P in idle_threads)
running = TRUE
data["programs"] += list(list(
"name" = P.filename,
"desc" = P.filedesc,
"icon" = P.program_menu_icon,
"running" = running,
"autorun" = (istype(autorun) && (autorun.stored_data == P.filename)) ? 1 : 0
))
data["has_light"] = FALSE // has_light
data["light_on"] = FALSE // light_on
data["comp_light_color"] = null // comp_light_color
return data
// Handles user's GUI input
/obj/item/modular_computer/Topic(href, href_list)
/obj/item/modular_computer/tgui_act(action, list/params, datum/tgui/ui, datum/tgui_state/state)
if(..())
return 1
if( href_list["PC_exit"] )
kill_program()
return 1
if( href_list["PC_enable_component"] )
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_enable_component"])
if(H && istype(H) && !H.enabled)
H.enabled = 1
. = 1
if( href_list["PC_disable_component"] )
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_disable_component"])
if(H && istype(H) && H.enabled)
H.enabled = 0
. = 1
if( href_list["PC_shutdown"] )
shutdown_computer()
return 1
if( href_list["PC_minimize"] )
var/mob/user = usr
minimize_program(user)
return TRUE
switch(action)
if("PC_exit")
kill_program()
return TRUE
if("PC_shutdown")
shutdown_computer()
return TRUE
if("PC_minimize")
var/mob/user = usr
minimize_program(user)
if("PC_killprogram")
var/prog = params["name"]
var/datum/computer_file/program/P = null
var/mob/user = usr
if(hard_drive)
P = hard_drive.find_file_by_name(prog)
if( href_list["PC_killprogram"] )
var/prog = href_list["PC_killprogram"]
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
if(!istype(P) || P.program_state == PROGRAM_STATE_KILLED)
P.kill_program(1)
to_chat(user, "<span class='notice'>Program [P.filename].[P.filetype] with PID [rand(100,999)] has been killed.</span>")
return TRUE
if("PC_runprogram")
return run_program(params["name"])
if("PC_setautorun")
if(!hard_drive)
return
set_autorun(params["name"])
return TRUE
if("PC_Eject_Disk")
var/param = params["name"]
switch(param)
if("ID")
proc_eject_id(usr)
return TRUE
else
return
P.kill_program(1)
update_uis()
to_chat(user, "<span class='notice'>Program [P.filename].[P.filetype] with PID [rand(100,999)] has been killed.</span>")
if( href_list["PC_runprogram"] )
return run_program(href_list["PC_runprogram"])
if( href_list["PC_setautorun"] )
if(!hard_drive)
return
set_autorun(href_list["PC_setautorun"])
if(.)
update_uis()
// Function used by NanoUI's to obtain data for header. All relevant entries begin with "PC_"
// Function used by TGUI's to obtain data for header. All relevant entries begin with "PC_"
/obj/item/modular_computer/proc/get_header_data()
var/list/data = list()
@@ -152,4 +177,4 @@
data["PC_stationtime"] = stationtime2text()
data["PC_hasheader"] = 1
data["PC_showexitprogram"] = active_program ? 1 : 0 // Hides "Exit Program" button on mainscreen
return data
return data

View File

@@ -6,6 +6,7 @@
var/enabled = 0 // Whether the computer is turned on.
var/screen_on = 1 // Whether the computer is active/opened/it's screen is on.
var/device_theme = "ntos" // Sets the theme for the main menu, hardware config, and file browser apps. Overridden by certain non-NT devices.
var/datum/computer_file/program/active_program = null // A currently active program running on the computer.
var/hardware_flag = 0 // A flag that describes this device type
var/last_power_usage = 0 // Last tick power usage of this computer

View File

@@ -0,0 +1,48 @@
//Rugged laptop
/obj/item/modular_computer/laptop/preset/custom_loadout/rugged
name = "rugged laptop computer"
desc = "A rugged portable computer."
icon_state_unpowered = "ruggedplus-open"
icon_state = "ruggedplus-open"
icon_state_closed = "ruggedplus-closed"
max_damage = 300
broken_damage = 200
/obj/item/modular_computer/laptop/preset/custom_loadout/rugged/install_default_hardware()
..()
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/small(src)
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/advanced(src)
network_card = new/obj/item/weapon/computer_hardware/network_card/advanced(src)
nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(src)
card_slot = new/obj/item/weapon/computer_hardware/card_slot(src)
battery_module = new/obj/item/weapon/computer_hardware/battery_module/super(src)
battery_module.charge_to_full()
//Fancy Schmancy - this is defined in normal file, just swapping the icon
/obj/item/modular_computer/laptop/preset/custom_loadout/elite
name = "elite laptop computer"
desc = "Fancy shcmancy laptop."
icon_state_unpowered = "elite-open"
icon_state = "elite-open"
icon_state_closed = "elite-closed"
//Alien/Human hybrid tech
/obj/item/modular_computer/laptop/preset/custom_loadout/hybrid
name = "hybrid laptop computer"
desc = "Weird glowy alien/human crossover tech."
icon_state_unpowered = "hybrid-open"
icon_state = "hybrid-open"
icon_state_closed = "hybrid-closed"
/obj/item/modular_computer/laptop/preset/custom_loadout/hybrid/install_default_hardware()
..()
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/photonic(src)
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/super(src)
network_card = new/obj/item/weapon/computer_hardware/network_card/advanced(src)
nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(src)
card_slot = new/obj/item/weapon/computer_hardware/card_slot(src)
battery_module = new/obj/item/weapon/computer_hardware/battery_module/lambda(src)
battery_module.charge_to_full()

View File

@@ -0,0 +1,53 @@
/obj/item/modular_computer/tablet/preset/custom_loadout/rugged
name = "rugged tablet computer"
desc = "A rugged tablet computer."
icon = 'icons/obj/modular_tablet.dmi'
icon_state = "rugged"
icon_state_unpowered = "rugged"
max_damage = 300
broken_damage = 200
/obj/item/modular_computer/tablet/preset/custom_loadout/rugged/install_default_hardware()
..()
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/small(src)
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/small(src)
network_card = new/obj/item/weapon/computer_hardware/network_card(src)
battery_module = new/obj/item/weapon/computer_hardware/battery_module/micro(src)
battery_module.charge_to_full()
/obj/item/modular_computer/tablet/preset/custom_loadout/elite
name = "elite tablet computer"
desc = "A more expensive tablet computer."
icon = 'icons/obj/modular_tablet.dmi'
icon_state = "elite"
icon_state_unpowered = "elite"
/obj/item/modular_computer/tablet/preset/custom_loadout/elite/install_default_hardware()
..()
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/small(src)
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/small(src)
network_card = new/obj/item/weapon/computer_hardware/network_card/advanced(src)
nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(src)
card_slot = new/obj/item/weapon/computer_hardware/card_slot(src)
battery_module = new/obj/item/weapon/computer_hardware/battery_module(src)
battery_module.charge_to_full()
/obj/item/modular_computer/tablet/preset/custom_loadout/hybrid
name = "hybrid tablet computer"
desc = "A human/alien hybrid tech tablet computer."
icon = 'icons/obj/modular_tablet.dmi'
icon_state = "hybrid"
icon_state_unpowered = "hybrid"
/obj/item/modular_computer/tablet/preset/custom_loadout/hybrid/install_default_hardware()
..()
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/photonic/small(src)
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/small(src)
network_card = new/obj/item/weapon/computer_hardware/network_card/advanced(src)
nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(src)
card_slot = new/obj/item/weapon/computer_hardware/card_slot(src)
battery_module = new/obj/item/weapon/computer_hardware/battery_module/lambda(src)
battery_module.charge_to_full()