Skip to content

Commit a01e9d0

Browse files
committed
Loadout shop now uses DMIcon
1 parent 4427a98 commit a01e9d0

File tree

4 files changed

+49
-38
lines changed

4 files changed

+49
-38
lines changed

monkestation/code/modules/asset_cache/assets/loadout_store.dm

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
if(!store_item::name || !store_item::item_path)
88
continue
99
var/obj/item_type = store_item::item_path
10+
if(!should_generate_icon(item_type))
11+
continue
1012
var/id = sanitize_css_class_name("[item_type]")
1113
if(id_list[id])
1214
continue
13-
var/icon/item_icon = generate_icon_for_item(item_type)
15+
var/icon/item_icon = icon(SSgreyscale.GetColoredIconByType(item_type::greyscale_config, item_type::greyscale_colors), item_type::icon_state)
1416
if(!item_icon)
1517
stack_trace("Failed to generate icon for [item_type]")
1618
continue
@@ -20,29 +22,9 @@
2022
Insert(id, item_icon)
2123
id_list[id] = TRUE
2224

23-
/datum/asset/spritesheet/loadout_store/proc/generate_icon_for_item(obj/item/item) as /icon
24-
RETURN_TYPE(/icon)
25-
var/icon_file = item::icon_preview || item::icon
26-
var/icon_state = item::icon_state_preview || item::icon_state
27-
var/has_gags_config = item::greyscale_config && item::greyscale_colors
28-
var/has_preview_icon = item::icon_preview && item::icon_state_preview
29-
if(has_gags_config && !has_preview_icon) // preview icons take priority over GAGS
30-
var/icon/gags_icon = SSgreyscale.GetColoredIconByType(item::greyscale_config, item::greyscale_colors)
31-
return icon(gags_icon, item::icon_state)
32-
else if(icon_exists(icon_file, icon_state))
33-
var/icon/item_icon = icon(
34-
icon_file,
35-
icon_state,
36-
dir = SOUTH,
37-
frame = 1,
38-
moving = FALSE,
39-
)
40-
return icon(fcopy_rsc(item_icon))
41-
else
42-
var/obj/item/dummy_item = new item
43-
var/icon/flat_icon = getFlatIcon(dummy_item)
44-
if(!flat_icon)
45-
CRASH("Failed to generate any icon for [item]")
46-
var/icon/cached_icon = icon(fcopy_rsc(flat_icon))
47-
qdel(dummy_item)
48-
return cached_icon
25+
/datum/asset/spritesheet/loadout_store/proc/should_generate_icon(obj/item/item)
26+
if(item::icon_preview && item::icon_state_preview)
27+
return FALSE
28+
if(item::greyscale_config && item::greyscale_colors)
29+
return TRUE
30+
return FALSE

monkestation/code/modules/store/store_items/__store.dm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,21 @@ GLOBAL_LIST_EMPTY(all_store_datums)
182182
if(item.hidden)
183183
formatted_list.len--
184184
continue
185+
var/obj/item/item_type = item.item_path
185186
var/list/formatted_item = list(
186187
"name" = item.name,
187188
"path" = item.item_path,
188189
"cost" = item.item_cost,
189-
"desc" = item.item_path::desc,
190-
"icon" = sanitize_css_class_name("[item.item_path]"),
190+
"desc" = item_type::desc,
191191
"job_restricted" = null,
192192
)
193+
if((item_type::icon_preview && item_type::icon_state_preview) || !(item_type::greyscale_config && item_type::greyscale_colors))
194+
formatted_item["icon"] = item_type::icon_preview || item_type::icon
195+
formatted_item["icon_state"] = item_type::icon_state_preview || item_type::icon_state
196+
else
197+
formatted_item["icon"] = sanitize_css_class_name("[item_type]")
193198

194-
var/datum/loadout_item/selected = GLOB.all_loadout_datums[item.item_path]
199+
var/datum/loadout_item/selected = GLOB.all_loadout_datums[item_type]
195200
if(length(selected?.restricted_roles))
196201
formatted_item["job_restricted"] = selected.restricted_roles.Join(", ")
197202

tgui/packages/tgui/interfaces/PreferencesMenu/data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ type LoadoutData = {
195195
type LoadoutItem = {
196196
name: string;
197197
icon: string;
198+
icon_state?: string;
198199
desc: string;
199200
cost: number;
200201
item_path: string;

tgui/packages/tgui/interfaces/StoreManager.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { useBackend, useSharedState } from '../backend';
2-
import { Box, Button, Section, Stack, Tabs, Table } from '../components';
2+
import {
3+
Box,
4+
Button,
5+
DmIcon,
6+
Section,
7+
Stack,
8+
Tabs,
9+
Table,
10+
Icon,
11+
} from '../components';
312
import { PreferencesMenuData } from './PreferencesMenu/data';
413
import { Window } from '../layouts';
514
import { classes } from 'common/react';
@@ -69,13 +78,27 @@ export const StoreManager = (props) => {
6978
backgroundColor={index % 2 === 0 ? '#19181e' : '#16151b'}
7079
>
7180
<Table.Cell>
72-
<Box
73-
inline
74-
verticalAlign="middle"
75-
width={'32px'}
76-
height={'32px'}
77-
className={classes(['loadout_store32x32', item.icon])}
78-
/>
81+
{item.icon && item.icon_state ? (
82+
<DmIcon
83+
icon={item.icon}
84+
icon_state={item.icon_state}
85+
verticalAlign="middle"
86+
height={'32px'}
87+
width={'32px'}
88+
fallback={<Icon name="spinner" size={2} spin />}
89+
/>
90+
) : (
91+
<Box
92+
inline
93+
verticalAlign="middle"
94+
width={'32px'}
95+
height={'32px'}
96+
className={classes([
97+
'loadout_store32x32',
98+
item.icon,
99+
])}
100+
/>
101+
)}
79102
</Table.Cell>
80103
<Table.Cell>
81104
<Button

0 commit comments

Comments
 (0)