From eaabe55a39defc406a9006b340337f78bf2b3af3 Mon Sep 17 00:00:00 2001 From: MrMelbert Date: Tue, 14 Nov 2023 02:51:33 -0600 Subject: [PATCH] Adds UI for sets --- .../code/__DEFINES/_module_defines.dm | 3 ++ .../client/preferences/loadout_preference.dm | 7 +++- .../loadouts/loadout_items/_loadout_datum.dm | 2 +- .../loadouts/loadout_ui/loadout_manager.dm | 8 ++++ .../loadout_ui/loadout_outfit_helpers.dm | 37 ++++++++++++++----- .../tgui/interfaces/_LoadoutManager.tsx | 29 ++++++++++++++- 6 files changed, 72 insertions(+), 14 deletions(-) diff --git a/maplestation_modules/code/__DEFINES/_module_defines.dm b/maplestation_modules/code/__DEFINES/_module_defines.dm index c8dd1faf9724..7154e4b2982d 100644 --- a/maplestation_modules/code/__DEFINES/_module_defines.dm +++ b/maplestation_modules/code/__DEFINES/_module_defines.dm @@ -37,3 +37,6 @@ #define SOUND_NORMAL (1<<0) #define SOUND_QUESTION (1<<1) #define SOUND_EXCLAMATION (1<<2) + +/// Max loadout presets available +#define MAX_LOADOUTS 5 diff --git a/maplestation_modules/code/modules/client/preferences/loadout_preference.dm b/maplestation_modules/code/modules/client/preferences/loadout_preference.dm index be047ae36f39..b186b3b89384 100644 --- a/maplestation_modules/code/modules/client/preferences/loadout_preference.dm +++ b/maplestation_modules/code/modules/client/preferences/loadout_preference.dm @@ -3,11 +3,14 @@ savefile_identifier = PREFERENCE_CHARACTER can_randomize = FALSE minimum = 1 - maximum = 5 + maximum = MAX_LOADOUTS /datum/preference/numeric/active_loadout/create_default_value() return minimum +/datum/preference/numeric/active_loadout/apply_to_human(mob/living/carbon/human/target, value) + return + /datum/preference/loadout savefile_key = "loadout_list" savefile_identifier = PREFERENCE_CHARACTER @@ -77,4 +80,4 @@ /datum/preferences/update_character(current_version, list/save_data) . = ..() if(current_version < 44) - update_loadout(src, save_data?["loadout_list"], save = TRUE) + save_loadout(src, save_data?["loadout_list"]) diff --git a/maplestation_modules/code/modules/loadouts/loadout_items/_loadout_datum.dm b/maplestation_modules/code/modules/loadouts/loadout_items/_loadout_datum.dm index 4b18b3984352..dfd97cf3a287 100644 --- a/maplestation_modules/code/modules/loadouts/loadout_items/_loadout_datum.dm +++ b/maplestation_modules/code/modules/loadouts/loadout_items/_loadout_datum.dm @@ -232,7 +232,7 @@ GLOBAL_LIST_EMPTY(all_loadout_datums) else // Not valid item_details -= INFO_RESKIN - update_loadout(preference_source, preference_list, save = TRUE) + save_loadout(preference_source, preference_list) return equipped_item diff --git a/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_manager.dm b/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_manager.dm index da87847f67cf..77d0f0396766 100644 --- a/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_manager.dm +++ b/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_manager.dm @@ -73,6 +73,7 @@ GLOBAL_LIST_INIT(loadout_categories, init_loadout_categories()) "toggle_job_clothes" = PROC_REF(action_toggle_job_outfit), "rotate_dummy" = PROC_REF(action_rotate_model_dir), "pass_to_loadout_item" = PROC_REF(action_pass_to_loadout_item), + "select_slot" = PROC_REF(select_slot), ) /// The preview dummy. @@ -169,6 +170,11 @@ GLOBAL_LIST_INIT(loadout_categories, init_loadout_categories()) SIGNAL_HANDLER menu = null +/datum/preference_middleware/loadout/proc/select_slot(list/params, mob/user) + preferences.write_preference(GLOB.preference_entries[/datum/preference/numeric/active_loadout], text2num(params["new_slot"])) + character_preview_view.update_body() + preferences.update_static_data_for_all_viewers() + /datum/preference_middleware/loadout/get_ui_data(mob/user) var/list/data = list() @@ -182,6 +188,7 @@ GLOBAL_LIST_INIT(loadout_categories, init_loadout_categories()) data["selected_loadout"] = all_selected_paths data["mob_name"] = preferences.read_preference(/datum/preference/name/real_name) data["job_clothes"] = character_preview_view.view_job_clothes + data["current_slot"] = preferences.read_preference(/datum/preference/numeric/active_loadout) return data @@ -202,6 +209,7 @@ GLOBAL_LIST_INIT(loadout_categories, init_loadout_categories()) data["loadout_tabs"] = loadout_tabs data["tutorial_text"] = get_tutorial_text() + data["max_loadout_slots"] = MAX_LOADOUTS return data /// Returns a formatted string for use in the UI. diff --git a/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_outfit_helpers.dm b/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_outfit_helpers.dm index ea1b45a21e9d..abdcc582ac83 100644 --- a/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_outfit_helpers.dm +++ b/maplestation_modules/code/modules/loadouts/loadout_ui/loadout_outfit_helpers.dm @@ -65,26 +65,43 @@ return datums +/** + * Gets the active loadout of the passed preference source. + * + * Returns a loadout lazylist + */ /proc/get_active_loadout(datum/preferences/preferences) + RETURN_TYPE(/list) var/slot = preferences.read_preference(/datum/preference/numeric/active_loadout) var/list/all_loadouts = preferences.read_preference(/datum/preference/loadout) if(slot > length(all_loadouts)) return null return all_loadouts[slot] -/proc/update_loadout(datum/preferences/preferences, list/loadout_list, save = FALSE) +/** + * Calls update_preference on the passed preference datum with the passed loadout list + */ +/proc/update_loadout(datum/preferences/preferences, list/loadout_list) + preferences.update_preference(GLOB.preference_entries[/datum/preference/loadout], get_updated_loadout_list(preferences, loadout_list)) + +/** + * Calls write_preference on the passed preference datum with the passed loadout list + */ +/proc/save_loadout(datum/preferences/preferences, list/loadout_list) + preferences.write_preference(GLOB.preference_entries[/datum/preference/loadout], get_updated_loadout_list(preferences, loadout_list)) + +/** + * Returns a list of all loadouts belonging to the passed preference source, + * and appends the passed loadout list to the proper index of the list. + */ +/proc/get_updated_loadout_list(datum/preferences/preferences, list/loadout_list) + RETURN_TYPE(/list) var/slot = preferences.read_preference(/datum/preference/numeric/active_loadout) var/list/new_list = list() for(var/list/loadout in preferences.read_preference(/datum/preference/loadout)) UNTYPED_LIST_ADD(new_list, loadout) - while(length(new_list) < slot - 1) + while(length(new_list) < slot) new_list += null - UNTYPED_LIST_ADD(new_list, loadout_list) - - if(save) - preferences.write_preference(GLOB.preference_entries[/datum/preference/loadout], new_list) - return - - ASYNC - preferences.update_preference(GLOB.preference_entries[/datum/preference/loadout], new_list) + new_list[slot] = loadout_list + return new_list diff --git a/tgui/packages/tgui/interfaces/_LoadoutManager.tsx b/tgui/packages/tgui/interfaces/_LoadoutManager.tsx index d95775c825c5..f11fe3a3e2f8 100644 --- a/tgui/packages/tgui/interfaces/_LoadoutManager.tsx +++ b/tgui/packages/tgui/interfaces/_LoadoutManager.tsx @@ -30,6 +30,8 @@ type Data = { loadout_preview_view: string; loadout_tabs: LoadoutCategory[]; tutorial_text: string; + current_slot: number; + max_loadout_slots: number; }; export const LoadoutPage = (props, context) => { @@ -297,8 +299,24 @@ const LoadoutTabs = (props, context) => { const LoadoutPreviewSection = (props, context) => { const { act, data } = useBackend(context); - const { mob_name, job_clothes, loadout_preview_view } = data; + const { + mob_name, + job_clothes, + loadout_preview_view, + current_slot, + max_loadout_slots, + } = data; + const [tutorialStatus] = useLocalState(context, 'tutorialStatus', false); + + const loadoutSlots = (maxSlots: number) => { + const slots: number[] = []; + for (let i = 1; i < maxSlots + 1; i++) { + slots.push(i); + } + return slots; + }; + return (
{ } /> + {loadoutSlots(max_loadout_slots).map((slot) => ( + +