From f4a9cea05987f3c3a805415c19b1afae87ffb4a7 Mon Sep 17 00:00:00 2001 From: FalloutFalcon Date: Tue, 28 May 2024 12:51:18 -0500 Subject: [PATCH] simplification of behaviors --- code/__DEFINES/datacore.dm | 4 +- .../game/machinery/computer/record/medical.dm | 8 + .../game/machinery/computer/record/records.dm | 8 - .../machinery/computer/record/security.dm | 56 +++- .../interfaces/MedicalRecords/RecordTabs.tsx | 25 +- .../interfaces/MedicalRecords/RecordView.tsx | 28 +- .../tgui/interfaces/MedicalRecords/helpers.ts | 11 +- .../SecurityRecords/CrimeWatcher.tsx | 284 ------------------ .../interfaces/SecurityRecords/RecordTabs.tsx | 32 +- .../interfaces/SecurityRecords/RecordView.tsx | 108 +++---- .../interfaces/SecurityRecords/helpers.ts | 54 +--- .../tgui/interfaces/SecurityRecords/types.ts | 16 +- 12 files changed, 163 insertions(+), 471 deletions(-) delete mode 100644 tgui/packages/tgui/interfaces/SecurityRecords/CrimeWatcher.tsx diff --git a/code/__DEFINES/datacore.dm b/code/__DEFINES/datacore.dm index 3c61434ae757..7d55dda74d29 100644 --- a/code/__DEFINES/datacore.dm +++ b/code/__DEFINES/datacore.dm @@ -20,6 +20,8 @@ #define DATACORE_NOTES "notes" //#define DATACORE_NOTES_DETAILS "notes_d" +#define DATACORE_NOTES_SECURITY "security_note" +#define DATACORE_NOTES_MEDICAL "medical_note" #define DATACORE_RANK "rank" #define DATACORE_INITIAL_RANK "initial_rank" @@ -74,7 +76,7 @@ #define WANTED_SUSPECT "Suspected" /// List of available wanted statuses -#define WANTED_STATUSES(...) list(\ +#define WANTED_STATUSES list(\ WANTED_NONE, \ WANTED_SUSPECT, \ WANTED_ARREST, \ diff --git a/code/game/machinery/computer/record/medical.dm b/code/game/machinery/computer/record/medical.dm index 532aba0990f6..e4c3895b52d6 100644 --- a/code/game/machinery/computer/record/medical.dm +++ b/code/game/machinery/computer/record/medical.dm @@ -42,6 +42,14 @@ return data +/obj/machinery/computer/records/med/ui_static_data(mob/user) + var/list/data = list() + data["min_age"] = AGE_MIN + data["max_age"] = AGE_MAX + data["physical_statuses"] = PHYSICAL_STATUSES + data["mental_statuses"] = MENTAL_STATUSES + return data + /obj/machinery/computer/records/med/syndie icon_keyboard = "syndie_key" diff --git a/code/game/machinery/computer/record/records.dm b/code/game/machinery/computer/record/records.dm index 1a4532a33177..e41098197681 100644 --- a/code/game/machinery/computer/record/records.dm +++ b/code/game/machinery/computer/record/records.dm @@ -25,14 +25,6 @@ insert_new_record(user, attacking_item) */ -/obj/machinery/computer/records/ui_static_data(mob/user) - var/list/data = list() - data["min_age"] = AGE_MIN - data["max_age"] = AGE_MAX - data["physical_statuses"] = PHYSICAL_STATUSES - data["mental_statuses"] = MENTAL_STATUSES - return data - /obj/machinery/computer/records/ui_data(mob/user) var/list/data = ..() diff --git a/code/game/machinery/computer/record/security.dm b/code/game/machinery/computer/record/security.dm index da2c48ddee29..29d8f9e2164d 100644 --- a/code/game/machinery/computer/record/security.dm +++ b/code/game/machinery/computer/record/security.dm @@ -17,10 +17,9 @@ ui.set_autoupdate(FALSE) ui.open() -/obj/machinery/computer/records/med/ui_data(mob/user) +/obj/machinery/computer/records/sec/ui_data(mob/user) var/list/data = ..() - data["available_statuses"] = WANTED_STATUSES() data["current_user"] = user.name var/list/records = list() @@ -43,12 +42,65 @@ rank = target.fields[DATACORE_RANK], species = target.fields[DATACORE_SPECIES], wanted_status = target.fields[DATACORE_CRIMINAL_STATUS], + security_note = target.fields[DATACORE_NOTES_SECURITY], )) data["records"] = records return data +/obj/machinery/computer/records/sec/ui_static_data(mob/user) + var/list/data = list() + data["min_age"] = AGE_MIN + data["max_age"] = AGE_MAX + data["available_statuses"] = WANTED_STATUSES + return data + +/obj/machinery/computer/records/sec/ui_act(action, list/params, datum/tgui/ui) + . = ..() + if(.) + return + + var/mob/user = ui.user + + var/datum/data/record/target + if(params["record_ref"]) + target = locate(params["record_ref"]) in SSdatacore.get_records(linked_ship) + + if(!target) + return FALSE + + switch(action) + if("add_crime") + //add_crime(user, target, params) + return TRUE + + if("edit_crime") + //edit_crime(user, target, params) + return TRUE + + if("invalidate_crime") + //invalidate_crime(user, target, params) + return TRUE + + if("set_note") + var/note = trim(params["security_note"], MAX_MESSAGE_LEN) + investigate_log("[user] has changed the security note of record: \"[target]\" from \"[target.fields[DATACORE_NOTES_SECURITY]]\" to \"[note]\".") + target.fields[DATACORE_NOTES_SECURITY] = note + return TRUE + + if("set_wanted_status") + var/wanted_status = params["wanted_status"] + if(!wanted_status || !(wanted_status in WANTED_STATUSES)) + return FALSE + + investigate_log("[target.name] has been set from [target.fields[DATACORE_CRIMINAL_STATUS]] to [wanted_status] by [key_name(usr)].", INVESTIGATE_RECORDS) + target.fields[DATACORE_CRIMINAL_STATUS] = wanted_status + + return TRUE + + return FALSE + /obj/machinery/computer/records/sec/syndie icon_keyboard = "syndie_key" diff --git a/tgui/packages/tgui/interfaces/MedicalRecords/RecordTabs.tsx b/tgui/packages/tgui/interfaces/MedicalRecords/RecordTabs.tsx index 62c90660390f..d9cc1bae598c 100644 --- a/tgui/packages/tgui/interfaces/MedicalRecords/RecordTabs.tsx +++ b/tgui/packages/tgui/interfaces/MedicalRecords/RecordTabs.tsx @@ -5,9 +5,6 @@ import { useBackend, useLocalState } from 'tgui/backend'; import { Box, Button, - Icon, - Input, - NoticeBox, Section, Stack, Tabs, @@ -18,13 +15,14 @@ import { MedicalRecord, MedicalRecordData } from './types'; /** Displays all found records. */ export const MedicalRecordTabs = (props, context) => { const { act, data } = useBackend(context); + const { records = [] } = data; return (
- {data.records.map((record, index) => ( + {records.map((record, index) => ( ))} @@ -38,8 +36,7 @@ export const MedicalRecordTabs = (props, context) => { onClick={() => act('new_record')} icon="plus" tooltip="New Record." - > - + > { /** Individual crew tab */ const CrewTab = (props: { record: MedicalRecord }, context) => { - const [selectedRecord, setSelectedRecord] = useLocalState( - context, - 'medicalRecord', - undefined - ); +const [selectedRecord, setSelectedRecord] = useLocalState< + MedicalRecord | undefined + >(context, 'medicalRecord', undefined); const { act, data } = useBackend(context); const { assigned_view } = data; @@ -81,13 +76,17 @@ const CrewTab = (props: { record: MedicalRecord }, context) => { } }; + const isSelected = selectedRecord?.record_ref === record_ref; + return ( selectRecord(record)} - selected={selectedRecord?.record_ref === record_ref} + selected={isSelected} > - {name} + + {name} + ); }; diff --git a/tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx b/tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx index 3df7bb6d0200..c909fc62dfe8 100644 --- a/tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx +++ b/tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx @@ -52,15 +52,20 @@ export const MedicalRecordView = (props, context) => {
act('expunge_record', { record_ref: record_ref })} - tooltip="Expunge record data." - /> + + + + act('delete_record', { record_ref: record_ref }) + } + tooltip="Delete record data." + /> + + } fill - scrollable title={name} > @@ -119,7 +124,7 @@ export const MedicalRecordView = (props, context) => { return ( @@ -149,7 +155,6 @@ export const MedicalRecordView = (props, context) => { return ( diff --git a/tgui/packages/tgui/interfaces/MedicalRecords/helpers.ts b/tgui/packages/tgui/interfaces/MedicalRecords/helpers.ts index 8b4318e59750..a5606c9be822 100644 --- a/tgui/packages/tgui/interfaces/MedicalRecords/helpers.ts +++ b/tgui/packages/tgui/interfaces/MedicalRecords/helpers.ts @@ -2,11 +2,6 @@ import { useBackend, useLocalState } from 'tgui/backend'; import { MedicalRecord, MedicalRecordData } from './types'; -/** Splits a medical string on
into a string array */ -export const getQuirkStrings = (string: string) => { - return string?.split('
') || []; -}; - /** We need an active reference and this a pain to rewrite */ export const getMedicalRecord = (props, context) => { const [selectedRecord, SetRecord] = useLocalState( @@ -14,6 +9,7 @@ export const getMedicalRecord = (props, context) => { 'medicalRecord', '' ); + if (!selectedRecord) return; const { data } = useBackend(context); const { records = [] } = data; const foundRecord = records.find( @@ -23,3 +19,8 @@ export const getMedicalRecord = (props, context) => { return foundRecord; }; + +/** Splits a medical string on
into a string array */ +export const getQuirkStrings = (string: string) => { + return string?.split('
') || []; +}; diff --git a/tgui/packages/tgui/interfaces/SecurityRecords/CrimeWatcher.tsx b/tgui/packages/tgui/interfaces/SecurityRecords/CrimeWatcher.tsx deleted file mode 100644 index f5f0c7323b47..000000000000 --- a/tgui/packages/tgui/interfaces/SecurityRecords/CrimeWatcher.tsx +++ /dev/null @@ -1,284 +0,0 @@ -import { useBackend, useLocalState } from 'tgui/backend'; -import { - BlockQuote, - Box, - Button, - Collapsible, - Icon, - Input, - LabeledList, - NoticeBox, - RestrictedInput, - Section, - Stack, - Tabs, - TextArea, - Tooltip, -} from 'tgui/components'; - -import { getSecurityRecord } from './helpers'; -import { Crime, SECURETAB, SecurityRecordsData } from './types'; - -/** Displays a list of crimes and allows to add new ones. */ -export const CrimeWatcher = (props, context) => { - const foundRecord = getSecurityRecord(); - if (!foundRecord) return <> ; - - const { crimes, citations } = foundRecord; - const [selectedTab, setSelectedTab] = useLocalState( - context, - 'selectedTab', - SECURETAB.Crimes - ); - - return ( - - - - setSelectedTab(SECURETAB.Crimes)} - selected={selectedTab === SECURETAB.Crimes} - > - Crimes: {crimes.length} - - setSelectedTab(SECURETAB.Citations)} - selected={selectedTab === SECURETAB.Citations} - > - Citations: {citations.length} - - - setSelectedTab(SECURETAB.Add)} - selected={selectedTab === SECURETAB.Add} - > - - - - - - -
- {selectedTab < SECURETAB.Add ? ( - - ) : ( - - )} -
-
-
- ); -}; - -/** Displays the crimes and citations of a record. */ -const CrimeList = (props) => { - const foundRecord = getSecurityRecord(); - if (!foundRecord) return <> ; - - const { citations, crimes } = foundRecord; - const { tab } = props; - const toDisplay = tab === SECURETAB.Crimes ? crimes : citations; - - return ( - - {!toDisplay.length ? ( - - - No {tab === SECURETAB.Crimes ? 'crimes' : 'citations'} found. - - - ) : ( - toDisplay.map((item, index) => ) - )} - - ); -}; - -/** Displays an individual crime */ -const CrimeDisplay = (props, context, { item }: { item: Crime }) => { - const foundRecord = getSecurityRecord(props, context); - if (!foundRecord) return <> ; - - const { crew_ref } = foundRecord; - const { act, data } = useBackend(context); - const { current_user, higher_access } = data; - const { author, crime_ref, details, fine, name, paid, time, valid } = item; - const showFine = !!fine && fine > 0 ? `: ${fine} cr` : ''; - - let collapsibleColor = ''; - if (!valid) { - collapsibleColor = 'grey'; - } else if (fine && fine > 0) { - collapsibleColor = 'average'; - } - - let displayTitle = name; - if (fine && fine > 0) { - displayTitle = name.slice(0, 18) + showFine; - } - - const [editing, setEditing] = useLocalState(`editing_${crime_ref}`, false); - - return ( - - - - {time} - {author} - - {!valid ? 'Void' : 'Active'} - - {fine && ( - <> - - {fine}cr - - - {paid}cr - - - )} - - - Details: - -
{details}
- - {!editing ? ( - - - - act('invalidate_crime', { - crew_ref: crew_ref, - crime_ref: crime_ref, - }) - } - /> - - ) : ( - <> - setEditing(false)} - onEnter={(event, value) => { - setEditing(false); - act('edit_crime', { - crew_ref: crew_ref, - crime_ref: crime_ref, - name: value, - }); - }} - placeholder="Enter a new name" - /> - setEditing(false)} - onEnter={(event, value) => { - setEditing(false); - act('edit_crime', { - crew_ref: crew_ref, - crime_ref: crime_ref, - description: value, - }); - }} - placeholder="Enter a new description" - /> - - )} -
-
- ); -}; - -/** Writes a new crime. Reducers don't seem to work here, so... */ -const CrimeAuthor = (props) => { - const foundRecord = getSecurityRecord(); - if (!foundRecord) return <> ; - - const { crew_ref } = foundRecord; - const { act } = useBackend(); - - const [crimeName, setCrimeName] = useState(''); - const [crimeDetails, setCrimeDetails] = useState(''); - const [crimeFine, setCrimeFine] = useState(0); - const [selectedTab, setSelectedTab] = useLocalState( - 'selectedTab', - SECURETAB.Crimes - ); - - const nameMeetsReqs = crimeName?.length > 2; - - /** Sends form to backend */ - const createCrime = () => { - if (!crimeName) return; - act('add_crime', { - crew_ref: crew_ref, - details: crimeDetails, - fine: crimeFine, - name: crimeName, - }); - reset(); - }; - - /** Resets form data since it persists.. */ - const reset = () => { - setCrimeDetails(''); - setCrimeFine(0); - setCrimeName(''); - setSelectedTab(crimeFine ? SECURETAB.Citations : SECURETAB.Crimes); - }; - - return ( - - - Name - setCrimeName(value)} - placeholder="Brief overview" - /> - - - Details -