From 548e603900252cd43ceba37ea352cb34f256a553 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 6 Dec 2019 20:54:30 +0100 Subject: [PATCH] made cameras snap right in small rooms and made panels not require a texture --- MLEM.Ui/Elements/Panel.cs | 3 ++- MLEM/Cameras/Camera.cs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index eed7462..a9e12f5 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -130,7 +130,8 @@ namespace MLEM.Ui.Elements { } public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { - batch.Draw(this.Texture, this.DisplayArea, Color.White * alpha, this.Scale); + if (this.Texture.Value != null) + batch.Draw(this.Texture, this.DisplayArea, Color.White * alpha, this.Scale); // if we handle overflow, draw using the render target in DrawUnbound if (!this.scrollOverflow) { base.Draw(time, batch, alpha, blendState, samplerState, matrix); diff --git a/MLEM/Cameras/Camera.cs b/MLEM/Cameras/Camera.cs index 227339e..b04baf8 100644 --- a/MLEM/Cameras/Camera.cs +++ b/MLEM/Cameras/Camera.cs @@ -71,15 +71,23 @@ namespace MLEM.Cameras { } public void ConstrainWorldBounds(Vector2 min, Vector2 max) { - if (this.Position.X < min.X) - this.Position.X = min.X; - if (this.Position.Y < min.Y) - this.Position.Y = min.Y; + if (this.Position.X < min.X && this.Max.X > max.X) { + this.LookingPosition = new Vector2((max.X - min.X) / 2, this.LookingPosition.Y); + } else { + if (this.Position.X < min.X) + this.Position.X = min.X; + if (this.Max.X > max.X) + this.Max = new Vector2(max.X, this.Max.Y); + } - if (this.Max.X > max.X) - this.Max = new Vector2(max.X, this.Max.Y); - if (this.Max.Y > max.Y) - this.Max = new Vector2(this.Max.X, max.Y); + if (this.Position.Y < min.Y && this.Max.Y > max.Y) { + this.LookingPosition = new Vector2(this.LookingPosition.X, (max.Y - min.Y) / 2); + } else { + if (this.Position.Y < min.Y) + this.Position.Y = min.Y; + if (this.Max.Y > max.Y) + this.Max = new Vector2(this.Max.X, max.Y); + } } public void Zoom(float delta, Vector2? zoomCenter = null) {