mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-22 16:12:19 +00:00
* tgui the beginning * binaries and the like * Bring in the last of it * Example radio UI * delete example * NTOS Main Menu, start on manifest, tgui states * tasks.json * gunnery ui pt 1 * okay * fix everything * scss update * oops * manifest gigablast * downloader part 1 * download prt 2 * NTOSDownloader final * mfw committing to_worlds * gunnery console pt2 * i cooked * targeting (finished) * one vueui down * voting ui almost done * MY MIND FEELS LIKE AN ARCH ENEMYYYY * voting ui down * photocopier * ntos config + download fixes * photocopier 2 * refactor define * NTOS client manager + fixes * fax machine final (it also uses toner now) * marching forwards... left behind... * ntnrc part 1 * canister * add quotes * portable pumps pt1 + more backgrounds * oops * finish the portable pump * freezers so I'll keep on pushing forward... you haven't seen the last of me... oooooooh... * doors ui pt1 * finish doors UI (forgive me wildkins it's a bit of shitcode) * vitals monitor, make things use labeled lists, new backgrounds * mais j'envoyé aucun mayday... * maglock pt1 * pour ça je me suis perdu... * infrared * fix that * prox sensor pt1 * prox sensor * signaler (this was actually pretty hard) * atmos control pt1 * atmos control pt1.1 * atmos pt 2 * fuel injector * multitool UI * jammer * list viewer * APC * portgen * targeting console updates + SMES ui * new themes, shield generator * supermatter * Add ore detector and (shitty) NTNet Relay * orderterminal pt1 * orderterminal pt2 * smartfridge * Add (air-)tank GUI update ore detector size * Adds Transfer Valves * Add AtmoScrubber * analyzer pt1 * weapons analyzer pt2 * bodyscanner pt1 * bodyscanner pt2 * fix this shitcode * seed storage * appearance changer * appearance changer final * sleeper pt1 * sleeper * gps * vehicles * chem dispenser * lily request * holopad * tgui modules pt1 * ppanel * damage menu * fixes * im here too now * follow menu, search bars * quikpay * quikpay fixes * circuit printer * ppanel * ppanel updates * pai * turret controls (i want to kill myself) * tweak * remove the boardgame * guntracker * implant tracker * penal mechs come close to me, come close to me * chem codex * pai radio * doorjack * pai directives * signaler removal, sensors * ghost spawner * spawnpoint * fixes * teleporter * one more to the chopping block * account database * remove divider * scanner, atmos * latejoin ui pt1 * latejoin * records pt1 * RECORDS UI DONE * delete interpreter & records * CHAT FUCKING CLIENT * data updates * fix some things * final UI, log * basic nanoui fix * antag panel * remove vueui * atm update * vending update * warrants, cameras * ntmonitor * time comes for all * preserve this legacy * bring that back (oops) * rcon, ui auto update for computer UIs, remove rcon computers * alarm monitoring (a bit broke and also todo: add custom alarm monitoring programs to a few consoles) * A LIKE SUPREME * a * power monitor * lights on * fuck this code, fuck nanoui modules, and fuck nanoui * LEAVE IT OH SO FAR BEHIND * fix alarm monitoring for synths * I SAW IN YOU WHAT LIFE WAS MISSING * comms console * idcard and record updates * turn the light on * arcade * pt2 * news browser * static * crusher * f * COULD I JUST SLEIGH THE GOLD FROM THE BALLS? I'M SO FRUSTRATED OH COULD YOU TELL? IF I HEAR ONE MORE VUEUI OR ONE NANOUI I'M GONNA LOSE IT SO LET ME GOOOOOOOOOOOOOOOOO * codeowners & suit sensors * html ui style removal * make lint happy * resist and disorder * i slowly get up and turn off the noise, already fed up... * pleaseeeeeeeeeeeeeee * THE CREDIT LARP IS NECESSARY * i hold the keys * RISE UP * fix that? * harry's suggestions xoxo * runtime fix pt2 * You are the only thing that I still care about * adds build workflow * Update update_tgui.yml * adds some needed steps * ATM * misc fixes and tweaks * fixes 2 * make newscasters usable and fix use power on freezers * turret control is clearer --------- Co-authored-by: John Wildkins <john.wildkins@gmail.com> Co-authored-by: Matt Atlas <liermattia@gmail.com> Co-authored-by: harryob <55142896+harryob@users.noreply.github.com> Co-authored-by: Werner <Arrow768@users.noreply.github.com> Co-authored-by: Geeves <ggrobler447@gmail.com> Co-authored-by: harryob <me@harryob.live>
362 lines
9.7 KiB
Plaintext
362 lines
9.7 KiB
Plaintext
/*!
|
|
* Copyright (c) 2020 Aleksej Komarov
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/**
|
|
* tgui datum (represents a UI).
|
|
*/
|
|
/datum/tgui
|
|
/// The mob who opened/is using the UI.
|
|
var/mob/user
|
|
/// The object which owns the UI.
|
|
var/datum/src_object
|
|
/// The title of the UI.
|
|
var/title
|
|
/// The window_id for browse() and onclose().
|
|
var/datum/tgui_window/window
|
|
/// Key that is used for remembering the window geometry.
|
|
var/window_key
|
|
/// Deprecated: Window size.
|
|
var/window_size
|
|
/// The interface (template) to be used for this UI.
|
|
var/interface
|
|
/// Update the UI every MC tick.
|
|
var/autoupdate = TRUE
|
|
/// If the UI has been initialized yet.
|
|
var/initialized = FALSE
|
|
/// Time of opening the window.
|
|
var/opened_at
|
|
/// Stops further updates when close() was called.
|
|
var/closing = FALSE
|
|
/// The status/visibility of the UI.
|
|
var/status = UI_INTERACTIVE
|
|
/// Timed refreshing state
|
|
var/refreshing = FALSE
|
|
/// Topic state used to determine status/interactability.
|
|
var/datum/ui_state/state = null
|
|
/// Rate limit client refreshes to prevent DoS.
|
|
COOLDOWN_DECLARE(refresh_cooldown)
|
|
/// Are byond mouse events beyond the window passed in to the ui
|
|
var/mouse_hooked = FALSE
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Create a new UI.
|
|
*
|
|
* required user mob The mob who opened/is using the UI.
|
|
* 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 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)
|
|
log_tgui(user,
|
|
"new [interface] fancy [user?.client?.prefs.tgui_fancy]",
|
|
src_object = src_object)
|
|
src.user = user
|
|
src.src_object = src_object
|
|
src.window_key = "[text_ref(src_object)]-main"
|
|
src.interface = interface
|
|
if(title)
|
|
src.title = title
|
|
src.state = src_object.ui_state(user)
|
|
// Deprecated
|
|
if(ui_x && ui_y)
|
|
src.window_size = list(ui_x, ui_y)
|
|
|
|
/datum/tgui/Destroy()
|
|
user = null
|
|
src_object = null
|
|
return ..()
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Open this UI (and initialize it with data).
|
|
*
|
|
* return bool - TRUE if a new pooled window is opened, FALSE in all other situations including if a new pooled window didn't open because one already exists.
|
|
*/
|
|
/datum/tgui/proc/open()
|
|
if(!user?.client)
|
|
return FALSE
|
|
if(window)
|
|
return FALSE
|
|
process_status()
|
|
if(status < UI_UPDATE)
|
|
return FALSE
|
|
window = SStgui.request_pooled_window(user)
|
|
if(!window)
|
|
return FALSE
|
|
opened_at = world.time
|
|
window.acquire_lock(src)
|
|
if(!window.is_ready())
|
|
window.initialize(
|
|
strict_mode = TRUE,
|
|
fancy = user.client.prefs.tgui_fancy,
|
|
assets = list(
|
|
get_asset_datum(/datum/asset/simple/tgui),
|
|
))
|
|
else
|
|
window.send_message("ping")
|
|
send_assets()
|
|
window.send_message("update", get_payload(
|
|
with_data = TRUE,
|
|
with_static_data = TRUE))
|
|
if(mouse_hooked)
|
|
window.set_mouse_macro()
|
|
SStgui.on_open(src)
|
|
|
|
return TRUE
|
|
|
|
/datum/tgui/proc/send_assets()
|
|
var/flush_queue = window.send_asset(get_asset_datum(
|
|
/datum/asset/simple/namespaced/fontawesome))
|
|
flush_queue |= window.send_asset(get_asset_datum(
|
|
/datum/asset/simple/namespaced/tgfont))
|
|
for(var/datum/asset/asset in src_object.ui_assets(user))
|
|
flush_queue |= window.send_asset(asset)
|
|
if (flush_queue)
|
|
user.client.browse_queue_flush()
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Close the UI.
|
|
*
|
|
* optional can_be_suspended bool
|
|
*/
|
|
/datum/tgui/proc/close(can_be_suspended = TRUE)
|
|
if(closing)
|
|
return
|
|
closing = TRUE
|
|
// 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)
|
|
// Windows you want to keep are usually blue screens of death
|
|
// and we want to keep them around, to allow user to read
|
|
// the error message properly.
|
|
window.release_lock()
|
|
window.close(can_be_suspended)
|
|
src_object.ui_close(user)
|
|
SStgui.on_close(src)
|
|
state = null
|
|
qdel(src)
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Enable/disable auto-updating of the UI.
|
|
*
|
|
* required value bool Enable/disable auto-updating.
|
|
*/
|
|
/datum/tgui/proc/set_autoupdate(autoupdate)
|
|
src.autoupdate = autoupdate
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Enable/disable passing through byond mouse events to the window
|
|
*
|
|
* required value bool Enable/disable hooking.
|
|
*/
|
|
/datum/tgui/proc/set_mouse_hook(value)
|
|
src.mouse_hooked = value
|
|
//Handle unhooking/hooking on already open windows ?
|
|
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Replace current ui.state with a new one.
|
|
*
|
|
* required state datum/ui_state/state Next state
|
|
*/
|
|
/datum/tgui/proc/set_state(datum/ui_state/state)
|
|
src.state = state
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Makes an asset available to use in tgui.
|
|
*
|
|
* required asset datum/asset
|
|
*
|
|
* return bool - true if an asset was actually sent
|
|
*/
|
|
/datum/tgui/proc/send_asset(datum/asset/asset)
|
|
if(!window)
|
|
CRASH("send_asset() was called either without calling open() first or when open() did not return TRUE.")
|
|
return window.send_asset(asset)
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Send a full update to the client (includes static data).
|
|
*
|
|
* optional custom_data list Custom data to send instead of ui_data.
|
|
* optional force bool Send an update even if UI is not interactive.
|
|
*/
|
|
/datum/tgui/proc/send_full_update(custom_data, force)
|
|
if(!user.client || !initialized || closing)
|
|
return
|
|
if(!COOLDOWN_FINISHED(src, refresh_cooldown))
|
|
refreshing = TRUE
|
|
addtimer(CALLBACK(src, PROC_REF(send_full_update), custom_data, force), COOLDOWN_TIMELEFT(src, refresh_cooldown), TIMER_UNIQUE)
|
|
return
|
|
refreshing = FALSE
|
|
var/should_update_data = force || status >= UI_UPDATE
|
|
window.send_message("update", get_payload(
|
|
custom_data,
|
|
with_data = should_update_data,
|
|
with_static_data = TRUE))
|
|
COOLDOWN_START(src, refresh_cooldown, TGUI_REFRESH_FULL_UPDATE_COOLDOWN)
|
|
|
|
/**
|
|
* public
|
|
*
|
|
* Send a partial update to the client (excludes static data).
|
|
*
|
|
* optional custom_data list Custom data to send instead of ui_data.
|
|
* optional force bool Send an update even if UI is not interactive.
|
|
*/
|
|
/datum/tgui/proc/send_update(custom_data, force)
|
|
if(!user.client || !initialized || closing)
|
|
return
|
|
var/should_update_data = force || status >= UI_UPDATE
|
|
window.send_message("update", get_payload(
|
|
custom_data,
|
|
with_data = should_update_data))
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Package the data to send to the UI, as JSON.
|
|
*
|
|
* return list
|
|
*/
|
|
/datum/tgui/proc/get_payload(custom_data, with_data, with_static_data)
|
|
var/list/json_data = list()
|
|
json_data["config"] = list(
|
|
"title" = title,
|
|
"status" = status,
|
|
"interface" = interface,
|
|
"refreshing" = refreshing,
|
|
"window" = list(
|
|
"key" = window_key,
|
|
"size" = window_size,
|
|
"fancy" = user.client.prefs.tgui_fancy,
|
|
"locked" = user.client.prefs.tgui_lock,
|
|
),
|
|
"client" = list(
|
|
"ckey" = user.client.ckey,
|
|
"address" = user.client.address,
|
|
"computer_id" = user.client.computer_id,
|
|
),
|
|
"user" = list(
|
|
"name" = "[user]",
|
|
"observer" = isobserver(user),
|
|
),
|
|
)
|
|
var/data = custom_data || with_data && src_object.ui_data(user)
|
|
if(data)
|
|
json_data["data"] = data
|
|
var/static_data = with_static_data && src_object.ui_static_data(user)
|
|
if(static_data)
|
|
json_data["static_data"] = static_data
|
|
if(src_object.tgui_shared_states)
|
|
json_data["shared"] = src_object.tgui_shared_states
|
|
return json_data
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Run an update cycle for this UI. Called internally by SStgui
|
|
* every second or so.
|
|
*/
|
|
/datum/tgui/process(seconds_per_tick, force = FALSE)
|
|
if(closing)
|
|
return
|
|
var/datum/host = src_object.ui_host(user)
|
|
// If the object or user died (or something else), abort.
|
|
if(QDELETED(src_object) || QDELETED(host) || QDELETED(user) || QDELETED(window))
|
|
close(can_be_suspended = FALSE)
|
|
return
|
|
// Validate ping
|
|
if(!initialized && world.time - opened_at > TGUI_PING_TIMEOUT)
|
|
log_tgui(user, "Error: Zombie window detected, closing.",
|
|
window = window,
|
|
src_object = src_object)
|
|
close(can_be_suspended = FALSE)
|
|
return
|
|
// Update through a normal call to ui_interact
|
|
if(status != UI_DISABLED && (autoupdate || force))
|
|
src_object.ui_interact(user, src)
|
|
return
|
|
// Update status only
|
|
var/needs_update = process_status()
|
|
if(status <= UI_CLOSE)
|
|
close()
|
|
return
|
|
if(needs_update)
|
|
window.send_message("update", get_payload())
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Updates the status, and returns TRUE if status has changed.
|
|
*/
|
|
/datum/tgui/proc/process_status()
|
|
var/prev_status = status
|
|
status = src_object.ui_status(user, state)
|
|
return prev_status != status
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Callback for handling incoming tgui messages.
|
|
*/
|
|
/datum/tgui/proc/on_message(type, list/payload, list/href_list)
|
|
// Pass act type messages to ui_act
|
|
if(type && copytext(type, 1, 5) == "act/")
|
|
var/act_type = copytext(type, 5)
|
|
log_tgui(user, "Action: [act_type] [href_list["payload"]]",
|
|
window = window,
|
|
src_object = src_object)
|
|
process_status()
|
|
on_act_message(act_type, payload, state)
|
|
//DEFAULT_QUEUE_OR_CALL_VERB(VERB_CALLBACK(src, PROC_REF(on_act_message), act_type, payload, state))
|
|
return FALSE
|
|
switch(type)
|
|
if("ready")
|
|
// Send a full update when the user manually refreshes the UI
|
|
if(initialized)
|
|
send_full_update()
|
|
initialized = TRUE
|
|
if("ping/reply")
|
|
initialized = TRUE
|
|
if("suspend")
|
|
close(can_be_suspended = TRUE)
|
|
if("close")
|
|
close(can_be_suspended = FALSE)
|
|
if("log")
|
|
if(href_list["fatal"])
|
|
close(can_be_suspended = FALSE)
|
|
if("setSharedState")
|
|
if(status != UI_INTERACTIVE)
|
|
return
|
|
LAZYINITLIST(src_object.tgui_shared_states)
|
|
src_object.tgui_shared_states[href_list["key"]] = href_list["value"]
|
|
SStgui.update_uis(src_object)
|
|
|
|
/// Wrapper for behavior to potentially wait until the next tick if the server is overloaded
|
|
/datum/tgui/proc/on_act_message(act_type, payload, state)
|
|
if(QDELETED(src) || QDELETED(src_object))
|
|
return
|
|
if(src_object.ui_act(act_type, payload, src, state))
|
|
SStgui.update_uis(src_object)
|