예제 #1
0
 // Returns 'null' if no file is chosen.
 // "currentPath" can be a file path or a directory path containing placeholders (or null).
 public static string BrowseFile(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, IEnumerable <FileFormat> fileFormats, VariableType?baseDirType, bool save)
 {
     using (FileDialog dialog = save ? (FileDialog) new SaveFileDialog() : new OpenFileDialog())
     {
         dialog.Filter = fileFormats.GetFilter();
         dialog.Title  = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             try
             {
                 string path = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
                 if (Directory.Exists(path))
                 {
                     dialog.InitialDirectory = path;
                 }
                 else
                 {
                     dialog.FileName         = Path.GetFileName(path);
                     dialog.InitialDirectory = Path.GetDirectoryName(path);
                 }
             }
             catch (Exception)
             { }
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(null);
         }
         return(baseDirType != null && levelSettings != null?levelSettings.MakeRelative(dialog.FileName, baseDirType.Value) : dialog.FileName);
     }
 }
예제 #2
0
        private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex < 0 || e.RowIndex >= _dataGridViewDataSource.Count)
            {
                return;
            }

            if (dataGridView.Columns[e.ColumnIndex].Name == errorMessageColumn.Name)
            {
                ImportedGeometry object_ = _dataGridViewDataSource[e.RowIndex].Object;
                if (object_.LoadException == null)
                {
                    e.CellStyle.BackColor          = _correctColor;
                    e.CellStyle.SelectionBackColor = e.CellStyle.SelectionBackColor.MixWith(_correctColor, 0.4);
                }
                else
                {
                    e.CellStyle.BackColor          = _wrongColor;
                    e.CellStyle.SelectionBackColor = e.CellStyle.SelectionBackColor.MixWith(_wrongColor, 0.4);
                }
            }
            else if (dataGridView.Columns[e.ColumnIndex].Name == pathColumn.Name)
            {
                ImportedGeometry object_      = _dataGridViewDataSource[e.RowIndex].Object;
                string           absolutePath = LevelSettings.MakeAbsolute(object_.Info.Path);
                dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = absolutePath;
            }
        }
        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);
            }
        }
예제 #4
0
 // Returns an empty collection if no folder is chosen.
 // "currentPath" should be a directory path containing placeholders (or null).
 public static IEnumerable <string> BrowseFiles(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, IEnumerable <FileFormat> fileFormats, VariableType?baseDirType = null)
 {
     using (OpenFileDialog dialog = new OpenFileDialog())
     {
         dialog.Multiselect = true;
         dialog.Filter      = fileFormats.GetFilter();
         dialog.Title       = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             dialog.InitialDirectory = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(new string[0]);
         }
         return(baseDirType != null && levelSettings != null?dialog.FileNames.Select(fileName => levelSettings.MakeRelative(fileName, baseDirType.Value)) : dialog.FileNames);
     }
 }
예제 #5
0
        public static string TryGetSamplePath(LevelSettings levelSettings, string name)
        {
            // Search the sample in all registered paths, in descending order
            for (int p = 0; p < levelSettings.WadSoundPaths.Count; p++)
            {
                string newPath = levelSettings.MakeAbsolute(levelSettings.WadSoundPaths[p].Path);
                if (newPath == null)
                {
                    continue;
                }

                newPath = Path.Combine(newPath, name);

                if (File.Exists(newPath))
                {
                    return(newPath);
                }
            }

            return(null);
        }
예제 #6
0
 // Returns 'null' if no folder is chosen.
 // "currentPath" should be a directory path containing placeholders (or null).
 public static string BrowseFolder(IWin32Window owner, LevelSettings levelSettings, string currentPath, string title, VariableType?baseDirType)
 {
     using (var dialog = new BrowseFolderDialog())
     {
         dialog.Title = title;
         if (!string.IsNullOrWhiteSpace(currentPath))
         {
             try
             {
                 dialog.InitialFolder = levelSettings?.MakeAbsolute(currentPath) ?? currentPath;
             }
             catch (Exception)
             { }
         }
         if (dialog.ShowDialog(owner) != DialogResult.OK)
         {
             return(null);
         }
         return(baseDirType != null && levelSettings != null?levelSettings.MakeRelative(dialog.Folder, baseDirType.Value) : dialog.Folder);
     }
 }
예제 #7
0
        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);
            }
        }