public void RefreshListBox() { MainListbox.ItemsSource = null; soundListItems.Clear(); for (int i = 0; i < mapEditor.mapdata.WAV.Length; i++) { string d = mapEditor.mapdata.WAV[i].String; if (mapEditor.mapdata.WAV[i].IsLoaded) { SoundListItem soundListItem = new SoundListItem(); soundListItem.FileName = d; SoundData soundData = mapEditor.mapdata.soundDatas.Find((x) => x.path == d); if (soundData == null) { soundListItem.Size = "외부파일"; } else { long s = soundData.bytes.Length; s /= 1024; soundListItem.Size = s.ToString() + "kb"; } soundListItems.Add(soundListItem); } } MainListbox.ItemsSource = soundListItems; }
private void MapSoundPlay() { SoundListItem soundListItems = (SoundListItem)MainListbox.SelectedItem; if (soundListItems != null) { string soundname = soundListItems.FileName; SoundData soundData = mapEditor.mapdata.soundDatas.Find((x) => x.path == soundname); try { if (soundData == null) { byte[] buffer = data.ReadFile(soundname); if (buffer.Length == 0) { return; } if (System.IO.Path.GetExtension(soundname).ToLower() == ".wav") { WaveFileReader waveFileReader = new WaveFileReader(new MemoryStream(buffer)); waveOut.Init(waveFileReader); waveOut.Play(); } else if (System.IO.Path.GetExtension(soundname).ToLower() == ".ogg") { NAudio.Vorbis.VorbisWaveReader vorbisWaveReader = new NAudio.Vorbis.VorbisWaveReader(new MemoryStream(buffer)); waveOut.Init(vorbisWaveReader); waveOut.Play(); } } else { if (System.IO.Path.GetExtension(soundname).ToLower() == ".wav") { WaveFileReader waveFileReader = new WaveFileReader(new MemoryStream(soundData.bytes)); waveOut.Init(waveFileReader); waveOut.Play(); } else if (System.IO.Path.GetExtension(soundname).ToLower() == ".ogg") { NAudio.Vorbis.VorbisWaveReader vorbisWaveReader = new NAudio.Vorbis.VorbisWaveReader(new MemoryStream(soundData.bytes)); waveOut.Init(vorbisWaveReader); waveOut.Play(); } } } catch (Exception) { System.Media.SystemSounds.Hand.Play(); } } }
private void DeleteItem(string soundname) { if (mapEditor.mapdata.DeleteSound(soundname)) { SoundListItem soundListItem = soundListItems.Find((x) => x.FileName == soundname); soundListItems.Remove(soundListItem); MainListbox.ItemsSource = null; MainListbox.ItemsSource = soundListItems; } }
private ObservableCollection <SoundListItem> GetSoundList() { ObservableCollection <SoundListItem> items = new ObservableCollection <SoundListItem>(); List <ISoundDetails> sounds = _soundEffectHolder.Sounds; foreach (ISoundDetails sound in sounds) { SoundListItem sli = new SoundListItem { SoundDetails = sound }; items.Add(sli); } _fullList = items; return(items); }
private void MapSoundSearchBox_TextChanged(object sender, TextChangedEventArgs e) { string searchText = MapSoundSearchBox.Text; MainListbox.Items.Filter = delegate(object obj) { SoundListItem unitdata = (SoundListItem)obj; string str = unitdata.FileName; if (String.IsNullOrEmpty(str)) { return(false); } int index = str.IndexOf(searchText, 0); return(index > -1); }; }
private void StarCraftSoundImport_Click(object sender, RoutedEventArgs e) { TreeViewItem titem = (TreeViewItem)MainTreeview.SelectedItem; if (titem != null) { if (titem.Items.Count == 0) { ComboBoxItem combo = (ComboBoxItem)SoundLan.SelectedItem; string lanstr = (string)combo.Tag; string filename = (string)titem.Tag; string lastname; //lanstr = lanstr.ToLower(); //filename = filename.ToLower(); lastname = lanstr + filename; byte[] buffer = data.ReadFile(lastname); if (buffer.Length == 0) { lastname = filename; buffer = data.ReadFile(filename); } if (buffer.Length == 0) { return; } lastname = lastname.Replace("/", "\\"); for (int i = 0; i < mapEditor.mapdata.WAV.Length; i++) { string d = mapEditor.mapdata.WAV[i].String; if (mapEditor.mapdata.WAV[i].IsLoaded) { if (lastname == d) { return; } } } for (int i = 0; i < mapEditor.mapdata.WAV.Length; i++) { string d = mapEditor.mapdata.WAV[i].String; if (!mapEditor.mapdata.WAV[i].IsLoaded) { mapEditor.mapdata.WAV[i].String = lastname; SoundListItem soundListItem = new SoundListItem(); soundListItem.FileName = lastname; soundListItem.Size = "외부파일"; soundListItems.Add(soundListItem); MainListbox.ItemsSource = null; MainListbox.ItemsSource = soundListItems; break; } } } } mapEditor.SetDirty(); }