Skip to content

Commit

Permalink
Adds UI for sets
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert committed Nov 14, 2023
1 parent 0f302e9 commit eaabe55
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
3 changes: 3 additions & 0 deletions maplestation_modules/code/__DEFINES/_module_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand All @@ -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

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 28 additions & 1 deletion tgui/packages/tgui/interfaces/_LoadoutManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -297,8 +299,24 @@ const LoadoutTabs = (props, context) => {

const LoadoutPreviewSection = (props, context) => {
const { act, data } = useBackend<Data>(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 (
<Section
title={`Preview: ${mob_name}`}
Expand Down Expand Up @@ -332,6 +350,15 @@ const LoadoutPreviewSection = (props, context) => {
}
/>
</Stack.Item>
{loadoutSlots(max_loadout_slots).map((slot) => (
<Stack.Item key={slot}>
<Button
color={slot === current_slot ? 'green' : ''}
content={slot}
onClick={() => act('select_slot', { new_slot: slot })}
/>
</Stack.Item>
))}
<Stack.Item>
<Button
icon="chevron-right"
Expand Down

0 comments on commit eaabe55

Please sign in to comment.