Exemplo n.º 1
0
        /// <summary>
        /// Saves the current DataSource to the specified file.
        /// </summary>
        /// <param name="filename">The specified file's name.</param>
        private void SaveFile(string filename)
        {
            dataGridView1.EndEdit();
            dataGridView2.EndEdit();


            var name   = CharacterFilename;
            var number = DataSource.Rows.Count;

            var header = new object[] { name, number };

            // pack all data
            var data = from r0 in DataSource.Rows.OfType <DataRowEx>()
                       select new object[2] {
                r0.ItemArray,
                from r1 in (r0.Tag as DataTable).Rows.OfType <DataRow>()
                select r1.ItemArray
            };

            var info = new object[2] {
                header, data
            };

            using (var dest = File.OpenWrite(filename))

                ObjectInfoFormatter.Write(dest, info);


            HasUnsavedChanges = false;
            Text = filename;
        }
Exemplo n.º 2
0
        protected override void RecvData()
        {
            dataGridView.DataSource = null;
            dataGridView.Invalidate();

            var row = parent.CurrentCell?.OwningRow;

            if (row == null)
            {
                return;
            }

            var kind = (byte)row.Cells["Kind"]?.Value;
            var idx  = func(row);

            if (idx < 9000000 && idx >= 8000000)
            {
                idx += 4000000;
            }



            base.RecvData();

            var objinf = (Owner as ItemViewer).objectinfo.Single(x => x.Name == idx.ToString("D8")).Data as object[];

            var table = ObjectInfoFormatter.GetSchema("data");

            foreach (var r in objinf[1] as object[])
            {
                table.Add((r as object[])[0] as object[], (r as object[])[1]);
            }

            dataGridView.DataSource = table;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens the specified file for reading.
        /// </summary>
        /// <param name="filename">The specified file's name.</param>
        private void OpenFile(string filename)
        {
            object[] LoadedInfo = null;

            try
            {
                Filename = filename;

                using (var source = File.OpenRead(filename))
                {
                    //if (OperationMode == 0)
                    LoadedInfo = ObjectInfoFormatter.Read(source);
                    //if (OperationMode == 1) LoadedInfo = EffectInfoFormatter.Read(source);
                }
            }
            catch
            {
                Filename = null;
            }
            finally
            {
                UpdateResource(LoadedInfo);

                SelectionChanged();
            }
        }
Exemplo n.º 4
0
        protected override void RecvData()
        {
            base.RecvData();

            var table = ObjectInfoFormatter.GetSchema("effects");

            var tag = parent.Effects;

            if (tag == null)
            {
                return;
            }

            foreach (var row in tag)
            {
                table.Rows.Add(row as object[]);
            }

            dataGridView.DataSource = table;

            dataGridView_SlectionChanged(null, null);
        }
Exemplo n.º 5
0
        void treeView_AddObjectInfo()
        {
            var node = new TreeNode("ObjectInfo [" + objectinfo.Count() + "]");

            // next line does not show useful information and is slow
            // panoskj disabled it
            // node.Tag = new object[] { 0, ObjectInfoFormatter.GetFormatter("header"), objectinfo.Select(x => x.Data as object[]).Where(x => x != null) };

            foreach (var inf in objectinfo)
            {
                var exists = File.Exists(@"res-obj\" + inf.Name + ".obj");

                var child = exists ? new TreeNode(inf.Name) : new TreeNode(inf.Name + " (without file)");


                child.Tag = new treeViewTag(4, ObjectInfoFormatter.GetFormatter("data"), inf, null);

                node.Nodes.Add(child);
            }

            treeView.Nodes.Add(node);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Was in ItemViewer() moved here to clean up.
        /// Finds some bodyconditions and displays them apparently.
        /// </summary>
        internal void helperfunc2()
        {
            var idx  = ObjectInfoFormatter.GetFormatter("effects")["EffectName"];
            var idx2 = ObjectInfoFormatter.GetFormatter("data")["BodyConditionName"];

            var x = from pair in objectinfo
                    let inf = (pair.Data as object[])?[1] as object[][]
                              where inf != null
                              from row in inf
                              let bodycond                       = row[0] as object[]
                                                        let effs = row[1] as object[][]
                                                                   from eff in effs
                                                                   let effname = eff[idx] as string
                                                                                 where effname.StartsWith("06400446") || effname.StartsWith("06400457") || effname.StartsWith("06400465")
                                                                                 select new { ObjectInfoName = pair.Name, BodyCondName = bodycond[idx2] as string, EffectName = effname };

            var form = new DataGridViewForm(x.ToArray());

            form.Show();

            //// 06400446
            //// 06400457
            //// 06400465
        }
Exemplo n.º 7
0
        /// <summary>
        /// Should be called when the filename changes.
        /// </summary>
        private void UpdateResource(object[] LoadedInfo)
        {
            if (LoadedInfo != null)
            {
                // save the character file name
                CharacterFilename = (LoadedInfo[0] as object[])[0] as string;

                var dataformatter = ObjectInfoFormatter.GetFormatter("data");
                var effsformatter = ObjectInfoFormatter.GetFormatter("effects");

                // create an empty DataTableEx that matches our data format
                var data = dataformatter.GetSchema <DataTableEx>();

                // iterate the body conditions
                foreach (var row in LoadedInfo[1] as IEnumerable <object[]> )
                {
                    // create a new row
                    var newrow = data.NewRow();

                    // create a DataTable and fill it with the effects of this row
                    var effs = effsformatter.GetSchema(row[1] as IEnumerable <object[]>);

                    // assign the body condition data to the row
                    newrow.ItemArray = row[0] as object[];
                    // tag the effects DataTable
                    newrow.Tag = effs;

                    // set up the appropriate events
                    effs.ColumnChanged += (sender, e) => DataChanged();
                    effs.RowChanged    += (sender, e) => DataChanged();
                    effs.RowDeleted    += (sender, e) => DataChanged();

                    // effs.ColumnChanged += (sender, e) => newrow[dataformatter["EffectNum"]] = effs.Rows.Count;
                    effs.RowChanged += (sender, e) => newrow[dataformatter["EffectNum"]] = effs.Rows.Count;
                    effs.RowDeleted += (sender, e) => newrow[dataformatter["EffectNum"]] = effs.Rows.Count;

                    // add the new row
                    data.Add(newrow);
                }

                // set up appropriate events for the first DataTable
                data.ColumnChanged += (sender, e) => DataChanged();
                data.RowChanged    += (sender, e) => DataChanged();
                data.RowDeleted    += (sender, e) => DataChanged();

                // if a row is added by the user
                data.TableNewRow += (sender, e)
                                    // we need to properly construct the effects' datatable and tag it
                                    => (e.Row as DataRowEx).Tag = ObjectInfoFormatter.GetFormatter("effects").GetSchema();


                bsDGV1.DataSource = data;
                bsDGV2.DataSource = null;

                dataGridView1.Refresh();
                dataGridView2.Refresh();

                Text = Filename;
            }

            else
            {
                Filename          = null;
                CharacterFilename = null;

                bsDGV1.DataSource = null;
                bsDGV2.DataSource = null;

                dataGridView1.Refresh();
                dataGridView2.Refresh();

                Text = AppName;
            }

            HasUnsavedChanges = false;
        }
Exemplo n.º 8
0
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            var node = e.Node;
            var tag  = node?.Tag as treeViewTag;

            if (tag == null)
            {
                return;
            }


            var type   = (int)tag.Operation;
            var format = tag.Formatter;
            var data   = tag.Data;

            dataGridView.ReadOnly = true;

            if (type == 0)
            {
                dataGridView.DataSource = format.GetSchema(data as IEnumerable <object[]>);
            }

            if (type == 1 && node.Nodes.Count == 0)
            {
                foreach (var group in data as IEnumerable <IGrouping <object, object[]> > )
                {
                    var child = new TreeNode(group.Key.ToString() + " [" + group.Count() + "]");

                    child.Tag = new object[] { 2, null, group };

                    node.Nodes.Add(child);
                }
            }

            if (type == 2)
            {
                dataGridView.DataSource = ((node.Parent.Parent.Tag as object[])[1] as Formatter.Struct).GetSchema(data as IEnumerable <object[]>);
            }


            if (type == 3 && node.Nodes.Count == 0)
            {
                var mapinf = ((CachedInfo)data).Data as object[];

                if (mapinf == null)
                {
                    node.Name = data as string + " [Invalid]";
                }

                else
                {
                    for (int i = 1; i < 4; ++i)
                    {
                        var formatter = MapFormatter.GetFormatter(i);

                        var child = new TreeNode(formatter.Name + " [" + (mapinf[i] as object[]).Length + "]");

                        child.Tag = new treeViewTag(0, formatter, mapinf[i], null);

                        node.Nodes.Add(child);
                    }
                }
            }

            if (type == 4 && data != null)
            {
                var objinfname = ((CachedInfo)data).Name;
                var objinf0    = ((CachedInfo)data).Data as object[];

                if (objinf0 == null)
                {
                    return;
                }

                var objinf = (objinf0[1] as IEnumerable <object>).Select(x => x as object[]).Select(x => new { data = x[0] as object[], effects = x[1] as object[][] });

                if (node.Nodes.Count == 0)
                {
                    node.Nodes.Add("Name: " + (objinf0[0] as object[])[0] as string);

                    var idx1 = FormatterOmi.GetFormatter("ti_Item")["ItemNum"];
                    var idx2 = FormatterOmi.GetFormatter("ti_Item")["Kind"];
                    var idx3 = FormatterOmi.GetFormatter("ti_Item")["ItemName"];
                    var idx4 = FormatterOmi.GetFormatter("ti_Item")["SourceIndex"];

                    int sourceindex;

                    if (int.TryParse(objinfname, out sourceindex))
                    {
                        var usages = from item in omi[0] as object[][]
                                     where (uint)item[idx4] == sourceindex ||
                                     (((byte)item[idx2] == 16 || (byte)item[idx2] == 60) && (uint)item[idx4] == (sourceindex - 4000000)) ||
                                     (((byte)item[idx2] < 16) && (uint)item[idx4] == (sourceindex - 100000)) ||
                                     (((byte)item[idx2] == 25) && (uint)item[idx4] == (sourceindex - 500000))
                                     select new { ItemNum = (uint)item[idx1], ItemName = item[idx3] as string };

                        var usagesnode = new TreeNode("Used by items [" + usages.Count() + "]");

                        foreach (var usage in usages)
                        {
                            var child = new TreeNode("[" + usage.ItemNum + "] " + usage.ItemName);

                            child.Tag = new treeViewTag(0, FormatterOmi.GetFormatter("ti_Item"), (omi[0] as object[][]).Where(x => (uint)x[idx1] == usage.ItemNum), null);

                            usagesnode.Nodes.Add(child);
                        }
                        node.Nodes.Add(usagesnode);
                    }

                    var effectsnode = new TreeNode("Body Condition Effects");

                    var idx = format["BodyConditionName"];

                    foreach (var row in objinf)
                    {
                        var child = new TreeNode(row.data[idx] as string + " [" + row.effects.Length + "]");

                        child.Tag = new treeViewTag(0, ObjectInfoFormatter.GetFormatter("effects"), row.effects, null);

                        effectsnode.Nodes.Add(child);
                    }

                    node.Nodes.Add(effectsnode);
                }

                dataGridView.DataSource = format.GetSchema(objinf.Select(x => x.data));
            }

            if (type == 5 && data != null)
            {
                dataGridView.ReadOnly = false;

                var temp = ((CachedInfo)data).Data as object[];

                var idx = EffectInfoFormatter.HeaderFormatter["EffectType"];

                var efftype = (uint)(temp[0] as object[])[idx];

                var formatter = EffectInfoFormatter.GetFormatter(efftype);

                dataGridView.DataSource = formatter.GetSchema(
                    new object[][] { temp[1] as object[] });
            }
        }
Exemplo n.º 9
0
 object DeserializeObjectInfo(string name)
 {
     using (var source = File.OpenRead(@"res-dev\objectinfo\" + name))
         return(ObjectInfoFormatter.Read(source));
 }
Exemplo n.º 10
0
 void SerializeObjectInfo(string name, object value)
 {
     using (var dest = File.OpenWrite(@"res-dev\objectinfo\" + name))
         ObjectInfoFormatter.Write(dest, value as object[]);
 }