Update Cryo, NanoUI states, add new contains() helper

This commit is contained in:
Bjorn Neergaard
2015-11-27 21:21:48 -05:00
parent 5f108eef4e
commit 2feedfa009
19 changed files with 346 additions and 210 deletions
+10 -5
View File
@@ -1,7 +1,12 @@
/*
This state checks that the user is an admin, end of story
*/
/**
* NanoUI State: admin_state
*
* Checks that the user is an admin, end-of-story.
**/
/var/global/datum/topic_state/admin_state/admin_state = new()
/datum/topic_state/admin_state/can_use_topic(var/src_object, var/mob/user)
return check_rights(R_ADMIN, 0, user) ? NANO_INTERACTIVE : NANO_CLOSE
/datum/topic_state/admin_state/can_use_topic(atom/movable/src_object, mob/user)
if (check_rights(R_ADMIN, 0, user))
return NANO_INTERACTIVE
return NANO_CLOSE
+70 -15
View File
@@ -1,14 +1,47 @@
/atom/proc/CanUseTopic(var/mob/user, var/datum/topic_state/state)
/**
* NanoUI State
*
* Base state and helpers for states. Just does some sanity checks, implement a state for in-depth checks.
**/
/**
* public
*
* Checks if a user can use src_object's NanoUI, under the given state.
*
* required user mob The mob who opened/is using the NanoUI.
* required state datum/topic_state The state to check.
*
* return NANO_state The state of the UI.
**/
/atom/proc/CanUseTopic(mob/user, datum/topic_state/state)
var/src_object = nano_host()
return state.can_use_topic(src_object, user) // Check if the state allows interaction.
/datum/topic_state/proc/can_use_topic(var/src_object, var/mob/user)
/**
* private
*
* Checks if a user can use src_object's NanoUI, and returns the state.
* Can call a mob proc, which allows overrides for each mob.
*
* required src_object atom/movable The object which owns the NanoUI.
* required user mob The mob who opened/is using the NanoUI.
*
* return NANO_state The state of the UI.
**/
/datum/topic_state/proc/can_use_topic(atom/movable/src_object, mob/user)
return NANO_CLOSE // Don't allow interaction by default.
/**
* public
*
* Standard interaction/sanity checks. Different mob types may have overrides.
*
* return NANO_state The state of the UI.
**/
/mob/proc/shared_nano_interaction()
if (!client || src.stat) // Close NanoUIs if mindless or dead/unconcious.
if (!client || stat) // Close NanoUIs if mindless or dead/unconcious.
return NANO_CLOSE
else if (restrained() || lying || stat || stunned || weakened) // Update NanoUIs if incapicitated but concious.
return NANO_UPDATE
@@ -26,18 +59,40 @@
return NANO_DISABLED
return ..()
/atom/proc/contents_nano_distance(var/src_object, var/mob/living/user)
return user.shared_living_nano_distance(src_object)
/mob/living/proc/shared_living_nano_distance(var/atom/movable/src_object)
if (!(src_object in view(4, src))) // If the src object is not in visable, disable updates
/**
* public
*
* Check the distance for a living mob.
* Really only used for checks outside the context of a mob.
* Otherwise, use shared_living_nano_distance().
*
* required src_object atom/movable The object which owns the NanoUI.
* required user mob The mob who opened/is using the NanoUI.
*
* return NANO_state The state of the UI.
**/
/atom/proc/contents_nano_distance(atom/movable/src_object, mob/living/user)
return user.shared_living_nano_distance(src_object) // Just call this mob's check.
/**
* public
*
* Distance versus interaction check.
*
* required src_object atom/movable The object which owns the NanoUI.
*
* return NANO_state The state of the UI.
**/
/mob/living/proc/shared_living_nano_distance(atom/movable/src_object)
if (!(src_object in view(4, src))) // If the object is out of view, close it.
return NANO_CLOSE
var/dist = get_dist(src_object, src)
if (dist <= 1)
return NANO_INTERACTIVE // interactive (green visibility)
else if (dist <= 2)
return NANO_UPDATE // update only (orange visibility)
else if (dist <= 4)
return NANO_DISABLED // no updates, completely disabled (red visibility)
return NANO_CLOSE
if (dist <= 1) // Open and interact if 1-0 tiles away.
return NANO_INTERACTIVE
else if (dist <= 2) // Open and view if 2-3 tiles away.
return NANO_UPDATE
else if (dist <= 4) // Open if 4 tiles away.
return NANO_DISABLED
return NANO_CLOSE // Otherwise, we got nothing.
+10 -5
View File
@@ -1,7 +1,12 @@
/*
This state only checks if user is conscious.
*/
/**
* NanoUI State: conscious_state
*
* Only checks if the user is conscious.
**/
/var/global/datum/topic_state/conscious_state/conscious_state = new()
/datum/topic_state/conscious_state/can_use_topic(var/src_object, var/mob/user)
return user.stat == CONSCIOUS ? NANO_INTERACTIVE : NANO_CLOSE
/datum/topic_state/conscious_state/can_use_topic(atom/movable/src_object, mob/user)
if (user.stat == CONSCIOUS)
return NANO_INTERACTIVE
return NANO_CLOSE
+8 -14
View File
@@ -1,18 +1,12 @@
/*
This state checks if user is somewhere within src_object, as well as the default NanoUI interaction.
*/
/**
* NanoUI State: contained_state
*
* Checks that the user is an admin, end-of-story.
**/
/var/global/datum/topic_state/contained_state/contained_state = new()
/datum/topic_state/contained_state/can_use_topic(var/atom/src_object, var/mob/user)
/datum/topic_state/contained_state/can_use_topic(atom/movable/src_object, mob/user)
if(!src_object.contains(user))
return NANO_CLOSE
return user.shared_nano_interaction()
/atom/proc/contains(var/atom/location)
if(!location)
return 0
if(location == src)
return 1
return contains(location.loc)
return user.shared_nano_interaction(src_object)
@@ -0,0 +1,12 @@
/**
* NanoUI State: deep_inventory_state
*
* Checks that the src_object is in the user's fist-level (backpack, webbing, etc) inventory.
**/
/var/global/datum/topic_state/deep_inventory_state/deep_inventory_state = new()
/datum/topic_state/deep_inventory_state/can_use_topic(atom/movable/src_object, mob/user)
if(!user.contains(src_object))
return NANO_CLOSE
return user.shared_nano_interaction()
+38 -46
View File
@@ -1,69 +1,61 @@
/**
* NanoUI State: default_state
*
* Checks a number of things -- mostly phyiscal distance for humans and view for robots.
**/
/var/global/datum/topic_state/default/default_state = new()
/datum/topic_state/default/can_use_topic(atom/movable/src_object, mob/user)
return user.default_can_use_topic(src_object) // Call the individual mob-overriden procs.
/datum/topic_state/default/can_use_topic(var/src_object, var/mob/user)
return user.default_can_use_topic(src_object)
/mob/proc/default_can_use_topic(atom/movable/src_object)
return NANO_CLOSE // Don't allow interaction by default.
/mob/proc/default_can_use_topic(var/src_object)
return NANO_CLOSE // By default no mob can do anything with NanoUI
/mob/dead/observer/default_can_use_topic()
/mob/dead/observer/default_can_use_topic(atom/movable/src_object)
if(check_rights(R_ADMIN, 0, src))
return NANO_INTERACTIVE // Admins are more equal
return NANO_UPDATE // Ghosts can view updates
return NANO_INTERACTIVE // Admins can interact anyway.
return NANO_UPDATE // Ghosts can only view.
/mob/living/silicon/robot/default_can_use_topic(var/src_object)
/mob/living/default_can_use_topic(atom/movable/src_object)
. = shared_nano_interaction(src_object)
if(. > NANO_CLOSE)
if(loc) // Check if the loc exists.
. = min(., loc.contents_nano_distance(src_object, src)) // Check the distance...
if(. == NANO_INTERACTIVE) // Non-human living mobs can only look, not touch.
return NANO_UPDATE
/mob/living/carbon/human/default_can_use_topic(atom/movable/src_object)
. = shared_nano_interaction(src_object)
if(. > NANO_CLOSE)
. = min(., shared_living_nano_distance(src_object)) // Check the distance...
// If we have telekinesis and remain close enough, allow interaction.
if(. == NANO_UPDATE && dna.check_mutation(TK))
return NANO_INTERACTIVE
/mob/living/silicon/robot/default_can_use_topic(atom/movable/src_object)
. = shared_nano_interaction()
if(. <= NANO_DISABLED)
return
// robots can interact with things they can see within their view range
// Robots can interact with anything they can see.
if((src_object in view(src)) && get_dist(src_object, src) <= src.client.view)
return NANO_INTERACTIVE // interactive (green visibility)
return NANO_DISABLED // no updates, completely disabled (red visibility)
/mob/living/silicon/robot/syndicate/default_can_use_topic(var/src_object)
. = ..()
if(. != NANO_INTERACTIVE)
return
if(istype(get_area(src), /area/syndicate_mothership) || istype(get_area(src), /area/shuttle/syndicate)) // If elsewhere, they can interact with everything on the syndicate shuttle
return NANO_INTERACTIVE
if(istype(src_object, /obj/machinery)) // Otherwise they can only interact with emagged machinery
var/obj/machinery/Machine = src_object
if(Machine.emagged)
return NANO_INTERACTIVE
return NANO_UPDATE
return NANO_DISABLED // Otherwise they can keep the UI open.
/mob/living/silicon/ai/default_can_use_topic(var/src_object)
/mob/living/silicon/ai/default_can_use_topic(atom/movable/src_object)
. = shared_nano_interaction()
if (. != NANO_INTERACTIVE)
if (. < NANO_INTERACTIVE)
return
// If an object is in view of the client and a camera then we can interact with it
if ((src_object in view(eyeobj)) && cameranet.checkTurfVis(get_turf(src_object)))
// The AI can interact with anything it can see nearby, or with cameras.
if ((src_object in view(src)) || ((src_object in view(eyeobj)) && cameranet.checkTurfVis(get_turf(src_object))))
return NANO_INTERACTIVE
return NANO_CLOSE
/mob/living/silicon/pai/default_can_use_topic(var/src_object)
/mob/living/silicon/pai/default_can_use_topic(atom/movable/src_object)
// pAIs can only use themselves and the owner's radio.
if((src_object == src || src_object == radio) && !stat)
return NANO_INTERACTIVE
else
return ..()
/mob/living/default_can_use_topic(var/src_object)
. = shared_nano_interaction(src_object)
if(. != NANO_CLOSE)
if(loc)
. = min(., loc.contents_nano_distance(src_object, src))
if(NANO_INTERACTIVE)
return NANO_UPDATE
/mob/living/carbon/human/default_can_use_topic(var/src_object)
. = shared_nano_interaction(src_object)
if(. != NANO_CLOSE)
. = min(., shared_living_nano_distance(src_object))
if(. == NANO_UPDATE && dna.check_mutation(TK)) // If we have telekinesis and remain close enough, allow interaction.
return NANO_INTERACTIVE
+7 -6
View File
@@ -1,11 +1,12 @@
/*
This state checks that the src_object is somewhere in the user's first-level inventory (in hands, on ear, etc.), but not further down (such as in bags).
*/
/**
* NanoUI State: inventory_state
*
* Checks that the src_object is in the user's top-level (hand, ear, pocket, belt, etc) inventory.
**/
/var/global/datum/topic_state/inventory_state/inventory_state = new()
/datum/topic_state/inventory_state/can_use_topic(var/src_object, var/mob/user)
/datum/topic_state/inventory_state/can_use_topic(atom/movable/src_object, mob/user)
if(!(src_object in user))
return NANO_CLOSE
return user.shared_nano_interaction()
@@ -1,10 +0,0 @@
/*
This state checks if src_object is contained anywhere in the user's inventory, including bags, etc.
*/
/var/global/datum/topic_state/deep_inventory_state/deep_inventory_state = new()
/datum/topic_state/deep_inventory_state/can_use_topic(var/src_object, var/mob/user)
if(!user.contains(src_object))
return NANO_CLOSE
return user.shared_nano_interaction()
@@ -0,0 +1,20 @@
/**
* NanoUI State: notcontained_state
*
* Checks that the user is not inside src_object, and then makes the default distance checks.
**/
/var/global/datum/topic_state/notcontained_state/notcontained_state = new()
/datum/topic_state/notcontained_state/can_use_topic(atom/movable/src_object, mob/user)
. = user.shared_nano_interaction(src_object)
if(. > NANO_CLOSE)
return min(., user.notcontained_can_use_topic(src_object))
/mob/proc/notcontained_can_use_topic(atom/movable/src_object)
return NANO_CLOSE
/mob/living/notcontained_can_use_topic(atom/movable/src_object)
if(src_object.contains(src))
return NANO_CLOSE
return shared_living_nano_distance(src_object)
+13 -6
View File
@@ -1,18 +1,25 @@
/**
* NanoUI State: physical_state
*
* Short-circuits the default state to only check physical distance.
**/
/var/global/datum/topic_state/physical/physical_state = new()
/datum/topic_state/physical/can_use_topic(var/src_object, var/mob/user)
/datum/topic_state/physical/can_use_topic(atom/movable/src_object, mob/user)
. = user.shared_nano_interaction(src_object)
if(. > NANO_CLOSE)
return min(., user.check_physical_distance(src_object))
return min(., user.physical_can_use_topic(src_object))
/mob/proc/check_physical_distance(var/src_object)
/mob/proc/physical_can_use_topic(atom/movable/src_object)
return NANO_CLOSE
/mob/dead/observer/check_physical_distance(var/src_object)
/mob/dead/observer/physical_can_use_topic(atom/movable/src_object)
return default_can_use_topic(src_object)
/mob/living/check_physical_distance(var/src_object)
/mob/living/physical_can_use_topic(atom/movable/src_object)
return shared_living_nano_distance(src_object)
/mob/living/silicon/check_physical_distance(var/src_object)
/mob/living/silicon/physical_can_use_topic(atom/movable/src_object)
// Silicons can always see.
return max(NANO_UPDATE, shared_living_nano_distance(src_object))
+7 -4
View File
@@ -1,9 +1,12 @@
/*
This state checks that the src_object is the same the as user
*/
/**
* NanoUI State: self_state
*
* Only checks that the user and src_object are the same.
**/
/var/global/datum/topic_state/self_state/self_state = new()
/datum/topic_state/self_state/can_use_topic(var/src_object, var/mob/user)
/datum/topic_state/self_state/can_use_topic(atom/movable/src_object, mob/user)
if(src_object != user)
return NANO_CLOSE
return user.shared_nano_interaction()
+8 -7
View File
@@ -1,13 +1,14 @@
/*
This state checks that the user is on the same Z-level as src_object
*/
/**
* NanoUI State: z_state
*
* Only checks that the Z-level of the user and src_object are the same.
**/
/var/global/datum/topic_state/z_state/z_state = new()
/datum/topic_state/z_state/can_use_topic(var/src_object, var/mob/user)
/datum/topic_state/z_state/can_use_topic(atom/movable/src_object, mob/user)
var/turf/turf_obj = get_turf(src_object)
var/turf/turf_usr = get_turf(user)
if(!turf_obj || !turf_usr)
if(!turf_obj || !turf_usr || !(turf_obj.z == turf_usr.z))
return NANO_CLOSE
return turf_obj.z == turf_usr.z ? NANO_INTERACTIVE : NANO_CLOSE
return NANO_INTERACTIVE
+4 -3
View File
@@ -407,12 +407,13 @@
if (width && height) // If we have a width and height, use them.
window_size = "size=[width]x[height];"
update_status(push_update = 0) // Update the window state.
if(status == NANO_CLOSE) return // Bail if we should close.
if (status == NANO_CLOSE)
return // Bail if we should close.
user << browse(get_html(), "window=[window_id];[window_size][window_options]") // Open the window.
winset(user, "mapwindow.map", "focus=true") // Return keyboard focus to map.
winset(user, window_id, "on-close=\"nanoclose \ref[src]\"") // Instruct the client to signal NanoUI when the window is closed.
SSnano.ui_opened(src) // Call the ui_opened handler.
SSnano.ui_opened(src) // Call the opened handler.
/**
* public
@@ -423,7 +424,7 @@
* optional template string The filename of the new template.
* optional data list The new initial data.
**/
/datum/nanoui/proc/reinitialise(template, list/data)
/datum/nanoui/proc/reinitialize(template, list/data)
if(template)
add_template("main", template) // Replace the 'main' template.
if(data)
+1 -1
View File
@@ -35,7 +35,7 @@
if (!force_open) // UI is already open; update it.
ui.push_data(data)
else // Re-open it anyways.
ui.reinitialise(null, data)
ui.reinitialize(null, data)
return ui // We found the UI, return it.
else
return null // We couldn't find a UI.