Skip to content

Commit

Permalink
Hide deprecated properties of the platformer character behind a button (
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H authored Jan 17, 2024
1 parent 16e2d8a commit f623b35
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Core/GDCore/Project/PropertyDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void PropertyDescriptor::SerializeTo(SerializerElement& element) const {
extraInformationElement.AddChild("").SetStringValue(information);
}
element.AddChild("hidden").SetBoolValue(hidden);
element.AddChild("deprecated").SetBoolValue(deprecated);
}

void PropertyDescriptor::UnserializeFrom(const SerializerElement& element) {
Expand Down Expand Up @@ -58,6 +59,9 @@ void PropertyDescriptor::UnserializeFrom(const SerializerElement& element) {
hidden = element.HasChild("hidden")
? element.GetChild("hidden").GetBoolValue()
: false;
deprecated = element.HasChild("deprecated")
? element.GetChild("deprecated").GetBoolValue()
: false;
}

void PropertyDescriptor::SerializeValuesTo(SerializerElement& element) const {
Expand Down
22 changes: 20 additions & 2 deletions Core/GDCore/Project/PropertyDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ class GD_CORE_API PropertyDescriptor {
* \param propertyValue The value of the property.
*/
PropertyDescriptor(gd::String propertyValue)
: currentValue(propertyValue), type("string"), label(""), hidden(false), measurementUnit(gd::MeasurementUnit::GetUndefined()) {}
: currentValue(propertyValue), type("string"), label(""), hidden(false),
deprecated(false),
measurementUnit(gd::MeasurementUnit::GetUndefined()) {}

/**
* \brief Empty constructor creating an empty property to be displayed.
*/
PropertyDescriptor() : hidden(false), measurementUnit(gd::MeasurementUnit::GetUndefined()) {};
PropertyDescriptor()
: hidden(false), deprecated(false),
measurementUnit(gd::MeasurementUnit::GetUndefined()){};

/**
* \brief Destructor
Expand Down Expand Up @@ -142,6 +146,19 @@ class GD_CORE_API PropertyDescriptor {
*/
bool IsHidden() const { return hidden; }

/**
* \brief Set if the property is deprecated.
*/
PropertyDescriptor& SetDeprecated(bool enable = true) {
deprecated = enable;
return *this;
}

/**
* \brief Check if the property is deprecated.
*/
bool IsDeprecated() const { return deprecated; }

/** \name Serialization
*/
///@{
Expand Down Expand Up @@ -179,6 +196,7 @@ class GD_CORE_API PropertyDescriptor {
///< choices, if a property is a displayed as a combo
///< box.
bool hidden;
bool deprecated;
gd::MeasurementUnit measurementUnit; //< The unit of measurement of the property vale.
};

Expand Down
4 changes: 3 additions & 1 deletion Extensions/PlatformBehavior/PlatformerObjectBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ PlatformerObjectBehavior::GetProperties(
properties["UseLegacyTrajectory"]
.SetLabel(_("Use frame rate dependent trajectories (deprecated, it's "
"recommended to leave this unchecked)"))
.SetGroup(_("Deprecated options (advanced)"))

.SetGroup(_("Deprecated options"))
.SetDeprecated()
.SetValue(behaviorContent.GetBoolAttribute("useLegacyTrajectory", true)
? "true"
: "false")
Expand Down
4 changes: 3 additions & 1 deletion GDevelop.js/Bindings/Bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,11 @@ interface PropertyDescriptor {
[Ref] PropertyDescriptor SetExtraInfo([Const, Ref] VectorString info);
[Ref] VectorString GetExtraInfo();
[Ref] PropertyDescriptor SetHidden(boolean enable);
boolean IsHidden();
[Ref] PropertyDescriptor SetDeprecated(boolean enable);
boolean IsDeprecated();
[Const, Ref] MeasurementUnit GetMeasurementUnit();
[Ref] PropertyDescriptor SetMeasurementUnit([Const, Ref] MeasurementUnit measurementUnit);
boolean IsHidden();

void SerializeTo([Ref] SerializerElement element);
void UnserializeFrom([Const, Ref] SerializerElement element);
Expand Down
4 changes: 3 additions & 1 deletion GDevelop.js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,11 @@ export class PropertyDescriptor extends EmscriptenObject {
setExtraInfo(info: VectorString): PropertyDescriptor;
getExtraInfo(): VectorString;
setHidden(enable: boolean): PropertyDescriptor;
isHidden(): boolean;
setDeprecated(enable: boolean): PropertyDescriptor;
isDeprecated(): boolean;
getMeasurementUnit(): MeasurementUnit;
setMeasurementUnit(measurementUnit: MeasurementUnit): PropertyDescriptor;
isHidden(): boolean;
serializeTo(element: SerializerElement): void;
unserializeFrom(element: SerializerElement): void;
serializeValuesTo(element: SerializerElement): void;
Expand Down
4 changes: 3 additions & 1 deletion GDevelop.js/types/gdpropertydescriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ declare class gdPropertyDescriptor {
setExtraInfo(info: gdVectorString): gdPropertyDescriptor;
getExtraInfo(): gdVectorString;
setHidden(enable: boolean): gdPropertyDescriptor;
isHidden(): boolean;
setDeprecated(enable: boolean): gdPropertyDescriptor;
isDeprecated(): boolean;
getMeasurementUnit(): gdMeasurementUnit;
setMeasurementUnit(measurementUnit: gdMeasurementUnit): gdPropertyDescriptor;
isHidden(): boolean;
serializeTo(element: gdSerializerElement): void;
unserializeFrom(element: gdSerializerElement): void;
serializeValuesTo(element: gdSerializerElement): void;
Expand Down
110 changes: 77 additions & 33 deletions newIDE/app/src/BehaviorsEditor/Editors/BehaviorPropertiesEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,93 @@ import * as React from 'react';
import PropertiesEditor from '../../PropertiesEditor';
import propertiesMapToSchema from '../../PropertiesEditor/PropertiesMapToSchema';
import EmptyMessage from '../../UI/EmptyMessage';
import { Column } from '../../UI/Grid';
import { Column, Line } from '../../UI/Grid';
import { type BehaviorEditorProps } from './BehaviorEditorProps.flow';
import FlatButton from '../../UI/FlatButton';
import { ColumnStackLayout } from '../../UI/Layout';

type Props = BehaviorEditorProps;

export default class BehaviorPropertiesEditor extends React.Component<Props> {
render() {
const {
project,
behavior,
object,
onBehaviorUpdated,
resourceManagementProps,
} = this.props;
const BehaviorPropertiesEditor = ({
project,
behavior,
object,
onBehaviorUpdated,
resourceManagementProps,
}: Props) => {
const [
shouldShowDeprecatedProperties,
setShouldShowDeprecatedProperties,
] = React.useState<boolean>(false);

const propertiesSchema = propertiesMapToSchema(
behavior.getProperties(),
behavior => behavior.getProperties(),
(behavior, name, value) => {
behavior.updateProperty(name, value);
},
object
);
const propertiesSchema = React.useMemo(
() =>
propertiesMapToSchema(
behavior.getProperties(),
behavior => behavior.getProperties(),
(behavior, name, value) => {
behavior.updateProperty(name, value);
},
object
),
[behavior, object]
);

return (
<Column expand>
{propertiesSchema.length ? (
const deprecatedPropertiesSchema = React.useMemo(
() =>
propertiesMapToSchema(
behavior.getProperties(),
behavior => behavior.getProperties(),
(behavior, name, value) => {
behavior.updateProperty(name, value);
},
object,
// Deprecated properties
true
),
[behavior, object]
);

return (
<Column expand>
{propertiesSchema.length ? (
<ColumnStackLayout expand noMargin>
<PropertiesEditor
project={project}
schema={propertiesSchema}
instances={[behavior]}
onInstancesModified={onBehaviorUpdated}
resourceManagementProps={resourceManagementProps}
/>
) : (
<EmptyMessage>
<Trans>
There is nothing to configure for this behavior. You can still use
events to interact with the object and this behavior.
</Trans>
</EmptyMessage>
)}
</Column>
);
}
}
{deprecatedPropertiesSchema.length > 0 &&
(shouldShowDeprecatedProperties ? (
<PropertiesEditor
project={project}
schema={deprecatedPropertiesSchema}
instances={[behavior]}
onInstancesModified={onBehaviorUpdated}
resourceManagementProps={resourceManagementProps}
/>
) : (
<Line justifyContent="center">
<FlatButton
key="show-deprecated"
label={<Trans>Show deprecated options</Trans>}
onClick={() => setShouldShowDeprecatedProperties(true)}
/>
</Line>
))}
</ColumnStackLayout>
) : (
<EmptyMessage>
<Trans>
There is nothing to configure for this behavior. You can still use
events to interact with the object and this behavior.
</Trans>
</EmptyMessage>
)}
</Column>
);
};

export default BehaviorPropertiesEditor;
6 changes: 5 additions & 1 deletion newIDE/app/src/PropertiesEditor/PropertiesMapToSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ const propertiesMapToSchema = (
propertyName: string,
newValue: string
) => void,
object: ?gdObject
object: ?gdObject,
deprecated: boolean = false
): Schema => {
const propertyNames = properties.keys();
// Aggregate field by groups to be able to build field groups with a title.
Expand All @@ -263,6 +264,9 @@ const propertiesMapToSchema = (
const name = propertyNames.at(i);
const property = properties.get(name);
if (property.isHidden()) return null;
if (property.isDeprecated() !== deprecated) {
return null;
}
if (alreadyHandledProperties.has(name)) return null;

const groupName = property.getGroup() || '';
Expand Down

0 comments on commit f623b35

Please sign in to comment.