コード例 #1
0
        public static AnimDataStruct AddEvent(AnimDataStruct animData)
        {
            TAE.EventStruct newEvent = new TAE.EventStruct();

            newEvent.parameters = new List <byte[]> {
            };
            newEvent.parameters.Add(new byte[4] {
                0x0, 0x0, 0x0, 0x0
            });
            newEvent.parameters.Add(new byte[4] {
                0x0, 0x0, 0x0, 0x0
            });
            newEvent.parameters.Add(new byte[4] {
                0xFF, 0xFF, 0xFF, 0xFF
            });

            animData.events.Add(newEvent);
            animData.eventCount++;

            return(animData);
        }
コード例 #2
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int eventIndex = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

            TAE.EventStruct Event = tae.data.animDatas[listBox1.SelectedIndex].events[eventIndex];

            if (e.ColumnIndex == 1)
            {
                int paramCount = 0;

                if (Helper.ok)
                {
                    bool found = false;
                    int  index = 0;
                    uint value = 0;

                    if (!uint.TryParse((string)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, out value))
                    {
                        MessageBox.Show("Invalid value for this type. Type of this cell:\n\nuint");
                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Event.eventType.ToString();
                        return;
                    }
                    else
                    {
                        while (!found && index < Helper.helpers.Count)
                        {
                            if (Helper.helpers[index].id == value)
                            {
                                paramCount = Helper.helpers[index].parameterTypes.Count;
                                found      = true;
                            }
                            else
                            {
                                index++;
                            }
                        }
                    }
                }
                else
                {
                    int value = 0;
                    if (!int.TryParse((string)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, out value))
                    {
                        MessageBox.Show("Invalid value for this type. Type of this cell:\n\nint");
                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Event.eventType.ToString();
                        return;
                    }
                    else
                    {
                        switch (value)
                        {
                        case 32:
                        case 33:
                        case 65:
                        case 66:
                        case 67:
                        case 101:
                        case 110:
                        case 145:
                        case 224:
                        case 225:
                        case 226:
                        case 229:
                        case 231:
                        case 232:
                        case 301:
                        case 302:
                        case 308:
                        case 401:
                            paramCount = 1;
                            break;

                        case 5:
                        case 64:
                        case 112:
                        case 121:
                        case 128:
                        case 193:
                        case 233:
                        case 304:
                            paramCount = 2;
                            break;

                        case 0:
                        case 1:
                        case 96:
                        case 100:
                        case 104:
                        case 109:
                        case 114:
                        case 115:
                        case 116:
                        case 118:
                        case 144:
                        case 228:
                        case 236:
                        case 307:
                            paramCount = 3;
                            break;

                        case 2:
                        case 16:
                        case 24:
                        case 130:
                        case 300:
                            paramCount = 4;
                            break;

                        case 120:
                            paramCount = 6;
                            break;

                        case 8:
                            paramCount = 12;
                            break;

                        default:
                            paramCount = 0;
                            break;
                        }
                    }
                }

                dataGridView1.Rows[e.RowIndex].Cells[2].Value = paramCount;

                while (paramCount + 5 > dataGridView1.ColumnCount)
                {
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.Name       = "Column" + (dataGridView1.ColumnCount - 4);
                    column.HeaderText = "Parameter #" + (dataGridView1.ColumnCount - 4);
                    column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    column.CellTemplate = new DataGridViewTextBoxCell();

                    dataGridView1.Columns.Add(column);
                }

                /*
                 * for (int i = 0; i < paramCount; i++)
                 * {
                 *  dataGridView1.Rows[e.RowIndex].Cells[i + 5].Value = "0";
                 * }
                 */

                for (int i = 0; i < dataGridView1.ColumnCount - 5; i++)
                {
                    if (i < paramCount)
                    {
                        dataGridView1.Rows[e.RowIndex].Cells[i + 5].Value = "0";
                    }
                    else
                    {
                        dataGridView1.Rows[e.RowIndex].Cells[i + 5] = new DataGridViewTextBoxCell();
                    }
                }

                Event.parameters = new List <byte[]> {
                };

                for (int i = 0; i < paramCount; i++)
                {
                    byte[] byteA = BitConverter.GetBytes(int.Parse((string)dataGridView1.Rows[e.RowIndex].Cells[i + 5].Value));
                    Event.parameters.Add(byteA);
                }
            }

            DataGridViewCellCollection cells = dataGridView1.Rows[e.RowIndex].Cells;

            string invalid = "Invalid value for this type. Type of this cell:\n\n";

            switch (e.ColumnIndex)
            {
            case 0:
                break;

            case 1:
                if (!uint.TryParse((string)cells[1].Value, out Event.eventType))
                {
                    MessageBox.Show(invalid + "uint");
                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Event.eventType;
                }
                break;

            case 2:
                break;

            case 3:
                float value1 = 0;
                if (!float.TryParse((string)cells[3].Value, out value1))
                {
                    MessageBox.Show(invalid + "float");
                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Event.startTime;
                }
                else
                {
                    Event.startTime = value1;

                    bool l = false;
                    uint i = 0;

                    while (!l && i < tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount)
                    {
                        if (tae.data.animDatas[listBox1.SelectedIndex].timeConstants[(int)i] == Event.startTime)
                        {
                            l = true;
                            Event.startTimeOffset = i * 4;
                        }

                        i++;
                    }

                    if (!l)
                    {
                        tae.data.animDatas[listBox1.SelectedIndex].timeConstants.Add(Event.startTime);
                        tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount++;
                        Event.startTimeOffset = (tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount - 1) * 4;
                    }

                    CheckForUnreferencedConstant();
                }

                break;

            case 4:
                value1 = 0;
                if (!float.TryParse((string)cells[4].Value, out value1))
                {
                    MessageBox.Show(invalid + "float");
                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Event.endTime;
                }
                else
                {
                    Event.endTime = value1;

                    bool l = false;
                    uint i = 0;

                    while (!l && i < tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount)
                    {
                        if (tae.data.animDatas[listBox1.SelectedIndex].timeConstants[(int)i] == Event.endTime)
                        {
                            l = true;
                            Event.endTimeOffset = i * 4;
                        }

                        i++;
                    }

                    if (!l)
                    {
                        tae.data.animDatas[listBox1.SelectedIndex].timeConstants.Add(Event.endTime);
                        tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount++;
                        Event.endTimeOffset = (tae.data.animDatas[listBox1.SelectedIndex].timeConstantsCount - 1) * 4;
                    }

                    CheckForUnreferencedConstant();
                }
                break;

            default:
                if (e.ColumnIndex - 5 < Event.parameters.Count)
                {
                    if (Helper.ok)
                    {
                        bool found = false;
                        int  index = 0;

                        while (!found && index < Helper.helpers.Count)
                        {
                            if (Helper.helpers[index].id == Event.eventType)
                            {
                                switch (Helper.helpers[index].parameterTypes[e.ColumnIndex - 5])
                                {
                                case "byte":
                                    sbyte sbValue = 0;
                                    if (!sbyte.TryParse((string)cells[e.ColumnIndex].Value, out sbValue))
                                    {
                                        MessageBox.Show(invalid + "byte");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ToByte(Event.parameters[e.ColumnIndex - 5]);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(sbValue);
                                    }
                                    break;

                                case "ubyte":
                                    byte bValue = 0;
                                    if (!byte.TryParse((string)cells[e.ColumnIndex].Value, out bValue))
                                    {
                                        MessageBox.Show(invalid + "byte");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ToByte(Event.parameters[e.ColumnIndex - 5]);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(bValue);
                                    }
                                    break;

                                case "short":
                                    short sValue = 0;
                                    if (!short.TryParse((string)cells[e.ColumnIndex].Value, out sValue))
                                    {
                                        MessageBox.Show(invalid + "short");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToInt16(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(sValue);
                                    }
                                    break;

                                case "ushort":
                                    ushort usValue = 0;
                                    if (!ushort.TryParse((string)cells[e.ColumnIndex].Value, out usValue))
                                    {
                                        MessageBox.Show(invalid + "ushort");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToUInt16(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(usValue);
                                    }
                                    break;

                                case "int":
                                    int iValue = 0;
                                    if (!int.TryParse((string)cells[e.ColumnIndex].Value, out iValue))
                                    {
                                        MessageBox.Show(invalid + "int");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToInt32(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(iValue);
                                    }
                                    break;

                                case "uint":
                                    uint uiValue = 0;
                                    if (!uint.TryParse((string)cells[e.ColumnIndex].Value, out uiValue))
                                    {
                                        MessageBox.Show(invalid + "uint");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToUInt32(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(uiValue);
                                    }
                                    break;

                                case "float":
                                    float fValue = 0;
                                    if (!float.TryParse((string)cells[e.ColumnIndex].Value, out fValue))
                                    {
                                        MessageBox.Show(invalid + "float");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToSingle(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(fValue);
                                    }
                                    break;

                                case "long":
                                    long lValue = 0;
                                    if (!long.TryParse((string)cells[e.ColumnIndex].Value, out lValue))
                                    {
                                        MessageBox.Show(invalid + "long");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToInt64(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(lValue);
                                    }
                                    break;

                                case "ulong":
                                    ulong ulValue = 0;
                                    if (!ulong.TryParse((string)cells[e.ColumnIndex].Value, out ulValue))
                                    {
                                        MessageBox.Show(invalid + "ulong");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToUInt64(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(ulValue);
                                    }
                                    break;

                                case "double":
                                    double dValue = 0;
                                    if (!double.TryParse((string)cells[e.ColumnIndex].Value, out dValue))
                                    {
                                        MessageBox.Show(invalid + "double");
                                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToDouble(Event.parameters[e.ColumnIndex - 5], 0);
                                    }
                                    else
                                    {
                                        Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(dValue);
                                    }
                                    break;

                                default:
                                    break;
                                }

                                found = true;
                            }
                            else
                            {
                                index++;
                            }
                        }
                    }
                    else
                    {
                        int value = 0;
                        if (!int.TryParse((string)cells[e.ColumnIndex].Value, out value))
                        {
                            MessageBox.Show(invalid + "int");
                            dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BitConverter.ToInt32(Event.parameters[e.ColumnIndex - 5], 0).ToString();
                        }
                        else
                        {
                            Event.parameters[e.ColumnIndex - 5] = BitConverter.GetBytes(value);
                        }
                    }
                }
                break;
            }

            tae.data.animDatas[listBox1.SelectedIndex].events[eventIndex] = Event;
        }