public ModProjectViewModel(ModProject project) { Project = project; if (Project.Name == null) { Project.Name = new MultilingualValue(); } Project.Name.OnChange += NameChanged; Project.Description.OnChange += NameChanged; foreach (var langCode in Project.Languages) { AddLanguageButton(langCode); /*<Button Style="{StaticResource NormalButton}"> * <StackPanel Orientation="Horizontal" Margin="-10,-17,-10,-16"> * <TextBlock Text="Englisch" VerticalAlignment="Center" Margin="10,0,10,0" /> * <Image Source="/resources/textures/Icons/Icon_Delete.png" Height="20" Margin="0,0,5,0" /> * </StackPanel> * </Button>*/ } foreach (var button in project.Buttons) { var _button = new ModProjectButton { DataContext = new ModProjectButtonViewModel(this, button) }; _Buttons.Add(_button); } CheckForErrors(); }
/// <summary> /// Build a mod file at the given path from the current <see cref="Project"/>. /// </summary> /// <param name="p_strPath">The file path at which to build the mod.</param> protected void BuildMod(string p_strPath) { if (!Validate()) { return; } if ((Warnings.Count > 0) && !GetIgnoreWarnings()) { return; } //save project string strProjectPath = ModProject.FilePath; if (String.IsNullOrEmpty(strProjectPath)) { strProjectPath = GetProjectSavePath(); } if (String.IsNullOrEmpty(strProjectPath)) { return; } ModProject.Save(strProjectPath); if (String.IsNullOrEmpty(p_strPath)) { p_strPath = GetNewModSavePath(); } if (!String.IsNullOrEmpty(p_strPath)) { ModBuilder.PackageMod(p_strPath, ModProject); ModPackingStarted(this, new EventArgs <IBackgroundTask>(ModBuilder)); } }
public void Remove(ModProject project) { for (int i = 0; i < _Projects.Count; i++) { ModProjectViewModel vm = (ModProjectViewModel)(_Projects[i].DataContext); if (vm.Project == project) { _Projects.RemoveAt(i); break; } } ModProjects.Remove(project); project.Remove(); }
/// <summary> /// Saves the mod packaging <see cref="Project"/> to the given path. /// </summary> /// <param name="p_strPath">The file path to which to save the <see cref="Project"/>.</param> protected void SaveProject(string p_strPath) { if (String.IsNullOrEmpty(p_strPath)) { p_strPath = ModProject.FilePath; } if (String.IsNullOrEmpty(p_strPath)) { p_strPath = GetProjectSavePath(); } if (!String.IsNullOrEmpty(p_strPath)) { ModProject.Save(p_strPath); } }
protected void FindProjects() { try { string path = System.IO.Path.GetFullPath(Configuration.GetPath("projects") + System.IO.Path.DirectorySeparatorChar + App.Game.GameConfiguration.ID); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string[] files = System.IO.Directory.GetDirectories(path); foreach (string file in files) { System.IO.FileAttributes attr = System.IO.File.GetAttributes(@file); if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { string id = System.IO.Path.GetFileName(file); bool add = true; foreach (ModProject project in ModProjects) { if (project.ID == id) { add = false; break; } } if (add && ModAPI.Data.Mod.Header.VerifyModID(id)) { ModProjects.Add(new ModProject(App.Game, id)); } } } /** Add new projects **/ foreach (ModProject project in ModProjects) { bool add = true; foreach (ListViewItem item in _Projects) { if (((ModProjectViewModel)item.DataContext).Project == project) { add = false; break; } } if (add) { ListViewItem newItem = new ListViewItem(); newItem.DataContext = new ModProjectViewModel(project); Grid panel = new Grid(); Image image = new Image(); image.Height = 20; BitmapImage source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri("pack://application:,,,/ModAPI;component/resources/textures/Icons/Icon_Warning.png"); source.EndInit(); image.Source = source; image.HorizontalAlignment = HorizontalAlignment.Right; //image.Margin = new Thickness(0, 0, 5, 0); image.SetBinding(Image.VisibilityProperty, "Error"); Image image2 = new Image(); image2.Height = 20; BitmapImage source2 = new BitmapImage(); source2.BeginInit(); source2.UriSource = new Uri("pack://application:,,,/ModAPI;component/resources/textures/Icons/Icon_Error.png"); source2.EndInit(); image2.Source = source2; image2.HorizontalAlignment = HorizontalAlignment.Right; image.Margin = new Thickness(5, 0, 0, 0); image2.SetBinding(Image.VisibilityProperty, "SaveError"); TextBlock label = new TextBlock(); label.SetBinding(TextBlock.TextProperty, "ID"); panel.Children.Add(label); panel.Children.Add(image); panel.Children.Add(image2); newItem.Content = panel; _Projects.Add(newItem); } } for (int i = 0; i < ModProjects.Count; i++) { ModProject p = ModProjects[i]; string checkPath = Configuration.GetPath("projects") + System.IO.Path.DirectorySeparatorChar + App.Game.GameConfiguration.ID + System.IO.Path.DirectorySeparatorChar + p.ID; if (!System.IO.Directory.Exists(checkPath)) { ModProjects.RemoveAt(i); i--; } } /** Remove deleted projects **/ for (int i = 0; i < _Projects.Count; i++) { ListViewItem item = _Projects[i]; ModProject check = ((ModProjectViewModel)item.DataContext).Project; if (!ModProjects.Contains(check)) { _Projects.RemoveAt(i); i--; } } } catch (Exception e) { Debug.Log("F", e.ToString()); } }