FIXED OLE-7

Global scripting is now somewhat available but needs some additional features to be really usable.
This commit is contained in:
Brendan Robert 2015-05-28 01:04:31 -05:00
parent 5ef88e1268
commit 32a3180ebd
14 changed files with 240 additions and 47 deletions

View File

@ -0,0 +1,76 @@
package org.badvision.outlaweditor;
import javafx.scene.layout.Pane;
import org.badvision.outlaweditor.data.xml.Global;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Scripts;
public class GlobalEditor extends Editor<Global, Void>{
@Override
public void addScript(Script script) {
Scripts scripts = Application.gameData.getGlobal().getScripts();
if (scripts == null) {
Application.gameData.getGlobal().setScripts(new Scripts());
scripts = Application.gameData.getGlobal().getScripts();
}
scripts.getScript().add(script);
}
public void removeScript(Script script) {
Scripts scripts = Application.gameData.getGlobal().getScripts();
scripts.getScript().remove(script);
}
@Override
public void setDrawMode(Void drawMode) {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void showShiftUI() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void buildEditorUI(Pane targetPane) {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void unregister() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void copy() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void paste() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void select() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void selectNone() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void redraw() {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void observedObjectChanged(Global object) {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -36,6 +36,7 @@ import org.badvision.outlaweditor.data.TileMap;
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.Scripts;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.ToolType;
import org.badvision.outlaweditor.ui.UIAction;
@ -143,7 +144,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
@Override
public void addScript(Script script) {
if (getCurrentMap().getBackingMap().getScripts() == null) {
getCurrentMap().getBackingMap().setScripts(new Map.Scripts());
getCurrentMap().getBackingMap().setScripts(new Scripts());
}
getCurrentMap().getBackingMap().getScripts().getScript().add(script);
}

View File

@ -0,0 +1,27 @@
package org.badvision.outlaweditor.data;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.data.xml.Global;
import org.badvision.outlaweditor.data.xml.Scripts;
public class DataUtilities {
public static void sortScripts(Scripts s) {
if (s == null || s.getScript() == null) {
return;
}
s.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());
});
}
public static void ensureGlobalExists() {
if (Application.gameData.getGlobal() == null) {
Application.gameData.setGlobal(new Global());
}
}
}

View File

@ -19,6 +19,7 @@ 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.Scripts;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.UIAction;
@ -165,7 +166,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
width = 0;
height = 0;
Set<Tile> unknownTiles = new HashSet<>();
Map.Scripts scripts = m.getScripts();
Scripts scripts = m.getScripts();
if (scripts != null) {
scripts.getScript().forEach(
s -> s.getLocationTrigger().forEach(

View File

@ -31,6 +31,8 @@ public abstract class ApplicationUIController {
protected MapEditorTabController mapController;
@FXML
protected ImageEditorTabController imageController;
@FXML
protected GlobalEditorTabController globalController;
@FXML // URL location of the FXML file that was given to the FXMLLoader
protected URL location;
@ -47,7 +49,7 @@ public abstract class ApplicationUIController {
abstract public void imageTabActivated(Event event);
@FXML
abstract public void scriptTabActivated(Event event);
abstract public void globalTabActivated(Event event);
@FXML // This method is called by the FXMLLoader when initialization is complete
public void initialize() {

View File

@ -1,15 +1,19 @@
package org.badvision.outlaweditor.ui;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import org.badvision.outlaweditor.GlobalEditor;
import org.badvision.outlaweditor.data.xml.Script;
public abstract class GlobalScriptTabController implements Initializable {
public abstract class GlobalEditorTabController {
private final GlobalEditor currentEditor = new GlobalEditor();
public GlobalEditor getCurrentEditor() {
return currentEditor;
}
@FXML
protected ListView<?> globalScriptList;
protected ListView<Script> globalScriptList;
@FXML
protected ListView<?> dataTypeList;
@FXML
@ -34,7 +38,8 @@ public abstract class GlobalScriptTabController implements Initializable {
@FXML
abstract protected void onVariableClonePressed(ActionEvent event);
@Override
public void initialize(URL url, ResourceBundle rb) {
abstract public void redrawGlobalScripts();
public void initialize() {
redrawGlobalScripts();
}
}

View File

@ -52,6 +52,7 @@ import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.FileUtils;
import org.badvision.outlaweditor.MythosEditor;
import org.badvision.outlaweditor.apple.ImageDitherEngine;
import org.badvision.outlaweditor.data.DataUtilities;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.TilesetUtils;
import org.badvision.outlaweditor.data.xml.GameData;
@ -110,6 +111,7 @@ public class UIAction {
ApplicationUIController.getController().clearData();
TilesetUtils.clear();
Application.gameData = newData;
DataUtilities.ensureGlobalExists();
ApplicationUIController.getController().updateSelectors();
break;
case Quit:

View File

@ -26,6 +26,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
tileController.initalize();
mapController.initalize();
imageController.initalize();
globalController.initialize();
}
@Override
@ -65,7 +66,11 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
@Override
public void redrawScripts() {
mapController.redrawMapScripts();
if (currentTab == TABS.map) {
mapController.redrawMapScripts();
} else {
globalController.redrawGlobalScripts();
}
}
@Override
@ -84,7 +89,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
}
public static enum TABS {
image, map, tile, scripting
image, map, tile, global
};
TABS currentTab;
@ -104,8 +109,8 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
}
@Override
public void scriptTabActivated(Event event) {
currentTab = TABS.scripting;
public void globalTabActivated(Event event) {
currentTab = TABS.global;
}
@Override
@ -117,6 +122,8 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
return mapController.getCurrentEditor();
case tile:
return tileController.getCurrentTileEditor();
case global:
return globalController.getCurrentEditor();
default:
return null;
}

View File

@ -1,19 +1,55 @@
package org.badvision.outlaweditor.ui.impl;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import org.badvision.outlaweditor.ui.GlobalScriptTabController;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.util.Callback;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.data.DataUtilities;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.ui.GlobalEditorTabController;
import org.badvision.outlaweditor.ui.UIAction;
import static org.badvision.outlaweditor.ui.UIAction.editScript;
public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
public class GlobalScriptTabControllerImpl extends GlobalScriptTabController {
@Override
protected void onScriptAddPressed(ActionEvent event) {
UIAction.createAndEditScript();
}
@Override
protected void onScriptDeletePressed(ActionEvent event) {
Script script = globalScriptList.getSelectionModel().getSelectedItem();
if (script != null) {
getCurrentEditor().removeScript(script);
redrawGlobalScripts();
}
}
@Override
protected void onScriptClonePressed(ActionEvent event) {
Script source = globalScriptList.getSelectionModel().getSelectedItem();
if (source == null) {
String message = "First select a script and then press Clone";
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
@ -39,4 +75,47 @@ public class GlobalScriptTabControllerImpl extends GlobalScriptTabController {
@Override
protected void onVariableClonePressed(ActionEvent event) {
}
@Override
public void redrawGlobalScripts() {
DataUtilities.ensureGlobalExists();
globalScriptList.setOnEditStart((ListView.EditEvent<Script> event) -> {
UIAction.editScript(event.getSource().getItems().get(event.getIndex()));
});
globalScriptList.setCellFactory(new Callback<ListView<Script>, ListCell<Script>>() {
@Override
public ListCell<Script> call(ListView<Script> param) {
final ListCell<Script> cell = new ListCell<Script>() {
@Override
protected void updateItem(Script item, boolean empty) {
super.updateItem(item, empty);
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());
setFont(Font.font(null, FontWeight.BOLD, 12.0));
// scriptDragDrop.registerDragSupport(this, item);
// visibleIcon.setMouseTransparent(false);
}
}
};
return cell;
}
});
if (globalScriptList.getItems() != null && Application.gameData.getGlobal().getScripts() != null) {
DataUtilities.sortScripts(Application.gameData.getGlobal().getScripts());
globalScriptList.getItems().setAll(Application.gameData.getGlobal().getScripts().getScript());
} else {
globalScriptList.getItems().clear();
}
}
}

View File

@ -22,11 +22,13 @@ import static org.badvision.outlaweditor.Application.currentPlatform;
import static org.badvision.outlaweditor.Application.gameData;
import org.badvision.outlaweditor.MapEditor;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.data.DataUtilities;
import static org.badvision.outlaweditor.data.PropertyHelper.bind;
import static org.badvision.outlaweditor.data.PropertyHelper.stringProp;
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.Scripts;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import org.badvision.outlaweditor.ui.MapEditorTabController;
@ -267,7 +269,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
mapWrapAround.setDisable(true);
setCurrentEditor(null);
} else {
sortScripts(m);
DataUtilities.sortScripts(m.getScripts());
if (m.getHeight() == null) {
m.setHeight(512);
}
@ -412,7 +414,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
mapScriptsList.getItems().clear();
} else {
if (mapScriptsList.getItems() != null && getCurrentMap().getScripts() != null) {
sortScripts(getCurrentMap());
DataUtilities.sortScripts(getCurrentMap().getScripts());
mapScriptsList.getItems().setAll(getCurrentMap().getScripts().getScript());
} else {
mapScriptsList.getItems().clear();
@ -443,18 +445,4 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
visibilityIcon.setImage(VISIBLE_IMAGE);
}
}
private void sortScripts(Map m) {
if (m == null || m.getScripts() == null || m.getScripts().getScript() == null) {
return;
}
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

@ -27,9 +27,9 @@
<fx:include fx:id="image" source="imageEditorTab.fxml" />
</content>
</Tab>
<Tab onSelectionChanged="#scriptTabActivated" text="Scripting">
<Tab onSelectionChanged="#globalTabActivated" text="Scripting">
<content>
<fx:include fx:id="scripting" source="globalScriptEditorTab.fxml" />
<fx:include fx:id="global" source="globalEditorTab.fxml" />
</content>
</Tab>
</tabs>

View File

@ -5,7 +5,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.GlobalScriptTabControllerImpl">
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.GlobalEditorTabControllerImpl">
<children>
<HBox prefHeight="438.0" prefWidth="677.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>

View File

@ -42,10 +42,10 @@
</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: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:complexType>
</xs:element>
</xs:sequence>
@ -61,13 +61,7 @@
<xs:attribute name="y" type="xs:int"/>
</xs:complexType>
</xs:element>
<xs:element name="scripts">
<xs:complexType>
<xs:sequence>
<xs:element name="script" type="tns:script" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="scripts" type="tns:scripts"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="width" type="xs:int"/>
@ -77,6 +71,16 @@
<xs:attribute name="startX" type="xs:int" default="0"/>
<xs:attribute name="startY" type="xs:int" default="0"/>
</xs:complexType>
<xs:complexType name="global">
<xs:sequence>
<xs:element name="scripts" type="tns:scripts"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="scripts">
<xs:sequence>
<xs:element name="script" type="tns:script" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="block">
<xs:sequence>
<xs:element minOccurs="0" name="next" type="tns:next"/>
@ -132,6 +136,7 @@
<xs:element name="gameData">
<xs:complexType>
<xs:sequence>
<xs:element name="global" minOccurs="0" maxOccurs="1" type="tns:global"/>
<xs:element name="image" minOccurs="0" maxOccurs="unbounded" type="tns:image"/>
<xs:element name="tile" minOccurs="0" maxOccurs="unbounded" type="tns:tile"/>
<xs:element name="map" minOccurs="0" maxOccurs="unbounded" type="tns:map"/>

View File

@ -9,7 +9,7 @@ import javax.xml.bind.Marshaller;
import org.badvision.outlaweditor.data.xml.Block;
import org.badvision.outlaweditor.data.xml.GameData;
import org.badvision.outlaweditor.data.xml.Map;
import org.badvision.outlaweditor.data.xml.Map.Scripts;
import org.badvision.outlaweditor.data.xml.Scripts;
import org.badvision.outlaweditor.data.xml.Script;
import org.junit.Test;
import static org.junit.Assert.*;