-
Notifications
You must be signed in to change notification settings - Fork 1
Update Night Sky Panel's Markings tab + Small Sun Tab refactor #207
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
base: master
Are you sure you want to change the base?
Changes from all commits
99993ac
ac625bb
cf03255
fc58b88
1ef5591
cf16098
39f0b53
6d193db
47b5b30
da83af6
4e9eabd
68bdb17
f9f94b8
fab388d
233ae07
713b70b
d643bb4
ab53467
601ddb8
b33137d
06a1975
eff704e
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |||||||||||||||||
| }, | ||||||||||||||||||
| "markings": { | ||||||||||||||||||
| "common-button-labels": { | ||||||||||||||||||
| "hide-all": "Hide All", | ||||||||||||||||||
| "hide-all": "Hide all", | ||||||||||||||||||
| "grid": "Grid", | ||||||||||||||||||
| "labels": "Labels", | ||||||||||||||||||
| "line_one": "Line", | ||||||||||||||||||
|
|
@@ -45,15 +45,18 @@ | |||||||||||||||||
| "cardinal-directions": { | ||||||||||||||||||
| "title": "Cardinal Directions", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "directions": "Directions", | ||||||||||||||||||
| "small": "Small", | ||||||||||||||||||
| "large": "Large", | ||||||||||||||||||
| "marks": "Marks" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "aria-labels": { | ||||||||||||||||||
| "small": "Show cardinal directions (small)", | ||||||||||||||||||
| "large": "Show cardianl directions (large)", | ||||||||||||||||||
| "toggle": "Toggle cardinal directions' size", | ||||||||||||||||||
| "marks": "Show marks on cardinal directions" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "scene-graph-node-toggle": { | ||||||||||||||||||
| "aria-label": "Toggle {{name}} visibility" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "location": { | ||||||||||||||||||
|
|
@@ -93,28 +96,28 @@ | |||||||||||||||||
| "trails": { | ||||||||||||||||||
| "title": "Trails", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "hide-trails": "Hide all Trails", | ||||||||||||||||||
| "show-planet-trails": "Show Planet Trails" | ||||||||||||||||||
| "hide-trails": "Hide all trails", | ||||||||||||||||||
| "show-planet-trails": "Show planet trails" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "labels": { | ||||||||||||||||||
| "title": "Labels", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "show-labels": "Show Labels", | ||||||||||||||||||
| "hide-labels": "Hide Labels" | ||||||||||||||||||
| "show-labels": "Show labels", | ||||||||||||||||||
| "hide-labels": "Hide labels" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "planets": { | ||||||||||||||||||
| "title": "Planets", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "show-planets": "Show Night Sky Planets", | ||||||||||||||||||
| "hide-planets": "Hide Night Sky Planets" | ||||||||||||||||||
| "show-planets": "Show night sky planets", | ||||||||||||||||||
| "hide-planets": "Hide night sky planets" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "moon": { | ||||||||||||||||||
| "title": "Moon", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "default-scale": "Default Moon Scale (1x)", | ||||||||||||||||||
| "default-scale": "Default Moon scale (1x)", | ||||||||||||||||||
| "2x-scale": "Enlarge Moon (2x)", | ||||||||||||||||||
| "4x-scale": "Enlarge Moon (4x)" | ||||||||||||||||||
| }, | ||||||||||||||||||
|
|
@@ -127,7 +130,7 @@ | |||||||||||||||||
| "moon-shading-settings": "Could not find Moon Perform Shading settings" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "show-phase-input": { | ||||||||||||||||||
| "title": "Show Phase", | ||||||||||||||||||
| "title": "Show phase", | ||||||||||||||||||
| "tooltip": "Uncheck this to always show the full moon. This is equivalent to 'Perform Shading' property on the Moon." | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -136,7 +139,7 @@ | |||||||||||||||||
| "visibility": { | ||||||||||||||||||
| "title": "Visibility", | ||||||||||||||||||
| "input": { | ||||||||||||||||||
| "show-stars": "Show Stars", | ||||||||||||||||||
| "show-stars": "Show stars", | ||||||||||||||||||
| "show-during-day": { | ||||||||||||||||||
| "label": "Show during Day", | ||||||||||||||||||
|
Member
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.
Suggested change
|
||||||||||||||||||
| "tooltip": "Check this box to show the stars during daytime" | ||||||||||||||||||
|
|
@@ -146,8 +149,8 @@ | |||||||||||||||||
| "labels": { | ||||||||||||||||||
| "title": "Labels", | ||||||||||||||||||
| "input": { | ||||||||||||||||||
| "show-labels": "Show Labels", | ||||||||||||||||||
| "show-alternate-labels": "Show Alternate Labels" | ||||||||||||||||||
| "show-labels": "Show labels", | ||||||||||||||||||
| "show-alternate-labels": "Show alternate labels" | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| "appearance": { | ||||||||||||||||||
|
|
@@ -172,10 +175,11 @@ | |||||||||||||||||
| }, | ||||||||||||||||||
| "size": { | ||||||||||||||||||
| "title": "Size", | ||||||||||||||||||
| "description": "Adjust the Sun's angular size on the sky.", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "default-size": "Default Angular Size", | ||||||||||||||||||
| "large-size": "Large Angular Size", | ||||||||||||||||||
| "extra-large-size": "Extra Large Angular Size" | ||||||||||||||||||
| "default-size": "Default", | ||||||||||||||||||
| "large-size": "Large", | ||||||||||||||||||
| "extra-large-size": "Extra large" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "aria-labels": { | ||||||||||||||||||
| "increase-size": "Increase angular size", | ||||||||||||||||||
|
|
@@ -186,10 +190,10 @@ | |||||||||||||||||
| "trails": { | ||||||||||||||||||
| "title": "Trails", | ||||||||||||||||||
| "buttons": { | ||||||||||||||||||
| "add-trail": "Add Trail", | ||||||||||||||||||
| "add-trail-simulation-date": "Add Trail for Simulation Date", | ||||||||||||||||||
| "add-trail-today": "Add Trail for Today", | ||||||||||||||||||
| "hide-trails": "Hide All" | ||||||||||||||||||
| "add-trail": "Add trail", | ||||||||||||||||||
| "add-trail-simulation-date": "Add trail for Simulation Date", | ||||||||||||||||||
| "add-trail-today": "Add trail for Today", | ||||||||||||||||||
|
Comment on lines
+194
to
+195
Member
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.
Suggested change
?
Member
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.
Suggested change
Alternative suggestion to make it more clear that that is the important part of the sentence |
||||||||||||||||||
| "hide-trails": "Hide all" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "choose-date": "Choose Date", | ||||||||||||||||||
| "added-trails": { | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .card:active { | ||
| transform: translateY(2px); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { PropsWithChildren, useEffect, useState } from 'react'; | ||
| import { Checkbox, CheckboxCardProps } from '@mantine/core'; | ||
|
|
||
| import styles from './ToggleCard.module.css'; | ||
|
|
||
| interface Props extends CheckboxCardProps, PropsWithChildren { | ||
| onClick: () => void; | ||
| checked: boolean; | ||
| } | ||
|
|
||
| export function ToggleCard({ onClick, checked, children, ...other }: Props) { | ||
| const [checkedState, setCheckedState] = useState(checked); | ||
|
|
||
| function handleClick() { | ||
| setCheckedState(!checkedState); | ||
| onClick(); | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| setCheckedState(checked); | ||
| }, [checked]); | ||
|
|
||
| return ( | ||
| <Checkbox.Card | ||
| classNames={styles} | ||
| checked={checkedState} | ||
| onClick={handleClick} | ||
| bg={checkedState ? 'blue' : 'dark.8'} | ||
| role={'switch'} | ||
| aria-checked={checkedState} | ||
| style={{ fontWeight: checkedState ? '500' : undefined }} | ||
| {...other} | ||
| > | ||
| {children} | ||
| </Checkbox.Card> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import { useCallback, useEffect, useState } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { | ||
| Box, | ||
| Group, | ||
| SegmentedControl, | ||
| Skeleton, | ||
| Stack, | ||
| Switch, | ||
| Text | ||
| } from '@mantine/core'; | ||
|
|
||
| import { useOpenSpaceApi } from '@/api/hooks'; | ||
| import { useProperty } from '@/hooks/properties'; | ||
| import { CompassSmallIcon, LetterAIcon, LetterASmallIcon } from '@/icons/icons'; | ||
| import { IconSize } from '@/types/enums'; | ||
|
|
||
| import { SceneGraphNodeToggle } from './SceneGraphNodeToggle'; | ||
|
|
||
| // @TODO (2025-05-19, emmbr) These checks, especially against the parts of the texture | ||
| // file names, are fragile agains file name changes. Consider more robust solution | ||
| const Data = { | ||
| small: { | ||
| showAction: 'os.nightsky.ShowNeswLettersSmall', | ||
| hideAction: 'os.nightsky.HideNesw', | ||
| textureCheck: 'red_small.png' | ||
| }, | ||
| large: { | ||
| showAction: 'os.nightsky.ShowNeswLetters', | ||
| hideAction: 'os.nightsky.HideNesw', | ||
| textureCheck: 'red.png' | ||
| }, | ||
| marks: { | ||
| showAction: 'os.nightsky.AddNeswBandMarks', | ||
| hideAction: 'os.nightsky.RemoveNeswBandMarks', | ||
| textureCheck: '_lines_' | ||
| } | ||
| }; | ||
|
|
||
| // @TODO (2025-05-19, emmbr) This component needs logic for checking if the used actions | ||
| // exist. However, for this we need to be able to access the actions state using the | ||
| // identifier of the action, so leaving for now | ||
|
|
||
| export function CardinalDirections() { | ||
| const { t } = useTranslation('panel-nightsky', { | ||
| keyPrefix: 'markings.cardinal-directions' | ||
| }); | ||
|
|
||
| const [sizeToggleValue, setSizeToggle] = useState<'small' | 'large' | undefined>( | ||
| undefined | ||
| ); | ||
|
|
||
| const luaApi = useOpenSpaceApi(); | ||
|
|
||
| const [texture] = useProperty( | ||
| 'StringProperty', | ||
| 'Scene.CardinalDirectionSphere.Renderable.Texture' | ||
| ); | ||
|
|
||
| const isTextureOn = useCallback( | ||
| (variant: keyof typeof Data): boolean => { | ||
| if (!texture) { | ||
| return false; | ||
| } | ||
| return texture.includes(Data[variant].textureCheck); | ||
| }, | ||
| [texture] | ||
| ); | ||
|
|
||
| const currentToggle = useCallback((): 'small' | 'large' | undefined => { | ||
| if (isTextureOn('small')) { | ||
| return 'small'; | ||
| } | ||
| if (isTextureOn('large')) { | ||
| return 'large'; | ||
| } | ||
| return undefined; | ||
| }, [isTextureOn]); | ||
|
|
||
| useEffect(() => { | ||
| if (texture) { | ||
| setSizeToggle(currentToggle()); | ||
| } | ||
| }, [texture, setSizeToggle, currentToggle]); | ||
|
|
||
| function sizeToggleLabel(text: string, icon: React.JSX.Element) { | ||
| return ( | ||
| <Stack gap={0} py={2} align={'center'}> | ||
| {icon} | ||
| <Text>{text}</Text> | ||
| </Stack> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Skeleton visible={!texture}> | ||
| <Group> | ||
| <Box w={100}> | ||
| <SceneGraphNodeToggle | ||
| title={t('buttons.directions')} | ||
| icon={<CompassSmallIcon size={IconSize.sm} />} | ||
| identifier={'CardinalDirectionSphere'} | ||
| /> | ||
| </Box> | ||
|
|
||
| <SegmentedControl | ||
| onChange={(value: string) => { | ||
| switch (value) { | ||
| case 'small': | ||
| luaApi?.action.triggerAction(Data['small'].showAction); | ||
| if (isTextureOn('marks')) { | ||
| // The action for showing the small letters also hides the marks, so we | ||
| // need to show them again if they were enabled before | ||
| luaApi?.action.triggerAction(Data['marks'].showAction); | ||
| } | ||
| setSizeToggle('small'); | ||
| break; | ||
| case 'large': | ||
| luaApi?.action.triggerAction(Data['large'].showAction); | ||
| if (isTextureOn('marks')) { | ||
| // The action for showing the large letters also hides the marks, so we | ||
| // need to show them again if they were enabled before | ||
| luaApi?.action.triggerAction(Data['marks'].showAction); | ||
| } | ||
| setSizeToggle('large'); | ||
| break; | ||
| default: | ||
| setSizeToggle(undefined); | ||
| break; | ||
| } | ||
| }} | ||
|
Comment on lines
+107
to
+131
Member
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. Should this be its own function instead? |
||
| value={sizeToggleValue} | ||
| data={[ | ||
| { | ||
| value: 'small', | ||
| label: sizeToggleLabel( | ||
| t('buttons.small'), | ||
| <LetterASmallIcon size={IconSize.sm} /> | ||
| ) | ||
| }, | ||
| { | ||
| value: 'large', | ||
| label: sizeToggleLabel( | ||
| t('buttons.large'), | ||
| <LetterAIcon size={IconSize.sm} /> | ||
| ) | ||
| } | ||
| ]} | ||
| aria-label={t('aria-labels.toggle')} | ||
| /> | ||
| <Switch | ||
| checked={isTextureOn('marks')} | ||
| onChange={(event) => | ||
| luaApi?.action.triggerAction( | ||
| event.target.checked ? Data['marks'].showAction : Data['marks'].hideAction | ||
| ) | ||
|
Comment on lines
+153
to
+156
Member
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. Should be wrapped with in a function body right? |
||
| } | ||
| label={t('buttons.marks')} | ||
| aria-label={t('aria-labels.marks')} | ||
| /> | ||
| </Group> | ||
| </Skeleton> | ||
| ); | ||
| } | ||
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.