Files
Bubberstation/code/modules/loadout/loadout_categories.dm
MrMelbert d244c86ce6 Adds Character Loadout Tab to preferences (with just a small handful of items to start) (#83521)
## About The Pull Request

Adds a Character Loadout Tab to the preference menu

This tab lets you pick items to start the round with


![image](https://private-user-images.githubusercontent.com/51863163/336254447-c5f7eefa-c44c-418d-b48e-0409bb5bb982.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgwNDAxMjMsIm5iZiI6MTcxODAzOTgyMywicGF0aCI6Ii81MTg2MzE2My8zMzYyNTQ0NDctYzVmN2VlZmEtYzQ0Yy00MThkLWI0OGUtMDQwOWJiNWJiOTgyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEwVDE3MTcwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYxYWFmYjI2NDU0YjUyODg3NjBmM2VjZDg4YWQ1YjlhMThmODU3MDYyMzYwOGVmYTcxYmY2MDhjZWVmYjQ5ZTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Y0_19Gisfp4yyUmLgW2atfKyneL7POWFRKNVgNWTbEs)

This also has some additional mechanics, such as being able to recolor
colorable items, rename certain items (such as plushies), set item skins
(such as the pride pin)


![image](https://github.com/tgstation/tgstation/assets/51863163/8a085d6c-a294-4538-95d2-ada902ab69b4)

## Why It's Good For The Game

This has been headcoder sanctioned for some time, just no one did it. So
here we are.

Allows players to add some additional customization to their characters.
Keeps us from cluttering the quirks list with quirks that do nothing but
grants items.

## Changelog

🆑 Melbert
add: Character Loadouts
del: Pride Pin quirk (it's in the Loadout menu now)
/🆑
2024-06-11 17:50:12 -07:00

80 lines
2.8 KiB
Plaintext

/**
* # Loadout categories
*
* Loadout categories are singletons used to group loadout items together in the loadout screen.
*/
/datum/loadout_category
/// The name of the category, shown in the tabs
var/category_name
/// FontAwesome icon for the category
var/category_ui_icon
/// String to display on the top-right of a category tab
var/category_info
/// Order which they appear in the tabs, ties go alphabetically
var/tab_order = -1
/// What type of loadout items should be generated for this category?
var/type_to_generate
/// List of all loadout items in this category
VAR_FINAL/list/datum/loadout_item/associated_items
/datum/loadout_category/New()
. = ..()
associated_items = get_items()
for(var/datum/loadout_item/item as anything in associated_items)
if(GLOB.all_loadout_datums[item.item_path])
stack_trace("Loadout datum collision - [item.item_path] is shared between multiple loadout datums.")
GLOB.all_loadout_datums[item.item_path] = item
/datum/loadout_category/Destroy(force, ...)
if(!force)
stack_trace("QDEL called on loadout category [type]. This shouldn't ever happen. (Use FORCE if necessary.)")
return QDEL_HINT_LETMELIVE
associated_items.Cut()
return ..()
/// Return a list of all /datum/loadout_items in this category.
/datum/loadout_category/proc/get_items() as /list
var/list/all_items = list()
for(var/datum/loadout_item/found_type as anything in typesof(type_to_generate))
if(found_type == initial(found_type.abstract_type))
continue
if(!ispath(initial(found_type.item_path), /obj/item))
stack_trace("Loadout get_items(): Attempted to instantiate a loadout item ([found_type]) with an invalid or null typepath! (got path: [initial(found_type.item_path)])")
continue
var/datum/loadout_item/spawned_type = new found_type(src)
all_items += spawned_type
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() as /list
if(!length(associated_items))
return list()
var/list/formatted_list = list()
for(var/datum/loadout_item/item as anything in associated_items)
var/list/item_data = item.to_ui_data()
UNTYPED_LIST_ADD(formatted_list, item_data)
sortTim(formatted_list, /proc/cmp_assoc_list_name) // Alphabetizing
return formatted_list
/**
* Handles what happens when two items of this category are selected at once
*
* Return TRUE if it's okay to continue with adding the incoming item,
* or return FALSE to stop the new item from being added
*/
/datum/loadout_category/proc/handle_duplicate_entires(
datum/preference_middleware/loadout/manager,
datum/loadout_item/conflicting_item,
datum/loadout_item/added_item,
list/datum/loadout_item/all_loadout_items,
)
manager.deselect_item(conflicting_item)
return TRUE