Skip to content

Commit 34b5180

Browse files
authored
Merge pull request #13580 from carolhmj/GEFixConnectedControls
Fix connected controls being unset when opening the editor
2 parents bde00a3 + 22443e2 commit 34b5180

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/tools/guiEditor/src/diagram/workbench.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,11 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
606606
}
607607
});
608608
liveRoot.clearControls();
609+
const originalToCloneMap = new Map<Control, Control>();
609610
const updatedRootChildren = this.trueRootContainer.children.slice(0);
610611
for (const child of updatedRootChildren) {
611612
const clone = child.clone(this.props.globalState.liveGuiTexture!);
613+
originalToCloneMap.set(child, clone);
612614
liveRoot.addControl(clone);
613615
}
614616

@@ -621,6 +623,8 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
621623
}
622624
}
623625
});
626+
627+
this._syncConnectedLines(updatedRootChildren, originalToCloneMap);
624628
}
625629
}
626630

@@ -850,17 +854,37 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
850854
}
851855
}
852856

857+
private _syncConnectedLines(controlList: Control[], originalToCloneMap: Map<Control, Control>) {
858+
for (const control of controlList) {
859+
if (control.getClassName() === "Line") {
860+
const lineControl = control as Line;
861+
if (lineControl.connectedControl) {
862+
const connectedControl = lineControl.connectedControl;
863+
const clonedLine = originalToCloneMap.get(lineControl) as Line;
864+
const clonedConnectedControl = originalToCloneMap.get(connectedControl);
865+
if (clonedLine && clonedConnectedControl) {
866+
clonedLine.connectedControl = clonedConnectedControl;
867+
}
868+
}
869+
}
870+
}
871+
}
872+
853873
private _copyLiveGUIToEditorGUI() {
854874
if (this.props.globalState.liveGuiTexture && this.trueRootContainer) {
855875
// Create special IDs that will allow us to know which cloned control corresponds to its original
856876
this.props.globalState.liveGuiTexture.rootContainer.getDescendants().forEach((control) => {
857877
control.metadata = { ...(control.metadata ?? {}), editorUniqueId: RandomGUID() };
858878
});
859879
this.trueRootContainer.clearControls();
880+
const originalToCloneMap = new Map<Control, Control>();
860881
for (const control of this.props.globalState.liveGuiTexture.rootContainer.children) {
861882
const cloned = control.clone(this.props.globalState.guiTexture);
883+
originalToCloneMap.set(control, cloned);
862884
this.appendBlock(cloned);
863885
}
886+
// Synchronize existing connectedControls
887+
this._syncConnectedLines(this.props.globalState.liveGuiTexture.rootContainer.children, originalToCloneMap);
864888
}
865889
}
866890

0 commit comments

Comments
 (0)