mirror of
https://github.com/quotefox/Hyper-Station-13.git
synced 2026-08-26 22:26:24 +01:00
first attempt at implementing TGUI 3
trying to update from TGUI Next to TGUI 3, so we can later upgrade from TGUI 3 to TGUI 4.
This commit is contained in:
+120
-109
@@ -1,140 +1,151 @@
|
||||
/**
|
||||
* tgui external
|
||||
*
|
||||
* Contains all external tgui declarations.
|
||||
**/
|
||||
/**
|
||||
* tgui external
|
||||
*
|
||||
* Contains all external tgui declarations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Used to open and update UIs.
|
||||
* If this proc is not implemented properly, the UI will not update correctly.
|
||||
*
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
* optional ui_key string The ui_key of the UI.
|
||||
* optional ui datum/tgui The UI to be updated, if it exists.
|
||||
* optional force_open bool If the UI should be re-opened instead of updated.
|
||||
* optional master_ui datum/tgui The parent UI.
|
||||
* optional state datum/ui_state The state used to determine status.
|
||||
**/
|
||||
/datum/proc/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Used to open and update UIs.
|
||||
* If this proc is not implemented properly, the UI will not update correctly.
|
||||
*
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
* optional ui_key string The ui_key of the UI.
|
||||
* optional ui datum/tgui The UI to be updated, if it exists.
|
||||
* optional force_open bool If the UI should be re-opened instead of updated.
|
||||
* optional master_ui datum/tgui The parent UI.
|
||||
* optional state datum/tgui_state The state used to determine status.
|
||||
*/
|
||||
|
||||
/datum/proc/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_default_state)
|
||||
return FALSE // Not implemented.
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Data to be sent to the UI.
|
||||
* This must be implemented for a UI to work.
|
||||
*
|
||||
* required user mob The mob interacting with the UI.
|
||||
*
|
||||
* return list Data to be sent to the UI.
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Data to be sent to the UI.
|
||||
* This must be implemented for a UI to work.
|
||||
*
|
||||
* required user mob The mob interacting with the UI.
|
||||
*
|
||||
* return list Data to be sent to the UI.
|
||||
*/
|
||||
/datum/proc/ui_data(mob/user)
|
||||
return list() // Not implemented.
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Static Data to be sent to the UI.
|
||||
* Static data differs from normal data in that it's large data that should be sent infrequently
|
||||
* This is implemented optionally for heavy uis that would be sending a lot of redundant data
|
||||
* frequently.
|
||||
* Gets squished into one object on the frontend side, but the static part is cached.
|
||||
*
|
||||
* required user mob The mob interacting with the UI.
|
||||
*
|
||||
* return list Statuic Data to be sent to the UI.
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Static Data to be sent to the UI.
|
||||
* Static data differs from normal data in that it's large data that should be sent infrequently
|
||||
* This is implemented optionally for heavy uis that would be sending a lot of redundant data
|
||||
* frequently.
|
||||
* Gets squished into one object on the frontend side, but the static part is cached.
|
||||
*
|
||||
* required user mob The mob interacting with the UI.
|
||||
*
|
||||
* return list Statuic Data to be sent to the UI.
|
||||
*/
|
||||
/datum/proc/ui_static_data(mob/user)
|
||||
return list()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Forces an update on static data. Should be done manually whenever something happens to change static data.
|
||||
*
|
||||
* required user the mob currently interacting with the ui
|
||||
* optional ui ui to be updated
|
||||
* optional ui_key ui key of ui to be updated
|
||||
*
|
||||
**/
|
||||
* public
|
||||
*
|
||||
* Forces an update on static data. Should be done manually whenever something happens to change static data.
|
||||
*
|
||||
* required user the mob currently interacting with the ui
|
||||
* optional ui ui to be updated
|
||||
* optional ui_key ui key of ui to be updated
|
||||
*/
|
||||
/datum/proc/update_static_data(mob/user, datum/tgui/ui, ui_key = "main")
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui)
|
||||
// If there was no ui to update, there's no static data to update either.
|
||||
if(!ui)
|
||||
return //If there was no ui to update, there's no static data to update either.
|
||||
return
|
||||
ui.push_data(null, ui_static_data(), TRUE)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on a UI when the UI receieves a href.
|
||||
* Think of this as Topic().
|
||||
*
|
||||
* required action string The action/button that has been invoked by the user.
|
||||
* required params list A list of parameters attached to the button.
|
||||
*
|
||||
* return bool If the UI should be updated or not.
|
||||
**/
|
||||
/datum/proc/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on a UI when the UI receieves a href.
|
||||
* Think of this as Topic().
|
||||
*
|
||||
* required action string The action/button that has been invoked by the user.
|
||||
* required params list A list of parameters attached to the button.
|
||||
*
|
||||
* return bool If the UI should be updated or not.
|
||||
*/
|
||||
/datum/proc/ui_act(action, list/params, datum/tgui/ui, datum/tgui_state/state)
|
||||
// If UI is not interactive or usr calling Topic is not the UI user, bail.
|
||||
if(!ui || ui.status != UI_INTERACTIVE)
|
||||
return 1 // If UI is not interactive or usr calling Topic is not the UI user, bail.
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on an object when a tgui object is being created, allowing you to customise the html
|
||||
* For example: inserting a custom stylesheet that you need in the head
|
||||
*
|
||||
* For this purpose, some tags are available in the html, to be parsed out with replacetext
|
||||
* (customheadhtml) - Additions to the head tag
|
||||
*
|
||||
* required html the html base text
|
||||
*
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on an object when a tgui object is being created, allowing you to
|
||||
* customise the html
|
||||
* For example: inserting a custom stylesheet that you need in the head
|
||||
*
|
||||
* For this purpose, some tags are available in the html, to be parsed out
|
||||
^ with replacetext
|
||||
* (customheadhtml) - Additions to the head tag
|
||||
*
|
||||
* required html the html base text
|
||||
*/
|
||||
/datum/proc/ui_base_html(html)
|
||||
return html
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* The UI's host object (usually src_object).
|
||||
* This allows modules/datums to have the UI attached to them,
|
||||
* and be a part of another object.
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* The UI's host object (usually src_object).
|
||||
* This allows modules/datums to have the UI attached to them,
|
||||
* and be a part of another object.
|
||||
*/
|
||||
/datum/proc/ui_host(mob/user)
|
||||
return src // Default src.
|
||||
|
||||
/**
|
||||
* global
|
||||
*
|
||||
* Used to track UIs for a mob.
|
||||
**/
|
||||
/mob/var/list/open_uis = list()
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on a UI's object when the UI is closed, not to be confused with client/verb/uiclose(), which closes the ui window
|
||||
*
|
||||
*
|
||||
**/
|
||||
/datum/proc/ui_close()
|
||||
/**
|
||||
* global
|
||||
*
|
||||
* Associative list of JSON-encoded shared states that were set by
|
||||
* tgui clients.
|
||||
*/
|
||||
|
||||
/**
|
||||
* verb
|
||||
*
|
||||
* Called by UIs when they are closed.
|
||||
* Must be a verb so winset() can call it.
|
||||
*
|
||||
* required uiref ref The UI that was closed.
|
||||
**/
|
||||
/client/verb/uiclose(ref as text)
|
||||
/datum/var/list/tgui_shared_states
|
||||
|
||||
/**
|
||||
* global
|
||||
*
|
||||
* Used to track UIs for a mob.
|
||||
*/
|
||||
/mob/var/list/open_tguis = list()
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on a UI's object when the UI is closed, not to be confused with
|
||||
* client/verb/uiclose(), which closes the ui window
|
||||
*/
|
||||
/datum/proc/ui_close(mob/user)
|
||||
|
||||
/**
|
||||
* verb
|
||||
*
|
||||
* Called by UIs when they are closed.
|
||||
* Must be a verb so winset() can call it.
|
||||
*
|
||||
* required uiref ref The UI that was closed.
|
||||
*/
|
||||
/client/verb/tguiclose(uid as text)
|
||||
// Name the verb, and hide it from the user panel.
|
||||
set name = "uiclose"
|
||||
set hidden = 1
|
||||
set hidden = TRUE
|
||||
|
||||
// Get the UI based on the ref.
|
||||
var/datum/tgui/ui = locate(ref)
|
||||
var/datum/tgui/ui = locateUID(uid)
|
||||
|
||||
// If we found the UI, close it.
|
||||
if(istype(ui))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
TGUI MODULES
|
||||
|
||||
This allows for datum-based TGUIs that can be hooked into objects.
|
||||
This is useful for things such as the power monitor, which needs to exist on a physical console in the world, but also as a virtual device the AI can use
|
||||
|
||||
Code is pretty much ripped verbatim from nano modules, but with un-needed stuff removed
|
||||
*/
|
||||
/datum/tgui_module
|
||||
var/name
|
||||
var/datum/host
|
||||
|
||||
/datum/tgui_module/New(var/host)
|
||||
src.host = host
|
||||
|
||||
/datum/tgui_module/ui_host()
|
||||
return host ? host : src
|
||||
|
||||
/datum/tgui_module/ui_close(mob/user)
|
||||
if(host)
|
||||
host.ui_close(user)
|
||||
+65
-65
@@ -1,20 +1,20 @@
|
||||
/**
|
||||
* tgui states
|
||||
*
|
||||
* Base state and helpers for states. Just does some sanity checks, implement a state for in-depth checks.
|
||||
**/
|
||||
/**
|
||||
* tgui states
|
||||
*
|
||||
* Base state and helpers for states. Just does some sanity checks, implement a state for in-depth checks.
|
||||
*/
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Checks the UI state for a mob.
|
||||
*
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
* required state datum/ui_state The state to check.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
**/
|
||||
/datum/proc/ui_status(mob/user, datum/ui_state/state)
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Checks the UI state for a mob.
|
||||
*
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
* required state datum/tgui_state The state to check.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
*/
|
||||
/datum/proc/ui_status(mob/user, datum/tgui_state/state)
|
||||
var/src_object = ui_host(user)
|
||||
. = UI_CLOSE
|
||||
if(!state)
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
if(isobserver(user))
|
||||
// If they turn on ghost AI control, admins can always interact.
|
||||
if(IsAdminGhost(user))
|
||||
if(user.has_unlimited_silicon_privilege)
|
||||
. = max(., UI_INTERACTIVE)
|
||||
|
||||
// Regular ghosts can always at least view if in range.
|
||||
@@ -34,72 +34,72 @@
|
||||
var/result = state.can_use_topic(src_object, user)
|
||||
. = max(., result)
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Checks if a user can use src_object's UI, and returns the state.
|
||||
* Can call a mob proc, which allows overrides for each mob.
|
||||
*
|
||||
* required src_object datum The object/datum which owns the UI.
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
**/
|
||||
/datum/ui_state/proc/can_use_topic(src_object, mob/user)
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Checks if a user can use src_object's UI, and returns the state.
|
||||
* Can call a mob proc, which allows overrides for each mob.
|
||||
*
|
||||
* required src_object datum The object/datum which owns the UI.
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
*/
|
||||
/datum/tgui_state/proc/can_use_topic(src_object, mob/user)
|
||||
return UI_CLOSE // Don't allow interaction by default.
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Standard interaction/sanity checks. Different mob types may have overrides.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
**/
|
||||
/mob/proc/shared_ui_interaction(src_object)
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Standard interaction/sanity checks. Different mob types may have overrides.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
*/
|
||||
/mob/proc/shared_tgui_interaction(src_object)
|
||||
if(!client) // Close UIs if mindless.
|
||||
return UI_CLOSE
|
||||
else if(stat) // Disable UIs if unconcious.
|
||||
return UI_DISABLED
|
||||
else if(incapacitated() || lying) // Update UIs if incapicitated but concious.
|
||||
else if(incapacitated()) // Update UIs if incapicitated but concious.
|
||||
return UI_UPDATE
|
||||
return UI_INTERACTIVE
|
||||
|
||||
/mob/living/silicon/ai/shared_ui_interaction(src_object)
|
||||
/mob/living/silicon/ai/shared_tgui_interaction(src_object)
|
||||
if(lacks_power()) // Disable UIs if the AI is unpowered.
|
||||
return UI_DISABLED
|
||||
return ..()
|
||||
|
||||
/mob/living/silicon/robot/shared_ui_interaction(src_object)
|
||||
/mob/living/silicon/robot/shared_tgui_interaction(src_object)
|
||||
if(!cell || cell.charge <= 0 || lockcharge) // Disable UIs if the Borg is unpowered or locked.
|
||||
return UI_DISABLED
|
||||
return ..()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Check the distance for a living mob.
|
||||
* Really only used for checks outside the context of a mob.
|
||||
* Otherwise, use shared_living_ui_distance().
|
||||
*
|
||||
* required src_object The object which owns the UI.
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
**/
|
||||
/atom/proc/contents_ui_distance(src_object, mob/living/user)
|
||||
return user.shared_living_ui_distance(src_object) // Just call this mob's check.
|
||||
* public
|
||||
*
|
||||
* Check the distance for a living mob.
|
||||
* Really only used for checks outside the context of a mob.
|
||||
* Otherwise, use shared_living_ui_distance().
|
||||
*
|
||||
* required src_object The object which owns the UI.
|
||||
* required user mob The mob who opened/is using the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
*/
|
||||
/atom/proc/contents_tgui_distance(src_object, mob/living/user)
|
||||
return user.shared_living_tgui_distance(src_object) // Just call this mob's check.
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Distance versus interaction check.
|
||||
*
|
||||
* required src_object atom/movable The object which owns the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
**/
|
||||
/mob/living/proc/shared_living_ui_distance(atom/movable/src_object)
|
||||
if(!(src_object in view(src))) // If the object is obscured, close it.
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Distance versus interaction check.
|
||||
*
|
||||
* required src_object atom/movable The object which owns the UI.
|
||||
*
|
||||
* return UI_state The state of the UI.
|
||||
*/
|
||||
/mob/living/proc/shared_living_tgui_distance(atom/movable/src_object, viewcheck = TRUE)
|
||||
if(viewcheck && !(src_object in view(src))) // If the object is obscured, close it.
|
||||
return UI_CLOSE
|
||||
|
||||
var/dist = get_dist(src_object, src)
|
||||
@@ -111,7 +111,7 @@
|
||||
return UI_DISABLED
|
||||
return UI_CLOSE // Otherwise, we got nothing.
|
||||
|
||||
/mob/living/carbon/human/shared_living_ui_distance(atom/movable/src_object)
|
||||
/mob/living/carbon/human/shared_living_tgui_distance(atom/movable/src_object)
|
||||
if(dna.check_mutation(TK) && tkMaxRangeCheck(src, src_object))
|
||||
return UI_INTERACTIVE
|
||||
return ..()
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Checks that the user is an admin, end-of-story.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(admin_state, /datum/ui_state/admin_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_admin_state, /datum/tgui_state/admin_state, new)
|
||||
|
||||
/datum/ui_state/admin_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/admin_state/can_use_topic(src_object, mob/user)
|
||||
if(check_rights_for(user.client, R_ADMIN))
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Always grants the user UI_INTERACTIVE. Period.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(always_state, /datum/ui_state/always_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_always_state, /datum/tgui_state/always_state, new)
|
||||
|
||||
/datum/ui_state/always_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/always_state/can_use_topic(src_object, mob/user)
|
||||
return UI_INTERACTIVE
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Only checks if the user is conscious.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(conscious_state, /datum/ui_state/conscious_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_conscious_state, /datum/tgui_state/conscious_state, new)
|
||||
|
||||
/datum/ui_state/conscious_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/conscious_state/can_use_topic(src_object, mob/user)
|
||||
if(user.stat == CONSCIOUS)
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Checks that the user is inside the src_object.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(contained_state, /datum/ui_state/contained_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_contained_state, /datum/tgui_state/contained_state, new)
|
||||
|
||||
/datum/ui_state/contained_state/can_use_topic(atom/src_object, mob/user)
|
||||
/datum/tgui_state/contained_state/can_use_topic(atom/src_object, mob/user)
|
||||
if(!src_object.contains(user))
|
||||
return UI_CLOSE
|
||||
return user.shared_ui_interaction(src_object)
|
||||
return user.shared_tgui_interaction(src_object)
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Checks that the src_object is in the user's deep (backpack, box, toolbox, etc) inventory.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(deep_inventory_state, /datum/ui_state/deep_inventory_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_deep_inventory_state, /datum/tgui_state/deep_inventory_state, new)
|
||||
|
||||
/datum/ui_state/deep_inventory_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/deep_inventory_state/can_use_topic(src_object, mob/user)
|
||||
if(!user.contains(src_object))
|
||||
return UI_CLOSE
|
||||
return user.shared_ui_interaction(src_object)
|
||||
return user.shared_tgui_interaction(src_object)
|
||||
|
||||
@@ -4,39 +4,39 @@
|
||||
* Checks a number of things -- mostly physical distance for humans and view for robots.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(default_state, /datum/ui_state/default, new)
|
||||
GLOBAL_DATUM_INIT(tgui_default_state, /datum/tgui_state/default, new)
|
||||
|
||||
/datum/ui_state/default/can_use_topic(src_object, mob/user)
|
||||
return user.default_can_use_topic(src_object) // Call the individual mob-overridden procs.
|
||||
/datum/tgui_state/default/can_use_topic(src_object, mob/user)
|
||||
return user.default_can_use_tgui_topic(src_object) // Call the individual mob-overridden procs.
|
||||
|
||||
/mob/proc/default_can_use_topic(src_object)
|
||||
/mob/proc/default_can_use_tgui_topic(src_object)
|
||||
return UI_CLOSE // Don't allow interaction by default.
|
||||
|
||||
/mob/living/default_can_use_topic(src_object)
|
||||
. = shared_ui_interaction(src_object)
|
||||
/mob/living/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE && loc)
|
||||
. = min(., loc.contents_ui_distance(src_object, src)) // Check the distance...
|
||||
. = min(., loc.contents_tgui_distance(src_object, src)) // Check the distance...
|
||||
if(. == UI_INTERACTIVE) // Non-human living mobs can only look, not touch.
|
||||
return UI_UPDATE
|
||||
|
||||
/mob/living/carbon/human/default_can_use_topic(src_object)
|
||||
. = shared_ui_interaction(src_object)
|
||||
/mob/living/carbon/human/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
. = min(., shared_living_ui_distance(src_object)) // Check the distance...
|
||||
. = min(., shared_living_tgui_distance(src_object)) // Check the distance...
|
||||
|
||||
/mob/living/silicon/robot/default_can_use_topic(src_object)
|
||||
. = shared_ui_interaction(src_object)
|
||||
/mob/living/silicon/robot/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. <= UI_DISABLED)
|
||||
return
|
||||
|
||||
// Robots can interact with anything they can see.
|
||||
var/list/clientviewlist = getviewsize(client.view)
|
||||
if(get_dist(src, src_object) <= min(clientviewlist[1],clientviewlist[2]))
|
||||
if((src_object in view(src)) && (get_dist(src, src_object) <= min(clientviewlist[1],clientviewlist[2])))
|
||||
return UI_INTERACTIVE
|
||||
return UI_DISABLED // Otherwise they can keep the UI open.
|
||||
|
||||
/mob/living/silicon/ai/default_can_use_topic(src_object)
|
||||
. = shared_ui_interaction(src_object)
|
||||
/mob/living/silicon/ai/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. < UI_INTERACTIVE)
|
||||
return
|
||||
|
||||
@@ -45,12 +45,12 @@ GLOBAL_DATUM_INIT(default_state, /datum/ui_state/default, new)
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/simple_animal/default_can_use_topic(src_object)
|
||||
. = shared_ui_interaction(src_object)
|
||||
/mob/living/simple_animal/default_can_use_tgui_topic(src_object)
|
||||
. = shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
. = min(., shared_living_ui_distance(src_object)) //simple animals can only use things they're near.
|
||||
. = min(., shared_living_tgui_distance(src_object)) //simple animals can only use things they're near.
|
||||
|
||||
/mob/living/silicon/pai/default_can_use_topic(src_object)
|
||||
/mob/living/silicon/pai/default_can_use_tgui_topic(src_object)
|
||||
// pAIs can only use themselves and the owner's radio.
|
||||
if((src_object == src || src_object == radio) && !stat)
|
||||
return UI_INTERACTIVE
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
* Checks that the src_object is in the user's hands.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(hands_state, /datum/ui_state/hands_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_hands_state, /datum/tgui_state/hands_state, new)
|
||||
|
||||
/datum/ui_state/hands_state/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_ui_interaction(src_object)
|
||||
/datum/tgui_state/hands_state/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
return min(., user.hands_can_use_topic(src_object))
|
||||
return min(., user.hands_can_use_tgui_topic(src_object))
|
||||
|
||||
/mob/proc/hands_can_use_topic(src_object)
|
||||
/mob/proc/hands_can_use_tgui_topic(src_object)
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/hands_can_use_topic(src_object)
|
||||
/mob/living/hands_can_use_tgui_topic(src_object)
|
||||
if(is_holding(src_object))
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/silicon/robot/hands_can_use_topic(src_object)
|
||||
/mob/living/silicon/robot/hands_can_use_tgui_topic(src_object)
|
||||
if(activated(src_object))
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
* human adjacent user.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(human_adjacent_state, /datum/ui_state/human_adjacent_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_human_adjacent_state, /datum/tgui_state/human_adjacent_state, new)
|
||||
|
||||
/datum/ui_state/human_adjacent_state/can_use_topic(src_object, mob/user)
|
||||
. = user.default_can_use_topic(src_object)
|
||||
/datum/tgui_state/human_adjacent_state/can_use_topic(src_object, mob/user)
|
||||
. = user.default_can_use_tgui_topic(src_object)
|
||||
|
||||
var/dist = get_dist(src_object, user)
|
||||
if((dist > 1) || (!ishuman(user)))
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Checks that the src_object is in the user's top-level (hand, ear, pocket, belt, etc) inventory.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(inventory_state, /datum/ui_state/inventory_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_inventory_state, /datum/tgui_state/inventory_state, new)
|
||||
|
||||
/datum/ui_state/inventory_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/inventory_state/can_use_topic(src_object, mob/user)
|
||||
if(!(src_object in user))
|
||||
return UI_CLOSE
|
||||
return user.shared_ui_interaction(src_object)
|
||||
return user.shared_tgui_interaction(src_object)
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* tgui state: language_menu_state
|
||||
*/
|
||||
|
||||
GLOBAL_DATUM_INIT(language_menu_state, /datum/ui_state/language_menu, new)
|
||||
GLOBAL_DATUM_INIT(language_menu_state, /datum/tgui_state/language_menu, new)
|
||||
|
||||
/datum/ui_state/language_menu/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/language_menu/can_use_topic(src_object, mob/user)
|
||||
. = UI_CLOSE
|
||||
if(check_rights_for(user.client, R_ADMIN))
|
||||
. = UI_INTERACTIVE
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Checks that the user isn't incapacitated
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(not_incapacitated_state, /datum/ui_state/not_incapacitated_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_not_incapacitated_state, /datum/tgui_state/not_incapacitated_state, new)
|
||||
|
||||
/**
|
||||
* tgui state: not_incapacitated_turf_state
|
||||
@@ -12,18 +12,18 @@ GLOBAL_DATUM_INIT(not_incapacitated_state, /datum/ui_state/not_incapacitated_sta
|
||||
* Checks that the user isn't incapacitated and that their loc is a turf
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(not_incapacitated_turf_state, /datum/ui_state/not_incapacitated_state, new(no_turfs = TRUE))
|
||||
GLOBAL_DATUM_INIT(tgui_not_incapacitated_turf_state, /datum/tgui_state/not_incapacitated_state, new(no_turfs = TRUE))
|
||||
|
||||
/datum/ui_state/not_incapacitated_state
|
||||
/datum/tgui_state/not_incapacitated_state
|
||||
var/turf_check = FALSE
|
||||
|
||||
/datum/ui_state/not_incapacitated_state/New(loc, no_turfs = FALSE)
|
||||
/datum/tgui_state/not_incapacitated_state/New(loc, no_turfs = FALSE)
|
||||
..()
|
||||
turf_check = no_turfs
|
||||
|
||||
/datum/ui_state/not_incapacitated_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/not_incapacitated_state/can_use_topic(src_object, mob/user)
|
||||
if(user.stat)
|
||||
return UI_CLOSE
|
||||
if(user.incapacitated() || user.lying || (turf_check && !isturf(user.loc)))
|
||||
if(user.incapacitated() || (turf_check && !isturf(user.loc)))
|
||||
return UI_DISABLED
|
||||
return UI_INTERACTIVE
|
||||
return UI_INTERACTIVE
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
* Checks that the user is not inside src_object, and then makes the default checks.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(notcontained_state, /datum/ui_state/notcontained_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_notcontained_state, /datum/tgui_state/notcontained_state, new)
|
||||
|
||||
/datum/ui_state/notcontained_state/can_use_topic(atom/src_object, mob/user)
|
||||
. = user.shared_ui_interaction(src_object)
|
||||
/datum/tgui_state/notcontained_state/can_use_topic(atom/src_object, mob/user)
|
||||
. = user.shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
return min(., user.notcontained_can_use_topic(src_object))
|
||||
return min(., user.notcontained_can_use_tgui_topic(src_object))
|
||||
|
||||
/mob/proc/notcontained_can_use_topic(src_object)
|
||||
/mob/proc/notcontained_can_use_tgui_topic(src_object)
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/notcontained_can_use_topic(atom/src_object)
|
||||
/mob/living/notcontained_can_use_tgui_topic(atom/src_object)
|
||||
if(src_object.contains(src))
|
||||
return UI_CLOSE // Close if we're inside it.
|
||||
return default_can_use_topic(src_object)
|
||||
return default_can_use_tgui_topic(src_object)
|
||||
|
||||
/mob/living/silicon/notcontained_can_use_topic(src_object)
|
||||
return default_can_use_topic(src_object) // Silicons use default bevhavior.
|
||||
/mob/living/silicon/notcontained_can_use_tgui_topic(src_object)
|
||||
return default_can_use_tgui_topic(src_object) // Silicons use default bevhavior.
|
||||
|
||||
/mob/living/simple_animal/drone/notcontained_can_use_topic(src_object)
|
||||
return default_can_use_topic(src_object) // Drones use default bevhavior.
|
||||
/mob/living/simple_animal/drone/notcontained_can_use_tgui_topic(src_object)
|
||||
return default_can_use_tgui_topic(src_object) // Drones use default bevhavior.
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Checks that the user is an observer/ghost.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(observer_state, /datum/ui_state/observer_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_observer_state, /datum/tgui_state/observer_state, new)
|
||||
|
||||
/datum/ui_state/observer_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/observer_state/can_use_topic(src_object, mob/user)
|
||||
if(isobserver(user))
|
||||
return UI_INTERACTIVE
|
||||
return UI_CLOSE
|
||||
|
||||
@@ -2,25 +2,25 @@
|
||||
* tgui state: physical_state
|
||||
*
|
||||
* Short-circuits the default state to only check physical distance.
|
||||
*/
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(physical_state, /datum/ui_state/physical, new)
|
||||
GLOBAL_DATUM_INIT(tgui_physical_state, /datum/tgui_state/physical, new)
|
||||
|
||||
/datum/ui_state/physical/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_ui_interaction(src_object)
|
||||
/datum/tgui_state/physical/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
return min(., user.physical_can_use_topic(src_object))
|
||||
return min(., user.physical_can_use_tgui_topic(src_object))
|
||||
|
||||
/mob/proc/physical_can_use_topic(src_object)
|
||||
/mob/proc/physical_can_use_tgui_topic(src_object)
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/physical_can_use_topic(src_object)
|
||||
return shared_living_ui_distance(src_object)
|
||||
/mob/living/physical_can_use_tgui_topic(src_object)
|
||||
return shared_living_tgui_distance(src_object)
|
||||
|
||||
/mob/living/silicon/physical_can_use_topic(src_object)
|
||||
return max(UI_UPDATE, shared_living_ui_distance(src_object)) // Silicons can always see.
|
||||
/mob/living/silicon/physical_can_use_tgui_topic(src_object)
|
||||
return max(UI_UPDATE, shared_living_tgui_distance(src_object)) // Silicons can always see.
|
||||
|
||||
/mob/living/silicon/ai/physical_can_use_topic(src_object)
|
||||
/mob/living/silicon/ai/physical_can_use_tgui_topic(src_object)
|
||||
return UI_UPDATE // AIs are not physical.
|
||||
|
||||
/**
|
||||
@@ -29,10 +29,10 @@ GLOBAL_DATUM_INIT(physical_state, /datum/ui_state/physical, new)
|
||||
* Short-circuits the default state to only check physical distance, being in view doesn't matter
|
||||
*/
|
||||
|
||||
GLOBAL_DATUM_INIT(physical_obscured_state, /datum/ui_state/physical_obscured_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_physical_obscured_state, /datum/tgui_state/physical_obscured_state, new)
|
||||
|
||||
/datum/ui_state/physical_obscured_state/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_ui_interaction(src_object)
|
||||
/datum/tgui_state/physical_obscured_state/can_use_topic(src_object, mob/user)
|
||||
. = user.shared_tgui_interaction(src_object)
|
||||
if(. > UI_CLOSE)
|
||||
return min(., user.physical_obscured_can_use_topic(src_object))
|
||||
|
||||
@@ -40,10 +40,10 @@ GLOBAL_DATUM_INIT(physical_obscured_state, /datum/ui_state/physical_obscured_sta
|
||||
return UI_CLOSE
|
||||
|
||||
/mob/living/physical_obscured_can_use_topic(src_object)
|
||||
return shared_living_ui_distance(src_object)
|
||||
return shared_living_tgui_distance(src_object)
|
||||
|
||||
/mob/living/silicon/physical_obscured_can_use_topic(src_object)
|
||||
return max(UI_UPDATE, shared_living_ui_distance(src_object)) // Silicons can always see.
|
||||
return max(UI_UPDATE, shared_living_tgui_distance(src_object)) // Silicons can always see.
|
||||
|
||||
/mob/living/silicon/ai/physical_obscured_can_use_topic(src_object)
|
||||
return UI_UPDATE // AIs are not physical.
|
||||
@@ -4,9 +4,9 @@
|
||||
* Only checks that the user and src_object are the same.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(self_state, /datum/ui_state/self_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_self_state, /datum/tgui_state/self_state, new)
|
||||
|
||||
/datum/ui_state/self_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/self_state/can_use_topic(src_object, mob/user)
|
||||
if(src_object != user)
|
||||
return UI_CLOSE
|
||||
return user.shared_ui_interaction(src_object)
|
||||
return user.shared_tgui_interaction(src_object)
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Only checks that the Z-level of the user and src_object are the same.
|
||||
**/
|
||||
|
||||
GLOBAL_DATUM_INIT(z_state, /datum/ui_state/z_state, new)
|
||||
GLOBAL_DATUM_INIT(tgui_z_state, /datum/tgui_state/z_state, new)
|
||||
|
||||
/datum/ui_state/z_state/can_use_topic(src_object, mob/user)
|
||||
/datum/tgui_state/z_state/can_use_topic(src_object, mob/user)
|
||||
var/turf/turf_obj = get_turf(src_object)
|
||||
var/turf/turf_usr = get_turf(user)
|
||||
if(turf_obj && turf_usr && turf_obj.z == turf_usr.z)
|
||||
|
||||
@@ -128,11 +128,11 @@
|
||||
* return int The number of UIs updated.
|
||||
**/
|
||||
/datum/controller/subsystem/tgui/proc/update_user_uis(mob/user, datum/src_object = null, ui_key = null)
|
||||
if(isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0)
|
||||
if(isnull(user.open_tguis) || !istype(user.open_tguis, /list) || open_uis.len == 0)
|
||||
return 0 // Couldn't find any UIs for this user.
|
||||
|
||||
var/update_count = 0
|
||||
for(var/datum/tgui/ui in user.open_uis)
|
||||
for(var/datum/tgui/ui in user.open_tguis)
|
||||
if((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key))
|
||||
ui.process(force = 1) // Update the UI.
|
||||
update_count++ // Count each UI we upadte.
|
||||
@@ -150,11 +150,11 @@
|
||||
* return int The number of UIs closed.
|
||||
**/
|
||||
/datum/controller/subsystem/tgui/proc/close_user_uis(mob/user, datum/src_object = null, ui_key = null)
|
||||
if(isnull(user.open_uis) || !istype(user.open_uis, /list) || open_uis.len == 0)
|
||||
if(isnull(user.open_tguis) || !istype(user.open_tguis, /list) || open_uis.len == 0)
|
||||
return 0 // Couldn't find any UIs for this user.
|
||||
|
||||
var/close_count = 0
|
||||
for(var/datum/tgui/ui in user.open_uis)
|
||||
for(var/datum/tgui/ui in user.open_tguis)
|
||||
if((isnull(src_object) || !isnull(src_object) && ui.src_object == src_object) && (isnull(ui_key) || !isnull(ui_key) && ui.ui_key == ui_key))
|
||||
ui.close() // Close the UI.
|
||||
close_count++ // Count each UI we close.
|
||||
@@ -175,7 +175,7 @@
|
||||
open_uis[src_object_key][ui.ui_key] = list() // Make a list for the ui_key.
|
||||
|
||||
// Append the UI to all the lists.
|
||||
ui.user.open_uis |= ui
|
||||
ui.user.open_tguis |= ui
|
||||
var/list/uis = open_uis[src_object_key][ui.ui_key]
|
||||
uis |= ui
|
||||
processing_uis |= ui
|
||||
@@ -198,7 +198,7 @@
|
||||
|
||||
processing_uis.Remove(ui) // Remove it from the list of processing UIs.
|
||||
if(ui.user) // If the user exists, remove it from them too.
|
||||
ui.user.open_uis.Remove(ui)
|
||||
ui.user.open_tguis.Remove(ui)
|
||||
var/Ukey = ui.ui_key
|
||||
var/list/uis = open_uis[src_object_key][Ukey] // Remove it from the list of open UIs.
|
||||
uis.Remove(ui)
|
||||
@@ -233,15 +233,15 @@
|
||||
* return bool If the UIs were transferred.
|
||||
**/
|
||||
/datum/controller/subsystem/tgui/proc/on_transfer(mob/source, mob/target)
|
||||
if(!source || isnull(source.open_uis) || !istype(source.open_uis, /list) || open_uis.len == 0)
|
||||
if(!source || isnull(source.open_tguis) || !istype(source.open_tguis, /list) || open_uis.len == 0)
|
||||
return 0 // The old mob had no open UIs.
|
||||
|
||||
if(isnull(target.open_uis) || !istype(target.open_uis, /list))
|
||||
target.open_uis = list() // Create a list for the new mob if needed.
|
||||
if(isnull(target.open_tguis) || !istype(target.open_tguis, /list))
|
||||
target.open_tguis = list() // Create a list for the new mob if needed.
|
||||
|
||||
for(var/datum/tgui/ui in source.open_uis)
|
||||
for(var/datum/tgui/ui in source.open_tguis)
|
||||
ui.user = target // Inform the UIs of their new owner.
|
||||
target.open_uis.Add(ui) // Transfer all the UIs.
|
||||
target.open_tguis.Add(ui) // Transfer all the UIs.
|
||||
|
||||
source.open_uis.Cut() // Clear the old list.
|
||||
source.open_tguis.Cut() // Clear the old list.
|
||||
return 1 // Let the caller know we did it.
|
||||
|
||||
+205
-182
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* tgui
|
||||
*
|
||||
* /tg/station user interface library
|
||||
**/
|
||||
/**
|
||||
* tgui
|
||||
*
|
||||
* /tg/station user interface library
|
||||
*/
|
||||
|
||||
/**
|
||||
* tgui datum (represents a UI).
|
||||
**/
|
||||
/**
|
||||
* tgui datum (represents a UI).
|
||||
*/
|
||||
/datum/tgui
|
||||
/// The mob who opened/is using the UI.
|
||||
var/mob/user
|
||||
@@ -22,8 +22,10 @@
|
||||
var/width = 0
|
||||
/// The window height
|
||||
var/height = 0
|
||||
/// The style to be used for this UI.
|
||||
var/style = "nanotrasen"
|
||||
|
||||
// /// The style to be used for this UI.
|
||||
// var/style = "nanotrasen"
|
||||
|
||||
/// The interface (template) to be used for this UI.
|
||||
var/interface
|
||||
/// Update the UI every MC tick.
|
||||
@@ -34,42 +36,40 @@
|
||||
var/list/initial_data
|
||||
/// The static data used to initialize the UI.
|
||||
var/list/initial_static_data
|
||||
/// Holder for the json string, that is sent during the initial update
|
||||
var/_initial_update
|
||||
/// The status/visibility of the UI.
|
||||
var/status = UI_INTERACTIVE
|
||||
/// Topic state used to determine status/interactability.
|
||||
var/datum/ui_state/state = null
|
||||
var/datum/tgui_state/state = null
|
||||
/// The parent UI.
|
||||
var/datum/tgui/master_ui
|
||||
/// Children of this UI.
|
||||
var/list/datum/tgui/children = list()
|
||||
var/custom_browser_id = FALSE
|
||||
var/ui_screen = "home"
|
||||
|
||||
/**
|
||||
* 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 ui_key string The ui_key of the UI.
|
||||
* required interface string The interface used to render the UI.
|
||||
* optional title string The title of the UI.
|
||||
* optional width int The window width.
|
||||
* optional height int The window height.
|
||||
* optional master_ui datum/tgui The parent UI.
|
||||
* optional state datum/ui_state The state used to determine status.
|
||||
*
|
||||
* return datum/tgui The requested UI.
|
||||
**/
|
||||
/datum/tgui/New(mob/user, datum/src_object, ui_key, interface, title, width = 0, height = 0, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state, browser_id = null)
|
||||
/**
|
||||
* 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 ui_key string The ui_key of the UI.
|
||||
* required interface string The interface used to render the UI.
|
||||
* optional title string The title of the UI.
|
||||
* optional width int The window width.
|
||||
* optional height int The window height.
|
||||
* optional master_ui datum/tgui The parent UI.
|
||||
* optional state datum/tgui_state The state used to determine status.
|
||||
*
|
||||
* return datum/tgui The requested UI.
|
||||
*/
|
||||
/datum/tgui/New(mob/user, datum/src_object, ui_key, interface, title, width = 0, height = 0, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_default_state)
|
||||
src.user = user
|
||||
src.src_object = src_object
|
||||
src.ui_key = ui_key
|
||||
src.window_id = browser_id ? browser_id : "[REF(src_object)]-[ui_key]" // DO NOT replace with \ref here. src_object could potentially be tagged
|
||||
src.custom_browser_id = browser_id ? TRUE : FALSE
|
||||
|
||||
set_interface(interface)
|
||||
src.window_id = "[src_object.UID()]-[ui_key]"
|
||||
src.interface = interface
|
||||
|
||||
if(title)
|
||||
src.title = sanitize(title)
|
||||
@@ -83,14 +83,16 @@
|
||||
master_ui.children += src
|
||||
src.state = state
|
||||
|
||||
var/datum/asset/assets = get_asset_datum(/datum/asset/group/tgui)
|
||||
assets.send(user)
|
||||
var/datum/asset/tgui_assets = get_asset_datum(/datum/asset/simple/tgui)
|
||||
var/datum/asset/fa = get_asset_datum(/datum/asset/simple/fontawesome)
|
||||
tgui_assets.send(user)
|
||||
fa.send(user)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Open this UI (and initialize it with data).
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Open this UI (and initialize it with data).
|
||||
*/
|
||||
/datum/tgui/proc/open()
|
||||
if(!user.client)
|
||||
return // Bail if there is no client.
|
||||
@@ -99,18 +101,19 @@
|
||||
if(status < UI_UPDATE)
|
||||
return // Bail if we're not supposed to open.
|
||||
|
||||
var/window_size
|
||||
if(width && height) // If we have a width and height, use them.
|
||||
window_size = "size=[width]x[height];"
|
||||
else
|
||||
window_size = ""
|
||||
|
||||
|
||||
// Build window options
|
||||
var/window_options = "can_minimize=0;auto_format=0;"
|
||||
// If we have a width and height, use them.
|
||||
if(width && height)
|
||||
window_options += "size=[width]x[height];"
|
||||
|
||||
// Remove titlebar and resize handles for a fancy window
|
||||
var/have_title_bar
|
||||
if(user.client.prefs.tgui_fancy)
|
||||
have_title_bar = "titlebar=0;can_resize=0;"
|
||||
window_options += "titlebar=0;can_resize=0;"
|
||||
else
|
||||
have_title_bar = "titlebar=1;can_resize=1;"
|
||||
window_options += "titlebar=1;can_resize=1;"
|
||||
|
||||
// Generate page html
|
||||
var/html
|
||||
@@ -118,52 +121,52 @@
|
||||
// Allow the src object to override the html if needed
|
||||
html = src_object.ui_base_html(html)
|
||||
// Replace template tokens with important UI data
|
||||
// NOTE: Intentional \ref usage; tgui datums can't/shouldn't
|
||||
// be tagged, so this is an effective unwrap
|
||||
html = replacetextEx(html, "\[ref]", "\ref[src]")
|
||||
html = replacetextEx(html, "\[style]", style)
|
||||
html = replacetextEx(html, "\[tgui:ref]", "[src.UID()]")
|
||||
|
||||
// Open the window.
|
||||
user << browse(html, "window=[window_id];can_minimize=0;auto_format=0;[window_size][have_title_bar]")
|
||||
if (!custom_browser_id)
|
||||
// Instruct the client to signal UI when the window is closed.
|
||||
// NOTE: Intentional \ref usage; tgui datums can't/shouldn't
|
||||
// be tagged, so this is an effective unwrap
|
||||
winset(user, window_id, "on-close=\"uiclose \ref[src]\"")
|
||||
user << browse(html, "window=[window_id];[window_options]")
|
||||
|
||||
// Instruct the client to signal UI when the window is closed.
|
||||
// NOTE: Intentional \ref usage; tgui datums can't/shouldn't
|
||||
// be tagged, so this is an effective unwrap
|
||||
winset(user, window_id, "on-close=\"uiclose [UID()]\"")
|
||||
|
||||
// Pre-fetch initial state while browser is still loading in
|
||||
// another thread
|
||||
if(!initial_data)
|
||||
initial_data = src_object.ui_data(user)
|
||||
if(!initial_static_data)
|
||||
initial_static_data = src_object.ui_static_data(user)
|
||||
_initial_update = url_encode(get_json(initial_data, initial_static_data))
|
||||
|
||||
SStgui.on_open(src)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Reinitialize the UI.
|
||||
* (Possibly with a new interface and/or data).
|
||||
*
|
||||
* optional template string The name of the new interface.
|
||||
* optional data list The new initial data.
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Reinitialize the UI.
|
||||
* (Possibly with a new interface and/or data).
|
||||
*
|
||||
* optional template string The name of the new interface.
|
||||
* optional data list The new initial data.
|
||||
*/
|
||||
/datum/tgui/proc/reinitialize(interface, list/data, list/static_data)
|
||||
if(interface)
|
||||
set_interface(interface) // Set a new interface.
|
||||
src.interface = interface
|
||||
if(data)
|
||||
initial_data = data
|
||||
if(static_data)
|
||||
initial_static_data = static_data
|
||||
open()
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Close the UI, and all its children.
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Close the UI, and all its children.
|
||||
*/
|
||||
/datum/tgui/proc/close()
|
||||
user << browse(null, "window=[window_id]") // Close the window.
|
||||
src_object.ui_close()
|
||||
src_object.ui_close(user)
|
||||
SStgui.on_close(src)
|
||||
for(var/datum/tgui/child in children) // Loop through and close all children.
|
||||
child.close()
|
||||
@@ -172,67 +175,68 @@
|
||||
master_ui = null
|
||||
qdel(src)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Set the style for this UI.
|
||||
*
|
||||
* required style string The new UI style.
|
||||
**/
|
||||
/datum/tgui/proc/set_style(style)
|
||||
src.style = lowertext(style)
|
||||
// /**
|
||||
// * public
|
||||
// *
|
||||
// * Set the style for this UI.
|
||||
// *
|
||||
// * required style string The new UI style.
|
||||
// **/
|
||||
// /datum/tgui/proc/set_style(style)
|
||||
// src.style = lowertext(style)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Set the interface (template) for this UI.
|
||||
*
|
||||
* required interface string The new UI interface.
|
||||
**/
|
||||
/datum/tgui/proc/set_interface(interface)
|
||||
src.interface = lowertext(interface)
|
||||
// /**
|
||||
// * public
|
||||
// *
|
||||
// * Set the interface (template) for this UI.
|
||||
// *
|
||||
// * required interface string The new UI interface.
|
||||
// **/
|
||||
// /datum/tgui/proc/set_interface(interface)
|
||||
// src.interface = lowertext(interface)
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Enable/disable auto-updating of the UI.
|
||||
*
|
||||
* required state bool Enable/disable auto-updating.
|
||||
**/
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Enable/disable auto-updating of the UI.
|
||||
*
|
||||
* required state bool Enable/disable auto-updating.
|
||||
*/
|
||||
/datum/tgui/proc/set_autoupdate(state = TRUE)
|
||||
autoupdate = state
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Package the data to send to the UI, as JSON.
|
||||
* This includes the UI data and config_data.
|
||||
*
|
||||
* return string The packaged JSON.
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Package the data to send to the UI, as JSON.
|
||||
* This includes the UI data and config_data.
|
||||
*
|
||||
* return string The packaged JSON.
|
||||
*/
|
||||
/datum/tgui/proc/get_json(list/data, list/static_data)
|
||||
var/list/json_data = list()
|
||||
|
||||
json_data["config"] = list(
|
||||
"title" = title,
|
||||
"status" = status,
|
||||
"screen" = ui_screen,
|
||||
"style" = style,
|
||||
// "style" = style,
|
||||
"interface" = interface,
|
||||
"fancy" = user.client.prefs.tgui_fancy,
|
||||
"locked" = user.client.prefs.tgui_lock && !custom_browser_id,
|
||||
"observer" = isobserver(user),
|
||||
"window" = window_id,
|
||||
// NOTE: Intentional \ref usage; tgui datums can't/shouldn't
|
||||
// be tagged, so this is an effective unwrap
|
||||
"ref" = "\ref[src]"
|
||||
// "map" = (GLOB.using_map && GLOB.using_map.name) ? GLOB.using_map.name : "Unknown",
|
||||
"ref" = "[src.UID()]"
|
||||
)
|
||||
|
||||
|
||||
if(!isnull(data))
|
||||
json_data["data"] = data
|
||||
if(!isnull(static_data))
|
||||
json_data["static_data"] = static_data
|
||||
|
||||
// Send shared states
|
||||
if(src_object.tgui_shared_states)
|
||||
json_data["shared"] = src_object.tgui_shared_states
|
||||
|
||||
// Generate the JSON.
|
||||
var/json = json_encode(json_data)
|
||||
// Strip #255/improper.
|
||||
@@ -240,13 +244,13 @@
|
||||
json = replacetext(json, "\improper", "")
|
||||
return json
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Handle clicks from the UI.
|
||||
* Call the src_object's ui_act() if status is UI_INTERACTIVE.
|
||||
* If the src_object's ui_act() returns 1, update all UIs attacked to it.
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Handle clicks from the UI.
|
||||
* Call the src_object's ui_act() if status is UI_INTERACTIVE.
|
||||
* If the src_object's ui_act() returns 1, update all UIs attacked to it.
|
||||
*/
|
||||
/datum/tgui/Topic(href, href_list)
|
||||
if(user != usr)
|
||||
return // Something is not right here.
|
||||
@@ -256,35 +260,48 @@
|
||||
|
||||
switch(action)
|
||||
if("tgui:initialize")
|
||||
user << output(url_encode(get_json(initial_data, initial_static_data)), "[custom_browser_id ? window_id : "[window_id].browser"]:initialize")
|
||||
user << output(_initial_update, "[window_id].browser:update")
|
||||
initialized = TRUE
|
||||
if("tgui:view")
|
||||
if(params["screen"])
|
||||
ui_screen = params["screen"]
|
||||
if("tgui:setSharedState")
|
||||
// Update the window state.
|
||||
update_status(push = FALSE)
|
||||
// Bail if UI is not interactive or usr calling Topic
|
||||
// is not the UI user.
|
||||
if(status != UI_INTERACTIVE)
|
||||
return
|
||||
var/key = params["key"]
|
||||
var/value = params["value"]
|
||||
if(!src_object.tgui_shared_states)
|
||||
src_object.tgui_shared_states = list()
|
||||
src_object.tgui_shared_states[key] = value
|
||||
SStgui.update_uis(src_object)
|
||||
if("tgui:setFancy")
|
||||
var/value = text2num(params["value"])
|
||||
user.client.prefs.tgui_fancy = value
|
||||
if("tgui:log")
|
||||
// Force window to show frills on fatal errors
|
||||
if(params["fatal"])
|
||||
winset(user, window_id, "titlebar=1;can-resize=1;size=600x600")
|
||||
log_message(params["log"])
|
||||
if("tgui:link")
|
||||
user << link(params["url"])
|
||||
if("tgui:fancy")
|
||||
user.client.prefs.tgui_fancy = TRUE
|
||||
if("tgui:nofrills")
|
||||
user.client.prefs.tgui_fancy = FALSE
|
||||
else
|
||||
update_status(push = FALSE) // Update the window state.
|
||||
if(src_object.ui_act(action, params, src, state)) // Call ui_act() on the src_object.
|
||||
SStgui.update_uis(src_object) // Update if the object requested it.
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Update the UI.
|
||||
* Only updates the data if update is true, otherwise only updates the status.
|
||||
*
|
||||
* optional force bool If the UI should be forced to update.
|
||||
**/
|
||||
else
|
||||
// Update the window state.
|
||||
update_status(push = FALSE)
|
||||
// Call ui_act() on the src_object.
|
||||
if(src_object.ui_act(action, params, src, state))
|
||||
// Update if the object requested it.
|
||||
SStgui.update_uis(src_object)
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Update the UI.
|
||||
* Only updates the data if update is true, otherwise only updates the status.
|
||||
*
|
||||
* optional force bool If the UI should be forced to update.
|
||||
*/
|
||||
/datum/tgui/process(force = FALSE)
|
||||
var/datum/host = src_object.ui_host(user)
|
||||
if(!src_object || !host || !user) // If the object or user died (or something else), abort.
|
||||
@@ -296,69 +313,75 @@
|
||||
else
|
||||
update_status(push = TRUE) // Otherwise only update status.
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Push data to an already open UI.
|
||||
*
|
||||
* required data list The data to send.
|
||||
* optional force bool If the update should be sent regardless of state.
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Push data to an already open UI.
|
||||
*
|
||||
* required data list The data to send.
|
||||
* optional force bool If the update should be sent regardless of state.
|
||||
*/
|
||||
/datum/tgui/proc/push_data(data, static_data, force = FALSE)
|
||||
update_status(push = FALSE) // Update the window state.
|
||||
// Update the window state.
|
||||
update_status(push = FALSE)
|
||||
// Cannot update UI if it is not set up yet.
|
||||
if(!initialized)
|
||||
return // Cannot update UI if it is not set up yet.
|
||||
return
|
||||
// Cannot update UI, we have no visibility.
|
||||
if(status <= UI_DISABLED && !force)
|
||||
return // Cannot update UI, we have no visibility.
|
||||
|
||||
return
|
||||
// Send the new JSON to the update() Javascript function.
|
||||
user << output(url_encode(get_json(data, static_data)), "[custom_browser_id ? window_id : "[window_id].browser"]:update")
|
||||
user << output(
|
||||
url_encode(get_json(data, static_data)),
|
||||
"[window_id].browser:update")
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Updates the UI by interacting with the src_object again, which will hopefully
|
||||
* call try_ui_update on it.
|
||||
*
|
||||
* optional force_open bool If force_open should be passed to ui_interact.
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Updates the UI by interacting with the src_object again, which will hopefully
|
||||
* call try_ui_update on it.
|
||||
*
|
||||
* optional force_open bool If force_open should be passed to ui_interact.
|
||||
*/
|
||||
/datum/tgui/proc/update(force_open = FALSE)
|
||||
src_object.ui_interact(user, ui_key, src, force_open, master_ui, state)
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Update the status/visibility of the UI for its user.
|
||||
*
|
||||
* optional push bool Push an update to the UI (an update is always sent for UI_DISABLED).
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Update the status/visibility of the UI for its user.
|
||||
*
|
||||
* optional push bool Push an update to the UI (an update is always sent for UI_DISABLED).
|
||||
*/
|
||||
/datum/tgui/proc/update_status(push = FALSE)
|
||||
var/status = src_object.ui_status(user, state)
|
||||
if(master_ui)
|
||||
status = min(status, master_ui.status)
|
||||
|
||||
set_status(status, push)
|
||||
if(status == UI_CLOSE)
|
||||
close()
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Set the status/visibility of the UI.
|
||||
*
|
||||
* required status int The status to set (UI_CLOSE/UI_DISABLED/UI_UPDATE/UI_INTERACTIVE).
|
||||
* optional push bool Push an update to the UI (an update is always sent for UI_DISABLED).
|
||||
**/
|
||||
/**
|
||||
* private
|
||||
*
|
||||
* Set the status/visibility of the UI.
|
||||
*
|
||||
* required status int The status to set (UI_CLOSE/UI_DISABLED/UI_UPDATE/UI_INTERACTIVE).
|
||||
* optional push bool Push an update to the UI (an update is always sent for UI_DISABLED).
|
||||
*/
|
||||
/datum/tgui/proc/set_status(status, push = FALSE)
|
||||
if(src.status != status) // Only update if status has changed.
|
||||
// Only update if status has changed.
|
||||
if(src.status != status)
|
||||
if(src.status == UI_DISABLED)
|
||||
src.status = status
|
||||
if(push)
|
||||
update()
|
||||
else
|
||||
src.status = status
|
||||
if(status == UI_DISABLED || push) // Update if the UI just because disabled, or a push is requested.
|
||||
// Update if the UI just because disabled, or a push is requested.
|
||||
if(status == UI_DISABLED || push)
|
||||
push_data(null, force = TRUE)
|
||||
|
||||
/datum/tgui/proc/log_message(message)
|
||||
log_tgui("[user] ([user.ckey]) using \"[title]\":\n[message]")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user