From 36b2b4e50b46dc5681617e49c0fa15c4e62d615b Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 15 Mar 2021 21:37:18 +0100 Subject: [PATCH] Implemented feature #18 : It is now possible to add gameplay features --- .../AnalyzeExistingGameplayFeatures.java | 21 +- .../data_stream/EditGameplayFeaturesFile.java | 100 ++++++- .../mgt2mt/util/GameplayFeatureHelper.java | 275 ++++++++++++++++++ .../lmh01/mgt2mt/util/TranslationManager.java | 39 ++- .../com/github/lmh01/mgt2mt/util/Utils.java | 46 +++ .../lmh01/mgt2mt/windows/WindowMain.java | 51 +++- 6 files changed, 512 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/github/lmh01/mgt2mt/util/GameplayFeatureHelper.java diff --git a/src/main/java/com/github/lmh01/mgt2mt/data_stream/AnalyzeExistingGameplayFeatures.java b/src/main/java/com/github/lmh01/mgt2mt/data_stream/AnalyzeExistingGameplayFeatures.java index c42ff0b3..124a152e 100644 --- a/src/main/java/com/github/lmh01/mgt2mt/data_stream/AnalyzeExistingGameplayFeatures.java +++ b/src/main/java/com/github/lmh01/mgt2mt/data_stream/AnalyzeExistingGameplayFeatures.java @@ -15,7 +15,6 @@ public class AnalyzeExistingGameplayFeatures { private static final Logger LOGGER = LoggerFactory.getLogger(AnalyzeExistingGameplayFeatures.class); public static List> gameplayFeatures; - public static Map gameplayFeatureNames; public static int maxGameplayFeatureId = 0; /** @@ -64,9 +63,9 @@ public static String[] getGameplayFeaturesByAlphabet(){ } /** - * Returns -1 when genre name does not exist. + * Returns -1 when gameplay feature name does not exist. * @param gameplayFeatureName The gameplay feature name - * @return Returns the genre id for the specified name. + * @return Returns the gameplay feature id for the specified name. */ public static int getGameplayFeatureIdByName(String gameplayFeatureName){ int genreId = -1; @@ -82,4 +81,20 @@ public static int getGameplayFeatureIdByName(String gameplayFeatureName){ } return genreId; } + + /** + * @param gameplayFeatureNameEn The gameplay feature for which the map should be returned. + * @return Returns a map containing all values for the specified gameplay feature. + */ + public static Map getSingleGameplayFeatureByNameMap(String gameplayFeatureNameEn){ + List> list = gameplayFeatures; + Map mapSingleGenre = null; + int publisherPosition = getGameplayFeatureIdByName(gameplayFeatureNameEn); + for(int i=0; i map) throws IOException { + AnalyzeExistingGameplayFeatures.analyzeGameplayFeatures(); + LOGGER.info("Adding new gameplay feature..."); + File gameplayFeatureFile = Utils.getGameplayFeaturesFile(); + if(gameplayFeatureFile.exists()){ + gameplayFeatureFile.delete(); + } + gameplayFeatureFile.createNewFile(); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gameplayFeatureFile), StandardCharsets.UTF_8)); + bw.write("\ufeff"); + for(Map existingGameplayFeatures : AnalyzeExistingGameplayFeatures.gameplayFeatures){ + bw.write("[ID]" + existingGameplayFeatures.get("ID"));bw.write(System.getProperty("line.separator")); + bw.write("[TYP]" + existingGameplayFeatures.get("TYP"));bw.write(System.getProperty("line.separator")); + TranslationManager.printLanguages(bw, existingGameplayFeatures); + bw.write("[DATE]" + existingGameplayFeatures.get("DATE"));bw.write(System.getProperty("line.separator")); + bw.write("[RES POINTS]" + existingGameplayFeatures.get("RES POINTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PRICE]" + existingGameplayFeatures.get("PRICE"));bw.write(System.getProperty("line.separator")); + bw.write("[DEV COSTS]" + existingGameplayFeatures.get("DEV COSTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PIC]" + existingGameplayFeatures.get("PIC"));bw.write(System.getProperty("line.separator")); + bw.write("[GAMEPLAY]" + existingGameplayFeatures.get("GAMEPLAY"));bw.write(System.getProperty("line.separator")); + bw.write("[GRAPHIC]" + existingGameplayFeatures.get("GRAPHIC"));bw.write(System.getProperty("line.separator")); + bw.write("[SOUND]" + existingGameplayFeatures.get("SOUND"));bw.write(System.getProperty("line.separator")); + bw.write("[TECH]" + existingGameplayFeatures.get("TECH"));bw.write(System.getProperty("line.separator")); + if(existingGameplayFeatures.get("GOOD") == null){ + existingGameplayFeatures.put("GOOD", ""); + } + if(existingGameplayFeatures.get("BAD") == null){ + existingGameplayFeatures.put("BAD", ""); + } + bw.write("[GOOD]" + existingGameplayFeatures.get("GOOD"));bw.write(System.getProperty("line.separator")); + bw.write("[BAD]" + existingGameplayFeatures.get("BAD"));bw.write(System.getProperty("line.separator")); + bw.write(System.getProperty("line.separator")); + } + bw.write("[ID]" + map.get("ID"));bw.write(System.getProperty("line.separator")); + bw.write("[TYP]" + map.get("TYP"));bw.write(System.getProperty("line.separator")); + TranslationManager.printLanguages(bw, map); + bw.write("[DATE]" + map.get("DATE"));bw.write(System.getProperty("line.separator")); + bw.write("[RES POINTS]" + map.get("RES POINTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PRICE]" + map.get("PRICE"));bw.write(System.getProperty("line.separator")); + bw.write("[DEV COSTS]" + map.get("DEV COSTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PIC]" + map.get("PIC"));bw.write(System.getProperty("line.separator")); + bw.write("[GAMEPLAY]" + map.get("GAMEPLAY"));bw.write(System.getProperty("line.separator")); + bw.write("[GRAPHIC]" + map.get("GRAPHIC"));bw.write(System.getProperty("line.separator")); + bw.write("[SOUND]" + map.get("SOUND"));bw.write(System.getProperty("line.separator")); + bw.write("[TECH]" + map.get("TECH"));bw.write(System.getProperty("line.separator")); + bw.write("[GOOD]" + map.get("GOOD"));bw.write(System.getProperty("line.separator")); + bw.write("[BAD]" + map.get("BAD"));bw.write(System.getProperty("line.separator")); + bw.write(System.getProperty("line.separator")); + bw.write("[EOF]"); + bw.close(); + } + + /** + * Removes the input gameplay feature id from the GameplayFeatures.txt file + * @param gameplayFeatureId The gameplay feature id for which the gameplay feature should be removed + */ + public static void removeGameplayFeature(int gameplayFeatureId) throws IOException { + AnalyzeExistingGameplayFeatures.analyzeGameplayFeatures(); + LOGGER.info("Adding new gameplay feature..."); + File gameplayFeatureFile = Utils.getGameplayFeaturesFile(); + if(gameplayFeatureFile.exists()){ + gameplayFeatureFile.delete(); + } + gameplayFeatureFile.createNewFile(); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gameplayFeatureFile), StandardCharsets.UTF_8)); + bw.write("\ufeff"); + for(Map existingGameplayFeatures : AnalyzeExistingGameplayFeatures.gameplayFeatures){ + if(Integer.parseInt(existingGameplayFeatures.get("ID")) != gameplayFeatureId){ + bw.write("[ID]" + existingGameplayFeatures.get("ID"));bw.write(System.getProperty("line.separator")); + bw.write("[TYP]" + existingGameplayFeatures.get("TYP"));bw.write(System.getProperty("line.separator")); + TranslationManager.printLanguages(bw, existingGameplayFeatures); + bw.write("[DATE]" + existingGameplayFeatures.get("DATE"));bw.write(System.getProperty("line.separator")); + bw.write("[RES POINTS]" + existingGameplayFeatures.get("RES POINTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PRICE]" + existingGameplayFeatures.get("PRICE"));bw.write(System.getProperty("line.separator")); + bw.write("[DEV COSTS]" + existingGameplayFeatures.get("DEV COSTS"));bw.write(System.getProperty("line.separator")); + bw.write("[PIC]" + existingGameplayFeatures.get("PIC"));bw.write(System.getProperty("line.separator")); + bw.write("[GAMEPLAY]" + existingGameplayFeatures.get("GAMEPLAY"));bw.write(System.getProperty("line.separator")); + bw.write("[GRAPHIC]" + existingGameplayFeatures.get("GRAPHIC"));bw.write(System.getProperty("line.separator")); + bw.write("[SOUND]" + existingGameplayFeatures.get("SOUND"));bw.write(System.getProperty("line.separator")); + bw.write("[TECH]" + existingGameplayFeatures.get("TECH"));bw.write(System.getProperty("line.separator")); + if(existingGameplayFeatures.get("GOOD") == null){ + existingGameplayFeatures.put("GOOD", ""); + } + if(existingGameplayFeatures.get("BAD") == null){ + existingGameplayFeatures.put("BAD", ""); + } + bw.write("[GOOD]" + existingGameplayFeatures.get("GOOD"));bw.write(System.getProperty("line.separator")); + bw.write("[BAD]" + existingGameplayFeatures.get("BAD"));bw.write(System.getProperty("line.separator")); + } + } + bw.write(System.getProperty("line.separator")); + bw.write("[EOF]"); + bw.close(); + } + /** * Edits the GameplayFeatures.txt file to add genre id to the input gameplay feature * @param gameplayFeaturesIdsToEdit The map containing the gameplay features where the operation should be executed diff --git a/src/main/java/com/github/lmh01/mgt2mt/util/GameplayFeatureHelper.java b/src/main/java/com/github/lmh01/mgt2mt/util/GameplayFeatureHelper.java new file mode 100644 index 00000000..e603c3aa --- /dev/null +++ b/src/main/java/com/github/lmh01/mgt2mt/util/GameplayFeatureHelper.java @@ -0,0 +1,275 @@ +package com.github.lmh01.mgt2mt.util; + +import com.github.lmh01.mgt2mt.data_stream.AnalyzeExistingGameplayFeatures; +import com.github.lmh01.mgt2mt.data_stream.EditGameplayFeaturesFile; +import jdk.nashorn.internal.scripts.JO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.swing.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; + +public class GameplayFeatureHelper { + private static final Logger LOGGER = LoggerFactory.getLogger(GameplayFeatureHelper.class); + + /** + * Open a gui with which the user can add a new gameplay feature + */ + public static void addGameplayFeature(){ + try{ + AnalyzeExistingGameplayFeatures.analyzeGameplayFeatures(); + final Map[] mapNameTranslations = new Map[]{new HashMap<>()}; + final Map[] mapDescriptionTranslations = new Map[]{new HashMap<>()}; + final ArrayList[] badGenreIds = new ArrayList[]{new ArrayList<>()}; + final ArrayList[] goodGenreIds = new ArrayList[]{new ArrayList<>()}; + AtomicBoolean nameTranslationsAdded = new AtomicBoolean(false); + AtomicBoolean descriptionTranslationsAdded = new AtomicBoolean(false); + + JPanel panelName = new JPanel(); + JLabel labelName = new JLabel("Name:"); + JTextField textFieldName = new JTextField("ENTER FEATURE NAME"); + panelName.add(labelName); + panelName.add(textFieldName); + + JButton buttonAddNameTranslations = new JButton("Add name translations"); + buttonAddNameTranslations.setToolTipText("Click to add name translations
The value entered in the main text field will be used as the english translation"); + buttonAddNameTranslations.addActionListener(actionEvent -> { + if(!nameTranslationsAdded.get()){ + mapNameTranslations[0] = TranslationManager.getTranslationsMap(); + nameTranslationsAdded.set(true); + }else{ + if(JOptionPane.showConfirmDialog(null, "Name translations have already been added.\nDo you want to clear the translations and add new ones?") == JOptionPane.OK_OPTION){ + mapNameTranslations[0] = TranslationManager.getTranslationsMap(); + nameTranslationsAdded.set(true); + } + } + }); + + JPanel panelDescription = new JPanel(); + JLabel labelDescription = new JLabel("Description:"); + JTextField textFieldDescription = new JTextField("ENTER FEATURE DESCRIPTION"); + panelDescription.add(labelDescription); + panelDescription.add(textFieldDescription); + + JButton buttonAddDescriptionTranslations = new JButton("Add description translations"); + buttonAddDescriptionTranslations.setToolTipText("Click to add description translations
The value entered in the main text field will be used as the english translation"); + buttonAddDescriptionTranslations.addActionListener(actionEvent -> { + if(!descriptionTranslationsAdded.get()){ + mapDescriptionTranslations[0] = TranslationManager.getTranslationsMap(); + descriptionTranslationsAdded.set(true); + }else{ + if(JOptionPane.showConfirmDialog(null, "Description translations have already been added.\nDo you want to clear the translations and add new ones?") == JOptionPane.OK_OPTION){ + mapDescriptionTranslations[0] = TranslationManager.getTranslationsMap(); + descriptionTranslationsAdded.set(true); + } + } + }); + + JPanel panelType = new JPanel(); + JLabel labelSelectType = new JLabel("Type:"); + JComboBox comboBoxFeatureType = new JComboBox(); + comboBoxFeatureType.setToolTipText("Select what type your gameplay feature should be"); + comboBoxFeatureType.setModel(new DefaultComboBoxModel<>(new String[]{"Controls", "Gameplay", "Multiplayer", "Physics", "Graphic", "Sound"})); + comboBoxFeatureType.setSelectedItem("Multiplayer"); + panelType.add(labelSelectType); + panelType.add(comboBoxFeatureType); + + JPanel panelUnlockMonth = new JPanel(); + JLabel labelUnlockMonth = new JLabel("Unlock Month:"); + JComboBox comboBoxUnlockMonth = new JComboBox(); + comboBoxUnlockMonth.setToolTipText("This is the month when your gameplay feature will be unlocked."); + comboBoxUnlockMonth.setModel(new DefaultComboBoxModel<>(new String[]{"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"})); + comboBoxUnlockMonth.setSelectedItem("JAN"); + panelUnlockMonth.add(labelUnlockMonth); + panelUnlockMonth.add(comboBoxUnlockMonth); + + JPanel panelUnlockYear = new JPanel(); + JLabel labelUnlockYear = new JLabel("Unlock Year:"); + JSpinner spinnerUnlockYear = new JSpinner(); + if(Settings.disableSafetyFeatures){ + spinnerUnlockYear.setToolTipText("[Range: 1976 - 2999]
This is the year when your gameplay feature will be unlocked.
Note: The latest date you can currently start the game is 2015."); + spinnerUnlockYear.setModel(new SpinnerNumberModel(1976, 1976, 2999, 1)); + ((JSpinner.DefaultEditor)spinnerUnlockYear.getEditor()).getTextField().setEditable(true); + }else{ + spinnerUnlockYear.setToolTipText("[Range: 1976 - 2050]
This is the year when your gameplay feature will be unlocked.
Note: The latest date you can currently start the game is 2015."); + spinnerUnlockYear.setModel(new SpinnerNumberModel(1976, 1976, 2050, 1)); + ((JSpinner.DefaultEditor)spinnerUnlockYear.getEditor()).getTextField().setEditable(false); + } + panelUnlockYear.add(labelUnlockYear); + panelUnlockYear.add(spinnerUnlockYear); + + JPanel panelResearchPoints = new JPanel(); + JPanel panelDevelopmentCost = new JPanel(); + JPanel panelPrice = new JPanel(); + JLabel labelResearchPoints = new JLabel("Research points: "); + JLabel labelDevelopmentCost = new JLabel("Development cost: "); + JLabel labelPrice = new JLabel("Research cost: "); + JSpinner spinnerResearchPoints = new JSpinner(); + JSpinner spinnerDevelopmentCost = new JSpinner(); + JSpinner spinnerPrice = new JSpinner(); + spinnerResearchPoints.setToolTipText("[Range: 1 - 100.000; Default: 500]
Number of required research points to research that genre."); + spinnerDevelopmentCost.setToolTipText("[Range: 1 - 1.000.000; Default: 35000]
Set the development cost for a game with your genre.
This cost will be added when developing a game with this gameplay feature."); + spinnerPrice.setToolTipText("[Range: 1 - 1.000.000; Default: 50000]
This is the research cost, it is being payed when researching this gameplay feature."); + if(Settings.disableSafetyFeatures){ + spinnerResearchPoints.setModel(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1)); + spinnerDevelopmentCost.setModel(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1)); + spinnerPrice.setModel(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1)); + ((JSpinner.DefaultEditor)spinnerResearchPoints.getEditor()).getTextField().setEditable(true); + ((JSpinner.DefaultEditor)spinnerDevelopmentCost.getEditor()).getTextField().setEditable(true); + ((JSpinner.DefaultEditor)spinnerPrice.getEditor()).getTextField().setEditable(true); + }else{ + spinnerResearchPoints.setModel(new SpinnerNumberModel(500, 1, 100000, 100)); + spinnerDevelopmentCost.setModel(new SpinnerNumberModel(35000, 1, 1000000, 1000)); + spinnerPrice.setModel(new SpinnerNumberModel(50000, 1, 1000000, 1000)); + ((JSpinner.DefaultEditor)spinnerResearchPoints.getEditor()).getTextField().setEditable(false); + ((JSpinner.DefaultEditor)spinnerDevelopmentCost.getEditor()).getTextField().setEditable(false); + ((JSpinner.DefaultEditor)spinnerPrice.getEditor()).getTextField().setEditable(false); + } + panelResearchPoints.add(labelResearchPoints); + panelResearchPoints.add(spinnerResearchPoints); + panelDevelopmentCost.add(labelDevelopmentCost); + panelDevelopmentCost.add(spinnerDevelopmentCost); + panelPrice.add(labelPrice); + panelPrice.add(spinnerPrice); + + JPanel panelGameplay = new JPanel(); + JPanel panelGraphic = new JPanel(); + JPanel panelSound = new JPanel(); + JPanel panelTech = new JPanel(); + JLabel labelGameplay = new JLabel("Gameplay:"); + JLabel labelGraphic = new JLabel("Graphic:"); + JLabel labelSound = new JLabel("Sound:"); + JLabel labelTech = new JLabel("Tech:"); + JSpinner spinnerGameplay = new JSpinner(); + JSpinner spinnerGraphic = new JSpinner(); + JSpinner spinnerSound = new JSpinner(); + JSpinner spinnerTech = new JSpinner(); + spinnerGameplay.setToolTipText("[Range: 0 - 250; Default: 10]
The amount of gameplay points that are added when a game is developed with this feature."); + spinnerGraphic.setToolTipText("[Range: 0 - 250; Default: 10]
The amount of graphic points that are added when a game is developed with this feature."); + spinnerSound.setToolTipText("[Range: 0 - 250; Default: 10]
The amount of sound points that are added when a game is developed with this feature."); + spinnerTech.setToolTipText("[Range: 0 - 250; Default: 10]
The amount of tech points that are added when a game is developed with this feature."); + if(Settings.disableSafetyFeatures){ + spinnerGameplay.setModel(new SpinnerNumberModel(10, 0, Integer.MAX_VALUE, 5)); + spinnerGraphic.setModel(new SpinnerNumberModel(10, 0, Integer.MAX_VALUE, 5)); + spinnerSound.setModel(new SpinnerNumberModel(10, 0, Integer.MAX_VALUE, 5)); + spinnerTech.setModel(new SpinnerNumberModel(10, 0, Integer.MAX_VALUE, 5)); + ((JSpinner.DefaultEditor)spinnerGameplay.getEditor()).getTextField().setEditable(true); + ((JSpinner.DefaultEditor)spinnerGraphic.getEditor()).getTextField().setEditable(true); + ((JSpinner.DefaultEditor)spinnerSound.getEditor()).getTextField().setEditable(true); + ((JSpinner.DefaultEditor)spinnerTech.getEditor()).getTextField().setEditable(true); + }else{ + spinnerGameplay.setModel(new SpinnerNumberModel(10, 0, 250, 5)); + spinnerGraphic.setModel(new SpinnerNumberModel(10, 0, 250, 5)); + spinnerSound.setModel(new SpinnerNumberModel(10, 0, 250, 5)); + spinnerTech.setModel(new SpinnerNumberModel(10, 0, 250, 5)); + ((JSpinner.DefaultEditor)spinnerGameplay.getEditor()).getTextField().setEditable(false); + ((JSpinner.DefaultEditor)spinnerGraphic.getEditor()).getTextField().setEditable(false); + ((JSpinner.DefaultEditor)spinnerSound.getEditor()).getTextField().setEditable(false); + ((JSpinner.DefaultEditor)spinnerTech.getEditor()).getTextField().setEditable(false); + } + panelGameplay.add(labelGameplay); + panelGameplay.add(spinnerGameplay); + panelGraphic.add(labelGraphic); + panelGraphic.add(spinnerGraphic); + panelSound.add(labelSound); + panelSound.add(spinnerSound); + panelTech.add(labelTech); + panelTech.add(spinnerTech); + + JButton buttonBadGenres = new JButton("Select Bad Genres"); + buttonBadGenres.setToolTipText("Click to select what genres don't work good with your gameplay feature"); + buttonBadGenres.addActionListener(actionEvent -> { + badGenreIds[0] = Utils.getSelectedGenresIds("Select the genre(s) that don't work with your gameplay feature"); + if(badGenreIds[0].size() != 0){ + buttonBadGenres.setToolTipText("Bad Genres Selected"); + }else{ + buttonBadGenres.setToolTipText("Select Bad Genres"); + } + }); + JButton buttonGoodGenres = new JButton("Select Good Genres"); + buttonGoodGenres.addActionListener(actionEvent -> { + goodGenreIds[0] = Utils.getSelectedGenresIds("Select the genre(s) that work with your gameplay feature"); + if(goodGenreIds[0].size() != 0){ + buttonGoodGenres.setToolTipText("Good Genres Selected"); + }else{ + buttonGoodGenres.setToolTipText("Select Good Genres"); + } + }); + Object[] params = {panelName, buttonAddNameTranslations, panelDescription, buttonAddDescriptionTranslations, panelType, panelUnlockMonth, panelUnlockYear, panelResearchPoints, panelDevelopmentCost, panelPrice, panelGameplay, panelGraphic, panelSound, panelTech, buttonBadGenres, buttonGoodGenres}; + while(true){ + if(JOptionPane.showConfirmDialog(null, params, "Add Gameplay Feature", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){ + if(textFieldName.getText().isEmpty() || textFieldName.getText().equals("ENTER FEATURE NAME") || textFieldDescription.getText().isEmpty() || textFieldDescription.getText().equals("ENTER FEATURE DESCRIPTION")){ + JOptionPane.showMessageDialog(null, "Unable to add gameplay feature: please enter a name/description first!", "Unable to continue", JOptionPane.ERROR_MESSAGE); + }else{ + Map newGameplayFeature = new HashMap<>(); + if(!nameTranslationsAdded.get() && !descriptionTranslationsAdded.get()){ + newGameplayFeature.putAll(TranslationManager.getDefaultNameTranslations(textFieldName.getText())); + newGameplayFeature.putAll(TranslationManager.getDefaultDescriptionTranslations(textFieldDescription.getText())); + }else if(!nameTranslationsAdded.get() && descriptionTranslationsAdded.get()){ + newGameplayFeature.putAll(TranslationManager.getDefaultNameTranslations(textFieldName.getText())); + newGameplayFeature.putAll(TranslationManager.transformTranslationMap(mapDescriptionTranslations[0], "DESC")); + }else if(nameTranslationsAdded.get() && !descriptionTranslationsAdded.get()){ + newGameplayFeature.putAll(TranslationManager.transformTranslationMap(mapNameTranslations[0], "NAME")); + newGameplayFeature.putAll(TranslationManager.getDefaultDescriptionTranslations(textFieldDescription.getText())); + }else{ + newGameplayFeature.putAll(TranslationManager.transformTranslationMap(mapNameTranslations[0], "NAME")); + newGameplayFeature.putAll(TranslationManager.transformTranslationMap(mapDescriptionTranslations[0], "DESC")); + newGameplayFeature.put("NAME EN", textFieldName.getText()); + newGameplayFeature.put("DESC EN", textFieldDescription.getText()); + } + newGameplayFeature.put("ID", Integer.toString(AnalyzeExistingGameplayFeatures.getFreeGameplayFeatureId())); + newGameplayFeature.put("TYP", Integer.toString(getGameplayFeatureTypeByName(comboBoxFeatureType.getSelectedItem().toString()))); + newGameplayFeature.put("DATE", Objects.requireNonNull(comboBoxUnlockMonth.getSelectedItem()).toString() + " " + spinnerUnlockYear.getValue().toString()); + newGameplayFeature.put("RES POINTS", spinnerResearchPoints.getValue().toString()); + newGameplayFeature.put("PRICE", spinnerPrice.getValue().toString()); + newGameplayFeature.put("DEV COSTS", spinnerDevelopmentCost.getValue().toString()); + newGameplayFeature.put("PIC", ""); + newGameplayFeature.put("GAMEPLAY", spinnerGameplay.getValue().toString()); + newGameplayFeature.put("GRAPHIC", spinnerGraphic.getValue().toString()); + newGameplayFeature.put("SOUND", spinnerSound.getValue().toString()); + newGameplayFeature.put("TECH", spinnerTech.getValue().toString()); + newGameplayFeature.put("GOOD", Utils.transformArrayListToString(goodGenreIds[0])); + newGameplayFeature.put("BAD", Utils.transformArrayListToString(badGenreIds[0])); + for(Map.Entry entry : newGameplayFeature.entrySet()){ + LOGGER.info("Key: " + entry.getKey() + " | " + entry.getValue()); + } + EditGameplayFeaturesFile.addGameplayFeature(newGameplayFeature); + break; + } + }else{ + break; + } + } + }catch(IOException e){ + + } + } + + /** + * Opens a gui where the user can select the gameplay feature that should be removed + */ + public static void removeGameplayFeature(){ + + } + + /** + * Converts the input string into the respective type number + * @param featureType The feature type string + * @return Returns the type number + */ + public static int getGameplayFeatureTypeByName(String featureType){ + switch (featureType){ + case "Graphic": return 0; + case "Sound": return 1; + case "Physics": return 3; + case "Gameplay": return 4; + case "Control": return 5; + case "Multiplayer": return 6; + } + return 10; + } +} diff --git a/src/main/java/com/github/lmh01/mgt2mt/util/TranslationManager.java b/src/main/java/com/github/lmh01/mgt2mt/util/TranslationManager.java index d45cd310..a2ae7afe 100644 --- a/src/main/java/com/github/lmh01/mgt2mt/util/TranslationManager.java +++ b/src/main/java/com/github/lmh01/mgt2mt/util/TranslationManager.java @@ -10,11 +10,11 @@ import java.util.Map; public class TranslationManager { + private static final Logger LOGGER = LoggerFactory.getLogger(GameplayFeatureHelper.class); public static final String[] TRANSLATION_KEYS = {"AR", "CH", "CT", "CZ", "EN", "ES", "FR", "GE", "HU", "IT", "KO", "PB", "PL", "RO", "RU", "TU"}; public static final String[] TRANSLATION_NAMES = {"Arabic", "Chinese simplified", "Chinese traditional", "Czech", "English", "Spanish", "French", "German", "Hungarian", "Italian", "Korean", "Portuguese", "Polish", "Romanian", "Russian", "Turkish"}; public static final String[] LANGUAGE_KEYS_UTF_8_BOM = {"IT", "RO", "RU"}; public static final String[] LANGUAGE_KEYS_UTF_16_LE = {"AR", "CH", "CT", "CZ", "EN", "ES", "FR", "GE", "HU", "KO", "PB", "PL", "TU"}; - /** * @return Returns a array list with the user input that should be used as translation. See cases for translation position in array list. */ @@ -106,4 +106,41 @@ public static void printLanguages(BufferedWriter bw, Map map) th } } + /** + * @param nameEN The name that should be added + * @return Returns a map with the translation keys where every name translation is set as the english one + */ + public static Map getDefaultNameTranslations(String nameEN){ + Map returnMap = new HashMap<>(); + for(String string : TranslationManager.TRANSLATION_KEYS){ + returnMap.put("NAME " + string, nameEN); + } + return returnMap; + } + + /** + * @param descriptionEN The description that should be added + * @return Returns a map with the translation keys where every description translation is set as the english one + */ + public static Map getDefaultDescriptionTranslations(String descriptionEN){ + Map returnMap = new HashMap<>(); + for(String string : TranslationManager.TRANSLATION_KEYS){ + returnMap.put("DESC " + string, descriptionEN); + } + return returnMap; + } + + /** + * The input map just has the language keys and the translations. This function changes the key to include the type. Eg. input map is "Key: GE" "Value: Hey" this is transformed to "Key: NAME GE" "Value Hey" + * @param map The input map + * @param type NAME or DESC + * @return + */ + public static Map transformTranslationMap(Map map, String type){ + Map outputMap = new HashMap<>(); + for(Map.Entry entry : map.entrySet()){ + outputMap.put(type + " " + entry.getKey(), entry.getValue()); + } + return outputMap; + } } diff --git a/src/main/java/com/github/lmh01/mgt2mt/util/Utils.java b/src/main/java/com/github/lmh01/mgt2mt/util/Utils.java index daeb4e05..97a539a2 100644 --- a/src/main/java/com/github/lmh01/mgt2mt/util/Utils.java +++ b/src/main/java/com/github/lmh01/mgt2mt/util/Utils.java @@ -2,6 +2,7 @@ import com.github.lmh01.mgt2mt.data_stream.AnalyzeExistingGameplayFeatures; import com.github.lmh01.mgt2mt.data_stream.AnalyzeExistingGenres; +import com.github.lmh01.mgt2mt.data_stream.SharingHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; @@ -16,6 +17,8 @@ import java.time.LocalDateTime; import java.util.*; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class Utils { @@ -538,4 +541,47 @@ public static String getCompatibleGameplayFeatureIdsForGenre(int genreId, boolea } return gameplayFeaturesIds.toString(); } + + /** + * Opens a window where the user can select genres. + * @param labelText The text that should be displayed at the top of the window + * @return Returns the genre ids for the selected genres as array list. + */ + public static ArrayList getSelectedGenresIds(String labelText){//TODO Make more use of this function + ArrayList genreIds = new ArrayList<>(); + JLabel labelChooseGenre = new JLabel(labelText); + String[] existingGenresByAlphabet; + existingGenresByAlphabet = AnalyzeExistingGenres.getGenresByAlphabetWithoutId(); + JList listAvailableGenres = new JList<>(existingGenresByAlphabet); + listAvailableGenres.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + listAvailableGenres.setLayoutOrientation(JList.VERTICAL); + listAvailableGenres.setVisibleRowCount(-1); + JScrollPane scrollPaneAvailableGenres = new JScrollPane(listAvailableGenres); + scrollPaneAvailableGenres.setPreferredSize(new Dimension(315,140)); + + Object[] params = {labelChooseGenre, scrollPaneAvailableGenres}; + + if(JOptionPane.showConfirmDialog(null, params, "Choose genre(s)", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){ + if(!listAvailableGenres.isSelectionEmpty()){ + for(String string : listAvailableGenres.getSelectedValuesList()){ + genreIds.add(AnalyzeExistingGenres.getGenreIdByName(string)); + } + }else{ + JOptionPane.showMessageDialog(null, "Please select a genre first.", "Action unavailable", JOptionPane.ERROR_MESSAGE); + } + } + return genreIds; + } + + /** + * @param arrayList The array list containing the ids + * @return Returns the ids in the respective formatting + */ + public static String transformArrayListToString(ArrayList arrayList){ + StringBuilder returnString = new StringBuilder(); + for(Integer integer : arrayList){ + returnString.append("<").append(integer).append(">"); + } + return returnString.toString(); + } } diff --git a/src/main/java/com/github/lmh01/mgt2mt/windows/WindowMain.java b/src/main/java/com/github/lmh01/mgt2mt/windows/WindowMain.java index 2350f9d3..3eed60f9 100644 --- a/src/main/java/com/github/lmh01/mgt2mt/windows/WindowMain.java +++ b/src/main/java/com/github/lmh01/mgt2mt/windows/WindowMain.java @@ -7,9 +7,7 @@ import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.*; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -18,7 +16,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -public class WindowMain { +public class WindowMain {//TODO Clean up main window -> Move all functions from below in new/existing classes private static final Logger LOGGER = LoggerFactory.getLogger(WindowMain.class); private static final JFrame frame = new JFrame("MGT2 Mod Tool"); private static final JMenuItem M211ADD_GENRE = new JMenuItem("Add Genre"); @@ -27,8 +25,9 @@ public class WindowMain { private static final JMenuItem M313EXPORT_THEME = new JMenuItem("Theme"); private static final JMenuItem M312EXPORT_PUBLISHER = new JMenuItem("Publisher"); private static final JMenuItem M22REMOVE_THEME = new JMenuItem("Remove Theme"); - private static final JMenuItem M24NPC_GAMES_LIST = new JMenuItem("NPC_Games_list"); + private static final JMenuItem M25NPC_GAMES_LIST = new JMenuItem("NPC_Games_list"); private static final JMenuItem M232REMOVE_PUBLISHER = new JMenuItem("Remove Publisher"); + private static final JMenuItem M242REMOVE_GAMEPLAY_FEATURE = new JMenuItem("Remove Gameplay Feature"); private static final JMenuItem M314EXPORT_ALL = new JMenuItem("Export All"); public static void createFrame(){ //Creating the Frame @@ -55,11 +54,13 @@ public static void createFrame(){ JMenu m21Genres = new JMenu("Genres"); JMenu m22Themes = new JMenu("Themes"); JMenu m23Publisher = new JMenu("Publisher"); + JMenu m24GameplayFeatures = new JMenu("Gameplay Features"); JMenuItem m221AddTheme = new JMenuItem("Add Theme"); JMenuItem m223ImportTheme = new JMenuItem("Import Theme"); JMenuItem m231AddPublisher = new JMenuItem("Add Publisher"); JMenuItem m213ImportGenre = new JMenuItem("Import Genre"); JMenuItem m233ImportPublisher = new JMenuItem("Import Publisher"); + JMenuItem m241AddGameplayFeature = new JMenuItem("Add Gameplay Feature"); m21Genres.add(M211ADD_GENRE); m21Genres.add(M212REMOVE_GENRE); m21Genres.add(m213ImportGenre); @@ -69,6 +70,8 @@ public static void createFrame(){ m23Publisher.add(m231AddPublisher); m23Publisher.add(M232REMOVE_PUBLISHER); m23Publisher.add(m233ImportPublisher); + m24GameplayFeatures.add(m241AddGameplayFeature); + m24GameplayFeatures.add(M242REMOVE_GAMEPLAY_FEATURE); M211ADD_GENRE.addActionListener(actionEvent -> addGenre()); M212REMOVE_GENRE.addActionListener(actionEvent -> removeGenre()); m221AddTheme.addActionListener(actionEvent -> addTheme()); @@ -76,20 +79,23 @@ public static void createFrame(){ m223ImportTheme.addActionListener(actionEvent -> importTheme()); m213ImportGenre.addActionListener(actionEvent -> importGenre()); m233ImportPublisher.addActionListener(actionEvent -> importPublisher()); - M24NPC_GAMES_LIST.setToolTipText("Click to add a genre id to the NPC_Games_list."); - M24NPC_GAMES_LIST.addActionListener(actionEvent -> npcGameList()); + M25NPC_GAMES_LIST.setToolTipText("Click to add a genre id to the NPC_Games_list."); + M25NPC_GAMES_LIST.addActionListener(actionEvent -> npcGameList()); m231AddPublisher.setToolTipText("Click to add a publisher to MGT2"); m231AddPublisher.addActionListener(actionEvent -> addPublisher()); M232REMOVE_PUBLISHER.setToolTipText("Click to remove a publisher from MGT2"); M232REMOVE_PUBLISHER.addActionListener(actionEvent -> removePublisher()); - JMenuItem m25AddCompanyIcon = new JMenuItem("Add Company Icon"); - m25AddCompanyIcon.addActionListener(actionEvent -> addCompanyIcon()); + m241AddGameplayFeature.addActionListener(actionEvent -> GameplayFeatureHelper.addGameplayFeature()); + M242REMOVE_GAMEPLAY_FEATURE.addActionListener(actionEvent -> GameplayFeatureHelper.removeGameplayFeature()); + JMenuItem m26AddCompanyIcon = new JMenuItem("Add Company Icon"); + m26AddCompanyIcon.addActionListener(actionEvent -> addCompanyIcon()); mb.add(m2Mods); m2Mods.add(m21Genres); m2Mods.add(m22Themes); m2Mods.add(m23Publisher); - m2Mods.add(M24NPC_GAMES_LIST); - m2Mods.add(m25AddCompanyIcon); + m2Mods.add(m24GameplayFeatures); + m2Mods.add(M25NPC_GAMES_LIST); + m2Mods.add(m26AddCompanyIcon); JMenu m3Share = new JMenu("Share"); JMenu m31Export = new JMenu("Export"); m31Export.add(M311EXPORT_GENRE); @@ -209,10 +215,12 @@ public static void checkActionAvailability(){ boolean noCustomGenreAvailable = true; boolean noCustomThemesAvailable = true; boolean noCustomPublishersAvailable = true; + boolean noCustomGameplayFeaturesAvailable = true; if(Settings.disableSafetyFeatures){ noCustomGenreAvailable = false; noCustomThemesAvailable = false; noCustomPublishersAvailable = false; + noCustomGameplayFeaturesAvailable = false; }else{ String[] stringCustomGenres = AnalyzeExistingGenres.getCustomGenresByAlphabetWithoutId(); if(stringCustomGenres.length != 0){ @@ -225,14 +233,19 @@ public static void checkActionAvailability(){ if(list.size() > 71){ noCustomPublishersAvailable = false; } + List> currentGameplayFeatures = AnalyzeExistingGameplayFeatures.gameplayFeatures; + if(currentGameplayFeatures.size() > 58){ + noCustomGameplayFeaturesAvailable = false; + } } M212REMOVE_GENRE.setEnabled(!noCustomGenreAvailable); M22REMOVE_THEME.setEnabled(!noCustomThemesAvailable); - M24NPC_GAMES_LIST.setEnabled(!noCustomGenreAvailable); + M25NPC_GAMES_LIST.setEnabled(!noCustomGenreAvailable); M232REMOVE_PUBLISHER.setEnabled(!noCustomPublishersAvailable); M311EXPORT_GENRE.setEnabled(!noCustomGenreAvailable); M312EXPORT_PUBLISHER.setEnabled(!noCustomPublishersAvailable); M313EXPORT_THEME.setEnabled(!noCustomThemesAvailable); + M242REMOVE_GAMEPLAY_FEATURE.setEnabled(!noCustomGameplayFeaturesAvailable); if(noCustomGenreAvailable && noCustomPublishersAvailable){ M314EXPORT_ALL.setEnabled(false); }else{ @@ -240,13 +253,13 @@ public static void checkActionAvailability(){ } if(noCustomGenreAvailable){ M212REMOVE_GENRE.setToolTipText("Disabled -> No genre to remove available"); - M24NPC_GAMES_LIST.setToolTipText("Disabled -> Add a genre first"); + M25NPC_GAMES_LIST.setToolTipText("Disabled -> Add a genre first"); M311EXPORT_GENRE.setToolTipText("Disabled -> No genre to export available"); - }else if(noCustomGenreAvailable && noCustomPublishersAvailable){ - M314EXPORT_ALL.setToolTipText("Disabled -> Mo genre or publisher to export available"); + }else if(noCustomGenreAvailable && noCustomPublishersAvailable && noCustomThemesAvailable){ + M314EXPORT_ALL.setToolTipText("Disabled -> Mo genre, theme or publisher to export available"); }else{ M212REMOVE_GENRE.setToolTipText(""); - M24NPC_GAMES_LIST.setToolTipText(""); + M25NPC_GAMES_LIST.setToolTipText(""); M311EXPORT_GENRE.setToolTipText(""); M314EXPORT_ALL.setToolTipText("Click to export all publishers and genres that have been added"); } @@ -263,6 +276,11 @@ public static void checkActionAvailability(){ M232REMOVE_PUBLISHER.setToolTipText(""); M312EXPORT_PUBLISHER.setToolTipText(""); } + if(noCustomGameplayFeaturesAvailable){ + M242REMOVE_GAMEPLAY_FEATURE.setToolTipText("Disabled -> Add gameplay feature first"); + }else{ + M242REMOVE_GAMEPLAY_FEATURE.setToolTipText(""); + } }catch (IOException e){ LOGGER.info("Error" + e.getMessage()); e.printStackTrace(); @@ -785,6 +803,9 @@ private static void removePublisher(){ e.printStackTrace(); } checkActionAvailability(); + } + private static void removeGameplayFeature(){ + } private static void addCompanyIcon(){ String imageFilePath = Utils.getImagePath();