-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIRROR] New Processing Unit UI (#608)
* New Processing Unit UI (#81029) Made a new TGUI for Ore Processing Unit, removed all `updateUsrDialog` calls. * New Processing Unit UI --------- Co-authored-by: Interception&? <[email protected]>
- Loading branch information
1 parent
c18c4c3
commit f437915
Showing
2 changed files
with
243 additions
and
64 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
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,169 @@ | ||
import { toTitleCase } from 'common/string'; | ||
|
||
import { useBackend } from '../backend'; | ||
import { | ||
Box, | ||
Button, | ||
Icon, | ||
Image, | ||
NoticeBox, | ||
Section, | ||
Stack, | ||
Table, | ||
} from '../components'; | ||
import { formatSiUnit } from '../format'; | ||
import { Window } from '../layouts'; | ||
import { Material } from './Fabrication/Types'; | ||
|
||
type IconData = { | ||
id: string; | ||
icon: string; | ||
}; | ||
|
||
type Alloy = { | ||
name: string; | ||
id: string; | ||
}; | ||
|
||
type Data = { | ||
materials: Material[]; | ||
materialIcons: IconData[]; | ||
selectedMaterial: string | null; | ||
alloys: Alloy[]; | ||
alloyIcons: IconData[]; | ||
selectedAlloy: string | null; | ||
state: boolean; | ||
SHEET_MATERIAL_AMOUNT: number; | ||
}; | ||
|
||
export const ProcessingConsole = (props: any) => { | ||
const { act, data } = useBackend<Data>(); | ||
const { state } = data; | ||
|
||
return ( | ||
<Window title="Processing Unit Console" width={580} height={500}> | ||
<Window.Content> | ||
<Stack fill vertical> | ||
<Stack.Item grow basis={0}> | ||
<Stack fill> | ||
<Stack.Item grow={1.2} basis={0}> | ||
<Section fill textAlign="center" title="Materials"> | ||
<MaterialSelection /> | ||
</Section> | ||
</Stack.Item> | ||
<Stack.Item grow basis={0}> | ||
<Section fill title="Alloys" textAlign="center"> | ||
<AlloySelection /> | ||
</Section> | ||
</Stack.Item> | ||
</Stack> | ||
</Stack.Item> | ||
<Stack.Item> | ||
<Button | ||
icon="arrows-spin" | ||
iconSpin={state} | ||
color={state ? 'bad' : 'good'} | ||
textAlign="center" | ||
fontSize={1.25} | ||
py={1} | ||
fluid | ||
bold | ||
onClick={() => act('toggle')} | ||
> | ||
{state ? 'Deactivate' : 'Activate'} | ||
</Button> | ||
</Stack.Item> | ||
</Stack> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; | ||
|
||
const MaterialSelection = (props: any) => { | ||
const { act, data } = useBackend<Data>(); | ||
const { materials, materialIcons, selectedMaterial, SHEET_MATERIAL_AMOUNT } = | ||
data; | ||
|
||
return materials.length > 0 ? ( | ||
<Table> | ||
{materials.map((material) => ( | ||
<DisplayRow | ||
key={material.name} | ||
name={material.name} | ||
icon={materialIcons.find((icon) => icon.id === material.ref)?.icon} | ||
amount={Math.floor(material.amount / SHEET_MATERIAL_AMOUNT)} | ||
selected={selectedMaterial === material.name} | ||
onSelect={() => act('setMaterial', { value: material.ref })} | ||
/> | ||
))} | ||
</Table> | ||
) : ( | ||
<NoticeBox danger>No material recipes found!</NoticeBox> | ||
); | ||
}; | ||
|
||
const AlloySelection = (props: any) => { | ||
const { act, data } = useBackend<Data>(); | ||
const { alloys, alloyIcons, selectedAlloy } = data; | ||
|
||
return alloys.length > 0 ? ( | ||
<Table> | ||
{alloys.map((alloy) => ( | ||
<DisplayRow | ||
key={alloy.id} | ||
name={alloy.name} | ||
icon={alloyIcons.find((icon) => icon.id === alloy.id)?.icon} | ||
selected={selectedAlloy === alloy.id} | ||
onSelect={() => act('setAlloy', { value: alloy.id })} | ||
/> | ||
))} | ||
</Table> | ||
) : ( | ||
<NoticeBox danger>No alloy recipes found!</NoticeBox> | ||
); | ||
}; | ||
|
||
type DisplayRowProps = { | ||
name: string; | ||
icon?: string; | ||
amount?: number; | ||
selected: boolean; | ||
onSelect: () => void; | ||
}; | ||
|
||
const DisplayRow = (props: DisplayRowProps) => { | ||
const { name, icon, amount, selected, onSelect } = props; | ||
|
||
return ( | ||
<Table.Row collapsing className="candystripe"> | ||
<Table.Cell collapsing pl={1}> | ||
{icon ? ( | ||
<Image | ||
m={1} | ||
width="24px" | ||
height="24px" | ||
verticalAlign="middle" | ||
src={`data:image/jpeg;base64,${icon}`} | ||
/> | ||
) : ( | ||
<Icon name="circle-question" verticalAlign="middle" /> | ||
)} | ||
</Table.Cell> | ||
<Table.Cell collapsing textAlign="left"> | ||
{toTitleCase(name)} | ||
</Table.Cell> | ||
{amount !== undefined ? ( | ||
<Box color="label"> | ||
{`${formatSiUnit(amount, 0)} ${amount === 1 ? 'sheet' : 'sheets'}`} | ||
</Box> | ||
) : null} | ||
<Table.Cell collapsing pr={1} textAlign="right"> | ||
<Button.Checkbox | ||
color="transparent" | ||
checked={selected} | ||
onClick={() => onSelect()} | ||
/> | ||
</Table.Cell> | ||
</Table.Row> | ||
); | ||
}; |