mirror of
https://github.com/4ian/GDevelop.git
synced 2026-10-12 02:01:17 +00:00
Allow behavior properties to be an animation name, displayed with a selector
This commit is contained in:
@@ -53,7 +53,8 @@ std::map<gd::String, gd::PropertyDescriptor> CustomConfigurationHelper::GetPrope
|
||||
if (configurationContent.HasChild(propertyName)) {
|
||||
if (propertyType == "String" || propertyType == "Choice" ||
|
||||
propertyType == "Color" || propertyType == "Behavior" ||
|
||||
propertyType == "Resource" || propertyType == "LeaderboardId") {
|
||||
propertyType == "Resource" || propertyType == "LeaderboardId" ||
|
||||
propertyType == "AnimationName") {
|
||||
newProperty.SetValue(
|
||||
configurationContent.GetChild(propertyName).GetStringValue());
|
||||
} else if (propertyType == "Number") {
|
||||
@@ -89,7 +90,8 @@ bool CustomConfigurationHelper::UpdateProperty(
|
||||
|
||||
if (propertyType == "String" || propertyType == "Choice" ||
|
||||
propertyType == "Color" || propertyType == "Behavior" ||
|
||||
propertyType == "Resource" || propertyType == "LeaderboardId") {
|
||||
propertyType == "Resource" || propertyType == "LeaderboardId" ||
|
||||
propertyType == "AnimationName") {
|
||||
element.SetStringValue(newValue);
|
||||
} else if (propertyType == "Number") {
|
||||
element.SetDoubleValue(newValue.To<double>());
|
||||
|
||||
@@ -838,6 +838,7 @@ interface ObjectConfiguration {
|
||||
void UnserializeFrom([Ref] Project project, [Const, Ref] SerializerElement element);
|
||||
|
||||
unsigned long GetAnimationsCount();
|
||||
[Const, Ref] DOMString GetAnimationName(unsigned long index);
|
||||
};
|
||||
|
||||
interface UniquePtrObjectConfiguration {
|
||||
|
||||
@@ -12,6 +12,7 @@ declare class gdObjectConfiguration {
|
||||
serializeTo(element: gdSerializerElement): void;
|
||||
unserializeFrom(project: gdProject, element: gdSerializerElement): void;
|
||||
getAnimationsCount(): number;
|
||||
getAnimationName(index: number): string;
|
||||
delete(): void;
|
||||
ptr: number;
|
||||
};
|
||||
@@ -234,6 +234,42 @@ const createField = (
|
||||
getDescription,
|
||||
hasImpactOnAllOtherFields: property.hasImpactOnOtherProperties(),
|
||||
};
|
||||
} else if (valueType === 'animationname') {
|
||||
return {
|
||||
getChoices: () => {
|
||||
if (!object) {
|
||||
return [];
|
||||
}
|
||||
const animationArray = mapFor(
|
||||
0,
|
||||
object.getConfiguration().getAnimationsCount(),
|
||||
i => {
|
||||
const animationName = object.getConfiguration().getAnimationName(i);
|
||||
if (animationName === '') {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
value: animationName,
|
||||
label: animationName,
|
||||
};
|
||||
}
|
||||
).filter(Boolean);
|
||||
animationArray.push({ value: '', label: '(no animation)' });
|
||||
return animationArray;
|
||||
},
|
||||
name,
|
||||
valueType: 'string',
|
||||
getValue: (instance: Instance): string => {
|
||||
return getProperties(instance)
|
||||
.get(name)
|
||||
.getValue();
|
||||
},
|
||||
setValue: (instance: Instance, newValue: string) => {
|
||||
onUpdateProperty(instance, name, newValue);
|
||||
},
|
||||
getLabel,
|
||||
getDescription,
|
||||
};
|
||||
} else {
|
||||
console.error(
|
||||
`A property with type=${valueType} could not be mapped to a field. Ensure that this type is correct and understood by the IDE.`
|
||||
|
||||
@@ -729,6 +729,11 @@ export default function EventsBasedBehaviorPropertiesEditor({
|
||||
value="Boolean"
|
||||
label={t`Boolean (checkbox)`}
|
||||
/>
|
||||
<SelectOption
|
||||
key="property-type-animationname"
|
||||
value="AnimationName"
|
||||
label={t`Animation name (text)`}
|
||||
/>
|
||||
<SelectOption
|
||||
key="property-type-choice"
|
||||
value="Choice"
|
||||
@@ -802,7 +807,9 @@ export default function EventsBasedBehaviorPropertiesEditor({
|
||||
</SelectField>
|
||||
)}
|
||||
{(property.getType() === 'String' ||
|
||||
property.getType() === 'Number') && (
|
||||
property.getType() === 'Number' ||
|
||||
property.getType() ===
|
||||
'AnimationName') && (
|
||||
<SemiControlledTextField
|
||||
commitOnBlur
|
||||
floatingLabelText={
|
||||
|
||||
@@ -220,6 +220,41 @@ const createField = (
|
||||
getLabel,
|
||||
getDescription,
|
||||
};
|
||||
} else if (valueType === 'animationname') {
|
||||
return {
|
||||
getChoices: () => {
|
||||
if (!object) {
|
||||
return [];
|
||||
}
|
||||
const animationArray = mapFor(
|
||||
0,
|
||||
object.getConfiguration().getAnimationsCount(),
|
||||
i => {
|
||||
const animationName = object.getConfiguration().getAnimationName(i);
|
||||
if (animationName === '') {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
value: animationName,
|
||||
label: animationName,
|
||||
};
|
||||
}
|
||||
).filter(Boolean);
|
||||
animationArray.push({ value: '', label: '(no animation)' });
|
||||
return animationArray;
|
||||
},
|
||||
name,
|
||||
valueType: 'string',
|
||||
getValue: (instance: Instance): string => {
|
||||
return getProperties(instance)
|
||||
.get(name)
|
||||
.getValue();
|
||||
},
|
||||
setValue: (instance: Instance, newValue: string) => {
|
||||
onUpdateProperty(instance, name, newValue);
|
||||
},
|
||||
getLabel,
|
||||
};
|
||||
} else {
|
||||
console.error(
|
||||
`A property with type=${valueType} could not be mapped to a field. Ensure that this type is correct and understood by the IDE.`
|
||||
|
||||
Reference in New Issue
Block a user