Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import PaletteBlock from "components/forms/PaletteBlock"; import React, { FC, useMemo } from "react"; import { OptionLabelWithPreview, Select, SingleValueWithPreview, } from "ui/form/Select"; import l10n from "shared/lib/lang/l10n"; import { SingleValue } from "react-select"; import { MonoOBJPalette, ObjPalette } from "shared/lib/resources/types"; import { DMG_PALETTE } from "consts"; interface ObjPaletteSelectProps { name: string; value?: ObjPalette; onChange?: (newValue: ObjPalette) => void; monoPalettes: [MonoOBJPalette, MonoOBJPalette]; } interface ObjPaletteOption { value: ObjPalette; label: string; colors: string[]; } export const ObjPaletteSelect: FC<ObjPaletteSelectProps> = ({ name, value = "OBP0", monoPalettes, onChange, }) => { const options: ObjPaletteOption[] = useMemo(() => { return [ { value: "OBP0", label: "0: OBP0", colors: [ DMG_PALETTE.colors[monoPalettes[0][0]], DMG_PALETTE.colors[monoPalettes[0][1]], "", DMG_PALETTE.colors[monoPalettes[0][2]], ], }, { value: "OBP1", label: "1: OBP1", colors: [ DMG_PALETTE.colors[monoPalettes[1][0]], DMG_PALETTE.colors[monoPalettes[1][1]], "", DMG_PALETTE.colors[monoPalettes[1][2]], ], }, ]; }, [monoPalettes]); const currentValue = options.find((o) => o.value === value); return ( <Select name={name} value={currentValue} options={options} onChange={(newValue: SingleValue<ObjPaletteOption>) => { Iif (newValue) { onChange?.(newValue.value); } }} formatOptionLabel={(option: ObjPaletteOption) => { return ( <OptionLabelWithPreview preview={ <PaletteBlock type="sprite" colors={option.colors} size={20} /> } > {l10n("FIELD_PALETTE")} {option.label} </OptionLabelWithPreview> ); }} components={{ SingleValue: () => ( <SingleValueWithPreview preview={ <PaletteBlock type="sprite" colors={currentValue?.colors || []} size={20} /> } > {l10n("FIELD_PALETTE")} {currentValue?.label} </SingleValueWithPreview> ), }} /> ); }; |