private void GeneratePlace_Click(object sender, EventArgs e) { Place.ForeColor = Color.Black; int cnt = 0; for (int i = 0; i <= (MapListBox.Items.Count - 1); i++) { if (MapListBox.GetItemChecked(i)) { cnt = (i + 1); } } if (cnt >= 2) { for (i = 0; i <= (MapListBox.Items.Count - 1); i++) { if (MapListBox.GetItemChecked(i)) { MapList.Add(MapListBox.Items[i].ToString()); } } result = Convert.ToString((string)MapList[random.Next(0, MapList.Count)]); DesidePlace.Start(); } else { MessageBox.Show("2つ以上の選択が必要", "Error"); } }
private void LoadMaps(string dir) { DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { throw new Exception("Could not locate map folder"); } maps_.Clear(); fmfs_.Clear(); obss_.Clear(); try { var files = di.GetFiles("*.json", SearchOption.AllDirectories); Regex rx = new Regex(@"[\\/]+(?<id>\d{3})[\\/]+(\k<id>)\.json$", RegexOptions.Compiled | RegexOptions.IgnoreCase); Parallel.ForEach(files, file => { var match = rx.Match(file.FullName); if (match.Success) { var fmf = file.FullName.Replace(".json", "_fmf.json"); var obs = file.FullName.Replace(".json", "_obs.json"); if (!File.Exists(fmf) || !File.Exists(obs)) { return; } var id = int.Parse(match.Groups["id"].Value); Parallel.Invoke(() => { LoadMad(file.FullName, id); }, () => { LoadFmf(fmf, id); }, () => { LoadObs(obs, id); }); } }); } catch (Exception e) { throw new Exception("Error iterating map folder: " + e.Message); } maps_.Sort((MadJson x, MadJson y) => { return(x.id.CompareTo(y.id)); }); fmfs_.Sort((FmfJson x, FmfJson y) => { return(x.id.CompareTo(y.id)); }); obss_.Sort((ObsJson x, ObsJson y) => { return(x.id.CompareTo(y.id)); }); MapListBox.ClearSelected(); MapListBox.Items.Clear(); MapNameTextBox.Clear(); MapFilenameTextBox.Clear(); ClearEncounter(); fmf_data_ = null; obs_data_ = null; map_layers_ = new byte[13][]; selected_map_ = -1; foreach (var map in maps_) { MapListBox.Items.Add(map.location_name); } MapMusicCB.SelectedIndex = -1; MapMusicCB.Items.Clear(); MapMusicCB.DisplayMember = "Item1"; MapMusicCB.ValueMember = "Item2"; foreach (var bgm in bgm_data_) { MapMusicCB.Items.Add(new Tuple <string, uint>(bgm.Value, bgm.Key)); } }