This commit is contained in:
David Schmenk 2014-06-12 18:40:35 -07:00
commit 3eaf2d1bed
6 changed files with 132 additions and 92 deletions

View File

@ -40,8 +40,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
<version>3.1</version>
</plugin>
@ -69,14 +69,13 @@
</build>
<dependencies>
<dependency>
<!-- <dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2</version>
<!--<systemPath>/usr/lib/jvm/jdk1.7.0_21/jre/lib/jfxrt.jar</systemPath>-->
<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
<scope>system</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>javafx-packager</groupId>
<artifactId>javafx-packager</artifactId>

View File

@ -1,19 +1,13 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.badvision.outlaweditor;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.ImageCursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.ImageView;
@ -27,7 +21,6 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.TransferHelper.DropEventHandler;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.xml.Map;
@ -62,16 +55,13 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
return currentMap;
}
EventHandler<ScrollEvent> scrollHandler = new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent t) {
if (t.isShiftDown()) {
t.consume();
if (t.getDeltaY() > 0) {
zoomIn();
} else {
zoomOut();
}
EventHandler<ScrollEvent> scrollHandler = (ScrollEvent t) -> {
if (t.isShiftDown()) {
t.consume();
if (t.getDeltaY() > 0) {
zoomIn();
} else {
zoomOut();
}
}
};
@ -101,28 +91,19 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
drawCanvas.heightProperty().bind(Application.getPrimaryStage().heightProperty().subtract(120));
drawCanvas.widthProperty().bind(Application.getPrimaryStage().widthProperty().subtract(200));
// drawCanvas.widthProperty().bind(anchorPane.widthProperty());
drawCanvas.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
redraw();
}
drawCanvas.widthProperty().addListener((ObservableValue<? extends Number> ov, Number t, Number t1) -> {
redraw();
});
drawCanvas.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
redraw();
}
drawCanvas.heightProperty().addListener((ObservableValue<? extends Number> ov, Number t, Number t1) -> {
redraw();
});
drawCanvas.addEventFilter(ScrollEvent.ANY, scrollHandler);
drawCanvas.setOnMousePressed(this);
drawCanvas.setOnMouseDragged(this);
drawCanvas.setOnMouseDragReleased(this);
drawCanvas.setOnMouseReleased(this);
scriptDragDrop.registerDropSupport(drawCanvas, new DropEventHandler<Script>() {
@Override
public void handle(Script script, double x, double y) {
assignScript(script, x, y);
}
scriptDragDrop.registerDropSupport(drawCanvas, (Script script, double x, double y) -> {
assignScript(script, x, y);
});
anchorPane.getChildren().add(0, drawCanvas);
}
@ -140,12 +121,9 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
}
public void togglePanZoom() {
for (Node n : anchorPane.getChildren()) {
if (n == drawCanvas) {
continue;
}
anchorPane.getChildren().stream().filter((n) -> !(n == drawCanvas)).forEach((n) -> {
n.setVisible(!n.isVisible());
}
});
}
public void scrollBy(int deltaX, int deltaY) {
@ -198,34 +176,29 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
private long redrawRequested;
private Thread redrawThread;
@Override
public void redraw() {
redrawRequested = System.nanoTime();
if (redrawThread == null || redrawThread.isAlive()) {
redrawThread = new Thread(new Runnable() {
@Override
public void run() {
long test = redrawRequested;
redrawThread = new Thread(() -> {
long test = redrawRequested;
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(MapEditor.class.getName()).log(Level.SEVERE, null, ex);
}
while (test != redrawRequested) {
test = redrawRequested;
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(MapEditor.class.getName()).log(Level.SEVERE, null, ex);
}
while (test != redrawRequested) {
test = redrawRequested;
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(MapEditor.class.getName()).log(Level.SEVERE, null, ex);
}
}
Platform.runLater(new Runnable() {
@Override
public void run() {
doRedraw();
}
});
redrawThread = null;
}
Platform.runLater(() -> {
doRedraw();
});
redrawThread = null;
});
redrawThread.start();
}

View File

@ -1,20 +1,25 @@
package org.badvision.outlaweditor.data;
import org.badvision.outlaweditor.Platform;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javax.swing.JOptionPane;
import javax.xml.bind.JAXBElement;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.ui.UIAction;
import org.badvision.outlaweditor.Platform;
import org.badvision.outlaweditor.data.xml.Map;
import org.badvision.outlaweditor.data.xml.Map.Chunk;
import org.badvision.outlaweditor.data.xml.ObjectFactory;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Script.LocationTrigger;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.UIAction;
/**
*
@ -35,6 +40,57 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
loadFromMap(m);
}
public static final double SATURATION = 0.5;
public static final double VALUE = 1.0;
public static double HUE = 0;
private java.util.Map<Integer, List<Script>> locationScripts = new HashMap<>();
private java.util.Map<Script, Color> scriptColors = new HashMap<>();
public Color getScriptColor(Script s) {
return scriptColors.get(s);
}
public List<Script> getLocationScripts(int x, int y) {
List<Script> list = locationScripts.get(getMortonNumber(x, y));
if (list != null) {
return list;
} else {
return Collections.EMPTY_LIST;
}
}
public void putLocationScript(int x, int y, Script s) {
LocationTrigger trigger = new Script.LocationTrigger();
trigger.setX(x);
trigger.setY(y);
s.getLocationTrigger().add(trigger);
registerLocationScript(x, y, s);
}
private void registerLocationScript(int x, int y, Script s) {
if (!scriptColors.containsKey(s)) {
scriptColors.put(s, Color.hsb(HUE, SATURATION, VALUE));
HUE = (HUE + 20) % 360;
}
int loc = getMortonNumber(x, y);
List<Script> list = locationScripts.get(loc);
if (list == null) {
list = new ArrayList<>();
locationScripts.put(loc, list);
}
list.add(s);
}
private int getMortonNumber(int x, int y) {
int morton = 0;
for (int i = 0; i < 16; i++) {
int mask = 1 << (i);
morton += (x & mask) << (i + 1);
morton += (y & mask) << i;
}
return morton;
}
public Tile get(int x, int y) {
if (size() <= y || get(y) == null) {
return null;
@ -52,7 +108,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
add(null);
}
if (get(y) == null) {
set(y, new ArrayList<Tile>());
set(y, new ArrayList<>());
}
List<Tile> row = get(y);
for (int i = row.size(); i <= x; i++) {
@ -93,7 +149,12 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
width = 0;
height = 0;
Set<Tile> unknownTiles = new HashSet<>();
for (Chunk c : m.getChunk()) {
m.getScripts().getScript().forEach(
s -> s.getLocationTrigger().forEach(
l -> registerLocationScript(l.getX(), l.getY(), s)
)
);
m.getChunk().forEach( c-> {
int y = c.getY();
for (JAXBElement<List<String>> row : c.getRow()) {
int x = c.getX();
@ -114,7 +175,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
}
y++;
}
}
});
if (!unknownTiles.isEmpty()) {
int numMissing = unknownTiles.size();
JOptionPane.showMessageDialog(null, (numMissing > 1

View File

@ -31,25 +31,21 @@
<xs:element name="name" type="xs:string"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="block" type="tns:block"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="locationScript">
<xs:complexContent>
<xs:extension base="tns:script">
<xs:attribute name="x" type="xs:int"/>
<xs:attribute name="y" type="xs:int"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="intervalScript">
<xs:complexContent>
<xs:extension base="tns:script">
<xs:element name="locationTrigger" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="x" type="xs:int"/>
<xs:attribute name="y" type="xs:int"/>
</xs:complexType>
</xs:element>
<xs:element name="intervalTrigger" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="start" type="xs:int" use="optional"/>
<xs:attribute name="end" type="xs:int" use="optional"/>
<xs:attribute name="period" type="xs:int" use="optional"/>
<xs:attribute name="ifTrue" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="map">
<xs:sequence>

View File

@ -80,9 +80,12 @@ is divided into following sections:
</and>
</condition>
<condition property="do.archive">
<not>
<istrue value="${jar.archive.disabled}"/>
</not>
<or>
<not>
<istrue value="${jar.archive.disabled}"/>
</not>
<istrue value="${not.archive.disabled}"/>
</or>
</condition>
<condition property="do.mkdist">
<and>
@ -170,7 +173,12 @@ is divided into following sections:
</condition>
<path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
<condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
<length length="0" string="${endorsed.classpath}" when="greater"/>
<and>
<isset property="endorsed.classpath"/>
<not>
<equals arg1="${endorsed.classpath}" arg2="" trim="true"/>
</not>
</and>
</condition>
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
<isset property="profile.available"/>
@ -827,7 +835,7 @@ is divided into following sections:
</pathconvert>
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
<copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
<fileset dir="${build.classes.dir}"/>
<fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
<customize/>
@ -839,7 +847,7 @@ is divided into following sections:
<target name="-init-presetdef-jar">
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
<jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
<j2seproject1:fileset dir="${build.classes.dir}"/>
<j2seproject1:fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
</jar>
</presetdef>
</target>
@ -1194,11 +1202,14 @@ is divided into following sections:
</not>
</and>
</condition>
<javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<condition else="" property="bug5101868workaround" value="*.java">
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
</condition>
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<classpath>
<path path="${javac.classpath}"/>
</classpath>
<fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}">
<fileset dir="${src.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
<fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
@ -1272,7 +1283,7 @@ is divided into following sections:
<mkdir dir="${build.test.results.dir}"/>
</target>
<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
<j2seproject3:test testincludes="**/*Test.java"/>
<j2seproject3:test includes="${includes}" testincludes="**/*Test.java"/>
</target>
<target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>

View File

@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=8064a381@1.68.1.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=5246bcd2
nbproject/build-impl.xml.script.CRC32=ca8bcaaf
nbproject/build-impl.xml.stylesheet.CRC32=cdba79fa@1.68.1.46
nbproject/build-impl.xml.script.CRC32=0f1cf190
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.1.48