Skip to content

Commit abdfa7b

Browse files
committed
New UI
1 parent be06c7f commit abdfa7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2090
-647
lines changed

App.xaml

Lines changed: 358 additions & 3 deletions
Large diffs are not rendered by default.

Controls/MyItemsControl.xaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<UserControl x:Class="ModShardLauncher.Controls.MyItemsControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:ModShardLauncher.Controls"
7+
xmlns:system="clr-namespace:System;assembly=mscorlib"
8+
xmlns:mod="clr-namespace:ModShardLauncher.Mods"
9+
xmlns:main="clr-namespace:ModShardLauncher"
10+
mc:Ignorable="d"
11+
d:DesignHeight="450" d:DesignWidth="800">
12+
<UserControl.Resources>
13+
14+
</UserControl.Resources>
15+
<ItemsControl Name="Viewer"
16+
Style="{DynamicResource MyStyle}"
17+
ScrollViewer.VerticalScrollBarVisibility="Visible"
18+
ScrollViewer.CanContentScroll="False"
19+
Background="#1B1926"
20+
ItemTemplateSelector="{StaticResource selector}"
21+
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource AncestorType=local:MyItemsControl, Mode=FindAncestor}}">
22+
<ItemsControl.Resources>
23+
</ItemsControl.Resources>
24+
</ItemsControl>
25+
</UserControl>

Controls/MyItemsControl.xaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using ModShardLauncher.Mods;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
17+
namespace ModShardLauncher.Controls
18+
{
19+
/// <summary>
20+
/// MyScrollViewer.xaml 的交互逻辑
21+
/// </summary>
22+
public partial class MyItemsControl : UserControl
23+
{
24+
public MyItemsControl()
25+
{
26+
InitializeComponent();
27+
}
28+
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
29+
"ItemsSource",
30+
typeof(object),
31+
typeof(MyItemsControl),
32+
new PropertyMetadata(default(object), OnItemsPropertyChanged));
33+
private static void OnItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
34+
{
35+
}
36+
public List<object> ItemsSource { get; set; }
37+
}
38+
public class TempSelector : DataTemplateSelector
39+
{
40+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
41+
{
42+
if (item is ModFile)
43+
return Application.Current.FindResource("mod") as DataTemplate;
44+
else return Application.Current.FindResource("source") as DataTemplate;
45+
}
46+
}
47+
}

Controls/MyToggleButton.xaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:local="clr-namespace:ModShardLauncher.Controls"
77
mc:Ignorable="d"
88
d:DesignHeight="450" d:DesignWidth="800">
9-
<Grid Height="40" Background="#1B1926" Name="MyGrid">
9+
<Grid Height="60" Background="#1B1926" Name="MyGrid">
1010
<Grid.Triggers>
1111
<EventTrigger RoutedEvent="ToggleButton.Checked">
1212
<BeginStoryboard>
@@ -33,15 +33,18 @@
3333
</BeginStoryboard>
3434
</EventTrigger>
3535
</Grid.Triggers>
36-
<TextBlock Grid.Row="1" Grid.Column="0" Margin="72,0,0,0"
36+
<TextBlock Grid.Row="1" Grid.Column="0" Margin="64,4,0,0"
3737
Text="{Binding Path=Text, RelativeSource={RelativeSource AncestorType=local:MyToggleButton}}"
38-
Foreground="White" FontSize="22" Background="Transparent"
39-
HorizontalAlignment="Left" VerticalAlignment="Center">
38+
Foreground="White" FontSize="18" Background="Transparent"
39+
HorizontalAlignment="Left" VerticalAlignment="Center"
40+
Style="{StaticResource sFont}">
4041
</TextBlock>
4142
<ToggleButton x:Name="MyButton" Grid.Column="0" VerticalAlignment="Center"
42-
HorizontalAlignment="Left" Margin="16,0,0,0"
43-
Height="32" Width="32" BorderThickness="0"
44-
Checked="MyButton_Checked">
43+
HorizontalAlignment="Left" Margin="8,0,0,0"
44+
Height="48" Width="48" BorderThickness="0"
45+
RenderOptions.BitmapScalingMode="NearestNeighbor"
46+
Checked="MyButton_Checked"
47+
Click="MyButton_Click">
4548
<ToggleButton.Style>
4649
<Style TargetType="{x:Type ToggleButton}">
4750
<Setter Property="Template">

Controls/MyToggleButton.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,26 @@ public MyToggleButton()
2626
InitializeComponent();
2727
}
2828
public ImageSource ImageSource { get; set; }
29+
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
30+
"Text",
31+
typeof(string),
32+
typeof(MyToggleButton),
33+
new PropertyMetadata(default(string), OnTextChanged));
34+
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
35+
{
36+
}
2937
public string Text { get; set; }
3038
[Category("Behavior")]
3139
public event EventHandler Checked;
40+
public event EventHandler Click;
3241
private void MyButton_Checked(object sender, RoutedEventArgs e)
3342
{
3443
if(Checked != null) Checked.Invoke(this, e);
3544
}
45+
46+
private void MyButton_Click(object sender, RoutedEventArgs e)
47+
{
48+
if (Click != null) Click.Invoke(this, e);
49+
}
3650
}
3751
}

DataLoader.cs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public static string GetVersion()
4848
}
4949
public static async Task<bool> DoOpenDialog()
5050
{
51+
if(Main.Settings.LoadPos != "")
52+
{
53+
await LoadFile(Main.Settings.LoadPos);
54+
return true;
55+
}
5156
OpenFileDialog dlg = new OpenFileDialog();
5257

5358
dlg.DefaultExt = "win";
@@ -62,8 +67,8 @@ public static async Task<bool> DoOpenDialog()
6267
}
6368
public static async Task LoadFile(string filename, bool re = false)
6469
{
65-
LoadingDialog loader = new LoadingDialog(re ? "重新加载中" :"加载中", "加载中 请稍候...");
66-
loader.PreventClose = true;
70+
LoadingDialog dialog = new LoadingDialog();
71+
dialog.Owner = Main.Instance;
6772
DataPath = filename;
6873
Task t = Task.Run(() =>
6974
{
@@ -94,18 +99,32 @@ public static async Task LoadFile(string filename, bool re = false)
9499
throw e;
95100
//this.ShowError("An error occured while trying to load:\n" + e.Message, "Load error");
96101
}
97-
MainWindow.Instance.Dispatcher.Invoke(async () =>
102+
Main.Instance.Dispatcher.Invoke(async () =>
98103
{
99-
loader.Hide();
104+
dialog.Hide();
100105
});
101106
});
102107

103-
loader.ShowDialog();
108+
dialog.ShowDialog();
104109
await t;
105110
ModLoader.Initalize();
111+
if(Main.Settings.LoadPos == "")
112+
{
113+
var result = MessageBox.Show(Application.Current.FindResource("LoadPath").ToString(),
114+
Application.Current.FindResource("LoadPath").ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question);
115+
if(result == MessageBoxResult.Yes)
116+
{
117+
Main.Settings.LoadPos = filename;
118+
}
119+
}
106120
}
107121
public static async Task<bool> DoSaveDialog()
108122
{
123+
if (Main.Settings.SavePos != "")
124+
{
125+
await SaveFile(Main.Settings.SavePos);
126+
return true;
127+
}
109128
SaveFileDialog dlg = new SaveFileDialog();
110129
dlg.DefaultExt = "win";
111130
dlg.Filter = "Game Maker Studio data files (.win, .unx, .ios, .droid, audiogroup*.dat)|*.win;*.unx;*.ios;*.droid;audiogroup*.dat|All files|*";
@@ -120,10 +139,8 @@ public static async Task<bool> DoSaveDialog()
120139
}
121140
public static async Task SaveFile(string filename)
122141
{
123-
LoadingDialog dialog = new LoadingDialog("保存中", "保存中 请稍候...");
124-
dialog.PreventClose = true;
125-
IProgress<Tuple<int, string>> progress = new Progress<Tuple<int, string>>(i => { dialog.ReportProgress(i.Item2, i.Item1); });
126-
IProgress<double?> setMax = new Progress<double?>(i => { dialog.Maximum = i; });
142+
LoadingDialog dialog = new LoadingDialog();
143+
dialog.Owner = Main.Instance;
127144
Task t = Task.Run(async () =>
128145
{
129146
bool SaveSucceeded = true;
@@ -156,7 +173,7 @@ public static async Task SaveFile(string filename)
156173
}
157174
catch { }
158175
}
159-
MainWindow.Instance.Dispatcher.Invoke(() =>
176+
Main.Instance.Dispatcher.Invoke(() =>
160177
{
161178
ShowError("An error occured while trying to save:\n" + e.Message, "Save error");
162179
});
@@ -178,21 +195,30 @@ public static async Task SaveFile(string filename)
178195
}
179196
catch (Exception exc)
180197
{
181-
MainWindow.Instance.Dispatcher.Invoke(() =>
198+
Main.Instance.Dispatcher.Invoke(() =>
182199
{
183200
ShowError("An error occured while trying to save:\n" + exc.Message, "Save error");
184201
});
185202

186203
SaveSucceeded = false;
187204
}
188-
MainWindow.Instance.Dispatcher.Invoke(() =>
205+
Main.Instance.Dispatcher.Invoke(() =>
189206
{
190207
dialog.Hide();
191208
});
192209
});
193210
dialog.ShowDialog();
194211
await t;
195212
ModLoader.LoadFiles();
213+
if (Main.Settings.SavePos == "")
214+
{
215+
var result = MessageBox.Show(Application.Current.FindResource("SavePath").ToString(),
216+
Application.Current.FindResource("SavePath").ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question);
217+
if (result == MessageBoxResult.Yes)
218+
{
219+
Main.Settings.SavePos = filename;
220+
}
221+
}
196222
}
197223
}
198224
}

FilePacker.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public static void Pack(string path)
5151
Write(fs, tex);
5252
foreach (var scr in scripts)
5353
Write(fs, scr);
54-
CompileMod(dir.Name, path, out var code, out _);
54+
var successful = CompileMod(dir.Name, path, out var code, out _, fs);
55+
if (!successful) return;
5556
Write(fs, code.Length);
5657
Write(fs, code);
5758
fs.Close();
@@ -110,6 +111,7 @@ public static Diagnostic[] RoslynCompile(string name, string[] files, string[] p
110111
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
111112
MetadataReference.CreateFromFile(refPath("System.Collections.dll")),//System.Core.dll
112113
MetadataReference.CreateFromFile(refPath("ModShardLauncher.dll")),
114+
MetadataReference.CreateFromFile(refPath("UndertaleModLib.dll")),
113115
MetadataReference.CreateFromFile(refPath("System.Runtime.dll")),
114116
MetadataReference.CreateFromFile(refPath("netstandard.dll"))
115117
};
@@ -126,11 +128,25 @@ public static Diagnostic[] RoslynCompile(string name, string[] files, string[] p
126128

127129
return results.Diagnostics.Where(d => d.Severity >= DiagnosticSeverity.Warning).ToArray();
128130
}
129-
public static void CompileMod(string name, string path, out byte[] code, out byte[] pdb)
131+
public static bool CompileMod(string name, string path, out byte[] code, out byte[] pdb, FileStream fs)
130132
{
131133
var files = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories).Where(file => !IgnoreCompletely(name, file)).ToArray();
132134
var preprocessorSymbols = new List<string>() { "FNA" };
133135
var result = RoslynCompile(name, files, preprocessorSymbols.ToArray(), out code, out pdb);
136+
137+
var WarningsCount = result.Count(e => e.Severity == DiagnosticSeverity.Warning);
138+
var ErrorsCount = result.Length - WarningsCount;
139+
140+
if(ErrorsCount > 0)
141+
{
142+
var firstError = result.First(e => e.Severity == DiagnosticSeverity.Error);
143+
fs.Close();
144+
File.Delete(fs.Name);
145+
MessageBox.Show(Application.Current.FindResource("CompileError").ToString() +
146+
"\n" + name + " : " + firstError);
147+
return false;
148+
}
149+
return true;
134150
}
135151
public static bool IgnoreCompletely(string name, string file)
136152
{

FileReader.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace ModShardLauncher
1515
{
16-
public class FileChunk
16+
public class FileChunk
1717
{
1818
public string name;
1919
public int offset;
@@ -41,6 +41,7 @@ public class ModFile
4141
public Mod instance { get; set; }
4242
public bool isEnabled { get; set; }
4343
public bool isExisted => File.Exists(Path);
44+
public byte[] Icon { get; set; } = new byte[0];
4445
public override string ToString()
4546
{
4647
return instance.ToString();
@@ -54,7 +55,8 @@ public byte[] GetFile(string name)
5455
return new byte[0];
5556
}
5657
var file = Files.FirstOrDefault(t => t.name == name);
57-
if(file != default)
58+
if(file == default) file = Files.FirstOrDefault(t => t.name.Split("\\").Last() == name);
59+
if (file != default)
5860
{
5961
if(!Stream.CanRead) Stream = new FileStream(Path, FileMode.Open);
6062
Stream.Position = FileOffset;
@@ -63,6 +65,10 @@ public byte[] GetFile(string name)
6365
}
6466
else return new byte[0];
6567
}
68+
public bool FileExist(string name)
69+
{
70+
return GetFile(name).Length > 0;
71+
}
6672
}
6773
public class FileReader
6874
{
@@ -109,12 +115,19 @@ public static ModFile Read(string path)
109115
count = BitConverter.ToInt32(Read(fs, 4), 0);
110116
file.Assembly = Assembly.Load(Read(fs, count));
111117
file.Path = path;
118+
if (file.FileExist(file.Name + "\\icon.png"))
119+
file.Icon = file.GetFile(file.Name + "\\icon.png");
112120
fs.Close();
113121
return file;
114122
}
115123
public static byte[] Read(FileStream fs, int length, int offset = 0)
116124
{
117125
byte[] bytes = new byte[length];
126+
if(fs.Length - fs.Position < length)
127+
{
128+
fs.Close();
129+
throw new Exception("Mod File Error: " + fs.Name.Split("\\").Last());
130+
}
118131
fs.Read(bytes, 0, length);
119132
return bytes;
120133
}

Language/en-us.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:sys="clr-namespace:System;assembly=mscorlib">
4+
<sys:String x:Key="ToolDescription">A tool for StoneShard modding.</sys:String>
5+
<sys:String x:Key="ToolStart">Start your first mod from here.</sys:String>
46
<sys:String x:Key="FileHeader">File</sys:String>
57
<sys:String x:Key="SettingHeader">Settings</sys:String>
68
<sys:String x:Key="FileHeader_Open">Open</sys:String>
@@ -9,6 +11,8 @@
911
<sys:String x:Key="PatchButtonText">Patch</sys:String>
1012
<sys:String x:Key="SearchBoxText">Search by mod's name...</sys:String>
1113
<sys:String x:Key="Welcome">Welcome!</sys:String>
14+
<sys:String x:Key="Enable">Enable</sys:String>
15+
<sys:String x:Key="Disable">Disable</sys:String>
1216
<sys:String x:Key="Welcome_Use">Welcome to use ModShardLauncher!</sys:String>
1317
<sys:String x:Key="Welcome_Desc" xml:space="preserve">if you want to refresh mods, just paste them into the /Mods path and click the refresh button on the left
1418
First, click File button and open a original data file then select Mods you want to enable.
@@ -24,4 +28,15 @@
2428
<sys:String x:Key="VersionDifferentWarningTitle">Mod version is different from game version</sys:String>
2529
<sys:String x:Key="VersionDifferentWarning">Mod version is different from game version, maybe it will crash if you load it.Still want to load?</sys:String>
2630
<sys:String x:Key="ModLostWarning">Mod file lost.</sys:String>
31+
<sys:String x:Key="CompileError">Compile Error:</sys:String>
32+
<sys:String x:Key="LoadPath">Save this path as default LoadPath?</sys:String>
33+
<sys:String x:Key="SavePath">Save this path as default SavePath?</sys:String>
34+
<sys:String x:Key="GeneralSettings">General</sys:String>
35+
<sys:String x:Key="Mod">Mods</sys:String>
36+
<sys:String x:Key="ModSource">ModSources</sys:String>
37+
<sys:String x:Key="Settings">Settings</sys:String>
38+
<sys:String x:Key="Menu">Menu</sys:String>
39+
<sys:String x:Key="Close">Close</sys:String>
40+
<sys:String x:Key="Minimize">Minimize</sys:String>
41+
<sys:String x:Key="Loading">Loading...</sys:String>
2742
</ResourceDictionary>

0 commit comments

Comments
 (0)