void RefreshList() { if (Dispatcher.Thread != Thread.CurrentThread) { this.Invoke(RefreshList); return; } var loadingDialog = new LoadingDialog { Text = "Getting Mission List", Owner = MainWindow.Instance }; Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); var list = client.ListMissionInfos(); this.Invoke(delegate { DataGrid.ItemsSource = showHiddenMissionsBox.IsChecked == true ? list : list.Where(m => !m.IsDeleted); loadingDialog.Close(); }); } catch (Exception e) { MessageBox.Show("Could not get mission list: " + e.Message); } }); loadingDialog.ShowDialog(); }
public static void LoadExistingMission(string fileName) { var loadingDialog = new LoadingDialog { Owner = MainWindow.Instance }; loadingDialog.Loaded += (s, e) => Utils.InvokeInNewThread(delegate { var mission = Mission.FromFile(fileName); loadingDialog.Text = "Scanning"; using (var unitSync = new UnitSync(Settings.Default.SpringPath)) { unitSync.LoadingStatusChanged += (se, ea) => loadingDialog.Text = ea.Data; loadingDialog.Text = "Loading Map"; mission.Map = LoadMap(unitSync, mission.MapName); loadingDialog.Text = "Loading Mod"; mission.Mod = LoadMod(unitSync, mission.ModName); } loadingDialog.Text = "Finalizing"; mission.PostLoad(); Settings.Default.MissionPath = fileName; Settings.Default.Save(); loadingDialog.Invoke(delegate { loadingDialog.Close(); MainWindow.Instance.SavePath = fileName; MainWindow.Instance.Mission = mission; }); }); loadingDialog.ShowDialog(); }
public static void PromptForNewMission() { var dialog = new NewMissionDialog { Owner = MainWindow.Instance }; dialog.ProgressBar.Visibility = Visibility.Visible; Utils.InvokeInNewThread(delegate { IEnumerable <string> modNames; IEnumerable <string> mapNames; using (var unitSync = new UnitSync(Settings.Default.SpringPath)) { modNames = unitSync.GetModNames(); mapNames = unitSync.GetMapNames(); } dialog.Invoke(delegate { dialog.MapList.ItemsSource = mapNames; dialog.ModList.ItemsSource = modNames; dialog.ProgressBar.Visibility = Visibility.Hidden; }); }); if (dialog.ShowDialog() == true) { MainWindow.Instance.SavePath = null; var mapName = (string)dialog.MapList.SelectedItem; var gameName = (string)dialog.ModList.SelectedItem; var missionName = dialog.NameBox.Text; var loadingDialog = new LoadingDialog { Owner = MainWindow.Instance }; loadingDialog.Loaded += delegate { Utils.InvokeInNewThread(delegate { Mission mission; loadingDialog.Text = "Scanning"; using (var unitSync = new UnitSync(Settings.Default.SpringPath)) { unitSync.LoadingStatusChanged += (s, e) => loadingDialog.Text = e.Data; loadingDialog.Text = "Loading Map"; var map = LoadMap(unitSync, mapName); loadingDialog.Text = "Loading Mod"; var mod = LoadMod(unitSync, gameName); mission = new Mission(missionName, mod, map); } dialog.Invoke(delegate { MainWindow.Instance.Mission = mission; loadingDialog.Close(); }); }); }; loadingDialog.ShowDialog(); } }
#pragma warning restore 612,618 void OpenButton_Click(object sender, RoutedEventArgs e) { var loadingDialog = new LoadingDialog { Text = "Opening Mission", Owner = this }; var selectedMission = (Mission)DataGrid.SelectedItem; if (selectedMission == null) { return; } Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); var missionData = client.GetMission(selectedMission.Name); loadingDialog.Invoke(delegate { loadingDialog.Close(); var filter = "Spring Mod Archive (*.sdz)|*.sdz|All files (*.*)|*.*"; var saveFileDialog = new SaveFileDialog { DefaultExt = "sdz", Filter = filter, RestoreDirectory = true }; if (saveFileDialog.ShowDialog() == true) { File.WriteAllBytes(saveFileDialog.FileName, missionData.Mutator.ToArray()); } WelcomeDialog.LoadExistingMission(saveFileDialog.FileName); }); } catch (FaultException <ExceptionDetail> ex) { MessageBox.Show(ex.Message); } }); loadingDialog.ShowDialog(); }
#pragma warning restore 612,618 void OpenButton_Click(object sender, RoutedEventArgs e) { var loadingDialog = new LoadingDialog { Text = "Opening Mission", Owner = this }; var selectedMission = (Mission)DataGrid.SelectedItem; if (selectedMission == null) return; Utils.InvokeInNewThread(delegate { try { var client = MissionServiceClientFactory.MakeClient(); var missionData = client.GetMission(selectedMission.Name); loadingDialog.Invoke(delegate { loadingDialog.Close(); var filter = "Spring Mod Archive (*.sdz)|*.sdz|All files (*.*)|*.*"; var saveFileDialog = new SaveFileDialog { DefaultExt = "sdz", Filter = filter, RestoreDirectory = true }; if (saveFileDialog.ShowDialog() == true) File.WriteAllBytes(saveFileDialog.FileName, missionData.Mutator.ToArray()); WelcomeDialog.LoadExistingMission(saveFileDialog.FileName); }); } catch (FaultException<ExceptionDetail> ex) { MessageBox.Show(ex.Message); } }); loadingDialog.ShowDialog(); }