Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool accept = false;
            Form prompt = new Form();

            prompt.Width           = 500;
            prompt.Height          = 150;
            prompt.FormBorderStyle = FormBorderStyle.FixedDialog;
            prompt.MinimizeBox     = false;
            prompt.MaximizeBox     = false;
            prompt.ShowInTaskbar   = false;
            prompt.Text            = "Select location";
            Label textLabel = new Label()
            {
                Left = 50, Top = 20, Text = "Select where to insert subroutine."
            };

            textLabel.AutoSize = true;
            ComboBox comboBox = new ComboBox()
            {
                Left = 50, Top = 50, Width = 400
            };

            comboBox.Items.AddRange(listBox1.Items.Cast <string>().ToArray());
            comboBox.Items.Add("End of file");
            comboBox.SelectedIndex = 0;

            NumericUpDown inputBox = new NumericUpDown()
            {
                Left = 50, Top = 50, Width = 400
            };
            Button confirmation = new Button()
            {
                Text = "OK", Left = 125, Width = 100, Top = 85
            };

            confirmation.Click += (a, b) => { prompt.Close(); accept = true; };
            Button cancel = new Button()
            {
                Text = "Cancel", Left = 250, Width = 100, Top = 85
            };

            cancel.Click += (a, b) => { prompt.Close(); };
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(comboBox);
            prompt.Controls.Add(cancel);
            prompt.ShowDialog();
            if (accept && comboBox.SelectedIndex != -1)
            {
                ScriptFile.subroutine sub = new ScriptFile.subroutine();
                sub.subType = 0x4C;
                internalFile.subroutines.Insert(comboBox.SelectedIndex, sub);
                listBox1.Items.Insert(comboBox.SelectedIndex, internalFile.subroutines[comboBox.SelectedIndex].name);
                forceChange            = true;
                listBox1.SelectedIndex = comboBox.SelectedIndex;
            }
        }
Пример #2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1 && (listBox1.SelectedIndex != prevIndex || forceChange))
            {
                forceChange = false;
                prevIndex   = listBox1.SelectedIndex;
                ScriptFile.subroutine currentSub = (ScriptFile.subroutine)internalFile.subroutines[listBox1.SelectedIndex];
                changing      = true;
                textBox1.Text = currentSub.name;
                if (currentSub.subType == 0x4C)
                {
                    comboBox1.SelectedIndex = 1;
                    dataGridView2.Enabled   = true;
                }
                else
                {
                    comboBox1.SelectedIndex = 0;
                    dataGridView2.Enabled   = false;
                }
                dataGridView2.AutoGenerateColumns = false;
                BindingSource binder = new BindingSource();
                binder.DataSource             = currentSub.opcodes;
                dataGridView2.DataSource      = binder;
                IntColumn.DataPropertyName    = "intArg";
                StringColumn.DataPropertyName = "strArg";
                FloatColumn.DataPropertyName  = "floatArg";
                OpcodeColumn.DataPropertyName = "opcodeName";

                /*
                 * dataGridView1.Rows.Clear();
                 *
                 * if (currentSub.opcodes.Count > 0)
                 * {
                 *  dataGridView1.Rows.Add(currentSub.opcodes.Count);
                 *  for (int i = 0; i < currentSub.opcodes.Count; i++)
                 *  {
                 *      dataGridView1[0, i].Value = internalFile.opcodes[((ScriptFile.operation)currentSub.opcodes[i]).opcode];
                 *      if (internalFile.opcodeTypes[((ScriptFile.operation)currentSub.opcodes[i]).opcode] == 1) // 1 = no args
                 *      {
                 *          dataGridView1[1, i].ReadOnly = true;
                 *          dataGridView1[2, i].ReadOnly = true;
                 *          dataGridView1[3, i].ReadOnly = true;
                 *      }
                 *      else if (internalFile.opcodeTypes[((ScriptFile.operation)currentSub.opcodes[i]).opcode] == 2) // 2 = int
                 *      {
                 *          dataGridView1[1, i].ReadOnly = true;
                 *          dataGridView1[2, i].ReadOnly = false;
                 *          dataGridView1[3, i].ReadOnly = true;
                 *          dataGridView1[2, i].Value = ((ScriptFile.operation)currentSub.opcodes[i]).intArg;
                 *      }
                 *      else if (internalFile.opcodeTypes[((ScriptFile.operation)currentSub.opcodes[i]).opcode] == 3) // 3 = float
                 *      {
                 *          dataGridView1[1, i].ReadOnly = false;
                 *          dataGridView1[2, i].ReadOnly = true;
                 *          dataGridView1[3, i].ReadOnly = true;
                 *          dataGridView1[1, i].Value = ((ScriptFile.operation)currentSub.opcodes[i]).floatArg;
                 *      }
                 *      else // 4/99 = string
                 *      {
                 *          dataGridView1[1, i].ReadOnly = true;
                 *          dataGridView1[2, i].ReadOnly = true;
                 *          dataGridView1[3, i].ReadOnly = false;
                 *          dataGridView1[3, i].Value = ((ScriptFile.operation)currentSub.opcodes[i]).strArg;
                 *      }
                 *  }
                 * }
                 */
                changing = false;
            }
        }