This commit is contained in:
Martin Haye 2015-05-21 07:19:28 -07:00
commit 2b9cfbde71
8 changed files with 96 additions and 14 deletions

View File

@ -28,7 +28,6 @@ import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.FillRule;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import static org.badvision.outlaweditor.Application.currentPlatform;

View File

@ -129,7 +129,6 @@ public class MythosEditor {
return;
}
script.setName(name);
System.out.println("Function title changed! >> " + name);
ApplicationUIController.getController().redrawScripts();
}
}

View File

@ -11,6 +11,13 @@ import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.util.JAXBSource;
import javax.xml.namespace.QName;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.ui.ToolType;
/**
@ -98,4 +105,17 @@ public class TransferHelper<T> {
});
};
}
public static <U> U cloneObject(U source, Class<U> type, String nodeType) throws JAXBException {
JAXBContext sourceJAXBContext = JAXBContext.newInstance(source.getClass());
Marshaller jaxbMarshaller = sourceJAXBContext.createMarshaller();
// format the XML output
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
JAXBContext targetJAXBContext = JAXBContext.newInstance(source.getClass());
QName qName = new QName("info.source4code.jaxb.model", nodeType);
JAXBElement<U> root = new JAXBElement<>(qName, type, source);
JAXBElement<U> cloneRoot = (JAXBElement<U>) targetJAXBContext.createUnmarshaller().unmarshal(new JAXBSource(sourceJAXBContext, root), type);
return cloneRoot.getValue();
}
}

View File

@ -12,7 +12,6 @@ import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import org.badvision.outlaweditor.Platform;
import org.badvision.outlaweditor.TileEditor;
import org.badvision.outlaweditor.data.DataObserver;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.data.TileUtils;
@ -24,6 +23,7 @@ public class AppleTileEditor extends TileEditor {
FillPattern currentPattern = FillPattern.DarkViolet1;
DrawMode drawMode = DrawMode.Toggle;
public static final long SAFE_WAIT_TIME = 100;
@Override
public void setEntity(Tile t) {
@ -74,6 +74,7 @@ public class AppleTileEditor extends TileEditor {
}
int lastActionX = -1;
int lastActionY = -1;
long debounceTime = 0;
public void performDragAction(int x, int y) {
performAction(false, x, y);
@ -82,9 +83,10 @@ public class AppleTileEditor extends TileEditor {
private void performAction(boolean alt, int x, int y) {
y = Math.min(Math.max(y, 0), 15);
x = Math.min(Math.max(x, 0), 13);
if (lastActionX == x && lastActionY == y) {
if ((lastActionX == x && lastActionY == y) && (debounceTime > System.currentTimeMillis())) {
return;
}
debounceTime = System.currentTimeMillis() + SAFE_WAIT_TIME;
lastActionX = x;
lastActionY = y;
switch (drawMode) {

View File

@ -193,6 +193,10 @@ public class UIAction {
public static void confirm(String message, Runnable yes, Runnable no) {
choose(message, new Choice("Yes", yes), new Choice("No", no));
}
public static void alert(String message) {
choose(message, new Choice("Ok", null));
}
public static void choose(String message, Choice... choices) {
final Stage dialogStage = new Stage();

View File

@ -14,6 +14,7 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.util.Callback;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import static org.badvision.outlaweditor.Application.currentPlatform;
import static org.badvision.outlaweditor.Application.gameData;
@ -25,18 +26,21 @@ import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.xml.Map;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import org.badvision.outlaweditor.ui.MapEditorTabController;
import org.badvision.outlaweditor.ui.ToolType;
import org.badvision.outlaweditor.ui.UIAction;
import static org.badvision.outlaweditor.ui.UIAction.confirm;
import static org.badvision.outlaweditor.ui.UIAction.createAndEditScript;
import static org.badvision.outlaweditor.ui.UIAction.editScript;
/**
*
* @author blurry
*/
public class MapEditorTabControllerImpl extends MapEditorTabController {
final TransferHelper<Script> scriptDragDrop = new TransferHelper<>(Script.class);
final TransferHelper<ToolType> toolDragDrop = new TransferHelper<>(ToolType.class);
@ -144,9 +148,46 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
createAndEditScript();
}
int errorCount = 0;
long gagTimeout = 0;
@Override
public void onMapScriptClonePressed(ActionEvent event) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Script source = mapScriptsList.getSelectionModel().getSelectedItem();
if (source == null) {
String message = "First select a script and then press Clone";
if (gagTimeout == 0 || gagTimeout < System.currentTimeMillis()) {
gagTimeout = System.currentTimeMillis() + 15000;
errorCount = 1;
} else {
switch (++errorCount) {
case 3:
message = "Seriously, select a script first";
break;
case 4:
message = "By select, I mean move the mouse and click on something";
break;
case 5:
message = "I really can't help you";
break;
case 6:
message = "Bored? Lonely? Have you trolled any YouTube comments lately?";
break;
default:
}
}
UIAction.alert(message);
} else {
try {
Script script = TransferHelper.cloneObject(source, Script.class, "script");
script.setName(source.getName() + " CLONE");
getCurrentEditor().addScript(script);
editScript(script);
} catch (JAXBException ex) {
Logger.getLogger(MapEditorTabControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
UIAction.alert("Error occured when attempting clone operation:\n" + ex.getMessage());
}
}
}
@Override
@ -225,6 +266,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
mapWrapAround.setDisable(true);
setCurrentEditor(null);
} else {
sortScripts(m);
if (m.getHeight() == null) {
m.setHeight(512);
}
@ -291,13 +333,13 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
});
toolDragDrop.registerDragSupport(scriptEraseTool, ToolType.ERASER);
}
@Override
public void rebuildTileSelectors() {
mapSelectTile.getItems().clear();
ToggleGroup tileGroup = new ToggleGroup();
HashMap<String,Menu> submenus = new HashMap<>();
HashMap<String, Menu> submenus = new HashMap<>();
Application.gameData.getTile().stream().forEach((Tile t) -> {
WritableImage img = TileUtils.getImage(t, currentPlatform);
ImageView iv = new ImageView(img);
@ -348,7 +390,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
setText("");
} else {
ImageView visibleIcon = getVisibleIcon(item);
visibleIcon.setOnMouseClicked((e)->{
visibleIcon.setOnMouseClicked((e) -> {
toggleVisibility(visibleIcon, item);
mapScriptsList.getSelectionModel().clearSelection();
});
@ -367,16 +409,17 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
mapScriptsList.getItems().clear();
} else {
if (mapScriptsList.getItems() != null && getCurrentMap().getScripts() != null) {
sortScripts(getCurrentMap());
mapScriptsList.getItems().setAll(getCurrentMap().getScripts().getScript());
} else {
mapScriptsList.getItems().clear();
}
}
}
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);
@ -384,9 +427,11 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
return new ImageView(INVISIBLE_IMAGE);
}
}
private void toggleVisibility(ImageView visibilityIcon, Script script) {
if (script.getName() == null) return;
if (script.getName() == null) {
return;
}
if (getCurrentEditor().isScriptVisible(script)) {
getCurrentEditor().setScriptVisible(script, false);
visibilityIcon.setImage(INVISIBLE_IMAGE);
@ -395,4 +440,15 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
visibilityIcon.setImage(VISIBLE_IMAGE);
}
}
private void sortScripts(Map m) {
m.getScripts().getScript().sort((a, b) -> {
if (a.getName().equalsIgnoreCase("init")) {
return -1;
} else if (b.getName().equalsIgnoreCase("init")) {
return 1;
}
return a.getName().compareTo(b.getName());
});
}
}

View File

@ -68,7 +68,7 @@
<AnchorPane fx:id="mapEditorAnchorPane" prefHeight="389.0" prefWidth="477.0000999999975" HBox.hgrow="SOMETIMES">
<children>
<Button alignment="TOP_CENTER" layoutX="265.0" mnemonicParsing="false" onAction="#scrollMapUp" styleClass="moveButton" text="Up" AnchorPane.topAnchor="5.0" />
<Button layoutY="185.0" mnemonicParsing="false" onAction="#scrollMapLeft" rotate="270.0" styleClass="moveButton" text="Left" AnchorPane.leftAnchor="-20.0" />
<Button layoutY="185.0" mnemonicParsing="false" onAction="#scrollMapLeft" rotate="270.0" styleClass="moveButton" text="Left" AnchorPane.leftAnchor="-10.0" />
<Button layoutX="265.0" mnemonicParsing="false" onAction="#scrollMapDown" rotate="180.0" styleClass="moveButton" text="Down" AnchorPane.bottomAnchor="5.0" />
<Button layoutY="175.0" mnemonicParsing="false" onAction="#scrollMapRight" rotate="90.0" styleClass="moveButton" text="Right" AnchorPane.rightAnchor="-15.0" />
<Button mnemonicParsing="false" onAction="#mapZoomIn" styleClass="zoomInButton" text="+" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="5.0" />

View File

@ -1,3 +1,5 @@
/* global Blockly */
if (typeof Mythos === "undefined") {
// Hook up the rename function to notify the java editor when changes occur
Blockly.Procedures.rename_old = Blockly.Procedures.rename;