void writeFields(UniFields fields, XmlWriter writer)
 {
     writer.WriteStartElement("fields");
     foreach (String str in fields.Keys) {
         writer.WriteStartElement("field");
         writer.WriteAttributeString("name", str);
         writer.WriteAttributeString("type", fields[str].Type.ToString());
         writer.WriteCData(fields[str].Value.ToString());
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Beispiel #2
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));
            }
        }
        //mxd. Only control sidedef scale is used by GZDoom
        public override void OnChangeScale(int incrementX, int incrementY)
        {
            if (!General.Map.UDMF || Texture == null || !Texture.IsImageLoaded)
            {
                return;
            }

            if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket))
            {
                undoticket = mode.CreateUndo("Change wall scale");
            }

            Sidedef target = extrafloor.Linedef.Front;

            if (target == null)
            {
                return;
            }

            float scaleX = target.Fields.GetValue("scalex_mid", 1.0f);
            float scaleY = target.Fields.GetValue("scaley_mid", 1.0f);

            target.Fields.BeforeFieldsChange();

            if (incrementX != 0)
            {
                float pix       = (int)Math.Round(Texture.Width * scaleX) - incrementX;
                float newscaleX = (float)Math.Round(pix / Texture.Width, 3);
                scaleX = (newscaleX == 0 ? scaleX * -1 : newscaleX);
                UniFields.SetFloat(target.Fields, "scalex_mid", scaleX, 1.0f);
            }

            if (incrementY != 0)
            {
                float pix       = (int)Math.Round(Texture.Height * scaleY) - incrementY;
                float newscaleY = (float)Math.Round(pix / Texture.Height, 3);
                scaleY = (newscaleY == 0 ? scaleY * -1 : newscaleY);
                UniFields.SetFloat(target.Fields, "scaley_mid", scaleY, 1.0f);
            }

            // Update the model sector to update all 3d floors
            mode.GetVisualSector(extrafloor.Linedef.Front.Sector).UpdateSectorGeometry(false);

            // Display result
            mode.SetActionResult("Wall scale changed to " + scaleX.ToString("F03", CultureInfo.InvariantCulture) + ", " + scaleY.ToString("F03", CultureInfo.InvariantCulture) + " (" + (int)Math.Round(Texture.Width / scaleX) + " x " + (int)Math.Round(Texture.Height / scaleY) + ").");
        }
Beispiel #4
0
        //mxd. Texture scale change
        protected override void ChangeTextureScale(int incrementX, int incrementY)
        {
            if (Texture == null || !Texture.IsImageLoaded)
            {
                return;
            }
            Sector s      = GetControlSector();
            float  scaleX = s.Fields.GetValue("xscalefloor", 1.0f);
            float  scaleY = s.Fields.GetValue("yscalefloor", 1.0f);

            s.Fields.BeforeFieldsChange();

            if (incrementX != 0)
            {
                float pix       = (int)Math.Round(Texture.Width * scaleX) - incrementX;
                float newscaleX = (float)Math.Round(pix / Texture.Width, 3);
                scaleX = (newscaleX == 0 ? scaleX * -1 : newscaleX);
                UniFields.SetFloat(s.Fields, "xscalefloor", scaleX, 1.0f);
            }

            if (incrementY != 0)
            {
                float pix       = (int)Math.Round(Texture.Height * scaleY) - incrementY;
                float newscaleY = (float)Math.Round(pix / Texture.Height, 3);
                scaleY = (newscaleY == 0 ? scaleY * -1 : newscaleY);
                UniFields.SetFloat(s.Fields, "yscalefloor", scaleY, 1.0f);
            }

            // Update geometry
            if (mode.VisualSectorExists(level.sector))
            {
                BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(level.sector);
                vs.UpdateSectorGeometry(false);
            }

            s.UpdateNeeded = true;
            s.UpdateCache();
            if (s.Index != Sector.Sector.Index)
            {
                Sector.Sector.UpdateNeeded = true;
                Sector.Sector.UpdateCache();
            }

            mode.SetActionResult("Floor scale changed to " + scaleX.ToString("F03", CultureInfo.InvariantCulture) + ", " + scaleY.ToString("F03", CultureInfo.InvariantCulture) + " (" + (int)Math.Round(Texture.Width / scaleX) + " x " + (int)Math.Round(Texture.Height / scaleY) + ").");
        }
Beispiel #5
0
        // Copy constructor
        internal ThingsFilter(ThingsFilter f)
        {
            // Copy
            name         = f.name;
            categoryname = f.categoryname;
            thingtype    = f.thingtype;
            thingzheight = f.thingzheight;
            thingangle   = f.thingangle;
            thingaction  = f.thingaction;
            thingargs    = new int[Thing.NUM_ARGS];
            Array.Copy(f.thingargs, thingargs, Thing.NUM_ARGS);
            thingtag        = f.thingtag;
            customfields    = new UniFields(f.customfields);
            requiredfields  = new List <string>(f.requiredfields);
            forbiddenfields = new List <string>(f.forbiddenfields);

            AdjustForMapFormat();
        }
Beispiel #6
0
        public void SetValues(UniFields fields, bool first)
        {
            if (mixedvalues)
            {
                return;
            }
            string c = fields.GetValue("comment", string.Empty);

            if (first)
            {
                textbox.Text = c;
            }
            else if (textbox.Text != c)
            {
                textbox.Clear();
                mixedvalues = true;
            }
        }
Beispiel #7
0
        public static bool PropertiesMatch(SidedefPropertiesCopySettings flags, Sidedef source, Sidedef target)
        {
            // Built-in properties
            if (flags.OffsetX && source.OffsetX != target.OffsetX)
            {
                return(false);
            }
            if (flags.OffsetY && source.OffsetY != target.OffsetY)
            {
                return(false);
            }
            if (flags.UpperTexture && source.HighTexture != target.HighTexture)
            {
                return(false);
            }
            if (flags.MiddleTexture && source.MiddleTexture != target.MiddleTexture)
            {
                return(false);
            }
            if (flags.LowerTexture && source.LowTexture != target.LowTexture)
            {
                return(false);
            }
            if (!General.Map.UDMF)
            {
                return(true);
            }

            // UDMF-specific properties
            if (flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags()))
            {
                return(false);
            }

            // UI fields
            if (!UIFieldsMatch(flags, source, target))
            {
                return(false);
            }

            // Custom fields
            return(!flags.Fields || UniFields.CustomFieldsMatch(source.Fields, target.Fields));
        }
Beispiel #8
0
        //mxd
        public virtual void OnChangeTextureRotation(float angle)
        {
            if (!General.Map.UDMF)
            {
                return;
            }

            if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket))
            {
                undoticket = mode.CreateUndo("Change texture rotation");
            }

            string key = (GeometryType == VisualGeometryType.FLOOR ? "rotationfloor" : "rotationceiling");

            mode.SetActionResult((GeometryType == VisualGeometryType.FLOOR ? "Floor" : "Ceiling") + " rotation changed to " + angle);

            // Set new angle
            Sector s = GetControlSector();

            s.Fields.BeforeFieldsChange();
            UniFields.SetFloat(s.Fields, key, angle, 0.0f);

            // Mark as changed
            changed = true;

            // Rebuild sector
            BaseVisualSector vs;

            if (mode.VisualSectorExists(level.sector))
            {
                vs = (BaseVisualSector)mode.GetVisualSector(level.sector);
            }
            else
            {
                //mxd. Need this to apply changes to 3d-floor even if control sector doesn't exist as BaseVisualSector
                vs = mode.CreateBaseVisualSector(level.sector);
            }

            if (vs != null)
            {
                vs.UpdateSectorGeometry(false);
            }
        }
Beispiel #9
0
        protected void ApplyCustomFields(UniFields other)
        {
            // Remove custom fields
            string[] keys = new string[other.Keys.Count];
            other.Keys.CopyTo(keys, 0);
            foreach (string key in keys)
            {
                if (!General.Map.FormatInterface.UIFields[elementtype].ContainsKey(key))
                {
                    other.Remove(key);
                }
            }

            // Replace with stored custom fields
            foreach (KeyValuePair <string, UniValue> group in fields)
            {
                other.Add(group.Key, new UniValue(group.Value));
            }
        }
Beispiel #10
0
        public static bool PropertiesMatch(VertexPropertiesCopySettings flags, Vertex source, Vertex target)
        {
            if (!General.Map.UDMF)
            {
                return(true);
            }

            // Built-in properties
            if (flags.ZCeiling && source.ZCeiling != target.ZCeiling)
            {
                return(false);
            }
            if (flags.ZFloor && source.ZFloor != target.ZFloor)
            {
                return(false);
            }

            // Custom fields
            return(!flags.Fields || UniFields.CustomFieldsMatch(source.Fields, target.Fields));
        }
        private void renderStyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (preventchanges)
            {
                return;
            }
            MakeUndo();             //mxd

            //update values
            foreach (Thing t in things)
            {
                UniFields.SetString(t.Fields, "renderstyle", renderstyles[renderStyle.SelectedIndex], "normal");
            }

            General.Map.IsChanged = true;
            if (OnValuesChanged != null)
            {
                OnValuesChanged(this, EventArgs.Empty);
            }
        }
Beispiel #12
0
        public void ApplyTo(UniFields fields, int min, int max, float oldValue1, float oldValue2)
        {
            if (!string.IsNullOrEmpty(value1.Text))
            {
                UniFields.SetFloat(fields, field1, General.Clamp(value1.GetResultFloat(oldValue1), min, max), defaultValue);
            }
            else
            {
                UniFields.SetFloat(fields, field1, oldValue1, defaultValue);
            }

            if (!string.IsNullOrEmpty(value2.Text))
            {
                UniFields.SetFloat(fields, field2, General.Clamp(value2.GetResultFloat(oldValue2), min, max), defaultValue);
            }
            else
            {
                UniFields.SetFloat(fields, field2, oldValue2, defaultValue);
            }
        }
Beispiel #13
0
        private static bool UIFieldsMatch(MapElementPropertiesCopySettings settings, MapElement first, MapElement second)
        {
            FieldInfo[] props = settings.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo prop in props)
            {
                // Property set?
                if (!(bool)prop.GetValue(settings))
                {
                    continue;
                }

                foreach (Attribute attr in Attribute.GetCustomAttributes(prop))
                {
                    if (attr.GetType() != typeof(FieldDescription))
                    {
                        continue;
                    }
                    FieldDescription fd = (FieldDescription)attr;
                    if (fd.SupportsCurrentMapFormat && !string.IsNullOrEmpty(fd.Field1))
                    {
                        if (!string.IsNullOrEmpty(fd.Field2))
                        {
                            if (!UniFields.ValuesMatch(fd.Field1, fd.Field2, first, second))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            if (!UniFields.ValuesMatch(fd.Field1, first, second))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #14
0
        //mxd
        public void ApplyUserVars(Dictionary <string, UniversalType> vars, UniFields tofields)
        {
            // Apply user variables when target map element contains user var definition and the value is not default
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;
                    if (frow.RowType != FieldsEditorRowType.USERVAR || !vars.ContainsKey(frow.Name))
                    {
                        continue;
                    }

                    object oldvalue = (tofields.ContainsKey(frow.Name) ? tofields[frow.Name].Value : null);
                    object newvalue = frow.GetResult(oldvalue);

                    // Skip field when mixed values
                    if (newvalue == null)
                    {
                        continue;
                    }

                    // Remove field
                    if (newvalue.Equals(frow.TypeHandler.GetDefaultValue()))
                    {
                        if (tofields.ContainsKey(frow.Name))
                        {
                            tofields.Remove(frow.Name);
                        }
                    }
                    // Add field
                    else if (!newvalue.Equals(oldvalue))
                    {
                        tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, newvalue);
                    }
                }
            }
        }
Beispiel #15
0
        // Constructor for a new filter
        internal ThingsFilter()
        {
            // Initialize everything as <any>
            requiredfields  = new List <string>();
            forbiddenfields = new List <string>();
            customfields    = new UniFields();
            categoryname    = "";
            thingtype       = -1;
            thingangle      = -1;
            thingzheight    = int.MinValue;
            thingaction     = -1;
            thingargs       = new int[Thing.NUM_ARGS];
            for (int i = 0; i < Thing.NUM_ARGS; i++)
            {
                thingargs[i] = -1;
            }
            thingtag = -1;
            name     = DEFAULT_NAME;

            // We have no destructor
            GC.SuppressFinalize(this);
        }
        public void SetValueFrom(UniFields fields, bool first)
        {
            blockevents = true;

            string colorval = String.Format("{0:X6}", UniFields.GetInteger(fields, field, defaultvalue));

            if (first)
            {
                tbColor.Text = colorval;
            }
            else if (!string.IsNullOrEmpty(tbColor.Text) && colorval != tbColor.Text)
            {
                blockupdate   = true;
                tbColor.Text  = string.Empty;
                cpColor.Color = PixelColor.FromInt(defaultvalue).WithAlpha(255);
                blockupdate   = false;

                CheckColor();
            }

            blockevents = false;
        }
Beispiel #17
0
        public UDMFMapFieldForm()
        {
            InitializeComponent();

            fields = new UniFields();

            if (General.Map.Map.UnidentifiedUDMF != null)
            {
                fieldslist.Setup("map");

                fieldslist.ClearFields();

                foreach (UniversalEntry u in General.Map.Map.UnidentifiedUDMF)
                {
                    if (!(u.Value is UniversalCollection))
                    {
                        int type = (int)UniversalType.Integer;

                        if (u.Value.GetType() == typeof(float))
                        {
                            type = (int)UniversalType.Float;
                        }
                        else if (u.Value.GetType() == typeof(bool))
                        {
                            type = (int)UniversalType.Boolean;
                        }
                        else if (u.Value.GetType() == typeof(string))
                        {
                            type = (int)UniversalType.String;
                        }

                        fields.Add(u.Key, new UniValue(type, u.Value));
                    }
                }
                // Custom fields
                fieldslist.SetValues(fields, true);
            }
        }
Beispiel #18
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;
        }
Beispiel #19
0
        public const string DEFAULT_NAME = "Unnamed filter";         //mxd

        #endregion

        #region ================== Constructor / Disposer

        // Copy constructor
        internal ThingsFilter(ThingsFilter f)
        {
            // Copy
            name         = f.name;
            categoryname = f.categoryname;
            invert       = f.invert;       //mxd
            displaymode  = f.displaymode;  //mxd
            thingtype    = f.thingtype;
            thingzheight = f.thingzheight;
            thingangle   = f.thingangle;
            thingaction  = f.thingaction;
            thingargs    = new int[Thing.NUM_ARGS];
            Array.Copy(f.thingargs, thingargs, Thing.NUM_ARGS);
            thingtag        = f.thingtag;
            customfields    = new UniFields(f.customfields);
            requiredfields  = new List <string>(f.requiredfields);
            forbiddenfields = new List <string>(f.forbiddenfields);

            AdjustForMapFormat();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
Beispiel #20
0
        protected MapElementProperties(UniFields other, MapElementType type)
        {
            // Should we bother?
            if (!General.Map.UDMF)
            {
                return;
            }

            // Copy source fields except the ones controlled by the UI
            fields      = new UniFields();
            uifields    = new UniFields();
            elementtype = type;
            foreach (KeyValuePair <string, UniValue> group in other)
            {
                if (General.Map.FormatInterface.UIFields[elementtype].ContainsKey(group.Key))
                {
                    uifields.Add(group.Key, new UniValue(group.Value));
                }
                else
                {
                    fields.Add(group.Key, new UniValue(group.Value));
                }
            }
        }
Beispiel #21
0
        // This sets up the fields and values from a UniFields object
        // When first is true, the values are applied unconditionally
        // When first is false, the values in the grid are erased when
        // they differ from the given values (for multiselection)
        public void SetValues(UniFields fromfields, bool first)
        {
            // Go for all the fields
            foreach (KeyValuePair <string, UniValue> f in fromfields)
            {
                if (uifields.ContainsKey(f.Key))
                {
                    continue;                                             //mxd
                }
                // Go for all rows
                bool foundrow = false;
                bool skiprow  = false;                //mxd
                foreach (DataGridViewRow row in fieldslist.Rows)
                {
                    // Row is a field?
                    if (row is FieldsEditorRow)
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        // Row name matches with field
                        if (frow.Name == f.Key)
                        {
                            //mxd. User vars are set separately
                            if (frow.RowType == FieldsEditorRowType.USERVAR)
                            {
                                skiprow = true;
                                break;
                            }

                            // First time?
                            if (first)
                            {
                                // Set type when row is not fixed
                                if (frow.RowType == FieldsEditorRowType.DYNAMIC)
                                {
                                    frow.ChangeType(f.Value.Type);
                                }

                                // Apply value of field to row
                                frow.Define(f.Value.Value);
                            }
                            else
                            {
                                // Check if the value is different
                                if (!frow.TypeHandler.GetValue().Equals(f.Value.Value))
                                {
                                    // Clear the value in the row
                                    frow.Define(f.Value.Value);
                                    frow.Clear();
                                }
                            }

                            // Done
                            foundrow = true;
                            break;
                        }
                    }
                }

                //mxd. User vars are set separately
                if (skiprow)
                {
                    continue;
                }

                // Row not found?
                if (!foundrow)
                {
                    // Make new row
                    FieldsEditorRow frow = new FieldsEditorRow(fieldslist, f.Key, f.Value.Type, f.Value.Value, false);
                    fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);

                    // When not the first, clear the field because the others did not define this one
                    if (!first)
                    {
                        frow.Clear();
                    }
                }
            }

            // Now check for rows that the givens fields do NOT have
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Is this row defined previously?
                    if (frow.IsDefined)
                    {
                        // Check if this row can not be found in the fields at all
                        if (!fromfields.ContainsKey(frow.Name))
                        {
                            // It is not defined in these fields, clear the value
                            frow.Clear();
                        }
                    }
                }
            }

            // Sort fields
            Sort();
        }
Beispiel #22
0
        //mxd
        protected void AlignTextureToSlopeLine(Linedef slopeSource, float slopeAngle, bool isFront, bool alignx, bool aligny)
        {
            bool isFloor = (geometrytype == VisualGeometryType.FLOOR);

            Sector.Sector.Fields.BeforeFieldsChange();
            float sourceAngle = (float)Math.Round(General.ClampAngle(isFront ? -Angle2D.RadToDeg(slopeSource.Angle) + 90 : -Angle2D.RadToDeg(slopeSource.Angle) - 90), 1);

            if (isFloor)
            {
                if ((isFront && slopeSource.Front.Sector.FloorHeight > slopeSource.Back.Sector.FloorHeight) ||
                    (!isFront && slopeSource.Front.Sector.FloorHeight < slopeSource.Back.Sector.FloorHeight))
                {
                    sourceAngle = General.ClampAngle(sourceAngle + 180);
                }
            }
            else
            {
                if ((isFront && slopeSource.Front.Sector.CeilHeight < slopeSource.Back.Sector.CeilHeight) ||
                    (!isFront && slopeSource.Front.Sector.CeilHeight > slopeSource.Back.Sector.CeilHeight))
                {
                    sourceAngle = General.ClampAngle(sourceAngle + 180);
                }
            }

            //update angle
            UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "rotationfloor" : "rotationceiling"), sourceAngle, 0f);

            //update scaleY
            string xScaleKey = (isFloor ? "xscalefloor" : "xscaleceiling");
            string yScaleKey = (isFloor ? "yscalefloor" : "yscaleceiling");

            float scaleX = Sector.Sector.Fields.GetValue(xScaleKey, 1.0f);
            float scaleY;

            //set scale
            if (aligny)
            {
                scaleY = (float)Math.Round(scaleX * (1 / (float)Math.Cos(slopeAngle)), 2);
                UniFields.SetFloat(Sector.Sector.Fields, yScaleKey, scaleY, 1.0f);
            }
            else
            {
                scaleY = Sector.Sector.Fields.GetValue(yScaleKey, 1.0f);
            }

            //update texture offsets
            Vector2D offset;

            if (isFloor)
            {
                if ((isFront && slopeSource.Front.Sector.FloorHeight < slopeSource.Back.Sector.FloorHeight) ||
                    (!isFront && slopeSource.Front.Sector.FloorHeight > slopeSource.Back.Sector.FloorHeight))
                {
                    offset = slopeSource.End.Position;
                }
                else
                {
                    offset = slopeSource.Start.Position;
                }
            }
            else
            {
                if ((isFront && slopeSource.Front.Sector.CeilHeight > slopeSource.Back.Sector.CeilHeight) ||
                    (!isFront && slopeSource.Front.Sector.CeilHeight < slopeSource.Back.Sector.CeilHeight))
                {
                    offset = slopeSource.End.Position;
                }
                else
                {
                    offset = slopeSource.Start.Position;
                }
            }

            offset = offset.GetRotated(Angle2D.DegToRad(sourceAngle));

            if (alignx)
            {
                if (Texture != null && Texture.IsImageLoaded)
                {
                    offset.x %= Texture.Width / scaleX;
                }
                UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "xpanningfloor" : "xpanningceiling"), (float)Math.Round(-offset.x), 0f);
            }

            if (aligny)
            {
                if (Texture != null && Texture.IsImageLoaded)
                {
                    offset.y %= Texture.Height / scaleY;
                }
                UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "ypanningfloor" : "ypanningceiling"), (float)Math.Round(offset.y), 0f);
            }

            //update geometry
            Sector.UpdateSectorGeometry(false);
        }
Beispiel #23
0
        //mxd
        protected void AlignTextureToClosestLine(bool alignx, bool aligny)
        {
            if (!(mode.HighlightedObject is BaseVisualSector))
            {
                return;
            }

            // Do we need to align this? (and also grab texture scale while we are at it)
            float scaleX, scaleY;
            bool  isFloor = (geometrytype == VisualGeometryType.FLOOR);

            if (mode.HighlightedTarget is VisualFloor)
            {
                VisualFloor target = (VisualFloor)mode.HighlightedTarget;

                // Check texture
                if (target.Sector.Sector.FloorTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture))
                {
                    return;
                }

                scaleX = target.Sector.Sector.Fields.GetValue("xscalefloor", 1.0f);
                scaleY = target.Sector.Sector.Fields.GetValue("yscalefloor", 1.0f);
            }
            else
            {
                VisualCeiling target = (VisualCeiling)mode.HighlightedTarget;

                // Check texture
                if (target.Sector.Sector.CeilTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture))
                {
                    return;
                }

                scaleX = target.Sector.Sector.Fields.GetValue("xscaleceiling", 1.0f);
                scaleY = target.Sector.Sector.Fields.GetValue("yscaleceiling", 1.0f);
            }

            //find a linedef to align to
            Vector2D hitpos = mode.GetHitPosition();

            if (!hitpos.IsFinite())
            {
                return;
            }

            //align to line of highlighted sector, which is closest to hitpos
            Sector         highlightedSector = ((BaseVisualSector)mode.HighlightedObject).Sector;
            List <Linedef> lines             = new List <Linedef>();

            foreach (Sidedef side in highlightedSector.Sidedefs)
            {
                lines.Add(side.Line);
            }

            Linedef targetLine = MapSet.NearestLinedef(lines, hitpos);

            if (targetLine == null)
            {
                return;
            }

            bool isFront = targetLine.SideOfLine(hitpos) > 0;

            Sector.Sector.Fields.BeforeFieldsChange();

            //find an angle to rotate texture
            float sourceAngle = (float)Math.Round(General.ClampAngle(isFront ? -Angle2D.RadToDeg(targetLine.Angle) + 90 : -Angle2D.RadToDeg(targetLine.Angle) - 90), 1);

            if (!isFront)
            {
                sourceAngle = General.ClampAngle(sourceAngle + 180);
            }

            //update angle
            UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "rotationfloor" : "rotationceiling"), sourceAngle, 0f);

            //set scale
            UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "xscalefloor" : "xscaleceiling"), scaleX, 1.0f);
            UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "yscalefloor" : "yscaleceiling"), scaleY, 1.0f);

            //update offset
            float    distToStart = Vector2D.Distance(hitpos, targetLine.Start.Position);
            float    distToEnd   = Vector2D.Distance(hitpos, targetLine.End.Position);
            Vector2D offset      = (distToStart < distToEnd ? targetLine.Start.Position : targetLine.End.Position).GetRotated(Angle2D.DegToRad(sourceAngle));

            if (alignx)
            {
                if (Texture != null && Texture.IsImageLoaded)
                {
                    offset.x %= Texture.Width / scaleX;
                }
                UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "xpanningfloor" : "xpanningceiling"), (float)Math.Round(-offset.x), 0f);
            }

            if (aligny)
            {
                if (Texture != null && Texture.IsImageLoaded)
                {
                    offset.y %= Texture.Height / scaleY;
                }
                UniFields.SetFloat(Sector.Sector.Fields, (isFloor ? "ypanningfloor" : "ypanningceiling"), (float)Math.Round(offset.y), 0f);
            }

            //update geometry
            Sector.UpdateSectorGeometry(false);
        }
Beispiel #24
0
 protected void Apply(UniFields other, string key1, string key2)
 {
     Apply(other, key1);
     Apply(other, key2);
 }
Beispiel #25
0
        public static bool PropertiesMatch(SectorPropertiesCopySettings flags, Sector source, Sector target)
        {
            // Built-in properties
            if (flags.FloorHeight && source.FloorHeight != target.FloorHeight)
            {
                return(false);
            }
            if (flags.CeilingHeight && source.CeilHeight != target.CeilHeight)
            {
                return(false);
            }
            if (flags.FloorTexture && source.FloorTexture != target.FloorTexture)
            {
                return(false);
            }
            if (flags.CeilingTexture && source.CeilTexture != target.CeilTexture)
            {
                return(false);
            }
            if (flags.Brightness && source.Brightness != target.Brightness)
            {
                return(false);
            }
            if (flags.Tag && !TagsMatch(source.Tags, target.Tags))
            {
                return(false);
            }
            if (flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags()))
            {
                return(false);
            }

            // Generalized effects require more tender loving care...
            if (flags.Special && source.Effect != target.Effect)
            {
                if (!General.Map.Config.GeneralizedEffects || source.Effect == 0 || target.Effect == 0)
                {
                    return(false);
                }

                // Get effect bits...
                SectorEffectData sourcedata = General.Map.Config.GetSectorEffectData(source.Effect);
                SectorEffectData targetdata = General.Map.Config.GetSectorEffectData(target.Effect);

                // No bits match when at least one effect is not generalized, or when bits don't overlap
                if (sourcedata.Effect != targetdata.Effect ||
                    sourcedata.GeneralizedBits.Count != targetdata.GeneralizedBits.Count ||
                    !sourcedata.GeneralizedBits.Overlaps(targetdata.GeneralizedBits))
                {
                    return(false);
                }
            }

            if (!General.Map.UDMF)
            {
                return(true);
            }

            // UI fields
            if (!UIFieldsMatch(flags, source, target))
            {
                return(false);
            }

            // Custom fields
            return(!flags.Fields || UniFields.CustomFieldsMatch(source.Fields, target.Fields));
        }
Beispiel #26
0
        // This applies the current fields to a UniFields object
        public void Apply(UniFields tofields)
        {
            tofields.BeforeFieldsChange();

            // Go for all the fields
            UniFields tempfields = new UniFields(tofields);

            foreach (KeyValuePair <string, UniValue> f in tempfields)
            {
                if (uifields.ContainsKey(f.Key))
                {
                    continue;                                             //mxd
                }
                // Go for all rows
                bool foundrow = false;
                bool skiprow  = false;                //mxd
                foreach (DataGridViewRow row in fieldslist.Rows)
                {
                    // Row is a field and matches field name?
                    if ((row is FieldsEditorRow) && (row.Cells[0].Value.ToString() == f.Key))
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        //mxd. User vars are stored separately
                        if (frow.RowType == FieldsEditorRowType.USERVAR)
                        {
                            skiprow = true;
                            break;
                        }

                        // Field is defined?
                        if (frow.IsDefined)
                        {
                            foundrow = true;
                            break;
                        }
                    }
                }

                //mxd. User vars are stored separately
                if (skiprow)
                {
                    continue;
                }

                // No such row?
                if (!foundrow)
                {
                    // Remove the definition from the fields
                    tofields.Remove(f.Key);
                }
            }

            // Go for all rows
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Field is defined and not empty?
                    if (frow.RowType != FieldsEditorRowType.USERVAR && frow.IsDefined && !frow.IsEmpty)
                    {
                        // Apply field
                        object oldvalue = null;
                        if (tofields.ContainsKey(frow.Name))
                        {
                            oldvalue = tofields[frow.Name].Value;
                        }
                        tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, frow.GetResult(oldvalue));

                        // Custom row?
                        if (frow.RowType == FieldsEditorRowType.DYNAMIC)
                        {
                            // Write type to map configuration
                            General.Map.Options.SetUniversalFieldType(elementname, frow.Name, frow.TypeHandler.Index);
                        }
                    }
                }
            }
        }
Beispiel #27
0
        public static bool PropertiesMatch(ThingPropertiesCopySettings flags, Thing source, Thing target)
        {
            // Built-in properties
            if (flags.Type && source.Type != target.Type)
            {
                return(false);
            }
            if (flags.Angle && source.AngleDoom != target.AngleDoom)
            {
                return(false);
            }
            if (flags.Action && source.Action != target.Action)
            {
                return(false);
            }
            if (flags.Arguments)
            {
                // Classic args
                for (int i = 0; i < source.Args.Length; i++)
                {
                    if (source.Args[i] != target.Args[i])
                    {
                        return(false);
                    }
                }

                // String args
                if (General.Map.UDMF)
                {
                    if (!UniFields.ValuesMatch("arg0str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg1str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg2str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg3str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg4str", source, target))
                    {
                        return(false);
                    }
                }
            }
            if (flags.Tag && source.Tag != target.Tag)
            {
                return(false);
            }
            if (flags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags()))
            {
                return(false);
            }
            if (!General.Map.UDMF)
            {
                return(true);
            }

            // UDMF-specific properties
            if (flags.Pitch && source.Pitch != target.Pitch)
            {
                return(false);
            }
            if (flags.Roll && source.Roll != target.Roll)
            {
                return(false);
            }
            if (flags.Scale && (source.ScaleX != target.ScaleX) || (source.ScaleY != target.ScaleY))
            {
                return(false);
            }

            // UI fields
            if (!UIFieldsMatch(flags, source, target))
            {
                return(false);
            }

            // Custom fields
            return(!flags.Fields || UniFields.CustomFieldsMatch(source.Fields, target.Fields));
        }
Beispiel #28
0
 public VertexProperties(Vertex v)
 {
     fields = new UniFields(v.Fields);
 }
        // Apply clicked
        private void apply_Click(object sender, EventArgs e)
        {
            //mxd. Make Undo
            MakeUndo();

            List <string> defaultflags = new List <string>();

            // Verify the tag
            if (General.Map.FormatInterface.HasThingTag)  //mxd
            {
                tagSelector.ValidateTag();                //mxd
                if (((tagSelector.GetTag(0) < General.Map.FormatInterface.MinTag) || (tagSelector.GetTag(0) > General.Map.FormatInterface.MaxTag)))
                {
                    General.ShowWarningMessage("Thing tag must be between " + General.Map.FormatInterface.MinTag + " and " + General.Map.FormatInterface.MaxTag + ".", MessageBoxButtons.OK);
                    return;
                }
            }

            // Verify the type
            if (!string.IsNullOrEmpty(thingtype.TypeStringValue) && ((thingtype.GetResult(0) < General.Map.FormatInterface.MinThingType) || (thingtype.GetResult(0) > General.Map.FormatInterface.MaxThingType)))
            {
                General.ShowWarningMessage("Thing type must be between " + General.Map.FormatInterface.MinThingType + " and " + General.Map.FormatInterface.MaxThingType + ".", MessageBoxButtons.OK);
                return;
            }

            // Verify the action
            if (General.Map.FormatInterface.HasThingAction && ((action.Value < General.Map.FormatInterface.MinAction) || (action.Value > General.Map.FormatInterface.MaxAction)))
            {
                General.ShowWarningMessage("Thing action must be between " + General.Map.FormatInterface.MinAction + " and " + General.Map.FormatInterface.MaxAction + ".", MessageBoxButtons.OK);
                return;
            }

            // Go for all the things
            int offset = 0;             //mxd

            foreach (Thing t in things)
            {
                // Coordination
                //mxd. Randomize rotations?
                if (cbrandomangle.Checked)
                {
                    int newangle = General.Random(0, 359);
                    if (General.Map.Config.DoomThingRotationAngles)
                    {
                        newangle = newangle / 45 * 45;
                    }
                    t.Rotate(newangle);
                }
                if (cbrandompitch.Checked)
                {
                    t.SetPitch(General.Random(0, 359));
                }
                if (cbrandomroll.Checked)
                {
                    t.SetRoll(General.Random(0, 359));
                }

                //mxd. Check position
                double px = General.Clamp(t.Position.x, General.Map.Config.LeftBoundary, General.Map.Config.RightBoundary);
                double py = General.Clamp(t.Position.y, General.Map.Config.BottomBoundary, General.Map.Config.TopBoundary);
                if (t.Position.x != px || t.Position.y != py)
                {
                    t.Move(new Vector2D(px, py));
                }

                // Action/tags
                t.Tag = General.Clamp(tagSelector.GetSmartTag(t.Tag, offset), General.Map.FormatInterface.MinTag, General.Map.FormatInterface.MaxTag);                 //mxd
                if (!action.Empty)
                {
                    t.Action = action.Value;
                }

                //mxd. Apply args
                argscontrol.Apply(t, offset);

                //mxd. Custom fields
                fieldslist.Apply(t.Fields);
                if (!string.IsNullOrEmpty(conversationID.Text))
                {
                    UniFields.SetInteger(t.Fields, "conversation", conversationID.GetResult(t.Fields.GetValue("conversation", 0)), 0);
                }
                if (!string.IsNullOrEmpty(floatbobphase.Text))
                {
                    UniFields.SetInteger(t.Fields, "floatbobphase", General.Clamp(floatbobphase.GetResult(t.Fields.GetValue("floatbobphase", -1)), -1, 63), -1);
                }
                if (!string.IsNullOrEmpty(gravity.Text))
                {
                    UniFields.SetFloat(t.Fields, "gravity", gravity.GetResultFloat(t.Fields.GetValue("gravity", 1.0)), 1.0);
                }
                if (!string.IsNullOrEmpty(health.Text))
                {
                    UniFields.SetInteger(t.Fields, "health", health.GetResult(t.Fields.GetValue("health", 1)), 1);
                }
                if (!string.IsNullOrEmpty(score.Text))
                {
                    UniFields.SetInteger(t.Fields, "score", score.GetResult(t.Fields.GetValue("score", 0)), 0);
                }

                //mxd. User vars. Should be called after fieldslist.Apply()
                ThingTypeInfo ti = General.Map.Data.GetThingInfoEx(t.Type);
                if (ti != null && ti.Actor != null && ti.Actor.UserVars.Count > 0)
                {
                    fieldslist.ApplyUserVars(ti.Actor.UserVars, t.Fields);
                }

                color.ApplyTo(t.Fields, t.Fields.GetValue("fillcolor", 0));

                //mxd. Comments
                commenteditor.Apply(t.Fields);

                // Update settings
                t.UpdateConfiguration();

                //mxd. Increase offset...
                offset++;
            }

            // Set as defaults
            foreach (CheckBox c in flags.Checkboxes)
            {
                if (c.CheckState == CheckState.Checked)
                {
                    defaultflags.Add(c.Tag.ToString());
                }
            }
            General.Settings.DefaultThingType  = thingtype.GetResult(General.Settings.DefaultThingType);
            General.Settings.DefaultThingAngle = Angle2D.DegToRad((float)angle.GetResult((int)Angle2D.RadToDeg(General.Settings.DefaultThingAngle) - 90) + 90);
            General.Settings.SetDefaultThingFlags(defaultflags);

            // Done
            General.Map.IsChanged = true;
            if (OnValuesChanged != null)
            {
                OnValuesChanged(this, EventArgs.Empty);                                     //mxd
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Beispiel #30
0
        //mxd
        public void SetUserVars(Dictionary <string, UniversalType> vars, UniFields fromfields, bool first)
        {
            foreach (KeyValuePair <string, UniversalType> group in vars)
            {
                // Go for all rows
                bool        foundrow = false;
                TypeHandler vartype  = General.Types.GetFieldHandler((int)group.Value, 0);
                object      value    = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue();

                foreach (DataGridViewRow row in fieldslist.Rows)
                {
                    // Row is a field?
                    if (row is FieldsEditorRow)
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        // Row name matches with user var?
                        if (frow.RowType == FieldsEditorRowType.USERVAR && frow.Name == group.Key)
                        {
                            // First time?
                            if (first)
                            {
                                frow.Define(value);
                            }
                            // Check if the value is different
                            else if (!frow.TypeHandler.GetValue().Equals(value))
                            {
                                // Clear the value in the row
                                frow.Define(value);
                                frow.Clear();
                            }

                            // Done
                            foundrow = true;
                            break;
                        }
                    }
                }

                // Row not found?
                if (!foundrow)
                {
                    // Make new row
                    object          defaultvalue = vartype.GetDefaultValue();
                    FieldsEditorRow frow         = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true);
                    if (!value.Equals(defaultvalue))
                    {
                        frow.Define(value);
                    }
                    fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
                }
            }

            // Now check for rows that the givens fields do NOT have
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Don't undefine user var rows defined by other actor types
                    if (frow.RowType == FieldsEditorRowType.USERVAR || vars.ContainsKey(frow.Name))
                    {
                        continue;
                    }

                    // Is this row defined previously?
                    if (frow.IsDefined)
                    {
                        // Check if this row can not be found in the fields at all
                        if (!fromfields.ContainsKey(frow.Name))
                        {
                            // It is not defined in these fields, undefine the value
                            frow.Undefine();
                        }
                    }
                }
            }

            // Sort fields
            Sort();
        }
Beispiel #31
0
        public static bool PropertiesMatch(LinedefPropertiesCopySettings linedefflags, SidedefPropertiesCopySettings sideflags, Linedef source, Linedef target)
        {
            // Built-in properties
            if (linedefflags.Action && source.Action != target.Action)
            {
                return(false);
            }
            if (linedefflags.Activation && source.Activate != target.Activate)
            {
                return(false);
            }
            if (linedefflags.Tag && !TagsMatch(source.Tags, target.Tags))
            {
                return(false);
            }
            if (linedefflags.Arguments)
            {
                // Classic args
                for (int i = 0; i < source.Args.Length; i++)
                {
                    if (source.Args[i] != target.Args[i])
                    {
                        return(false);
                    }
                }

                // String args
                if (General.Map.UDMF)
                {
                    if (!UniFields.ValuesMatch("arg0str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg1str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg2str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg3str", source, target))
                    {
                        return(false);
                    }
                    if (!UniFields.ValuesMatch("arg4str", source, target))
                    {
                        return(false);
                    }
                }
            }
            if (linedefflags.Flags && !FlagsMatch(source.GetEnabledFlags(), target.GetEnabledFlags()))
            {
                return(false);
            }

            if (General.Map.UDMF)
            {
                // UI fields
                if (!UIFieldsMatch(linedefflags, source, target))
                {
                    return(false);
                }

                // Custom fields
                if (linedefflags.Fields && !UniFields.CustomFieldsMatch(source.Fields, target.Fields))
                {
                    return(false);
                }
            }

            // Sidedef properties
            return((source.Front != null && target.Front != null && PropertiesMatch(sideflags, source.Front, target.Front)) ||
                   (source.Front != null && target.Back != null && PropertiesMatch(sideflags, source.Front, target.Back)) ||
                   (source.Back != null && target.Front != null && PropertiesMatch(sideflags, source.Back, target.Front)) ||
                   (source.Back != null && target.Back != null && PropertiesMatch(sideflags, source.Back, target.Back)));
        }