Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional ui_act checks for tacmap #5255

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 52 additions & 28 deletions code/controllers/subsystem/minimap.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define CANVAS_COOLDOWN_TIME 4 MINUTES
#define FLATTEN_MAP_COOLDOWN_TIME 3 MINUTES

/**
* # Minimaps subsystem
*
Expand Down Expand Up @@ -438,11 +441,11 @@ SUBSYSTEM_DEF(minimaps)
if(faction == FACTION_MARINE)
if(!COOLDOWN_FINISHED(GLOB, uscm_flatten_map_icon_cooldown))
return FALSE
COOLDOWN_START(GLOB, uscm_flatten_map_icon_cooldown, flatten_map_cooldown_time)
COOLDOWN_START(GLOB, uscm_flatten_map_icon_cooldown, FLATTEN_MAP_COOLDOWN_TIME)
else if(faction == XENO_HIVE_NORMAL)
if(!COOLDOWN_FINISHED(GLOB, xeno_flatten_map_icon_cooldown))
return FALSE
COOLDOWN_START(GLOB, xeno_flatten_map_icon_cooldown, flatten_map_cooldown_time)
COOLDOWN_START(GLOB, xeno_flatten_map_icon_cooldown, FLATTEN_MAP_COOLDOWN_TIME)
else
return FALSE

Expand Down Expand Up @@ -500,6 +503,8 @@ SUBSYSTEM_DEF(minimaps)
qdel(svg_store_overlay)
debug_log("SVG coordinates for [faction] are not implemented!")

#define can_draw(faction, user) ((faction == FACTION_MARINE && skillcheck(user, SKILL_LEADERSHIP, SKILL_LEAD_EXPERT)) || (faction == XENO_HIVE_NORMAL && isqueen(user)))

/datum/controller/subsystem/minimaps/proc/fetch_tacmap_datum(zlevel, flags)
var/hash = "[zlevel]-[flags]"
if(hashed_tacmaps[hash])
Expand Down Expand Up @@ -625,9 +630,6 @@ SUBSYSTEM_DEF(minimaps)
var/toolbar_color_selection = "black"
var/toolbar_updated_selection = "black"

var/canvas_cooldown_time = 4 MINUTES
var/flatten_map_cooldown_time = 3 MINUTES

/// boolean value to keep track if the canvas has been updated or not, the value is used in tgui state.
var/updated_canvas = FALSE
/// current flattend map
Expand Down Expand Up @@ -740,7 +742,6 @@ SUBSYSTEM_DEF(minimaps)
else
data["canvasCooldown"] = max(GLOB.uscm_canvas_cooldown - world.time, 0)

data["nextCanvasTime"] = canvas_cooldown_time
data["updatedCanvas"] = updated_canvas

data["lastUpdateTime"] = last_update_time
Expand All @@ -750,6 +751,7 @@ SUBSYSTEM_DEF(minimaps)

/datum/tacmap/ui_static_data(mob/user)
var/list/data = list()

data["mapRef"] = map_holder?.map_ref
data["canDraw"] = FALSE
data["canViewTacmap"] = TRUE
Expand All @@ -761,6 +763,7 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/drawing/ui_static_data(mob/user)
var/list/data = list()

data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapRef"] = map_holder?.map_ref
data["canDraw"] = FALSE
data["mapFallback"] = wiki_map_fallback
Expand All @@ -773,14 +776,16 @@ SUBSYSTEM_DEF(minimaps)
data["canViewTacmap"] = is_xeno
data["canViewCanvas"] = faction == FACTION_MARINE || faction == XENO_HIVE_NORMAL

if(faction == FACTION_MARINE && skillcheck(user, SKILL_LEADERSHIP, SKILL_LEAD_EXPERT) || faction == XENO_HIVE_NORMAL && isqueen(user))
if(can_draw(faction, user))
data["canDraw"] = TRUE
data["canViewTacmap"] = TRUE

return data

/datum/tacmap/drawing/status_tab_view/ui_static_data(mob/user)
var/list/data = list()

data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapFallback"] = wiki_map_fallback
data["canDraw"] = FALSE
data["canViewTacmap"] = FALSE
Expand All @@ -791,6 +796,8 @@ SUBSYSTEM_DEF(minimaps)

/datum/tacmap/drawing/status_tab_view/xeno/ui_static_data(mob/user)
var/list/data = list()

data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapFallback"] = wiki_map_fallback
data["canDraw"] = FALSE
data["canViewTacmap"] = FALSE
Expand All @@ -814,16 +821,21 @@ SUBSYSTEM_DEF(minimaps)
var/mob/user = ui.user
var/mob/living/carbon/xenomorph/xeno = user
var/faction = istype(xeno) ? xeno.hivenumber : user.faction
if(faction == FACTION_NEUTRAL && isobserver(user))
var/is_observer = isobserver(user)
if(faction == FACTION_NEUTRAL && is_observer)
faction = allowed_flags == MINIMAP_FLAG_XENO ? XENO_HIVE_NORMAL : FACTION_MARINE
var/drawing_allowed = !is_observer && can_draw(faction, user)

switch (action)
if ("menuSelect")
switch(action)
if("menuSelect")
if(params["selection"] != "new canvas")
if(updated_canvas)
updated_canvas = FALSE
toolbar_updated_selection = toolbar_color_selection // doing this if it == canvas can cause a latency issue with the stroke.
else
if(!drawing_allowed)
msg_admin_niche("[key_name(user)] made an unauthorized attempt to 'menuSelect' the 'new canvas' panel of the [faction] tacmap!")
return FALSE
distribute_current_map_png(faction)
last_update_time = world.time
// An attempt to get the image to load on first try in the interface, but doesn't seem always reliable
Expand All @@ -832,60 +844,68 @@ SUBSYSTEM_DEF(minimaps)
old_map = get_tacmap_data_png(faction)
current_svg = get_tacmap_data_svg(faction)

if ("updateCanvas")
// forces state change, this will export the svg.
if("updateCanvas")
toolbar_updated_selection = "export"
updated_canvas = TRUE
action_queue_change += 1

if ("clearCanvas")
if("clearCanvas")
toolbar_updated_selection = "clear"
updated_canvas = FALSE
action_queue_change += 1

if ("undoChange")
if("undoChange")
toolbar_updated_selection = "undo"
updated_canvas = FALSE
action_queue_change += 1

if ("selectColor")
if("selectColor")
var/newColor = params["color"]
if(newColor)
toolbar_color_selection = newColor
toolbar_updated_selection = newColor
action_queue_change += 1

if ("onDraw")
if("onDraw")
updated_canvas = FALSE
harryob marked this conversation as resolved.
Show resolved Hide resolved

if ("selectAnnouncement")
if("selectAnnouncement")
if(!drawing_allowed)
msg_admin_niche("[key_name(user)] made an unauthorized attempt to 'selectAnnouncement' the [faction] tacmap!")
return FALSE

if(!istype(params["image"], /list)) // potentially very serious?
return FALSE

var/cooldown_satisfied = FALSE
if(faction == FACTION_MARINE)
GLOB.uscm_flat_tacmap_data += new_current_map
cooldown_satisfied = COOLDOWN_FINISHED(GLOB, uscm_canvas_cooldown)
else if(faction == XENO_HIVE_NORMAL)
GLOB.xeno_flat_tacmap_data += new_current_map

store_current_svg_coords(faction, params["image"], user)
current_svg = get_tacmap_data_svg(faction)
old_map = get_tacmap_data_png(faction)
cooldown_satisfied = COOLDOWN_FINISHED(GLOB, xeno_canvas_cooldown)
if(!cooldown_satisfied)
msg_admin_niche("[key_name(user)] attempted to 'selectAnnouncement' the [faction] tacmap while it is still on cooldown!")
return FALSE

if(faction == FACTION_MARINE)
COOLDOWN_START(GLOB, uscm_canvas_cooldown, canvas_cooldown_time)
var/mob/living/carbon/human/human_leader = user
GLOB.uscm_flat_tacmap_data += new_current_map
COOLDOWN_START(GLOB, uscm_canvas_cooldown, CANVAS_COOLDOWN_TIME)
for(var/datum/squad/current_squad in GLOB.RoleAuthority.squads)
current_squad.send_maptext("Tactical map update in progress...", "Tactical Map:")
var/mob/living/carbon/human/human_leader = user
human_leader.visible_message(SPAN_BOLDNOTICE("Tactical map update in progress..."))
playsound_client(human_leader.client, "sound/effects/sos-morse-code.ogg")
notify_ghosts(header = "Tactical Map", message = "The USCM tactical map has been updated.", ghost_sound = "sound/effects/sos-morse-code.ogg", notify_volume = 80, action = NOTIFY_USCM_TACMAP, enter_link = "uscm_tacmap=1", enter_text = "View", source = owner)

else if(faction == XENO_HIVE_NORMAL)
var/mutable_appearance/appearance = mutable_appearance(icon('icons/mob/hud/actions_xeno.dmi'), "toggle_queen_zoom")
COOLDOWN_START(GLOB, xeno_canvas_cooldown, canvas_cooldown_time)
GLOB.xeno_flat_tacmap_data += new_current_map
COOLDOWN_START(GLOB, xeno_canvas_cooldown, CANVAS_COOLDOWN_TIME)
xeno_maptext("The Queen has updated our hive mind map", "We sense something unusual...", faction)
var/mutable_appearance/appearance = mutable_appearance(icon('icons/mob/hud/actions_xeno.dmi'), "toggle_queen_zoom")
notify_ghosts(header = "Tactical Map", message = "The Xenomorph tactical map has been updated.", ghost_sound = "sound/voice/alien_distantroar_3.ogg", notify_volume = 50, action = NOTIFY_XENO_TACMAP, enter_link = "xeno_tacmap=1", enter_text = "View", source = user, alert_overlay = appearance)

store_current_svg_coords(faction, params["image"], user)
current_svg = get_tacmap_data_svg(faction)
old_map = get_tacmap_data_png(faction)

toolbar_updated_selection = toolbar_color_selection
message_admins("[key_name(user)] has updated the <a href='?tacmaps_panel=1'>tactical map</a> for [faction].")
updated_canvas = FALSE
Expand Down Expand Up @@ -995,3 +1015,7 @@ SUBSYSTEM_DEF(minimaps)
if(XENO_HIVE_RENEGADE)
return MINIMAP_FLAG_XENO_RENEGADE
return 0

#undef CANVAS_COOLDOWN_TIME
#undef FLATTEN_MAP_COOLDOWN_TIME
#undef can_draw
4 changes: 2 additions & 2 deletions tgui/packages/tgui/interfaces/TacticalMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface TacMapProps {
mapRef: string;
currentMenu: string;
lastUpdateTime: any;
nextCanvasTime: any;
canvasCooldownDuration: any;
canvasCooldown: any;
exportedTacMapImage: any;
tacmapReady: number;
Expand Down Expand Up @@ -192,7 +192,7 @@ const OldMapPanel = (props, context) => {
const DrawMapPanel = (props, context) => {
const { data, act } = useBackend<TacMapProps>(context);

const timeLeftPct = data.canvasCooldown / data.nextCanvasTime;
const timeLeftPct = data.canvasCooldown / data.canvasCooldownDuration;
const canUpdate = data.canvasCooldown <= 0 && !data.updatedCanvas;

const handleTacMapExport = (image: any) => {
Expand Down