Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 2289881

Browse files
authored
[admin] Adds a system to assign roles to players in the lobby (#20778)
* [admin] [events] Adds a system to assign roles to players in the lobby * Fucking linter
1 parent 260ccdc commit 2289881

7 files changed

Lines changed: 201 additions & 1 deletion

File tree

code/controllers/subsystem/job.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ SUBSYSTEM_DEF(job)
354354
initial_players_to_assign = unassigned.len
355355

356356
JobDebug("DO, Len: [unassigned.len]")
357+
GLOB.event_role_manager.setup_event_positions()
357358
if(unassigned.len == 0)
358359
return validate_required_jobs(required_jobs)
359360

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
GLOBAL_DATUM_INIT(event_role_manager, /datum/event_role_manager, new)
2+
3+
/client/proc/event_role_manager()
4+
set name = "Event Role Manager"
5+
set category = "Event"
6+
GLOB.event_role_manager.ui_interact(mob)
7+
8+
/datum/event_role_manager
9+
var/role_assignments = list()
10+
11+
/datum/event_role_manager/ui_interact(mob/user, datum/tgui/ui)
12+
ui = SStgui.try_update_ui(user, src, ui)
13+
if(!ui)
14+
ui = new(user, src, "EventRoleManager")
15+
ui.open()
16+
17+
/datum/event_role_manager/ui_state(mob/user)
18+
return GLOB.fun_state
19+
20+
/datum/event_role_manager/ui_data(mob/user)
21+
. = ..()
22+
23+
var/list/assignments = list()
24+
for(var/ckey in role_assignments)
25+
var/ckey_data = list()
26+
var/datum/event_role_assignment/assignment = role_assignments[ckey]
27+
ckey_data["ckey"] = ckey
28+
ckey_data["title"] = assignment.title
29+
ckey_data["role_alt_title"] = assignment.role_alt_title
30+
assignments.Add(list(ckey_data))
31+
.["assignments"] = assignments
32+
33+
var/jobs = list()
34+
for(var/job in SSjob.name_occupations_all)
35+
jobs += job
36+
.["jobs"] = jobs
37+
38+
/datum/event_role_manager/ui_act(action, params)
39+
if(..())
40+
return
41+
var/ckey = ckey(params["ckey"])
42+
switch(action)
43+
if("addCkey")
44+
LAZYSET(role_assignments, ckey, new /datum/event_role_assignment)
45+
return TRUE
46+
if("setTitle")
47+
var/datum/event_role_assignment/assignment = LAZYACCESS(role_assignments, ckey)
48+
if(assignment)
49+
assignment.title = params["title"]
50+
return TRUE
51+
if("setAltTitle")
52+
var/datum/event_role_assignment/assignment = LAZYACCESS(role_assignments, ckey)
53+
if(assignment)
54+
assignment.role_alt_title = params["alt_title"]
55+
return TRUE
56+
if("removeCkey")
57+
LAZYREMOVE(role_assignments, ckey)
58+
return TRUE
59+
60+
/datum/event_role_manager/proc/admin_status_panel(var/list/items)
61+
if(!LAZYLEN(role_assignments))
62+
return
63+
64+
items += "Assigned player status:"
65+
66+
for(var/ckey in role_assignments)
67+
var/client/client = GLOB.directory[ckey]
68+
if(!client)
69+
items += "<font color='red'>[ckey] is not connected</font>"
70+
continue
71+
var/mob/player = client.mob
72+
if(!istype(player, /mob/dead/new_player))
73+
items += "<font color='red'>[ckey] is type [player.type]</font>"
74+
else
75+
var/mob/dead/new_player/new_player = player
76+
if(new_player.ready == PLAYER_READY_TO_PLAY)
77+
items += "<font color='green'>[ckey] - Ready</font>"
78+
else
79+
items += "<font color='red'>[ckey] - Not Ready</font>"
80+
81+
/datum/event_role_manager/proc/setup_event_positions()
82+
for(var/ckey in role_assignments)
83+
var/client/client = GLOB.directory[ckey]
84+
if(!client)
85+
message_admins("[ckey] is not connected")
86+
continue
87+
var/mob/player = client.mob
88+
var/datum/event_role_assignment/assignment = role_assignments[ckey]
89+
if(!istype(player, /mob/dead/new_player))
90+
message_admins("[ckey] is not in the lobby!")
91+
continue
92+
if(assignment.title)
93+
player.mind.assigned_role = assignment.title
94+
if(assignment.role_alt_title)
95+
player.mind.role_alt_title = assignment.role_alt_title
96+
SSjob.unassigned -= player
97+
98+
var/mob/dead/new_player/new_player = player
99+
if(new_player.ready != PLAYER_READY_TO_PLAY)
100+
message_admins("[ckey] is not ready, forcing ready")
101+
new_player.ready = PLAYER_READY_TO_PLAY
102+
103+
/datum/event_role_assignment
104+
var/title
105+
var/role_alt_title

code/modules/admin/admin_verbs.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ GLOBAL_LIST_INIT(admin_verbs_fun, list(
130130
/client/proc/admin_vox, // yogs - Admin AI Vox
131131
/client/proc/admin_away,
132132
/client/proc/centcom_podlauncher,/*Open a window to launch a Supplypod and configure it or it's contents*/
133-
/client/proc/load_json_admin_event
133+
/client/proc/load_json_admin_event,
134+
/client/proc/event_role_manager
134135
))
135136
GLOBAL_PROTECT(admin_verbs_fun)
136137
GLOBAL_LIST_INIT(admin_verbs_spawn, list(/datum/admins/proc/spawn_atom, /datum/admins/proc/podspawn_atom, /datum/admins/proc/spawn_cargo, /datum/admins/proc/spawn_objasmob, /client/proc/respawn_character, /datum/admins/proc/beaker_panel))

code/modules/mob/dead/dead.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ INITIALIZE_IMMEDIATE(/mob/dead)
5353
. += "Players: [SSticker.totalPlayers]"
5454
if(client.holder)
5555
. += "Players Ready: [SSticker.totalPlayersReady]"
56+
GLOB.event_role_manager.admin_status_panel(.)
5657

5758
/mob/dead/proc/server_hop()
5859
set category = "OOC"

code/modules/tgui/states/fun.dm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GLOBAL_DATUM_INIT(fun_state, /datum/ui_state/fun_state, new)
2+
3+
/datum/ui_state/fun_state/can_use_topic(src_object, mob/user)
4+
if(check_rights_for(user.client, R_FUN))
5+
return UI_INTERACTIVE
6+
return UI_CLOSE
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { KEY_ENTER } from '../../common/keycodes';
2+
import { useBackend, useLocalState } from '../backend';
3+
import { Button, Flex, NoticeBox, Section, ProgressBar, Table, Box, Input, Dropdown } from '../components';
4+
import { Window } from '../layouts';
5+
6+
type RoleManagerContext = {
7+
assignments: Assignment[];
8+
jobs: string[];
9+
};
10+
11+
type Assignment = {
12+
ckey: string;
13+
title: string;
14+
role_alt_title: string
15+
}
16+
17+
export const EventRoleManager = (props, context) => {
18+
const { data, act } = useBackend<RoleManagerContext>(context);
19+
const { assignments, jobs } = data;
20+
21+
const [
22+
message,
23+
setMessage,
24+
] = useLocalState(context, 'text', '');
25+
26+
return (
27+
<Window width={700}
28+
height={700}
29+
title="Event Role Manager"
30+
resizable>
31+
<Window.Content>
32+
<Section fill title="Role Assignments" buttons={(
33+
<Box>
34+
<Input value={message} onChange={(e, value) => {
35+
if (e.keyCode === KEY_ENTER) {
36+
act('addCkey', { 'ckey': value });
37+
e.target.value = '';
38+
setMessage('');
39+
} else {
40+
setMessage(value);
41+
}
42+
}} />
43+
<Button icon="plus" color="good" onClick={(e, value) => {
44+
act('addCkey', { 'ckey': message });
45+
setMessage('');
46+
}} />
47+
</Box>
48+
)}>
49+
<Table>
50+
<Table.Row>
51+
<Table.Cell>
52+
Ckey
53+
</Table.Cell>
54+
<Table.Cell>
55+
Job
56+
</Table.Cell>
57+
<Table.Cell pl="10px">
58+
Title
59+
</Table.Cell>
60+
</Table.Row>
61+
{assignments.map(assignment => (
62+
<Table.Row key={assignment.ckey}>
63+
<Table.Cell width="150px">
64+
{assignment.ckey}
65+
</Table.Cell>
66+
<Table.Cell collapsing py="3px">
67+
<Dropdown width="200px" selected={assignment.title} options={jobs} onSelected={value => act("setTitle", { ckey: assignment.ckey, title: value })} />
68+
</Table.Cell>
69+
<Table.Cell px="10px">
70+
<Input value={assignment.role_alt_title} width="100%" onChange={(e, value) => {
71+
act("setAltTitle", { ckey: assignment.ckey, alt_title: value });
72+
}} />
73+
</Table.Cell>
74+
<Table.Cell collapsing>
75+
<Button icon="trash" color="bad" onClick={() => act('removeCkey', { ckey: assignment.ckey })} />
76+
</Table.Cell>
77+
</Table.Row>
78+
))}
79+
</Table>
80+
</Section>
81+
</Window.Content>
82+
</Window>
83+
);
84+
};

yogstation.dme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,7 @@
15431543
#include "code\modules\admin\topic.dm"
15441544
#include "code\modules\admin\whitelist.dm"
15451545
#include "code\modules\admin\admin_events\admin_events.dm"
1546+
#include "code\modules\admin\admin_events\event_role_manager.dm"
15461547
#include "code\modules\admin\permissions\database.dm"
15471548
#include "code\modules\admin\permissions\forums.dm"
15481549
#include "code\modules\admin\permissions\permissions.dm"
@@ -3689,6 +3690,7 @@
36893690
#include "code\modules\tgui\states\contained.dm"
36903691
#include "code\modules\tgui\states\deep_inventory.dm"
36913692
#include "code\modules\tgui\states\default.dm"
3693+
#include "code\modules\tgui\states\fun.dm"
36923694
#include "code\modules\tgui\states\hands.dm"
36933695
#include "code\modules\tgui\states\holder.dm"
36943696
#include "code\modules\tgui\states\human_adjacent.dm"

0 commit comments

Comments
 (0)