Skip to content

Commit e4a8a73

Browse files
Allows setting user component display name.
1 parent aec7da8 commit e4a8a73

File tree

8 files changed

+46
-16
lines changed

8 files changed

+46
-16
lines changed

source/editor/plugins/phasereditor2d.scene/src/ui/editor/commands/SceneEditorCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ namespace phasereditor2d.scene.ui.editor.commands {
354354
if (obj instanceof usercomponent.UserComponent) {
355355

356356
return [{
357-
text: obj.getName(),
357+
text: obj.getDisplayNameOrName(),
358358
color: theme.viewerForeground
359359
}];
360360
}

source/editor/plugins/phasereditor2d.scene/src/ui/editor/outline/SceneEditorOutlineStyledLabelProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace phasereditor2d.scene.ui.editor.outline {
4545

4646
} else if (obj instanceof sceneobjects.UserComponentNode) {
4747

48-
return obj.getComponentName();
48+
return obj.getUserComponent().getDisplayNameOrName();
4949

5050
} else if (obj instanceof sceneobjects.PrefabUserProperties) {
5151

source/editor/plugins/phasereditor2d.scene/src/ui/editor/properties/DynamicUserComponentSection.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ namespace phasereditor2d.scene.ui.editor.properties {
77
export class DynamicUserComponentSection extends sceneobjects.SceneGameObjectSection<sceneobjects.ISceneGameObject> {
88

99
private _componentName: string;
10+
private _componentDisplayName: string;
1011

11-
constructor(page: controls.properties.PropertyPage, componentName: string, hash: string) {
12+
constructor(page: controls.properties.PropertyPage, componentName: string, componentDisplayName: string, hash: string) {
1213
super(page,
1314
DynamicUserComponentSection.computeId(componentName, hash),
1415
componentName, false, true,
1516
resources.getIcon(resources.ICON_USER_COMPONENT),
1617
`DynamicUserComponentSection_${componentName}}`);
1718

1819
this._componentName = componentName;
20+
this._componentDisplayName = componentDisplayName;
1921
}
2022

2123
private static computeId(compName: string, hash: string) {
@@ -35,7 +37,7 @@ namespace phasereditor2d.scene.ui.editor.properties {
3537
.getUserComponentsComponent()
3638
.getPrefabUserComponents())
3739
.filter(i => i.components.find(c => c.getName() === this._componentName))
38-
.map(i => i.prefabFile.getNameWithoutExtension());
40+
.map(i => sceneobjects.getSceneDisplayName(i.prefabFile));
3941

4042
const distinctPrefabNames: string[] = [];
4143

@@ -54,10 +56,10 @@ namespace phasereditor2d.scene.ui.editor.properties {
5456
distinctPrefabNames.push(prefabName);
5557
}
5658

57-
return `${this._componentName} <span class="UserComponentTitle_PrefabsPart">← ${distinctPrefabNames.join(" &amp; ")}</span>`;
59+
return `${this._componentDisplayName} <span class="UserComponentTitle_PrefabsPart">← ${distinctPrefabNames.join(" &amp; ")}</span>`;
5860
}
5961

60-
return this._componentName;
62+
return this._componentDisplayName;
6163
}
6264

6365
createMenu(menu: controls.Menu): void {
@@ -66,7 +68,7 @@ namespace phasereditor2d.scene.ui.editor.properties {
6668
const objES = obj.getEditorSupport();
6769

6870
menu.addAction({
69-
text: `Select Objects With ${this._componentName}`,
71+
text: `Select Objects With ${this._componentDisplayName}`,
7072
callback: () => {
7173

7274
const sel = [];
@@ -90,7 +92,7 @@ namespace phasereditor2d.scene.ui.editor.properties {
9092
});
9193

9294
menu.addAction({
93-
text: "Open Definition Of " + this._componentName,
95+
text: "Open Definition Of " + this._componentDisplayName,
9496
callback: () => this.openComponentEditor()
9597
});
9698

source/editor/plugins/phasereditor2d.scene/src/ui/editor/properties/DynamicUserSectionExtension.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ namespace phasereditor2d.scene.ui.editor.properties {
2626
for (const compInfo of localComps) {
2727

2828
const compName = compInfo.component.getName();
29+
const compDisplayName = compInfo.component.getDisplayNameOrName();
2930

3031
visitedComps.add(compName);
3132

3233
result.push(page => new DynamicUserComponentSection(
33-
page, compName, `${compInfo.file.getModTime()}`));
34+
page, compName, compDisplayName, `${compInfo.file.getModTime()}`));
3435
}
3536
}
3637

@@ -69,14 +70,16 @@ namespace phasereditor2d.scene.ui.editor.properties {
6970

7071
const userComps = objES.getUserComponentsComponent();
7172

72-
const compNames = userComps
73+
const components = userComps
7374
.getPrefabUserComponents()
7475
.filter(i => i.prefabFile === prefabInfo.prefabFile)
7576
.flatMap(i => i.components)
76-
.map(c => c.getName())
77-
.filter(name => !visitedComps.has(name));
77+
.filter(c => !visitedComps.has(c.getName()));
7878

79-
for (const compName of compNames) {
79+
for (const comp of components) {
80+
81+
const compName = comp.getName();
82+
const compDisplayName = comp.getDisplayNameOrName();
8083

8184
visitedComps.add(compName);
8285

@@ -85,7 +88,7 @@ namespace phasereditor2d.scene.ui.editor.properties {
8588
if (findResult) {
8689

8790
result.push(page => new DynamicUserComponentSection(
88-
page, compName, `${findResult.file.getModTime()}`));
91+
page, compName, compDisplayName, `${findResult.file.getModTime()}`));
8992
}
9093
}
9194
}

source/editor/plugins/phasereditor2d.scene/src/ui/editor/usercomponent/UserComponent.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
55
export class UserComponent {
66

77
private _name: string;
8+
private _displayName: string;
89
private _baseClass: string;
910
private _gameObjectType: string;
1011
private _properties: sceneobjects.UserPropertiesManager;
@@ -13,6 +14,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
1314

1415
this._name = name;
1516
this._baseClass = "";
17+
this._displayName = "";
1618
this._gameObjectType = "Phaser.GameObjects.Image";
1719
this._properties = new UserComponentProperties(this);
1820
}
@@ -24,6 +26,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
2426

2527
const data = {
2628
name: this._name,
29+
displayName: this._displayName,
2730
baseClass: this._baseClass,
2831
gameObjectType: this._gameObjectType,
2932
properties: propsData
@@ -35,6 +38,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
3538
readJSON(data: any) {
3639

3740
this._name = data.name;
41+
this._displayName = read(data, "displayName", "");
3842
this._baseClass = read(data, "baseClass", "");
3943
this._gameObjectType = read(data, "gameObjectType", "Phaser.GameObjects.Image");
4044
this._properties.readJSON(data.properties);
@@ -50,6 +54,26 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
5054
this._name = name;
5155
}
5256

57+
getDisplayName() {
58+
59+
return this._displayName;
60+
}
61+
62+
setDisplayName(displayName: string) {
63+
64+
this._displayName = displayName;
65+
}
66+
67+
getDisplayNameOrName() {
68+
69+
if (this._displayName && this._displayName.trim().length > 0) {
70+
71+
return this._displayName;
72+
}
73+
74+
return this._name;
75+
}
76+
5377
getBaseClass() {
5478

5579
return this._baseClass;

source/editor/plugins/phasereditor2d.scene/src/ui/editor/usercomponent/UserComponentSection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
4040

4141
this.stringProp(comp, "BaseClass", "Super Class", "Name of the super class of the component. It is optional.", () => this.createSuperClassOptions());
4242

43+
this.stringProp(comp, "DisplayName", "Display Name", "The display name of the component.");
4344

4445
const op = (
4546
action: editor.properties.TUserPropertiesAction) => {

source/editor/plugins/phasereditor2d.scene/src/ui/editor/usercomponent/UserComponentsEditorOutlineProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace phasereditor2d.scene.ui.editor.usercomponent {
4141

4242
return new controls.viewers.LabelProvider(obj => {
4343

44-
return obj instanceof UserComponent ? obj.getName() : obj as string;
44+
return obj instanceof UserComponent ? obj.getDisplayNameOrName() : obj as string;
4545
});
4646
}
4747

source/editor/plugins/phasereditor2d.scene/src/ui/sceneobjects/object/properties/DynamicPrefabInstanceSection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace phasereditor2d.scene.ui.sceneobjects {
1414
properties: UserProperty[]) {
1515
super(page,
1616
DynamicPrefabInstanceSection.computeId(prefabFile),
17-
prefabFile.getNameWithoutExtension(),
17+
getSceneDisplayName(prefabFile),
1818
false, true, resources.getIcon(resources.ICON_GROUP),
1919
DynamicPrefabInstanceSection.computeTypeHash(prefabFile));
2020

0 commit comments

Comments
 (0)