Exemplo n.º 1
0
        /// <summary>
        ///  If a rule is selected from the parent GUI Fretlight, then this constructor is called instead to fill in the fields of the rule
        /// </summary>
        public RuleBuilderGUI(Rule selectedRule)
            : this()
        {
            Rule = selectedRule;

            // Fill boxes
            NameBox.Text = selectedRule.RuleName;
            StartFrameField.Text = selectedRule.StartFrame.ToString();
            EndFrameField.Text = selectedRule.EndFrame.ToString();
            StartPointField.Text = selectedRule.StartPoint[0] + ", " + selectedRule.StartPoint[1];
            EndPointField.Text = selectedRule.EndPoint[0] + ", " + selectedRule.EndPoint[1];
            RuleTypeBox.Text = selectedRule.RuleType;

            // Arrange LED
            this.StartPoint[0] = selectedRule.StartPoint[0];
            this.StartPoint[1] = selectedRule.StartPoint[1];
            this.EndPoint[0] = selectedRule.EndPoint[0];
            this.EndPoint[1] = selectedRule.EndPoint[1];
            this.FretBoard.Invalidate();
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Builds the Rule according to the fields set, has default values if the fields are empty or invalid
        /// </summary>
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            int result;

            if (RuleType.Equals("Basic"))
                Rule = new BasicRule();
            else if (RuleType.Equals("Conway"))
                Rule = new Conway();

            if(! int.TryParse(StartFrameField.Text, out result)){
                result = 0;
            }
            Rule.StartFrame = result;

            if (!int.TryParse(EndFrameField.Text, out result))
            {
                result = 0;
            }

            Rule.EndFrame = result;

            Rule.StartPoint[0] = this.StartPoint[0];
            Rule.StartPoint[1] = this.StartPoint[1];

            Rule.EndPoint[0] = this.EndPoint[0];
            Rule.EndPoint[1] = this.EndPoint[1];
            Rule.RuleName = NameBox.Text;
            this.Close();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves rules to a file
        /// </summary>
        private void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Rule[]));

                // Convert listbox content to array for serialization
                Rule[] ruleArray = new Rule[RulesListbox.Items.Count];
                int counter = 0;
                foreach (Rule n in RulesListbox.Items)
                {
                    ruleArray[counter] = n;
                    counter++;
                }

                // this process will open a save file dialog and give the option to choose
                // file location, name, and ext.  then when you press save it will save it
                FileDialog oDialog = new SaveFileDialog();

                oDialog.InitialDirectory = Environment.CurrentDirectory;
                oDialog.DefaultExt = "xml";
                oDialog.FileName = "Rules";
                oDialog.RestoreDirectory = true;

                if (oDialog.ShowDialog() == DialogResult.OK)
                {
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@oDialog.FileName))
                    {
                        serializer.Serialize(file, ruleArray);
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("" + exp);
            }
        }