mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Allow behavior properties to be hidden in the editor
This commit is contained in:

committed by
Florian Rival

parent
181976e1b3
commit
689136cadb
@@ -22,6 +22,7 @@ void PropertyDescriptor::SerializeTo(SerializerElement& element) const {
|
||||
for (const gd::String& information : extraInformation) {
|
||||
extraInformationElement.AddChild("").SetStringValue(information);
|
||||
}
|
||||
element.AddChild("hidden").SetBoolValue(hidden);
|
||||
}
|
||||
|
||||
void PropertyDescriptor::UnserializeFrom(const SerializerElement& element) {
|
||||
@@ -36,6 +37,10 @@ void PropertyDescriptor::UnserializeFrom(const SerializerElement& element) {
|
||||
for (std::size_t i = 0; i < extraInformationElement.GetChildrenCount(); ++i)
|
||||
extraInformation.push_back(
|
||||
extraInformationElement.GetChild(i).GetStringValue());
|
||||
|
||||
hidden = element.HasChild("hidden")
|
||||
? element.GetChild("hidden").GetBoolValue()
|
||||
: false;
|
||||
}
|
||||
|
||||
} // namespace gd
|
||||
|
@@ -24,12 +24,12 @@ class GD_CORE_API PropertyDescriptor {
|
||||
* value. \param propertyValue The value of the property.
|
||||
*/
|
||||
PropertyDescriptor(gd::String propertyValue)
|
||||
: currentValue(propertyValue), type("string"), label("") {}
|
||||
: currentValue(propertyValue), type("string"), label(""), hidden(false) {}
|
||||
|
||||
/**
|
||||
* \brief Empty constructor creating an empty property to be displayed.
|
||||
*/
|
||||
PropertyDescriptor(){};
|
||||
PropertyDescriptor() : hidden(false){};
|
||||
|
||||
/**
|
||||
* \brief Destructor
|
||||
@@ -83,6 +83,19 @@ class GD_CORE_API PropertyDescriptor {
|
||||
return extraInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set if the property should be shown or hidden in the editor.
|
||||
*/
|
||||
PropertyDescriptor& SetHidden(bool enable = true) {
|
||||
hidden = enable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check if the property should be shown or hidden in the editor.
|
||||
*/
|
||||
bool IsHidden() const { return hidden; }
|
||||
|
||||
/** \name Serialization
|
||||
*/
|
||||
///@{
|
||||
@@ -107,6 +120,7 @@ class GD_CORE_API PropertyDescriptor {
|
||||
extraInformation; ///< Can be used to store for example the available
|
||||
///< choices, if a property is a displayed as a combo
|
||||
///< box.
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
} // namespace gd
|
||||
|
@@ -588,6 +588,8 @@ interface PropertyDescriptor {
|
||||
[Const, Ref] DOMString GetLabel();
|
||||
[Ref] PropertyDescriptor AddExtraInfo([Const] DOMString type);
|
||||
[Value] VectorString GetExtraInfo();
|
||||
[Ref] PropertyDescriptor SetHidden(boolean enable);
|
||||
boolean IsHidden();
|
||||
|
||||
void SerializeTo([Ref] SerializerElement element);
|
||||
void UnserializeFrom([Const, Ref] SerializerElement element);
|
||||
|
@@ -17,6 +17,9 @@ import SemiControlledTextField from '../UI/SemiControlledTextField';
|
||||
import MiniToolbar from '../UI/MiniToolbar';
|
||||
import { showWarningBox } from '../UI/Messages/MessageBox';
|
||||
import newNameGenerator from '../Utils/NewNameGenerator';
|
||||
import InlineCheckbox from '../UI/InlineCheckbox';
|
||||
import Visibility from 'material-ui/svg-icons/action/visibility';
|
||||
import VisibilityOff from 'material-ui/svg-icons/action/visibility-off';
|
||||
|
||||
const gd = global.gd;
|
||||
|
||||
@@ -143,6 +146,23 @@ export default class EventsBasedBehaviorPropertiesEditor extends React.Component
|
||||
fullWidth
|
||||
/>
|
||||
</Column>
|
||||
<InlineCheckbox
|
||||
label={
|
||||
property.isHidden() ? (
|
||||
<Trans>Hidden</Trans>
|
||||
) : (
|
||||
<Trans>Visible in editor</Trans>
|
||||
)
|
||||
}
|
||||
checked={!property.isHidden()}
|
||||
onCheck={(e, checked) => {
|
||||
property.setHidden(!checked);
|
||||
this.forceUpdate();
|
||||
this.props.onPropertiesUpdated();
|
||||
}}
|
||||
checkedIcon={<Visibility />}
|
||||
uncheckedIcon={<VisibilityOff />}
|
||||
/>
|
||||
<IconMenu
|
||||
iconButtonElement={
|
||||
<IconButton>
|
||||
|
@@ -37,6 +37,8 @@ export default (
|
||||
);
|
||||
};
|
||||
|
||||
if (property.isHidden()) return null;
|
||||
|
||||
if (valueType === 'number') {
|
||||
return {
|
||||
name,
|
||||
|
@@ -175,13 +175,14 @@ export default class PropertiesEditor extends React.Component<Props, {||}> {
|
||||
if (field.name === 'PLEASE_ALSO_SHOW_EDIT_BUTTON_THANKS') return null; // This special property was used in GDevelop 4 IDE to ask for a Edit button to be shown, ignore it.
|
||||
|
||||
if (field.valueType === 'boolean') {
|
||||
const { setValue } = field;
|
||||
return (
|
||||
<InlineCheckbox
|
||||
label={getFieldLabel(this.props.instances, field)}
|
||||
key={field.name}
|
||||
checked={getFieldValue(this.props.instances, field)}
|
||||
onCheck={(event, newValue) => {
|
||||
this.props.instances.forEach(i => field.setValue(i, !!newValue));
|
||||
this.props.instances.forEach(i => setValue(i, !!newValue));
|
||||
this._onInstancesModified(this.props.instances);
|
||||
}}
|
||||
disabled={field.disabled}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import Checkbox from 'material-ui/Checkbox';
|
||||
|
||||
const styles = {
|
||||
@@ -11,10 +12,19 @@ const styles = {
|
||||
},
|
||||
};
|
||||
|
||||
type Props = {|
|
||||
label: React.Node,
|
||||
checked: boolean,
|
||||
onCheck?: (e: {||}, checked: boolean) => void,
|
||||
checkedIcon?: React.Node,
|
||||
uncheckedIcon?: React.Node,
|
||||
disabled?: boolean,
|
||||
|};
|
||||
|
||||
/**
|
||||
* A checkbox based on Material-UI Checkbox, but that can be displayed
|
||||
* without having it taking the full width of its container.
|
||||
*/
|
||||
export default props => (
|
||||
export default (props: Props) => (
|
||||
<Checkbox style={styles.root} labelStyle={styles.label} {...props} />
|
||||
);
|
||||
|
Reference in New Issue
Block a user