mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
TGUI Backend Tweaks & Fixes
This commit is contained in:
@@ -12,9 +12,10 @@
|
||||
*
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
* optional ui datum/tgui The UI to be updated, if it exists.
|
||||
* optional parent_ui datum/tgui A parent UI that, when closed, closes this UI as well.
|
||||
*/
|
||||
|
||||
/datum/proc/tgui_interact(mob/user, datum/tgui/ui = null)
|
||||
/datum/proc/tgui_interact(mob/user, datum/tgui/ui = null, datum/tgui/parent_ui = null)
|
||||
return FALSE // Not implemented.
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@
|
||||
*
|
||||
* return list Data to be sent to the UI.
|
||||
*/
|
||||
/datum/proc/tgui_data(mob/user)
|
||||
/datum/proc/tgui_data(mob/user, datum/tgui/ui, datum/tgui_state/state)
|
||||
return list() // Not implemented.
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,12 +12,15 @@ Code is pretty much ripped verbatim from nano modules, but with un-needed stuff
|
||||
var/list/using_access
|
||||
|
||||
var/tgui_id
|
||||
var/ntos = FALSE
|
||||
|
||||
/datum/tgui_module/New(var/host)
|
||||
src.host = host
|
||||
if(ntos)
|
||||
tgui_id = "Ntos" + tgui_id
|
||||
|
||||
/datum/tgui_module/tgui_host()
|
||||
return host ? host : src
|
||||
return host ? host.tgui_host() : src
|
||||
|
||||
/datum/tgui_module/tgui_close(mob/user)
|
||||
if(host)
|
||||
@@ -43,4 +46,34 @@ Code is pretty much ripped verbatim from nano modules, but with un-needed stuff
|
||||
if(access in I.access)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
return 0
|
||||
|
||||
/datum/tgui_module/tgui_static_data()
|
||||
. = ..()
|
||||
|
||||
var/obj/item/modular_computer/host = tgui_host()
|
||||
if(istype(host))
|
||||
. += host.get_header_data()
|
||||
|
||||
/datum/tgui_module/tgui_act(action, params)
|
||||
if(..())
|
||||
return TRUE
|
||||
|
||||
var/obj/item/modular_computer/host = tgui_host()
|
||||
if(istype(host))
|
||||
if(action == "PC_exit")
|
||||
host.kill_program()
|
||||
return TRUE
|
||||
if(action == "PC_shutdown")
|
||||
host.shutdown_computer()
|
||||
return TRUE
|
||||
if(action == "PC_minimize")
|
||||
host.minimize_program(usr)
|
||||
return TRUE
|
||||
|
||||
// Just a nice little default interact in case the subtypes don't need any special behavior here
|
||||
/datum/tgui_module/tgui_interact(mob/user, datum/tgui/ui = null)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, tgui_id, name)
|
||||
ui.open()
|
||||
@@ -144,7 +144,7 @@
|
||||
return data
|
||||
|
||||
/datum/tgui_module/camera/tgui_static_data(mob/user)
|
||||
var/list/data = list()
|
||||
var/list/data = ..()
|
||||
data["mapRef"] = map_name
|
||||
var/list/cameras = get_available_cameras(user)
|
||||
data["cameras"] = list()
|
||||
@@ -160,11 +160,11 @@
|
||||
|
||||
/datum/tgui_module/camera/tgui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
return TRUE
|
||||
|
||||
if(action && !issilicon(usr))
|
||||
playsound(tgui_host(), "terminal_type", 50, 1)
|
||||
|
||||
|
||||
if(action == "switch_camera")
|
||||
var/c_tag = params["name"]
|
||||
var/list/cameras = get_available_cameras(usr)
|
||||
@@ -287,33 +287,7 @@
|
||||
// If/when that is done, just move all the PC_ specific data and stuff to the modular computers themselves
|
||||
// instead of copying this approach here.
|
||||
/datum/tgui_module/camera/ntos
|
||||
tgui_id = "NtosCameraConsole"
|
||||
|
||||
/datum/tgui_module/camera/ntos/tgui_state()
|
||||
return GLOB.tgui_ntos_state
|
||||
|
||||
/datum/tgui_module/camera/ntos/tgui_static_data()
|
||||
. = ..()
|
||||
|
||||
var/datum/computer_file/program/host = tgui_host()
|
||||
if(istype(host) && host.computer)
|
||||
. += host.computer.get_header_data()
|
||||
|
||||
/datum/tgui_module/camera/ntos/tgui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
|
||||
var/datum/computer_file/program/host = tgui_host()
|
||||
if(istype(host) && host.computer)
|
||||
if(action == "PC_exit")
|
||||
host.computer.kill_program()
|
||||
return TRUE
|
||||
if(action == "PC_shutdown")
|
||||
host.computer.shutdown_computer()
|
||||
return TRUE
|
||||
if(action == "PC_minimize")
|
||||
host.computer.minimize_program(usr)
|
||||
return TRUE
|
||||
ntos = TRUE
|
||||
|
||||
// ERT Version provides some additional networks.
|
||||
/datum/tgui_module/camera/ntos/ert
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
return TRUE
|
||||
if("setZLevel")
|
||||
ui.set_map_z_level(params["mapZLevel"])
|
||||
SStgui.update_uis(src)
|
||||
return TRUE
|
||||
|
||||
/datum/tgui_module/crew_monitor/tgui_interact(mob/user, datum/tgui/ui = null)
|
||||
var/z = get_z(user)
|
||||
@@ -43,7 +43,7 @@
|
||||
ui.open()
|
||||
|
||||
|
||||
/datum/tgui_module/crew_monitor/tgui_data(mob/user, ui_key = "main", datum/tgui_state/state = GLOB.tgui_default_state)
|
||||
/datum/tgui_module/crew_monitor/tgui_data(mob/user)
|
||||
var/data[0]
|
||||
|
||||
data["isAI"] = isAI(user)
|
||||
@@ -59,33 +59,7 @@
|
||||
return data
|
||||
|
||||
/datum/tgui_module/crew_monitor/ntos
|
||||
tgui_id = "NtosCrewMonitor"
|
||||
|
||||
/datum/tgui_module/crew_monitor/ntos/tgui_state(mob/user)
|
||||
return GLOB.tgui_ntos_state
|
||||
|
||||
/datum/tgui_module/crew_monitor/ntos/tgui_static_data()
|
||||
. = ..()
|
||||
|
||||
var/datum/computer_file/program/host = tgui_host()
|
||||
if(istype(host) && host.computer)
|
||||
. += host.computer.get_header_data()
|
||||
|
||||
/datum/tgui_module/crew_monitor/ntos/tgui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
|
||||
var/datum/computer_file/program/host = tgui_host()
|
||||
if(istype(host) && host.computer)
|
||||
if(action == "PC_exit")
|
||||
host.computer.kill_program()
|
||||
return TRUE
|
||||
if(action == "PC_shutdown")
|
||||
host.computer.shutdown_computer()
|
||||
return TRUE
|
||||
if(action == "PC_minimize")
|
||||
host.computer.minimize_program(usr)
|
||||
return TRUE
|
||||
ntos = TRUE
|
||||
|
||||
// Subtype for glasses_state
|
||||
/datum/tgui_module/crew_monitor/glasses
|
||||
|
||||
@@ -36,13 +36,29 @@ GLOBAL_DATUM_INIT(tgui_default_state, /datum/tgui_state/default, new)
|
||||
return STATUS_DISABLED // Otherwise they can keep the UI open.
|
||||
|
||||
/mob/living/silicon/ai/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. < STATUS_INTERACTIVE)
|
||||
. = shared_tgui_interaction()
|
||||
if(. != STATUS_INTERACTIVE)
|
||||
return
|
||||
|
||||
// The AI can interact with anything it can see nearby, or with cameras while wireless control is enabled.
|
||||
if(!control_disabled && can_see(src_object))
|
||||
// Prevents the AI from using Topic on admin levels (by for example viewing through the court/thunderdome cameras)
|
||||
// unless it's on the same level as the object it's interacting with.
|
||||
var/turf/T = get_turf(src_object)
|
||||
if(!T || !(z == T.z || (T.z in using_map.player_levels)))
|
||||
return STATUS_CLOSE
|
||||
|
||||
// If an object is in view then we can interact with it
|
||||
if(src_object in view(client.view, src))
|
||||
return STATUS_INTERACTIVE
|
||||
|
||||
// If we're installed in a chassi, rather than transfered to an inteliCard or other container, then check if we have camera view
|
||||
if(is_in_chassis())
|
||||
//stop AIs from leaving windows open and using then after they lose vision
|
||||
if(cameranet && !cameranet.checkTurfVis(get_turf(src_object)))
|
||||
return STATUS_CLOSE
|
||||
return STATUS_INTERACTIVE
|
||||
else if(get_dist(src_object, src) <= client.view) // View does not return what one would expect while installed in an inteliCard
|
||||
return STATUS_INTERACTIVE
|
||||
|
||||
return STATUS_CLOSE
|
||||
|
||||
/mob/living/simple_animal/default_can_use_tgui_topic(src_object)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* tgui state: ntos_state
|
||||
*
|
||||
* Checks a number of things -- mostly physical distance for humans and view for robots.
|
||||
* This is basically the same as default, except instead of src_object, it uses the computer
|
||||
* it's attached to.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(tgui_ntos_state, /datum/tgui_state/ntos, new)
|
||||
|
||||
/datum/tgui_state/ntos/can_use_topic(src_object, mob/user)
|
||||
var/datum/computer_file/program/P = src_object
|
||||
if(!istype(P) || !P.computer)
|
||||
return FALSE
|
||||
return user.default_can_use_tgui_topic(P.computer) // Call the individual mob-overridden procs.
|
||||
@@ -34,8 +34,12 @@
|
||||
var/status = STATUS_INTERACTIVE
|
||||
/// Topic state used to determine status/interactability.
|
||||
var/datum/tgui_state/state = null
|
||||
// The map z-level to display.
|
||||
/// The map z-level to display.
|
||||
var/map_z_level = 1
|
||||
/// The Parent UI
|
||||
var/datum/tgui/parent_ui
|
||||
/// Children of this UI
|
||||
var/list/children = list()
|
||||
|
||||
/**
|
||||
* public
|
||||
@@ -46,12 +50,13 @@
|
||||
* required src_object datum The object or datum which owns the UI.
|
||||
* required interface string The interface used to render the UI.
|
||||
* optional title string The title of the UI.
|
||||
* optional parent_ui datum/tgui The parent of this UI.
|
||||
* optional ui_x int Deprecated: Window width.
|
||||
* optional ui_y int Deprecated: Window height.
|
||||
*
|
||||
* return datum/tgui The requested UI.
|
||||
*/
|
||||
/datum/tgui/New(mob/user, datum/src_object, interface, title, ui_x, ui_y)
|
||||
/datum/tgui/New(mob/user, datum/src_object, interface, title, datum/tgui/parent_ui, ui_x, ui_y)
|
||||
src.user = user
|
||||
src.src_object = src_object
|
||||
src.window_key = "[REF(src_object)]-main"
|
||||
@@ -59,6 +64,9 @@
|
||||
if(title)
|
||||
src.title = title
|
||||
src.state = src_object.tgui_state()
|
||||
src.parent_ui = parent_ui
|
||||
if(parent_ui)
|
||||
parent_ui.children += src
|
||||
// Deprecated
|
||||
if(ui_x && ui_y)
|
||||
src.window_size = list(ui_x, ui_y)
|
||||
@@ -104,6 +112,9 @@
|
||||
if(closing)
|
||||
return
|
||||
closing = TRUE
|
||||
for(var/datum/tgui/child in children)
|
||||
child.close()
|
||||
children.Cut()
|
||||
// If we don't have window_id, open proc did not have the opportunity
|
||||
// to finish, therefore it's safe to skip this whole block.
|
||||
if(window)
|
||||
@@ -115,6 +126,7 @@
|
||||
src_object.tgui_close(user)
|
||||
SStgui.on_close(src)
|
||||
state = null
|
||||
parent_ui = null
|
||||
qdel(src)
|
||||
|
||||
/**
|
||||
@@ -209,7 +221,7 @@
|
||||
"observer" = isobserver(user),
|
||||
),
|
||||
)
|
||||
var/data = custom_data || with_data && src_object.tgui_data(user)
|
||||
var/data = custom_data || with_data && src_object.tgui_data(user, src, state)
|
||||
if(data)
|
||||
json_data["data"] = data
|
||||
var/static_data = with_static_data && src_object.tgui_static_data(user)
|
||||
@@ -244,7 +256,7 @@
|
||||
return
|
||||
// Update through a normal call to ui_interact
|
||||
if(status != STATUS_DISABLED && (autoupdate || force))
|
||||
src_object.tgui_interact(user, src)
|
||||
src_object.tgui_interact(user, src, parent_ui)
|
||||
return
|
||||
// Update status only
|
||||
var/needs_update = process_status()
|
||||
@@ -262,6 +274,8 @@
|
||||
/datum/tgui/proc/process_status()
|
||||
var/prev_status = status
|
||||
status = src_object.tgui_status(user, state)
|
||||
if(parent_ui)
|
||||
status = min(status, parent_ui.status)
|
||||
return prev_status != status
|
||||
|
||||
/datum/tgui/proc/log_message(message)
|
||||
|
||||
@@ -190,9 +190,9 @@
|
||||
/datum/tgui_window/proc/send_asset(datum/asset/asset)
|
||||
if(!client || !asset)
|
||||
return
|
||||
// if(istype(asset, /datum/asset/spritesheet))
|
||||
// var/datum/asset/spritesheet/spritesheet = asset
|
||||
// send_message("asset/stylesheet", spritesheet.css_filename())
|
||||
if(istype(asset, /datum/asset/spritesheet))
|
||||
var/datum/asset/spritesheet/spritesheet = asset
|
||||
send_message("asset/stylesheet", spritesheet.css_filename())
|
||||
send_message("asset/mappings", asset.get_url_mappings())
|
||||
sent_assets += list(asset)
|
||||
asset.send(client)
|
||||
|
||||
Reference in New Issue
Block a user