Switched to JFX 1.8 packaging and added visibility controls for scripts (still a work in progress though)

This commit is contained in:
Brendan Robert 2015-05-14 01:01:58 -05:00
parent c79f333d24
commit f4b45003bd
4 changed files with 70 additions and 10 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,5 +1,7 @@
package org.badvision.outlaweditor.ui.impl; package org.badvision.outlaweditor.ui.impl;
import java.util.HashSet;
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 javafx.event.ActionEvent; import javafx.event.ActionEvent;
@ -7,6 +9,7 @@ import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
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;
@ -310,9 +313,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 +339,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);
}
}
} }