Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw order UI #14164

Merged
merged 9 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions code/__DEFINES/equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ GLOBAL_LIST_INIT(slot_str_to_slot, list(
SLOT_IN_BACKPACK\
)

///Each slot you can draw from, used and messed with in your preferences.
#define SLOT_DRAW_ORDER list(\
SLOT_IN_HOLSTER,\
SLOT_IN_S_HOLSTER,\
Expand Down Expand Up @@ -539,8 +540,12 @@ GLOBAL_LIST_INIT(slot_str_to_slot, list(
return SLOT_IN_HEAD
if("Left Pocket")
return SLOT_L_STORE
if("Left Pocket Inside")
return SLOT_IN_L_POUCH
if("Right Pocket")
return SLOT_R_STORE
if("Right Pocket Inside")
return SLOT_IN_R_POUCH
if("Webbing")
return SLOT_IN_ACCESSORY
if("Belt Inside")
Expand All @@ -551,6 +556,8 @@ GLOBAL_LIST_INIT(slot_str_to_slot, list(
return SLOT_IN_S_HOLSTER
if("Back Holster")
return SLOT_IN_B_HOLSTER
if("Active Storage")
return SLOT_IN_STORAGE

/proc/slot_flag_to_fluff(slot)
switch(slot)
Expand All @@ -572,8 +579,12 @@ GLOBAL_LIST_INIT(slot_str_to_slot, list(
return "Helmet"
if(SLOT_L_STORE)
return "Left Pocket"
if(SLOT_IN_L_POUCH)
return "Left Pocket Inside"
if(SLOT_R_STORE)
return "Right Pocket"
if(SLOT_IN_R_POUCH)
return "Right Pocket Inside"
if(SLOT_IN_ACCESSORY)
return "Webbing"
if(SLOT_IN_HOLSTER)
Expand All @@ -582,3 +593,6 @@ GLOBAL_LIST_INIT(slot_str_to_slot, list(
return "Suit Storage Holster"
if(SLOT_IN_B_HOLSTER)
return "Back Holster"
if(SLOT_IN_STORAGE)
return "Active Storage"

1 change: 1 addition & 0 deletions code/__DEFINES/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#define JOB_PREFERENCES 4
#define GAME_SETTINGS 5
#define KEYBIND_SETTINGS 6
#define DRAW_ORDER 7

#define CITIZENSHIP_CHOICES list(\
"Earth Born",\
Expand Down
4 changes: 3 additions & 1 deletion code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ GLOBAL_LIST_EMPTY(preferences_datums)
///What outfit typepaths we've favorited in the SelectEquipment menu
var/list/favorite_outfits = list()

///List of slot_draw_order
var/list/slot_draw_order_pref = list()

/datum/preferences/New(client/C)
if(!istype(C))
return
Expand Down Expand Up @@ -224,7 +227,6 @@ GLOBAL_LIST_EMPTY(preferences_datums)
C.set_macros()
loadout_manager = new


/datum/preferences/can_interact(mob/user)
return TRUE

Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/preferences_savefile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
custom_emotes = sanitize_is_full_emote_list(custom_emotes)
chem_macros = sanitize_islist(chem_macros, list())
quick_equip = sanitize_islist(quick_equip, QUICK_EQUIP_ORDER, MAX_QUICK_EQUIP_SLOTS, TRUE, VALID_EQUIP_SLOTS)
slot_draw_order_pref = sanitize_islist(slot_draw_order_pref, SLOT_DRAW_ORDER, length(SLOT_DRAW_ORDER), TRUE, SLOT_DRAW_ORDER)

mute_self_combat_messages = sanitize_integer(mute_self_combat_messages, FALSE, TRUE, initial(mute_self_combat_messages))
mute_others_combat_messages = sanitize_integer(mute_others_combat_messages, FALSE, TRUE, initial(mute_others_combat_messages))
Expand Down Expand Up @@ -475,6 +476,7 @@
alternate_option = sanitize_integer(alternate_option, 0, 2, initial(alternate_option))
job_preferences = SANITIZE_LIST(job_preferences)
quick_equip = sanitize_islist(quick_equip, QUICK_EQUIP_ORDER, MAX_QUICK_EQUIP_SLOTS, TRUE, VALID_EQUIP_SLOTS)
slot_draw_order_pref = sanitize_islist(slot_draw_order_pref, SLOT_DRAW_ORDER, length(SLOT_DRAW_ORDER), TRUE, SLOT_DRAW_ORDER)
for(var/quick_equip_slots in quick_equip)
quick_equip_slots = sanitize_inlist(quick_equip_slots, SLOT_DRAW_ORDER[quick_equip], quick_equip_slots)
if(gender == MALE)
Expand Down Expand Up @@ -566,6 +568,7 @@
quick_equip = sanitize_islist(quick_equip, QUICK_EQUIP_ORDER, MAX_QUICK_EQUIP_SLOTS, TRUE, VALID_EQUIP_SLOTS)
for(var/quick_equip_slots in quick_equip)
quick_equip_slots = sanitize_inlist(quick_equip_slots, SLOT_DRAW_ORDER[quick_equip], quick_equip_slots)
slot_draw_order_pref = sanitize_islist(slot_draw_order_pref, SLOT_DRAW_ORDER, length(SLOT_DRAW_ORDER), TRUE, SLOT_DRAW_ORDER)
if(gender == MALE)
underwear = sanitize_integer(underwear, 1, length(GLOB.underwear_m), initial(underwear))
undershirt = sanitize_integer(undershirt, 1, length(GLOB.undershirt_m), initial(undershirt))
Expand Down
30 changes: 27 additions & 3 deletions code/modules/client/preferences_ui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
data["pixel_size"] = pixel_size
data["parallax"] = parallax
data["fullscreen_mode"] = fullscreen_mode
data["quick_equip"] = list()
for(var/quick_equip_slots in quick_equip)
data["quick_equip"] += slot_flag_to_fluff(quick_equip_slots)
data["fast_mc_refresh"] = fast_mc_refresh
data["split_admin_tabs"] = split_admin_tabs
if(KEYBIND_SETTINGS)
Expand All @@ -147,6 +144,13 @@
sentence = emote.message,
emote_type = (emote.spoken_emote ? "say" : "me"),
)
if(DRAW_ORDER)
data["draw_order"] = list()
for(var/slot in slot_draw_order_pref)
data["draw_order"] += slot_flag_to_fluff(slot)
data["quick_equip"] = list()
for(var/quick_equip_slots in quick_equip)
data["quick_equip"] += slot_flag_to_fluff(quick_equip_slots)
return data

/datum/preferences/ui_static_data(mob/user)
Expand Down Expand Up @@ -655,6 +659,26 @@
quick_equip[editing_slot] = slot_fluff_to_flag(slot)
to_chat(src, span_notice("You will now equip/draw from the [slot] slot first."))

if("equip_slot_equip_position")
var/returned_item_list_position = slot_draw_order_pref.Find(slot_fluff_to_flag(params["changing_item"]))
if(isnull(returned_item_list_position))
return
var/direction = params["direction"]
if(!direction)
return
var/swapping_with = returned_item_list_position
switch(direction)
if("down")
if(returned_item_list_position == length(SLOT_DRAW_ORDER))
return
swapping_with += 1
slot_draw_order_pref.Swap(returned_item_list_position, swapping_with)
if("up")
if(returned_item_list_position == 1)
return
swapping_with -= 1
slot_draw_order_pref.Swap(swapping_with, returned_item_list_position)

if("show_typing")
show_typing = !show_typing
// Need to remove any currently shown
Expand Down
10 changes: 7 additions & 3 deletions code/modules/mob/living/carbon/human/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
if(incapacitated() || lying_angle)
return

var/slot_requested = client?.prefs?.quick_equip[quick_equip_slot]
var/slot_requested = client?.prefs?.quick_equip[quick_equip_slot] || VALID_EQUIP_SLOTS
var/obj/item/I = get_active_held_item()
if(!I) //draw item
if(next_move > world.time)
return
if(slot_requested)

if(slot_requested) //Equips from quick_equip 1-5
if(draw_from_slot_if_possible(slot_requested))
next_move = world.time + 1
return
for(var/slot in SLOT_DRAW_ORDER)

var/list/slot_to_draw = client?.prefs?.slot_draw_order_pref || SLOT_DRAW_ORDER //Equips from draw order in prefs
for(var/slot in slot_to_draw)
if(draw_from_slot_if_possible(slot))
next_move = world.time + 1
return

else //store item
if(s_active?.attackby(I, src)) //stored in currently open storage
return TRUE
Expand Down
63 changes: 63 additions & 0 deletions tgui/packages/tgui/interfaces/PlayerPreferences/DrawOrder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useBackend } from '../../backend';
import { Box, Section, Stack, LabeledList, Button, Table } from '../../components';
import { TableCell, TableRow } from '../../components/Table';

export const DrawOrder = (props, context) => {
const { act, data } = useBackend<DrawOrder>(context);
const { draw_order = [], quick_equip = [] } = data;
return (
<Section title="Draw Order">
<Stack fill>
<Stack.Item grow>
<Section title="Equip Slot Order">
<Section>
<Table>
{draw_order.map((item) => (
<TableRow key={item}>
<TableCell>{item}</TableCell>
<Button
icon="arrow-up"
onClick={() =>
act('equip_slot_equip_position', {
direction: 'up',
changing_item: item,
})
}
/>
<Button
icon="arrow-down"
onClick={() =>
act('equip_slot_equip_position', {
direction: 'down',
changing_item: item,
})
}
/>
</TableRow>
))}
</Table>
</Section>
</Section>
</Stack.Item>
<Stack.Item grow>
<Section title="Keybinding Settings">
<LabeledList>
{quick_equip.map((equip_slot, index_slot) => (
<>
<Box>Quick equip #{index_slot + 1}</Box>
<Button
key={equip_slot}
content={equip_slot}
onClick={() =>
act('change_quick_equip', { selection: index_slot + 1 })
}
/>
</>
))}
</LabeledList>
</Section>
</Stack.Item>
</Stack>
</Section>
);
};
30 changes: 3 additions & 27 deletions tgui/packages/tgui/interfaces/PlayerPreferences/GameSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useBackend } from '../../backend';
import { Box, Button, Section, LabeledList, Stack, ColorBox } from '../../components';
import { Button, Section, LabeledList, Stack, ColorBox } from '../../components';
import { ToggleFieldPreference, TextFieldPreference, SelectFieldPreference, LoopingSelectionPreference } from './FieldPreferences';

const ParallaxNumToString = (integer) => {
Expand Down Expand Up @@ -28,14 +28,8 @@ const ParallaxNumToString = (integer) => {

export const GameSettings = (props, context) => {
const { act, data } = useBackend<GameSettingData>(context);
const {
ui_style_color,
scaling_method,
pixel_size,
parallax,
quick_equip,
is_admin,
} = data;
const { ui_style_color, scaling_method, pixel_size, parallax, is_admin } =
data;
return (
<Section title="Game Settings">
<Stack fill>
Expand Down Expand Up @@ -277,24 +271,6 @@ export const GameSettings = (props, context) => {
</LabeledList>
</Section>
</Stack.Item>
<Stack.Item grow>
<Section title="Keybinding Settings">
<LabeledList>
{quick_equip.map((equip_slot, index_slot) => (
<>
<Box>Quick equip #{index_slot + 1}</Box>
<Button
key={equip_slot}
content={equip_slot}
onClick={() =>
act('change_quick_equip', { selection: index_slot + 1 })
}
/>
</>
))}
</LabeledList>
</Section>
</Stack.Item>
</Stack>
{!!is_admin && (
<Stack>
Expand Down
6 changes: 5 additions & 1 deletion tgui/packages/tgui/interfaces/PlayerPreferences/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type GameSettingData = {
scaling_method: string;
pixel_size: number;
parallax: number;
quick_equip: string[];
is_admin: number;
};

Expand Down Expand Up @@ -172,3 +171,8 @@ type PreferencesJobDatum = {
type PreferencesFlagsList = {
bold: number;
};

type DrawOrder = {
draw_order: string[];
quick_equip: string[];
};
9 changes: 9 additions & 0 deletions tgui/packages/tgui/interfaces/PlayerPreferences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { JobPreferences } from './JobPreferences';
import { GameSettings } from './GameSettings';
import { KeybindSettings } from './KeybindSettings';
import { BackgroundInformation } from './BackgroundInformation';
import { DrawOrder } from './DrawOrder';

export const PlayerPreferences = (props, context) => {
const { act, data } = useBackend<PlayerPreferencesData>(context);
Expand Down Expand Up @@ -38,6 +39,9 @@ export const PlayerPreferences = (props, context) => {
case 6:
CurrentTab = KeybindSettings;
break;
case 7:
CurrentTab = DrawOrder;
break;
default:
}

Expand Down Expand Up @@ -113,6 +117,11 @@ const NavigationSelector = (props, context) => {
onClick={() => act('tab_change', { tabIndex: 6 })}>
Keybindings
</Tabs.Tab>
<Tabs.Tab
selected={tabIndex === 7}
onClick={() => act('tab_change', { tabIndex: 7 })}>
Draw Order
</Tabs.Tab>
</Tabs>
);
};
Loading