// This sets the Lower Unpegged flag public virtual void ApplyBottomAlignment(bool set) { if (!set) { // Remove flag mode.CreateUndo("Remove bottom-aligned setting"); mode.SetActionResult("Removed bottom-aligned setting."); Sidedef.SetFlag(General.Map.FormatInterface.WallFlags.AlignImageToBottom, false); } else { // Add flag mode.CreateUndo("Set bottom-aligned setting"); mode.SetActionResult("Set bottom-aligned setting."); Sidedef.SetFlag(General.Map.FormatInterface.WallFlags.AlignImageToBottom, true); } // Update sidedef geometry VisualWallParts parts = Sector.GetSidedefParts(Sidedef); parts.SetupAllParts(); // Update other sidedef geometry /*if(Sidedef.Other != null) * { * BaseVisualSector othersector = (BaseVisualSector)mode.GetVisualSector(Sidedef.Other.Sector); * parts = othersector.GetSidedefParts(Sidedef.Other); * parts.SetupAllParts(); * }*/ }
// Paste texture offsets public virtual void OnPasteImageOffsets() { mode.CreateUndo("Paste image offsets"); Sidedef.OffsetX = BuilderPlug.Me.CopiedOffsets.X; Sidedef.OffsetY = BuilderPlug.Me.CopiedOffsets.Y; mode.SetActionResult("Pasted image offsets " + Sidedef.OffsetX + ", " + Sidedef.OffsetY + "."); // Update sidedef geometry VisualWallParts parts = Sector.GetSidedefParts(Sidedef); parts.SetupAllParts(); }
// Image offset change public virtual void OnChangeImageOffset(int horizontal, int vertical) { if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket)) { undoticket = mode.CreateUndo("Change image offsets"); } // Apply offsets Sidedef.OffsetX -= horizontal; Sidedef.OffsetY -= vertical; mode.SetActionResult("Changed image offsets to " + Sidedef.OffsetX + ", " + Sidedef.OffsetY + "."); // Update wall geometry VisualWallParts parts = Sector.GetSidedefParts(Sidedef); parts.SetupAllParts(); }
// Sector brightness change public virtual void OnChangeTargetShade(bool up) { // Change shade if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket)) { undoticket = mode.CreateUndo("Change wall shade"); } // Apply shade Sidedef.Shade = General.Clamp(Sidedef.Shade + (up ? 1 : -1), General.Map.FormatInterface.MinShade, General.Map.FormatInterface.MaxShade); mode.SetActionResult("Changed wall shade to " + Sidedef.Shade + "."); // Update wall geometry VisualWallParts parts = Sector.GetSidedefParts(Sidedef); parts.SetupAllParts(); }
// Auto-align texture X offsets public virtual void OnImageAlign(bool alignx, bool aligny) { mode.CreateUndo("Auto-align images"); mode.SetActionResult("Auto-aligned images."); // Make sure the texture is loaded (we need the texture size) if (!base.Texture.IsImageLoaded) { base.Texture.LoadImage(); } if (mode.IsSingleSelection) { // Clear all marks, this will align everything it can General.Map.Map.ClearMarkedSidedefs(false); } else { // Limit the alignment to selection only General.Map.Map.ClearMarkedSidedefs(true); List <Sidedef> sides = mode.GetSelectedWalls(); foreach (Sidedef sd in sides) { sd.Marked = false; } } // Do the alignment Tools.AutoAlignImages(this.Sidedef, base.Texture, alignx, aligny, false); // Get the changed sidedefs List <Sidedef> changes = General.Map.Map.GetMarkedSidedefs(true); foreach (Sidedef sd in changes) { // Update the parts for this sidedef! if (mode.VisualSectorExists(sd.Sector)) { BaseVisualSector vs = (mode.GetVisualSector(sd.Sector) as BaseVisualSector); VisualWallParts parts = vs.GetSidedefParts(sd); parts.SetupAllParts(); } } }
// This (re)builds the visual sector, calculating all geometry from scratch public void Rebuild() { // Forget old geometry base.ClearGeometry(); // Create floor if (floor == null) { floor = new VisualFloor(mode, this); } floor.Setup(); base.AddGeometry(floor); // Create ceiling if (ceiling == null) { ceiling = new VisualCeiling(mode, this); } ceiling.Setup(); base.AddGeometry(ceiling); // Go for all sidedefs Dictionary <Sidedef, VisualWallParts> oldsides = sides ?? new Dictionary <Sidedef, VisualWallParts>(1); sides = new Dictionary <Sidedef, VisualWallParts>(base.Sector.Sidedefs.Count); foreach (Sidedef sd in base.Sector.Sidedefs) { // VisualSidedef already exists? VisualWallParts parts = oldsides.ContainsKey(sd) ? oldsides[sd] : new VisualWallParts(); // Doublesided or singlesided? if (sd.Other != null) { // Create upper part VisualUpper vu = parts.upper ?? new VisualUpper(mode, this, sd); vu.Setup(); base.AddGeometry(vu); // Create lower part VisualLower vl = parts.lower ?? new VisualLower(mode, this, sd); vl.Setup(); base.AddGeometry(vl); // Create middle part VisualMiddleDouble vm = parts.middledouble ?? new VisualMiddleDouble(mode, this, sd); vm.Setup(); base.AddGeometry(vm); // Store sides.Add(sd, new VisualWallParts(vu, vl, vm)); } else { // Create middle part VisualMiddleSingle vm = parts.middlesingle ?? new VisualMiddleSingle(mode, this, sd); vm.Setup(); base.AddGeometry(vm); // Store sides.Add(sd, new VisualWallParts(vm)); } } // Done changed = false; }
// This usually happens when geometry is changed by undo, redo, cut or paste actions // and uses the marks to check what needs to be reloaded. protected override void ResourcesReloadedPartial() { bool sectorsmarked = false; if (General.Map.UndoRedo.GeometryChanged) { // Let the core do this (it will just dispose the sectors that were changed) base.ResourcesReloadedPartial(); } else { // Neighbour sectors must be updated as well foreach (Sector s in General.Map.Map.Sectors) { if (s.Marked) { sectorsmarked = true; foreach (Sidedef sd in s.Sidedefs) { sd.Marked = true; if (sd.Other != null) { sd.Other.Marked = true; } } } } // Go for all sidedefs to update foreach (Sidedef sd in General.Map.Map.Sidedefs) { if (sd.Marked && VisualSectorExists(sd.Sector)) { BaseVisualSector vs = (BaseVisualSector)GetVisualSector(sd.Sector); VisualWallParts parts = vs.GetSidedefParts(sd); parts.SetupAllParts(); } } // Go for all sectors to update foreach (Sector s in General.Map.Map.Sectors) { if (s.Marked && VisualSectorExists(s)) { BaseVisualSector vs = (BaseVisualSector)GetVisualSector(s); vs.Floor.Setup(); vs.Ceiling.Setup(); } } if (!sectorsmarked) { // No sectors or geometry changed. So we only have // to update things when they have changed. foreach (KeyValuePair <Thing, VisualThing> vt in allthings) { if ((vt.Value != null) && vt.Key.Marked) { (vt.Value as BaseVisualThing).Rebuild(); } } } else { // Things depend on the sector they are in and because we can't // easily determine which ones changed, we dispose all things foreach (KeyValuePair <Thing, VisualThing> vt in allthings) { if (vt.Value != null) { vt.Value.Dispose(); } } // Apply new lists allthings = new Dictionary <Thing, VisualThing>(allthings.Count); } // Clear visibility collections visiblesectors.Clear(); visibleblocks.Clear(); visiblegeometry.Clear(); visiblethings.Clear(); // Make new blockmap if (sectorsmarked || General.Map.UndoRedo.PopulationChanged) { FillBlockMap(); } // Visibility culling (this re-creates the needed resources) DoCulling(); } // Determine what we're aiming at now PickTarget(); }
// Flood-fill textures public virtual void OnImageFloodfill() { if (BuilderPlug.Me.CopiedImageIndex <= -1) { return; } int oldtile = GetImageIndex(); int newtile = BuilderPlug.Me.CopiedImageIndex; if (newtile == oldtile) { return; } mode.CreateUndo("Flood-fill images with image " + newtile); mode.SetActionResult("Flood-filled images with " + newtile + "."); mode.Renderer.SetCrosshairBusy(true); General.Interface.RedrawDisplay(); // Get the image ImageData newtextureimage = General.Map.Data.GetImageData(newtile); if (newtextureimage == null) { return; } if (mode.IsSingleSelection) { // Clear all marks, this will align everything it can General.Map.Map.ClearMarkedSidedefs(false); } else { // Limit the alignment to selection only General.Map.Map.ClearMarkedSidedefs(true); List <Sidedef> sides = mode.GetSelectedWalls(); foreach (Sidedef sd in sides) { sd.Marked = false; } } // Do the alignment Tools.FloodfillWallImages(this.Sidedef, oldtile, newtile, false); // Get the changed sidedefs List <Sidedef> changes = General.Map.Map.GetMarkedSidedefs(true); foreach (Sidedef sd in changes) { // Update the parts for this sidedef! if (mode.VisualSectorExists(sd.Sector)) { BaseVisualSector vs = (mode.GetVisualSector(sd.Sector) as BaseVisualSector); VisualWallParts parts = vs.GetSidedefParts(sd); parts.SetupAllParts(); } } General.Map.Data.UpdateUsedImages(); mode.Renderer.SetCrosshairBusy(false); mode.ShowTargetInfo(); }