From 797efc3ebef41f90d5e608397a2770a71cf6fb86 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 4 Aug 2022 16:48:19 +0200 Subject: [PATCH] [MIRROR] Improves stack recipe UI Search [MDB IGNORE] (#15367) * Improves stack recipe UI Search (#68780) * Improves stack recipe ui search * Changes Stack interface to be called StackCrafting * Improves stack recipe UI Search Co-authored-by: Tastyfish --- code/game/objects/items/stacks/stack.dm | 2 +- tgui/packages/tgui/interfaces/Stack.js | 181 ------------- .../tgui/interfaces/StackCrafting.tsx | 249 ++++++++++++++++++ 3 files changed, 250 insertions(+), 182 deletions(-) delete mode 100644 tgui/packages/tgui/interfaces/Stack.js create mode 100644 tgui/packages/tgui/interfaces/StackCrafting.tsx diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index b67c15f12cf..982272eeb97 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -262,7 +262,7 @@ /obj/item/stack/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) if(!ui) - ui = new(user, src, "Stack", name) + ui = new(user, src, "StackCrafting", name) ui.open() /obj/item/stack/ui_data(mob/user) diff --git a/tgui/packages/tgui/interfaces/Stack.js b/tgui/packages/tgui/interfaces/Stack.js deleted file mode 100644 index 3cfef42aabe..00000000000 --- a/tgui/packages/tgui/interfaces/Stack.js +++ /dev/null @@ -1,181 +0,0 @@ -import { createSearch } from 'common/string'; -import { sortBy } from 'common/collections'; -import { useBackend, useLocalState } from '../backend'; -import { Box, Button, Input, NoticeBox, Section, Collapsible, Table } from '../components'; -import { Window } from '../layouts'; - -export const Stack = (props, context) => { - const { act, data } = useBackend(context); - - const { amount, recipes = [] } = data; - - const [searchText, setSearchText] = useLocalState(context, 'searchText', ''); - - const testSearch = createSearch(searchText, (item) => { - return item; - }); - - const items = - (searchText.length > 0 && - Object.keys(recipes) - .filter(testSearch) - .reduce((obj, key) => { - obj[key] = recipes[key]; - return obj; - }, {})) || - recipes; - - const height = Math.max(94 + Object.keys(recipes).length * 26, 250); - - return ( - - -
- Search - setSearchText(value)} - mx={1} - /> - - }> - {(items.length === 0 && No recipes found.) || ( - - )} -
-
-
- ); -}; - -const RecipeList = (props, context) => { - const { act, data } = useBackend(context); - - const { recipes } = props; - - const sortedKeys = sortBy((key) => key.toLowerCase())(Object.keys(recipes)); - - return sortedKeys.map((title) => { - const recipe = recipes[title]; - if (recipe.ref === undefined) { - return ( - - - - - - ); - } else { - return ; - } - }); -}; - -const buildMultiplier = (recipe, amount) => { - if (recipe.req_amount > amount) { - return 0; - } - - return Math.floor(amount / recipe.req_amount); -}; - -const Multipliers = (props, context) => { - const { act, data } = useBackend(context); - - const { recipe, maxMultiplier } = props; - - const maxM = Math.min( - maxMultiplier, - Math.floor(recipe.max_res_amount / recipe.res_amount) - ); - - const multipliers = [5, 10, 25]; - - let finalResult = []; - - for (const multiplier of multipliers) { - if (maxM >= multiplier) { - finalResult.push( -