/// <summary> /// Gets the current lot's thumbnail. /// </summary> /// <param name="objects">The object components to draw.</param> /// <param name="gd">GraphicsDevice instance.</param> /// <param name="state">WorldState instance.</param> /// <returns>Object's ID if the object was found at the given position.</returns> public virtual Texture2D GetLotThumb(GraphicsDevice gd, WorldState state) { if (!(state.Camera is WorldCamera)) { return(new Texture2D(gd, 8, 8)); } var oldZoom = state.Zoom; var oldRotation = state.Rotation; var oldLevel = state.Level; var oldCutaway = Blueprint.Cutaway; var wCam = (WorldCamera)state.Camera; var oldViewDimensions = wCam.ViewDimensions; //wCam.ViewDimensions = new Vector2(-1, -1); var oldPreciseZoom = state.PreciseZoom; //full invalidation because we must recalculate all object sprites. slow but necessary! state.Zoom = WorldZoom.Far; state.Rotation = WorldRotation.TopLeft; state.Level = Blueprint.Stories; state.PreciseZoom = 1 / 4f; state._2D.PreciseZoom = state.PreciseZoom; state.WorldSpace.Invalidate(); state.InvalidateCamera(); var oldCenter = state.CenterTile; state.CenterTile = new Vector2(Blueprint.Width / 2, Blueprint.Height / 2); state.CenterTile -= state.WorldSpace.GetTileFromScreen(new Vector2((576 - state.WorldSpace.WorldPxWidth) * 4, (576 - state.WorldSpace.WorldPxHeight) * 4) / 2); var pxOffset = -state.WorldSpace.GetScreenOffset(); state.TempDraw = true; Blueprint.Cutaway = new bool[Blueprint.Cutaway.Length]; var _2d = state._2D; state.ClearLighting(true); Promise <Texture2D> bufferTexture = null; var lastLight = state.OutsideColor; state.OutsideColor = Color.White; state._2D.OBJIDMode = false; using (var buffer = state._2D.WithBuffer(BUFFER_LOTTHUMB, ref bufferTexture)) { _2d.SetScroll(pxOffset); while (buffer.NextPass()) { _2d.Pause(); _2d.Resume(); Blueprint.FloorGeom.SliceReset(gd, new Rectangle(6, 6, Blueprint.Width - 13, Blueprint.Height - 13)); //Blueprint.SetLightColor(WorldContent.GrassEffect, Color.White, Color.White); Blueprint.Terrain.Draw(gd, state); Blueprint.WallComp.Draw(gd, state); _2d.Pause(); _2d.Resume(); foreach (var obj in Blueprint.Objects) { var renderInfo = GetRenderInfo(obj); var tilePosition = obj.Position; _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition)); _2d.OffsetTile(tilePosition); obj.Draw(gd, state); } Blueprint.RoofComp.Draw(gd, state); } } Blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.LIGHTING_CHANGED)); Blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.FLOOR_CHANGED)); //return things to normal //state.PrepareLighting(); state.OutsideColor = lastLight; state.PreciseZoom = oldPreciseZoom; state.WorldSpace.Invalidate(); state.InvalidateCamera(); wCam.ViewDimensions = oldViewDimensions; state.TempDraw = false; state.CenterTile = oldCenter; state.Zoom = oldZoom; state.Rotation = oldRotation; state.Level = oldLevel; Blueprint.Cutaway = oldCutaway; var tex = bufferTexture.Get(); return(tex); //TextureUtils.Clip(gd, tex, bounds); }
/// <summary> /// Gets an object group's thumbnail provided an array of objects. /// </summary> /// <param name="objects">The object components to draw.</param> /// <param name="gd">GraphicsDevice instance.</param> /// <param name="state">WorldState instance.</param> /// <returns>Object's ID if the object was found at the given position.</returns> public virtual Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd, WorldState state) { var oldZoom = state.Zoom; var oldRotation = state.Rotation; var oldPreciseZoom = state.PreciseZoom; /** Center average position **/ Vector3 average = new Vector3(); for (int i = 0; i < positions.Length; i++) { average += positions[i]; } average /= positions.Length; state.SilentZoom = WorldZoom.Near; state.SilentRotation = WorldRotation.BottomRight; state.SilentPreciseZoom = 1; state.WorldSpace.Invalidate(); state.InvalidateCamera(); state.DrawOOB = true; state.TempDraw = true; var pxOffset = new Vector2(442, 275) - state.WorldSpace.GetScreenFromTile(average); var _2d = state._2D; Promise <Texture2D> bufferTexture = null; Promise <Texture2D> depthTexture = null; state._2D.OBJIDMode = false; Rectangle bounds = new Rectangle(); state.ClearLighting(true); using (var buffer = state._2D.WithBuffer(BUFFER_THUMB, ref bufferTexture, BUFFER_THUMB_DEPTH, ref depthTexture)) { _2d.SetScroll(new Vector2()); while (buffer.NextPass()) { for (int i = 0; i < objects.Length; i++) { var obj = objects[i]; var tilePosition = positions[i]; //we need to trick the object into believing it is in a set world state. var oldObjRot = obj.Direction; var oldRoom = obj.Room; obj.Direction = Direction.NORTH; obj.Room = 65535; state.SilentZoom = WorldZoom.Near; state.SilentRotation = WorldRotation.BottomRight; obj.OnRotationChanged(state); obj.OnZoomChanged(state); _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition) + pxOffset); _2d.OffsetTile(tilePosition); _2d.SetObjID(obj.ObjectID); obj.Draw(gd, state); //return everything to normal obj.Direction = oldObjRot; obj.Room = oldRoom; state.SilentZoom = oldZoom; state.SilentRotation = oldRotation; obj.OnRotationChanged(state); obj.OnZoomChanged(state); } bounds = _2d.GetSpriteListBounds(); } } bounds.Inflate(1, 1); bounds.X = Math.Max(0, Math.Min(1023, bounds.X)); bounds.Y = Math.Max(0, Math.Min(1023, bounds.Y)); if (bounds.Width + bounds.X > 1024) { bounds.Width = 1024 - bounds.X; } if (bounds.Height + bounds.Y > 1024) { bounds.Height = 1024 - bounds.Y; } //return things to normal state.DrawOOB = false; state.SilentPreciseZoom = oldPreciseZoom; state.WorldSpace.Invalidate(); state.InvalidateCamera(); state.TempDraw = false; var tex = bufferTexture.Get(); return(TextureUtils.Clip(gd, tex, bounds)); }