Add Z-Level Manager, a basic admin tool. (#30397)

* Add Z-Level Manager, a basic admin tool.

* build bundle, use ui_module/admin

* fix type restriction

* remove unnecessary params
This commit is contained in:
warriorstar-orion
2025-10-09 20:17:29 -04:00
committed by GitHub
parent 7e4f0a0b0f
commit 82663d1c10
7 changed files with 217 additions and 2 deletions
+2 -1
View File
@@ -72,7 +72,8 @@ GLOBAL_LIST_INIT(admin_verbs_admin, list(
/client/proc/ping_all_admins,
/client/proc/show_watchlist,
/client/proc/debugstatpanel,
/client/proc/create_rnd_restore_disk
/client/proc/create_rnd_restore_disk,
/client/proc/open_admin_zlevel_manager,
))
GLOBAL_LIST_INIT(admin_verbs_ban, list(
/client/proc/ban_panel,
@@ -0,0 +1,15 @@
/client/proc/open_admin_zlevel_manager()
set name = "Z-Level Manager"
set desc = "Opens the Z-Level Manager UI"
set category = "Admin"
if(!check_rights(R_ADMIN))
return
if(!SSmapping || !SSmapping.initialized)
to_chat(usr, "<span class='notice'>SSmapping has not initialized yet, Z-Level Manager is not available yet.</span>")
return
message_admins("[key_name_admin(usr)] is using the Z-Level Manager")
var/datum/ui_module/admin/z_level_manager/ZLM = get_admin_ui_module(/datum/ui_module/admin/z_level_manager)
ZLM.ui_interact(usr)
@@ -200,3 +200,34 @@ GLOBAL_LIST_INIT(cable_typecache, typecacheof(/obj/structure/cable))
transition_border_east = (world.maxx - 4)
transition_border_south = 3
transition_border_west = 3
// space levels have no UI of their own so borrowing this proc for serialization
// for other UIs
/datum/space_level/ui_data(mob/user)
. = list(
"name" = name,
"zpos" = zpos,
"linkage" = linkage,
"transition_tag" = transition_tag,
"traits" = flags,
)
.["neighbors"] = list()
for(var/direction in list(Z_LEVEL_SOUTH, Z_LEVEL_NORTH, Z_LEVEL_EAST, Z_LEVEL_WEST))
var/datum/space_level/neighbor = get_connection(direction)
if(neighbor)
var/dirname = dir2text(text2num(direction))
.["neighbors"][dirname] = neighbor.zpos
.["ruins"] = list()
for(var/obj/effect/landmark/ruin/ruin_landmark in GLOB.ruin_landmarks)
if(ruin_landmark.z == zpos)
.["ruins"] += list(list(
"name" = ruin_landmark.ruin_template.name,
"mappath" = ruin_landmark.ruin_template.mappath,
"coords" = list(
"x" = ruin_landmark.x,
"y" = ruin_landmark.y,
"z" = ruin_landmark.z,
),
))
@@ -0,0 +1,37 @@
RESTRICT_TYPE(/datum/ui_module/admin/z_level_manager)
/datum/ui_module/admin/z_level_manager
name = "Z-Level Manager"
/datum/ui_module/admin/z_level_manager/ui_state(mob/user)
return GLOB.admin_state
/datum/ui_module/admin/z_level_manager/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ZLevelManager", name)
ui.set_autoupdate(FALSE)
ui.open()
/datum/ui_module/admin/z_level_manager/ui_data(mob/user)
. = list()
.["levels"] = list()
for(var/zlvl in GLOB.space_manager.z_list)
var/datum/space_level/level = GLOB.space_manager.z_list[zlvl]
.["levels"]["[level.zpos]"] = level.ui_data()
/datum/ui_module/admin/z_level_manager/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
if(..())
return
switch(action)
if("jump_to_coords")
var/x = params["x"]
var/y = params["y"]
var/z = params["z"]
usr.client.jumptocoord(x, y, z)
return TRUE
+2
View File
@@ -1627,6 +1627,7 @@
#include "code\modules\admin\tickets\adminticketsverbs.dm"
#include "code\modules\admin\tickets\mentorticketsverbs.dm"
#include "code\modules\admin\verbs\admin_dice.dm"
#include "code\modules\admin\verbs\admin_zlevel_manager_verb.dm"
#include "code\modules\admin\verbs\adminhelp.dm"
#include "code\modules\admin\verbs\adminjump.dm"
#include "code\modules\admin\verbs\adminpm.dm"
@@ -3270,6 +3271,7 @@
#include "code\modules\tgui\modules\power_monitor.dm"
#include "code\modules\tgui\modules\robot_self_diagnosis.dm"
#include "code\modules\tgui\modules\volume_mixer.dm"
#include "code\modules\tgui\modules\z_level_manager.dm"
#include "code\modules\tgui\plugins\modal.dm"
#include "code\modules\tgui\plugins\tgui_login.dm"
#include "code\modules\tgui\states\admin_state.dm"
@@ -0,0 +1,129 @@
import { Button, LabeledList, Section, Stack, Tabs } from 'tgui-core/components';
import { useBackend } from '../backend';
import { Window } from '../layouts';
import { useState } from 'react';
type JumpToCoordsProps = {
coords: Coord3;
};
const JumpToCoords = (props: JumpToCoordsProps) => {
const { act } = useBackend();
const { coords } = props;
const { x, y, z } = coords;
return <Button onClick={() => act('jump_to_coords', { x: x, y: y, z: z })}>JMP</Button>;
};
type Coord3 = {
x: number;
y: number;
z: number;
};
type Ruin = {
name: string;
mappath: string;
coords: Coord3;
};
type ZLevel = {
name: string;
zpos: number;
linkage: number;
transition_tag?: string;
traits: string[];
neighbors: { [key: string]: number };
ruins: Ruin[];
};
type ManagerData = {
levels: { [key: string]: ZLevel };
};
export const ZLevelManager = () => {
const { data } = useBackend<ManagerData>();
const { levels } = data;
const [activeZ, setActiveZ] = useState(1);
const zlevel = levels[`${activeZ}`];
const neighbor_to_element = (neighbor: ZLevel) => {
if (neighbor === undefined) return 'None';
if (zlevel.linkage == 0) return 'None';
if (neighbor.zpos == zlevel.zpos) return 'Looped';
const neighbor_zlevel = levels[`${neighbor.zpos}`];
return (
<Button onClick={() => setActiveZ(neighbor.zpos)}>
{neighbor_zlevel.name} ({neighbor.zpos})
</Button>
);
};
return (
<Window width={600} height={500} title="Z-Level Manager">
<Window.Content scrollable>
<Stack fill>
<Stack.Item>
<Section fill fitted>
<Tabs vertical>
{Object.values(levels).map((level, i) => (
<Tabs.Tab
key={i + 1}
color="transparent"
selected={level.zpos === activeZ}
onClick={() => setActiveZ(i + 1)}
>
{level.name} ({level.zpos})
</Tabs.Tab>
))}
</Tabs>
</Section>
</Stack.Item>
<Stack.Item grow>
{zlevel && (
<>
<Section title={`${zlevel.name} (${zlevel.zpos})`}>
<Stack fill vertical>
<Stack.Item>Traits: {zlevel.traits.join(', ')}</Stack.Item>
<Stack.Item>
Connections:
<br />
North: {neighbor_to_element(levels[`${zlevel.neighbors.north}`])}
<br />
South: {neighbor_to_element(levels[`${zlevel.neighbors.south}`])}
<br />
East: {neighbor_to_element(levels[`${zlevel.neighbors.east}`])}
<br />
West: {neighbor_to_element(levels[`${zlevel.neighbors.west}`])}
<br />
</Stack.Item>
</Stack>
</Section>
{!!zlevel.ruins.length && (
<Section title="Known Ruins">
<Stack vertical fill>
<LabeledList>
{zlevel.ruins
.toSorted((a, b) => a.name.localeCompare(b.name))
.map((ruin) => (
<LabeledList.Item
label={ruin.name}
buttons={<JumpToCoords coords={ruin.coords} />}
className="candystripe"
>
({ruin.coords.x},{ruin.coords.y},{ruin.coords.z})
</LabeledList.Item>
))}
</LabeledList>
</Stack>
</Section>
)}
</>
)}
</Stack.Item>
</Stack>
</Window.Content>
</Window>
);
};
File diff suppressed because one or more lines are too long