private void ExecuteExportAn8Command() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetSaveAn8FileName(System.IO.Path.ChangeExtension(this.OptModel.File.FileName, "an8")); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Exporting ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; bool scale = this.IsImportExportScaleEnabled; try { OptAn8Converter.Converter.OptToAn8(opt, fileName, scale); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } }); }
private void ExecuteReplaceAlphaMapCommand(Texture texture) { if (texture == null) { return; } BusyIndicatorService.Run(dispatcher => { string name = texture.Name + "_alpha"; string fileName = FileDialogService.GetOpenTextureFileName(name); if (fileName == null) { return; } try { this.OptModel.File.Textures[texture.Name].SetAlphaMap(fileName); dispatcher(() => this.OptModel.File = this.OptModel.File); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(name, ex)); } }); }
private void ExecuteScaleCommand() { BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; var size = opt.SpanSize.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor); var message = Messenger.Instance.Notify( new ScaleFactorMessage { SizeX = size.X, SizeY = size.Y, SizeZ = size.Z }); if (!message.Changed) { return; } BusyIndicatorService.Notify(string.Concat(message.ScaleType, "...")); opt.Scale(message.ScaleX, message.ScaleY, message.ScaleZ); dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("scale")); }); }
private static BusyIndicatorService CreateBusyIndicatorService(BusyIndicatorHandler handler = null) { var result = new BusyIndicatorService(); result.SetBusyIndicatorHandler(handler != null ? handler.SetVisibility : default(Action <bool>)); return(result); }
private void ExecuteSaveAsCommand(Texture texture) { if (texture == null) { return; } BusyIndicatorService.Run(() => { string fileName = FileDialogService.GetSaveTextureFileName(texture.Name); if (fileName == null) { return; } try { texture.Save(fileName); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(texture.Name, ex)); } }); }
private void ExecuteOpenCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Opening ", System.IO.Path.GetFileName(fileName), "...")); try { dispatcher(() => this.OptModel.File = null); var opt = OptFile.FromFile(fileName); dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("open " + System.IO.Path.GetFileNameWithoutExtension(fileName))); if (!this.OptModel.IsPlayable) { Messenger.Instance.Notify(new MainViewSelectorMessage("PlayabilityMessages")); Messenger.Instance.Notify(new MessageBoxMessage(fileName + "\n\n" + "This opt will not be fully playable.", "Check Opt Playability", MessageBoxButton.OK, MessageBoxImage.Warning)); } } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } }); }
private void ExecuteNewCommand() { BusyIndicatorService.Run(dispatcher => { bool isEmpty = this.OptModel.File == null || (string.IsNullOrEmpty(this.OptModel.File.FileName) && this.OptModel.File.Meshes.Count == 0 && this.OptModel.File.Textures.Count == 0); if (!isEmpty) { var message = Messenger.Instance.Notify(new MessageBoxMessage("Creating a new opt will erase the existing one.\nDo you want to continue?", "New opt", MessageBoxButton.YesNo, MessageBoxImage.Warning)); if (message.Result != MessageBoxResult.Yes) { return; } } dispatcher(() => this.OptModel.File = null); var opt = new OptFile(); dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("new")); }); }
private void ExecuteSaveCommand() { if (this.OptModel.File == null) { return; } if (string.IsNullOrEmpty(this.OptModel.File.FileName)) { this.ExecuteSaveAsCommand(); return; } BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; BusyIndicatorService.Notify(string.Concat("Saving ", System.IO.Path.GetFileName(this.OptModel.File.FileName), "...")); try { opt.Save(opt.FileName); dispatcher(() => this.OptModel.File = this.OptModel.File); dispatcher(() => this.OptModel.UndoStackPush("save " + System.IO.Path.GetFileNameWithoutExtension(opt.FileName))); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(opt.FileName, ex)); } }); }
private void ExecuteDownMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; dispatcher(() => this.CurrentMeshes.ClearSelection()); var orderedMeshes = meshes .Select(mesh => new { Mesh = mesh, Index = opt.Meshes.IndexOf(mesh) }) .OrderByDescending(t => t.Index) .Select(t => t.Mesh) .ToList(); foreach (var mesh in orderedMeshes) { int index = opt.Meshes.IndexOf(mesh); if (index == opt.Meshes.Count - 1) { continue; } opt.Meshes.RemoveAt(index); opt.Meshes.Insert(index + 1, mesh); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(meshes)); }); }
private void ExecuteReplaceMapCommand(Texture texture) { if (texture == null) { return; } BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenTextureFileName(texture.Name); if (fileName == null) { return; } try { var newTexture = Texture.FromFile(fileName); newTexture.Name = texture.Name; this.OptModel.File.Textures[newTexture.Name] = newTexture; dispatcher(() => this.OptModel.File = this.OptModel.File); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(texture.Name, ex)); } }); }
private void ExecuteSaveAsCommand(Texture texture) { if (texture == null) { return; } BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetSaveTextureFileName(texture.Name); if (fileName == null) { return; } try { texture.Save(fileName); dispatcher(() => this.OptModel.UndoStackPush("save " + System.IO.Path.GetFileName(fileName))); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(texture.Name, ex)); } }); }
private void ExecuteBrowseTextureNameCommand() { if (this.CurrentFaceGroups.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { Messenger.Instance.Notify(new BusyIndicatorMessage("Browsing texture...")); var message = Messenger.Instance.Notify(new TextureBrowserMessage(this.OptModel.File)); if (string.IsNullOrEmpty(message.TextureName)) { return; } var mesh = this.CurrentMeshes.SelectedItem; var lod = this.CurrentLods.SelectedItem; var faceGroup = this.CurrentFaceGroups.SelectedItem; faceGroup.Textures.Add(message.TextureName); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.CurrentLods.SetSelection(lod)); dispatcher(() => this.CurrentFaceGroups.SetSelection(faceGroup)); }); }
private void ExecuteDeleteLodsCommand(IList <MeshLod> lods) { if (this.CurrentMeshes.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; dispatcher(() => this.CurrentLods.ClearSelection()); foreach (var lod in lods) { mesh.Lods.Remove(lod); } mesh.CompactBuffers(); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.OptModel.UndoStackPush("delete lod")); }); }
private void ExecuteRotateMeshCommand(Mesh mesh) { BusyIndicatorService.Run(dispatcher => { var message = new RotateFactorMessage(); if (mesh.Descriptor != null) { var center = mesh.Descriptor.Center; message.CenterX = center.X; message.CenterY = center.Y; } Messenger.Instance.Notify(message); if (!message.Changed) { return; } BusyIndicatorService.Notify("Rotating ..."); mesh.RotateXY(message.Angle, message.CenterX, message.CenterY); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.OptModel.UndoStackPush("rotate mesh")); }); }
private void ExecuteDeleteTextureNamesCommand(IList <string> textureNames) { if (this.CurrentFaceGroups.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; var lod = this.CurrentLods.SelectedItem; var selectedTextures = this.CurrentFaceGroups.SelectedItem.Textures.ToList(); var faceGroups = this.CurrentFaceGroups.SelectedItems.ToList(); foreach (var faceGroup in faceGroups.Where(t => selectedTextures.SequenceEqual(t.Textures))) { foreach (var textureName in textureNames) { faceGroup.Textures.Remove(textureName); } } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.CurrentLods.SetSelection(lod)); dispatcher(() => this.CurrentFaceGroups.SetSelection(faceGroups)); dispatcher(() => this.OptModel.UndoStackPush("delete texture names")); }); }
private void ExecuteBrowseTextureNameCommand() { if (this.CurrentFaceGroups.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { Messenger.Instance.Notify(new BusyIndicatorMessage("Browsing texture...")); var message = Messenger.Instance.Notify(new TextureBrowserMessage(this.OptModel.File)); if (string.IsNullOrEmpty(message.TextureName)) { return; } var mesh = this.CurrentMeshes.SelectedItem; var lod = this.CurrentLods.SelectedItem; var selectedTextures = this.CurrentFaceGroups.SelectedItem.Textures.ToList(); var faceGroups = this.CurrentFaceGroups.SelectedItems.ToList(); foreach (var faceGroup in faceGroups.Where(t => selectedTextures.SequenceEqual(t.Textures))) { faceGroup.Textures.Add(message.TextureName); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.CurrentLods.SetSelection(lod)); dispatcher(() => this.CurrentFaceGroups.SetSelection(faceGroups)); dispatcher(() => this.OptModel.UndoStackPush("add texture name " + message.TextureName)); }); }
private void ExecuteImportOptCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Importing ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; try { dispatcher(() => this.OptModel.File = null); var import = OptFile.FromFile(fileName); string importName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_"; foreach (var faceGroup in import.Meshes.SelectMany(t => t.Lods).SelectMany(t => t.FaceGroups)) { var textures = faceGroup.Textures.ToList(); faceGroup.Textures.Clear(); foreach (var texture in textures) { faceGroup.Textures.Add(texture.StartsWith(importName, StringComparison.Ordinal) ? texture : (importName + texture)); } } foreach (var texture in import.Textures.Values) { texture.Name = texture.Name.StartsWith(importName, StringComparison.Ordinal) ? texture.Name : (importName + texture.Name); } foreach (var texture in import.Textures.Values) { opt.Textures[texture.Name] = texture; } foreach (var mesh in import.Meshes) { opt.Meshes.Add(mesh); } } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("import " + System.IO.Path.GetFileName(fileName))); }); }
private void ExecuteAddTextureNameCommand() { if (this.CurrentFaceGroups.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenTextureFileName(); if (fileName == null) { return; } try { var texture = Texture.FromFile(fileName); int bpp = texture.BitsPerPixel; texture.GenerateMipmaps(); if (bpp == 8) { texture.Convert32To8(); } var mesh = this.CurrentMeshes.SelectedItem; var lod = this.CurrentLods.SelectedItem; var selectedTextures = this.CurrentFaceGroups.SelectedItem.Textures.ToList(); var faceGroups = this.CurrentFaceGroups.SelectedItems.ToList(); this.OptModel.File.Textures[texture.Name] = texture; foreach (var faceGroup in faceGroups.Where(t => selectedTextures.SequenceEqual(t.Textures))) { faceGroup.Textures.Add(texture.Name); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.CurrentLods.SetSelection(lod)); dispatcher(() => this.CurrentFaceGroups.SetSelection(faceGroups)); dispatcher(() => this.OptModel.UndoStackPush("add texture name " + texture.Name)); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } }); }
private void ExecuteComputeHitzonesCommand() { BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; this.OptModel.File.ComputeHitzones(); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); }); }
private void ExecutePasteEngineGlowsCommand() { if (this.CurrentMeshes.SelectedItem == null) { return; } var selected = this.clipboardObject as Tuple <Mesh, IList <EngineGlow> >; if (selected == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; if (selected.Item1 == null) { foreach (var engineGlow in selected.Item2) { mesh.EngineGlows .Add(new EngineGlow { IsDisabled = engineGlow.IsDisabled, Position = engineGlow.Position, CoreColor = engineGlow.CoreColor, OuterColor = engineGlow.OuterColor, Format = engineGlow.Format, Look = engineGlow.Look, Up = engineGlow.Up, Right = engineGlow.Right }); } } else { this.clipboardObject = null; foreach (var engineGlow in selected.Item2) { selected.Item1.EngineGlows.Remove(engineGlow); mesh.EngineGlows.Add(engineGlow); } } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.OptModel.UndoStackPush("paste engine glows")); }); }
private void ExecuteConvertAllTexturesTo8BppCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } string directory = System.IO.Path.GetDirectoryName(fileName); BusyIndicatorService.Notify("Converting all textures to 8 bpp..."); var message = Messenger.Instance.Notify(new MessageBoxMessage(string.Concat("The textures of all OPTs in \"", directory, "\" will be converted to 8 bpp.\nDo you want to continue?"), "Converting textures", MessageBoxButton.YesNo, MessageBoxImage.Warning)); if (message.Result != MessageBoxResult.Yes) { return; } foreach (string file in System.IO.Directory.GetFiles(directory, "*.opt")) { BusyIndicatorService.Notify(string.Concat("Converting ", System.IO.Path.GetFileName(file), " to 8 bpp...")); OptFile opt = null; try { opt = OptFile.FromFile(file); } catch (System.IO.InvalidDataException) { continue; } if (opt.TexturesBitsPerPixel == 8) { continue; } opt.ConvertTextures32To8(); opt.Save(opt.FileName); } BusyIndicatorService.Notify("Converting all textures to 8 bpp completed."); Messenger.Instance.Notify(new MessageBoxMessage("Converting all textures to 8 bpp completed.", "Converting textures")); }); }
private void ExecuteDeleteMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { dispatcher(() => this.CurrentMeshes.ClearSelection()); foreach (var mesh in meshes) { this.OptModel.File.Meshes.Remove(mesh); } dispatcher(() => this.UpdateModel()); }); }
private void ExecuteNewMeshCommand() { BusyIndicatorService.Run(dispatcher => { dispatcher(() => this.CurrentMeshes.ClearSelection()); var mesh = new Mesh(); mesh.Lods.Add(new MeshLod()); this.OptModel.File.Meshes.Add(mesh); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); }); }
private void ExecuteDuplicateMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { BusyIndicatorService.Notify("Duplicating ..."); foreach (var mesh in meshes) { this.OptModel.File.Meshes.Add(mesh.Duplicate()); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(meshes)); }); }
private void ExecuteAddHardpointCommand(Tuple <MeshLodFace, Point3D> tag) { BusyIndicatorService.Run(dispatcher => { var mesh = tag.Item1.Mesh; mesh.Hardpoints .Add(new Hardpoint { Position = new JeremyAnsel.Xwa.Opt.Vector((float)-tag.Item2.Y, (float)-tag.Item2.X, (float)tag.Item2.Z) }); dispatcher(() => this.UpdateModel(true)); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); }); }
private void ExecuteSplitMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; dispatcher(() => this.CurrentMeshes.ClearSelection()); foreach (var mesh in meshes) { opt.SplitMesh(mesh); } dispatcher(() => this.UpdateModel()); }); }
private void ExecutePasteHardpointsCommand() { if (this.CurrentMeshes.SelectedItem == null) { return; } var selected = this.clipboardObject as Tuple <Mesh, IList <Hardpoint> >; if (selected == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; if (selected.Item1 == null) { foreach (var hardpoint in selected.Item2) { mesh.Hardpoints .Add(new Hardpoint { HardpointType = hardpoint.HardpointType, Position = hardpoint.Position }); } } else { this.clipboardObject = null; foreach (var hardpoint in selected.Item2) { selected.Item1.Hardpoints.Remove(hardpoint); mesh.Hardpoints.Add(hardpoint); } } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.OptModel.UndoStackPush("paste hardpoints")); }); }
private void ExecuteComputeHitzoneCommand() { if (this.CurrentMeshes.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; mesh.ComputeHitzone(); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); }); }
private void ExecuteNewHardpointCommand() { if (this.CurrentMeshes.SelectedItem == null) { return; } BusyIndicatorService.Run(dispatcher => { var mesh = this.CurrentMeshes.SelectedItem; mesh.Hardpoints.Add(new Hardpoint()); dispatcher(() => this.UpdateModel(true)); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); }); }
private void ExecuteGenerateNamesCommand() { BusyIndicatorService.Run(dispatcher => { try { BusyIndicatorService.Notify("Generating textures names..."); this.OptModel.File.GenerateTexturesNames(); dispatcher(() => this.OptModel.File = this.OptModel.File); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Generate textures names.", ex)); } }); }