Skip to content

Commit

Permalink
adds a medal viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Dec 7, 2023
1 parent 8a462cf commit c68580f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
14 changes: 12 additions & 2 deletions code/game/verbs/records.dm
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@

GLOBAL_DATUM_INIT(medals_view_tgui, /datum/medals_view_tgui, new)

GLOBAL_SUBTYPE_PATHS_LIST_INDEXED(all_medals, /obj/item/clothing/accessory/medal, name)

/datum/medals_view_tgui/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
Expand All @@ -195,18 +197,26 @@ GLOBAL_DATUM_INIT(medals_view_tgui, /datum/medals_view_tgui, new)
.["medals"] = list()

for(var/datum/view_record/medal_view/medal as anything in DB_VIEW(/datum/view_record/medal_view, DB_COMP("player_id"), DB_EQUALS, user.client.player_data.id))
.["medals"] += list(
var/list/current_medal = list(
"round_id" = medal.round_id,
"medal_type" = medal.medal_type,
"medal_icon" = replacetext(medal.medal_type, " ", "-"),
"recipient_name" = medal.recipient_name,
"recipient_role" = medal.recipient_role,
"giver_name" = medal.giver_name,
"citation" = medal.citation
)

/datum/medals_view_tgui/ui_status(mob/user, datum/ui_state/state)
.["medals"] += list(current_medal)

/datum/medals_view_tgui/ui_state(mob/user)
return GLOB.always_state

/datum/medals_view_tgui/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/spritesheet/medal)
)

/client/verb/view_own_medals()
set name = "View Own Medals"
set category = "OOC.Records"
Expand Down
10 changes: 10 additions & 0 deletions code/modules/asset_cache/assets/medals.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/datum/asset/spritesheet/medal
name = "medal"

/datum/asset/spritesheet/medal/register()
for(var/obj/item/clothing/accessory/medal/medal as anything in subtypesof(/obj/item/clothing/accessory/medal))
var/icon/current_icon = icon(initial(medal.icon), initial(medal.icon_state), SOUTH)
var/imgid = replacetext("[initial(medal.name)]", " ", "-")

Insert(imgid, current_icon)
return ..()
1 change: 1 addition & 0 deletions colonialmarines.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@
#include "code\modules\asset_cache\asset_list.dm"
#include "code\modules\asset_cache\asset_list_items.dm"
#include "code\modules\asset_cache\assets\fontawesome.dm"
#include "code\modules\asset_cache\assets\medals.dm"
#include "code\modules\asset_cache\assets\tgfont.dm"
#include "code\modules\asset_cache\assets\tgui.dm"
#include "code\modules\asset_cache\assets\vending.dm"
Expand Down
41 changes: 27 additions & 14 deletions tgui/packages/tgui/interfaces/MedalsViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { classes } from 'common/react';
import { useBackend } from '../backend';
import { Flex } from '../components';
import { Section } from '../components';
import { Window } from '../layouts';

interface MedalProps {
Expand All @@ -9,6 +10,7 @@ interface MedalProps {
interface Medal {
round_id: string;
medal_type?: string;
medal_icon?: string;
recipient_name?: string;
recipient_role?: string;
giver_name?: string;
Expand All @@ -20,20 +22,31 @@ export const MedalsViewer = (props, context) => {
const { medals } = data;

return (
<Window width={350} height={350}>
<Window width={700} height={350}>
<Window.Content scrollable>
<Flex direction="column">
{medals.map((medal) => {
return (
<Flex.Item key={medal.citation}>
{medal.round_id}: {medal.medal_type} issued to{' '}
{medal.recipient_name} ({medal.recipient_role}) by{' '}
{medal.giver_name} for: <br />
{medal.citation}
</Flex.Item>
);
})}
</Flex>
{medals.map((medal) => {
const medalType = medal.medal_type
? medal.medal_type
: 'Unknown Medal';
const sectionTitle = `Round ${medal.round_id} - ${medalType}`;
return (
<Section key={medal.citation} title={sectionTitle}>
Issued to{' '}
<b>
{medal.recipient_name} ({medal.recipient_role})
</b>{' '}
by <b>{medal.giver_name}</b> for: <br />
<span
className={classes([
'medal32x32',
medal.medal_icon,
'medal-icon',
])}
/>
{medal.citation}
</Section>
);
})}
</Window.Content>
</Window>
);
Expand Down
3 changes: 3 additions & 0 deletions tgui/packages/tgui/styles/interfaces/MedalsViewer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.medal-icon {
vertical-align: -50%;
}
1 change: 1 addition & 0 deletions tgui/packages/tgui/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@include meta.load-css('./interfaces/ElevatorControl.scss');
@include meta.load-css('./interfaces/ExperimentConfigure.scss');
@include meta.load-css('./interfaces/MarkMenu.scss');
@include meta.load-css('./interfaces/MedalsViewer.scss');
@include meta.load-css('./interfaces/NavigationShuttle.scss');
@include meta.load-css('./interfaces/NuclearBomb.scss');
@include meta.load-css('./interfaces/Paper.scss');
Expand Down

0 comments on commit c68580f

Please sign in to comment.