Beispiel #1
0
 public Table(MemoryStream stream)
 {
     while (stream.Position < stream.Length)
     {
         var id    = stream.ReadString();
         var row   = Rows.GetValue(id) ?? (Rows[id] = new Row(id));
         var count = stream.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             var column = stream.ReadString();
             var value  = stream.ReadString();
             row[column] = value;
             stream.ReadInt32();
         }
     }
     foreach (var row in Rows.Values.ToArray())
     {
         if (row["Deleted"].HasValue())
         {
             Rows.Remove(row.ID);
         }
     }
     foreach (var row in Rows.Values)
     {
         var value = row["Parent"];
         if (!value.HasValue())
         {
             continue;
         }
         var index = ParentIndex.GetValue(value) ?? (ParentIndex[value] = new List <string>());
         index.Add(row.ID);
     }
 }
Beispiel #2
0
        public virtual void Paint(GraphicsLayer.IGraphics g, int width, int height)
        {
            var bounds = ComputeBounds(g, width, height);

            if (!string.IsNullOrEmpty(_label))
            {
                if (Color.Equals(default(GraphicsLayer.ARGB)))
                {
                    if (IsUniversal)
                    {
                        g.FillEllipse(UniversalVertexFillBrushColor, bounds);
                    }
                }
                else
                {
                    g.FillEllipse(Color, bounds);
                }

                g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1);
                g.DrawString(_label, LabelFont, LabelBrushColor, bounds);
            }
            else
            {
                if (Color.Equals(default(GraphicsLayer.ARGB)))
                {
                    g.FillEllipse(IsUniversal ? UniversalVertexFillBrushColor : DefaultFillBrushColor, bounds);
                }
                else
                {
                    g.FillEllipse(Color, bounds);
                }


                g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1);
            }

            if (_showIndex)
            {
                var cx = (bounds.Left + bounds.Right) / 2;
                var cy = (bounds.Bottom + bounds.Top) / 2;
                var r  = Math.Max(bounds.Width, bounds.Height) / 2 + 5;
                var bb = new GraphicsLayer.Box(cx + r * Math.Cos(IndexAngle) - 5, cy + r * Math.Sin(IndexAngle) - 5, 10, 10);
                g.DrawString(ParentIndex.ToString(), IndexFont, IndexBrushColor, bb);
            }
        }
Beispiel #3
0
        public override int GetHashCode()
        {
            int result = 17;

            unchecked
            {
                if (ParentIndex != default(int))
                {
                    result = (result * 31) + ParentIndex.GetHashCode();
                }

                if (Name != default(string))
                {
                    result = (result * 31) + Name.GetHashCode();
                }
            }

            return(result);
        }
        public void WriteXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("Object", true, out subEle);
            Object.WriteXML(subEle, master);

            ele.TryPathTo("ParentIndex", true, out subEle);
            subEle.Value = ParentIndex.ToString();

            ele.TryPathTo("Unused", true, out subEle);
            subEle.Value = Unused.ToHex();

            ele.TryPathTo("Density", true, out subEle);
            subEle.Value = Density.ToString("G15");

            ele.TryPathTo("Clustering", true, out subEle);
            subEle.Value = Clustering.ToString();

            ele.TryPathTo("Slope/Min", true, out subEle);
            subEle.Value = MinSlope.ToString();

            ele.TryPathTo("Slope/Max", true, out subEle);
            subEle.Value = MaxSlope.ToString();

            ele.TryPathTo("Flags", true, out subEle);
            subEle.Value = Flags.ToString();

            ele.TryPathTo("RadiusWithRespectToParent", true, out subEle);
            subEle.Value = RadiusWithRespectToParent.ToString();

            ele.TryPathTo("Radius", true, out subEle);
            subEle.Value = Radius.ToString();

            ele.TryPathTo("Unknown1", true, out subEle);
            subEle.Value = Unknown1.ToHex();

            ele.TryPathTo("MaxHeight", true, out subEle);
            subEle.Value = MaxHeight.ToString("G15");

            ele.TryPathTo("Sink", true, out subEle);
            subEle.Value = Sink.ToString("G15");

            ele.TryPathTo("SinkVariance", true, out subEle);
            subEle.Value = SinkVariance.ToString("G15");

            ele.TryPathTo("SizeVariance", true, out subEle);
            subEle.Value = SizeVariance.ToString("G15");

            ele.TryPathTo("XAngleVariance", true, out subEle);
            subEle.Value = XAngleVariance.ToString();

            ele.TryPathTo("YAngleVariance", true, out subEle);
            subEle.Value = YAngleVariance.ToString();

            ele.TryPathTo("ZAngleVariance", true, out subEle);
            subEle.Value = ZAngleVariance.ToString();

            ele.TryPathTo("Unknown2", true, out subEle);
            subEle.Value = Unknown2.ToHex();
        }
Beispiel #5
0
        public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            Bitfield = reader.ReadUInt32();

            AllowFreeHeading = (Bitfield & 4) != 0;
            HasPhysicsBSP    = (Bitfield & 8) != 0;

            // Get all the GraphicsObjects in this SetupModel. These are all the 01-types.
            uint numParts = reader.ReadUInt32();

            for (int i = 0; i < numParts; i++)
            {
                Parts.Add(reader.ReadUInt32());
            }

            if ((Bitfield & 1) != 0)
            {
                for (int i = 0; i < numParts; i++)
                {
                    ParentIndex.Add(reader.ReadUInt32());
                }
            }

            if ((Bitfield & 2) != 0)
            {
                for (int i = 0; i < numParts; i++)
                {
                    DefaultScale.Add(reader.ReadVector3());
                }
            }

            HoldingLocations.Unpack(reader);
            ConnectionPoints.Unpack(reader);

            int placementsCount = reader.ReadInt32();

            for (int i = 0; i < placementsCount; i++)
            {
                int key = reader.ReadInt32();
                // there is a frame for each Part
                var placementType = new PlacementType();
                placementType.Unpack(reader, (uint)Parts.Count);
                PlacementFrames.Add(key, placementType);
            }

            CylSpheres.Unpack(reader);

            Spheres.Unpack(reader);

            Height         = reader.ReadSingle();
            Radius         = reader.ReadSingle();
            StepDownHeight = reader.ReadSingle();
            StepUpHeight   = reader.ReadSingle();

            SortingSphere.Unpack(reader);
            SelectionSphere.Unpack(reader);

            Lights.Unpack(reader);

            DefaultAnimation   = reader.ReadUInt32();
            DefaultScript      = reader.ReadUInt32();
            DefaultMotionTable = reader.ReadUInt32();
            DefaultSoundTable  = reader.ReadUInt32();
            DefaultScriptTable = reader.ReadUInt32();
        }
Beispiel #6
0
        public void Paint(GraphicsLayer.IGraphics g, int width, int height)
        {
            if (_V1 == _V2)
            {
                // Draw self loop.
            }
            else
            {
                var maxRadius1 = Math.Max(_V1.LocalBounds.Width, _V1.LocalBounds.Height) / 2;
                var maxRadius2 = Math.Max(_V2.LocalBounds.Width, _V2.LocalBounds.Height) / 2;

                var cos = (_V2.X - _V1.X) / Math.Sqrt((_V2.X - _V1.X) * (_V2.X - _V1.X) + (_V2.Y - _V1.Y) * (_V2.Y - _V1.Y));
                cos = Math.Min(Math.Max(cos, -1), 1);

                var sin = (_V2.Y - _V1.Y) / Math.Sqrt((_V2.X - _V1.X) * (_V2.X - _V1.X) + (_V2.Y - _V1.Y) * (_V2.Y - _V1.Y));
                sin = Math.Min(Math.Max(sin, -1), 1);

                var angle = Math.Acos(cos);
                if (_V1.Y > _V2.Y)
                {
                    angle = -angle;
                }

                if (double.IsNaN(angle))
                {
                    return;
                }

                var angleStep    = Math.PI / 2.0 / _Multiplicity;
                var evenModifier = (_Multiplicity % 2 == 0) ? 0.5 : 0;

                GraphicsLayer.Box topStart  = new GraphicsLayer.Box(0, 0);
                GraphicsLayer.Box topFinish = new GraphicsLayer.Box(0, 0);
                var first = true;
                for (int i = -(_Multiplicity - 1) / 2; i < Math.Ceiling((_Multiplicity + 1) / 2.0); i++)
                {
                    var startAngle  = angle + angleStep * (i - evenModifier);
                    var finishAngle = angle - angleStep * (i - evenModifier);

                    var start  = LocalToGlobal(_V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.01, startAngle), width, height);
                    var finish = LocalToGlobal(_V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.01, finishAngle), width, height);


                    if (first)
                    {
                        first     = false;
                        topStart  = start;
                        topFinish = finish;
                    }

                    g.DrawLine(_penColor, start, finish, _thickness);
                }

                if (_Orientation != Orientations.None)
                {
                    var points = new GraphicsLayer.Box[3];
                    if (_Orientation == Orientations.Forward)
                    {
                        var sweep = _V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.025f, angle);

                        points[0] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V2.Location, Math.PI / 180.0 * 10.0), width, height);
                        points[1] = LocalToGlobal(_V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.005f, angle), width, height);
                        points[2] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V2.Location, -Math.PI / 180.0 * 10.0), width, height);
                    }
                    else if (_Orientation == Orientations.Backward)
                    {
                        var sweep = _V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.025f, angle);

                        points[0] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V1.Location, Math.PI / 180.0 * 10.0), width, height);
                        points[1] = LocalToGlobal(_V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.005f, angle), width, height);
                        points[2] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V1.Location, -Math.PI / 180.0 * 10.0), width, height);
                    }

                    g.FillPolygon(new GraphicsLayer.ARGB(0, 0, 0), points);
                }

                var label = Label;
                if (!string.IsNullOrEmpty(label))
                {
                    var box    = g.MeasureString(label, LabelFont);
                    var bounds = new GraphicsLayer.Box(topStart.X + (topFinish.X - topStart.X) / 2 - box.Width / 2 - 0.75 * box.Width * sin, topStart.Y + (topFinish.Y - topStart.Y) / 2 - box.Height / 2 + 0.75 * box.Height * cos, box.Width, box.Height);
                    g.DrawString(label, LabelFont, LabelBrushColor, bounds);
                }

                if (_showIndex)
                {
                    var bounds = new GraphicsLayer.Box(topStart.X + (topFinish.X - topStart.X) / 2, topStart.Y + (topFinish.Y - topStart.Y) / 2, 10, 10);
                    var cx     = (bounds.Left + bounds.Right) / 2;
                    var cy     = (bounds.Bottom + bounds.Top) / 2;
                    var r      = Math.Max(bounds.Width, bounds.Height) / 2 + 5;
                    var bb     = new GraphicsLayer.Box(cx + r * Math.Cos(IndexAngle) - 5, cy + r * Math.Sin(IndexAngle) - 5, 10, 10);
                    g.DrawString(ParentIndex.ToString(), IndexFont, IndexBrushColor, bb);
                }
            }
        }
Beispiel #7
0
 public override string ToString()
 {
     return
         ($"Name: '{Name}' Index: '{Index.Map(i => i.ToString()).IfNone("")}', ParentIndex: '{ParentIndex.Map(i => i.ToString()).IfNone("")}'");
 }