This commit is contained in:
CitadelStationBot
2017-05-09 00:46:42 -05:00
committed by kevinz000
parent 0c5d7796f8
commit ba0f4b1c59
4 changed files with 148 additions and 30 deletions

View File

@@ -11,6 +11,9 @@ GLOBAL_LIST_EMPTY(GPS_list)
var/emped = FALSE
var/turf/locked_location
var/tracking = TRUE
var/updating = TRUE //Automatic updating of GPS list. Can be set to manual by user.
var/global_mode = TRUE //If disabled, only GPS signals of the same Z level are shown
/obj/item/device/gps/Initialize()
..()
@@ -27,6 +30,7 @@ GLOBAL_LIST_EMPTY(GPS_list)
cut_overlay("working")
add_overlay("emp")
addtimer(CALLBACK(src, .proc/reboot), 300, TIMER_OVERRIDE) //if a new EMP happens, remove the old timer so it doesn't reactivate early
SStgui.close_uis(src) //Close the UI control if it is open.
/obj/item/device/gps/proc/reboot()
emped = FALSE
@@ -34,6 +38,9 @@ GLOBAL_LIST_EMPTY(GPS_list)
add_overlay("working")
/obj/item/device/gps/AltClick(mob/user)
toggletracking(user)
/obj/item/device/gps/proc/toggletracking(mob/user)
if(!user.canUseTopic(src, be_close=TRUE))
return //user not valid to use gps
if(emped)
@@ -48,36 +55,81 @@ GLOBAL_LIST_EMPTY(GPS_list)
to_chat(user, "[src] is now tracking, and visible to other GPS devices.")
tracking = TRUE
/obj/item/device/gps/attack_self(mob/user)
if(!tracking)
to_chat(user, "[src] is turned off. Use alt+click to toggle it back on.")
return
var/obj/item/device/gps/t = ""
var/gps_window_height = 110 + GLOB.GPS_list.len * 20 // Variable window height, depending on how many GPS units there are to show
/obj/item/device/gps/ui_interact(mob/user, ui_key = "gps", datum/tgui/ui = null, force_open = 0, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state) // Remember to use the appropriate state.
if(emped)
t += "ERROR"
else
t += "<BR><A href='?src=\ref[src];tag=1'>Set Tag</A> "
t += "<BR>Tag: [gpstag]"
if(locked_location && locked_location.loc)
t += "<BR>Bluespace coordinates saved: [locked_location.loc]"
gps_window_height += 20
for(var/obj/item/device/gps/G in GLOB.GPS_list)
var/turf/pos = get_turf(G)
var/area/gps_area = get_area(G)
var/tracked_gpstag = G.gpstag
if(G.emped == 1)
t += "<BR>[tracked_gpstag]: ERROR"
else if(G.tracking)
t += "<BR>[tracked_gpstag]: [format_text(gps_area.name)] ([pos.x], [pos.y], [pos.z])"
else
continue
var/datum/browser/popup = new(user, "GPS", name, 360, min(gps_window_height, 800))
popup.set_content(t)
popup.set_title_image(user.browse_rsc_icon(src.icon, src.icon_state))
popup.open()
to_chat(user, "[src] fizzles weakly.")
return
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
var/gps_window_height = 300 + GLOB.GPS_list.len * 20 // Variable window height, depending on how many GPS units there are to show
ui = new(user, src, ui_key, "gps", "Global Positioning System", 600, gps_window_height, master_ui, state) //width, height
ui.open()
ui.set_autoupdate(state = updating)
/obj/item/device/gps/ui_data(mob/user)
var/list/data = list()
data["power"] = tracking
data["tag"] = gpstag
data["updating"] = updating
data["globalmode"] = global_mode
if(!tracking || emped) //Do not bother scanning if the GPS is off or EMPed
return data
var/turf/curr = get_turf(src)
data["current"] = "[get_area_name(curr)] ([curr.x], [curr.y], [curr.z])"
var/list/signals = list()
data["signals"] = list()
for(var/gps in GLOB.GPS_list)
var/obj/item/device/gps/G = gps
if(G.emped || !G.tracking || G == src)
continue
var/turf/pos = get_turf(G)
if(!global_mode && pos.z != curr.z)
continue
var/area/gps_area = get_area_name(G)
var/list/signal = list()
signal["entrytag"] = G.gpstag //Name or 'tag' of the GPS
signal["area"] = format_text(gps_area)
signal["coord"] = "[pos.x], [pos.y], [pos.z]"
if(pos.z == curr.z) //Distance/Direction calculations for same z-level only
signal["dist"] = max(get_dist(curr, pos), 0) //Distance between the src and remote GPS turfs
signal["degrees"] = round(Get_Angle(curr, pos)) //0-360 degree directional bearing, for more precision.
var/direction = uppertext(dir2text(get_dir(curr, pos))) //Direction text (East, etc). Not as precise, but still helpful.
if(!direction)
direction = "CENTER"
signal["degrees"] = "N/A"
signal["direction"] = direction
signals += list(signal) //Add this signal to the list of signals
data["signals"] = signals
return data
/obj/item/device/gps/ui_act(action, params)
if(..())
return
switch(action)
if("rename")
var/a = input("Please enter desired tag.", name, gpstag) as text
a = uppertext(copytext(sanitize(a), 1, 5))
gpstag = a
name = "global positioning system ([gpstag])"
. = TRUE
if("power")
toggletracking(usr)
. = TRUE
if("updating")
updating = !updating
. = TRUE
if("globalmode")
global_mode = !global_mode
. = TRUE
/obj/item/device/gps/Topic(href, href_list)
..()
@@ -157,4 +209,4 @@ GLOBAL_LIST_EMPTY(GPS_list)
clear()
tagged = null
STOP_PROCESSING(SSfastprocess, src)
. = ..()
. = ..()

File diff suppressed because one or more lines are too long

36
tgui/assets/tgui.js.rej Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,30 @@
<ui-display title='Controls'>
<ui-section label='Power'>
<ui-button icon="power-off" style='{{data.power ? "selected" : "danger"}}' action='power'>{{data.power ? "Enabled" : "Disabled"}}</ui-button>
</ui-section>
<ui-section label='Tag'>
<ui-button icon='pencil' action='rename'>{{data.tag}}</ui-button>
</ui-section>
<ui-section label='Scanning mode'>
<ui-button icon={{data.updating ? "unlock" : "lock"}} style= {{data.updating ? null : "danger"}} action='updating' tooltip='Toggle between automatic scanning or scan only when a button is pressed.' tooltip-side='right'>{{data.updating ? "AUTO" : "MANUAL"}}</ui-button>
</ui-section>
<ui-section label='Detection range'>
<ui-button icon='refresh' style= {{data.globalmode ? null : "selected"}} action='globalmode' tooltip='Local sector or whole region scanning.' tooltip-side='right'>{{data.globalmode ? "MAXIMUM" : "LOCAL"}}</ui-button>
</ui-section>
</ui-display>
{{#if data.power}}
<ui-display title='Current Location'>
<span>{{data.current}}</span>
</ui-display>
<ui-display title='Detected Signals'>
{{#each data.signals}}
<ui-section label={{entrytag}}>
<span>{{area}} ({{coord}}) </span>
{{#if direction}}
<span>Dist: {{dist}}m Dir: {{degrees}}° ({{direction}})</span>
{{/if}}
</ui-section>
{{/each}}
</ui-display>
{{/if}}