private void PopulateBuildEditor(Build build) { if (build != null) { if (build.Race.Equals(TERRAN)) { RaceBox.SelectedIndex = 0; } else if (build.Race.Equals(PROTOSS)) { RaceBox.SelectedIndex = 1; } else if (build.Race.Equals(ZERG)) { RaceBox.SelectedIndex = 2; } if (build.Versus.Equals(TERRAN)) { MatchupBox.SelectedIndex = 0; } else if (build.Versus.Equals(PROTOSS)) { MatchupBox.SelectedIndex = 1; } else if (build.Versus.Equals(ZERG)) { MatchupBox.SelectedIndex = 2; } NameBox.Text = build.Name; BuildSpecTextBox.Text = ""; foreach (Step S in build.Steps) { if (S.Equals(Step.ErrorStep)) { BuildSpecTextBox.AppendText(INVALID_STEP_COMMAND + "\n"); } else { BuildSpecTextBox.AppendText(S.RawString() + "\n"); } } } }
/******************************** User Interface Events ********************************/ /************************************************************************************************************ * * Build Specification Formatting * ************************************************************************************************************/ private void FormatEditorContents() { string text = BuildSpecTextBox.Text; bool formatOn = false; int selectStart, selectLength; int formatStart = -1, formatLength = -1; Font formatFont = new Font(BuildSpecTextBox.Font.Name, BuildSpecTextBox.Font.Size - 1f, FontStyle.Italic | BuildSpecTextBox.Font.Style); selectStart = BuildSpecTextBox.SelectionStart; selectLength = BuildSpecTextBox.SelectionLength; BuildSpecTextBox.Enabled = false; BuildSpecTextBox.SelectionStart = 0; BuildSpecTextBox.SelectionLength = BuildSpecTextBox.Text.Length; BuildSpecTextBox.SelectionFont = BuildSpecTextBox.Font; BuildSpecTextBox.SelectionColor = BuildSpecTextBox.ForeColor; for (int i = 0; i < text.Length; i++) { if (text[i] == '}') { formatOn = false; BuildSpecTextBox.SelectionStart = formatStart; BuildSpecTextBox.SelectionLength = formatLength; BuildSpecTextBox.SelectionFont = formatFont; BuildSpecTextBox.SelectionColor = Color.Gray; } if (formatOn) { formatLength++; } if (text[i] == '{') { formatOn = true; formatStart = i + 1; formatLength = 0; } } BuildSpecTextBox.Enabled = true; BuildSpecTextBox.Select(); BuildSpecTextBox.SelectionStart = selectStart; BuildSpecTextBox.SelectionLength = selectLength; }