mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-12-25 13:29:59 +00:00
Script editing is now completely hooked up to load/save
This commit is contained in:
parent
763507acf3
commit
a21a38bf4c
@ -18,7 +18,6 @@ import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.badvision.outlaweditor.data.xml.Tile;
|
||||
|
||||
public abstract class ApplicationUIController {
|
||||
|
||||
@FXML // ResourceBundle that was given to the FXMLLoader
|
||||
protected ResourceBundle resources;
|
||||
@FXML // URL location of the FXML file that was given to the FXMLLoader
|
||||
@ -218,10 +217,6 @@ public abstract class ApplicationUIController {
|
||||
// Handler for Button[Button[id=null, styleClass=button]] onAction
|
||||
@FXML
|
||||
abstract public void onMapScriptClonePressed(ActionEvent event);
|
||||
|
||||
// Handler for onClick
|
||||
@FXML
|
||||
abstract public void onMapScriptClicked(MouseEvent event);
|
||||
|
||||
// Handler for Button[Button[id=null, styleClass=button]] onAction
|
||||
@FXML
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.badvision.outlaweditor;
|
||||
|
||||
import org.badvision.outlaweditor.apple.AppleTileRenderer;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -21,12 +20,14 @@ import javafx.scene.input.MouseEvent;
|
||||
import javafx.util.Callback;
|
||||
import static org.badvision.outlaweditor.Application.currentPlatform;
|
||||
import static org.badvision.outlaweditor.Application.gameData;
|
||||
import static org.badvision.outlaweditor.data.PropertyHelper.*;
|
||||
import static org.badvision.outlaweditor.UIAction.*;
|
||||
import org.badvision.outlaweditor.apple.AppleTileRenderer;
|
||||
import static org.badvision.outlaweditor.data.PropertyHelper.*;
|
||||
import org.badvision.outlaweditor.data.TileUtils;
|
||||
import org.badvision.outlaweditor.data.TilesetUtils;
|
||||
import org.badvision.outlaweditor.data.xml.Image;
|
||||
import org.badvision.outlaweditor.data.xml.PlatformData;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.badvision.outlaweditor.data.xml.Tile;
|
||||
|
||||
/**
|
||||
@ -465,12 +466,6 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapScriptClicked(MouseEvent event) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMapSelected(ActionEvent event) {
|
||||
setCurrentMap(mapSelect.getSelectionModel().getSelectedItem());
|
||||
@ -737,6 +732,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
||||
currentMapEditor.setEntity(m);
|
||||
currentMapEditor.buildEditorUI(mapEditorAnchorPane);
|
||||
}
|
||||
redrawMapScripts();
|
||||
}
|
||||
|
||||
public void rebuildMapSelectors() {
|
||||
@ -837,6 +833,36 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void redrawMapScripts() {
|
||||
mapScriptsList.setOnEditStart(new EventHandler<ListView.EditEvent<Script>>() {
|
||||
@Override
|
||||
public void handle(ListView.EditEvent<Script> event) {
|
||||
UIAction.editScript(event.getSource().getItems().get(event.getIndex()));
|
||||
}
|
||||
});
|
||||
mapScriptsList.setCellFactory(new Callback<ListView<Script>, ListCell<Script>>() {
|
||||
@Override
|
||||
public ListCell<Script> call(ListView<Script> param) {
|
||||
return new ListCell<Script>() {
|
||||
@Override
|
||||
protected void updateItem(Script item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setText("");
|
||||
} else {
|
||||
setText(item.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
if (currentMap == null) {
|
||||
mapScriptsList.getItems().clear();
|
||||
} else {
|
||||
mapScriptsList.getItems().setAll(currentMap.getScripts().getScript());
|
||||
}
|
||||
}
|
||||
|
||||
abstract public static class EntitySelectorCell<T> extends ComboBoxListCell<T> {
|
||||
|
||||
static Map<TextField, Object> lastSelected = new HashMap<>();
|
||||
|
@ -17,6 +17,7 @@ import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@ -100,8 +101,13 @@ public class MythosEditor {
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(Block.class);
|
||||
StringWriter buffer = new StringWriter();
|
||||
context.createMarshaller().marshal(script.getBlock(), buffer);
|
||||
QName qName = new QName("outlaw","block");
|
||||
JAXBElement<Block> root = new JAXBElement<>(qName, Block.class, script.getBlock());
|
||||
context.createMarshaller().marshal(root, buffer);
|
||||
String xml = buffer.toString();
|
||||
xml=xml.replace("?>", "?><xml>");
|
||||
xml += "</xml>";
|
||||
System.out.println("xml: "+xml);
|
||||
return generateLoadScript(xml);
|
||||
} catch (JAXBException ex) {
|
||||
Logger.getLogger(MythosEditor.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -111,7 +117,6 @@ public class MythosEditor {
|
||||
}
|
||||
|
||||
public String generateLoadScript(String xml) {
|
||||
xml = XML_HEADER + xml;
|
||||
xml = xml.replaceAll("'", "\\'");
|
||||
xml = xml.replaceAll("\n", "");
|
||||
String loadScript = "Mythos.setScriptXml('"+xml+"');";
|
||||
@ -119,11 +124,17 @@ public class MythosEditor {
|
||||
}
|
||||
|
||||
private String getDefaultBlockMarkup() {
|
||||
return "<xml><block type=\"procedures_defreturn\" id=\"1\" inline=\"false\" x=\"5\" y=\"5\"><mutation></mutation><field name=\"NAME\">NewScript</field></block></xml>";
|
||||
return XML_HEADER+"<xml><block type=\"procedures_defreturn\" id=\"1\" inline=\"false\" x=\"5\" y=\"5\"><mutation></mutation><field name=\"NAME\">NewScript</field></block></xml>";
|
||||
}
|
||||
|
||||
// Called when the name of the root block is changed in the JS editor
|
||||
public void setFunctionName(String name) {
|
||||
if (script == null) {
|
||||
System.out.println("How can the script be null?? wanted to set script name to "+name);
|
||||
return;
|
||||
}
|
||||
script.setName(name);
|
||||
System.out.println("Function title changed! >> "+name);
|
||||
Application.instance.controller.redrawMapScripts();
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,9 @@ import javafx.scene.layout.VBoxBuilder;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.xml.bind.JAXB;
|
||||
import org.badvision.outlaweditor.data.TilesetUtils;
|
||||
import org.badvision.outlaweditor.data.xml.GameData;
|
||||
import org.badvision.outlaweditor.data.xml.IntervalScript;
|
||||
import org.badvision.outlaweditor.data.xml.Map;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
|
||||
@ -203,12 +201,20 @@ public class UIAction {
|
||||
public static Script createAndEditScript() {
|
||||
Script script = new Script();
|
||||
script.setName("New Script");
|
||||
MythosEditor editor = new MythosEditor(script);
|
||||
editor.show();
|
||||
if (Application.instance.controller.currentMap.getScripts() == null) {
|
||||
Application.instance.controller.currentMap.setScripts(new Map.Scripts());
|
||||
}
|
||||
Application.instance.controller.currentMap.getScripts().getScript().add(script);
|
||||
return script;
|
||||
return editScript(script);
|
||||
}
|
||||
|
||||
public static Script editScript(Script script) {
|
||||
if (script == null) {
|
||||
System.err.println("Requested to edit a null script object, ignoring!");
|
||||
return null;
|
||||
}
|
||||
MythosEditor editor = new MythosEditor(script);
|
||||
editor.show();
|
||||
return script;
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,7 @@
|
||||
<content>
|
||||
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
|
||||
<children>
|
||||
<ListView fx:id="mapScriptsList" onMouseClicked="#onMapScriptClicked" prefHeight="217.0" prefWidth="199.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<ListView fx:id="mapScriptsList" editable="true" prefHeight="217.0" prefWidth="199.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
Loading…
Reference in New Issue
Block a user