Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire alarm TGUI #19139

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 64 additions & 84 deletions code/game/machinery/firealarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
///looping sound datum for our fire alarm siren.
var/datum/looping_sound/firealarm/soundloop

/obj/machinery/firealarm/Initialize(mapload, ndir = 0, building)
. = ..(mapload, ndir)

update_icon()

if(isContactLevel(z))
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(set_security_level), (GLOB.security_level ? get_security_level() : "green"))

soundloop = new(src, FALSE)

var/area/A = get_area(src)
RegisterSignal(A, COMSIG_AREA_FIRE_ALARM, TYPE_PROC_REF(/atom, update_icon))

if(!mapload)
set_pixel_offsets()

/obj/machinery/firealarm/Destroy()
QDEL_NULL(soundloop)
. = ..()

/obj/machinery/firealarm/get_examine_text(mob/user, distance, is_adjacent, infix, suffix)
. = ..()
if((stat & (NOPOWER|BROKEN)) || buildstage != 2)
Expand Down Expand Up @@ -136,7 +156,7 @@

src.alarm()

/obj/machinery/firealarm/process()//Note: this processing was mostly phased out due to other code, and only runs when needed
/obj/machinery/firealarm/process(seconds_per_tick)//Note: this processing was mostly phased out due to other code, and only runs when needed
if(stat & (NOPOWER|BROKEN))
return

Expand All @@ -149,51 +169,66 @@
timing = FALSE
. = PROCESS_KILL
else
src.time = src.time - ((world.timeofday - last_process) / 10)

updateDialog()
src.time = src.time - (((world.timeofday - last_process) / 10) * seconds_per_tick)

last_process = world.timeofday

/obj/machinery/firealarm/power_change()
..()
queue_icon_update()

/obj/machinery/firealarm/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/ui_state/state = GLOB.default_state)
var/data[0]
/obj/machinery/firealarm/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "FireAlarm")
ui.open()

/obj/machinery/firealarm/attack_hand(mob/user as mob)
if (buildstage != 2 || stat & (NOPOWER|BROKEN))
return

if(user.a_intent == I_HURT)
alarm()
else
ui_interact(user)

/obj/machinery/firealarm/ui_data(mob/user)
var/list/data = list()

data["alertLevel"] = get_security_level()
data["time"] = src.time

var/area/A = get_area(src)
data["active"] = A.fire

ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "firealarm.tmpl", "Fire Alarm", 325, 325, state = state)
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
data["timing"] = src.timing

/obj/machinery/firealarm/attack_hand(mob/user as mob)
if (buildstage != 2 || stat & (NOPOWER|BROKEN))
return data

/obj/machinery/firealarm/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return

ui_interact(user)
return
switch(action)
if("activate_alarm")
src.alarm()
if("reset_alarm")
src.reset()
if("set_timer")
var/input_time = text2num(params["set_timer"])
if(!isnum(input_time))
return

/obj/machinery/firealarm/Topic(href, href_list)
..()
time = Clamp(input_time SECONDS, 1, 600)

if("start_timer")
src.timing = 1
START_PROCESSING_MACHINE(src, MACHINERY_PROCESS_SELF)
if("stop_timer")
src.timing = 0

if (href_list["state"] == "active")
src.alarm()
else if (href_list["state"] == "inactive")
src.reset()
if (href_list["tmr"] == "set")
time = Clamp(input(usr, "Enter time delay", "Fire Alarm Delayed Activation", time) as num, 0, 600)
else if (href_list["tmr"] == "start")
src.timing = 1
START_PROCESSING_MACHINE(src, MACHINERY_PROCESS_SELF)
else if (href_list["tmr"] == "stop")
src.timing = 0
return TRUE

/obj/machinery/firealarm/proc/reset()
if (!( src.working ))
Expand All @@ -219,26 +254,6 @@
if(seclevel != new_security_level)
seclevel = new_security_level

/obj/machinery/firealarm/Initialize(mapload, ndir = 0, building)
. = ..(mapload, ndir)

update_icon()

if(isContactLevel(z))
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(set_security_level), (GLOB.security_level ? get_security_level() : "green"))

soundloop = new(src, FALSE)

var/area/A = get_area(src)
RegisterSignal(A, COMSIG_AREA_FIRE_ALARM, TYPE_PROC_REF(/atom, update_icon))

if(!mapload)
set_pixel_offsets()

/obj/machinery/firealarm/Destroy()
QDEL_NULL(soundloop)
. = ..()

/obj/machinery/firealarm/set_pixel_offsets()
// Overwrite the mapped in values.
pixel_x = ((dir & (NORTH|SOUTH)) ? 0 : (dir == EAST ? 22 : -22))
Expand Down Expand Up @@ -272,38 +287,3 @@ Just a object used in constructing fire alarms
desc = "A circuit. It has a label on it, it says \"Can handle heat levels up to 40 degrees celsius!\""
w_class = ITEMSIZE_SMALL
matter = list(DEFAULT_WALL_MATERIAL = 50, MATERIAL_GLASS = 50)


/obj/machinery/firealarm/partyalarm
name = "\improper PARTY BUTTON"
desc = "Cuban Pete is in the house!"

/obj/machinery/firealarm/partyalarm/alarm(var/duration = 0)
if (!( working ))
return
var/area/A = get_area(src)
ASSERT(isarea(A))
A.partyalert()
return

/obj/machinery/firealarm/partyalarm/reset()
if (!( working ))
return
var/area/A = get_area(src)
ASSERT(isarea(A))
A.partyreset()
return

/obj/machinery/firealarm/partyalarm/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/ui_state/state = GLOB.default_state)
var/data[0]
data["alertLevel"] = get_security_level()
data["time"] = src.time
var/area/A = get_area(src)
data["active"] = A.party

ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "partyalarm.tmpl", "PARTY ALARM", 325, 325, state = state)
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
59 changes: 59 additions & 0 deletions html/changelogs/fluffyghost-firealarmtgui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# - (fixes bugs)
# wip
# - (work in progress)
# qol
# - (quality of life)
# soundadd
# - (adds a sound)
# sounddel
# - (removes a sound)
# rscadd
# - (adds a feature)
# rscdel
# - (removes a feature)
# imageadd
# - (adds an image or sprite)
# imagedel
# - (removes an image or sprite)
# spellcheck
# - (fixes spelling or grammar)
# experiment
# - (experimental change)
# balance
# - (balance changes)
# code_imp
# - (misc internal code change)
# refactor
# - (refactors code)
# config
# - (makes a change to the config files)
# admin
# - (makes changes to administrator tools)
# server
# - (miscellaneous changes to server)
#################################

# Your name.
author: FluffyGhost

# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True

# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit.
# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog.
changes:
- rscadd: "Attacking a fire alarm with harm intent will trigger the fire alarm."
- refactor: "Refactored fire alarms from NanoUI to TGUI."
27 changes: 0 additions & 27 deletions nano/templates/firealarm.tmpl

This file was deleted.

56 changes: 56 additions & 0 deletions tgui/packages/tgui/interfaces/FireAlarm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { BooleanLike } from '../../common/react';
import { useBackend } from '../backend';
import { Section, Button, Box } from '../components';
import { Window } from '../layouts';

export type FireAlarmData = {
alertLevel: String;
time: number;
active: BooleanLike;
timing: BooleanLike;
};

export const FireAlarm = (props, context) => {
const { act, data } = useBackend<FireAlarmData>(context);
return (
<Window resizable theme="hephaestus" title="Fire Alarm">
<Window.Content scrollable>
<Section title="Alert Level">
{data.alertLevel.toLocaleUpperCase()}
</Section>
<Section title="Fire Alarm Control">
<Button onClick={() => act('activate_alarm')} disabled={data.active}>
Activate
</Button>
<Button onClick={() => act('reset_alarm')} disabled={!data.active}>
Reset
</Button>
</Section>
<Section title="Timed Lockdown">
<Box title="Current Timer">
{data.time > 1
? (data.time / 10).toFixed(0).toString() + ' seconds'
: 'Not Set'}
</Box>
<Button.Input
content="Set Activation Timer"
onCommit={(e, value) => {
act('set_timer', {
set_timer: value,
});
}}
/>
<br />
<Button
onClick={() => act('start_timer')}
disabled={data.timing || !data.time}>
Start Timer
</Button>
<Button onClick={() => act('stop_timer')} disabled={!data.timing}>
Stop Timer
</Button>
</Section>
</Window.Content>
</Window>
);
};
Loading