-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundSelector.cs
75 lines (64 loc) · 2.04 KB
/
SoundSelector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.IO;
namespace ED7Editor
{
public partial class SoundSelector : Form
{
public SoundSelector()
{
InitializeComponent();
var path = Properties.Settings.Default.ED7Path + @"\data\se";
int pos = path.Length + @"\ed7v".Length;
foreach (var se in Directory.GetFiles(path))
listBox1.Items.Add(new SE { name = se.Substring(pos, 4), path = se });
}
SoundPlayer soundPlayer = new SoundPlayer();
public void SetSelect(ushort id)
{
initValue = id;
for (int i = 0; i < listBox1.Items.Count; i++)
if (int.Parse((listBox1.Items[i] as SE).name) == id)
listBox1.SelectedIndex = i;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var se = listBox1.SelectedItem as SE;
if (se == null) return;
var path = se.path;
soundPlayer.Stop();
soundPlayer.SoundLocation = path;
soundPlayer.Play();
Result = ushort.Parse(se.name);
}
private void SoundSelector_Load(object sender, EventArgs e)
{
}
public ushort Result { get; private set; }
ushort? initValue = null;
private void btnOK_Click(object sender, EventArgs e)
{
if (Result == initValue) DialogResult = DialogResult.Cancel;
DialogResult = DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
class SE
{
public string name;
public string path;
public override string ToString()
{
return name;
}
}
}