private void SetTuningCombo(TuningStrings tuningStrings, bool isBass = false) { //Detect tuning TuningDefinition tuning = TuningDefinitionRepository.Instance().SelectAny(tuningStrings, currentGameVersion); //Create tuning if (tuning == null) { using (var form = new TuningForm()) { tuning = new TuningDefinition(); tuning.Tuning = tuningStrings; tuning.Custom = true; tuning.GameVersion = currentGameVersion; tuning.Name = tuning.UIName = tuning.NameFromStrings(tuningStrings, isBass); form.Tuning = tuning; form.IsBass = isBass; if (DialogResult.OK != form.ShowDialog()) { return; } FillTuningCombo(); } } //Set tuning tuningComboBox.SelectedItem = tuning; }
private void tuningEditButton_Click(object sender, EventArgs e) { var selectedType = ((ArrangementType)((ComboBox)arrangementTypeCombo).SelectedItem); TuningDefinition tuning = (TuningDefinition)tuningComboBox.SelectedItem; if (tuning == null) { MessageBox.Show("At least one tuning definition is needed to edit.\r\n (Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var form = new TuningForm()) { form.Tuning = tuning; form.IsBass = selectedType == ArrangementType.Bass; form.EditMode = true; var oldUIName = tuning.UIName.Clone().ToString(); //Important to set it here if (DialogResult.OK != form.ShowDialog()) { return; } if (oldUIName != form.Tuning.UIName && !form.AddNew) { // Update LB slots if tuning name are changed for (int i = 0; i < parentControl.ArrangementLB.Items.Count; i++) { var selectedArrangement = (Arrangement)parentControl.ArrangementLB.Items[i]; if (oldUIName.Equals(selectedArrangement.Tuning)) { selectedArrangement.Tuning = form.Tuning.UIName; parentControl.ArrangementLB.Items[i] = selectedArrangement; } } } //Update from xml definition tuning = form.Tuning; tuning = TuningDefinitionRepository.Instance().SelectAny(tuning.Tuning, tuning.GameVersion); FillTuningCombo(); tuningComboBox.SelectedItem = tuning; Arrangement.TuningStrings = tuning.Tuning; } }
private void tuningEditButton_Click(object sender, EventArgs e) { var selectedType = ((ArrangementType)((ComboBox)arrangementTypeCombo).SelectedItem); TuningDefinition selectedTuning = (TuningDefinition)tuningComboBox.SelectedItem; if (selectedTuning == null) { MessageBox.Show("At least one tuning definition is needed to edit.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var form = new TuningForm()) { form.Tuning = selectedTuning; form.IsBass = selectedType == ArrangementType.Bass; form.EditMode = true; var oldUIName = selectedTuning.UIName.Clone().ToString(); if (DialogResult.OK != form.ShowDialog()) { return; } if (oldUIName != form.Tuning.UIName) { // Update LB slots if name are changed for (int i = 0; i < parentControl.ArrangementLB.Items.Count; i++) { var arrangement = (Arrangement)parentControl.ArrangementLB.Items[i]; if (oldUIName.Equals(arrangement.Tuning)) { arrangement.Tuning = form.Tuning.UIName; parentControl.ArrangementLB.Items[i] = arrangement; } } } FillTuningCombo(); tuningComboBox.SelectedItem = (form.IsBass) ? TuningDefinitionRepository.Instance().SelectForBass(form.Tuning.Tuning, currentGameVersion) : TuningDefinitionRepository.Instance().Select(form.Tuning.Tuning, currentGameVersion); } }
private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning) { if (tuning == null) { MessageBox.Show("Pick a tuning definition to start editing.\r\n (Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool addNew; TuningDefinition formTuning; using (var form = new TuningForm()) { form.Tuning = tuning; form.IsBass = selectedType == ArrangementType.Bass; if (DialogResult.OK != form.ShowDialog()) { return; } // prevent any further SET calls to form.Tuning formTuning = form.Tuning; addNew = form.AddNew; } if (tuning.UIName != formTuning.UIName) { // Update LB slots if tuning name is changed for (int i = 0; i < parentControl.arrangementLB.Items.Count; i++) { var selectedArrangement = (Arrangement)parentControl.arrangementLB.Items[i]; if (tuning.UIName.Equals(selectedArrangement.Tuning)) { selectedArrangement.Tuning = formTuning.UIName; parentControl.arrangementLB.Items[i] = selectedArrangement; } } } // TODO: figure out logic behind unexpected LINQ behaviors // tuningComboBox list is being updated with custom tuning info // so refilling the combobox is required to produce the expected results // for now using old fashioned non-LINQ method FillTuningCombo(selectedType, currentGameVersion); int foundTuning = -1; tuningComboBox.SelectedIndex = -1; for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++) { tuningComboBox.SelectedIndex = tcbIndex; tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex]; if (tuning.Tuning == formTuning.Tuning) { foundTuning = tcbIndex; break; } } // add the custom tuning to tuningComboBox if (foundTuning == -1) { formTuning.Custom = true; tuningComboBox.Items.Add(formTuning); tuningComboBox.SelectedIndex = tuningComboBox.Items.Count - 1; if (addNew) { SaveTuningDefinition(formTuning); } } else { tuningComboBox.SelectedIndex = foundTuning; } tuningComboBox.Refresh(); Arrangement.TuningStrings = formTuning.Tuning; // forces SET update }
private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning) { if (tuning == null) { MessageBox.Show("Pick a tuning definition to start editing.\r\n (DEBUG: Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // get the latest comments from the XML to check if previous bass fixed is valid if (!String.IsNullOrEmpty(Arrangement.SongXml.File) && selectedType == ArrangementType.Bass) { //var debugMe = ""; var xmlComments = Song2014.ReadXmlComments(Arrangement.SongXml.File); var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00; // commented out ... Arrangement.XmlComments may not be populated // var isBassFixed = Arrangement.XmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00; if (isBassFixed && !tuning.UIName.Contains("Fixed")) { // UIName may contain spaces, where as Name contains no spaces tuning.UIName = String.Format("{0} Fixed", tuning.UIName); tuning.Name = tuning.UIName.ReplaceSpaceWith(""); tuning.Custom = true; // fixed bass tuning definition is auto added to repository TuningDefinitionRepository.SaveUnique(tuning); } } bool addNew; TuningDefinition formTuning; using (var form = new TuningForm()) { form.Tuning = tuning; form.IsBass = selectedType == ArrangementType.Bass; if (DialogResult.OK != form.ShowDialog()) return; // prevent any further SET calls to form.Tuning formTuning = form.Tuning; addNew = form.AddNew; } if (tuning.UIName != formTuning.UIName) { // Update lstArrangements slots if tuning name is changed for (int i = 0; i < _parentControl.lstArrangements.Items.Count; i++) { var selectedArrangement = (Arrangement)_parentControl.lstArrangements.Items[i]; if (tuning.UIName.Equals(selectedArrangement.Tuning)) { selectedArrangement.Tuning = formTuning.UIName; _parentControl.lstArrangements.Items[i] = selectedArrangement; } } } FillTuningCombo(_gameVersion); int foundTuning = -1; cmbTuningName.SelectedIndex = -1; for (int tcbIndex = 0; tcbIndex < cmbTuningName.Items.Count; tcbIndex++) { cmbTuningName.SelectedIndex = tcbIndex; tuning = (TuningDefinition)cmbTuningName.Items[tcbIndex]; // check at least tuning strings and name match if (tuning.Tuning == formTuning.Tuning && tuning.Name == formTuning.Name) { foundTuning = tcbIndex; break; } } // add the custom tuning to tuningComboBox if (foundTuning == -1) { if (addNew) TuningDefinitionRepository.SaveUnique(formTuning); formTuning.Custom = true; cmbTuningName.Items.Add(formTuning); cmbTuningName.SelectedIndex = cmbTuningName.Items.Count - 1; } else cmbTuningName.SelectedIndex = foundTuning; cmbTuningName.Refresh(); Arrangement.TuningStrings = formTuning.Tuning; Arrangement.Tuning = formTuning.UIName; }
private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning) { if (tuning == null) { MessageBox.Show("Pick a tuning definition to start editing.\r\n (Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool addNew; TuningDefinition formTuning; using (var form = new TuningForm()) { form.Tuning = tuning; form.IsBass = selectedType == ArrangementType.Bass; if (DialogResult.OK != form.ShowDialog()) return; // prevent any further SET calls to form.Tuning formTuning = form.Tuning; addNew = form.AddNew; } if (tuning.UIName != formTuning.UIName) { // Update LB slots if tuning name is changed for (int i = 0; i < parentControl.arrangementLB.Items.Count; i++) { var selectedArrangement = (Arrangement)parentControl.arrangementLB.Items[i]; if (tuning.UIName.Equals(selectedArrangement.Tuning)) { selectedArrangement.Tuning = formTuning.UIName; parentControl.arrangementLB.Items[i] = selectedArrangement; } } } // TODO: figure out logic behind unexpected LINQ behaviors // tuningComboBox list is being updated with custom tuning info // so refilling the combobox is required to produce the expected results // for now using old fashioned non-LINQ method FillTuningCombo(selectedType, currentGameVersion); int foundTuning = -1; tuningComboBox.SelectedIndex = -1; for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++) { tuningComboBox.SelectedIndex = tcbIndex; tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex]; if (tuning.Tuning == formTuning.Tuning) { foundTuning = tcbIndex; break; } } // add the custom tuning to tuningComboBox if (foundTuning == -1) { formTuning.Custom = true; tuningComboBox.Items.Add(formTuning); tuningComboBox.SelectedIndex = tuningComboBox.Items.Count - 1; if (addNew) SaveTuningDefinition(formTuning); } else tuningComboBox.SelectedIndex = foundTuning; tuningComboBox.Refresh(); Arrangement.TuningStrings = formTuning.Tuning; // forces SET update }