-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/update-gdd' into develop
- Loading branch information
Showing
15 changed files
with
325 additions
and
22 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
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,98 @@ | ||
import React, { useCallback } from 'react' | ||
import { ParsedValueInput } from './parsedValueInput' | ||
|
||
export const PercentageInput: React.FC< | ||
( | ||
| { | ||
currentValue: number | undefined | ||
onChange: (newValue: number | undefined) => void | ||
allowUndefined: true | ||
} | ||
| { | ||
currentValue: number | ||
onChange: (newValue: number) => void | ||
allowUndefined: false | ||
defaultValue: number | ||
} | ||
) & { | ||
indeterminate?: boolean | ||
emptyPlaceholder?: string | ||
label?: React.ReactNode | ||
focusTooltip?: string | ||
disabled?: boolean | ||
fullWidth?: boolean | ||
width?: string | ||
tooltip?: string | ||
endAdornment?: React.ReactNode | ||
} | ||
> = (props) => { | ||
const onIncrement = useCallback((value: number | undefined | null, inc: number) => { | ||
value = (value ?? 0) + inc / 100 | ||
value = Math.round(value * 100000) / 100000 // fix any rounding errors | ||
value = Math.max(0, value) | ||
return value | ||
}, []) | ||
|
||
if (props.allowUndefined) { | ||
return ParsedValueInput<number | undefined>( | ||
props.currentValue, | ||
props.indeterminate, | ||
props.onChange, | ||
undefined, | ||
(str: string) => parsePercentage(str) ?? undefined, | ||
formatPercentage, | ||
props.label, | ||
props.emptyPlaceholder, | ||
'text', | ||
props.disabled, | ||
props.fullWidth, | ||
props.width, | ||
undefined, | ||
onIncrement, | ||
props.endAdornment, | ||
props.tooltip, | ||
props.focusTooltip | ||
) | ||
} else { | ||
return ParsedValueInput<number>( | ||
props.currentValue, | ||
props.indeterminate, | ||
props.onChange, | ||
props.defaultValue, | ||
(str: string) => parsePercentage(str) ?? undefined, | ||
formatPercentage, | ||
props.label, | ||
props.emptyPlaceholder, | ||
'text', | ||
props.disabled, | ||
props.fullWidth, | ||
props.width, | ||
undefined, | ||
onIncrement, | ||
props.endAdornment, | ||
props.tooltip, | ||
props.focusTooltip | ||
) | ||
} | ||
} | ||
|
||
function parsePercentage(str: string): number | undefined { | ||
str = str + '' | ||
if (str === '') return undefined | ||
str = str.replace(/,/, '.') | ||
const m = str.match(/([\d,.]+)/) | ||
if (m) { | ||
const percentage = parseFloat(m[1]) | ||
if (!Number.isNaN(percentage)) { | ||
return percentage / 100 | ||
} | ||
} | ||
|
||
return 0 | ||
} | ||
function formatPercentage(inputValue: number | undefined): string { | ||
if (inputValue === undefined) return '' | ||
|
||
const percentage = Math.round(inputValue * 100 * 100000) / 100000 // fix any rounding errors | ||
return `${percentage}%` | ||
} |
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
25 changes: 25 additions & 0 deletions
25
apps/app/src/react/components/sidebar/timelineObj/GDD/GDDTypes/integer-duration-ms.tsx
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,25 @@ | ||
import { GDDTypeDurationMs } from 'graphics-data-definition' | ||
import React from 'react' | ||
import { getEditPropertyMeta, PropertyProps } from '../lib' | ||
import { EditProperty } from '../util' | ||
import { DurationInput } from '../../../../inputs/DurationInput' | ||
|
||
export const gddTypeIntegerMs: React.FC<PropertyProps<GDDTypeDurationMs>> = (props) => { | ||
const data = props.data || '' | ||
const { label, description } = getEditPropertyMeta(props) | ||
return ( | ||
<EditProperty className="gdd-edit-data__gddType__integer-duration-ms" {...props}> | ||
<DurationInput | ||
label={label} | ||
focusTooltip={description} | ||
fullWidth | ||
currentValue={data} | ||
onChange={(v) => { | ||
props.setData(v) | ||
props.onSave() | ||
}} | ||
allowUndefined={true} | ||
/> | ||
</EditProperty> | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/app/src/react/components/sidebar/timelineObj/GDD/GDDTypes/number-percentage.tsx
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,25 @@ | ||
import { GDDTypeDurationMs } from 'graphics-data-definition' | ||
import React from 'react' | ||
import { getEditPropertyMeta, PropertyProps } from '../lib' | ||
import { EditProperty } from '../util' | ||
import { PercentageInput } from '../../../../inputs/PercentageInput' | ||
|
||
export const gddTypePercentage: React.FC<PropertyProps<GDDTypeDurationMs>> = (props) => { | ||
const data = props.data || '' | ||
const { label, description } = getEditPropertyMeta(props) | ||
return ( | ||
<EditProperty className="gdd-edit-data__gddType__integer-duration-ms" {...props}> | ||
<PercentageInput | ||
label={label} | ||
focusTooltip={description} | ||
fullWidth | ||
currentValue={data} | ||
onChange={(v) => { | ||
props.setData(v) | ||
props.onSave() | ||
}} | ||
allowUndefined={true} | ||
/> | ||
</EditProperty> | ||
) | ||
} |
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
82 changes: 82 additions & 0 deletions
82
apps/app/src/react/components/sidebar/timelineObj/GDD/GDDTypes/string-color-rrggbbaa.tsx
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,82 @@ | ||
import { GDDTypeColorRRGGBBAA } from 'graphics-data-definition' | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
import { PropertyProps } from '../lib' | ||
import { EditProperty, WithLabel } from '../util' | ||
|
||
export const gddTypeColorRRGGBBAA: React.FC<PropertyProps<GDDTypeColorRRGGBBAA>> = (props) => { | ||
return <RRGGBBAA {...props} /> | ||
} | ||
export const RRGGBBAA: React.FC<PropertyProps<GDDTypeColorRRGGBBAA>> = (props) => { | ||
const [rgbValue, setRgbValue] = useState(props.data || '') | ||
const [aValue, setAValue] = useState(props.data || '') | ||
const [rgbaValue, setRgbaValue] = useState(props.data || '') | ||
|
||
const storedValue = props.data || '' | ||
useEffect(() => { | ||
let r = 0 | ||
let g = 0 | ||
let b = 0 | ||
let a = 0 | ||
|
||
const m = storedValue.match(/(\w\w)(\w\w)(\w\w)(\w\w)/) | ||
if (m) { | ||
r = parseInt(m[1], 16) | ||
g = parseInt(m[2], 16) | ||
b = parseInt(m[3], 16) | ||
a = parseInt(m[4], 16) | ||
} else { | ||
const m = storedValue.match(/(\w\w)(\w\w)(\w\w)/) | ||
if (m) { | ||
r = parseInt(m[1], 16) | ||
g = parseInt(m[2], 16) | ||
b = parseInt(m[3], 16) | ||
a = 255 | ||
} | ||
} | ||
|
||
const rgbStr = | ||
'#' + r.toString(16).padStart(2, '0') + g.toString(16).padStart(2, '0') + b.toString(16).padStart(2, '0') | ||
const aStr = a.toString(16).padStart(2, '0') | ||
|
||
setRgbValue(rgbStr) | ||
setAValue(aStr) | ||
setRgbaValue(rgbStr + aStr) | ||
}, [storedValue]) | ||
|
||
const setRGB = useCallback( | ||
(rgb: string) => { | ||
props.setData(rgb + aValue) | ||
}, | ||
[props, aValue] | ||
) | ||
const setRGBA = useCallback((rgba: string) => { | ||
setRgbaValue(rgba) | ||
}, []) | ||
const saveRGBA = useCallback(() => { | ||
props.setData(rgbaValue) | ||
props.onSave() | ||
}, [props, rgbaValue]) | ||
|
||
return ( | ||
<EditProperty className="gdd-edit-data__gddType__string-color-rrggbbaa" {...props}> | ||
<WithLabel {...props}> | ||
<input | ||
type="color" | ||
value={rgbValue} | ||
onChange={(e) => { | ||
setRGB(e.target.value) | ||
}} | ||
onBlur={props.onSave} | ||
/> | ||
<input | ||
type="text" | ||
value={rgbaValue} | ||
onChange={(e) => { | ||
setRGBA(e.target.value) | ||
}} | ||
onBlur={saveRGBA} | ||
/> | ||
</WithLabel> | ||
</EditProperty> | ||
) | ||
} |
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
Oops, something went wrong.