Skip to content

Commit

Permalink
Some reorganization of private vars, make undo actions bound to level…
Browse files Browse the repository at this point in the history
… instead of global
  • Loading branch information
meh2481 committed Dec 23, 2023
1 parent c0e7998 commit a0d8ed9
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 167 deletions.
129 changes: 62 additions & 67 deletions src/main/java/com/WooGLEFX/Engine/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WoGAnimation> animations = new ArrayList<>();;

private static SplitPane splitPane;

private static TreeTableView<EditorAttribute> 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<String> failedResources = new ArrayList<>();

private static VBox vBox;

public static TreeTableView<EditorObject> 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());
Expand Down Expand Up @@ -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<String> failedResources = new ArrayList<>();

public static void openLevel(String levelName, double version) {

// Don't open a level if none selected
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<UserAction[]> 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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();

}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();

}

Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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<WoGAnimation> animations = new ArrayList<>();;

private static SplitPane splitPane;

private static TreeTableView<EditorAttribute> 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;
}
Expand Down Expand Up @@ -2613,12 +2614,6 @@ public static EditorObject generateBlankTextObject() {
return EditorObject.create("strings", new EditorAttribute[0], null);
}

private static VBox vBox;

public static TreeTableView<EditorObject> hierarchy;

private final static Stack<UserAction[]> userActions = new Stack<>();

private static void importGameResources(double version) {
ArrayList<String> allFailedResources = new ArrayList<>();

Expand Down
Loading

0 comments on commit a0d8ed9

Please sign in to comment.