public bool SaveFile(string path = null, bool forceOverride = false, bool switchPath = true) { path = forceOverride ? path : path ?? MapFile; if (path == null) { using (var sfd = new SaveFileDialog()) { var filter = String.Join("|", FileTypeRegistration.GetSupportedExtensions() .Where(x => x.IsPrimaryFormat).Select(x => x.Description + " (*" + x.Extension + ")|*" + x.Extension)); var all = FileTypeRegistration.GetSupportedExtensions().Where(x => x.IsPrimaryFormat).Select(x => "*" + x.Extension).ToArray(); sfd.Filter = "All supported formats (" + String.Join(", ", all) + ")|" + String.Join(";", all) + "|" + filter; if (sfd.ShowDialog() == DialogResult.OK) { path = sfd.FileName; } } } if (path == null) { return(false); } // Save the 3D camera position var cam = ViewportManager.Viewports.OfType <Viewport3D>().Select(x => x.Camera).FirstOrDefault(); if (cam != null) { if (Map.ActiveCamera == null) { Map.ActiveCamera = !Map.Cameras.Any() ? new Camera { LookPosition = Coordinate.UnitX * Map.GridSpacing * 1.5m } : Map.Cameras.First(); if (!Map.Cameras.Contains(Map.ActiveCamera)) { Map.Cameras.Add(Map.ActiveCamera); } } var dist = (Map.ActiveCamera.LookPosition - Map.ActiveCamera.EyePosition).VectorMagnitude(); var loc = cam.Location; var look = cam.LookAt - cam.Location; look.Normalize(); look = loc + look * (float)dist; Map.ActiveCamera.EyePosition = new Coordinate((decimal)loc.X, (decimal)loc.Y, (decimal)loc.Z); Map.ActiveCamera.LookPosition = new Coordinate((decimal)look.X, (decimal)look.Y, (decimal)look.Z); } Map.WorldSpawn.EntityData.SetPropertyValue("wad", string.Join(";", GetUsedTexturePackages().Select(x => x.PackageRoot).Where(x => x.EndsWith(".wad")))); MapProvider.SaveMapToFile(path, Map); if (switchPath) { MapFile = path; MapFileName = Path.GetFileName(MapFile); History.TotalActionsSinceLastSave = 0; Mediator.Publish(EditorMediator.DocumentSaved, this); } return(true); }
protected override void OnDragEnter(DragEventArgs drgevent) { if (drgevent.Data.GetDataPresent(DataFormats.FileDrop)) { var supported = FileTypeRegistration.GetSupportedExtensions(); var files = (drgevent.Data.GetData(DataFormats.FileDrop) as IEnumerable <string> ?? new string[0]) .Where(x => supported.Any(f => x.EndsWith(f.Extension, StringComparison.InvariantCultureIgnoreCase))) .ToList(); drgevent.Effect = files.Any() ? DragDropEffects.Link : DragDropEffects.None; } base.OnDragEnter(drgevent); }
protected override void OnDragDrop(DragEventArgs drgevent) { if (drgevent.Data.GetDataPresent(DataFormats.FileDrop)) { var supported = FileTypeRegistration.GetSupportedExtensions(); var files = (drgevent.Data.GetData(DataFormats.FileDrop) as IEnumerable <string> ?? new string[0]) .Where(x => supported.Any(f => x.EndsWith(f.Extension, StringComparison.InvariantCultureIgnoreCase))) .ToList(); foreach (var file in files) { LoadFile(file); } } base.OnDragDrop(drgevent); }
private static void FileOpen() { using (var ofd = new OpenFileDialog()) { var filter = String.Join("|", FileTypeRegistration.GetSupportedExtensions().Where(x => x.CanLoad) .Select(x => x.Description + " (*" + x.Extension + ")|*" + x.Extension)); var all = FileTypeRegistration.GetSupportedExtensions().Where(x => x.CanLoad).Select(x => "*" + x.Extension).ToArray(); ofd.Filter = "All supported formats (" + String.Join(", ", all) + ")|" + String.Join(";", all) + "|" + filter; if (ofd.ShowDialog() != DialogResult.OK) { return; } LoadFile(ofd.FileName); } }
private void EditorLoad(object sender, EventArgs e) { FileTypeRegistration.RegisterFileTypes(); SettingsManager.Read(); if (TaskbarManager.IsPlatformSupported) { TaskbarManager.Instance.ApplicationId = FileTypeRegistration.ProgramId; _jumpList = JumpList.CreateJumpList(); _jumpList.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent; _jumpList.Refresh(); } UpdateDocumentTabs(); UpdateRecentFiles(); DockBottom.Hidden = DockLeft.Hidden = DockRight.Hidden = true; MenuManager.Init(mnuMain, tscToolStrip); MenuManager.Rebuild(); SidebarManager.Init(RightSidebar); ViewportManager.Init(TableSplitView); ToolManager.Init(); foreach (var tool in ToolManager.Tools) { var tl = tool; var hotkey = Sledge.Settings.Hotkeys.GetHotkeyForMessage(HotkeysMediator.SwitchTool, tool.GetHotkeyToolType()); tspTools.Items.Add(new ToolStripButton( "", tl.GetIcon(), (s, ea) => Mediator.Publish(HotkeysMediator.SwitchTool, tl.GetHotkeyToolType()), tl.GetName()) { Checked = (tl == ToolManager.ActiveTool), ToolTipText = tl.GetName() + (hotkey != null ? " (" + hotkey.Hotkey + ")" : ""), DisplayStyle = ToolStripItemDisplayStyle.Image, ImageScaling = ToolStripItemImageScaling.None, AutoSize = false, Width = 36, Height = 36 } ); } TextureProvider.SetCachePath(SettingsManager.GetTextureCachePath()); MapProvider.Register(new RmfProvider()); MapProvider.Register(new MapFormatProvider()); MapProvider.Register(new VmfProvider()); MapProvider.Register(new ObjProvider()); GameDataProvider.Register(new FgdProvider()); TextureProvider.Register(new WadProvider()); TextureProvider.Register(new SprProvider()); TextureProvider.Register(new VmtProvider()); ModelProvider.Register(new MdlProvider()); WadProvider.ReplaceTransparentPixels = !Sledge.Settings.View.DisableWadTransparency && !Sledge.Settings.View.GloballyDisableTransparency; TextureHelper.EnableTransparency = !Sledge.Settings.View.GloballyDisableTransparency; TextureHelper.DisableTextureFiltering = Sledge.Settings.View.DisableTextureFiltering; TextureHelper.ForceNonPowerOfTwoResize = Sledge.Settings.View.ForcePowerOfTwoTextureResizing; Subscribe(); Mediator.MediatorException += (mthd, ex) => Logging.Logger.ShowException(ex.Exception, "Mediator Error: " + ex.Message); if (Sledge.Settings.View.LoadSession) { foreach (var session in SettingsManager.LoadSession()) { LoadFileGame(session.Item1, session.Item2); } } ProcessArguments(System.Environment.GetCommandLineArgs()); }