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); } }
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)); }
public static void Launch(LevelSettings settings, IWin32Window owner) { string executablePath = settings.MakeAbsolute(settings.GameExecutableFilePath); string levelPath = settings.MakeAbsolute(settings.GameLevelFilePath); // Try to launch the game try { var info = new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(executablePath), FileName = executablePath }; // Start the game (i.e. "tomb4.exe") Process process = Process.Start(info); try { // Seperate thread to wait for the options dialog to appear // so it can be suppressed subsequently by sending WM_CLOSE. if (settings.GameVersion.Legacy() == TRVersion.Game.TR4 && settings.GameEnableQuickStartFeature && IsWindows) { Process process2 = process; Thread thread = new Thread(() => { try { Tomb4ConvinienceImprovements.Do(process2, info.WorkingDirectory, levelPath); } catch (Exception exc) { logger.Error(exc, "The 'Tomb4ConvinienceImprovements' thread caused issues."); } finally { process2?.Dispose(); } }); thread.IsBackground = true; thread.Priority = ThreadPriority.BelowNormal; thread.Start(); process = null; } } finally { process?.Dispose(); } } catch (Exception exc) { logger.Warn(exc, "Trying to launch the game '" + executablePath + "'."); // Show message string message = "\nGo to Tools -> Level Settings -> Game Paths to set a valid executable path."; if (PathC.IsFileNotFoundException(exc) || !File.Exists(executablePath)) { message = "Unable to find '" + executablePath + "'. " + message; } else { message = "Unable to start '" + executablePath + "' because a " + exc.GetType().Name + " occurred (" + exc.Message + "). " + message; } Editor.Instance.SendMessage(message, PopupType.Error); } }