// 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();
        }
        public void ApplyTo(UniFields fields, int oldvalue)
        {
            int colorval = !string.IsNullOrEmpty(tbColor.Text) ? (cpColor.Color.ToInt() & 0x00FFFFFF) : oldvalue;

            UniFields.SetInteger(fields, field, colorval, defaultvalue);
        }
Exemplo n.º 3
0
        //mxd. Sector brightness change
        public override void OnChangeTargetBrightness(bool up)
        {
            if (level != null && level.sector != Sector.Sector)
            {
                int index = -1;
                for (int i = 0; i < Sector.ExtraCeilings.Count; i++)
                {
                    if (Sector.ExtraCeilings[i] == this)
                    {
                        index = i + 1;
                        break;
                    }
                }

                if (index > -1 && index < Sector.ExtraCeilings.Count)
                {
                    ((BaseVisualSector)mode.GetVisualSector(Sector.ExtraCeilings[index].level.sector)).Floor.OnChangeTargetBrightness(up);
                }
                else
                {
                    base.OnChangeTargetBrightness(up);
                }
            }
            else
            {
                //if a map is not in UDMF format, or this ceiling is part of 3D-floor...
                if (!General.Map.UDMF || (level != null && Sector.Sector != level.sector))
                {
                    base.OnChangeTargetBrightness(up);
                    return;
                }

                int  light    = Sector.Sector.Fields.GetValue("lightceiling", 0);
                bool absolute = Sector.Sector.Fields.GetValue("lightceilingabsolute", false);
                int  newLight;

                if (up)
                {
                    newLight = General.Map.Config.BrightnessLevels.GetNextHigher(light, absolute);
                }
                else
                {
                    newLight = General.Map.Config.BrightnessLevels.GetNextLower(light, absolute);
                }

                if (newLight == light)
                {
                    return;
                }

                //create undo
                mode.CreateUndo("Change ceiling brightness", UndoGroup.SurfaceBrightnessChange, Sector.Sector.FixedIndex);
                Sector.Sector.Fields.BeforeFieldsChange();

                //apply changes
                UniFields.SetInteger(Sector.Sector.Fields, "lightceiling", newLight, (absolute ? int.MinValue : 0));
                mode.SetActionResult("Changed ceiling brightness to " + newLight + ".");
                Sector.Sector.UpdateNeeded = true;
                Sector.Sector.UpdateCache();

                //rebuild sector
                Sector.UpdateSectorGeometry(false);
            }
        }
Exemplo n.º 4
0
        private void UpdateShading()
        {
            // Update sector shading
            foreach (KeyValuePair <Sector, Vector3D> group in sectors)
            {
                // Calculate light amount
                float      anglediff = Vector3D.DotProduct(group.Value, sunvector);
                int        targetlight;
                PixelColor targetcolor;

                // Calculate light and light color when surface normal is rotated towards the sun vector
                if (anglediff >= 0.5f)
                {
                    float lightmul = (anglediff - 0.5f) * 2.0f;
                    targetlight = (int)Math.Round(lightamount.Value * lightmul);
                    targetcolor = InterpolationTools.InterpolateColor(shadecolor.Color, lightcolor.Color, anglediff);
                }
                // Otherwise calculate shade and shade color
                else
                {
                    float lightmul = (0.5f - anglediff) * -2.0f;
                    targetlight = (int)Math.Round(shadeamount.Value * lightmul);
                    targetcolor = InterpolationTools.InterpolateColor(shadecolor.Color, lightcolor.Color, anglediff);
                }

                // Apply settings
                if (group.Key.Fields.GetValue("lightfloorabsolute", false))
                {
                    UniFields.SetInteger(group.Key.Fields, "lightfloor", General.Clamp(targetlight + sectorbrightness[group.Key], 0, 255), 0);
                }
                else
                {
                    UniFields.SetInteger(group.Key.Fields, "lightfloor", General.Clamp(targetlight, -255, 255), 0);
                }

                // Apply sector color
                int c = (targetcolor.ToInt() & 0x00FFFFFF);

                // Restore initial color?
                if (c == PixelColor.INT_WHITE_NO_ALPHA)
                {
                    c = sectorcolors[group.Key];
                }

                // Apply color
                UniFields.SetInteger(group.Key.Fields, "lightcolor", c, PixelColor.INT_WHITE_NO_ALPHA);

                // Mark for update
                group.Key.UpdateNeeded = true;
            }

            // Update sidedef shading
            foreach (KeyValuePair <Sidedef, Vector3D> group in sides)
            {
                // Calculate light amount
                float anglediff = Vector3D.DotProduct(group.Value, sunvector);
                int   targetlight;

                // Calculate light and light color when surface normal is rotated towards the sun vector
                if (anglediff >= 0.5f)
                {
                    float lightmul = (anglediff - 0.5f) * 2.0f;
                    targetlight = (int)Math.Round(lightamount.Value * lightmul);
                }
                // Otherwise calculate shade and shade color
                else
                {
                    float lightmul = (0.5f - anglediff) * -2.0f;
                    targetlight = (int)Math.Round(shadeamount.Value * lightmul);
                }

                // Apply settings
                if (group.Key.Fields.GetValue("lightabsolute", false))
                {
                    UniFields.SetInteger(group.Key.Fields, "light", General.Clamp(targetlight + sidebrightness[group.Key], 0, 255), 0);
                }
                else
                {
                    UniFields.SetInteger(group.Key.Fields, "light", General.Clamp(targetlight, -255, 255), 0);
                }

                // Mark for update
                group.Key.Sector.UpdateNeeded = true;
            }

            // Update map
            General.Map.Map.Update();
            General.Map.IsChanged = true;

            // Update view
            if (visualsectors != null)
            {
                foreach (var vs in visualsectors)
                {
                    vs.UpdateSectorData();
                }
            }
            else if (sectors.Count > 0)
            {
                General.Interface.RedrawDisplay();
            }
        }