public ImportedGeometryInfo(string path, IOGeometrySettings settings) { Name = PathC.GetFileNameWithoutExtensionTry(path); Path = path; Scale = settings.Scale; SwapXY = settings.SwapXY; SwapXZ = settings.SwapXZ; SwapYZ = settings.SwapYZ; InvertFaces = settings.InvertFaces; FlipX = settings.FlipX; FlipY = settings.FlipY; FlipZ = settings.FlipZ; FlipUV_V = settings.FlipUV_V; }
protected override void OnPaint(PaintEventArgs e) { LevelSettings settings = _editor?.Level?.Settings; if (settings == null) { return; } if (settings.ImportedGeometries.All(geo => geo.LoadException != null)) { ImportedGeometry errorGeo = settings.ImportedGeometries.FirstOrDefault(geo => geo.LoadException != null); string notifyMessage; if (errorGeo == null) { notifyMessage = "Click here to load new imported geometry."; } else { string filePath = settings.MakeAbsolute(errorGeo.Info.Path); string fileName = PathC.GetFileNameWithoutExtensionTry(filePath) ?? ""; if (PathC.IsFileNotFoundException(errorGeo.LoadException)) { notifyMessage = "Geometry file '" + fileName + "' was not found!\n"; } else { notifyMessage = "Unable to load geometry from file '" + fileName + "'.\n"; } notifyMessage += "Click here to choose a replacement.\n\n"; notifyMessage += "Path: " + (filePath ?? ""); } e.Graphics.Clear(Parent.BackColor); using (var b = new SolidBrush(Colors.DisabledText)) e.Graphics.DrawString(notifyMessage, Font, b, ClientRectangle, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Colors.GreySelection, ButtonBorderStyle.Solid); } else { base.OnPaint(e); } }
public string GetVariable(VariableType type) { string result; switch (type) { case VariableType.EditorDirectory: result = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); break; case VariableType.ScriptDirectory: result = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Dir + "Script"; break; case VariableType.LevelDirectory: if (!string.IsNullOrEmpty(LevelFilePath)) { result = Path.GetDirectoryName(LevelFilePath); } else { result = GetVariable(VariableType.EditorDirectory); } break; case VariableType.GameDirectory: result = MakeAbsolute(GameDirectory ?? VariableCreate(VariableType.LevelDirectory), VariableType.GameDirectory); break; case VariableType.LevelName: if (!string.IsNullOrEmpty(LevelFilePath)) { result = PathC.GetFileNameWithoutExtensionTry(LevelFilePath); } else if (Wads.Count > 0 && !string.IsNullOrEmpty(Wads[0].Path)) { result = PathC.GetFileNameWithoutExtensionTry(Wads[0].Path); } else { result = "Default"; } break; case VariableType.EngineVersion: result = GameVersion.ToString(); break; case VariableType.SoundEngineVersion: result = (GameVersion.Native()).ToString(); break; default: throw new ArgumentException(); } if (result == null) { result = ""; } return(result); }
private void EditorEventRaised(IEditorEvent obj) { // Gray out menu options that do not apply if (obj is Editor.SelectedObjectChangedEvent || obj is Editor.ModeChangedEvent || obj is Editor.SelectedSectorsChangedEvent) { ObjectInstance selectedObject = _editor.SelectedObject; bool enableCutCopy = _editor.Mode == EditorMode.Map2D || selectedObject is PositionBasedObjectInstance || _editor.SelectedSectors.Valid; copyToolStripMenuItem.Enabled = enableCutCopy; cutToolStripMenuItem.Enabled = enableCutCopy; deleteToolStripMenuItem.Enabled = _editor.Mode == EditorMode.Map2D || selectedObject != null; stampToolStripMenuItem.Enabled = selectedObject is PositionBasedObjectInstance; if (obj is Editor.ModeChangedEvent) { ClipboardEvents_ClipboardChanged(this, EventArgs.Empty); } bookmarkObjectToolStripMenuItem.Enabled = selectedObject != null; splitSectorObjectOnSelectionToolStripMenuItem.Enabled = selectedObject is SectorBasedObjectInstance && _editor.SelectedSectors.Valid; } // Disable version-specific controls if (obj is Editor.InitEvent || obj is Editor.GameVersionChangedEvent || obj is Editor.LevelChangedEvent) { addFlybyCameraToolStripMenuItem.Enabled = _editor.Level.Settings.GameVersion >= TRVersion.Game.TR4; addBoxVolumeToolStripMenuItem.Enabled = _editor.Level.Settings.GameVersion == TRVersion.Game.TR5Main; } if (obj is Editor.UndoStackChangedEvent) { var stackEvent = (Editor.UndoStackChangedEvent)obj; undoToolStripMenuItem.Enabled = stackEvent.UndoPossible; redoToolStripMenuItem.Enabled = stackEvent.RedoPossible; } if (obj is Editor.SelectedSectorsChangedEvent) { bool validSectorSelection = _editor.SelectedSectors.Valid; smoothRandomCeilingDownToolStripMenuItem.Enabled = validSectorSelection; smoothRandomCeilingUpToolStripMenuItem.Enabled = validSectorSelection; smoothRandomFloorDownToolStripMenuItem.Enabled = validSectorSelection; smoothRandomFloorUpToolStripMenuItem.Enabled = validSectorSelection; sharpRandomCeilingDownToolStripMenuItem.Enabled = validSectorSelection; sharpRandomCeilingUpToolStripMenuItem.Enabled = validSectorSelection; sharpRandomFloorDownToolStripMenuItem.Enabled = validSectorSelection; sharpRandomFloorUpToolStripMenuItem.Enabled = validSectorSelection; averageCeilingToolStripMenuItem.Enabled = validSectorSelection; averageFloorToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn3ToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn5ToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn3SquaresToolStripMenuItem.Enabled = validSectorSelection; gridWallsIn5SquaresToolStripMenuItem.Enabled = validSectorSelection; splitSectorObjectOnSelectionToolStripMenuItem.Enabled = _editor.SelectedObject is SectorBasedObjectInstance && validSectorSelection; } // Update version-specific controls if (obj is Editor.InitEvent || obj is Editor.LevelChangedEvent || obj is Editor.GameVersionChangedEvent) { bool isNG = _editor.Level.Settings.GameVersion == TRVersion.Game.TRNG; bool isT5M = _editor.Level.Settings.GameVersion == TRVersion.Game.TR5Main; addSphereVolumeToolStripMenuItem.Enabled = isT5M; addPrismVolumeToolStripMenuItem.Enabled = isT5M; addBoxVolumeToolStripMenuItem.Enabled = isT5M; makeQuickItemGroupToolStripMenuItem.Enabled = isNG; } // Update compilation statistics if (obj is Editor.LevelCompilationCompletedEvent) { var evt = obj as Editor.LevelCompilationCompletedEvent; statusLastCompilation.Text = "Last level output { " + evt.InfoString + " }"; } // Update autosave status if (obj is Editor.AutosaveEvent) { var evt = obj as Editor.AutosaveEvent; statusAutosave.Text = evt.Exception == null ? "Autosave OK: " + evt.Time : "Autosave failed!"; statusAutosave.ForeColor = evt.Exception == null ? statusLastCompilation.ForeColor : Color.LightSalmon; } // Update room information on the status strip if (obj is Editor.SelectedRoomChangedEvent || _editor.IsSelectedRoomEvent(obj as Editor.RoomGeometryChangedEvent) || _editor.IsSelectedRoomEvent(obj as Editor.RoomSectorPropertiesChangedEvent) || obj is Editor.RoomPropertiesChangedEvent) { var room = _editor.SelectedRoom; if (room == null) { statusStripSelectedRoom.Text = "Selected room: None"; } else { statusStripSelectedRoom.Text = "Selected room: " + "Name = " + room + " | " + "Pos = (" + room.Position.X + ", " + room.Position.Y + ", " + room.Position.Z + ") | " + "Floor = " + (room.Position.Y + room.GetLowestCorner()) + " | " + "Ceiling = " + (room.Position.Y + room.GetHighestCorner()); } } // Update selection information of the status strip if (obj is Editor.SelectedRoomChangedEvent || _editor.IsSelectedRoomEvent(obj as Editor.RoomGeometryChangedEvent) || _editor.IsSelectedRoomEvent(obj as Editor.RoomSectorPropertiesChangedEvent) || obj is Editor.SelectedSectorsChangedEvent) { var room = _editor.SelectedRoom; if (room == null || !_editor.SelectedSectors.Valid) { statusStripGlobalSelectionArea.Text = "Global area: None"; statusStripLocalSelectionArea.Text = "Local area: None"; } else { int minHeight = room.GetLowestCorner(_editor.SelectedSectors.Area); int maxHeight = room.GetHighestCorner(_editor.SelectedSectors.Area); statusStripGlobalSelectionArea.Text = "Global area = " + "(" + (room.Position.X + _editor.SelectedSectors.Area.X0) + ", " + (room.Position.Z + _editor.SelectedSectors.Area.Y0) + ") \u2192 " + "(" + (room.Position.X + _editor.SelectedSectors.Area.X1) + ", " + (room.Position.Z + _editor.SelectedSectors.Area.Y1) + ")" + " | y = [" + (minHeight == int.MaxValue || maxHeight == int.MinValue ? "N/A" : room.Position.Y + minHeight + ", " + (room.Position.Y + maxHeight)) + "]"; statusStripLocalSelectionArea.Text = "Local area = " + "(" + _editor.SelectedSectors.Area.X0 + ", " + _editor.SelectedSectors.Area.Y0 + ") \u2192 " + "(" + _editor.SelectedSectors.Area.X1 + ", " + _editor.SelectedSectors.Area.Y1 + ")" + " | y = [" + (minHeight == int.MaxValue || maxHeight == int.MinValue ? "N/A" : minHeight + ", " + maxHeight) + "]"; } } // Update application title bar if (obj is Editor.LevelFileNameChangedEvent || obj is Editor.HasUnsavedChangesChangedEvent) { string LevelName = string.IsNullOrEmpty(_editor.Level.Settings.LevelFilePath) ? "Untitled" : PathC.GetFileNameWithoutExtensionTry(_editor.Level.Settings.LevelFilePath); Text = "Tomb Editor " + Application.ProductVersion + " - " + LevelName + (_editor.HasUnsavedChanges ? "*" : ""); } // Update save button if (obj is Editor.HasUnsavedChangesChangedEvent) { saveLevelToolStripMenuItem.Enabled = _editor.HasUnsavedChanges; } // Reload window layout and keyboard shortcuts if the configuration changed if (obj is Editor.ConfigurationChangedEvent) { var e = (Editor.ConfigurationChangedEvent)obj; if (e.UpdateKeyboardShortcuts) { GenerateMenusRecursive(menuStrip.Items, true); } if (e.UpdateLayout) { LoadWindowLayout(_editor.Configuration); } UpdateUIColours(); UpdateControls(); } // Update texture controls if (obj is Editor.LoadedTexturesChangedEvent) { remapTextureToolStripMenuItem.Enabled = removeTexturesToolStripMenuItem.Enabled = unloadTexturesToolStripMenuItem.Enabled = reloadTexturesToolStripMenuItem.Enabled = importConvertTexturesToPng.Enabled = _editor.Level.Settings.Textures.Count > 0; } // Update wad controls if (obj is Editor.LoadedWadsChangedEvent) { removeWadsToolStripMenuItem.Enabled = reloadWadsToolStripMenuItem.Enabled = _editor.Level.Settings.Wads.Count > 0; } if (obj is Editor.LoadedSoundsCatalogsChangedEvent) { reloadSoundsToolStripMenuItem.Enabled = _editor.Level.Settings.SoundsCatalogs.Count > 0; } // Update object bookmarks if (obj is Editor.BookmarkedObjectChanged) { var @event = (Editor.BookmarkedObjectChanged)obj; bookmarkRestoreObjectToolStripMenuItem.Enabled = @event.Current != null; } if (obj is Editor.LevelFileNameChangedEvent) { RefreshRecentProjectsList(); } // Quit editor if (obj is Editor.EditorQuitEvent) { Close(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.IntersectClip(new RectangleF(new PointF(), ClientSize - new SizeF(_scrollSizeTotal, _scrollSizeTotal))); // Only proceed if texture is actually available if (VisibleTexture?.IsAvailable ?? false) { PointF drawStart = ToVisualCoord(new Vector2(0.0f, 0.0f)); PointF drawEnd = ToVisualCoord(new Vector2(VisibleTexture.Image.Width, VisibleTexture.Image.Height)); RectangleF drawArea = RectangleF.FromLTRB(drawStart.X, drawStart.Y, drawEnd.X, drawEnd.Y); // Draw background using (var textureBrush = new TextureBrush(Properties.Resources.misc_TransparentBackground)) e.Graphics.FillRectangle(textureBrush, drawArea); // Switch interpolation based on current view scale if (ViewScale >= 1.0) { e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; } else { e.Graphics.InterpolationMode = InterpolationMode.Bicubic; } // Draw image VisibleTexture.Image.GetTempSystemDrawingBitmap(tempBitmap => { // System.Drawing being silly, it draws the first row of pixels only half, so everything would be shifted // To work around it, we have to do some silly coodinate changes :/ e.Graphics.DrawImage(tempBitmap, new RectangleF(drawArea.X, drawArea.Y, drawArea.Width + 0.5f * ViewScale, drawArea.Height + 0.5f * ViewScale), new RectangleF(-0.5f, -0.5f, tempBitmap.Width + 0.5f, tempBitmap.Height + 0.5f), GraphicsUnit.Pixel); }); OnPaintSelection(e); } else { string notifyMessage; if (string.IsNullOrEmpty(VisibleTexture?.Path)) { notifyMessage = "Click here to load new texture file."; } else { string fileName = PathC.GetFileNameWithoutExtensionTry(VisibleTexture?.Path) ?? ""; if (PathC.IsFileNotFoundException(VisibleTexture?.LoadException)) { notifyMessage = "Texture file '" + fileName + "' was not found!\n"; } else { notifyMessage = "Unable to load texture from file '" + fileName + "'.\n"; } notifyMessage += "Click here to choose a replacement.\n\n"; notifyMessage += "Path: " + (_editor.Level.Settings.MakeAbsolute(VisibleTexture?.Path) ?? ""); } RectangleF textArea = ClientRectangle; textArea.Size -= new SizeF(_scrollSizeTotal, _scrollSizeTotal); using (var b = new SolidBrush(Colors.DisabledText)) e.Graphics.DrawString(notifyMessage, Font, b, textArea, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); } // Draw borders using (Pen pen = new Pen(Colors.GreySelection, 1.0f)) e.Graphics.DrawRectangle(pen, new RectangleF(0, 0, ClientSize.Width - _scrollSizeTotal - 1, ClientSize.Height - _scrollSizeTotal - 1)); }