mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-08-23 13:29:01 +00:00
Switched to JFX 1.8 packaging and added visibility controls for scripts (still a work in progress though)
This commit is contained in:
parent
c79f333d24
commit
f4b45003bd
@ -79,7 +79,7 @@
|
||||
<dependency>
|
||||
<groupId>javafx-packager</groupId>
|
||||
<artifactId>javafx-packager</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8</version>
|
||||
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>
|
||||
|
@ -1,9 +1,12 @@
|
||||
package org.badvision.outlaweditor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
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 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) {
|
||||
if (scripts == null || scripts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<Script> visibleScripts = scripts.stream().filter(this::isScriptVisible).collect(Collectors.toList());
|
||||
if (visibleScripts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
GraphicsContext gc = drawCanvas.getGraphicsContext2D();
|
||||
int idx = 0;
|
||||
double xx = x * tileWidth;
|
||||
double yy = y * tileHeight;
|
||||
gc.setLineWidth(4);
|
||||
for (int i = 0; i < tileWidth - 2; i += dashLength) {
|
||||
idx = (idx + 1) % scripts.size();
|
||||
idx = (idx + 1) % visibleScripts.size();
|
||||
gc.beginPath();
|
||||
gc.moveTo(xx, yy);
|
||||
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke);
|
||||
currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
|
||||
xx += dashLength;
|
||||
gc.lineTo(xx, yy);
|
||||
gc.setEffect(new DropShadow(2, Color.BLACK));
|
||||
gc.stroke();
|
||||
}
|
||||
for (int i = 0; i < tileHeight - 2; i += dashLength) {
|
||||
idx = (idx + 1) % scripts.size();
|
||||
idx = (idx + 1) % visibleScripts.size();
|
||||
gc.beginPath();
|
||||
gc.moveTo(xx, yy);
|
||||
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke);
|
||||
currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
|
||||
yy += dashLength;
|
||||
gc.lineTo(xx, yy);
|
||||
gc.setEffect(new DropShadow(2, Color.BLACK));
|
||||
gc.stroke();
|
||||
}
|
||||
for (int i = 0; i < tileWidth - 2; i += dashLength) {
|
||||
idx = (idx + 1) % scripts.size();
|
||||
idx = (idx + 1) % visibleScripts.size();
|
||||
gc.beginPath();
|
||||
gc.moveTo(xx, yy);
|
||||
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke);
|
||||
currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
|
||||
xx -= dashLength;
|
||||
gc.lineTo(xx, yy);
|
||||
gc.setEffect(new DropShadow(2, Color.BLACK));
|
||||
gc.stroke();
|
||||
}
|
||||
for (int i = 0; i < tileHeight - 2; i += dashLength) {
|
||||
idx = (idx + 1) % scripts.size();
|
||||
idx = (idx + 1) % visibleScripts.size();
|
||||
gc.beginPath();
|
||||
gc.moveTo(xx, yy);
|
||||
currentMap.getScriptColor(scripts.get(idx)).ifPresent(gc::setStroke);
|
||||
currentMap.getScriptColor(visibleScripts.get(idx)).ifPresent(gc::setStroke);
|
||||
yy -= dashLength;
|
||||
gc.lineTo(xx, yy);
|
||||
gc.setEffect(new DropShadow(2, Color.BLACK));
|
||||
|
@ -150,7 +150,7 @@ public class UIAction {
|
||||
|
||||
public static WritableImage getBadImage(int width, int height) {
|
||||
if (badImage == null) {
|
||||
badImage = new Image("/images/icon_brokenLink.png");
|
||||
badImage = new Image("images/icon_brokenLink.png");
|
||||
}
|
||||
WritableImage img = new WritableImage(width, height);
|
||||
img.getPixelWriter().setPixels(0, 0, (int) badImage.getWidth(), (int) badImage.getHeight(), badImage.getPixelReader(), 0, 0);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.badvision.outlaweditor.ui.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.event.ActionEvent;
|
||||
@ -7,6 +9,7 @@ import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.cell.ComboBoxListCell;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.util.Callback;
|
||||
@ -310,9 +313,16 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
|
||||
if (empty || item == null) {
|
||||
setText("");
|
||||
} else {
|
||||
ImageView visibleIcon = getVisibleIcon(item);
|
||||
visibleIcon.setOnMouseClicked((e)->{
|
||||
toggleVisibility(visibleIcon, item);
|
||||
mapScriptsList.getSelectionModel().clearSelection();
|
||||
});
|
||||
setGraphic(visibleIcon);
|
||||
getCurrentEditor().getCurrentMap().getScriptColor(item).ifPresent(this::setTextFill);
|
||||
setText(item.getName());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user