This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MapView.xaml.cs
171 lines (161 loc) · 6.07 KB
/
MapView.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;
namespace Phonon
{
/// <summary>
/// Interaction logic for MapView.xaml
/// </summary>
public partial class MapView : UserControl
{
Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> MapInfoDict;
string PkgName = "";
private MainWindow mainWindow = null; // Reference to the MainWindow
public MapView()
{
InitializeComponent();
ReadMapListData();
}
private void OnControlLoaded(object sender, RoutedEventArgs e)
{
mainWindow = Window.GetWindow(this) as MainWindow;
ShowPkgList();
}
private void ReadMapListData()
{
MapInfoDict = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>>>(File.ReadAllText("D1MapInfo.json"));
}
private void ShowMapList(string PkgName)
{
this.PkgName = PkgName;
var Info = MapInfoDict[PkgName];
MapsList.Children.Clear();
List<string> MapNames = Info.Keys.ToList<string>();
MapNames.Sort();
Style style = Application.Current.Resources["Button_Command"] as Style;
foreach (string MapName in MapNames)
{
// We want to verify that this pkg has at least 1 dynamic model in it.
ToggleButton btn = new ToggleButton();
btn.Focusable = true;
btn.Focus();
btn.Content = new TextBlock
{
Text = MapName,
TextWrapping = TextWrapping.Wrap,
FontSize = 13,
};
btn.Style = style;
btn.Height = 50;
btn.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(61, 61, 61));
btn.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(230, 230, 230));
MapsList.Children.Add(btn);
}
ScrollView2.ScrollToTop();
}
private void PkgButton_Click(object sender, RoutedEventArgs e)
{
string ClickedPackageName = (((sender as ToggleButton).Content) as TextBlock).Text;
foreach (ToggleButton button in PrimaryList.Children)
{
button.IsChecked = false;
}
(sender as ToggleButton).IsChecked = true;
ShowMapList(ClickedPackageName);
}
public string GetPackagesPath()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
if (config.AppSettings.Settings["PackagesPathD1"] == null)
{
System.Windows.MessageBox.Show($"No package path found for Destiny 1.");
return "";
}
return config.AppSettings.Settings["PackagesPathD1"].Value.ToString();
}
private void ExtractSelectedMapsButton_Click(object sender, RoutedEventArgs e)
{
// Get static hashes
List<string> MapNames = new List<string>();
foreach (ToggleButton button in MapsList.Children)
{
if (button.IsChecked == true)
{
MapNames.Add(((button.Content) as TextBlock).Text);
}
button.IsChecked = false;
}
if (MapNames.Count == 0)
{
System.Windows.MessageBox.Show("No maps selected");
return;
}
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if (dialog.SelectedPath == "")
{
return;
}
mainWindow.ExportSettings.Path = dialog.SelectedPath;
}
string PkgsPath = GetPackagesPath();
if (PkgsPath == "")
{
return;
}
bool status = mainWindow.ExportSettings.ExportD1Map(PkgsPath, MapNames, MapInfoDict[PkgName]);
if (status)
{
System.Windows.MessageBox.Show("Export success");
}
else
{
System.Windows.MessageBox.Show("Export failed");
}
}
private void ShowPkgList()
{
MapsList.Children.Clear();
PrimaryList.Children.Clear();
List<string> PackageNames = MapInfoDict.Keys.ToList<string>();
PackageNames.Sort();
Style style = Application.Current.Resources["Button_Command"] as Style;
foreach (string PkgName in PackageNames)
{
// We want to verify that this pkg has at least 1 dynamic model in it.
ToggleButton btn = new ToggleButton();
btn.Focusable = true;
btn.Focus();
btn.Content = new TextBlock
{
Text = PkgName,
TextWrapping = TextWrapping.Wrap,
FontSize = 13,
}; ;
btn.Style = style;
btn.Height = 50;
btn.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(61, 61, 61));
btn.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(230, 230, 230));
btn.Click += PkgButton_Click;
PrimaryList.Children.Add(btn);
}
ScrollView.ScrollToTop();
}
}
}