Skip to content

Commit

Permalink
Fixed view statistics menu to show playtimes instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Watermelon914 authored and Neth Iafin committed Sep 26, 2020
1 parent 0d69829 commit d8969a8
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 33 deletions.
9 changes: 5 additions & 4 deletions #preprocessor/define/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ var/global/list/JOB_COMMAND_ROLES_LIST = list(JOB_CO, JOB_XO, JOB_SO)
#define JOB_PREDATOR "Predator"
#define JOB_XENOMORPH "Xenomorph"

#define MATURE_THRESHOLD 10 HOURS
#define ELDER_THRESHOLD 25 HOURS
#define ANCIENT_THRESHOLD 70 HOURS
#define PRIME_THRESHOLD 175 HOURS
// For colouring the ranks in the statistics menu
#define JOB_PLAYTIME_TIER_1 (10 HOURS)
#define JOB_PLAYTIME_TIER_2 (25 HOURS)
#define JOB_PLAYTIME_TIER_3 (70 HOURS)
#define JOB_PLAYTIME_TIER_4 (175 HOURS)

#define XENO_NO_AGE -1
#define XENO_NORMAL 0
Expand Down
5 changes: 5 additions & 0 deletions code/__HELPERS/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

#define HOURS *36000

#define MINUTES_TO_DECISECOND *600
#define MINUTES_TO_HOURS /60

#define DECISECONDS_TO_HOURS /36000

#define SECONDS_1 10
#define SECONDS_2 20
#define SECONDS_3 30
Expand Down
11 changes: 10 additions & 1 deletion code/datums/entities/player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


// UNTRACKED FIELDS
var/name // Used for NanoUI statistics menu

var/warning_count = 0
var/refs_loaded = FALSE
var/notes_loaded = FALSE
Expand All @@ -38,6 +40,7 @@
var/list/datum/entity/player_note/notes
var/list/datum/entity/player_job_ban/job_bans
var/list/datum/entity/player_time/playtimes
var/list/playtime_data // For the NanoUI menu
var/client/owning_client

BSQL_PROTECT_DATUM(/datum/entity/player)
Expand Down Expand Up @@ -385,9 +388,15 @@ BSQL_PROTECT_DATUM(/datum/entity/player)

/datum/entity/player/proc/on_read_timestat(var/list/datum/entity/player_time/_stat)
playtime_loaded = TRUE
if(_stat)
if(_stat) // Viewable playtime statistics are only loaded when the player connects, as they do not need constant updates since playtime is a statistic that is recorded over a long period of time
LAZYSET(playtime_data, "category", 0)
LAZYSET(playtime_data, "loaded", FALSE) // The jobs themselves can be loaded whenever a player opens their statistic menu
LAZYSET(playtime_data, "stored_human_playtime", list())
LAZYSET(playtime_data, "stored_xeno_playtime", list())

for(var/datum/entity/player_time/S in _stat)
LAZYSET(playtimes, S.role_id, S)


/proc/get_player_from_key(key)
var/safe_key = ckey(key)
Expand Down
104 changes: 101 additions & 3 deletions code/datums/entities/player_times.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@

#define get_job_playtime(client, job) (client.player_data? LAZYACCESS(client.player_data.playtimes, job)? client.player_data.playtimes[job].total_minutes MINUTES_TO_DECISECOND : 0 : 0)

/datum/entity/player_time
var/player_id
var/role_id
var/total_minutes

// Untracked vars
var/bgcolor = "#4a4a4a"
var/textcolor = "#ffffff"

BSQL_PROTECT_DATUM(/datum/entity/player_time)

/datum/entity_meta/player_time
Expand All @@ -15,7 +22,7 @@ BSQL_PROTECT_DATUM(/datum/entity/player_time)
)

/datum/entity_meta/player_time/on_insert(var/datum/entity/player_time/player)
player.total_minutes = 0
player.total_minutes = 0

/datum/entity_link/player_to_time
parent_entity = /datum/entity/player
Expand All @@ -25,6 +32,97 @@ BSQL_PROTECT_DATUM(/datum/entity/player_time)
parent_name = "player"
child_name = "player_times"

#define MINUTES_TO_DECISECOND *600 // Converting to decisecond makes it easier to do in calculations
/datum/view_record/playtime
var/player_id
var/role_id
var/total_minutes

#define get_job_playtime(client, job) (client.player_data? LAZYACCESS(client.player_data.playtimes, job)? client.player_data.playtimes[job].total_minutes MINUTES_TO_DECISECOND : 0 : 0)
/datum/entity_view_meta/playtime_ordered
root_record_type = /datum/entity/player_time
destination_entity = /datum/view_record/playtime
fields = list(
"player_id",
"role_id",
"total_minutes"
)
order_by = list("total_minutes" = DB_ORDER_BY_DESC)

/datum/view_record/playtime/proc/get_nanoui_data()

var/playtime_percentage = min((total_minutes MINUTES_TO_DECISECOND) / JOB_PLAYTIME_TIER_4, 1)
return list(
"job" = role_id,
"playtime" = round(total_minutes MINUTES_TO_HOURS, 0.1),
"bgcolor" = "rgb(0, [Floor(128 * playtime_percentage)], [Floor(255 * playtime_percentage)])",
"textcolor" = "#FFFFFF"
)

/datum/entity/player/proc/ui_interact(mob/user, ui_key = "playtime", var/datum/nanoui/ui = null, force_open = FALSE)
if(!user.client || !playtime_loaded || LAZYACCESS(playtime_data, "loading"))
return

if(!LAZYACCESS(playtime_data, "loaded"))
load_timestat_data()

ui = nanomanager.try_update_ui(user, src, ui_key, ui, playtime_data, force_open)

if(!ui)
ui = new(user, src, ui_key, "playtime.tmpl", "Playtimes", 450, 700, null, -1)
ui.set_initial_data(playtime_data)
ui.open()
ui.set_auto_update(FALSE)

/datum/entity/player/Topic(href, href_list)
var/mob/user = usr
user.set_interaction(src)

if(href_list["switchCategory"])
LAZYSET(playtime_data, "category", href_list["switchCategory"])


nanomanager.update_uis(src)

/datum/entity/player/proc/load_timestat_data()
if(!playtime_loaded || !RoleAuthority || LAZYACCESS(playtime_data, "loading")) // Need roleauthority to be up to see which job is xeno-related
return

LAZYSET(playtime_data, "loading", TRUE)
var/list/datum/view_record/playtime/PTs = DB_VIEW(/datum/view_record/playtime, DB_COMP("player_id", DB_EQUALS, id))

var/list/xeno_playtimes = LAZYACCESS(playtime_data, "stored_xeno_playtime")
var/list/marine_playtimes = LAZYACCESS(playtime_data, "stored_human_playtime")

LAZYCLEARLIST(xeno_playtimes)
LAZYCLEARLIST(marine_playtimes)

if(owning_client)
var/list/xeno_playtime = list(
"job" = "Xenomorph",
"playtime" = round(owning_client.get_total_xeno_playtime() DECISECONDS_TO_HOURS, 0.1),
"bgcolor" = "#3a3a3a",
"textcolor" = "#FFFFFF"
)

var/list/marine_playtime = list(
"job" = "Human",
"playtime" = round(owning_client.get_total_human_playtime() DECISECONDS_TO_HOURS, 0.1),
"bgcolor" = "#3a3a3a",
"textcolor" = "#FFFFFF"
)

LAZYADD(xeno_playtimes, list(xeno_playtime))
LAZYADD(marine_playtimes, list(marine_playtime))

for(var/datum/view_record/playtime/PT in PTs)
var/isXeno = (PT.role_id in RoleAuthority.castes_by_name)

if(!(PT.role_id in RoleAuthority.roles_by_name) && !isXeno)
continue

if(isXeno)
LAZYADD(xeno_playtimes, list(PT.get_nanoui_data()))
else
LAZYADD(marine_playtimes, list(PT.get_nanoui_data()))

LAZYSET(playtime_data, "loading", FALSE)
LAZYSET(playtime_data, "loaded", TRUE)
7 changes: 0 additions & 7 deletions code/game/gamemodes/game_mode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ var/global/cas_tracking_id_increment = 0 //this var used to assign unique tracki
M.track_death_calculations()
M.statistic_exempt = TRUE

/datum/game_mode/proc/show_end_statistics()
round_statistics.update_panel_data()
for(var/mob/M in player_list)
if(M.client && M.client.player_entity)
M.client.player_entity.show_statistics(M, round_statistics, TRUE)
//save_player_entities()

/datum/game_mode/proc/check_win() //universal trigger to be called at mob death, nuke explosion, etc. To be called from everywhere.
return 0

Expand Down
5 changes: 0 additions & 5 deletions code/game/gamemodes/gameticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ var/global/datum/controller/gameticker/ticker = new()

spawn(1)
declare_completion()
calculate_end_statistics()
show_end_statistics()

spawn(50)
callHook("roundend")
Expand Down Expand Up @@ -272,9 +270,6 @@ var/global/datum/controller/gameticker/ticker = new()
/datum/controller/gameticker/proc/calculate_end_statistics()
mode.calculate_end_statistics()

/datum/controller/gameticker/proc/show_end_statistics()
mode.show_end_statistics()

/datum/controller/gameticker/proc/declare_completion()
mode.declare_completion()//To declare normal completion.

Expand Down
9 changes: 6 additions & 3 deletions code/modules/mob/dead/observer/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ Works together with spawning an observer, noted above.
ghost.client.soundOutput.status_flags = 0 //Clear all effects that would affect a living mob
ghost.client.soundOutput.apply_status()

if(ghost.client.player_data)
ghost.client.player_data.load_timestat_data()

ghost.set_huds_from_prefs()

return ghost
Expand Down Expand Up @@ -804,11 +807,11 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp

/mob/dead/observer/verb/view_stats()
set category = "Ghost"
set name = "View Statistics"
set desc = "View global and player statistics tied to the game."
set name = "View Playtimes"
set desc = "View your playtimes."

if(client && client.player_entity)
client.player_entity.show_statistics(src, round_statistics)
client.player_data.ui_interact(src)

/mob/dead/observer/verb/view_kill_feed()
set category = "Ghost"
Expand Down
17 changes: 16 additions & 1 deletion code/modules/mob/living/carbon/human/human_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,19 @@

var/datum/action/human_action/activable/selected_ability

var/datum/agent/agent_holder
var/datum/agent/agent_holder

/client/var/cached_human_playtime

/client/proc/get_total_human_playtime(var/skip_cache = FALSE)
if(cached_human_playtime && !skip_cache)
return cached_human_playtime

var/total_marine_playtime = 0

for(var/job in RoleAuthority.roles_by_name)
total_marine_playtime += get_job_playtime(src, job)

cached_human_playtime = total_marine_playtime

return total_marine_playtime
8 changes: 4 additions & 4 deletions code/modules/mob/living/carbon/xenomorph/XenoUpgrade.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
var/hours_as_caste = get_job_playtime(client, caste.caste_name)

switch(hours_as_caste)
if(MATURE_THRESHOLD to ELDER_THRESHOLD)
if(JOB_PLAYTIME_TIER_1 to JOB_PLAYTIME_TIER_2)
age = XENO_MATURE
if(ELDER_THRESHOLD to ANCIENT_THRESHOLD)
if(JOB_PLAYTIME_TIER_2 to JOB_PLAYTIME_TIER_3)
age = XENO_ELDER
if(ANCIENT_THRESHOLD to PRIME_THRESHOLD)
if(JOB_PLAYTIME_TIER_3 to JOB_PLAYTIME_TIER_4)
age = XENO_ANCIENT
if(PRIME_THRESHOLD to INFINITY)
if(JOB_PLAYTIME_TIER_4 to INFINITY)
age = XENO_PRIME

// For people who wish to remain anonymous
Expand Down
9 changes: 4 additions & 5 deletions code/modules/mob/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
output +="<br><b>[xeno_text]</b>"
output += "<p><a href='byond://?src=\ref[src];lobby_choice=show_preferences'>Setup Character</A></p>"

output += "<p><a href='byond://?src=\ref[src];lobby_choice=show_statistics'>View Statistics</A></p>"
output += "<p><a href='byond://?src=\ref[src];lobby_choice=show_playtimes'>View Playtimes</A></p>"

if(round_start)
output += "<p>\[ [ready? "<b>Ready</b>":"<a href='byond://?src=\ref[src];lobby_choice=ready'>Ready</a>"] | [ready? "<a href='byond://?src=\ref[src];lobby_choice=unready'>Not Ready</a>":"<b>Not Ready</b>"] \]</p>"
Expand Down Expand Up @@ -101,10 +101,9 @@
client.prefs.ShowChoices(src)
return 1

if("show_statistics")
if(client.player_entity)
client.player_entity.menu = 1
client.player_entity.show_statistics(src, null)
if("show_playtimes")
if(client.player_data)
client.player_data.ui_interact(src)
return 1

if("ready")
Expand Down
46 changes: 46 additions & 0 deletions nano/templates/playtime.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<style>
.playtime_table {
width: 100%;
margin-top: 5px;
background: linear-gradient(180deg, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%);
}
.playtime_row {
width: 100%;
margin: 10px 0 0 0;

font-size: large;
text-align: center;
border: solid black 1px;
}
</style>

<div class="item">
{{:helper.link('Human', null, {'switchCategory' : 0}, data.category == 0 ? 'selected' : null)}}
{{:helper.link('Xenomorph', null, {'switchCategory' : 1}, data.category == 1 ? 'selected' : null)}}
</div>

<table class="playtime_table">
<tr>
<th>Role</th>
<th>Playtime</th>
</tr>

{{if data.category == 0}}
{{:helper.USCMMode()}}
{{for data.stored_human_playtime}}
<tr class="playtime_row" style="background-color: {{:value.bgcolor}}">
<td style="color: {{:value.textcolor}}">{{:value.job}}</td>
<td style="color: {{:value.textcolor}}">{{:value.playtime}} HOURS</td>
</tr>
{{/for}}
{{else data.category == 1}}
{{:helper.xenoMode()}}

{{for data.stored_xeno_playtime}}
<tr class="playtime_row" style="background-color: {{:value.bgcolor}}">
<td style="color: {{:value.textcolor}}">{{:value.job}}</td>
<td style="color: {{:value.textcolor}}">{{:value.playtime}} HOURS</td>
</tr>
{{/for}}
{{/if}}
</table>

0 comments on commit d8969a8

Please sign in to comment.