public SoundEditor(SoundPackage package, SoundLocation type) { // Create controls and style the header InitializeComponent(); headerPanel.BackColor = Color.FromArgb(51, 53, 53); // Set internals NewSound = true; Package = package; Type = type; // Create new sound switch (package.SoundType) { case SoundType.Engine: Sound = new EngineSound(); break; case SoundType.Truck: Sound = new TruckSound(); break; default: throw new Exception("Invalid sound type"); } InitializeForm(); }
public static SoundPackage Missle() { var sound = new SoundPackage(true, _missle.CreateInstance()); _soundEffects.Add(sound); return(sound); }
public override void ParticleEffect() { ParticleSystem.MissleTrail(this.Position); if (_currentPackage.Play == false && (_currentPackage.Sound == null || _currentPackage.Sound.State == Microsoft.Xna.Framework.Audio.SoundState.Stopped)) { _currentPackage = SoundManager.Missle(); } }
public SoundPackageEditor(SoundPackage package) : this() { // Set internals NewPackage = false; Package = package; // Set title label text switch (Package.SoundType) { case SoundType.Engine: shadowLabel1.Text = "Engine Sound Package Editor"; break; case SoundType.Truck: shadowLabel1.Text = "Truck Sound Package Editor"; break; default: throw new Exception("Invalid sound type"); } // Set form input field values if existing package labelAuthor.Text = Package.Author; labelVersion.Text = Package.Version.ToString(); packageNameBox.Enabled = true; packageNameBox.Text = Package.Name; packageNameBox.SelectionStart = packageNameBox.Text.Length; unitNameBox.Enabled = true; unitNameBox.Text = Package.UnitName; folderNameBox.Enabled = true; folderNameBox.Text = Package.FolderName; if (package.SoundType == SoundType.Engine) { intFilenameBox.Enabled = true; intFilenameBox.Text = Package.InteriorFileName; extFilenameBox.Enabled = true; extFilenameBox.Text = Package.ExteriorFileName; } if (String.IsNullOrWhiteSpace(Package.YoutubeVideoId)) { youtubeLinkLabel.Enabled = false; youtubeLinkLabel.Visible = false; youtubeIcon.Visible = false; } // Change Import button text and size importButton.Size = new Size(125, 25); importButton.Text = "Import Update"; // Enable buttons confirmButton.Enabled = true; }
/// <summary> /// Installs this <see cref="SoundPackage"/> onto the file system and database. /// </summary> /// <param name="db"></param> /// <param name="package"></param> /// <param name="folderPath"></param> /// <param name="deleteExisting"></param> public void InstallPackage(AppDatabase db, SoundPackage package, string folderPath, bool deleteExisting = false) { // Grab all properties that have the SoundAttribute attribute List <PropertyInfo> properties = typeof(AccessorySoundData).GetProperties() .Where(prop => prop.IsDefined(typeof(SoundAttributeAttribute), false)) .ToList(); // Get sound data var interior = (Interior == null) ? GetSoundFile(SoundLocation.Interior) : Interior; var exterior = (Exterior == null) ? GetSoundFile(SoundLocation.Exterior) : Exterior; // Import sounds var files = new List <string>(); ImportSounds(db, package, interior, SoundLocation.Interior, properties, files); ImportSounds(db, package, exterior, SoundLocation.Exterior, properties, files); // Extract sound files used foreach (string file in files) { // Format the file name, removing any @ directives var filename = Regex.Replace(file, "^@(?<Code>[A-Z]+)/", "").TrimStart(new[] { '/' }); var entry = Archive.GetEntry(filename); // Ignore missing files if (entry != null) { // Ensure directory existance var fileExtractPath = Path.Combine(folderPath, filename.Replace('/', Path.DirectorySeparatorChar)); var dirName = Path.GetDirectoryName(fileExtractPath); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } // Extract audio file entry.ExtractToFile(fileExtractPath, deleteExisting); } } // Incase there were no sound files, ensure sound directory exists if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } // Extract sound files and manifest Archive.GetEntry("manifest.sii").ExtractToFile(Path.Combine(folderPath, "manifest.sii"), true); Archive.GetEntry("interior.sii").ExtractToFile(Path.Combine(folderPath, "interior.sii"), true); Archive.GetEntry("exterior.sii").ExtractToFile(Path.Combine(folderPath, "exterior.sii"), true); }
public SoundEditor(Sound sound, SoundPackage package) { // Create controls and style the header InitializeComponent(); headerPanel.BackColor = Color.FromArgb(51, 53, 53); // Set internals NewSound = false; Sound = sound; Package = package; Type = sound.Location; InitializeForm(); }
public SoundSelectForm(SoundPackage package, Sound currentSound = null) { // Create controls and style the header InitializeComponent(); headerPanel.BackColor = Color.FromArgb(51, 53, 53); // Create treeView image list treeView1.ImageList = new ImageList(); treeView1.ImageList.Images.Add(Resources.folder2); treeView1.ImageList.Images.Add(Resources.folder_open2); treeView1.ImageList.Images.Add(Resources.music); // Fill the tree Package = package; StartingSound = currentSound; FillTree(); }
/// <summary> /// Sound File compiler /// </summary> /// <param name="location"></param> /// <returns></returns> private static string CompileSoundFile( SoundLocation location, Truck truck, SoundPackageWrapper <EngineSoundPackage, EngineSound> enginePackage, SoundPackageWrapper <TruckSoundPackage, TruckSound> truckPackage, string unitName = null) { // Local variables var builder = new SiiFileBuilder(); var objectMap = new Dictionary <string, Sound>(); var engineSounds = enginePackage.GetSoundsByLocation(location); var truckSounds = truckPackage.GetSoundsByLocation(location); // Figure out the accessory name var name = new StringBuilder(unitName ?? enginePackage.Package.UnitName); name.Append($".{truck.UnitName}."); name.AppendLineIf(location == SoundLocation.Exterior, "esound", "isound"); // Write file intro builder.IndentStructs = false; builder.WriteStartDocument(); // Write the accessory type builder.WriteStructStart("accessory_sound_data", name.ToString().TrimEnd()); // Mark exterior or interior attribute builder.WriteAttribute("exterior_sound", location == SoundLocation.Exterior); builder.WriteLine(); // === // === Write Engine Attributes // === foreach (var info in SoundInfo.Attributes.Values) { // Only engine sounds if (info.SoundType != SoundType.Engine) { continue; } WriteAttribute(info, engineSounds, objectMap, builder); } // === // === Write Truck Attributes // === foreach (var info in SoundInfo.Attributes.Values) { // Only truck sounds if (info.SoundType != SoundType.Truck) { continue; } WriteAttribute(info, truckSounds, objectMap, builder); } // Include directive.. Directives have no tabs at all! if (location == SoundLocation.Interior) { builder.WriteInclude("/def/vehicle/truck/common_sound_int.sui"); } else { builder.WriteInclude("/def/vehicle/truck/common_sound_ext.sui"); } // Close Accessory builder.WriteStructEnd(); builder.WriteLine(); // === // === Append class objects // === foreach (var item in objectMap) { // Get sound package SoundPackage package = (item.Value.SoundType == SoundType.Engine) ? enginePackage.Package as SoundPackage : truckPackage.Package as SoundPackage; // Add sound object item.Value.AppendTo(builder, item.Key, package); } // Write the include directive if (location == SoundLocation.Interior) { builder.WriteInclude("/def/vehicle/truck/common_sound_int_data.sui"); } else { builder.WriteInclude("/def/vehicle/truck/common_sound_ext_data.sui"); } // Close SiiNUnit builder.WriteEndDocument(); return(builder.ToString()); }
/// <summary> /// Confirm button click callback /// </summary> private void confirmButton_Click(object sender, EventArgs e) { // Check for a valid identifier string if (!Regex.Match(unitNameBox.Text, @"^[a-z0-9_\.]+$", RegexOptions.IgnoreCase).Success) { // Tell the user this isnt allowed MessageBox.Show("Invalid Sii Unit Name. Please use alpha-numeric, or underscores only", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } // Check engine name if (!Regex.Match(truckNameBox.Text, @"^[a-z0-9_.,\-\s\t]+$", RegexOptions.IgnoreCase).Success) { // Tell the user this isnt allowed MessageBox.Show( "Invalid truck name string. Please use alpha-numeric, period, underscores, dashes or spaces only", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } // Grab sound packages selected SoundPackage enginePackage = engineSoundPackageBox.SelectedItem as SoundPackage; SoundPackage truckPackage = truckSoundPackageBox.SelectedItem as SoundPackage; // We need a sound package on a truck! if (truckSoundPackageBox.SelectedIndex < 0) { // Tell the user this isnt allowed MessageBox.Show( "No truck sound package selected! Please select a sound package and try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } // Engine sound override? if (checkBox1.Checked) { if (engineSoundPackageBox.SelectedIndex < 0) { // Tell the user this isnt allowed MessageBox.Show( "No engine sound package selected! Please select a sound package and try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } } try { // Add or update the truck in the database using (AppDatabase db = new AppDatabase()) { if (Truck == null) { Truck = new Truck() { Name = truckNameBox.Text.Trim(), UnitName = unitNameBox.Text.Trim(), SoundPackageId = truckPackage.Id }; db.Trucks.Add(Truck); } else { Truck.Name = truckNameBox.Text.Trim(); Truck.UnitName = unitNameBox.Text.Trim(); Truck.SoundPackageId = truckPackage.Id; db.Trucks.Update(Truck); } // Sync sound settings if (Setting != null) { if (checkBox1.Checked) { var newSetting = new TruckSoundSetting() { TruckId = Truck.Id, EngineSoundPackageId = enginePackage.Id }; // If something changed if (!newSetting.IsDuplicateOf(Setting)) { db.TruckSoundSettings.Update(newSetting); } } else { db.TruckSoundSettings.Remove(Setting); } } else if (checkBox1.Checked) { // Alert the user if this is an SCS engine if (Truck?.IsScsTruck ?? false) { var result = MessageBox.Show( "You are attempting to change the default sounds of an SCS created truck. " + "If you decide to revert these changes later, you will experience the \"No Sound Bug\". " + "Are you sure you wish to continue?", "Verification", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ); if (result != DialogResult.Yes) { return; } } // Appy setting var newSetting = new TruckSoundSetting() { TruckId = Truck.Id, EngineSoundPackageId = enginePackage.Id }; db.TruckSoundSettings.Add(newSetting); } } } catch (Exception ex) { // Tell the user about the failed validation error MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Truck = null; return; } // Close the form this.DialogResult = DialogResult.OK; }
/// <summary> /// Imports the sound accessory objects into the AppDatabase /// </summary> /// <param name="db">An open AppData.db connection</param> /// <param name="package">The <see cref="SoundPackage"/> that will own these accessory objects</param> /// <param name="data">The accessory data object</param> /// <param name="location">The sound type</param> protected void ImportSounds( AppDatabase db, SoundPackage package, AccessorySoundData data, SoundLocation location, List <PropertyInfo> properties, List <string> files) { // Using reflection, we will now loop through each property // with the SoundAttribute attribute, and create an EngineSound // entity using that data. foreach (var prop in properties) { // Define local vars SoundAttribute attr = prop.GetCustomAttribute <SoundAttributeAttribute>().Attribute; SoundInfo info = SoundInfo.Attributes[attr]; // Skip if wrong sound type if (info.SoundType != Type) { continue; } if (Type == SoundType.Engine) { if (info.IsArray) { if (info.IsEngineSoundData) { var values = ((SoundEngineData[])prop.GetValue(data) ?? new SoundEngineData[] { }); foreach (var sound in values) { db.EngineSounds.Add(new EngineSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } else { var values = ((SoundData[])prop.GetValue(data) ?? new SoundData[] { }); foreach (var sound in values) { db.EngineSounds.Add(new EngineSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } } else { if (info.IsEngineSoundData) { var sound = (SoundEngineData)prop.GetValue(data); if (sound != null) { db.EngineSounds.Add(new EngineSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } else { var sound = (SoundData)prop.GetValue(data); if (sound != null) { db.EngineSounds.Add(new EngineSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } } } else if (Type == SoundType.Truck) { if (info.IsArray) { var values = ((SoundData[])prop.GetValue(data) ?? new SoundData[] { }); foreach (var sound in values) { db.TruckSounds.Add(new TruckSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } else { var sound = (SoundData)prop.GetValue(data); if (sound != null) { db.TruckSounds.Add(new TruckSound(sound, attr, location) { PackageId = package.Id }); files.Add(sound.Name); } } } } }