Skip to content

Commit

Permalink
Fix Area map object in editor
Browse files Browse the repository at this point in the history
It was not possible to define custom properties for a map area.
  • Loading branch information
steffen-wilke committed Apr 12, 2020
1 parent 1ae4b21 commit b20fbdd
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public MapObjectInspector() {

this.tabbedPanel = new JTabbedPane(SwingConstants.TOP);
this.tabbedPanel.setFont(Style.getHeaderFont());

this.infoPanel = new JPanel();

GroupLayout groupLayout = new GroupLayout(this);
Expand Down Expand Up @@ -179,9 +179,9 @@ public void bind(IMapObject mapObject) {

if (mapObject != null) {
MapObjectType t = MapObjectType.get(mapObject.getType());
this.setMapObjectType(t != null ? t : MapObjectType.AREA);
this.setMapObjectType(t != null ? t : null);
} else {
this.setMapObjectType(MapObjectType.AREA);
this.setMapObjectType(null);
}

if (this.currentPanel != null) {
Expand All @@ -205,62 +205,73 @@ public void bind(IMapObject mapObject) {
private void switchPanel() {
final MapObjectType currentType = this.getObjectType();
if (currentType == null) {
this.clearPanels();
return;
}

PropertyPanel panel = this.panels.get(type);
if (panel == null) {
if (this.currentPanel != null) {
this.tabbedPanel.remove(this.currentPanel);
this.currentPanel.bind(null);
this.currentPanel = null;
this.tabbedPanel.revalidate();
this.tabbedPanel.repaint();
if (this.currentPanel != null) {
// panel is already selected
if (panel == this.currentPanel) {
return;
}
this.tabbedPanel.remove(this.collisionPanel);
this.tabbedPanel.remove(this.combatPanel);
this.tabbedPanel.remove(this.movementPanel);
this.tabbedPanel.remove(this.customPanel);

return;
}

if (panel == this.currentPanel) {
return;
}

if (this.currentPanel != null) {
// clear current panel
this.currentPanel.bind(null);
this.tabbedPanel.remove(this.currentPanel);
}
tabbedPanel.addTab(Resources.strings().get(panel.getIdentifier()), panel.getIcon(), panel);

if (panel != null) {
// add explicit map object panel
tabbedPanel.addTab(Resources.strings().get(panel.getIdentifier()), panel.getIcon(), panel);
}

// add/remove collision panel
if (currentType == MapObjectType.PROP || currentType == MapObjectType.CREATURE) {
tabbedPanel.addTab(Resources.strings().get(this.collisionPanel.getIdentifier()), this.collisionPanel.getIcon(), this.collisionPanel);
} else {
this.tabbedPanel.remove(this.collisionPanel);
}

// add/remove combat panel
if (currentType == MapObjectType.PROP || currentType == MapObjectType.CREATURE) {
tabbedPanel.addTab(Resources.strings().get(this.combatPanel.getIdentifier()), this.combatPanel);
} else {
this.tabbedPanel.remove(this.combatPanel);
}

// add/remove movement panel
if (currentType == MapObjectType.CREATURE) {
tabbedPanel.addTab(Resources.strings().get(this.movementPanel.getIdentifier()), this.movementPanel.getIcon(), this.movementPanel);
} else {
this.tabbedPanel.remove(this.movementPanel);
}

// always add custom panel
tabbedPanel.addTab(Resources.strings().get(this.customPanel.getIdentifier()), this.customPanel.getIcon(), this.customPanel);

this.currentPanel = panel;
this.currentPanel = panel != null ? panel : this.customPanel;
this.currentPanel.bind(this.getDataSource());
this.tabbedPanel.revalidate();
this.tabbedPanel.repaint();
}

private void clearPanels() {
if (this.currentPanel != null) {
this.tabbedPanel.remove(this.currentPanel);
this.currentPanel.bind(null);
this.currentPanel = null;
}

this.tabbedPanel.revalidate();
this.tabbedPanel.repaint();

this.tabbedPanel.remove(this.collisionPanel);
this.tabbedPanel.remove(this.combatPanel);
this.tabbedPanel.remove(this.movementPanel);
this.tabbedPanel.remove(this.customPanel);
}

@Override
public void setMapObjectType(MapObjectType type) {
this.type = type;
Expand All @@ -274,7 +285,7 @@ protected void clearControls() {
this.spinnerY.setValue(0);
this.spinnerWidth.setValue(0);
this.spinnerHeight.setValue(0);
this.type = MapObjectType.AREA;
this.type = null;

this.textFieldName.setText("");
this.labelEntityID.setText("####");
Expand Down

0 comments on commit b20fbdd

Please sign in to comment.