-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for per scene and project wide DMG palettes #1601
base: develop
Are you sure you want to change the base?
Changes from 16 commits
0c5dc0b
27c9f71
a840e83
feb87db
5c1579b
8af70eb
b979450
e65305e
491cc10
6f01ceb
0e8ac08
ebbad21
adfdd17
a5b470a
8cd7007
dbb4514
ffcbf8d
7a59195
3237f33
591b584
53209d2
736c0da
1df68d9
d334907
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
backgroundSelectors, | ||
sceneSelectors, | ||
} from "store/features/entities/entitiesState"; | ||
import settingsActions from "store/features/settings/settingsActions"; | ||
import editorActions from "store/features/editor/editorActions"; | ||
import electronActions from "store/features/electron/electronActions"; | ||
import { SceneSelect } from "components/forms/SceneSelect"; | ||
|
@@ -66,7 +67,12 @@ const BackgroundPreviewSettings = ({ | |
); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const [buttonFocus, setButtonFocus] = useState<boolean>(false); | ||
const value = useAppSelector((state) => state.editor.previewAsSceneId); | ||
const value = useAppSelector((state) => { | ||
if (state.project.present.settings.previewAsMono) return "0"; | ||
const sceneId = state.editor.previewAsSceneId; | ||
if (sceneId === "") return "1"; | ||
return sceneId; | ||
}); | ||
const scene = useAppSelector((state) => | ||
sceneSelectors.selectById(state, value) | ||
); | ||
|
@@ -144,6 +150,11 @@ const BackgroundPreviewSettings = ({ | |
}; | ||
|
||
const onChange = (newValue: string) => { | ||
dispatch( | ||
settingsActions.editSettings({ | ||
previewAsMono: (newValue == "0"), | ||
}) | ||
); | ||
dispatch(editorActions.setPreviewAsSceneId(newValue)); | ||
}; | ||
Comment on lines
152
to
159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also using the "preview as" drop down selection to drive the |
||
|
||
|
@@ -173,7 +184,7 @@ const BackgroundPreviewSettings = ({ | |
onBlur={closeMenu} | ||
maxMenuHeight={200} | ||
optional | ||
optionalLabel={l10n("FIELD_DEFAULT_COLORS")} | ||
optionalLabels={[l10n("FIELD_COLOR_MODE_MONO"), l10n("FIELD_DEFAULT_COLORS")]} | ||
{...selectMenuStyleProps} | ||
/> | ||
</SelectMenu> | ||
|
@@ -190,7 +201,8 @@ const BackgroundPreviewSettings = ({ | |
? l10n("FIELD_PREVIEW_AS_SCENE", { | ||
sceneName: sceneName(scene, sceneIndex), | ||
}) | ||
: l10n("FIELD_PREVIEW_AS_DEFAULT")} | ||
: ([l10n("FIELD_PREVIEW_AS_MONO"), l10n("FIELD_PREVIEW_AS_DEFAULT")][+value]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As someone who has never used TypeScript before, I found the |
||
} | ||
</Pill> | ||
<FixedSpacer width={5} /> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ import { ScriptEditorCtx } from "shared/lib/scripts/context"; | |
import { TilesetSelect } from "components/forms/TilesetSelect"; | ||
import { FlexGrow } from "ui/spacing/Spacing"; | ||
import CachedScroll from "ui/util/CachedScroll"; | ||
import { DMGPalettePicker } from "components/forms/DMGPalettePicker"; | ||
|
||
interface SceneEditorProps { | ||
id: string; | ||
|
@@ -149,7 +150,18 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
const [commonTilesetOpen, setCommonTilesetOpen] = useState<boolean>( | ||
!!scene?.tilesetId | ||
); | ||
|
||
const defaultBGP = useAppSelector((state) => | ||
state.project.present.settings.defaultBGP | ||
); | ||
const defaultOBP0 = useAppSelector((state) => | ||
state.project.present.settings.defaultOBP0 | ||
); | ||
const defaultOBP1 = useAppSelector((state) => | ||
state.project.present.settings.defaultOBP1 | ||
); | ||
const monoEnabled = useAppSelector( | ||
(state) => state.project.present.settings.colorMode !== "color" | ||
); | ||
const colorsEnabled = useAppSelector( | ||
(state) => state.project.present.settings.colorMode !== "mono" | ||
); | ||
|
@@ -324,6 +336,24 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
[onChangeSettingProp] | ||
); | ||
|
||
const onEditBGP = useCallback( | ||
(palette: [number, number, number, number]) => | ||
onChangeSceneProp("dmgBGP", palette), | ||
[onChangeSceneProp] | ||
); | ||
|
||
const onEditOBP0 = useCallback( | ||
(palette: [number, number, number, number]) => | ||
onChangeSceneProp("dmgOBP0", palette), | ||
[onChangeSceneProp] | ||
); | ||
|
||
const onEditOBP1 = useCallback( | ||
(palette: [number, number, number, number]) => | ||
onChangeSceneProp("dmgOBP1", palette), | ||
[onChangeSceneProp] | ||
); | ||
|
||
const selectSidebar = () => { | ||
dispatch(editorActions.selectSidebar()); | ||
}; | ||
|
@@ -739,14 +769,14 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
</SidebarColumn> | ||
)} | ||
|
||
{colorsEnabled && ( | ||
<SidebarColumn> | ||
<FormRow> | ||
<FormField | ||
name="playerSpriteSheetId" | ||
label={ | ||
<> | ||
{l10n("FIELD_SCENE_BACKGROUND_PALETTES")} | ||
Comment on lines
-742
to
-749
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that there's a palette to edit even in monochrome mode, I moved the |
||
{l10n("FIELD_SCENE_BACKGROUND_PALETTES")} | ||
{colorsEnabled && ( | ||
<InlineDropdownWrapper> | ||
<DropdownButton | ||
size="small" | ||
|
@@ -784,10 +814,19 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
</MenuItem> | ||
</DropdownButton> | ||
</InlineDropdownWrapper> | ||
)} | ||
</> | ||
} | ||
> | ||
{!background?.autoColor && ( | ||
}> | ||
{monoEnabled && ( | ||
<DMGPalettePicker | ||
name="bgp" | ||
palette={scene.dmgBGP ?? defaultBGP} | ||
isSpritePalette={false} | ||
onChange={onEditBGP} | ||
showName={true} | ||
/> | ||
)} | ||
{colorsEnabled && !background?.autoColor && ( | ||
<PaletteButtons> | ||
{[0, 1, 2, 3, 4, 5, 6, 7].map((index) => ( | ||
<PaletteSelectButton | ||
|
@@ -816,6 +855,25 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
name="playerSpriteSheetId" | ||
label={l10n("FIELD_SCENE_SPRITE_PALETTES")} | ||
> | ||
{monoEnabled && | ||
<PaletteButtons> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
<DMGPalettePicker | ||
name="obp0" | ||
palette={scene.dmgOBP0 ?? defaultOBP0} | ||
isSpritePalette={true} | ||
onChange={onEditOBP0} | ||
showName={true} | ||
/> | ||
<DMGPalettePicker | ||
name="obp1" | ||
palette={scene.dmgOBP1 ?? defaultOBP1} | ||
isSpritePalette={true} | ||
onChange={onEditOBP1} | ||
showName={true} | ||
/> | ||
</PaletteButtons> | ||
} | ||
{colorsEnabled && ( | ||
<PaletteButtons> | ||
{[0, 1, 2, 3, 4, 5, 6, 7].map((index) => ( | ||
<PaletteSelectButton | ||
|
@@ -837,12 +895,12 @@ export const SceneEditor = ({ id }: SceneEditorProps) => { | |
/> | ||
))} | ||
</PaletteButtons> | ||
)} | ||
</FormField> | ||
</FormRow> | ||
|
||
{/* <FormDivider /> */} | ||
</SidebarColumn> | ||
)} | ||
{scene.type !== "LOGO" && ( | ||
<SidebarColumn> | ||
<FormRow> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useCallback } from "react"; | ||
import {useAppSelector } from "store/hooks"; | ||
import { NumberInput } from "ui/form/NumberInput"; | ||
import { castEventToInt } from "renderer/lib/helpers/castEventValue"; | ||
import styled, { css } from "styled-components"; | ||
|
||
type DMGPalettePickerProps = { | ||
name: string | ||
palette: [number, number, number, number] | ||
isSpritePalette: boolean | ||
onChange: (palette: [number, number, number, number]) => void; | ||
showName?: boolean | ||
}; | ||
|
||
export const DMGPalettePicker = ({ | ||
name, | ||
palette, | ||
isSpritePalette, | ||
onChange, | ||
showName | ||
}: DMGPalettePickerProps) => { | ||
|
||
const settings = useAppSelector((state) => state.project.present.settings); | ||
const dmgColors = [settings.customColorsWhite, settings.customColorsLight, settings.customColorsDark, settings.customColorsBlack]; | ||
const fields = isSpritePalette ? [1, 2, 3] : [0, 1, 2, 3]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At one point, I was showing all 4 input boxes for sprites. Then, I realized the lowest two bits are never used anyway and it felt silly to show them. I didn't want to change the underlying data structure from |
||
const width = showName ? `max-width: ${isSpritePalette ? 121 : 245}px;` : "width: 100%"; | ||
const DMGPalettePickerStyle = styled.div` | ||
display: flex; | ||
${width} | ||
box-sizing: border-box; | ||
` | ||
|
||
const DMGPaletteTextStyle = styled.div` | ||
width: 9px; | ||
color: grey; | ||
font-size: 9px; | ||
text-align: center; | ||
transform-origin:50% 50%; | ||
transform: rotate(90deg) translate(-7px,8px); | ||
Comment on lines
+27
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of hacky stuff going on with the styling:
|
||
` | ||
function getRows() { | ||
return fields.map((index) => | ||
<NumberInput | ||
style={{backgroundColor:`#${dmgColors[palette[index]]}`, color:`#${dmgColors[(palette[index]+2)%4]}`}} | ||
id={`${name}_${index}`} | ||
name={`${name}_${index}`} | ||
min={0} | ||
max={3} | ||
value={palette[index]} | ||
onChange={(e) => { | ||
let newPalette = [palette[0], palette[1], palette[2], palette[3]]; | ||
newPalette[index] = castEventToInt(e, 0); | ||
onChange(newPalette as [number, number, number, number]); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
if (showName) return <DMGPalettePickerStyle><DMGPaletteTextStyle>{name.toUpperCase()}</DMGPaletteTextStyle>{getRows()}</DMGPalettePickerStyle>; | ||
else return <DMGPalettePickerStyle>{getRows()}</DMGPalettePickerStyle>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
} from "ui/form/Select"; | ||
import l10n from "shared/lib/lang/l10n"; | ||
import { SingleValue } from "react-select"; | ||
import { useAppSelector } from "store/hooks"; | ||
|
||
interface ObjPaletteSelectProps { | ||
name: string; | ||
|
@@ -21,24 +22,30 @@ interface ObjPaletteOption { | |
colors: string[]; | ||
} | ||
|
||
const options: ObjPaletteOption[] = [ | ||
{ | ||
value: "OBP0", | ||
label: "0: OBP0", | ||
colors: ["E8F8E0", "B0F088", "", "202850"], | ||
}, | ||
{ | ||
value: "OBP1", | ||
label: "1: OBP1", | ||
colors: ["E8F8E0", "509878", "", "202850"], | ||
}, | ||
]; | ||
|
||
export const ObjPaletteSelect: FC<ObjPaletteSelectProps> = ({ | ||
name, | ||
value = "OBP0", | ||
onChange, | ||
}) => { | ||
const settings = useAppSelector((state) => state.project.present.settings); | ||
const obp0 = settings.defaultOBP0; | ||
const obp1 = settings.defaultOBP1; | ||
const dmgPal = [settings.customColorsWhite, settings.customColorsLight, settings.customColorsDark, settings.customColorsBlack]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the custom colors from settings instead of |
||
const obp0Colors = [dmgPal[obp0[1]], dmgPal[obp0[2]], "", dmgPal[obp0[3]]]; | ||
const obp1Colors = [dmgPal[obp1[1]], dmgPal[obp1[2]], "", dmgPal[obp1[3]]]; | ||
const options: ObjPaletteOption[] = [ | ||
{ | ||
value: "OBP0", | ||
label: "0: OBP0", | ||
colors: obp0Colors, | ||
}, | ||
{ | ||
value: "OBP1", | ||
label: "1: OBP1", | ||
colors: obp1Colors, | ||
}, | ||
]; | ||
|
||
const currentValue = options.find((o) => o.value === value); | ||
return ( | ||
<Select | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ interface SceneSelectProps extends SelectCommonProps { | |
name: string; | ||
value?: string; | ||
optional?: boolean; | ||
optionalLabel?: string; | ||
optionalLabels?: string[]; | ||
onChange?: (newId: string) => void; | ||
} | ||
|
||
|
@@ -61,10 +61,11 @@ export const SceneSelect: FC<SceneSelectProps> = ({ | |
value, | ||
onChange, | ||
optional, | ||
optionalLabel, | ||
optionalLabels, | ||
...selectProps | ||
}) => { | ||
const scenes = useAppSelector((state) => sceneSelectors.selectAll(state)); | ||
const optionalScenes = (optionalLabels || []).map((optionalLabel, i) => ({ value: i.toString(), label: optionalLabel }) ) as SceneOption[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there was only one non-scene option, a |
||
const backgroundsLookup = useAppSelector((state) => | ||
backgroundSelectors.selectEntities(state) | ||
); | ||
|
@@ -84,20 +85,9 @@ export const SceneSelect: FC<SceneSelectProps> = ({ | |
}, [scenes]); | ||
|
||
useEffect(() => { | ||
setOptions( | ||
([] as SceneOption[]).concat( | ||
optional | ||
? ([ | ||
{ | ||
value: "", | ||
label: optionalLabel || "None", | ||
}, | ||
] as SceneOption[]) | ||
: ([] as SceneOption[]), | ||
scenes.map(sceneToSceneOption).sort(sortByLabel) | ||
) | ||
); | ||
}, [scenes, optional, optionalLabel]); | ||
const sceneOptions = scenes.map(sceneToSceneOption).sort(sortByLabel); | ||
setOptions(([] as SceneOption[]).concat(optionalScenes, sceneOptions)); | ||
}, [scenes, optional, optionalLabels]); | ||
|
||
useEffect(() => { | ||
setCurrentScene(scenes.find((v) => v.id === value)); | ||
|
@@ -109,6 +99,7 @@ export const SceneSelect: FC<SceneSelectProps> = ({ | |
sceneToSceneOption(currentScene, scenes.indexOf(currentScene)) | ||
); | ||
} | ||
else if (optional && optionalScenes.length > 0) setCurrentValue(optionalScenes[+(value || 1)]); | ||
}, [currentScene, scenes]); | ||
|
||
const onSelectChange = (newValue: SingleValue<Option>) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a mono mode, similar to the one found on the world page, to the "preview as" drop down. Previously, only one non-scene option was available in this drop down, "Default Colors", which was used when
previewAsSceneId
was "". To facilitate more options, I'm just using the stringified index of the non-scene values. To ensure a consistent experience when switching between pages, I set the default state to "0" whenpreviewAsMono
and "1" whenpreviewAsSceneId
is unset.