Skip to content

Commit

Permalink
simplification of behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed May 28, 2024
1 parent 9ea5e32 commit f4a9cea
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 471 deletions.
4 changes: 3 additions & 1 deletion code/__DEFINES/datacore.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, \
Expand Down
8 changes: 8 additions & 0 deletions code/game/machinery/computer/record/medical.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 0 additions & 8 deletions code/game/machinery/computer/record/records.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ..()

Expand Down
56 changes: 54 additions & 2 deletions code/game/machinery/computer/record/security.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"

Expand Down
25 changes: 12 additions & 13 deletions tgui/packages/tgui/interfaces/MedicalRecords/RecordTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { useBackend, useLocalState } from 'tgui/backend';
import {
Box,
Button,
Icon,
Input,
NoticeBox,
Section,
Stack,
Tabs,
Expand All @@ -18,13 +15,14 @@ import { MedicalRecord, MedicalRecordData } from './types';
/** Displays all found records. */
export const MedicalRecordTabs = (props, context) => {
const { act, data } = useBackend<MedicalRecordData>(context);
const { records = [] } = data;

return (
<Stack fill vertical>
<Stack.Item grow>
<Section fill scrollable>
<Tabs vertical>
{data.records.map((record, index) => (
{records.map((record, index) => (
<CrewTab key={index} record={record} />
))}
</Tabs>
Expand All @@ -38,8 +36,7 @@ export const MedicalRecordTabs = (props, context) => {
onClick={() => act('new_record')}
icon="plus"
tooltip="New Record."
>
</Button>
></Button>
</Stack.Item>
<Stack.Item>
<Button.Confirm
Expand All @@ -57,11 +54,9 @@ export const MedicalRecordTabs = (props, context) => {

/** 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;
Expand All @@ -81,13 +76,17 @@ const CrewTab = (props: { record: MedicalRecord }, context) => {
}
};

const isSelected = selectedRecord?.record_ref === record_ref;

return (
<Tabs.Tab
className="candystripe"
onClick={() => selectRecord(record)}
selected={selectedRecord?.record_ref === record_ref}
selected={isSelected}
>
{name}
<Box bold={isSelected}>
{name}
</Box>
</Tabs.Tab>
);
};
28 changes: 17 additions & 11 deletions tgui/packages/tgui/interfaces/MedicalRecords/RecordView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ export const MedicalRecordView = (props, context) => {
<Stack.Item grow>
<Section
buttons={
<Button.Confirm
content="Delete"
icon="trash"
onClick={() => act('expunge_record', { record_ref: record_ref })}
tooltip="Expunge record data."
/>
<Stack>
<Stack.Item>
<Button.Confirm
content="Delete"
icon="trash"
onClick={() =>
act('delete_record', { record_ref: record_ref })
}
tooltip="Delete record data."
/>
</Stack.Item>
</Stack>
}
fill
scrollable
title={name}
>
<LabeledList>
Expand Down Expand Up @@ -119,7 +124,7 @@ export const MedicalRecordView = (props, context) => {
return (
<Button
color={isSelected ? PHYSICALSTATUS2COLOR[button] : 'grey'}
height={'1.75rem'}

icon={PHYSICALSTATUS2ICON[button]}
key={index}
onClick={() =>
Expand All @@ -128,10 +133,11 @@ export const MedicalRecordView = (props, context) => {
physical_status: button,
})
}
height={'1.75rem'}
width={!isSelected ? '3.0rem' : 3.0}
textAlign="center"
tooltip={PHYSICALSTATUS2DESC[button] || ''}
tooltipPosition="bottom-start"
width={!isSelected ? '3.0rem' : 3.0}
>
{button[0]}
</Button>
Expand All @@ -149,7 +155,6 @@ export const MedicalRecordView = (props, context) => {
return (
<Button
color={isSelected ? MENTALSTATUS2COLOR[button] : 'grey'}
height={'1.75rem'}
icon={MENTALSTATUS2ICON[button]}
key={index}
onClick={() =>
Expand All @@ -158,10 +163,11 @@ export const MedicalRecordView = (props, context) => {
mental_status: button,
})
}
height={'1.75rem'}
width={!isSelected ? '3.0rem' : 3.0}
textAlign="center"
tooltip={MENTALSTATUS2DESC[button] || ''}
tooltipPosition="bottom-start"
width={!isSelected ? '3.0rem' : 3.0}
>
{button[0]}
</Button>
Expand Down
11 changes: 6 additions & 5 deletions tgui/packages/tgui/interfaces/MedicalRecords/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ import { useBackend, useLocalState } from 'tgui/backend';

import { MedicalRecord, MedicalRecordData } from './types';

/** Splits a medical string on <br> into a string array */
export const getQuirkStrings = (string: string) => {
return string?.split('<br>') || [];
};

/** We need an active reference and this a pain to rewrite */
export const getMedicalRecord = (props, context) => {
const [selectedRecord, SetRecord] = useLocalState<MedicalRecord>(
context,
'medicalRecord',
''
);
if (!selectedRecord) return;
const { data } = useBackend<MedicalRecord>(context);
const { records = [] } = data;
const foundRecord = records.find(
Expand All @@ -23,3 +19,8 @@ export const getMedicalRecord = (props, context) => {

return foundRecord;
};

/** Splits a medical string on <br> into a string array */
export const getQuirkStrings = (string: string) => {
return string?.split('<br>') || [];
};
Loading

0 comments on commit f4a9cea

Please sign in to comment.