Пример #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            TableLayoutPanel[] tables = { tableLayoutPanel1, tableLayoutPanel2, tableLayoutPanel3, tableLayoutPanel4 };
            if (!File.Exists("opts.ini"))
            {
                MessageBox.Show(this, "Failed to load opts.ini.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }
            foreach (KeyValuePair <string, TrackOptInfo> item in IniSerializer.Deserialize <Dictionary <string, TrackOptInfo> >("opts.ini"))
            {
                TrackOptions.Add(new TrackInfoInternal(item.Key, item.Value.Name, item.Value.EnableByZone, item.Value.EnableByCharacter));
            }
            if (File.Exists("Music.ini"))
            {
                settings = IniSerializer.Deserialize <Settings>("Music.ini");
            }
            else
            {
                settings = new Settings();
            }
            soundfontTextBox.Text = settings.MIDISoundFont;
            for (int gn = 0; gn < GameIDs.Length; gn++)
            {
                string game = GameIDs[gn];
                if (!settings.Music.ContainsKey(game))
                {
                    settings.Music.Add(game, new SettingsGame());
                }
                SettingsGame     group = settings.Music[game];
                TableLayoutPanel table = tables[gn];
                table.SuspendLayout();
                textboxes[gn] = new List <TextBox>();
                for (int tn = 0; tn < TrackOptions.Count; tn++)
                {
                    string track = TrackOptions[tn].Key;
                    table.Controls.Add(new Label()
                    {
                        Text = TrackOptions[tn].Name + ":", AutoSize = true, TextAlign = ContentAlignment.MiddleLeft
                    }, 0, tn);
                    List <string> list = new List <string>()
                    {
                        "MIDI"
                    };
                    if (gn == 1)
                    {
                        if (TrackOptions[tn].EnableByCharacter)
                        {
                            list.Add("ByCharacter");
                        }
                        if (TrackOptions[tn].EnableByZone)
                        {
                            list.Add("ByZone");
                        }
                    }
                    list.AddRange(smpsSongs);
                    TextBox tb = new TextBox()
                    {
                        AutoCompleteMode = AutoCompleteMode.Suggest, AutoCompleteSource = AutoCompleteSource.CustomSource, Width = 300
                    };
                    tb.AutoCompleteCustomSource = new AutoCompleteStringCollection();
                    tb.AutoCompleteCustomSource.AddRange(list.ToArray());
                    tb.AutoCompleteCustomSource.AddRange(Directory.EnumerateFiles(Environment.CurrentDirectory).Where(a =>
                    {
                        switch (Path.GetExtension(a).ToLowerInvariant())
                        {
                        case ".exe":
                        case ".dll":
                        case ".pdb":
                        case ".config":
                        case ".ini":
                        case ".txt":
                            return(false);

                        default:
                            return(true);
                        }
                    }).Select(a => a.Substring(Environment.CurrentDirectory.Length + 1)).ToArray());
                    table.Controls.Add(tb, 1, tn);
                    textboxes[gn].Add(tb);
                    Button btn = new Button()
                    {
                        AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Text = "List..."
                    };
                    btn.Click += new EventHandler((s, ev) =>
                    {
                        using (ListDialog dlg = new ListDialog(list))
                            if (dlg.ShowDialog(this) == DialogResult.OK)
                            {
                                tb.Text = dlg.SelectedItem;
                            }
                    });
                    table.Controls.Add(btn, 2, tn);
                    btn = new Button()
                    {
                        AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Text = "File..."
                    };
                    btn.Click += new EventHandler((s, ev) =>
                    {
                        using (OpenFileDialog dlg = new OpenFileDialog()
                        {
                            Filter = "Common Music Files|*.mid;*.midi;*.adx;*.aax;*.brstm;*.bcstm;*.ogg;*.mp3;*.logg;*.wav|All Files|*.*", InitialDirectory = Environment.CurrentDirectory, RestoreDirectory = true
                        })
                            if (dlg.ShowDialog(this) == DialogResult.OK)
                            {
                                string fn = dlg.FileName;
                                if (fn.StartsWith(Environment.CurrentDirectory))
                                {
                                    fn = fn.Substring(Environment.CurrentDirectory.Length + 1);
                                }
                                tb.Text = fn;
                            }
                    });
                    table.Controls.Add(btn, 3, tn);
                    if (!group.Tracks.ContainsKey(track))
                    {
                        group.Tracks.Add(track, string.Empty);
                    }
                    else
                    {
                        tb.Text = group.Tracks[track];
                    }
                    if (tn > 0)
                    {
                        table.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                    }
                    tb.TextChanged += new EventHandler((s, ev) => group.Tracks[track] = tb.Text);
                }
                table.ResumeLayout();
            }
        }