コード例 #1
0
        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();
        }
コード例 #2
0
		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();
		}
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        public static void SendMissionWithDialog(Mission mission, string password, int?missionId)
        {
            var loading = new LoadingDialog {
                Text = "Uploading Mission", Owner = MainWindow.Instance
            };

            loading.Loaded += delegate
            {
                Utils.InvokeInNewThread(delegate
                {
                    SendMission(mission, password, missionId);
                    loading.Invoke(loading.Close);
                });
            };
            loading.ShowDialog();
        }
コード例 #6
0
#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();
        }
コード例 #7
0
#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();
		}
コード例 #8
0
		void BuildMission(bool hideFromModList = false)
		{
			var filter = "Spring Mod Archive (*.sdz)|*.sdz|All files (*.*)|*.*";
			var saveFileDialog = new SaveFileDialog { DefaultExt = "sdz", Filter = filter, RestoreDirectory = true };
			if (saveFileDialog.ShowDialog() == true)
			{
				var loadingDialog = new LoadingDialog { Owner =this };
				loadingDialog.Text = "Building Mission";
				loadingDialog.Loaded += delegate
					{
						var mission = Mission;
						var fileName = saveFileDialog.FileName;
						Utils.InvokeInNewThread(delegate
							{
								mission.CreateArchive(fileName, hideFromModList);
								var scriptPath = String.Format("{0}\\{1}.txt", Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName));
								File.WriteAllText(scriptPath, mission.GetScript());
								this.Invoke(loadingDialog.Close);
							});
					};
				loadingDialog.ShowDialog();
			}
		}
コード例 #9
0
		public static void SendMissionWithDialog(Mission mission, string password, int? missionId)
		{
			var loading = new LoadingDialog { Text = "Uploading Mission", Owner = MainWindow.Instance };
			loading.Loaded += delegate
				{
					Utils.InvokeInNewThread(delegate
						{
							SendMission(mission, password, missionId);
							loading.Invoke(loading.Close);
						});
				};
			loading.ShowDialog();
		}
コード例 #10
0
		void BuildMission(bool hideFromModList = false, bool sdd = false)
		{
			var filter = "Spring Mod Archive (*.sdz)|*.sdz|All files (*.*)|*.*";
			if (sdd) filter = "Temporary Archive (auto-extracts to .sdd) (*.zip)|*.zip|All files (*.*)|*.*";
			var saveFileDialog = new System.Windows.Forms.SaveFileDialog { DefaultExt = sdd ? "zip" : "sdz", Filter = filter, RestoreDirectory = true };
			if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				var fileName = saveFileDialog.FileName;
				if (sdd && Directory.Exists(Path.ChangeExtension(fileName, "sdd")))
				{
					System.Windows.Forms.DialogResult confirmOverwrite = System.Windows.Forms.MessageBox.Show("The .sdd already exists in the selected directory.\nIt will be deleted and replaced.\nContinue?",
						"sdd already exists",
						System.Windows.Forms.MessageBoxButtons.YesNo);
					if (confirmOverwrite != System.Windows.Forms.DialogResult.Yes) return;
				}
				var loadingDialog = new LoadingDialog { Owner = this };
				loadingDialog.Text = "Building Mission";
				loadingDialog.Loaded += delegate
					{
						var mission = Mission;
						
						//if (sdd) fileName = Path.ChangeExtension(fileName, "zip"); // this is the temporary zip, leave the .sdd path for the actual .sdd
						Utils.InvokeInNewThread(delegate
							{
								mission.CreateArchive(fileName, hideFromModList, sdd);
								if (!sdd) {
									var scriptPath = String.Format("{0}\\{1}.txt", Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName));
									var scriptPathLua = String.Format("{0}\\{1}.lua", Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName));
									File.WriteAllText(scriptPath, mission.GetScript());
									File.WriteAllText(scriptPathLua, "return " + mission.GetLuaStartscript());
								}
								this.Invoke(loadingDialog.Close);
							});
					};
				loadingDialog.ShowDialog();
			}
		}