The option.
Inheritance: BaseObject
コード例 #1
0
            /// <summary>
            /// The button 1_ click.
            /// </summary>
            /// <param name="sender">The sender.</param>
            /// <param name="e">The e.</param>
            /// <remarks></remarks>
            private void button1_Click(object sender, EventArgs e)
            {
                ControlSwapper parent = (ControlSwapper)this.Parent.Parent.Parent;

                // Add selected control
                IFPIO.Option[] options = null;
                //int strLength = 0;
                Control con = null;
                switch (((dataTypeStruct)comboBox1.SelectedItem).name.ToLower())
                {
                    /*
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Byte, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Short, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Int, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Float, parent.lineNum));
                */
                    case "byte":
                    case "short":
                    case "ushort":
                    case "int":
                    case "uint":
                    case "float":
                    case "unknown":
                    case "unused":
                        con = new DataValues(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            (IFPIO.ObjectEnum)
                            Enum.Parse(typeof(IFPIO.ObjectEnum), ((dataTypeStruct)comboBox1.SelectedItem).name, true),
                            parent.lineNum);
                        break;
                    case "char_enum":
                    case "enum":
                    case "long_enum":
                        options = new IFPIO.Option[((dataTypeStruct)comboBox1.SelectedItem).size << 3];

                        // Size * 8 bits
                        for (int x = 0; x < options.Length; x++)
                        {
                            options[x] = new IFPIO.Option("Bit " + x, x.ToString(), parent.lineNum);
                        }

                        if (parent.splitContainer1.Panel1.Controls[0] is Bitmask)
                        {
                            Bitmask b = (Bitmask)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in b.Options)
                            {
                                if (o.value < options.Length)
                                {
                                    options[o.value].name = o.name;
                                }
                            }
                        }

                        ;
                        if (parent.splitContainer1.Panel1.Controls[0] is Enums)
                        {
                            Enums en = (Enums)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in en.Options)
                            {
                                if (o.value < options.Length)
                                {
                                    options[o.value].name = o.name;
                                }
                            }
                        }

                        ;
                        con = new Enums(parent.name, null, parent.chunkoffset, options.Length, options, parent.lineNum);
                        break;
                    case "byte_flags":
                    case "word_flags":
                    case "long_flags":
                        options = new IFPIO.Option[((dataTypeStruct)comboBox1.SelectedItem).size << 3];

                        // Size * 8 bits
                        for (int x = 0; x < options.Length; x++)
                        {
                            options[x] = new IFPIO.Option("Bit " + x, x.ToString(), parent.lineNum);
                        }

                        if (parent.splitContainer1.Panel1.Controls[0] is Bitmask)
                        {
                            Bitmask b = (Bitmask)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in b.Options)
                            {
                                options[o.value].name = o.name;
                            }
                        }

                        ;
                        if (parent.splitContainer1.Panel1.Controls[0] is Enums)
                        {
                            Enums en = (Enums)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in en.Options)
                            {
                                options[o.value].name = o.name;
                            }
                        }

                        ;
                        con = new Bitmask(
                            parent.name, null, parent.chunkoffset, options.Length, options, parent.lineNum);
                        break;
                    case "stringid":
                        con = new SID(parent.name, null, parent.chunkoffset, parent.lineNum);
                        break;
                    case "string":
                        con = new EntStrings(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            ((dataTypeStruct)comboBox1.SelectedItem).size,
                            false,
                            parent.lineNum);
                        break;
                    case "unicodestring":
                        con = new EntStrings(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            ((dataTypeStruct)comboBox1.SelectedItem).size,
                            true,
                            parent.lineNum);
                        break;
                    case "block":
                        con = new TagBlock(parent.name, null, parent.chunkoffset, parent.lineNum);
                        break;
                    case "ident":
                        con = new Ident(parent.name, null, parent.chunkoffset, true, parent.lineNum);
                        break;
                    case "struct":

                        // Unhandled
                        //int ifkdn = 0;
                        break;
                    default:
                        {
                            return;
                        }
                }

                Button but = new Button();
                but.Dock = DockStyle.Right;
                but.Size = new Size(30, 30);
                but.Text = "-";
                but.Click += but_Click;

                if (con != null)
                {
                    con.Controls.Add(but);

                    // con.Enabled = false;
                    con.Dock = DockStyle.Top;
                    Point loc = con.Controls[con.Controls.Count - 2].Location;
                    loc.X -= 50;
                    con.Controls[con.Controls.Count - 2].Location = loc;

                    // con.TabIndex--;
                    parent.splitContainer1.Panel2.Controls.Add(con);
                    con.BringToFront();
                    ((ControlSwapper)this.TopLevelControl).newControlSize +=
                        ((ControlSwapper)this.TopLevelControl).getSizeOf(((dataTypeStruct)comboBox1.SelectedItem).name);
                    if (((ControlSwapper)this.TopLevelControl).label1.Text.Contains(" :: "))
                    {
                        ((ControlSwapper)this.TopLevelControl).label1.Text =
                            ((ControlSwapper)this.TopLevelControl).label1.Text.Remove(
                                ((ControlSwapper)this.TopLevelControl).label1.Text.IndexOf(" :: "));
                    }

                    ((ControlSwapper)this.TopLevelControl).label1.Text += " :: New Control Size : " +
                                                                          ((ControlSwapper)this.TopLevelControl).
                                                                              newControlSize;
                }

                parent.splitContainer1.Panel2.Controls[parent.splitContainer1.Panel2.Controls.IndexOf(this)].
                    BringToFront();
                parent.splitContainer1.Panel2.Controls[parent.splitContainer1.Panel2.Controls.IndexOf(this)].TabIndex++;
            }
コード例 #2
0
        /// <summary>
        /// The field type changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void fieldTypeChanged(object sender, EventArgs e)
        {
            // Get original data
            Control c = ((Control)sender).Parent;
            int origPlacement = c.Parent.Controls.IndexOf(c);
            Control origParent = c.Parent;

            ControlSwapper cs = new ControlSwapper(c);
            cs.ShowDialog();
            string name = string.Empty;
            int offset = -1;
            int chunkoffset = -1;
            int lineNum = -1;
            int sizeCount = 0;

            //////
            c.Enabled = true;
            origParent.Controls.Add(c);
            origParent.Controls.SetChildIndex(c, origPlacement);
            return;

            /////

            switch (c.ToString())
            {
                case "Entity.MetaEditor.Bitmask":
                    Bitmask bt = (Bitmask)c;
                    name = bt.EntName;
                    offset = bt.offsetInMap;
                    chunkoffset = bt.chunkOffset;
                    lineNum = bt.LineNumber;
                    sizeCount = bt.bitCount >> 3;
                    break;
                case "Entity.MetaEditor.DataValues":
                    DataValues dv = (DataValues)c;
                    name = dv.EntName;
                    offset = dv.offsetInMap;
                    chunkoffset = dv.chunkOffset;
                    lineNum = dv.LineNumber;
                    switch (dv.ValueType)
                    {
                        case IFPIO.ObjectEnum.Byte:
                            // case DataValues.ENTType.ub:
                            sizeCount = 1;
                            break;
                        case IFPIO.ObjectEnum.Short:
                        case IFPIO.ObjectEnum.UShort:
                            sizeCount = 2;
                            break;
                        case IFPIO.ObjectEnum.Float:
                        case IFPIO.ObjectEnum.Int:
                        case IFPIO.ObjectEnum.UInt:
                            sizeCount = 4;
                            break;
                    }

                    break;
            }

            Control c2 = null;
            switch (((string)((ComboBox)sender).SelectedItem).ToLower())
            {
                case "byte":
                    if (sizeCount < 1)
                    {
                        break;
                    }

                    DataValues dv = new DataValues(name, map, chunkoffset, IFPIO.ObjectEnum.Byte, lineNum);
                    dv.Controls.RemoveAt(dv.Controls.Count - 1);
                    c2 = dv;
                    sizeCount -= 1;
                    break;
                case "short":
                    if (sizeCount < 2)
                    {
                        break;
                    }

                    dv = new DataValues(name, map, chunkoffset, IFPIO.ObjectEnum.Short, lineNum);
                    dv.Controls.RemoveAt(dv.Controls.Count - 1);
                    c2 = dv;
                    sizeCount -= 2;
                    break;
                case "int":
                    if (sizeCount < 4)
                    {
                        break;
                    }

                    dv = new DataValues(name, map, chunkoffset, IFPIO.ObjectEnum.Int, lineNum);
                    dv.Controls.RemoveAt(dv.Controls.Count - 1);
                    c2 = dv;
                    sizeCount -= 4;
                    break;
                case "float":
                    if (sizeCount < 4)
                    {
                        break;
                    }

                    dv = new DataValues(name, map, chunkoffset, IFPIO.ObjectEnum.Float, lineNum);
                    dv.Controls.RemoveAt(dv.Controls.Count - 1);
                    c2 = dv;
                    sizeCount -= 4;
                    break;
                case "byte_flags":
                    if (sizeCount < 1)
                    {
                        break;
                    }

                    IFPIO.Option[] options = new IFPIO.Option[8];
                    for (int x = 0; x < 8; x++)
                    {
                        options[x] = new IFPIO.Option("bit " + x, x.ToString(), lineNum);
                    }

                    Bitmask bt = new Bitmask(name, map, chunkoffset, 8, options, lineNum);
                    bt.Controls.RemoveAt(bt.Controls.Count - 1);
                    c2 = bt;
                    sizeCount -= 1;
                    break;
                case "word_flags":
                    if (sizeCount < 2)
                    {
                        break;
                    }

                    options = new IFPIO.Option[16];
                    for (int x = 0; x < 16; x++)
                    {
                        options[x] = new IFPIO.Option("bit " + x, x.ToString(), lineNum);
                    }

                    bt = new Bitmask(name, map, chunkoffset, 16, options, lineNum);
                    bt.Controls.RemoveAt(bt.Controls.Count - 1);
                    c2 = bt;
                    sizeCount -= 2;
                    break;
                case "long_flags":
                    if (sizeCount < 4)
                    {
                        break;
                    }

                    options = new IFPIO.Option[32];
                    for (int x = 0; x < 32; x++)
                    {
                        options[x] = new IFPIO.Option("bit " + x, x.ToString(), lineNum);
                    }

                    bt = new Bitmask(name, map, chunkoffset, 32, options, lineNum);
                    bt.Controls.RemoveAt(bt.Controls.Count - 1);
                    c2 = bt;
                    sizeCount -= 4;
                    break;
            }

            if (c2 != null && sizeCount == 0)
            {
                c2.TabIndex = c.TabIndex;
                c2.Location = c.Location;
                c.Parent.Controls.Add(c2);
                c.Parent.Controls.SetChildIndex(c2, c.Parent.Controls.GetChildIndex(c));
                c2.Controls.Add((ComboBox)sender);
                c.Parent.Controls.Remove(c);
                c = c2.Parent;
                while (!(c is MetaEditor))
                {
                    c = c.Parent;
                }

                ((MetaEditor)c).ReloadMetaForSameTagType(true);
            }
        }