Skip to content

Commit

Permalink
Fix map editor
Browse files Browse the repository at this point in the history
  • Loading branch information
armin-reichert committed Jun 22, 2024
1 parent c4ca2e1 commit 9fa66fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PropertyEditor extends BorderPane {
public final BooleanProperty enabledPy = new SimpleBooleanProperty(true);

private final TileMapEditor editor;
private final TileMap tileMap;
private TileMap tileMap;
private Properties editedProperties;
private final GridPane grid = new GridPane();
private final List<ColorPicker> colorPickers = new ArrayList<>();
Expand All @@ -36,9 +36,8 @@ public class PropertyEditor extends BorderPane {

private int numRows;

public PropertyEditor(String title, TileMapEditor editor, TileMap tileMap) {
public PropertyEditor(String title, TileMapEditor editor) {
this.editor = editor;
this.tileMap = tileMap;

var lblTitle = new Label(title);
lblTitle.setFont(Font.font("Sans", FontWeight.BOLD, 14));
Expand All @@ -57,12 +56,13 @@ public PropertyEditor(String title, TileMapEditor editor, TileMap tileMap) {
setCenter(grid);
}

public void edit(Properties properties) {
this.editedProperties = properties;
public void edit(TileMap tileMap) {
this.tileMap = tileMap;
this.editedProperties = tileMap.getProperties();
rebuildEditors();
}

public void rebuildEditors() {
private void rebuildEditors() {
colorPickers.clear();
tileXEditors.clear();
tileYEditors.clear();
Expand All @@ -78,6 +78,7 @@ public void rebuildEditors() {
int nameColumnMinWidth = 160;
nameEditor.setMinWidth(nameColumnMinWidth);
nameEditor.disableProperty().bind(enabledPy.not());
nameEditor.setOnAction(e -> rebuildEditors());
grid.add(nameEditor, 0, row);
if (propertyName.startsWith("color_")) {
var colorPicker = new ColorPicker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ private void createLayout() {

palettesTabPane = new TabPane(terrainPaletteTab, actorPaletteTab, foodPaletteTab);

terrainMapPropertiesEditor = new PropertyEditor(tt("terrain"), this, map().terrain());
terrainMapPropertiesEditor = new PropertyEditor(tt("terrain"), this);
terrainMapPropertiesEditor.enabledPy.bind(editingEnabledPy);
terrainMapPropertiesEditor.setPadding(new Insets(10,0,0,0));

foodMapPropertiesEditor = new PropertyEditor(tt("pellets"), this, map().food());
foodMapPropertiesEditor = new PropertyEditor(tt("pellets"), this);
foodMapPropertiesEditor.enabledPy.bind(editingEnabledPy);
foodMapPropertiesEditor.setPadding(new Insets(10,0,0,0));

Expand Down Expand Up @@ -447,8 +447,8 @@ private void addBorder(TileMap terrain, int emptyRowsTop, int emptyRowsBottom) {
public void setMap(WorldMap other) {
checkNotNull(other);
mapPy.set(other);
foodMapPropertiesEditor.edit(map().food().getProperties());
terrainMapPropertiesEditor.edit(map().terrain().getProperties());
foodMapPropertiesEditor.edit(map().food());
terrainMapPropertiesEditor.edit(map().terrain());
invalidatePaths();
updatePaths();
Logger.debug("Edit canvas size: w={} h={}", editCanvas.getWidth(), editCanvas.getHeight());
Expand Down

0 comments on commit 9fa66fa

Please sign in to comment.