Exemplo n.º 1
0
        //mxd
        private static bool SetPairedUDMFFieldsLabel(UniFields fields, string paramX, string paramY, double defaultvalue, Label namelabel, Label valuelabel, bool highlight)
        {
            double x = UniFields.GetFloat(fields, paramX, defaultvalue);
            double y = UniFields.GetFloat(fields, paramY, defaultvalue);

            if (fields.ContainsKey(paramX))
            {
                x = (double)fields[paramX].Value;
            }
            if (fields.ContainsKey(paramY))
            {
                y = (double)fields[paramY].Value;
            }

            if (x != defaultvalue || y != defaultvalue)
            {
                valuelabel.Text    = x.ToString(CultureInfo.InvariantCulture) + ", " + y.ToString(CultureInfo.InvariantCulture);
                valuelabel.Enabled = true;
                namelabel.Enabled  = true;
                return(true);
            }
            else
            {
                valuelabel.Text    = "--, --";
                valuelabel.Enabled = highlight;
                namelabel.Enabled  = highlight;
                return(false);
            }
        }
        //mxd. Alpha based picking
        public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray)
        {
            if (!BuilderPlug.Me.AlphaBasedTextureHighlighting || !Texture.IsImageLoaded || (!Texture.IsTranslucent && !Texture.IsMasked))
            {
                return(base.PickAccurate(from, to, dir, ref u_ray));
            }

            float u;

            new Line2D(from, to).GetIntersection(Sidedef.Line.Line, out u);
            if (Sidedef != Sidedef.Line.Front)
            {
                u = 1.0f - u;
            }

            // Some textures (e.g. HiResImage) may lie about their size, so use bitmap size instead
            int imageWidth  = Texture.GetAlphaTestWidth();
            int imageHeight = Texture.GetAlphaTestHeight();

            // Determine texture scale...
            Vector2D imgscale = new Vector2D((float)Texture.Width / imageWidth, (float)Texture.Height / imageHeight);
            Vector2D texscale = (Texture is HiResImage) ? imgscale * Texture.Scale : Texture.Scale;

            // Get correct offset to texture space...
            int ox = (int)Math.Floor((u * Sidedef.Line.Length * UniFields.GetFloat(Sidedef.Fields, "scalex_mid", 1.0f) / texscale.x
                                      + ((Sidedef.OffsetX + UniFields.GetFloat(Sidedef.Fields, "offsetx_mid")) / imgscale.x))
                                     % imageWidth);

            int oy;

            if (repeatmidtex)
            {
                bool  pegbottom = Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag);
                float zoffset   = (pegbottom ? Sidedef.Sector.FloorHeight : Sidedef.Sector.CeilHeight);
                oy = (int)Math.Floor(((pickintersect.z - zoffset) * UniFields.GetFloat(Sidedef.Fields, "scaley_mid", 1.0f) / texscale.y
                                      - ((Sidedef.OffsetY - UniFields.GetFloat(Sidedef.Fields, "offsety_mid")) / imgscale.y))
                                     % imageHeight);
            }
            else
            {
                float zoffset = bottomclipplane.GetZ(pickintersect);
                oy = (int)Math.Ceiling(((pickintersect.z - zoffset) * UniFields.GetFloat(Sidedef.Fields, "scaley_mid", 1.0f) / texscale.y) % imageHeight);
            }

            // Make sure offsets are inside of texture dimensions...
            if (ox < 0)
            {
                ox += imageWidth;
            }
            if (oy < 0)
            {
                oy += imageHeight;
            }

            // Check pixel alpha
            Point pixelpos = new Point(General.Clamp(ox, 0, imageWidth - 1), General.Clamp(imageHeight - oy, 0, imageHeight - 1));

            return(Texture.AlphaTestPixel(pixelpos.X, pixelpos.Y) && base.PickAccurate(from, to, dir, ref u_ray));
        }
Exemplo n.º 3
0
        internal SortedVisualSide(BaseVisualGeometrySidedef side)
        {
            Side   = side;
            Bounds = BuilderModesTools.GetSidedefPartSize(side);
            Index  = index++;

            if (side.Sidedef.Line.Front == side.Sidedef)
            {
                Start = side.Sidedef.Line.Start.Position;
                End   = side.Sidedef.Line.End.Position;
            }
            else
            {
                Start = side.Sidedef.Line.End.Position;
                End   = side.Sidedef.Line.Start.Position;
            }

            switch (side.GeometryType)
            {
            case VisualGeometryType.WALL_UPPER:
                OffsetX = UniFields.GetFloat(side.Sidedef.Fields, "offsetx_top");
                OffsetY = UniFields.GetFloat(side.Sidedef.Fields, "offsety_top");
                ScaleX  = UniFields.GetFloat(side.Sidedef.Fields, "scalex_top", 1.0f);
                ScaleY  = UniFields.GetFloat(side.Sidedef.Fields, "scaley_top", 1.0f);
                break;

            case VisualGeometryType.WALL_MIDDLE:
                OffsetX = UniFields.GetFloat(side.Sidedef.Fields, "offsetx_mid");
                OffsetY = UniFields.GetFloat(side.Sidedef.Fields, "offsety_mid");
                ScaleX  = UniFields.GetFloat(side.Sidedef.Fields, "scalex_mid", 1.0f);
                ScaleY  = UniFields.GetFloat(side.Sidedef.Fields, "scaley_mid", 1.0f);
                break;

            case VisualGeometryType.WALL_MIDDLE_3D:
                Sidedef cs = side.GetControlLinedef().Front;
                ControlSideOffsetX = cs.OffsetX + UniFields.GetFloat(cs.Fields, "offsetx_mid");
                OffsetX            = UniFields.GetFloat(side.Sidedef.Fields, "offsetx_mid");
                ControlSideOffsetY = cs.OffsetY + UniFields.GetFloat(cs.Fields, "offsety_mid");
                OffsetY            = UniFields.GetFloat(side.Sidedef.Fields, "offsety_mid");
                ScaleX             = UniFields.GetFloat(cs.Fields, "scalex_mid", 1.0f);
                ScaleY             = UniFields.GetFloat(cs.Fields, "scaley_mid", 1.0f);
                break;

            case VisualGeometryType.WALL_LOWER:
                OffsetX = UniFields.GetFloat(side.Sidedef.Fields, "offsetx_bottom");
                OffsetY = UniFields.GetFloat(side.Sidedef.Fields, "offsety_bottom");
                ScaleX  = UniFields.GetFloat(side.Sidedef.Fields, "scalex_bottom", 1.0f);
                ScaleY  = UniFields.GetFloat(side.Sidedef.Fields, "scaley_bottom", 1.0f);
                break;
            }

            NextSides     = new Dictionary <SortedVisualSide, bool>();
            PreviousSides = new Dictionary <SortedVisualSide, bool>();
        }
 public ThingProperties(Thing t)
 {
     X = t.Position.x;
     Y = t.Position.y;
     Z = t.Position.z;
     //Type = t.Type;
     AngleDoom = t.AngleDoom;
     Pitch     = t.Pitch;
     Roll      = t.Roll;
     ScaleX    = t.ScaleX;
     ScaleY    = t.ScaleY;
     Alpha     = UniFields.GetFloat(t.Fields, "alpha", 1.0f);
     Flags     = t.GetFlags();
 }
        private static double GetSidedefValue(Sidedef target, VisualGeometryType targetparttype, string key, double defaultvalue)
        {
            switch (targetparttype)
            {
            case VisualGeometryType.WALL_UPPER:
                return(Math.Round(UniFields.GetFloat(target.Fields, key + "_top", defaultvalue), 3));

            case VisualGeometryType.WALL_MIDDLE:
                return(Math.Round(UniFields.GetFloat(target.Fields, key + "_mid", defaultvalue), 3));

            case VisualGeometryType.WALL_LOWER:
                return(Math.Round(UniFields.GetFloat(target.Fields, key + "_bottom", defaultvalue), 3));
            }

            return(0);
        }
Exemplo n.º 6
0
        //mxd. Alpha based picking
        public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray)
        {
            if (!BuilderPlug.Me.AlphaBasedTextureHighlighting || !Texture.IsImageLoaded || (!Texture.IsTranslucent && !Texture.IsMasked))
            {
                return(base.PickAccurate(from, to, dir, ref u_ray));
            }

            float   u;
            Sidedef sourceside = extrafloor.Linedef.Front;

            new Line2D(from, to).GetIntersection(Sidedef.Line.Line, out u);
            if (Sidedef != Sidedef.Line.Front)
            {
                u = 1.0f - u;
            }

            // Some textures (e.g. HiResImage) may lie about their size, so use bitmap size instead
            Bitmap image = Texture.GetBitmap();

            lock (image)
            {
                // Determine texture scale...
                Vector2D imgscale = new Vector2D((float)Texture.Width / image.Width, (float)Texture.Height / image.Height);
                Vector2D texscale = (Texture is HiResImage) ? imgscale * Texture.Scale : Texture.Scale;

                // Get correct offset to texture space...
                float texoffsetx = Sidedef.OffsetX + sourceside.OffsetX + UniFields.GetFloat(Sidedef.Fields, "offsetx_mid") + UniFields.GetFloat(sourceside.Fields, "offsetx_mid");
                int   ox         = (int)Math.Floor((u * Sidedef.Line.Length * UniFields.GetFloat(sourceside.Fields, "scalex_mid", 1.0f) / texscale.x + (texoffsetx / imgscale.x)) % image.Width);

                float texoffsety = Sidedef.OffsetY + sourceside.OffsetY + UniFields.GetFloat(Sidedef.Fields, "offsety_mid") + UniFields.GetFloat(sourceside.Fields, "offsety_mid");
                int   oy         = (int)Math.Ceiling(((pickintersect.z - sourceside.Sector.CeilHeight) * UniFields.GetFloat(sourceside.Fields, "scaley_mid", 1.0f) / texscale.y - (texoffsety / imgscale.y)) % image.Height);

                // Make sure offsets are inside of texture dimensions...
                if (ox < 0)
                {
                    ox += image.Width;
                }
                if (oy < 0)
                {
                    oy += image.Height;
                }

                // Check pixel alpha
                Point pixelpos = new Point(General.Clamp(ox, 0, image.Width - 1), General.Clamp(image.Height - oy, 0, image.Height - 1));
                return(image.GetPixel(pixelpos.X, pixelpos.Y).A > 0 && base.PickAccurate(@from, to, dir, ref u_ray));
            }
        }
Exemplo n.º 7
0
        public void SetValuesFrom(UniFields fields, bool first)
        {
            blockUpdate = true;

            string newValue1;
            string newValue2;

            if (AllowDecimal)
            {
                newValue1 = ((float)Math.Round(UniFields.GetFloat(fields, field1, defaultValue), 2)).ToString();
                newValue2 = ((float)Math.Round(UniFields.GetFloat(fields, field2, defaultValue), 2)).ToString();
            }
            else
            {
                newValue1 = ((float)Math.Round(UniFields.GetFloat(fields, field1, defaultValue))).ToString();
                newValue2 = ((float)Math.Round(UniFields.GetFloat(fields, field2, defaultValue))).ToString();
            }

            if (first)
            {
                value1.Text = newValue1;
                value2.Text = newValue2;
            }
            else
            {
                if (!string.IsNullOrEmpty(value1.Text))
                {
                    value1.Text = (value1.Text != newValue1 ? string.Empty : newValue1);
                }
                if (!string.IsNullOrEmpty(value2.Text))
                {
                    value2.Text = (value2.Text != newValue2 ? string.Empty : newValue2);
                }
            }
            CheckValues();

            blockUpdate = false;
        }