Skip to content

Commit

Permalink
Added new option so settings: You can now select what language the ui…
Browse files Browse the repository at this point in the history
… should be in. The translations have not been started yet. Reference to FR #25
  • Loading branch information
LMH01 committed Mar 20, 2021
1 parent b3f5c51 commit 8f0f577
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public class MadGamesTycoon2ModTool {
private static final Logger LOGGER = LoggerFactory.getLogger(MadGamesTycoon2ModTool.class);
public static final String VERSION = "1.8.3b";
public static void main(String[] args) throws IOException {
ToolTipManager.sharedInstance().setDismissDelay(30000);
ToolTipManager.sharedInstance().setInitialDelay(500);
UpdateChecker.checkForUpdates(false);
Locale locale = new Locale("en","US");//Sets the language to english
JOptionPane.setDefaultLocale(locale);
WindowMain.createFrame();
if(Settings.importSettings()){
LOGGER.info("Settings have been imported.");
if(!DataStreamHelper.doesFolderContainFile(Settings.mgt2FilePath, "Mad Games Tycoon 2.exe")){
Expand All @@ -31,6 +25,12 @@ public static void main(String[] args) throws IOException {
Settings.madGamesTycoonFolderIsCorrect = true;
//If settings do not exist they will automatically be reset inside ImportSettings.import()
}
ToolTipManager.sharedInstance().setDismissDelay(30000);
ToolTipManager.sharedInstance().setInitialDelay(500);
UpdateChecker.checkForUpdates(false);
Locale locale = new Locale("en","US");//Sets the language to english
JOptionPane.setDefaultLocale(locale);
WindowMain.createFrame();
Backup.createInitialBackup();//Creates a initial backup when it does not already exist.
AnalyzeExistingGenres.analyzeGenreFile();
WindowMain.checkActionAvailability();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static void export() {
Settings.steamLibraryFolder + "\n" +
Settings.enableCustomFolder + "\n" +
Settings.enableGenreNameTranslationInfo + "\n" +
Settings.enableGenreDescriptionTranslationInfo);
Settings.enableGenreDescriptionTranslationInfo + "\n" +
Settings.language);
pw.close();
if(Settings.enableDebugLogging){
LOGGER.info(Settings.mgt2FilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static boolean Import(String fileLocation) {
}else if(currentLine.equals("false")){
Settings.enableGenreDescriptionTranslationInfo = false;
} break;
case 9:
Settings.language = currentLine;
}
if(Settings.enableDebugLogging){
LOGGER.info("Imported Setting (" + setting + "): " + currentLine);
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/com/github/lmh01/mgt2mt/util/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public class Settings {
public static boolean enableDisclaimerMessage = true;
public static boolean enableGenreNameTranslationInfo = true;
public static boolean enableGenreDescriptionTranslationInfo = true;
public static String language = "English";
public static void resetSettings(){
setMgt2Folder(false);
setSettings(false, false, false, false, "", true, true, true);
setSettings(false, false, false, false, "", true, true, true, "English");
LOGGER.info("Settings have been reset.");
}

Expand All @@ -36,13 +37,14 @@ public static void resetSettings(){
* @param customFolderPath The custom folder path
* @param enableCustomFolder True when the custom folder is enabled.
*/
public static void setSettings(boolean showSuccessDialog, boolean enableDebugLogging, boolean disableSafetyFeatures, boolean enableCustomFolder, String customFolderPath, boolean showDisclaimerMessage, boolean enableGenreNameTranslationInfo, boolean enableGenreDescriptionTranslationInfo){
public static void setSettings(boolean showSuccessDialog, boolean enableDebugLogging, boolean disableSafetyFeatures, boolean enableCustomFolder, String customFolderPath, boolean showDisclaimerMessage, boolean enableGenreNameTranslationInfo, boolean enableGenreDescriptionTranslationInfo, String language){
Settings.enableDebugLogging = enableDebugLogging;
Settings.disableSafetyFeatures = disableSafetyFeatures;
Settings.enableCustomFolder = enableCustomFolder;
Settings.enableDisclaimerMessage = showDisclaimerMessage;
Settings.enableGenreNameTranslationInfo = enableGenreNameTranslationInfo;
Settings.enableGenreDescriptionTranslationInfo = enableGenreDescriptionTranslationInfo;
setLanguage(language);
if(!customFolderPath.isEmpty()){
Settings.mgt2FilePath = customFolderPath;
}
Expand All @@ -57,7 +59,22 @@ public static void setSettings(boolean showSuccessDialog, boolean enableDebugLog
* @return Returns true if settings have been imported successfully.
*/
public static boolean importSettings(){
return ImportSettings.Import(MGT2_MOD_MANAGER_PATH + "//settings.txt");
boolean importSuccessful = ImportSettings.Import(MGT2_MOD_MANAGER_PATH + "//settings.txt");
setLanguage(Settings.language);
return importSuccessful;
}

/**
* Sets the application language
* @param language The language that should be set
*/
public static void setLanguage(String language){
if(language.equals("English")){
I18n.INSTANCE.setCurrentLocale("en");
}else if(language.equals("Deutsch")){
I18n.INSTANCE.setCurrentLocale("de");
}
Settings.language = language;
}

/**
Expand Down
74 changes: 47 additions & 27 deletions src/main/java/com/github/lmh01/mgt2mt/windows/WindowSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class WindowSettings extends JFrame {
private static boolean unsavedChanges = false;
private static String customFolderPath = "";
JComboBox comboBoxMGT2FolderOperation = new JComboBox();
JComboBox comboBoxLanguage = new JComboBox();
JCheckBox checkBoxDisableSafety = new JCheckBox("Disable safety features");
JCheckBox checkBoxDebugMode = new JCheckBox("Enable debug logging");

Expand All @@ -36,7 +37,7 @@ public static void createFrame(){

public WindowSettings(){
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setBounds(100, 100, 343, 200);
this.setBounds(100, 100, 343, 250);

JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
Expand Down Expand Up @@ -67,13 +68,29 @@ public WindowSettings(){
});
contentPane.add(checkBoxDisableSafety);

JLabel labelLanguage = new JLabel("Language:");
labelLanguage.setBounds(20, 128, 127, 14);
contentPane.add(labelLanguage);

comboBoxLanguage.setBounds(117, 125, 100, 23);
comboBoxLanguage.setToolTipText("<html>Select what language the ui should use<br>German translations are currently work in progress.<br>You might encounter things that have not been translated yet.");
comboBoxLanguage.addActionListener(actionEvent -> {
if(!Objects.equals(comboBoxLanguage.getSelectedItem().toString(), Settings.language)){
JOptionPane.showMessageDialog(null, "To apply the language please save the settings and restart the program.");
unsavedChanges = true;
}else{
unsavedChanges = false;
}
});
contentPane.add(comboBoxLanguage);

JLabel lblMinecraftLocation = new JLabel("MGT2 Folder:");
lblMinecraftLocation.setBounds(20, 103, 127, 14);
lblMinecraftLocation.setBounds(20, 153, 127, 14);
contentPane.add(lblMinecraftLocation);

AtomicBoolean automaticWasLastSelectedOption = new AtomicBoolean(!Settings.enableCustomFolder);
AtomicBoolean manualWasLastSelectedOption = new AtomicBoolean(Settings.enableCustomFolder);
comboBoxMGT2FolderOperation.setBounds(117, 100, 100, 23);
comboBoxMGT2FolderOperation.setBounds(117, 150, 100, 23);
comboBoxMGT2FolderOperation.setToolTipText("<html>[Automatic]: The folder will be selected automatically<br>[Manual]: Use a custom path.");
comboBoxMGT2FolderOperation.addActionListener(e -> {
LOGGER.info("comboBoxMGT2FolderOperation action: " + e.getActionCommand());
Expand Down Expand Up @@ -124,7 +141,7 @@ public WindowSettings(){
contentPane.add(comboBoxMGT2FolderOperation);

JButton buttonResetCustomFolder = new JButton("Reset");
buttonResetCustomFolder.setBounds(230, 99, 89, 23);
buttonResetCustomFolder.setBounds(230, 150, 89, 23);
buttonResetCustomFolder.setToolTipText("<html>Click to reset the custom folder.<br>This will restore the default folder.");
buttonResetCustomFolder.addActionListener(actionEvent -> {
customFolderSetAndValid = false;
Expand All @@ -133,13 +150,13 @@ public WindowSettings(){
contentPane.add(buttonResetCustomFolder);

JButton btnBack = new JButton("Back");
btnBack.setBounds(10, 132, 69, 23);
btnBack.setBounds(10, 182, 69, 23);
btnBack.setToolTipText("Click to get to the main page.");
btnBack.addActionListener(actionEvent -> {
if(unsavedChanges){
String unsavedChanges = getChangesInSettings(checkBoxDebugMode, checkBoxDisableSafety);
String unsavedChanges = getChangesInSettings(checkBoxDebugMode, checkBoxDisableSafety, comboBoxLanguage);
if(JOptionPane.showConfirmDialog(null, "You have made changes that have not been saved:\n\n" + unsavedChanges + "\nDo you want to save them?", "Unsaved changes", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION){
setCurrentSettings(checkBoxDebugMode, checkBoxDisableSafety);WindowSettings.FRAME.dispose();
setCurrentSettings(checkBoxDebugMode, checkBoxDisableSafety, comboBoxLanguage);WindowSettings.FRAME.dispose();
Backup.createInitialBackup();
}
}
Expand All @@ -150,7 +167,7 @@ public WindowSettings(){
contentPane.add(btnBack);

JButton btnResetSettings = new JButton("Reset Settings");
btnResetSettings.setBounds(90, 132, 127, 23);
btnResetSettings.setBounds(90, 182, 127, 23);
btnResetSettings.setToolTipText("Click to reset the settings to default values.");
btnResetSettings.addActionListener(actionEvent -> {
if (JOptionPane.showConfirmDialog(null, "Are you sure?", "Reset Settings", JOptionPane.YES_NO_OPTION) == 0) {
Expand All @@ -167,20 +184,15 @@ public WindowSettings(){
contentPane.add(btnResetSettings);

JButton btnSave = new JButton("Save");
btnSave.setBounds(230, 132, 89, 23);
btnSave.setBounds(230, 182, 89, 23);
btnSave.setToolTipText("Click to save the current settings.");
btnSave.addActionListener(actionEvent -> {
unsavedChanges = false;
if(checkBoxDisableSafety.isSelected()){
String unsavedChanges = getChangesInSettings(checkBoxDebugMode, checkBoxDisableSafety);
if(JOptionPane.showConfirmDialog(null, "Save the following settings?\n\n" + unsavedChanges, "Unsaved changes", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION){
setCurrentSettings(checkBoxDebugMode, checkBoxDisableSafety);
WindowMain.checkActionAvailability();
Backup.createInitialBackup();
}
}else{
setCurrentSettings(checkBoxDebugMode, checkBoxDisableSafety);
String unsavedChangesList = getChangesInSettings(checkBoxDebugMode, checkBoxDisableSafety, comboBoxLanguage);
if(JOptionPane.showConfirmDialog(null, "Save the following settings?\n\n" + unsavedChangesList, "Unsaved changes", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION){
setCurrentSettings(checkBoxDebugMode, checkBoxDisableSafety, comboBoxLanguage);
WindowMain.checkActionAvailability();
Backup.createInitialBackup();
unsavedChanges = false;
}
});
contentPane.add(btnSave);
Expand All @@ -192,6 +204,11 @@ private void loadCurrentSelections(){
}else{
comboBoxMGT2FolderOperation.setModel(new DefaultComboBoxModel<>(new String[]{"Automatic", "Manual"}));
}
if(Settings.language.equals("English")){
comboBoxLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"English", "Deutsch"}));
}else if(Settings.language.equals("Deutsch")){
comboBoxLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"Deutsch", "English"}));
}
checkBoxDebugMode.setSelected(Settings.enableDebugLogging);
checkBoxDisableSafety.setSelected(Settings.disableSafetyFeatures);
}
Expand All @@ -201,26 +218,29 @@ private void loadCurrentSelections(){
* @param checkBoxDebugMode The debug mode checkbox
* @param checkBoxDisableSafety The disable safety features checkbox
*/
private static void setCurrentSettings(JCheckBox checkBoxDebugMode,JCheckBox checkBoxDisableSafety){
Settings.setSettings(true, checkBoxDebugMode.isSelected(),checkBoxDisableSafety.isSelected(), customFolderSetAndValid, customFolderPath, Settings.enableDisclaimerMessage, Settings.enableGenreNameTranslationInfo, Settings.enableGenreDescriptionTranslationInfo);
private static void setCurrentSettings(JCheckBox checkBoxDebugMode,JCheckBox checkBoxDisableSafety, JComboBox comboBoxLanguage){
Settings.setSettings(true, checkBoxDebugMode.isSelected(),checkBoxDisableSafety.isSelected(), customFolderSetAndValid, customFolderPath, Settings.enableDisclaimerMessage, Settings.enableGenreNameTranslationInfo, Settings.enableGenreDescriptionTranslationInfo, comboBoxLanguage.getSelectedItem().toString());
}

/**
* @param checkBoxDebugMode The debug mode checkbox
* @param checkBoxDisableSafety The disable safety features checkbox
* @return Returns the changes that have been made to the settings
*/
private static String getChangesInSettings(JCheckBox checkBoxDebugMode,JCheckBox checkBoxDisableSafety){
String unsavedChanges = "";
private static String getChangesInSettings(JCheckBox checkBoxDebugMode,JCheckBox checkBoxDisableSafety, JComboBox comboBoxLanguage){
StringBuilder unsavedChanges = new StringBuilder();
if(Settings.enableDebugLogging != checkBoxDebugMode.isSelected()){
unsavedChanges = unsavedChanges + "Enable debug logging: " + Settings.enableDebugLogging + " -> " + checkBoxDebugMode.isSelected() + "\n";
unsavedChanges.append("Enable debug logging: ").append(Settings.enableDebugLogging).append(" -> ").append(checkBoxDebugMode.isSelected()).append(System.getProperty("line.separator"));
}
if(Settings.disableSafetyFeatures != checkBoxDisableSafety.isSelected()){
unsavedChanges = unsavedChanges + "Disable safety features: " + Settings.disableSafetyFeatures + " -> " + checkBoxDisableSafety.isSelected() + "\n";
unsavedChanges.append("Disable safety features: ").append(Settings.disableSafetyFeatures).append(" -> ").append(checkBoxDisableSafety.isSelected()).append(System.getProperty("line.separator"));
}
if(!Settings.mgt2FilePath.equals(customFolderPath) && !customFolderPath.isEmpty() && !Settings.mgt2FilePath.isEmpty()){
unsavedChanges = unsavedChanges + "Mad Games Tycoon folder: " + Settings.mgt2FilePath + " -> " + customFolderPath + "\n";
unsavedChanges.append("Mad Games Tycoon folder: ").append(Settings.mgt2FilePath).append(" -> ").append(customFolderPath).append(System.getProperty("line.separator"));
}
if(!Settings.language.equals(comboBoxLanguage.getSelectedItem().toString())){
unsavedChanges.append("Language: ").append(Settings.language).append(" -> ").append(comboBoxLanguage.getSelectedItem().toString()).append(System.getProperty("line.separator"));
}
return unsavedChanges;
return unsavedChanges.toString();
}
}

0 comments on commit 8f0f577

Please sign in to comment.