<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.xtx.ut4converter.ui;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import javax.swing.SwingUtilities;
import javax.xml.bind.JAXBException;

import org.xtx.ut4converter.MainApp;
import org.xtx.ut4converter.MapConverter;
import org.xtx.ut4converter.UTGames;
import org.xtx.ut4converter.UTGames.UTGame;
import org.xtx.ut4converter.UTGames.UnrealEngine;
import org.xtx.ut4converter.config.UserConfig;
import org.xtx.ut4converter.config.UserGameConfig;
import org.xtx.ut4converter.t3d.T3DUtils;
import org.xtx.ut4converter.tools.Installation;

/**
 * FXML Controller class
 *
 * @author XtremeXp
 */
@SuppressWarnings("restriction")
public class ConversionSettingsController implements Initializable {
	@FXML
	private AnchorPane ConversionSettings;

	Stage dialogStage;

	@FXML
	private Label inputGameLbl;
	@FXML
	private Label outputGameLbl;
	@FXML
	private Label inputMapLbl;
	@FXML
	private Label outputFolderLbl;
	
	/**
	 * Path where ressources will be referenced to
	 * (e.g: '/Game/RestrictedAssets/Maps/WIP/DM-Deck16'
	 */
	@FXML
	private Label ut4BaseReferencePath;

	MainApp mainApp;

	MapConverter mapConverter;

	UTGames.UTGame inputGame;
	UTGames.UTGame outputGame;

	UserConfig userConfig;
	UserGameConfig userInputGameConfig;
	UserGameConfig userOutputGameConfig;
	@FXML
	private TitledPane advancedSettingsTitle;
	@FXML
	private TitledPane mainSettingsTitle;
	@FXML
	private CheckBox convTexCheckBox;
	@FXML
	private CheckBox convSndCheckBox;
	@FXML
	private CheckBox convSmCheckBox;
	@FXML
	private CheckBox convMusicCheckBox;

	/**
	 * Default scale factor of converted maps from UE1/UE2 ut games to UT4
	 */
	static final BigDecimal DEFAULT_SCALE_FACTOR_UE12_UE4 = new BigDecimal("2.4");
	
	/**
	 * Default scale factor of converted maps from UT3 (Unreal Engine 3) to UT4
	 */
	static final BigDecimal DEFAULT_SCALE_FACTOR_UE3_UE4 = new BigDecimal("2.2");
	
	@FXML
	private ComboBox<String> scaleFactorList;
	@FXML
	private ComboBox<String> lightningBrightnessFactor;
	@FXML
	private ComboBox<String> soundVolumeFactor;
	@FXML
	private Label outMapNameLbl;
	// @FXML
	// private Label relativeUtMapPathLbl;
	@FXML
	private CheckBox debugLogLevel;
	@FXML
	private Button changeMapNameBtn;

	@FXML
	private Button changeRelativeUtMapPathBtn;

	@FXML
	private Label warningMessage;

	@FXML
	private TextField classesNameFilter;

	/**
	 * Initializes the controller class.
	 * 
	 * @param url
	 * @param rb
	 */
	@Override
	public void initialize(URL url, ResourceBundle rb) {
		// TODO
		advancedSettingsTitle.setText("Advanced Settings");
		mainSettingsTitle.setText("Main Settings");

		if(mapConverter.getInputGame().engine.version <= 2){
			scaleFactorList.getSelectionModel().select(String.valueOf(DEFAULT_SCALE_FACTOR_UE12_UE4));
		} else if (mapConverter.getInputGame().engine.version == 3) {
			scaleFactorList.getSelectionModel().select(String.valueOf(DEFAULT_SCALE_FACTOR_UE3_UE4));
		} else {
			scaleFactorList.getSelectionModel().select("1");
		}
		lightningBrightnessFactor.getSelectionModel().select("1");
		soundVolumeFactor.getSelectionModel().select("1");
	}

	public void setDialogStage(Stage dialogStage) {
		this.dialogStage = dialogStage;
	}

	public void setInputGame(UTGames.UTGame inputGame) {
		this.inputGame = inputGame;
	}

	public void setOutputGame(UTGames.UTGame outputGame) {
		this.outputGame = outputGame;
	}

	public void setMainApp(MainApp mainApp) {
		this.mainApp = mainApp;
	}

	public void load() throws JAXBException {

		inputGameLbl.setText(inputGame.name);
		outputGameLbl.setText(outputGame.name);

		userConfig = UserConfig.load();

		if (userConfig != null) {
			userInputGameConfig = userConfig.getGameConfigByGame(inputGame);
			userOutputGameConfig = userConfig.getGameConfigByGame(outputGame);
		}

		if (userConfig.getUModelPath() == null || !userConfig.getUModelPath().exists()) {
			warningMessage.setText("UModel not set in settings. Some ressources might not be exported.");
			warningMessage.setStyle("-fx-text-fill: red; -fx-font-size: 16;");
		}

		mapConverter = new MapConverter(inputGame, outputGame);

		// relativeUtMapPathLbl.setText(mapConverter.getRelativeUtMapPath());
		disableConversionType();<commit_msg>fix conversion settings crash<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.xtx.ut4converter.ui;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import javax.swing.SwingUtilities;
import javax.xml.bind.JAXBException;

import org.xtx.ut4converter.MainApp;
import org.xtx.ut4converter.MapConverter;
import org.xtx.ut4converter.UTGames;
import org.xtx.ut4converter.UTGames.UTGame;
import org.xtx.ut4converter.UTGames.UnrealEngine;
import org.xtx.ut4converter.config.UserConfig;
import org.xtx.ut4converter.config.UserGameConfig;
import org.xtx.ut4converter.t3d.T3DUtils;
import org.xtx.ut4converter.tools.Installation;

/**
 * FXML Controller class
 *
 * @author XtremeXp
 */
@SuppressWarnings("restriction")
public class ConversionSettingsController implements Initializable {
	@FXML
	private AnchorPane ConversionSettings;

	Stage dialogStage;

	@FXML
	private Label inputGameLbl;
	@FXML
	private Label outputGameLbl;
	@FXML
	private Label inputMapLbl;
	@FXML
	private Label outputFolderLbl;
	
	/**
	 * Path where ressources will be referenced to
	 * (e.g: '/Game/RestrictedAssets/Maps/WIP/DM-Deck16'
	 */
	@FXML
	private Label ut4BaseReferencePath;

	MainApp mainApp;

	MapConverter mapConverter;

	UTGames.UTGame inputGame;
	UTGames.UTGame outputGame;

	UserConfig userConfig;
	UserGameConfig userInputGameConfig;
	UserGameConfig userOutputGameConfig;
	@FXML
	private TitledPane advancedSettingsTitle;
	@FXML
	private TitledPane mainSettingsTitle;
	@FXML
	private CheckBox convTexCheckBox;
	@FXML
	private CheckBox convSndCheckBox;
	@FXML
	private CheckBox convSmCheckBox;
	@FXML
	private CheckBox convMusicCheckBox;

	/**
	 * Default scale factor of converted maps from UE1/UE2 ut games to UT4
	 */
	static final BigDecimal DEFAULT_SCALE_FACTOR_UE12_UE4 = new BigDecimal("2.4");
	
	/**
	 * Default scale factor of converted maps from UT3 (Unreal Engine 3) to UT4
	 */
	static final BigDecimal DEFAULT_SCALE_FACTOR_UE3_UE4 = new BigDecimal("2.2");
	
	@FXML
	private ComboBox<String> scaleFactorList;
	@FXML
	private ComboBox<String> lightningBrightnessFactor;
	@FXML
	private ComboBox<String> soundVolumeFactor;
	@FXML
	private Label outMapNameLbl;
	// @FXML
	// private Label relativeUtMapPathLbl;
	@FXML
	private CheckBox debugLogLevel;
	@FXML
	private Button changeMapNameBtn;

	@FXML
	private Button changeRelativeUtMapPathBtn;

	@FXML
	private Label warningMessage;

	@FXML
	private TextField classesNameFilter;

	/**
	 * Initializes the controller class.
	 * 
	 * @param url
	 * @param rb
	 */
	@Override
	public void initialize(URL url, ResourceBundle rb) {
		// TODO
		advancedSettingsTitle.setText("Advanced Settings");
		mainSettingsTitle.setText("Main Settings");

		lightningBrightnessFactor.getSelectionModel().select("1");
		soundVolumeFactor.getSelectionModel().select("1");
	}

	public void setDialogStage(Stage dialogStage) {
		this.dialogStage = dialogStage;
	}

	public void setInputGame(UTGames.UTGame inputGame) {
		this.inputGame = inputGame;
	}

	public void setOutputGame(UTGames.UTGame outputGame) {
		this.outputGame = outputGame;
	}

	public void setMainApp(MainApp mainApp) {
		this.mainApp = mainApp;
	}

	public void load() throws JAXBException {

		inputGameLbl.setText(inputGame.name);
		outputGameLbl.setText(outputGame.name);

		userConfig = UserConfig.load();

		if (userConfig != null) {
			userInputGameConfig = userConfig.getGameConfigByGame(inputGame);
			userOutputGameConfig = userConfig.getGameConfigByGame(outputGame);
		}

		if (userConfig.getUModelPath() == null || !userConfig.getUModelPath().exists()) {
			warningMessage.setText("UModel not set in settings. Some ressources might not be exported.");
			warningMessage.setStyle("-fx-text-fill: red; -fx-font-size: 16;");
		}

		mapConverter = new MapConverter(inputGame, outputGame);
		
		if(mapConverter.getInputGame().engine.version <= 2){
			scaleFactorList.getSelectionModel().select(String.valueOf(DEFAULT_SCALE_FACTOR_UE12_UE4));
		} else if (mapConverter.getInputGame().engine.version == 3) {
			scaleFactorList.getSelectionModel().select(String.valueOf(DEFAULT_SCALE_FACTOR_UE3_UE4));
		} else {
			scaleFactorList.getSelectionModel().select("1");
		}

		// relativeUtMapPathLbl.setText(mapConverter.getRelativeUtMapPath());
		disableConversionType();
{'fraction_non_alphanumeric': 0.09749877390877881, 'fraction_numerical': 0.008239333006375674, 'mean_word_length': 5.336855189558732, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1920042', 'n_tokens_mistral': 3467, 'n_tokens_neox': 3269, 'n_words': 708}