Skip to content

Commit

Permalink
Add option to load tp2 files in the app itself to start mod installat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Argent77 committed Oct 15, 2023
1 parent a7dee01 commit db34d57
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 21 deletions.
46 changes: 45 additions & 1 deletion src/main/java/io/infinitytools/wml/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -1012,8 +1013,12 @@ private void onShowFindDialog() {
*/
private void setWeiduRunning() {
updateWindowTitle(true);

getController().quitButton.setText(R.get("ui.main.terminate.button"));

getController().loadModButton.setDisable(true);
getController().inputButtons.forEach(button -> button.setDisable(false));

if (getTray() != null && getTray().isAvailable()) {
getTray().getQuitItem().setLabel(getTray().getQuitLabel());
// tray icon: update label and icon color
Expand All @@ -1039,6 +1044,7 @@ private void setWeiduTerminated() {
getTray().getTrayIcon().setImage(Tray.getIcon(isDarkModeEnabled(), false));
}

getController().loadModButton.setDisable(false);
getController().inputButtons.forEach(button -> button.setDisable(true));

// Triggering tray notification if main window is not active
Expand Down Expand Up @@ -1159,7 +1165,12 @@ private void applyDarkModeUi(boolean enable) {
// updating window skins
CustomScene.updateSceneCache();

// updating Options menu icon
// updating UI icons
if (getController().loadModButton.getGraphic() instanceof ImageView iv) {
final Icons icon = enable ? Icons.OpenModDark32 : Icons.OpenMod32;
iv.setImage(icon.getImage());
}

if (getController().optionsButton.getGraphic() instanceof ImageView iv) {
final Icons icon = enable ? Icons.OptionsDark32 : Icons.Options32;
iv.setImage(icon.getImage());
Expand Down Expand Up @@ -1316,6 +1327,7 @@ private void setupUI(Scene scene) {
getController().quitButton.setOnAction(event -> onQuitClicked());
getController().detailsButton.selectedProperty().addListener((ob, ov, nv) -> onDetailsButtonSelected(nv));
getController().detailsButton.setOnAction(event -> setInputFocus());
getController().loadModButton.setOnAction(event -> openModFile());
getController().aboutButton.setOnAction(event -> showAboutDialog());
getController().sendButton.setOnAction(event -> sendInput(getController().inputField.getText(), true));

Expand Down Expand Up @@ -2198,6 +2210,38 @@ private void showAboutDialog() {
}
}

/**
* Let's the user choose a tp2 file for a new mod installation process.
*/
private void openModFile() {
if (isProcessRunning()) {
Logger.debug("Process is still running.");
return;
}

Path initialPath = null;
String lastPath = Configuration.getInstance().getOption(Configuration.Key.LAST_MOD_PATH);
if (lastPath != null) {
try {
initialPath = Path.of(lastPath);
} catch (InvalidPathException e) {
Logger.debug("Invalid path: {}", lastPath);
}
}

Path tp2File = Utils.chooseOpenFile(getStage(), R.get("ui.configuration.fileDialog.tp2.title"), initialPath,
new FileChooser.ExtensionFilter(R.get("ui.configuration.fileDialog.tp2.filter.tp2"), "*.tp2"),
new FileChooser.ExtensionFilter(R.get("ui.fileDialog.filter.allFiles"), "*.*"));
if (tp2File != null) {
try {
restart(tp2File.toString());
} catch (Exception e) {
Logger.warn(e, "Open mod file: {}", tp2File);
Utils.showErrorDialog(getStage(), R.ERROR(), R.get("ui.main.loadMod.message.loadError.header"), null);
}
}
}

/**
* Terminates a running process.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class MainWindowController implements Initializable {
public TextField inputField;
public Button sendButton;
public Button aboutButton;
public Button loadModButton;
public Button inputDigit0Button;
public Button inputDigit1Button;
public Button inputDigit2Button;
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/io/infinitytools/wml/icons/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,49 @@ public enum Icons {
*/
Logo(Logo256.getFileName(), Logo128.getFileName(), Logo64.getFileName(), Logo32.getFileName(), Logo16.getFileName()),

/**
* Icon for "Open Mod: button
*/
OpenMod256("icon-tp2/256x256.png"),
/**
* Icon for "Open Mod: button
*/
OpenMod128("icon-tp2/128x128.png"),
/**
* Icon for "Open Mod: button
*/
OpenMod64("icon-tp2/64x64.png"),
/**
* Icon for "Open Mod: button
*/
OpenMod32("icon-tp2/32x32.png"),
/**
* Collection of "Open Mod" button icons in all available dimensions.
*/
OpenMod(OpenMod256.getFileName(), OpenMod128.getFileName(), OpenMod64.getFileName(), OpenMod32.getFileName()),

/**
* Icon for "Open Mod: button (Dark Mode UI version)
*/
OpenModDark256("icon-tp2-dark/256x256.png"),
/**
* Icon for "Open Mod: button (Dark Mode UI version)
*/
OpenModDark128("icon-tp2-dark/128x128.png"),
/**
* Icon for "Open Mod: button (Dark Mode UI version)
*/
OpenModDark64("icon-tp2-dark/64x64.png"),
/**
* Icon for "Open Mod: button (Dark Mode UI version)
*/
OpenModDark32("icon-tp2-dark/32x32.png"),
/**
* Collection of "Open Mod" button icons in all available dimensions (Dark Mode UI version).
*/
OpenModDark(OpenModDark256.getFileName(), OpenModDark128.getFileName(), OpenModDark64.getFileName(),
OpenModDark32.getFileName()),

/**
* Icon for Options menu
*/
Expand Down
36 changes: 16 additions & 20 deletions src/main/resources/io/infinitytools/wml/gui/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,13 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckMenuItem?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.CustomMenuItem?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.layout.*?>
<GridPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="io.infinitytools.wml.gui.MainWindowController"
Expand Down Expand Up @@ -72,6 +55,19 @@
<Tooltip text="%ui.main.about.tooltip"/>
</tooltip>
</Button>
<Button fx:id="loadModButton"
text="%ui.main.loadMod.button">
<graphic>
<ImageView fitWidth="16"
fitHeight="16"
preserveRatio="true">
<Image url="@../icons/icon-tp2/32x32.png"/>
</ImageView>
</graphic>
<tooltip>
<Tooltip text="%ui.main.loadMod.tooltip"/>
</tooltip>
</Button>
<MenuButton fx:id="optionsButton"
text="%ui.main.menu"
HBox.hgrow="ALWAYS">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/l10n/wml.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
ui.main.output.label = Output:
ui.main.about.button = \u00a0?\u00a0
ui.main.about.tooltip = About Weidu Mod Launcher...
ui.main.loadMod.button = Load Mod...
ui.main.loadMod.tooltip = Choose a tp2 file to start a new mod installation.
ui.main.menu = Options
ui.main.menu.tooltip = Click to pop up a menu with available options.
ui.main.menu.item.autoQuit = Quit on Enter
Expand Down Expand Up @@ -251,6 +253,8 @@ ui.main.dragdrop.message.openFile.tooMany.content = Too many files (allowed: 1,
ui.main.dragdrop.message.openFile.loadError.content = Could not load tp2 file:
ui.main.dragdrop.message.openFile.error.unspecified = Unspecified error

ui.main.loadMod.message.loadError.header = The specified tp2 file could not be loaded.

ui.main.tray.message.quitHint.caption = Launcher is hidden
ui.main.tray.message.quitHint.text = Right-click on the tray icon and select "Quit" to quit the application.
ui.main.tray.message.terminatedHint.text = WeiDU operation has completed.
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/l10n/wml_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
ui.main.output.label = Ausgabe:
ui.main.about.button = \u00a0?\u00a0
ui.main.about.tooltip = Über Weidu Mod Launcher ...
ui.main.loadMod.button = Mod laden ...
ui.main.loadMod.tooltip = Startet eine neue Modinstallation mit einer ausgewählten Tp2-Datei.
ui.main.menu = Optionen
ui.main.menu.tooltip = Öffnet ein Menü mit allen verfügbaren Optionen.
ui.main.menu.item.autoQuit = Enter drücken zum Beenden
Expand Down Expand Up @@ -216,6 +218,7 @@ ui.checkWeidu.downloadProgress.message = WeiDU-Programmdatei wird heruntergelade

ui.main.message.process.header = WeiDU-Fehler
ui.main.message.process.content = WeiDU konnte nicht ausgeführt werden:

ui.main.modInfo.fileDialog.title = Spielauswahl: Key-Datei auswählen
ui.main.modInfo.fileDialog.filter.key = Key-Dateien
ui.main.modInfo.message.gameNotFound.header = Spielverzeichnis wurde nicht gefunden.
Expand Down Expand Up @@ -250,6 +253,8 @@ ui.main.dragdrop.message.openFile.tooMany.content = Zu viele Dateien (erlaubt: 1
ui.main.dragdrop.message.openFile.loadError.content = Tp2 Mod-Datei konnte nicht geladen werden:
ui.main.dragdrop.message.openFile.error.unspecified = Allgemeiner Fehler

ui.main.loadMod.message.loadError.header = Die ausgewählte Tp2-Datei konnte nicht geladen werden.

ui.main.tray.message.quitHint.caption = Launcher wurde versteckt
ui.main.tray.message.quitHint.text = Rechtsklick auf das Taskleistensymbol und "Beenden" auswählen, um die Anwendung zu beenden.
ui.main.tray.message.terminatedHint.text = Die WeiDU-Operation wurde beendet.
Expand Down

0 comments on commit db34d57

Please sign in to comment.