Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Commit

Permalink
Update 3.1
Browse files Browse the repository at this point in the history
Improve 290.rec editor
  • Loading branch information
Leo40Git committed Dec 16, 2017
1 parent 3072b77 commit 9182a14
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
3.0.1
3.1
Update 3.1:
- Improve 290.rec editor
Hotfix 3.0.1:
- Fix 290.rec editor crashing program when entered number is invalid
Version 3.0 - The Plus Update:
Expand Down
166 changes: 155 additions & 11 deletions src/main/java/com/leo/cse/backend/niku/NikuRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,148 @@
import java.io.IOException;
import java.util.Random;

import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
import javax.swing.undo.UndoableEdit;

import com.leo.cse.backend.ByteUtils;

public class NikuRecord {

private static boolean modified;

public static boolean isModified() {
return modified;
}

private static UndoManager undoMan;

static class NikuEdit implements UndoableEdit {

private int oldValue;
private int newValue;
private boolean hasBeenUndone;

public NikuEdit(int oldValue, int newValue) {
this.oldValue = oldValue;
this.newValue = newValue;
}

@Override
public void undo() throws CannotUndoException {
setValue(oldValue, false);
hasBeenUndone = true;
}

@Override
public boolean canUndo() {
return !hasBeenUndone;
}

@Override
public void redo() throws CannotRedoException {
setValue(newValue, false);
hasBeenUndone = false;
}

@Override
public boolean canRedo() {
return hasBeenUndone;
}

@Override
public void die() {
oldValue = 0;
newValue = 0;
}

@Override
public boolean addEdit(UndoableEdit anEdit) {
return false;
}

@Override
public boolean replaceEdit(UndoableEdit anEdit) {
return false;
}

@Override
public boolean isSignificant() {
return true;
}

@Override
public String getPresentationName() {
return "290.rec time";
}

@Override
public String getUndoPresentationName() {
return "undo " + getPresentationName() + " to " + oldValue;
}

@Override
public String getRedoPresentationName() {
return "redo " + getPresentationName() + " to " + newValue;
}

}

public static boolean canUndo() {
if (undoMan == null)
return false;
return undoMan.canUndo();
}

/**
* Undoes an edit.
*/
public static void undo() {
if (!canUndo())
return;
undoMan.undo();
}

public static boolean canRedo() {
if (undoMan == null)
return false;
return undoMan.canRedo();
}

/**
* Redoes an edit.
*/
public static void redo() {
if (!canRedo())
return;
undoMan.redo();
}

private static int value;
private static File file;

public static File getFile() {
return file;
}

private static boolean loaded;

public static boolean isLoaded() {
return loaded;
}

private static byte unsigned(byte b) {
return (byte) (b & 0xFF);
}

public static void create() {
value = 0;
file = null;
loaded = true;
modified = false;
undoMan = new UndoManager();
}

public static void load(File src) throws IOException {
int[] result = new int[4];
Expand Down Expand Up @@ -45,6 +177,9 @@ public static void load(File src) throws IOException {
throw new IOException("290.rec file is corrupt");
value = result[0];
file = src;
loaded = true;
modified = false;
undoMan = new UndoManager();
}

public static void save(File dest) throws IOException {
Expand Down Expand Up @@ -74,6 +209,15 @@ public static void save(File dest) throws IOException {
fos.write(bufByte);
fos.close();
file = dest;
modified = false;
}

public static void unload() {
file = null;
loaded = false;
value = 0;
modified = false;
undoMan = null;
}

public static int getValue() {
Expand All @@ -85,46 +229,46 @@ public static void setValue(int value, boolean addUndo) {
value = 0;
if (value > 299999)
value = 299999;
if (undoMan != null && addUndo && value != NikuRecord.value) {
modified = true;
undoMan.addEdit(new NikuEdit(NikuRecord.value, value));
}
NikuRecord.value = value;
}

public static void setValue(int value) {
setValue(value, true);
}

public static int getTenths() {
return (value / 5) % 10;
}

public static int getSeconds() {
return (value / 50) % 60;
}

public static int getMinutes() {
return value / 3000;
}

public static void setTime(int tens, int seconds, int minutes) {
int value = tens * 5;
value += seconds * 50;
value += minutes * 3000;
setValue(value);
}

public static void setTenths(int tens) {
setTime(tens, getSeconds(), getMinutes());
}

public static void setSeconds(int seconds) {
setTime(getTenths(), seconds, getMinutes());
}

public static void setMinutes(int minutes) {
setTime(getTenths(), getSeconds(), minutes);
}

public static File getFile() {
return file;
}

}
1 change: 1 addition & 0 deletions src/main/java/com/leo/cse/frontend/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private Config() {
public static final String KEY_LAST_PROFIE = "last_profile";
public static final String KEY_LAST_MCI_FILE = "last_defines";
public static final String KEY_LAST_MOD = "last_mod";
public static final String KEY_LAST_NIKU = "last_niku";
public static final String KEY_HIDE_UNDEFINED_FLAGS = "hide_undefined_flags";
public static final String KEY_HIDE_SYSTEM_FLAGS = "hide_system_flags";
public static final String KEY_SORT_MAPS_ALPHABETICALLY = "sort_maps_alphabetically";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leo/cse/frontend/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Main extends JFrame implements ExeLoadListener, ProfileListener {
private static final long serialVersionUID = -5073541927297432013L;

public static final Dimension WINDOW_SIZE = new Dimension(867, 686);
public static final Version VERSION = new Version("3.0.1");
public static final Version VERSION = new Version("3.1");
public static final String UPDATE_CHECK_SITE = "https://raw.githubusercontent.com/Leo40Git/CaveSaveEdit/master/.version";
public static final String DOWNLOAD_SITE = "https://github.com/Leo40Git/CaveSaveEdit/releases/";
public static final Color COLOR_BG = new Color(0, 0, 25);
Expand Down
84 changes: 43 additions & 41 deletions src/main/java/com/leo/cse/frontend/ui/SaveEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,57 +1016,59 @@ private void mouseMoved(int px, int py) {

@Override
public void keyReleased(KeyEvent e) {
if (!dBoxes.isEmpty())
return;
int code = e.getKeyCode();
int mods = e.getModifiersEx();
boolean shift = (mods & KeyEvent.SHIFT_DOWN_MASK) != 0;
boolean ctrl = (mods & KeyEvent.CTRL_DOWN_MASK) != 0;
if (code == KeyEvent.VK_ESCAPE) {
Main.close();
}
ScrollBar scroll = tabs[currentTab].getPanel().getGlobalScrollbar();
if (scroll != null && (code == KeyEvent.VK_HOME || code == KeyEvent.VK_END)) {
scroll.onKey(code, shift, ctrl);
repaint();
} else if (lastFocus == null) {
switch (code) {
case KeyEvent.VK_O:
if (ctrl) {
if (shift)
loadExe();
else
loadProfile();
}
break;
case KeyEvent.VK_S:
if (ctrl) {
if (shift)
saveProfileAs();
else {
saveProfile();
Main.setTitle(Main.window);
if (!dBoxes.isEmpty()) {
dBoxes.get(0).onKey(code, shift, ctrl);
} else {
ScrollBar scroll = tabs[currentTab].getPanel().getGlobalScrollbar();
if (scroll != null && (code == KeyEvent.VK_HOME || code == KeyEvent.VK_END)) {
scroll.onKey(code, shift, ctrl);
repaint();
} else if (lastFocus == null) {
switch (code) {
case KeyEvent.VK_O:
if (ctrl) {
if (shift)
loadExe();
else
loadProfile();
}
}
break;
case KeyEvent.VK_Z:
if (ctrl) {
if (shift)
break;
case KeyEvent.VK_S:
if (ctrl) {
if (shift)
saveProfileAs();
else {
saveProfile();
Main.setTitle(Main.window);
}
}
break;
case KeyEvent.VK_Z:
if (ctrl) {
if (shift)
ProfileManager.redo();
else
ProfileManager.undo();
}
break;
case KeyEvent.VK_Y:
if (ctrl) {
ProfileManager.redo();
else
ProfileManager.undo();
}
break;
case KeyEvent.VK_Y:
if (ctrl) {
ProfileManager.redo();
}
break;
default:
break;
}
break;
default:
break;
}
} else
lastFocus.onKey(code, shift, ctrl);
} else
lastFocus.onKey(code, shift, ctrl);
}
repaint();
}

Expand Down
Loading

0 comments on commit 9182a14

Please sign in to comment.