Display Z coordinate in instance tooltip for instances of 3D objects

- Also fixes some weird behavior around the "Custom size" checkbox in instance properties
This commit is contained in:
AlexandreS
2023-06-01 16:12:34 +02:00
committed by GitHub
parent a578fa32e9
commit e186681f39
6 changed files with 43 additions and 5 deletions

View File

@@ -7,7 +7,9 @@ import Rectangle from '../Utils/Rectangle';
export default class HighlightedInstance {
instanceMeasurer: InstanceMeasurer;
toCanvasCoordinates: (x: number, y: number) => [number, number];
isInstanceOf3DObject: gdInitialInstance => boolean;
highlightedInstance: gdInitialInstance | null;
isHighlightedInstanceOf3DObject: boolean;
highlightRectangle: PIXI.Container;
tooltipBackground: PIXI.Container;
tooltipText: PIXI.Container;
@@ -15,14 +17,18 @@ export default class HighlightedInstance {
constructor({
instanceMeasurer,
toCanvasCoordinates,
isInstanceOf3DObject,
}: {
instanceMeasurer: InstanceMeasurer,
toCanvasCoordinates: (x: number, y: number) => [number, number],
isInstanceOf3DObject: gdInitialInstance => boolean,
}) {
this.instanceMeasurer = instanceMeasurer;
this.toCanvasCoordinates = toCanvasCoordinates;
this.isInstanceOf3DObject = isInstanceOf3DObject;
this.highlightedInstance = null;
this.isHighlightedInstanceOf3DObject = false;
this.highlightRectangle = new PIXI.Graphics();
this.highlightRectangle.hitArea = new PIXI.Rectangle(0, 0, 0, 0);
@@ -37,6 +43,9 @@ export default class HighlightedInstance {
}
setInstance(instance: gdInitialInstance | null) {
this.isHighlightedInstanceOf3DObject = instance
? this.isInstanceOf3DObject(instance)
: false;
this.highlightedInstance = instance;
}
@@ -84,13 +93,19 @@ export default class HighlightedInstance {
Math.round(highlightedInstance.getX() * 100) / 100 + // An instance position can have a lot of decimals, so round to 2 decimals.
' Y: ' +
Math.round(highlightedInstance.getY() * 100) / 100 + // An instance position can have a lot of decimals, so round to 2 decimals.
(this.isHighlightedInstanceOf3DObject
? ' Z: ' +
// An instance position can have a lot of decimals, so round to 2 decimals.
Math.round(highlightedInstance.getZ() * 100) / 100
: '') +
'\n' +
'Layer: ' +
(highlightedInstance.getLayer() || 'Base layer') +
'\n' +
'Z: ' +
highlightedInstance.getZOrder() +
(this.isHighlightedInstanceOf3DObject
? ''
: '\nZ order: ' + highlightedInstance.getZOrder()) +
'\n';
this.tooltipText.text = tooltipInfo;
this.tooltipText.x = Math.round(

View File

@@ -197,6 +197,18 @@ const makeSchema = ({
valueType: 'boolean',
getValue: (instance: gdInitialInstance) => instance.hasCustomSize(),
setValue: (instance: gdInitialInstance, newValue: boolean) => {
if (
instance.getCustomHeight() === 0 &&
instance.getCustomWidth() === 0 &&
instance.getCustomDepth() === 0
) {
// The instance custom dimensions have never been set before.
// To avoid setting setting all the dimensions to 0 when enabling
// the instance custom size flag, the current instance dimensions are used.
instance.setCustomWidth(getInstanceWidth(instance));
instance.setCustomHeight(getInstanceHeight(instance));
instance.setCustomDepth(getInstanceDepth(instance));
}
instance.setHasCustomSize(newValue);
instance.setHasCustomDepth(newValue);
forceUpdate();

View File

@@ -71,6 +71,7 @@ export type InstancesEditorPropsWithoutSizeAndScroll = {|
selectedLayer: string,
initialInstances: gdInitialInstancesContainer,
instancesEditorSettings: InstancesEditorSettings,
isInstanceOf3DObject: gdInitialInstance => boolean,
onInstancesEditorSettingsMutated: (
instancesEditorSettings: InstancesEditorSettings
) => void,
@@ -430,6 +431,7 @@ export default class InstancesEditor extends Component<Props> {
this.highlightedInstance = new HighlightedInstance({
instanceMeasurer: this.instancesRenderer.getInstanceMeasurer(),
toCanvasCoordinates: this.viewPosition.toCanvasCoordinates,
isInstanceOf3DObject: this.props.isInstanceOf3DObject,
});
this.instancesResizer = new InstancesResizer({
instanceMeasurer: this.instancesRenderer.getInstanceMeasurer(),

View File

@@ -83,11 +83,11 @@ export default class RenderedInstance {
}
getCustomWidth(): number {
return this._instance.getCustomWidth() || this.getDefaultWidth();
return this._instance.getCustomWidth();
}
getCustomHeight(): number {
return this._instance.getCustomHeight() || this.getDefaultHeight();
return this._instance.getCustomHeight();
}
getWidth(): number {

View File

@@ -1153,6 +1153,13 @@ export default class SceneEditor extends React.Component<Props, State> {
});
};
isInstanceOf3DObject = (instance: gdInitialInstance) => {
const { project, layout } = this.props;
const object = getObjectByName(project, layout, instance.getObjectName());
return !!object && object.is3DObject();
};
buildContextMenu = (i18n: I18nType, layout: gdLayout, options: any) => {
let contextMenuItems = [];
if (
@@ -1590,6 +1597,7 @@ export default class SceneEditor extends React.Component<Props, State> {
onInstancesRotated={this._onInstancesRotated}
selectedObjectNames={selectedObjectNames}
onContextMenu={this._onContextMenu}
isInstanceOf3DObject={this.isInstanceOf3DObject}
instancesEditorShortcutsCallbacks={{
onCopy: () => this.copySelection({ useLastCursorPosition: true }),
onCut: () => this.cutSelection({ useLastCursorPosition: true }),

View File

@@ -43,6 +43,7 @@ export const Default = () => (
initialInstances={testProject.testLayout.getInitialInstances()}
instancesEditorSettings={instancesEditorSettings}
onInstancesEditorSettingsMutated={() => {}}
isInstanceOf3DObject={() => false}
instancesSelection={instancesSelection}
onInstancesAdded={() => {}}
onInstancesSelected={() => {}}