diff --git a/src/main/java/com/WooGLEFX/Engine/Main.java b/src/main/java/com/WooGLEFX/Engine/Main.java index 9bdeb2c..ac18133 100644 --- a/src/main/java/com/WooGLEFX/Engine/Main.java +++ b/src/main/java/com/WooGLEFX/Engine/Main.java @@ -12,7 +12,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import java.util.Stack; import javax.imageio.ImageIO; import javax.xml.parsers.ParserConfigurationException; @@ -122,12 +121,45 @@ public class Main extends Application { private static EditorObject strand1Gooball; + private static Canvas canvas; + private static Canvas imageCanvas; + private static WorldLevel level = null; + + private static final ArrayList<_Ball> importedBalls = new ArrayList<>(); + + private static final ArrayList animations = new ArrayList<>();; + + private static SplitPane splitPane; + + private static TreeTableView propertiesView; + + private static Stage stage; + + private static Scene scene; + + private static EditorObject moving; + private static int oldDropIndex; + + private static Pane thingPane; + + private static boolean SHIFT; + private static boolean CTRL; + + private static double mouseStartX; + private static double mouseStartY; + + public static final ArrayList failedResources = new ArrayList<>(); + + private static VBox vBox; + + public static TreeTableView hierarchy; + + private static TabPane levelSelectPane; + public static EditorObject getStrand1Gooball() { return strand1Gooball; } - private static TabPane levelSelectPane; - public static Point2D getScreenCenter() { return new Point2D((thingPane.getWidth() / 2 - level.getOffsetX()) / level.getZoom(), (thingPane.getHeight() / 2 - level.getOffsetY()) / level.getZoom()); @@ -373,24 +405,22 @@ public static void enableAllButtons(boolean disable) { FXCreator.buttonSaveAndPlay.setDisable(false); FXCreator.saveAndPlayLevelItem.setDisable(false); } - if (userActions.size() == 0) { - FXCreator.undoItem.setDisable(true); - FXCreator.buttonUndo.setDisable(true); - } else { + if (level != null && level.undoActions.size() > 0) { FXCreator.undoItem.setDisable(disable); FXCreator.buttonUndo.setDisable(disable); - } - if (redoActions.size() == 0) { - FXCreator.redoItem.setDisable(true); - FXCreator.buttonRedo.setDisable(true); } else { + FXCreator.undoItem.setDisable(true); + FXCreator.buttonUndo.setDisable(true); + } + if (level != null && level.redoActions.size() > 0) { FXCreator.redoItem.setDisable(disable); FXCreator.buttonRedo.setDisable(disable); + } else { + FXCreator.redoItem.setDisable(true); + FXCreator.buttonRedo.setDisable(true); } } - public static final ArrayList failedResources = new ArrayList<>(); - public static void openLevel(String levelName, double version) { // Don't open a level if none selected @@ -759,9 +789,9 @@ public static void exportLevel(boolean includeAddinInfo) { } public static void undo() { - if (userActions.size() != 0) { - UserAction[] changes = userActions.pop(); - redoActions.add(changes); + if (level.undoActions.size() != 0) { + UserAction[] changes = level.undoActions.pop(); + level.redoActions.add(changes); FXCreator.redoItem.setDisable(false); FXCreator.buttonRedo.setDisable(false); for (UserAction change : changes) { @@ -801,24 +831,22 @@ public static void undo() { } } // TODO Undo stack should track if there are any unsaved changes, this isn't always true - if (userActions.size() == 0) { + if (level.undoActions.size() == 0) { level.setEditingStatus(WorldLevel.NO_UNSAVED_CHANGES, true); FXCreator.undoItem.setDisable(true); FXCreator.buttonUndo.setDisable(true); } } - private static final Stack redoActions = new Stack<>(); - public static void clearRedoActions() { - redoActions.clear(); + level.redoActions.clear(); FXCreator.redoItem.setDisable(true); FXCreator.buttonRedo.setDisable(true); } public static void redo() { - if (redoActions.size() != 0) { - UserAction[] changes = redoActions.pop(); + if (level.redoActions.size() != 0) { + UserAction[] changes = level.redoActions.pop(); registerChange(changes); for (UserAction change : changes) { if (change instanceof AttributeChangeAction) { @@ -859,7 +887,7 @@ public static void redo() { hierarchy.refresh(); } } - if (redoActions.size() == 0) { + if (level.redoActions.size() == 0) { FXCreator.redoItem.setDisable(true); FXCreator.buttonRedo.setDisable(true); } @@ -975,7 +1003,7 @@ public static void paste() { setSelected(object); registerChange(new ObjectCreationAction(object, hierarchy.getRow(object.getTreeItem()) - hierarchy.getRow(object.getParent().getTreeItem()) - 1)); - redoActions.clear(); + level.redoActions.clear(); hierarchy.refresh(); } } @@ -1034,7 +1062,7 @@ public static void delete() { EditorObject parent = level.getSelected().getParent(); int row = parent.getChildren().indexOf(level.getSelected()); registerChange(new ObjectDestructionAction(level.getSelected(), row)); - redoActions.clear(); + level.redoActions.clear(); deleteItem(level.getSelected(), false); if (row == 0) { setSelected(parent); @@ -1049,7 +1077,7 @@ public static void delete() { } public static void registerChange(UserAction... actions) { - userActions.add(actions); + level.undoActions.add(actions); if (level.getEditingStatus() == WorldLevel.NO_UNSAVED_CHANGES) { level.setEditingStatus(WorldLevel.UNSAVED_CHANGES, true); } @@ -1168,7 +1196,7 @@ public static void importImage(File resrcFile) { imageResourceObject.getTreeItem()); registerChange(new ImportResourceAction(imageResourceObject, imgPath)); - redoActions.clear(); + level.redoActions.clear(); GlobalResourceManager.addResource(imageResourceObject, level.getVersion()); } catch (IOException e) { @@ -1183,7 +1211,7 @@ public static void newTextResource() { setSelected(newTextObject); registerChange( new ObjectCreationAction(newTextObject, level.getTextObject().getChildren().indexOf(newTextObject))); - redoActions.clear(); + level.redoActions.clear(); } public static void cleanLevelResources() { @@ -1312,7 +1340,7 @@ && new File(FileManager.getNewWOGdir() + "\\res\\music\\" + resrcFile.getName()) music.setAttribute("id", soundResourceName); registerChange(new ImportResourceAction(soundResourceObject, resrcFile.getPath()), new AttributeChangeAction(music, "id", oldID, soundResourceName)); - redoActions.clear(); + level.redoActions.clear(); return; } } @@ -1324,7 +1352,7 @@ && new File(FileManager.getNewWOGdir() + "\\res\\music\\" + resrcFile.getName()) registerChange(new ImportResourceAction(soundResourceObject, resrcFile.getPath()), new ObjectCreationAction(soundResourceObject, whereToPlaceResource), new ObjectCreationAction(musicObject, level.getLevel().size() - 1)); - redoActions.clear(); + level.redoActions.clear(); } @@ -1406,7 +1434,7 @@ && new File(FileManager.getNewWOGdir() + "\\res\\sounds\\" + resrcFile.getName() music.setAttribute("id", soundResourceName); registerChange(new ImportResourceAction(soundResourceObject, resrcFile.getPath()), new AttributeChangeAction(music, "id", oldID, soundResourceName)); - redoActions.clear(); + level.redoActions.clear(); return; } } @@ -1418,7 +1446,7 @@ && new File(FileManager.getNewWOGdir() + "\\res\\sounds\\" + resrcFile.getName() registerChange(new ImportResourceAction(soundResourceObject, resrcFile.getPath()), new ObjectCreationAction(soundResourceObject, whereToPlaceResource), new ObjectCreationAction(musicObject, level.getLevel().size() - 1)); - redoActions.clear(); + level.redoActions.clear(); } @@ -1498,7 +1526,7 @@ public static void addAnything(EditorObject obj, EditorObject parent) { registerChange(new ObjectCreationAction(obj, hierarchy.getRow(obj.getTreeItem()) - hierarchy.getRow(obj.getParent().getTreeItem()))); - redoActions.clear(); + level.redoActions.clear(); } /** @@ -2178,7 +2206,7 @@ public static void eventMouseReleased(MouseEvent event) { UserAction[] changes = level.getSelected().getUserActions(oldAttributes); if (changes.length > 0) { registerChange(changes); - redoActions.clear(); + level.redoActions.clear(); } } @@ -2331,33 +2359,6 @@ public static Stage getStage() { return stage; } - private static Canvas canvas; - private static Canvas imageCanvas; - private static WorldLevel level = null; - - private static final ArrayList<_Ball> importedBalls = new ArrayList<>(); - - private static final ArrayList animations = new ArrayList<>();; - - private static SplitPane splitPane; - - private static TreeTableView propertiesView; - - private static Stage stage; - - private static Scene scene; - - private static EditorObject moving; - private static int oldDropIndex; - - private static Pane thingPane; - - private static boolean SHIFT; - private static boolean CTRL; - - private static double mouseStartX; - private static double mouseStartY; - public static WorldLevel getLevel() { return level; } @@ -2613,12 +2614,6 @@ public static EditorObject generateBlankTextObject() { return EditorObject.create("strings", new EditorAttribute[0], null); } - private static VBox vBox; - - public static TreeTableView hierarchy; - - private final static Stack userActions = new Stack<>(); - private static void importGameResources(double version) { ArrayList allFailedResources = new ArrayList<>(); diff --git a/src/main/java/com/WooGLEFX/Structures/WorldLevel.java b/src/main/java/com/WooGLEFX/Structures/WorldLevel.java index d835350..d919faf 100644 --- a/src/main/java/com/WooGLEFX/Structures/WorldLevel.java +++ b/src/main/java/com/WooGLEFX/Structures/WorldLevel.java @@ -1,9 +1,14 @@ package com.WooGLEFX.Structures; -import com.WooGLEFX.File.FileManager; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Stack; + import com.WooGLEFX.Engine.FXCreator; import com.WooGLEFX.Engine.Main; +import com.WooGLEFX.File.FileManager; import com.WooGLEFX.File.GlobalResourceManager; +import com.WooGLEFX.Structures.UserActions.UserAction; import com.WorldOfGoo.Addin.Addin; import com.WorldOfGoo.Level.Level; import com.WorldOfGoo.Level.Signpost; @@ -11,6 +16,7 @@ import com.WorldOfGoo.Scene.Scene; import com.WorldOfGoo.Text.TextString; import com.WorldOfGoo.Text.TextStrings; + import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.control.Tab; @@ -21,17 +27,104 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; -import java.io.FileNotFoundException; -import java.util.ArrayList; - public class WorldLevel { + public final Stack redoActions = new Stack<>(); + public final Stack undoActions = new Stack<>(); + private final ArrayList scene; private final ArrayList level; private final ArrayList resources; private final ArrayList addin; private final ArrayList text; + private EditorObject levelObject; + private EditorObject sceneObject; + private EditorObject resourcesObject; + private EditorObject addinObject; + private EditorObject textObject; + + private boolean showCameras = false; + private boolean showForcefields = true; + private boolean showGeometry = true; + private boolean showGraphics = true; + private int showGoos = 2; + private boolean showParticles = true; + private boolean showLabels = true; + private boolean showAnimations = true; + private boolean showSceneBGColor = false; + + public static Image showHideAnim0; + public static Image showHideAnim; + public static Image showHideCam0; + public static Image showHideCam1; + public static Image showHideForcefields0; + public static Image showHideForcefields1; + public static Image showHideGeometry0; + public static Image showHideGeometry1; + public static Image showHideGoobs0; + public static Image showHideGoobs1; + public static Image showHideGoobs2; + public static Image showHideImages0; + public static Image showHideImages1; + public static Image showHideLabels0; + public static Image showHideLabels1; + public static Image showHideParticles0; + public static Image showHideParticles1; + public static Image showHideSceneBGColor0; + public static Image showHideSceneBGColor1; + + public static final int NO_UNSAVED_CHANGES = 0; + public static final int UNSAVED_CHANGES = 1; + public static final int UNSAVED_CHANGES_UNMODIFIABLE = 2; + + private static final Image noChangesImageOld; + private static final Image changesImageOld; + private static final Image changesUnmodifiableImageOld; + + private static final Image noChangesImageNew; + private static final Image changesImageNew; + private static final Image changesUnmodifiableImageNew; + + private Image currentStatusImage; + private Tab levelTab; + + private double offsetX = 0; + private double offsetY = 0; + private double zoom = 1; + + static { + try { + showHideAnim0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_anim_disabled.png"); + showHideAnim = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_anim.png"); + showHideCam0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_cam_disabled.png"); + showHideCam1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_cam.png"); + showHideForcefields0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_forcefields_disabled.png"); + showHideForcefields1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_forcefields.png"); + showHideGeometry0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_geometry_disabled.png"); + showHideGeometry1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_geometry.png"); + showHideGoobs0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs_disabled.png"); + showHideGoobs1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs_wireframe.png"); + showHideGoobs2 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs.png"); + showHideImages0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_images_disabled.png"); + showHideImages1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_images.png"); + showHideLabels0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_labels_disabled.png"); + showHideLabels1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_labels.png"); + showHideParticles0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_particles_disabled.png"); + showHideParticles1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_particles.png"); + showHideSceneBGColor0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_scenebgcolor_disabled.png"); + showHideSceneBGColor1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_scenebgcolor.png"); + noChangesImageOld = FileManager.getIcon("ButtonIcons\\Level\\no_unsaved_changes_old.png"); + changesImageOld = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_old.png"); + changesUnmodifiableImageOld = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_unmodifiable_old.png"); + noChangesImageNew = FileManager.getIcon("ButtonIcons\\Level\\no_unsaved_changes_new.png"); + changesImageNew = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_new.png"); + changesUnmodifiableImageNew = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_unmodifiable_new.png"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + public ArrayList getScene() { return scene; } @@ -52,12 +145,6 @@ public ArrayList getText() { return text; } - private EditorObject levelObject; - private EditorObject sceneObject; - private EditorObject resourcesObject; - private EditorObject addinObject; - private EditorObject textObject; - public EditorObject getLevelObject() { return levelObject; } @@ -94,17 +181,6 @@ public double getVersion() { return version; } - private boolean showCameras = false; - private boolean showForcefields = true; - private boolean showGeometry = true; - private boolean showGraphics = true; - private int showGoos = 2; - private boolean showParticles = true; - private boolean showLabels = true; - private boolean showAnimations = true; - private boolean showSceneBGColor = false; - - public boolean isShowCameras() { return showCameras; } @@ -191,81 +267,6 @@ public void setShowSceneBGColor(boolean showSceneBGColor) { FXCreator.buttonShowHideSceneBGColor.setGraphic(new ImageView(showSceneBGColor ? showHideSceneBGColor1 : showHideSceneBGColor0)); } - public static Image showHideAnim0; - public static Image showHideAnim; - public static Image showHideCam0; - public static Image showHideCam1; - public static Image showHideForcefields0; - public static Image showHideForcefields1; - public static Image showHideGeometry0; - public static Image showHideGeometry1; - public static Image showHideGoobs0; - public static Image showHideGoobs1; - public static Image showHideGoobs2; - public static Image showHideImages0; - public static Image showHideImages1; - public static Image showHideLabels0; - public static Image showHideLabels1; - public static Image showHideParticles0; - public static Image showHideParticles1; - public static Image showHideSceneBGColor0; - public static Image showHideSceneBGColor1; - - static { - try { - showHideAnim0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_anim_disabled.png"); - showHideAnim = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_anim.png"); - showHideCam0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_cam_disabled.png"); - showHideCam1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_cam.png"); - showHideForcefields0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_forcefields_disabled.png"); - showHideForcefields1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_forcefields.png"); - showHideGeometry0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_geometry_disabled.png"); - showHideGeometry1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_geometry.png"); - showHideGoobs0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs_disabled.png"); - showHideGoobs1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs_wireframe.png"); - showHideGoobs2 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_goobs.png"); - showHideImages0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_images_disabled.png"); - showHideImages1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_images.png"); - showHideLabels0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_labels_disabled.png"); - showHideLabels1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_labels.png"); - showHideParticles0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_particles_disabled.png"); - showHideParticles1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_particles.png"); - showHideSceneBGColor0 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_scenebgcolor_disabled.png"); - showHideSceneBGColor1 = FileManager.getIcon("ButtonIcons\\ShowHide\\showhide_scenebgcolor.png"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - - public static final int NO_UNSAVED_CHANGES = 0; - public static final int UNSAVED_CHANGES = 1; - public static final int UNSAVED_CHANGES_UNMODIFIABLE = 2; - - private static final Image noChangesImageOld; - private static final Image changesImageOld; - private static final Image changesUnmodifiableImageOld; - - private static final Image noChangesImageNew; - private static final Image changesImageNew; - private static final Image changesUnmodifiableImageNew; - - static { - try { - noChangesImageOld = FileManager.getIcon("ButtonIcons\\Level\\no_unsaved_changes_old.png"); - changesImageOld = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_old.png"); - changesUnmodifiableImageOld = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_unmodifiable_old.png"); - noChangesImageNew = FileManager.getIcon("ButtonIcons\\Level\\no_unsaved_changes_new.png"); - changesImageNew = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_new.png"); - changesUnmodifiableImageNew = FileManager.getIcon("ButtonIcons\\Level\\unsaved_changes_unmodifiable_new.png"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - - private Image currentStatusImage; - - private Tab levelTab; - public Tab getLevelTab() { return levelTab; } @@ -335,10 +336,6 @@ public void setCurrentlySelectedSection(String currentlySelectedSection) { this.currentlySelectedSection = currentlySelectedSection; } - private double offsetX = 0; - private double offsetY = 0; - private double zoom = 1; - public double getOffsetX() { return offsetX; }