Skip to content

Commit

Permalink
Add Skip Intro option
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoester committed Aug 29, 2024
1 parent 84be35f commit 037f3b1
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 9 deletions.
50 changes: 50 additions & 0 deletions bfme-resfix/src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -175,10 +178,53 @@ private boolean applyChanges(List<Game> games) {
listener.resume();
changes = true;
}

// DVD
Intro selectedIntro = mainView.getGameView(game.getId()).getIntroSelectedItem();
if (selectedIntro != null && !selectedIntro.equals(game.getIntro())) {
listener.pause();
handleIntroSelection(game, selectedIntro);
listener.resume();
changes = true;
}
}
return changes;
}

private void handleIntroSelection(Game game, Intro selectedIntro) {
logger.info("handleIntroSelection(): {}: {} > {}", game.getId(), game.getIntro().isOriginal(), selectedIntro.isOriginal());

Path root = Paths.get(game.getInstallationPath() + "/data/movies/");
List<Path> fileList = new ArrayList<>();
fileList.add(Paths.get(root + "/NewLineLogo.vp6"));
fileList.add(Paths.get(root + "/EALogo.vp6")); // ALL
if (game.getId().equals(BFME1)) {
fileList.add(Paths.get(root + "/intel.vp6"));
fileList.add(Paths.get(root + "/THX.vp6"));
} else if (game.getId().equals(BFME2) || game.getId().equals(ROTWK)) {
fileList.add(Paths.get(root + "/NLC_LOGO.vp6"));
fileList.add(Paths.get(root + "/TE_LOGO.vp6"));
}

// A: Restore Original from Backup
if (selectedIntro.isOriginal()) {
logger.info("handleIntroSelection(): Restore Original from Backup");
for (Path file : fileList) {
Path backupFile = Paths.get(file + ".bak");
boolean result = BigManager.copyBigFileFromTo(backupFile, file, labels); // Restore from Backup
if (result) BigManager.removeBigFile(backupFile, labels); // Delete previous Backup
}

// B: Create Backup, then remove
} else {
for (Path file : fileList) {
Path backupFile = Paths.get(file + ".bak");
boolean result = BigManager.copyBigFileFromTo(file, backupFile, labels); // Restore from Backup
if (result) BigManager.removeBigFile(file, labels); // Delete previous Backup
}
}
}

private void handleDVDSelection(Game game, DVD selectedDVD) {
logger.info("handleDVDSelection(): {}: {} > {}", game.getId(), game.getDvd().isOriginal(), selectedDVD.isOriginal());
DVD dvd = game.getDvd();
Expand Down Expand Up @@ -354,6 +400,10 @@ public void updateDVDBox(GameID gameID) {
SwingUtilities.invokeLater(() -> mainView.renderDVDBox(getGame(gameID)));
}

public void updateIntroBox(GameID gameID) {
SwingUtilities.invokeLater(() -> mainView.renderIntroBox(getGame(gameID)));
}

public void updateAllResBoxes() {
SwingUtilities.invokeLater(() -> {
mainView.renderResBox(getGame(BFME1), display);
Expand Down
27 changes: 22 additions & 5 deletions bfme-resfix/src/main/java/listener/ChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,23 @@ private void pollSingleGame(Game game, Map<String, Boolean> runningStatus) {
dvd.setOriginal(retrieveGameDatVersion(dvd.getHash()));
game.setDvd(dvd);

Intro intro = new Intro();
intro.setFilePath(Paths.get(currentInstallPath + "/data/movies/NewLineLogo.vp6"));
intro.setBackupPath(Paths.get(currentInstallPath + "/data/movies/NewLineLogo.vp6.bak"));
intro.setOriginal(Files.exists(intro.getFilePath()));
game.setIntro(intro);

if (previousInstallPath != null) {
unregisterListener(previousInstallPath);
unregisterListener(previousUserDataPath);
unregisterListener(Paths.get(previousInstallPath + "/data/movies"));
System.out.println("NEW " + game.getId() + ": Registered: " + monitoredPaths);
}
if (currentInstallPath != null) {
registerListener(currentInstallPath, game.getId());
registerListener(currentUserDataPath, game.getId());
registerListener(Paths.get(currentInstallPath + "/data/movies"), game.getId());

System.out.println("NEW " + game.getId() + ": Registered: " + monitoredPaths);
}

Expand Down Expand Up @@ -249,7 +258,7 @@ private void handleFileChange(Path filePath, GameID gameId) {
}

// Handle File changes
if (filePath.toString().contains("Options.ini")) {
if (filePath.toString().endsWith("Options.ini")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
game.setInGameResolution(retrieveResolution(filePath));

Expand All @@ -258,7 +267,7 @@ private void handleFileChange(Path filePath, GameID gameId) {
controller.resolutionTooHighFeedback(game);
controller.resolution32_9Feedback(game);

} else if (filePath.toString().contains("Maps.big")) {
} else if (filePath.toString().endsWith("Maps.big")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
Maps maps = game.getMaps();
maps.setHash(retrieveHash(filePath));
Expand All @@ -267,30 +276,38 @@ private void handleFileChange(Path filePath, GameID gameId) {

controller.updateMapsBox(game.getId());

} else if (filePath.toString().contains("Maps_Backup.big")) {
} else if (filePath.toString().endsWith("Maps_Backup.big")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
Maps maps = game.getMaps();
maps.setBackup(Files.exists(filePath));
game.setMaps(maps);

controller.updateMapsBox(game.getId());

} else if (filePath.toString().contains("_unstretched-hud.big")) {
} else if (filePath.toString().endsWith("_unstretched-hud.big")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
HUD hud = game.getHud();
hud.setOriginal(Files.notExists(filePath));
game.setHud(hud);

controller.updateHudBox(game.getId());

} else if (filePath.toString().contains("game.dat")) {
} else if (filePath.toString().endsWith("game.dat")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
DVD dvd = game.getDvd();
dvd.setHash(retrieveHash(filePath));
dvd.setOriginal(retrieveGameDatVersion(dvd.getHash()));
game.setDvd(dvd);

controller.updateDVDBox(game.getId());

} else if (filePath.toString().endsWith("NewLineLogo.vp6")) {
System.out.println("NEW " + gameId + ": Modified: " + filePath);
Intro intro = game.getIntro();
intro.setOriginal(Files.exists(intro.getFilePath()));
game.setIntro(intro);

controller.updateIntroBox(game.getId());
}
}

Expand Down
13 changes: 11 additions & 2 deletions bfme-resfix/src/main/java/model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Game {
private Maps maps;
private HUD hud;
private DVD dvd;
private Intro intro;
private boolean isInstalled;
private boolean isPatched;
private boolean isRunning;
Expand Down Expand Up @@ -125,16 +126,24 @@ public void setDvd(DVD dvd) {
this.dvd = dvd;
}

public Intro getIntro() {
return intro;
}

public void setIntro(Intro intro) {
this.intro = intro;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Game game = (Game) o;
return isInstalled == game.isInstalled && isPatched == game.isPatched && isRunning == game.isRunning && id == game.id && Objects.equals(language, game.language) && Objects.equals(installationPath, game.installationPath) && Objects.equals(userDataPath, game.userDataPath) && Objects.equals(versionInstalled, game.versionInstalled) && Objects.equals(versionAvailablePatch, game.versionAvailablePatch) && Objects.equals(inGameResolution, game.inGameResolution) && Objects.equals(maps, game.maps) && Objects.equals(hud, game.hud) && Objects.equals(dvd, game.dvd);
return isInstalled == game.isInstalled && isPatched == game.isPatched && isRunning == game.isRunning && id == game.id && Objects.equals(language, game.language) && Objects.equals(installationPath, game.installationPath) && Objects.equals(userDataPath, game.userDataPath) && Objects.equals(versionInstalled, game.versionInstalled) && Objects.equals(versionAvailablePatch, game.versionAvailablePatch) && Objects.equals(inGameResolution, game.inGameResolution) && Objects.equals(maps, game.maps) && Objects.equals(hud, game.hud) && Objects.equals(dvd, game.dvd) && Objects.equals(intro, game.intro);
}

@Override
public int hashCode() {
return Objects.hash(id, language, installationPath, userDataPath, versionInstalled, versionAvailablePatch, inGameResolution, maps, hud, dvd, isInstalled, isPatched, isRunning);
return Objects.hash(id, language, installationPath, userDataPath, versionInstalled, versionAvailablePatch, inGameResolution, maps, hud, dvd, intro, isInstalled, isPatched, isRunning);
}
}
71 changes: 71 additions & 0 deletions bfme-resfix/src/main/java/model/Intro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package model;

import java.nio.file.Path;
import java.util.Objects;

public class Intro {
private Path filePath;
private Path backupPath;
private String label;
private boolean original;

public Intro(Path filePath, boolean isOriginal, String label) {
this.filePath = filePath;
this.label = label;
this.original = isOriginal;
}

public Intro() {

}

public Path getFilePath() {
return filePath;
}

public void setFilePath(Path filePath) {
this.filePath = filePath;
}

public Path getBackupPath() {
return backupPath;
}

public void setBackupPath(Path backupPath) {
this.backupPath = backupPath;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public boolean isOriginal() {
return original;
}

public void setOriginal(boolean original) {
this.original = original;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Intro intro = (Intro) o;
return original == intro.original;
}

@Override
public int hashCode() {
return Objects.hashCode(original);
}

@Override
public String toString() {
return label;
}
}
24 changes: 22 additions & 2 deletions bfme-resfix/src/main/java/view/GameView.form
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="view.GameView">
<grid id="27dc6" binding="root" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="root" layout-manager="GridLayoutManager" row-count="13" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="25" y="25" width="284" height="405"/>
<xy x="25" y="25" width="284" height="480"/>
</constraints>
<properties>
<enabled value="true"/>
Expand Down Expand Up @@ -142,6 +142,26 @@
<model/>
</properties>
</component>
<component id="a2dae" class="javax.swing.JLabel">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="f0654"/>
<text resource-bundle="labels" key="title.intro"/>
</properties>
</component>
<component id="e312b" class="javax.swing.JComboBox" binding="comboBoxIntro">
<constraints>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="180" height="45"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
<model/>
</properties>
</component>
</children>
</grid>
</form>
Loading

0 comments on commit 037f3b1

Please sign in to comment.