2022-01-19 13:06:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-02-06 10:20:32 +00:00
|
|
|
|
using System.Diagnostics;
|
2022-02-06 03:29:03 +00:00
|
|
|
|
using System.IO;
|
2022-01-19 13:06:54 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
2022-02-06 03:29:03 +00:00
|
|
|
|
namespace ScrapModLoader
|
|
|
|
|
{
|
2022-01-19 13:06:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
2022-02-06 03:29:03 +00:00
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly ModsLauncher modsLauncher;
|
|
|
|
|
|
|
|
|
|
private GridLength gridLength = new GridLength(1, GridUnitType.Star);
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
modsLauncher = new ModsLauncher();
|
2022-01-19 13:06:54 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2022-02-06 03:29:03 +00:00
|
|
|
|
|
|
|
|
|
private void Window_Initialized(Object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Settings.Default.ModsPathes.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
|
|
|
|
|
+ Path.DirectorySeparatorChar + "Scrapland mods";
|
|
|
|
|
Settings.Default.ModsPathes.Add(path);
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Refactor it to separate window with pretty loading animation
|
2022-02-06 09:38:13 +00:00
|
|
|
|
if (modsLauncher.ScraplandPath == String.Empty && modsLauncher.ScraplandRemasteredPath == String.Empty)
|
2022-02-06 03:29:03 +00:00
|
|
|
|
{
|
2022-02-06 09:38:13 +00:00
|
|
|
|
Boolean isFoundScrapland = modsLauncher.SearchForScrapland();
|
|
|
|
|
if (!isFoundScrapland)
|
|
|
|
|
{
|
|
|
|
|
ButtonRunScrapland.IsEnabled = false;
|
|
|
|
|
MessageBox.Show("Error: unable to find Scrapland instalation. Please, specify yours game installation folder in settings.");
|
|
|
|
|
}
|
2022-02-06 03:29:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-06 09:38:13 +00:00
|
|
|
|
((ComboBoxItem)ScraplandVersion.Items[0]).IsEnabled = modsLauncher.ScraplandPath != String.Empty;
|
|
|
|
|
((ComboBoxItem)ScraplandVersion.Items[1]).IsEnabled = modsLauncher.ScraplandRemasteredPath != String.Empty;
|
|
|
|
|
|
|
|
|
|
ScraplandVersion.SelectedIndex = modsLauncher.ScraplandRemasteredPath != String.Empty ? 1 : 0;
|
|
|
|
|
|
2022-02-06 03:29:03 +00:00
|
|
|
|
modsLauncher.ScanMods();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ModsList_Initialized(Object sender, EventArgs e) => ModsList.ItemsSource = modsLauncher.Mods;
|
|
|
|
|
|
|
|
|
|
private void ModsList_MouseDown(Object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainGrid.ColumnDefinitions[2].Width.Value != 0)
|
|
|
|
|
{
|
|
|
|
|
gridLength = MainGrid.ColumnDefinitions[2].Width;
|
|
|
|
|
MainGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListViewItem_PreviewMouseLeftButtonDown(Object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MainGrid.ColumnDefinitions[2].Width = gridLength;
|
|
|
|
|
|
|
|
|
|
if (sender is ListViewItem item)
|
|
|
|
|
{
|
|
|
|
|
String? selectedModName = (item.Content as ScrapMod)?.Name;
|
|
|
|
|
if (selectedModName == null)
|
|
|
|
|
throw new KeyNotFoundException(nameof(selectedModName));
|
|
|
|
|
|
|
|
|
|
ScrapMod ? mod = modsLauncher.Mods.Find(mod => mod.Name == selectedModName);
|
|
|
|
|
|
|
|
|
|
if (mod == null)
|
|
|
|
|
throw new KeyNotFoundException(nameof(mod));
|
|
|
|
|
|
|
|
|
|
if (e.ClickCount == 2)
|
|
|
|
|
{
|
|
|
|
|
mod.Checked = !mod.Checked;
|
|
|
|
|
ModsList.Items.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteModInfo(mod);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WriteModInfo(ScrapMod mod)
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Document.Blocks.Clear();
|
|
|
|
|
Paragraph parahraph = new Paragraph();
|
|
|
|
|
|
|
|
|
|
parahraph.Inlines.Add(new Bold(new Run("Description:\n")));
|
|
|
|
|
parahraph.Inlines.Add(new Run(mod.Description));
|
|
|
|
|
|
|
|
|
|
parahraph.Inlines.Add(new Bold(new Run("\n\nAuthors:\n")));
|
|
|
|
|
foreach (String autor in mod.Authors)
|
|
|
|
|
parahraph.Inlines.Add(new Run(autor + "\n"));
|
|
|
|
|
|
|
|
|
|
ModInfo.Document.Blocks.Add(parahraph);
|
|
|
|
|
|
|
|
|
|
ModCreditsTab.Visibility = Visibility.Visible;
|
|
|
|
|
if (mod.Credits.Count == 0)
|
|
|
|
|
ModCreditsTab.Visibility = Visibility.Hidden;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ModCredits.Document.Blocks.Clear();
|
|
|
|
|
parahraph = new Paragraph();
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<String, List<String>> credit in mod.Credits)
|
|
|
|
|
{
|
|
|
|
|
parahraph.Inlines.Add(new Bold(new Run(credit.Key + "\n")));
|
|
|
|
|
foreach (String autor in credit.Value)
|
|
|
|
|
parahraph.Inlines.Add(new Run(autor + "\n"));
|
|
|
|
|
parahraph.Inlines.Add(new Run("\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModCredits.Document.Blocks.Add(parahraph);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckBox_Checked(Object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CheckBox checkbox = (CheckBox)sender;
|
|
|
|
|
Boolean? isChecked = checkbox.IsChecked;
|
|
|
|
|
|
|
|
|
|
if (isChecked == null)
|
|
|
|
|
throw new NullReferenceException(nameof(isChecked));
|
|
|
|
|
|
|
|
|
|
StackPanel parent = (StackPanel)checkbox.Parent;
|
|
|
|
|
Label label = (Label)parent.Children[2];
|
|
|
|
|
String? selectedModName = label.Content.ToString();
|
|
|
|
|
|
|
|
|
|
if (selectedModName == null)
|
|
|
|
|
throw new KeyNotFoundException(nameof(selectedModName));
|
|
|
|
|
|
|
|
|
|
ScrapMod? mod = modsLauncher.Mods.Find(mod => mod.Name == selectedModName);
|
|
|
|
|
|
|
|
|
|
if (mod == null)
|
|
|
|
|
throw new KeyNotFoundException(nameof(selectedModName));
|
|
|
|
|
|
|
|
|
|
mod.Checked = (Boolean)isChecked;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-06 09:38:13 +00:00
|
|
|
|
private void ButtonSettings_Click(Object sender, RoutedEventArgs e)
|
2022-02-06 03:29:03 +00:00
|
|
|
|
{
|
2022-02-06 09:38:13 +00:00
|
|
|
|
SettingsWindow settingsWindow = new SettingsWindow();
|
2022-02-06 03:29:03 +00:00
|
|
|
|
settingsWindow.ShowDialog();
|
|
|
|
|
if (settingsWindow.Save)
|
|
|
|
|
modsLauncher.ScanMods();
|
|
|
|
|
ModsList.Items.Refresh();
|
|
|
|
|
}
|
2022-02-06 10:20:32 +00:00
|
|
|
|
|
|
|
|
|
private void ButtonRunScrapland_Click(Object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
String executablePath = ScraplandVersion.SelectedIndex == 0
|
|
|
|
|
? modsLauncher.ScraplandPath : modsLauncher.ScraplandRemasteredPath;
|
|
|
|
|
|
|
|
|
|
String args = "-fullscreen:1";
|
|
|
|
|
if (Windowed.IsChecked ?? false)
|
|
|
|
|
args = "-fullscreen:0";
|
|
|
|
|
|
|
|
|
|
Process.Start(executablePath + @"\bin\Scrap.exe", args);
|
|
|
|
|
|
|
|
|
|
if (CloseLauncher.IsChecked ?? false)
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2022-01-19 13:06:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|