Skip to content

Commit

Permalink
Stat panel general cleanup + Improvements (Partial Bounty) (#9655)
Browse files Browse the repository at this point in the history
* Stat panel improvements

* Executes prettier

* Images

* Makes the sorting a bit nicer

* Executes prettier again

* Fixes mobs always showing as "unknown"

* Optimises the obscure check

* Proper number

* Update StatText.js
  • Loading branch information
PowerfulBacon authored Oct 6, 2023
1 parent b007485 commit 5589dfc
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 52 deletions.
1 change: 0 additions & 1 deletion code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1808,4 +1808,3 @@
qdel(src)
return TRUE
return FALSE

13 changes: 12 additions & 1 deletion code/modules/admin/verbs/_help.dm
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,19 @@
for(var/datum/help_ticket/AH in l)
if(AH.initiator)
tab_data["#[AH.id]. [AH.initiator_key_name]"] = list(
text = AH.name,
text = AH.stat_text,
type = STAT_BUTTON,
action = "open_ticket",
params = list("id" = AH.id),
multirow = TRUE,
buttons = list(
list(
"title" = AH.claimee_key_name ? "Claimed by [AH.claimee_key_name]" : "Claim",
"color" = AH.claimee_key_name ? "red" : "green",
"action_id" = "claim_ticket",
"params" = list("id" = AH.id)
)
)
)
else
++num_disconnected
Expand Down Expand Up @@ -311,6 +320,7 @@
/datum/help_ticket
var/id
var/name
var/stat_text
var/state = TICKET_UNCLAIMED
/// The first (sanitized) message for this ticket
var/initial_msg
Expand Down Expand Up @@ -359,6 +369,7 @@
opened_at = world.time

name = copytext_char(msg, 1, 100)
stat_text = copytext_char(msg, 1, 500)

var/datum/help_tickets/data_glob = get_data_glob()
if(!istype(data_glob))
Expand Down
145 changes: 119 additions & 26 deletions code/modules/mob/mob_stat.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
/// How many items per tile until we just completely give up?
#define MAX_ITEMS_TO_READ 500
/// How many unique entries should we show per-tile before giving up?
#define MAX_ICONS_PER_TILE 50

/// Determine the priority of this item in the stat panel
/// I decided to do it this way to reduce the amount of memory wasted on all atoms.
/// There is a reason for this madness
#define STAT_PANEL_TAG(atom) ishuman(atom) \
? "Human" \
: ismob(atom) \
? "Mob" \
: isitem(atom) \
? "Item" \
: isstructure(atom) \
? "Structure" \
: ismachinery(atom) \
? "Machinery" \
: isturf(atom) \
? "Turf" \
: "Other"

/client
var/stat_update_mode = STAT_FAST_UPDATE
var/stat_update_time = 0
Expand Down Expand Up @@ -73,32 +93,8 @@
// ===== NON CONSTANT TABS (Tab names which can change) =====
// ===== LISTEDS TURFS =====
if(listed_turf && sanitize(listed_turf.name) == selected_tab)
client.stat_update_mode = STAT_MEDIUM_UPDATE
var/list/overrides = list()
for(var/image/I in client.images)
if(I.loc && I.loc.loc == listed_turf && I.override)
overrides += I.loc
tab_data[REF(listed_turf)] = list(
text="[listed_turf.name]",
type=STAT_ATOM
)
var/sanity = MAX_ICONS_PER_TILE
for(var/atom/A in listed_turf)
if(!A.mouse_opacity)
continue
if(A.invisibility > see_invisible)
continue
if(overrides.len && (A in overrides))
continue
if(A.IsObscured())
continue
sanity --
tab_data[REF(A)] = list(
text="[A.name]",
type=STAT_ATOM
)
if(sanity < 0)
break
// Check if we can actually see the turf
listed_turf.render_stat_information(client, tab_data)
if(mind)
tab_data += get_spell_stat_data(mind.spell_list, selected_tab)
tab_data += get_spell_stat_data(mob_spell_list, selected_tab)
Expand All @@ -108,6 +104,81 @@
return list()
return tab_data

/turf/proc/render_stat_information(client/client, list/tab_data)
client.stat_update_mode = STAT_MEDIUM_UPDATE
// Display the turf
var/list/overrides = list()
for(var/image/I in client.images)
if(I.loc && I.loc.loc == src && I.override)
overrides[I.loc] = I
tab_data[REF(src)] = list(
text="[name]",
tag = STAT_PANEL_TAG(src),
type=STAT_ATOM
)
var/max_item_sanity = MAX_ITEMS_TO_READ
var/icon_count_sanity = MAX_ICONS_PER_TILE
var/list/atom_count = list()
var/list/image_overrides = list()
// Caching for A.IsObscured to improve performance, in is faster than dictionary lookups for
// small (and even quite large) lists.
var/list/checked_layers = list()
var/list/obscured_layers = list()
// Find items and group them by both name and count
for (var/atom/A as() in src)
// Too many items read
if(max_item_sanity-- < 0)
break
if(!A.mouse_opacity)
continue
if(A.invisibility > client.mob.see_invisible)
continue
if(A.layer in checked_layers)
if (A.layer in obscured_layers)
continue
else
checked_layers += A.layer
if (A.IsObscured())
obscured_layers += A.layer
var/atom_type = A.type
var/atom_name = A.name
if(overrides.len && overrides[A])
var/image/override_image = overrides[A]
atom_name = override_image.name
image_overrides[A] = override_image
var/list/item_group = atom_count["[atom_type][atom_name]"]
if (item_group)
item_group += A
else
atom_count["[A.type][A.name]"] = list(A)
// To many icon types per tile
if (icon_count_sanity-- <= 0)
break
// Display the atoms
for(var/atom_type in atom_count)
var/atom_items = atom_count[atom_type]
var/item_count = length(atom_items)
var/atom/first_atom = atom_items[1]
if (istype(first_atom, /obj/item/stack))
item_count = 0
for (var/obj/item/stack/stack_item as() in atom_items)
item_count += stack_item.amount
var/atom_name = first_atom.name
if (image_overrides[first_atom])
var/image/override_image = image_overrides[first_atom]
atom_name = override_image.name
tab_data[REF(first_atom)] = list(
text = "[atom_name][item_count > 1 ? " (x[item_count])" : ""]",
tag = STAT_PANEL_TAG(first_atom),
type = STAT_ATOM
)
// Display self
tab_data[REF(client.mob)] = list(
text = client.mob.name,
tag = "You",
type = STAT_ATOM
)

/mob/proc/get_all_verbs()
var/list/all_verbs = new

Expand Down Expand Up @@ -254,18 +325,33 @@
return
switch(button_pressed)
if("browsetickets")
if (!client.holder)
return
GLOB.ahelp_tickets.BrowseTickets(src)
if("browseinterviews")
if (!check_rights(R_ADMIN))
return
GLOB.interviews.BrowseInterviews(src)
if("open_interview")
if (!check_rights(R_ADMIN))
return
var/datum/interview/I = GLOB.interviews.interview_by_id(text2num(params["id"]))
if (I && client.holder)
I.ui_interact(src)
if("open_ticket")
if (!client.holder)
return
var/ticket_id = text2num(params["id"])
var/datum/help_ticket/AH = GLOB.ahelp_tickets.TicketByID(ticket_id)
if(AH && client.holder)
AH.ui_interact(src)
if ("claim_ticket")
if (!check_rights(R_ADMIN))
return
var/ticket_id = text2num(params["id"])
var/datum/help_ticket/AH = GLOB.ahelp_tickets.TicketByID(ticket_id)
if(AH && client.holder)
AH.Claim()
if("atomClick")
var/atomRef = params["ref"]
var/atom/atom_actual = locate(atomRef)
Expand Down Expand Up @@ -305,13 +391,19 @@
var/verb_name = params["verb"]
winset(client, null, "command=[replacetext(verb_name, " ", "-")]")
if("sdql2debug")
if (!check_rights(R_DEBUG))
return
client.debug_variables(GLOB.sdql2_queries)
if("sdql2delete")
if (!check_rights(R_DEBUG))
return
var/query_id = params["qid"]
var/datum/SDQL2_query/query = sdqlQueryByID(text2num(query_id))
if(query)
query.delete_click()
if("sdql2toggle")
if (!check_rights(R_DEBUG))
return
var/query_id = params["qid"]
var/datum/SDQL2_query/query = sdqlQueryByID(text2num(query_id))
if(query)
Expand Down Expand Up @@ -378,4 +470,5 @@
var/list/status_data = get_stat(client.selected_stat_tab)
client.tgui_panel.set_panel_infomation(status_data)

#undef MAX_ITEMS_TO_READ
#undef MAX_ICONS_PER_TILE
Loading

0 comments on commit 5589dfc

Please sign in to comment.