Group fields inside some object editors to make it easier to find them and quickly understand their usage

This commit is contained in:
Florian Rival
2022-01-22 19:49:52 +00:00
parent 95d78521d2
commit e583556a4d
6 changed files with 63 additions and 32 deletions

View File

@@ -67,19 +67,22 @@ module.exports = {
.getOrCreate('color')
.setValue(objectContent.color)
.setType('color')
.setLabel(_('Base color'));
.setLabel(_('Base color'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('opacity')
.setValue(objectContent.opacity.toString())
.setType('number')
.setLabel(_('Opacity (0-255)'));
.setLabel(_('Opacity (0-255)'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('fontSize')
.setValue(objectContent.fontSize.toString())
.setType('number')
.setLabel(_('Base size'));
.setLabel(_('Base size'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('align')
@@ -88,26 +91,30 @@ module.exports = {
.addExtraInfo('left')
.addExtraInfo('center')
.addExtraInfo('right')
.setLabel(_('Base alignment'));
.setLabel(_('Base alignment'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('fontFamily')
.setValue(objectContent.fontFamily)
.setType('resource')
.addExtraInfo('font')
.setLabel(_('Base font family'));
.setLabel(_('Font'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('wordWrap')
.setValue(objectContent.wordWrap ? 'true' : 'false')
.setType('boolean')
.setLabel(_('Word wrapping'));
.setLabel(_('Word wrapping'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('visible')
.setValue(objectContent.visible ? 'true' : 'false')
.setType('boolean')
.setLabel(_('Visible on start'));
.setLabel(_('Visible on start'))
.setGroup(_("Appearance"));
return objectProperties;
};

View File

@@ -67,7 +67,8 @@ module.exports = {
.getOrCreate('opacity')
.setValue(objectContent.opacity.toString())
.setType('number')
.setLabel(_('Opacity (0-255)'));
.setLabel(_('Opacity (0-255)'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('align')
@@ -76,7 +77,8 @@ module.exports = {
.addExtraInfo('left')
.addExtraInfo('center')
.addExtraInfo('right')
.setLabel(_('Alignment, when multiple lines are displayed'));
.setLabel(_('Alignment, when multiple lines are displayed'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('bitmapFontResourceName')
@@ -96,19 +98,22 @@ module.exports = {
.getOrCreate('scale')
.setValue(objectContent.scale.toString())
.setType('number')
.setLabel(_('Text scale'));
.setLabel(_('Text scale'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('tint')
.setValue(objectContent.tint)
.setType('color')
.setLabel(_('Font tint'));
.setLabel(_('Font tint'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('wordWrap')
.setValue(objectContent.wordWrap ? 'true' : 'false')
.setType('boolean')
.setLabel(_('Word wrapping'));
.setLabel(_('Word wrapping'))
.setGroup(_("Appearance"));
return objectProperties;
};

View File

@@ -132,6 +132,7 @@ module.exports = {
'When activated, display the lines used to render the light - useful to understand how the light is rendered on screen.'
)
)
.setGroup(_("Advanced"))
);
objectProperties

View File

@@ -86,6 +86,7 @@ module.exports = {
.setDescription(
_('This is the JSON file that was saved or exported from Tiled.')
)
.setGroup(_("Tilemap and tileset"))
);
objectProperties.set(
'tilesetJsonFile',
@@ -98,6 +99,7 @@ module.exports = {
"Optional, don't specify it if you've not saved the tileset in a different file."
)
)
.setGroup(_("Tilemap and tileset"))
);
objectProperties.set(
'tilemapAtlasImage',
@@ -105,6 +107,7 @@ module.exports = {
.setType('resource')
.addExtraInfo('image')
.setLabel(_('Atlas image'))
.setGroup(_("Tilemap and tileset"))
);
objectProperties.set(
'displayMode',
@@ -114,6 +117,7 @@ module.exports = {
.addExtraInfo('all')
.addExtraInfo('index')
.setLabel(_('Display mode'))
.setGroup(_("Appearance"))
);
objectProperties.set(
'layerIndex',
@@ -125,18 +129,21 @@ module.exports = {
'If "index" is selected as the display mode, this is the index of the layer to display.'
)
)
.setGroup(_("Appearance"))
);
objectProperties.set(
'animationSpeedScale',
new gd.PropertyDescriptor(objectContent.animationSpeedScale.toString())
.setType('number')
.setLabel(_('Animation speed scale'))
.setGroup(_("Animation"))
);
objectProperties.set(
'animationFps',
new gd.PropertyDescriptor(objectContent.animationFps.toString())
.setType('number')
.setLabel(_('Animation FPS'))
.setGroup(_("Animation"))
);
return objectProperties;

View File

@@ -69,17 +69,20 @@ module.exports = {
.getOrCreate('Opacity')
.setValue(objectContent.opacity.toString())
.setType('number')
.setLabel(_('Video opacity (0-255)'));
.setLabel(_('Video opacity (0-255)'))
.setGroup(_("Appearance"));
objectProperties
.getOrCreate('Looped')
.setValue(objectContent.loop ? 'true' : 'false')
.setType('boolean')
.setLabel(_('Loop the video'));
.setLabel(_('Loop the video'))
.setGroup(_("Playback settings"));
objectProperties
.getOrCreate('Volume')
.setValue(objectContent.volume.toString())
.setType('number')
.setLabel(_('Video volume (0-100)'));
.setLabel(_('Video volume (0-100)'))
.setGroup(_("Playback settings"));
objectProperties
.getOrCreate('videoResource')
.setValue(objectContent.videoResource)

View File

@@ -108,8 +108,7 @@ export type Field =
// The schema is the tree of all fields.
export type Schema = Array<Field>;
// Mandatory props in any case when using the component
type MandatoryProps = {|
type Props = {|
onInstancesModified?: Instances => void,
instances: Instances,
schema: Schema,
@@ -119,19 +118,13 @@ type MandatoryProps = {|
// (see getExtraDescription).
renderExtraDescriptionText?: (extraDescription: string) => string,
unsavedChanges?: ?UnsavedChanges,
|};
type Props =
// Mandatory props in all cases:
| MandatoryProps
// Props to be used when you want to display resources:
| {|
...MandatoryProps,
project: gdProject,
resourceSources: Array<ResourceSource>,
onChooseResource: ChooseResourceFunction,
resourceExternalEditors: Array<ResourceExternalEditor>,
|};
// Optional context:
project?: ?gdProject,
resourceSources?: ?Array<ResourceSource>,
onChooseResource?: ?ChooseResourceFunction,
resourceExternalEditors?: ?Array<ResourceExternalEditor>,
|};
const styles = {
columnContainer: {
@@ -446,11 +439,16 @@ export default class PropertiesEditor extends React.Component<Props, {||}> {
};
_renderResourceField = (field: ResourceField) => {
if (!this.props.project) {
if (
!this.props.project ||
!this.props.resourceSources ||
!this.props.onChooseResource ||
!this.props.resourceExternalEditors
) {
console.error(
'You tried to display a resource field in a PropertiesEditor that does not support display resources. If you need to display resources, pass additional props (project, resourceSources, etc...)'
'You tried to display a resource field in a PropertiesEditor that does not support display resources. If you need to display resources, pass additional props (project, resourceSources, onChooseResource, resourceExternalEditors).'
);
return;
return null;
}
const { setValue } = field;
@@ -504,6 +502,10 @@ export default class PropertiesEditor extends React.Component<Props, {||}> {
<UnsavedChangesContext.Consumer key={field.name}>
{unsavedChanges => (
<PropertiesEditor
project={this.props.project}
resourceSources={this.props.resourceSources}
onChooseResource={this.props.onChooseResource}
resourceExternalEditors={this.props.resourceExternalEditors}
schema={field.children}
instances={this.props.instances}
mode="row"
@@ -531,6 +533,12 @@ export default class PropertiesEditor extends React.Component<Props, {||}> {
<UnsavedChangesContext.Consumer key={field.name}>
{unsavedChanges => (
<PropertiesEditor
project={this.props.project}
resourceSources={this.props.resourceSources}
onChooseResource={this.props.onChooseResource}
resourceExternalEditors={
this.props.resourceExternalEditors
}
schema={field.children}
instances={this.props.instances}
mode="column"