Exemplo n.º 1
0
        public static bool LoadReferenceLevel(WadToolClass tool, IWin32Window owner, string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = LevelFileDialog.BrowseFile(owner, null, null, "Open Tomb Editor reference level", LevelSettings.FileFormatsLevel, null, false);
            }

            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            tool.ReferenceLevel = Prj2Loader.LoadFromPrj2(path, null, new Prj2Loader.Settings {
                IgnoreTextures = true, IgnoreWads = true
            });

            if (tool.ReferenceLevel != null)
            {
                tool.Configuration.Tool_ReferenceProject = path;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        private void CompileMainSFX(TRVersion.Game version, bool onlyIndexed)
        {
            LevelSettings settings;
            var           sounds = Sounds.SoundInfos;

            if (sounds.Count == 0)
            {
                popup.ShowError(soundInfoEditor, "No sounds present. Nothing to compile!");
                return;
            }

            settings = new LevelSettings()
            {
                GameVersion = version
            };
            settings.WadSoundPaths.Clear();
            var samplePath = LevelFileDialog.BrowseFolder(this, null, _configuration.SoundTool_LastMainSFXSamplePath,
                                                          "Choose a path where all samples are stored", null);

            if (string.IsNullOrEmpty(samplePath))
            {
                return; // User cancelled path selection
            }
            settings.WadSoundPaths.Add(new WadSoundPath(samplePath));
            _configuration.SoundTool_LastMainSFXSamplePath = samplePath; // Update settings

            var mainSFXPath = LevelFileDialog.BrowseFile(this, null, _configuration.SoundTool_LastMainSFXPath,
                                                         "Choose a path to save MAIN.SFX", _fileFormatSfx, null, true);

            if (string.IsNullOrEmpty(mainSFXPath))
            {
                return; // User cancelled saving
            }
            bool missing;
            var  samples = WadSample.CompileSamples(sounds, settings, onlyIndexed, out missing);

            try
            {
                using (var writer = new BinaryWriterEx(new FileStream(mainSFXPath, FileMode.Create, FileAccess.Write, FileShare.None)))
                {
                    foreach (var sample in samples.Values)
                    {
                        writer.Write(sample.Data, 0, sample.Data.Length);
                    }
                }

                var message = "MAIN.SFX compiled successfully!";
                if (missing)
                {
                    message += "\n" + "Some samples weren't found and won't play in game.";
                }
                popup.ShowInfo(soundInfoEditor, message);
                _configuration.SoundTool_LastMainSFXPath = mainSFXPath;
            }
            catch (Exception ex)
            {
                popup.ShowError(soundInfoEditor, "There was a error writing MAIN.SFX. \nException: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private bool OpenArchive(string filename = null)
        {
            CheckForSavedChanges();

            if (filename == null)
            {
                filename = LevelFileDialog.BrowseFile(this, null, _configuration.SoundTool_LastCatalogPath, "Select archive to open",
                                                      WadSounds.FormatExtensions, null,
                                                      false);
            }

            if (filename == null || !File.Exists(filename))
            {
                return(false);
            }

            // Read the sounds archive in XML or TXT format
            var sounds = WadSounds.ReadFromFile(filename);

            if (sounds == null)
            {
                return(false);
            }

            // File read correctly, save catalog path to recent
            _configuration.SoundTool_LastCatalogPath = filename;

            dgvSoundInfos.Rows.Clear();

            // Fill the grid
            sounds.SoundInfos.Sort((a, b) => a.Id.CompareTo(b.Id));
            foreach (var soundInfo in sounds.SoundInfos)
            {
                dgvSoundInfos.Rows.Add(soundInfo.Id.ToString().PadLeft(4, '0'), soundInfo.Name);
                dgvSoundInfos.Rows[dgvSoundInfos.Rows.Count - 1].Tag = soundInfo;
            }

            SelectSoundInfo();

            // Decide on saved flag based on file format.
            // If TXT was loaded (i.e. conversion was made), mark the file as unsaved.
            var extension = Path.GetExtension(filename);

            if (extension == ".xml")
            {
                _currentArchive = filename;
                Saved           = true;
            }
            else
            {
                _currentArchive = null;
                Saved           = false;
            }
            return(true);
        }
Exemplo n.º 4
0
        private void ButBrowseTxt_Click(object sender, EventArgs e)
        {
            string result = LevelFileDialog.BrowseFile(this, "Select sound catalog to import",
                                                       LevelSettings.FileFormatsSoundsCatalogs,
                                                       false);

            if (result != null)
            {
                tbTxtPath.Text = result;
            }
        }
Exemplo n.º 5
0
        public ImportedGeometryManager()
        {
            InitializeComponent();

            _correctColor = dataGridView.BackColor.MixWith(Color.LimeGreen, 0.55);
            _wrongColor   = dataGridView.BackColor.MixWith(Color.DarkRed, 0.55);

            dataGridView.CellMouseDoubleClick += dataGridView_CellMouseDoubleClick;

            // Initialize sound path data grid view
            dataGridViewControls.DataGridView = dataGridView;
            dataGridViewControls.Enabled      = true;
            dataGridViewControls.CreateNewRow = delegate
            {
                List <string> paths = LevelFileDialog.BrowseFiles(this, null, PathC.GetDirectoryNameTry(LevelSettings.LevelFilePath),
                                                                  "Select 3D files that you want to see imported.", ImportedGeometry.FileExtensions).ToList();

                // Load imported geometries
                var importInfos = new List <KeyValuePair <ImportedGeometry, ImportedGeometryInfo> >();
                foreach (string path in paths)
                {
                    using (var settingsDialog = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                    {
                        settingsDialog.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                        settingsDialog.SelectPreset("Normal scale to TR scale");

                        if (settingsDialog.ShowDialog(this) == DialogResult.Cancel)
                        {
                            continue;
                        }

                        var info = new ImportedGeometryInfo(LevelSettings.MakeRelative(path, VariableType.LevelDirectory), settingsDialog.Settings);
                        importInfos.Add(new KeyValuePair <ImportedGeometry, ImportedGeometryInfo>(new ImportedGeometry(), info));
                    }
                }

                LevelSettings.ImportedGeometryUpdate(importInfos);
                LevelSettings.ImportedGeometries.AddRange(importInfos.Select(entry => entry.Key));
                return(importInfos.Select(entry => new ImportedGeometryWrapper(this, entry.Key)));
            };
            dataGridView.DataSource = _dataGridViewDataSource;
            dataGridViewControls.DeleteRowCheckIfCancel = MessageUserAboutHimDeletingRows;
            _dataGridViewDataSource.ListChanged        += delegate(object sender, ListChangedEventArgs e)
            {
                switch (e.ListChangedType)
                {
                case ListChangedType.ItemDeleted:
                    var remainingElements = new HashSet <ImportedGeometry>(_dataGridViewDataSource.Select(wrapper => wrapper.Object));
                    LevelSettings.ImportedGeometries.RemoveAll(obj => !remainingElements.Contains(obj));         // Don't use indices here, the wrapper indices might not match with the real object if sorting was enabled.
                    break;
                }
            };
            Enabled = true;
        }
Exemplo n.º 6
0
        private void butSearchSoundsCatalogPath_Click(object sender, EventArgs e)
        {
            string result = LevelFileDialog.BrowseFile(this, "Select sound catalog to import",
                                                       LevelSettings.FileFormatsSoundsCatalogs,
                                                       false);

            if (result != null)
            {
                var sounds = WadSounds.ReadFromFile(result);
                if (sounds == null)
                {
                    return;
                }
                Sounds = sounds;
                tbSoundsCatalogPath.Text = result;
            }
        }
Exemplo n.º 7
0
        private void LoadReferenceLevel(string fileName = null)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = LevelFileDialog.BrowseFile(this, "Open Tomb Editor reference project", LevelSettings.FileFormatsLevel, false);
            }

            if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                return;
            }

            ReferenceLevel = Prj2Loader.LoadFromPrj2(fileName, null, new Prj2Loader.Settings {
                IgnoreTextures = true, IgnoreWads = true
            });
            _configuration.SoundTool_ReferenceProject = fileName;
            UpdateUI();
        }
Exemplo n.º 8
0
        private void SaveArchive(string filename = null)
        {
            if (filename == null)
            {
                filename = LevelFileDialog.BrowseFile(this, "Save sound catalog to XML",
                                                      LevelSettings.FileFormatsSoundsXmlFiles,
                                                      true);
            }
            if (filename == null)
            {
                return;
            }

            Sounds.SoundInfos.Sort((a, b) => a.Id.CompareTo(b.Id));
            WadSounds.SaveToXml(filename, Sounds);

            _currentArchive = filename;
            Saved           = true;
        }
Exemplo n.º 9
0
        private void butBrowse_Click(object sender, EventArgs e)
        {
            var files = LevelFileDialog.BrowseFiles(FindForm(), ReferenceLevel?.Settings, null, "Choose samples", FileExtensions, null);

            if (files != null)
            {
                bool samplesAreMisplaced = false;

                foreach (var file in files)
                {
                    bool alreadyInList = false;
                    var  fileName      = Path.GetFileName(file).ToLower();

                    foreach (DataGridViewRow row in dgvSamples.Rows)
                    {
                        if (row.Cells[0].Value.ToString().ToLower().Equals(fileName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            alreadyInList = true; break;
                        }
                    }
                    if (alreadyInList)
                    {
                        break;
                    }

                    samplesAreMisplaced = !AddSampleToList(fileName);
                }

                if (samplesAreMisplaced)
                {
                    DarkMessageBox.Show(this,
                                        "Selected samples aren't placed in any of your reference level's sample paths.\nPlease copy samples to one of the sample paths or add specified path to path list.",
                                        "Wrong folder", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemplo n.º 10
0
        public static void HandleDialog(IDialogDescription dialogDescription_, IWin32Window owner)
        {
            if (dialogDescription_ is DialogDescriptonTextureUnloadable)
            {
                var dialogDescription = (DialogDescriptonTextureUnloadable)dialogDescription_;

                if (dialogDescription.Texture.LoadException != null)
                {
                    owner.InvokeIfNecessary(() =>
                    {
                        while (dialogDescription.Texture.LoadException != null)
                        {
                            switch (DarkMessageBox.Show(owner, "The texture file '" + dialogDescription.Settings.MakeAbsolute(dialogDescription.Texture.Path) +
                                                        " could not be loaded: " + (dialogDescription.Texture.LoadException?.Message ?? "null") + ". \n" +
                                                        "Do you want to load a substituting file now?", "Open project",
                                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
                            {
                            case DialogResult.Yes:
                                dialogDescription.Texture.SetPath(dialogDescription.Settings,
                                                                  LevelFileDialog.BrowseFile(owner, dialogDescription.Settings, dialogDescription.Texture.Path,
                                                                                             "Load a texture", LevelTexture.FileExtensions, VariableType.LevelDirectory, false));
                                break;     // Don't unlock, we don't want to have other messages in the meantime.

                            case DialogResult.No:
                                return;

                            case DialogResult.Cancel:
                                throw new OperationCanceledException("Canceled because texture was not loadable");
                            }
                        }
                    });
                }
            }
            else if (dialogDescription_ is DialogDescriptonWadUnloadable)
            {
                var dialogDescription = (DialogDescriptonWadUnloadable)dialogDescription_;

                if (dialogDescription.Wad.LoadException != null)
                {
                    owner.InvokeIfNecessary(() =>
                    {
                        while (dialogDescription.Wad.LoadException != null)
                        {
                            switch (DarkMessageBox.Show(owner, "The objects file '" + dialogDescription.Settings.MakeAbsolute(dialogDescription.Wad.Path) +
                                                        " could not be loaded: " + (dialogDescription.Wad.LoadException?.Message ?? "null") + ". \n" +
                                                        "Do you want to load a substituting file now?", "Open project",
                                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
                            {
                            case DialogResult.Yes:
                                dialogDescription.Wad.SetPath(dialogDescription.Settings,
                                                              LevelFileDialog.BrowseFile(owner, dialogDescription.Settings, dialogDescription.Wad.Path,
                                                                                         "Load an object file (*.wad)", Wad2.WadFormatExtensions, VariableType.LevelDirectory, false));
                                break;     // Don't unlock, we don't want to have other messages in the meantime.

                            case DialogResult.No:
                                return;

                            case DialogResult.Cancel:
                                throw new OperationCanceledException("Canceled because wad file was not loadable");
                            }
                        }
                    });
                }
            }
            else if (dialogDescription_ is DialogDescriptonSoundsCatalogUnloadable)
            {
                var dialogDescription = (DialogDescriptonSoundsCatalogUnloadable)dialogDescription_;

                if (dialogDescription.Sounds.LoadException != null)
                {
                    owner.InvokeIfNecessary(() =>
                    {
                        while (dialogDescription.Sounds.LoadException != null)
                        {
                            switch (DarkMessageBox.Show(owner, "Sound catalog file '" + dialogDescription.Settings.MakeAbsolute(dialogDescription.Sounds.Path) +
                                                        " could not be loaded: " + (dialogDescription.Sounds.LoadException?.Message ?? "null") + ". \n" +
                                                        "Do you want to load a substituting file now?", "Open project",
                                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
                            {
                            case DialogResult.Yes:
                                dialogDescription.Sounds.SetPath(dialogDescription.Settings,
                                                                 LevelFileDialog.BrowseFile(owner, dialogDescription.Settings, dialogDescription.Sounds.Path,
                                                                                            "Load a sound catalog (*.sfx)", ReferencedSoundsCatalog.FileExtensions, VariableType.LevelDirectory, false));
                                break;     // Don't unlock, we don't want to have other messages in the meantime.

                            case DialogResult.No:
                                return;

                            case DialogResult.Cancel:
                                throw new OperationCanceledException("Canceled because sound catalog file was not loadable");
                            }
                        }
                    });
                }
            }
            else
            {
                logger.Info("Ignored dialog event of type " + dialogDescription_.GetType().FullName + ".");
            }
        }