-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tgui body color/type/size picker (#7475)
vido https://github.com/user-attachments/assets/be1b699a-4bda-4343-8d13-90f979ff19ac 🆑 add: a new tgui with better previews for the different skin colors / body types / body sizes /🆑 --------- Co-authored-by: Drathek <[email protected]>
- Loading branch information
Showing
8 changed files
with
303 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/datum/body_picker/ui_static_data(mob/user) | ||
. = ..() | ||
|
||
.["icon"] = /datum/species::icobase | ||
|
||
.["body_types"] = list() | ||
for(var/key in GLOB.body_type_list) | ||
var/datum/body_type/type = GLOB.body_type_list[key] | ||
.["body_types"] += list( | ||
list("name" = type.name, "icon" = type.icon_name) | ||
) | ||
|
||
.["skin_colors"] = list() | ||
for(var/key in GLOB.skin_color_list) | ||
var/datum/skin_color/color = GLOB.skin_color_list[key] | ||
.["skin_colors"] += list( | ||
list("name" = color.name, "icon" = color.icon_name, "color" = color.color) | ||
) | ||
|
||
.["body_sizes"] = list() | ||
for(var/key in GLOB.body_size_list) | ||
var/datum/body_size/size = GLOB.body_size_list[key] | ||
.["body_sizes"] += list( | ||
list("name" = size.name, "icon" = size.icon_name) | ||
) | ||
|
||
/datum/body_picker/ui_data(mob/user) | ||
. = ..() | ||
|
||
.["body_type"] = GLOB.body_type_list[user.client.prefs.body_type].icon_name | ||
.["skin_color"] = GLOB.skin_color_list[user.client.prefs.skin_color].icon_name | ||
.["body_size"] = GLOB.body_size_list[user.client.prefs.body_size].icon_name | ||
|
||
/datum/body_picker/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) | ||
. = ..() | ||
|
||
var/datum/preferences/prefs = ui.user.client.prefs | ||
|
||
switch(action) | ||
if("type") | ||
if(!GLOB.body_type_list[params["name"]]) | ||
return | ||
|
||
prefs.body_type = params["name"] | ||
|
||
if("size") | ||
if(!GLOB.body_size_list[params["name"]]) | ||
return | ||
|
||
prefs.body_size = params["name"] | ||
|
||
if("color") | ||
if(!GLOB.skin_color_list[params["name"]]) | ||
return | ||
|
||
prefs.skin_color = params["name"] | ||
|
||
prefs.ShowChoices(ui.user) | ||
return TRUE | ||
|
||
/datum/body_picker/tgui_interact(mob/user, datum/tgui/ui) | ||
. = ..() | ||
|
||
ui = SStgui.try_update_ui(user, src, ui) | ||
|
||
if(!ui) | ||
ui = new(user, src, "BodyPicker", "Body Picker") | ||
ui.open() | ||
ui.set_autoupdate(FALSE) | ||
|
||
winset(user, ui.window.id, "focus=true") | ||
|
||
/datum/body_picker/ui_state(mob/user) | ||
return GLOB.always_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { useState } from 'react'; | ||
|
||
import { useBackend } from '../backend'; | ||
import { | ||
Box, | ||
Button, | ||
ColorBox, | ||
DmIcon, | ||
Modal, | ||
Stack, | ||
Tooltip, | ||
} from '../components'; | ||
import { Window } from '../layouts'; | ||
|
||
type PickerData = { | ||
icon: string; | ||
body_types: { name: string; icon: string }[]; | ||
skin_colors: { name: string; icon: string; color: string }[]; | ||
body_sizes: { name: string; icon: string }[]; | ||
|
||
body_type: string; | ||
skin_color: string; | ||
body_size: string; | ||
}; | ||
|
||
export const BodyPicker = () => { | ||
const { data } = useBackend<PickerData>(); | ||
|
||
const { icon, body_size, body_type, skin_color, body_types, body_sizes } = | ||
data; | ||
|
||
const [picker, setPicker] = useState<'type' | 'size' | undefined>(); | ||
|
||
const unselectedBodyType = body_types.filter( | ||
(val) => val.icon !== body_type, | ||
)[0]; | ||
|
||
const unselectedBodySize = body_sizes.filter( | ||
(val) => val.icon !== body_size, | ||
)[0]; | ||
|
||
return ( | ||
<Window width={390} height={180} theme={'crtblue'}> | ||
<Window.Content className="BodyPicker"> | ||
{picker && ( | ||
<Modal m={1}> | ||
<TypePicker picker={setPicker} toUse={picker} /> | ||
</Modal> | ||
)} | ||
<Stack> | ||
<Stack.Item> | ||
<Stack vertical> | ||
<Stack.Item> | ||
<DmIcon | ||
icon={icon} | ||
icon_state={`${skin_color}_torso_${body_size}_${body_type}`} | ||
width={'128px'} | ||
mt={-5} | ||
/> | ||
</Stack.Item> | ||
<Stack width="100%" fill mt={-4} justify="space-around"> | ||
<Stack.Item> | ||
<Button width={'4em'} height={'4em'}> | ||
<Tooltip | ||
content={'Change Body Type'} | ||
position="bottom-start" | ||
> | ||
<Box | ||
position="relative" | ||
onClick={() => setPicker('type')} | ||
> | ||
<DmIcon | ||
position="relative" | ||
icon={icon} | ||
icon_state={`${skin_color}_torso_${body_size}_${unselectedBodyType.icon}`} | ||
width={'80px'} | ||
right={'22px'} | ||
bottom={'18px'} | ||
/> | ||
</Box> | ||
</Tooltip> | ||
</Button> | ||
</Stack.Item> | ||
<Stack.Item> | ||
<Button width={'4em'} height={'4em'}> | ||
<Tooltip | ||
content={'Change Body Size'} | ||
position="bottom-start" | ||
> | ||
<Box | ||
position="relative" | ||
onClick={() => setPicker('size')} | ||
> | ||
<DmIcon | ||
position="relative" | ||
icon={icon} | ||
icon_state={`${skin_color}_torso_${unselectedBodySize.icon}_${body_type}`} | ||
width={'80px'} | ||
right={'22px'} | ||
bottom={'18px'} | ||
/> | ||
</Box> | ||
</Tooltip> | ||
</Button> | ||
</Stack.Item> | ||
</Stack> | ||
</Stack> | ||
</Stack.Item> | ||
<Stack.Item> | ||
<ColorOptions /> | ||
</Stack.Item> | ||
</Stack> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; | ||
|
||
const TypePicker = (props: { | ||
readonly picker: (_) => void; | ||
readonly toUse: 'type' | 'size'; | ||
}) => { | ||
const { data, act } = useBackend<PickerData>(); | ||
|
||
const { picker, toUse } = props; | ||
|
||
const { body_type, body_types, skin_color, body_size, body_sizes, icon } = | ||
data; | ||
|
||
const toIterate = toUse === 'type' ? body_types : body_sizes; | ||
|
||
const active = toUse === 'type' ? body_type : body_size; | ||
|
||
return ( | ||
<Stack> | ||
{toIterate.map((type) => ( | ||
<Stack.Item key={type.name}> | ||
<Tooltip content={type.name}> | ||
<Box | ||
onClick={() => { | ||
picker(undefined); | ||
act(toUse, { name: type.name }); | ||
}} | ||
position="relative" | ||
className={`typePicker ${active === type.icon ? 'active' : ''}`} | ||
> | ||
<DmIcon | ||
icon={icon} | ||
icon_state={ | ||
toUse === 'type' | ||
? `${skin_color}_torso_${body_size}_${type.icon}` | ||
: `${skin_color}_torso_${type.icon}_${body_type}` | ||
} | ||
width={'80px'} | ||
/> | ||
</Box> | ||
</Tooltip> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
); | ||
}; | ||
|
||
const ColorOptions = () => { | ||
const { data, act } = useBackend<PickerData>(); | ||
|
||
const { skin_color, skin_colors } = data; | ||
|
||
return ( | ||
<Stack wrap={'wrap'} width={'250px'}> | ||
{skin_colors.map((color) => ( | ||
<Stack.Item key={color.name} className="colorPickerContainer"> | ||
<ColorBox | ||
color={color.color} | ||
p={3.5} | ||
mt={0.5} | ||
onClick={() => act('color', { name: color.name })} | ||
className={`colorPicker ${skin_color === color.icon ? 'active' : ''}`} | ||
/> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.theme-crtblue { | ||
.BodyPicker { | ||
.Stack--horizontal > .colorPickerContainer:first-of-type { | ||
margin-left: 6px; | ||
} | ||
|
||
.typePicker { | ||
border: 1px dotted #8ac8ff; | ||
} | ||
|
||
.typePicker.active { | ||
border: 1px solid #8ac8ff; | ||
} | ||
|
||
.colorPicker.active { | ||
outline: solid 2px #8ac8ff; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters