Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly update the UI when adding or removing a mixin #699

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/components/components/CommonComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ export default class CommonComponents extends React.Component {
if (detail.entity !== this.props.entity) {
return;
}
if (DEFAULT_COMPONENTS.indexOf(detail.component) !== -1) {
if (
DEFAULT_COMPONENTS.indexOf(detail.component) !== -1 ||
detail.component === 'mixin'
) {
this.forceUpdate();
}
});

Events.on('refreshsidebarobject3d', () => {
this.forceUpdate();
});

var clipboard = new Clipboard('[data-action="copy-entity-to-clipboard"]', {
text: (trigger) => {
return getEntityClipboardRepresentation(this.props.entity);
Expand Down
14 changes: 11 additions & 3 deletions src/components/components/ComponentsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import AddComponent from './AddComponent';
import Component from './Component';
import CommonComponents from './CommonComponents';
import DEFAULT_COMPONENTS from './DefaultComponents';
import Events from '../../lib/Events';

export default class ComponentsContainer extends React.Component {
static propTypes = {
entity: PropTypes.object
};

refresh = () => {
this.forceUpdate();
};
componentDidMount() {
Events.on('entityupdate', (detail) => {
if (detail.entity !== this.props.entity) {
return;
}
if (detail.component === 'mixin') {
this.forceUpdate();
}
});
}

render() {
const entity = this.props.entity;
Expand Down
15 changes: 0 additions & 15 deletions src/components/components/PropertyRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import debounce from 'lodash.debounce';
import Events from '../../lib/Events';

import BooleanWidget from '../widgets/BooleanWidget';
import ColorWidget from '../widgets/ColorWidget';
Expand Down Expand Up @@ -36,19 +34,6 @@ export default class PropertyRow extends React.Component {
constructor(props) {
super(props);
this.id = props.componentname + ':' + props.name;

if (
['position', 'rotation', 'scale'].indexOf(this.props.componentname) !== -1
) {
Events.on(
'entitytransformed',
debounce((entity) => {
if (entity === props.entity) {
this.forceUpdate();
}
}, 250)
);
}
}

getWidget() {
Expand Down
5 changes: 5 additions & 0 deletions src/components/scenegraph/SceneGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default class SceneGraph extends React.Component {
Events.on('entityidchange', this.rebuildEntityOptions);
Events.on('entitycreated', this.rebuildEntityOptions);
Events.on('entityclone', this.rebuildEntityOptions);
Events.on('entityupdate', (detail) => {
if (detail.component === 'mixin') {
this.rebuildEntityOptions();
}
});
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/lib/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export function Viewport(inspector) {

updateHelpers(object);

Events.emit('refreshsidebarobject3d', object);

// Emit update event for watcher.
let component;
let value;
Expand Down Expand Up @@ -85,8 +83,6 @@ export function Viewport(inspector) {
property: '',
value: value
});

Events.emit('entitytransformed', transformControls.object.el);
});

transformControls.addEventListener('mouseDown', () => {
Expand Down
Loading