Skip to content

Commit

Permalink
Loadout Fixes (#28540)
Browse files Browse the repository at this point in the history
* wee

* I am so smart

* It werks

---------

Co-authored-by: Waterpig <[email protected]>
Co-authored-by: Waterpig <[email protected]>
  • Loading branch information
3 people committed Jul 2, 2024
1 parent 37afcb5 commit ad15317
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 18 deletions.
6 changes: 1 addition & 5 deletions code/modules/loadout/loadout_categories.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@
return all_items

/// Returns a list of all /datum/loadout_items in this category, formatted for UI use. Only ran once.
/datum/loadout_category/proc/items_to_ui_data(client/user) as /list // SKYRAT EDIT CHANGE - Added user poaram
/datum/loadout_category/proc/items_to_ui_data() as /list
if(!length(associated_items))
return list()

var/list/formatted_list = list()

for(var/datum/loadout_item/item as anything in associated_items)
// SKYRAT EDIT ADDITION
if(item.ckeywhitelist && !(user?.ckey in item.ckeywhitelist))
continue
// SKYRAT EDIT END
var/list/item_data = item.to_ui_data()
UNTYPED_LIST_ADD(formatted_list, item_data)

Expand Down
13 changes: 12 additions & 1 deletion code/modules/loadout/loadout_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GLOBAL_LIST_INIT(all_loadout_categories, init_loadout_categories())
var/can_be_greyscale = FALSE
/// Whether this item can be renamed.
/// I recommend you apply this sparingly becuase it certainly can go wrong (or get reset / overridden easily)
var/can_be_named = FALSE
var/can_be_named = TRUE // SKYRAT EDIT
/// Whether this item can be reskinned.
/// Only works if the item has a "unique reskin" list set.
var/can_be_reskinned = FALSE
Expand Down Expand Up @@ -315,6 +315,14 @@ GLOBAL_LIST_INIT(all_loadout_categories, init_loadout_categories())
formatted_item["reskins"] = get_reskin_options()
formatted_item["icon"] = ui_icon
formatted_item["icon_state"] = ui_icon_state

// SKYRAT EDIT BEGIN - Extra loadout stuff
formatted_item["ckey_whitelist"] = ckeywhitelist
formatted_item["donator_only"] = donator_only
formatted_item["restricted_roles"] = restricted_roles
formatted_item["blacklisted_roles"] = restricted_roles
// SKYRAT EDIT END

return formatted_item

/**
Expand Down Expand Up @@ -342,6 +350,9 @@ GLOBAL_LIST_INIT(all_loadout_categories, init_loadout_categories())
if(donator_only)
displayed_text += "Donator only"

if(ckeywhitelist)
displayed_text += "Unique"

if(restricted_roles || blacklisted_roles)
displayed_text += "Role restricted"

Expand Down
25 changes: 15 additions & 10 deletions code/modules/loadout/loadout_menu.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
continue
if(!item.category.handle_duplicate_entires(src, item, selected_item, loadout_datums))
return
// SKYRAT EDIT ADDITION
if(item.ckeywhitelist && !(preferences?.parent?.ckey in item.ckeywhitelist))
to_chat(preferences.parent, span_warning("You cannot select this item!"))
return
// SKYRAT EDIT ADDITION
if(!isnull(selected_item.ckeywhitelist) && !(preferences?.parent?.ckey in selected_item.ckeywhitelist))
to_chat(preferences.parent, span_warning("You cannot select this item!"))
return

if(item.donator_only && !GLOB.donator_list[preferences?.parent?.ckey])
to_chat(preferences.parent, span_warning("That item is for donators only."))
return
// SKYRAT EDIT END
if(!isnull(selected_item.donator_only) && !GLOB.donator_list[preferences?.parent?.ckey])
to_chat(preferences.parent, span_warning("This item is for donators only."))
return
// SKYRAT EDIT END

LAZYSET(loadout, selected_item.item_path, list())
preferences.update_preference(GLOB.preference_entries[/datum/preference/loadout], loadout)
Expand Down Expand Up @@ -111,6 +111,11 @@
/datum/preference_middleware/loadout/get_ui_static_data(mob/user)
var/list/data = list()
data["loadout_preview_view"] = preferences.character_preview_view.assigned_map
// SKYRAT EDIT START - EXPANDED LOADOUT
data["ckey"] = user.ckey
if(SSplayer_ranks.is_donator(user.client))
data["is_donator"] = TRUE
// SKYRAT EDIT END
return data

/datum/preference_middleware/loadout/get_constant_data()
Expand All @@ -121,8 +126,8 @@
"name" = category.category_name,
"category_icon" = category.category_ui_icon,
"category_info" = category.category_info,
"contents" = category.items_to_ui_data(preferences?.parent),
) // SKYRAT EDIT CHANGE - items_to_ui_data(preferences?.parent)
"contents" = category.items_to_ui_data(),
)
UNTYPED_LIST_ADD(loadout_tabs, cat_data)

data["loadout_tabs"] = loadout_tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
/datum/loadout_item/gloves/yellow
name = "Yellow Gloves"
item_path = /obj/item/clothing/gloves/color/ffyellow
additional_displayed_text = list("NON-INSULATING - This item is purely cosmetic and provide no shock insulation.")
additional_displayed_text = list("NON-INSULATING")

/datum/loadout_item/gloves/white
name = "White Gloves"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/datum/loadout_item/toys
abstract_type = /datum/loadout_item/toys
can_be_named = TRUE

/datum/loadout_item/toys/bee
name = "Bee Plushie"
Expand Down
2 changes: 2 additions & 0 deletions tgui/packages/tgui/interfaces/PreferencesMenu/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export type PreferencesMenuData = {
quirks_balance: number;
positive_quirk_count: number;
species_restricted_jobs?: string[];
ckey: string;
is_donator: BooleanLike;
// SKYRAT EDIT END
keybindings: Record<string, string[]>;
overflow_role: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ export const ItemDisplay = (props: {
{info}
</Box>
))}
{
// SKYRAT EDIT START - EXPANDED LOADOUT
<Flex.Item
ml={5.7}
mt={0.35}
style={{ position: 'absolute', bottom: 5, right: 5 }}
>
{ShouldDisplayJobRestriction(item) && ItemJobRestriction(item)}
{ShouldDisplayPlayerRestriction(item) &&
ItemPlayerRestriction(item)}
</Flex.Item>

/* SKYRAT EDIT END */
}
</Flex.Item>
)}
</Flex>
Expand All @@ -94,9 +108,10 @@ export const ItemDisplay = (props: {
const ItemListDisplay = (props: { items: LoadoutItem[] }) => {
const { data } = useBackend<LoadoutManagerData>();
const { loadout_list } = data.character_preferences.misc;
const itemList = FilterItemList(props.items); // SKYRAT EDIT - EXPANDED LOADOUT
return (
<Flex wrap>
{props.items.map((item) => (
{itemList.map((item /* SKYRAT EDIT : {props.items.map((item) => (*/) => (
<Flex.Item key={item.name} mr={2} mb={2}>
<ItemDisplay
item={item}
Expand All @@ -107,7 +122,90 @@ const ItemListDisplay = (props: { items: LoadoutItem[] }) => {
</Flex>
);
};
// SKYRAT EDIT START - EXPANDED LOADOUT
const FilterItemList = (items: LoadoutItem[]) => {
const { data } = useBackend<LoadoutManagerData>();
const { is_donator } = data;
const ckey = data.ckey;

return items.filter((item: LoadoutItem) => {
if (item.ckey_whitelist && item.ckey_whitelist.indexOf(ckey) === -1) {
return false;
}
if (item.donator_only && !is_donator) {
return false;
}
return true;
});
};
const ShouldDisplayPlayerRestriction = (item: LoadoutItem) => {
if (item.ckey_whitelist || item.restricted_species) {
return true;
}

return false;
};

const ShouldDisplayJobRestriction = (item: LoadoutItem) => {
if (item.restricted_roles || item.blacklisted_roles) {
return true;
}

return false;
};

const ItemPlayerRestriction = (item: LoadoutItem) => {
let restrictions: string[] = [];

if (item.ckey_whitelist) {
restrictions.push('CKEY Whitelist: ' + item.ckey_whitelist.join(', '));
}

if (item.restricted_species) {
restrictions.push(
'Species Whitelist: ' + item.restricted_species.join(', '),
);
}

const tooltip = restrictions.join(', ');

return (
<Button
icon="lock"
height="22px"
width="22px"
color="yellow"
tooltip={tooltip}
tooltipPosition={'bottom-start'}
style={{ zIndex: '2' }}
/>
);
};

const ItemJobRestriction = (item: LoadoutItem) => {
let restrictions: string[] = [];
if (item.restricted_roles) {
restrictions.push('Job Whitelist: ' + item.restricted_roles.join(', '));
}

if (item.blacklisted_roles) {
restrictions.push('Job Blacklist: ' + item.blacklisted_roles.join(', '));
}
const tooltip = restrictions.join(', ');
return (
<Button
icon="briefcase"
height="22px"
width="22px"
color="blue"
tooltip={tooltip}
tooltipPosition={'bottom-start'}
style={{ zIndex: '2' }}
/>
);
};

// SKYRAT EDIT END - EXPANDED LOADOUT
export const LoadoutTabDisplay = (props: {
category: LoadoutCategory | undefined;
}) => {
Expand Down
8 changes: 8 additions & 0 deletions tgui/packages/tgui/interfaces/PreferencesMenu/loadout/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export type LoadoutItem = {
buttons: LoadoutButton[];
reskins: ReskinOption[] | null;
information: string[];
// SKYRAT EDIT
ckey_whitelist: string[] | null;
restricted_roles: string[] | null;
blacklisted_roles: string[] | null;
restricted_species: string[] | null;
donator_only: BooleanLike;
erp_item: BooleanLike;
// SKYRAT EDIT
};

// Category of items in the loadout
Expand Down

0 comments on commit ad15317

Please sign in to comment.