This commit is contained in:
Martin Haye 2015-05-15 08:19:32 -07:00
commit f0a53623b5
7 changed files with 107 additions and 18 deletions

View File

@ -79,7 +79,7 @@
<dependency> <dependency>
<groupId>javafx-packager</groupId> <groupId>javafx-packager</groupId>
<artifactId>javafx-packager</artifactId> <artifactId>javafx-packager</artifactId>
<version>1.7</version> <version>1.8</version>
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath> <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
<scope>system</scope> <scope>system</scope>
</dependency> </dependency>

View File

@ -1,9 +1,12 @@
package org.badvision.outlaweditor; package org.badvision.outlaweditor;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler; import javafx.event.EventHandler;
@ -247,50 +250,75 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
private static final int dashLength = 3; private static final int dashLength = 3;
private final Set<Script> invisibleScripts = new HashSet<>();
public boolean isScriptVisible(Script script) {
return !invisibleScripts.contains(script);
}
public void setScriptVisible(Script script, boolean visible) {
setScriptVisible(script, visible, true);
}
public void setScriptVisible(Script script, boolean visible, boolean redraw) {
if (visible) {
invisibleScripts.remove(script);
} else {
invisibleScripts.add(script);
}
if (redraw) {
redraw();
}
}
private void highlightScripts(int x, int y, List<Script> scripts) { private void highlightScripts(int x, int y, List<Script> scripts) {
if (scripts == null || scripts.isEmpty()) { if (scripts == null || scripts.isEmpty()) {
return; return;
} }
List<Script> visibleScripts = scripts.stream().filter(this::isScriptVisible).collect(Collectors.toList());
if (visibleScripts.isEmpty()) {
return;
}
GraphicsContext gc = drawCanvas.getGraphicsContext2D(); GraphicsContext gc = drawCanvas.getGraphicsContext2D();
int idx = 0; int idx = 0;
double xx = x * tileWidth; double xx = x * tileWidth;
double yy = y * tileHeight; double yy = y * tileHeight;
gc.setLineWidth(4); gc.setLineWidth(4);
for (int i = 0; i < tileWidth - 2; i += dashLength) { for (int i = 0; i < tileWidth - 2; i += dashLength) {
idx = (idx + 1) % scripts.size(); idx = (idx + 1) % visibleScripts.size();
gc.beginPath(); gc.beginPath();
gc.moveTo(xx, yy); gc.moveTo(xx, yy);
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke); currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
xx += dashLength; xx += dashLength;
gc.lineTo(xx, yy); gc.lineTo(xx, yy);
gc.setEffect(new DropShadow(2, Color.BLACK)); gc.setEffect(new DropShadow(2, Color.BLACK));
gc.stroke(); gc.stroke();
} }
for (int i = 0; i < tileHeight - 2; i += dashLength) { for (int i = 0; i < tileHeight - 2; i += dashLength) {
idx = (idx + 1) % scripts.size(); idx = (idx + 1) % visibleScripts.size();
gc.beginPath(); gc.beginPath();
gc.moveTo(xx, yy); gc.moveTo(xx, yy);
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke); currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
yy += dashLength; yy += dashLength;
gc.lineTo(xx, yy); gc.lineTo(xx, yy);
gc.setEffect(new DropShadow(2, Color.BLACK)); gc.setEffect(new DropShadow(2, Color.BLACK));
gc.stroke(); gc.stroke();
} }
for (int i = 0; i < tileWidth - 2; i += dashLength) { for (int i = 0; i < tileWidth - 2; i += dashLength) {
idx = (idx + 1) % scripts.size(); idx = (idx + 1) % visibleScripts.size();
gc.beginPath(); gc.beginPath();
gc.moveTo(xx, yy); gc.moveTo(xx, yy);
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke); currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
xx -= dashLength; xx -= dashLength;
gc.lineTo(xx, yy); gc.lineTo(xx, yy);
gc.setEffect(new DropShadow(2, Color.BLACK)); gc.setEffect(new DropShadow(2, Color.BLACK));
gc.stroke(); gc.stroke();
} }
for (int i = 0; i < tileHeight - 2; i += dashLength) { for (int i = 0; i < tileHeight - 2; i += dashLength) {
idx = (idx + 1) % scripts.size(); idx = (idx + 1) % visibleScripts.size();
gc.beginPath(); gc.beginPath();
gc.moveTo(xx, yy); gc.moveTo(xx, yy);
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke); currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
yy -= dashLength; yy -= dashLength;
gc.lineTo(xx, yy); gc.lineTo(xx, yy);
gc.setEffect(new DropShadow(2, Color.BLACK)); gc.setEffect(new DropShadow(2, Color.BLACK));

View File

@ -150,7 +150,7 @@ public class UIAction {
public static WritableImage getBadImage(int width, int height) { public static WritableImage getBadImage(int width, int height) {
if (badImage == null) { if (badImage == null) {
badImage = new Image("/images/icon_brokenLink.png"); badImage = new Image("images/icon_brokenLink.png");
} }
WritableImage img = new WritableImage(width, height); WritableImage img = new WritableImage(width, height);
img.getPixelWriter().setPixels(0, 0, (int) badImage.getWidth(), (int) badImage.getHeight(), badImage.getPixelReader(), 0, 0); img.getPixelWriter().setPixels(0, 0, (int) badImage.getWidth(), (int) badImage.getHeight(), badImage.getPixelReader(), 0, 0);

View File

@ -1,12 +1,16 @@
package org.badvision.outlaweditor.ui.impl; package org.badvision.outlaweditor.ui.impl;
import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem; import javafx.scene.control.Menu;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.ComboBoxListCell; import javafx.scene.control.cell.ComboBoxListCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage; import javafx.scene.image.WritableImage;
import javafx.util.Callback; import javafx.util.Callback;
@ -197,8 +201,10 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
if (getCurrentMap() != null && getCurrentMap().equals(m)) { if (getCurrentMap() != null && getCurrentMap().equals(m)) {
return; return;
} }
Tile currentTile = null;
// mapEditorAnchorPane.getChildren().clear(); // mapEditorAnchorPane.getChildren().clear();
if (getCurrentEditor() != null) { if (getCurrentEditor() != null) {
currentTile = getCurrentEditor().getCurrentTile();
getCurrentEditor().unregister(); getCurrentEditor().unregister();
} }
if (m == null) { if (m == null) {
@ -238,6 +244,9 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
e.buildEditorUI(mapEditorAnchorPane); e.buildEditorUI(mapEditorAnchorPane);
setCurrentEditor(e); setCurrentEditor(e);
e.setupDragDrop(scriptDragDrop, toolDragDrop); e.setupDragDrop(scriptDragDrop, toolDragDrop);
if (currentTile != null) {
e.setCurrentTile(currentTile);
}
} }
redrawMapScripts(); redrawMapScripts();
} }
@ -279,19 +288,40 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
@Override @Override
public void rebuildTileSelectors() { public void rebuildTileSelectors() {
mapSelectTile.getItems().clear(); mapSelectTile.getItems().clear();
Application.gameData.getTile().stream().map((Tile t) -> {
ToggleGroup tileGroup = new ToggleGroup();
HashMap<String,Menu> submenus = new HashMap<>();
Application.gameData.getTile().stream().forEach((Tile t) -> {
WritableImage img = TileUtils.getImage(t, currentPlatform); WritableImage img = TileUtils.getImage(t, currentPlatform);
ImageView iv = new ImageView(img); ImageView iv = new ImageView(img);
MenuItem mapSelectItem = new MenuItem(String.valueOf(t.getCategory())+"/"+String.valueOf(t.getName()), iv); String category = String.valueOf(t.getCategory());
mapSelectItem.setGraphic(new ImageView(TileUtils.getImage(t, currentPlatform))); Menu categoryMenu = submenus.get(category);
mapSelectItem.setOnAction((event) -> { if (categoryMenu == null) {
categoryMenu = new Menu(category);
submenus.put(category, categoryMenu);
}
final Menu theMenu = categoryMenu;
RadioMenuItem tileSelection = new RadioMenuItem(String.valueOf(t.getName()), iv);
tileSelection.setToggleGroup(tileGroup);
if (getCurrentEditor() != null && getCurrentEditor().getCurrentTile() == t) {
tileGroup.selectToggle(tileSelection);
theMenu.setStyle("-fx-font-weight:bold; -fx-text-fill:blue");
}
tileSelection.setGraphic(new ImageView(TileUtils.getImage(t, currentPlatform)));
tileSelection.setOnAction((event) -> {
if (getCurrentEditor() != null) { if (getCurrentEditor() != null) {
getCurrentEditor().setCurrentTile(t); getCurrentEditor().setCurrentTile(t);
} }
tileGroup.selectToggle(tileSelection);
submenus.values().stream().forEach((menu) -> {
menu.setStyle(null);
});
theMenu.setStyle("-fx-font-weight:bold; -fx-text-fill:blue");
}); });
return mapSelectItem; categoryMenu.getItems().add(tileSelection);
}).forEach((mapSelectItem) -> { });
mapSelectTile.getItems().add(mapSelectItem); submenus.values().stream().forEach((menu) -> {
mapSelectTile.getItems().add(menu);
}); });
} }
@ -310,9 +340,16 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
if (empty || item == null) { if (empty || item == null) {
setText(""); setText("");
} else { } else {
ImageView visibleIcon = getVisibleIcon(item);
visibleIcon.setOnMouseClicked((e)->{
toggleVisibility(visibleIcon, item);
mapScriptsList.getSelectionModel().clearSelection();
});
setGraphic(visibleIcon);
getCurrentEditor().getCurrentMap().getScriptColor(item).ifPresent(this::setTextFill); getCurrentEditor().getCurrentMap().getScriptColor(item).ifPresent(this::setTextFill);
setText(item.getName()); setText(item.getName());
scriptDragDrop.registerDragSupport(this, item); scriptDragDrop.registerDragSupport(this, item);
visibleIcon.setMouseTransparent(false);
} }
} }
}; };
@ -329,4 +366,26 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
} }
} }
} }
public static final Image VISIBLE_IMAGE = new Image("images/visible.png");
public static final Image INVISIBLE_IMAGE = new Image("images/not_visible.png");
private ImageView getVisibleIcon(Script script) {
if (getCurrentEditor().isScriptVisible(script)) {
return new ImageView(VISIBLE_IMAGE);
} else {
return new ImageView(INVISIBLE_IMAGE);
}
}
private void toggleVisibility(ImageView visibilityIcon, Script script) {
if (script.getName() == null) return;
if (getCurrentEditor().isScriptVisible(script)) {
getCurrentEditor().setScriptVisible(script, false);
visibilityIcon.setImage(INVISIBLE_IMAGE);
} else {
getCurrentEditor().setScriptVisible(script, true);
visibilityIcon.setImage(VISIBLE_IMAGE);
}
}
} }

View File

@ -229,6 +229,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
@Override @Override
public void rebuildTileSelectors() { public void rebuildTileSelectors() {
Tile t = getCurrentTile();
tileSelector.getItems().clear(); tileSelector.getItems().clear();
List<Tile> allTiles = Application.gameData.getTile(); List<Tile> allTiles = Application.gameData.getTile();
allTiles.sort((Tile o1, Tile o2) -> { allTiles.sort((Tile o1, Tile o2) -> {
@ -240,5 +241,6 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
}); });
tileSelector.getItems().addAll(allTiles); tileSelector.getItems().addAll(allTiles);
tileSelector.getSelectionModel().select(allTiles.indexOf(getCurrentTile())); tileSelector.getSelectionModel().select(allTiles.indexOf(getCurrentTile()));
setCurrentTile(t);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 B