-
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.
implements a new loadout picker tgui menu (#7524)
MORE tgui slop yum yum more `<DmIcon />` please! vido https://github.com/user-attachments/assets/385f3aab-0df5-478b-b2e1-b7d0d85be67c 🆑 ui: adds a prettier custom loadout menu with images /🆑 --------- Co-authored-by: Drathek <[email protected]>
- Loading branch information
Showing
8 changed files
with
251 additions
and
56 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,89 @@ | ||
/datum/loadout_picker/ui_static_data(mob/user) | ||
. = ..() | ||
|
||
.["categories"] = list() | ||
for(var/category in GLOB.gear_datums_by_category) | ||
var/list/datum/gear/gears = GLOB.gear_datums_by_category[category] | ||
|
||
var/items = list() | ||
|
||
for(var/gear_key as anything in gears) | ||
var/datum/gear/gear = gears[gear_key] | ||
items += list( | ||
list("name" = gear.display_name, "cost" = gear.cost, "icon" = gear.path::icon, "icon_state" = gear.path::icon_state) | ||
) | ||
|
||
.["categories"] += list( | ||
list("name" = category, "items" = items) | ||
) | ||
|
||
.["max_points"] = MAX_GEAR_COST | ||
|
||
/datum/loadout_picker/ui_data(mob/user) | ||
. = ..() | ||
|
||
var/datum/preferences/prefs = user.client?.prefs | ||
if(!prefs) | ||
return | ||
|
||
var/points = 0 | ||
|
||
.["loadout"] = list() | ||
|
||
for(var/item in prefs.gear) | ||
var/datum/gear/gear = GLOB.gear_datums_by_name[item] | ||
points += gear.cost | ||
|
||
.["loadout"] += list( | ||
list("name" = gear.display_name, "cost" = gear.cost, "icon" = gear.path::icon, "icon_state" = gear.path::icon_state) | ||
) | ||
|
||
.["points"] = points | ||
|
||
/datum/loadout_picker/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) | ||
. = ..() | ||
|
||
var/datum/preferences/prefs = ui.user.client?.prefs | ||
if(!prefs) | ||
return | ||
|
||
switch(action) | ||
if("add") | ||
var/datum/gear/gear = GLOB.gear_datums_by_name[params["name"]] | ||
if(!istype(gear)) | ||
return | ||
|
||
var/total_cost = 0 | ||
for(var/gear_name in prefs.gear) | ||
total_cost += GLOB.gear_datums_by_name[gear_name].cost | ||
|
||
total_cost += gear.cost | ||
if(total_cost > MAX_GEAR_COST) | ||
return | ||
|
||
prefs.gear += gear.display_name | ||
|
||
if("remove") | ||
var/datum/gear/gear = GLOB.gear_datums_by_name[params["name"]] | ||
if(!istype(gear)) | ||
return | ||
|
||
prefs.gear -= gear.display_name | ||
|
||
prefs.ShowChoices(ui.user) | ||
return TRUE | ||
|
||
/datum/loadout_picker/tgui_interact(mob/user, datum/tgui/ui) | ||
. = ..() | ||
|
||
ui = SStgui.try_update_ui(user, src, ui) | ||
|
||
if(!ui) | ||
ui = new(user, src, "LoadoutPicker", "Loadout Picker") | ||
ui.open() | ||
ui.set_autoupdate(FALSE) | ||
|
||
winset(user, ui.window.id, "focus=true") | ||
|
||
/datum/loadout_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,131 @@ | ||
import { useState } from 'react'; | ||
|
||
import { useBackend } from '../backend'; | ||
import { Box, Button, DmIcon, Section, Stack } from '../components'; | ||
import { Window } from '../layouts'; | ||
import { Loader } from './common/Loader'; | ||
|
||
type LoadoutPickerData = { | ||
categories: { | ||
name: string; | ||
items: LoadoutItem[]; | ||
}[]; | ||
points: number; | ||
max_points: number; | ||
loadout: LoadoutItem[]; | ||
}; | ||
|
||
type LoadoutItem = { | ||
name: string; | ||
cost: number; | ||
icon: string; | ||
icon_state: string; | ||
}; | ||
|
||
export const LoadoutPicker = () => { | ||
const { data } = useBackend<LoadoutPickerData>(); | ||
|
||
const { categories, points, max_points, loadout } = data; | ||
|
||
const [selected, setSelected] = useState(categories[0]); | ||
|
||
return ( | ||
<Window height={485} width={610} theme="crtblue"> | ||
<Window.Content className="LoadoutPicker"> | ||
<Stack fill> | ||
<Stack.Item> | ||
<Stack vertical fill> | ||
<Stack.Item> | ||
<Section scrollable height="220px"> | ||
<Stack vertical height="200px"> | ||
{categories.map((category) => ( | ||
<Stack.Item key={category.name}> | ||
<Button | ||
fluid | ||
selected={selected === category} | ||
onClick={() => setSelected(category)} | ||
> | ||
{category.name} | ||
</Button> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
<Stack.Item grow> | ||
<Section | ||
title={`Loadout (${points}/${max_points} points)`} | ||
height="100%" | ||
scrollable | ||
> | ||
<Stack wrap width="180px" height="165px"> | ||
{loadout.map((item) => ( | ||
<Stack.Item key={item.name} className="ItemPicker"> | ||
<ItemRender item={item} loadout /> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
</Stack> | ||
</Stack.Item> | ||
<Stack.Item grow> | ||
<Section title={selected.name} fill width="100%" scrollable> | ||
<Stack wrap> | ||
{selected.items.map((item) => ( | ||
<Stack.Item key={item.name} className="ItemPicker"> | ||
<ItemRender item={item} /> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
</Stack> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; | ||
|
||
const ItemRender = (props: { | ||
readonly item: LoadoutItem; | ||
readonly loadout?: boolean; | ||
}) => { | ||
const { item, loadout } = props; | ||
|
||
const { icon, icon_state, name, cost } = item; | ||
|
||
const { data, act } = useBackend<LoadoutPickerData>(); | ||
|
||
const { points, max_points } = data; | ||
|
||
const atLimit = points + cost > max_points; | ||
|
||
return ( | ||
<Stack> | ||
<Stack.Item> | ||
<Button | ||
tooltip={name} | ||
onClick={() => act(loadout ? 'remove' : 'add', { name: name })} | ||
disabled={!loadout && atLimit} | ||
width="78px" | ||
height="74px" | ||
mb="3px" | ||
mt="3px" | ||
> | ||
<DmIcon | ||
icon={icon} | ||
icon_state={icon_state} | ||
height="64px" | ||
width="64px" | ||
mb={1} | ||
mt={1} | ||
fallback={<Loader />} | ||
/> | ||
<Box position="absolute" bottom="0px"> | ||
{cost} | ||
</Box> | ||
</Button> | ||
</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,7 @@ | ||
.theme-crtblue { | ||
.LoadoutPicker { | ||
.Stack--horizontal > .ItemPicker:first-of-type { | ||
margin-left: 6px; | ||
} | ||
} | ||
} |
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