-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathlatejoin_menu.dm
220 lines (171 loc) · 7.37 KB
/
latejoin_menu.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#define JOB_CHOICE_YES "Yes"
#define JOB_CHOICE_REROLL "Reroll"
#define JOB_CHOICE_CANCEL "Cancel"
GLOBAL_DATUM_INIT(latejoin_menu, /datum/latejoin_menu, new)
/// Makes a list of jobs and pushes them to a DM list selector. Just in case someone did a special kind of fucky-wucky with TGUI.
/datum/latejoin_menu/proc/fallback_ui(mob/dead/new_player/user)
var/list/jobs = list()
for(var/datum/job/job as anything in SSjob.occupations)
jobs += job.title
var/input_contents = input(user, "Pick a job to join as:", "Latejoin Job Selection") as null|anything in jobs
if(!input_contents)
return
user.AttemptLateSpawn(input_contents)
/datum/latejoin_menu/verb/open_fallback_ui()
set category = "Preferences"
set name = "Open fallback latejoin menu"
set desc = "Open fallback latejoin menu"
if (!istype(usr, /mob/dead/new_player))
to_chat(usr, span_notice("You cannot do this at this time!"))
return
if (!GLOB.latejoin_menu.check_latejoin_eligibility(usr, use_chat = TRUE))
return
GLOB.latejoin_menu.fallback_ui(usr)
/datum/latejoin_menu/ui_close(mob/dead/new_player/user)
. = ..()
if(istype(user))
user.jobs_menu_mounted = TRUE // Don't flood a user's chat if they open and close the UI.
/datum/latejoin_menu/ui_interact(mob/dead/new_player/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
// In case they reopen the GUI
// FIXME: this can cause a runtime since user can be a living mob
if(istype(user))
user.jobs_menu_mounted = FALSE
ui = new(user, src, "JobSelection", "Latejoin Menu")
ui.open()
/datum/latejoin_menu/ui_data(mob/user)
var/mob/dead/new_player/owner = user
var/list/departments = list()
var/list/data = list(
"disable_jobs_for_non_observers" = SSticker.late_join_disabled,
"round_duration" = DisplayTimeText(world.time - SSticker.round_start_time, round_seconds_to = 1),
"departments" = departments,
)
if(SSshuttle.emergency)
switch(SSshuttle.emergency.mode)
if(SHUTTLE_ESCAPE)
data["shuttle_status"] = "The station has been evacuated."
if(SHUTTLE_CALL, SHUTTLE_DOCKED, SHUTTLE_IGNITING, SHUTTLE_ESCAPE)
if(!SSshuttle.canRecall())
data["shuttle_status"] = "The station is currently undergoing evacuation procedures."
for(var/datum/job/prioritized_job in SSjob.prioritized_jobs)
if(prioritized_job.current_positions >= prioritized_job.total_positions)
SSjob.prioritized_jobs -= prioritized_job
for(var/datum/job_department/department as anything in SSjob.joinable_departments)
var/list/department_jobs = list()
var/list/department_data = list(
"jobs" = department_jobs,
"open_slots" = 0,
)
departments[department.department_name] = department_data
for(var/datum/job/job_datum as anything in department.department_jobs)
var/job_availability = owner.IsJobUnavailable(job_datum.title, latejoin = TRUE)
var/list/job_data = list(
"prioritized" = (job_datum in SSjob.prioritized_jobs),
"used_slots" = job_datum.current_positions,
"open_slots" = job_datum.total_positions < 0 ? "∞" : job_datum.total_positions,
)
if(job_availability != JOB_AVAILABLE)
job_data["unavailable_reason"] = get_job_unavailable_error_message(job_availability, job_datum.title)
if(job_datum.total_positions < 0)
department_data["open_slots"] = "∞"
if(department_data["open_slots"] != "∞")
if(job_datum.total_positions - job_datum.current_positions > 0)
department_data["open_slots"] += job_datum.total_positions - job_datum.current_positions
department_jobs[job_datum.title] = job_data
return data
/datum/latejoin_menu/ui_static_data(mob/user)
var/list/departments = list()
for(var/datum/job_department/department as anything in SSjob.joinable_departments)
var/list/department_jobs = list()
var/list/department_data = list(
"jobs" = department_jobs,
"color" = department.ui_color,
)
departments[department.department_name] = department_data
for(var/datum/job/job_datum as anything in department.department_jobs)
var/list/job_data = list(
"command" = !!(job_datum.departments_bitflags & DEPARTMENT_BITFLAG_COMMAND),
"description" = job_datum.description,
"icon" = job_datum.orbit_icon,
)
department_jobs[job_datum.title] = job_data
return list("departments_static" = departments)
// we can't use GLOB.new_player_state here since it also allows any admin to see the ui, which will cause runtimes
/datum/latejoin_menu/ui_status(mob/user)
return isnewplayer(user) ? UI_INTERACTIVE : UI_CLOSE
/datum/latejoin_menu/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(!ui.user.client || !isnewplayer(ui.user))
return TRUE
var/mob/dead/new_player/owner = ui.user
switch(action)
if("ui_mounted_with_no_bluescreen")
owner.jobs_menu_mounted = TRUE
if("select_job")
if(params["job"] == "Random")
var/job = get_random_job(owner)
if(!job)
tgui_alert(owner, "There is no randomly assignable job at this time. Please manually choose one of the other possible options.")
return TRUE
params["job"] = job
if (!check_latejoin_eligibility(owner))
return TRUE
remove_verb(owner, /datum/latejoin_menu/verb/open_fallback_ui)
// SAFETY: AttemptLateSpawn has it's own sanity checks. This is perfectly safe.
owner.AttemptLateSpawn(params["job"])
return TRUE
/datum/latejoin_menu/proc/check_latejoin_eligibility(mob/dead/new_player/owner, use_chat = FALSE)
if(!SSticker?.IsRoundInProgress())
if (use_chat)
to_chat(owner, span_notice("The round is either not ready, or has already finished..."))
else
tgui_alert(owner, "The round is either not ready, or has already finished...", "Oh No!")
return FALSE
if(!GLOB.enter_allowed || SSticker.late_join_disabled)
if (use_chat)
to_chat(owner, span_notice("There is an administrative lock on entering the game for non-observers!"))
else
tgui_alert(owner, "There is an administrative lock on entering the game for non-observers!", "Oh No!")
return FALSE
//Determines Relevent Population Cap
var/relevant_cap
var/hard_popcap = CONFIG_GET(number/hard_popcap)
var/extreme_popcap = CONFIG_GET(number/extreme_popcap)
if(hard_popcap && extreme_popcap)
relevant_cap = min(hard_popcap, extreme_popcap)
else
relevant_cap = max(hard_popcap, extreme_popcap)
if(SSticker.queued_players.len)
if((living_player_count() >= relevant_cap) || (owner != SSticker.queued_players[1]))
if (use_chat)
to_chat(owner, span_notice("The server is full!"))
else
tgui_alert(owner, "The server is full!", "Oh No!")
return FALSE
return TRUE
/// Gives the user a random job that they can join as, and prompts them if they'd actually like to keep it, rerolling if not. Cancellable by the user.
/// WARNING: BLOCKS THREAD!
/datum/latejoin_menu/proc/get_random_job(mob/dead/new_player/owner)
var/attempts = 0
while(TRUE)
if (attempts > 10)
// Give it a few attempts before giving up
return
var/datum/job/random_job = SSjob.GetRandomJob(owner)
if (!random_job)
return
if (owner.IsJobUnavailable(random_job.title, latejoin = TRUE) != JOB_AVAILABLE)
attempts++
continue
attempts = 0
var/list/random_job_options = list(JOB_CHOICE_YES, JOB_CHOICE_REROLL, JOB_CHOICE_CANCEL)
var/choice = tgui_alert(owner, "Do you want to play as \a [random_job.title]?", "Random Job", random_job_options)
if(choice == JOB_CHOICE_CANCEL)
return
if(choice == JOB_CHOICE_YES)
return random_job.title
#undef JOB_CHOICE_YES
#undef JOB_CHOICE_REROLL
#undef JOB_CHOICE_CANCEL