Fixes and minor enhancements for sub editor

- Zoom now works relative to the mouse's position rather than the center of the screen, much like Valve's Hammer Editor (or pulsegun's map editor shameless plug ;) )
- Rectangles now have line widths dependent on the camera zoom, not perfect but it's better than having lines disappear
- Fixed background resizing
- Fixed editor being completely broken because of no vsync, might still have a few bugs here and there
- Fixed selection rectangle not rendering at all when dragging from bottom right to top left
- Newline change in Item.cs
This commit is contained in:
juanjp600
2016-10-06 21:15:01 -03:00
parent 16ee20aaaa
commit 94895edbdb
12 changed files with 2116 additions and 1963 deletions

View File

@@ -189,7 +189,7 @@ namespace Barotrauma
Color clr = (open == 0.0f) ? Color.Red : Color.Cyan;
if (isHighlighted) clr = Color.Gold;
GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y, rect.Width, rect.Height), clr * 0.5f, true);
GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y, rect.Width, rect.Height), clr * 0.5f, true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
for (int i = 0; i < linkedTo.Count; i++)
{
@@ -212,7 +212,10 @@ namespace Barotrauma
GUI.DrawRectangle(sb,
new Vector2(WorldRect.X - 5, -WorldRect.Y - 5),
new Vector2(rect.Width + 10, rect.Height + 10),
Color.Red);
Color.Red,
false,
0,
(int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
}
}

View File

@@ -570,7 +570,8 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch,
new Vector2(drawRect.X, -drawRect.Y),
new Vector2(rect.Width, rect.Height),
Color.Black,true);
Color.Black,true,
0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
}
if (!ShowHulls && !GameMain.DebugDraw) return;
@@ -585,11 +586,11 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch,
new Vector2(drawRect.X, -drawRect.Y),
new Vector2(rect.Width, rect.Height),
Color.Blue);
Color.Blue,false,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
GUI.DrawRectangle(spriteBatch,
new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height),
Color.Red*((100.0f-OxygenPercentage)/400.0f), true);
Color.Red*((100.0f-OxygenPercentage)/400.0f), true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
if (GameMain.DebugDraw)
{
@@ -604,7 +605,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch,
new Vector2(drawRect.X + 5, -drawRect.Y + 5),
new Vector2(rect.Width - 10, rect.Height - 10),
isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true);
isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
}
}

View File

@@ -451,7 +451,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch,
new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount,
new Vector2(e.rect.Width, e.rect.Height),
Color.DarkRed);
Color.DarkRed,false,0,(int)Math.Max(1.5f/GameScreen.Selected.Cam.Zoom,1.0f));
//stop dragging the "selection rectangle"
selectionPos = Vector2.Zero;
@@ -459,7 +459,7 @@ namespace Barotrauma
}
if (selectionPos != null && selectionPos != Vector2.Zero)
{
GUI.DrawRectangle(spriteBatch, new Vector2(selectionPos.X, -selectionPos.Y), selectionSize, Color.DarkRed);
GUI.DrawRectangle(spriteBatch, new Vector2(selectionPos.X, -selectionPos.Y), selectionSize, Color.DarkRed,false,0,(int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
}
}
@@ -543,7 +543,7 @@ namespace Barotrauma
bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos)<5.0f;
GUI.DrawRectangle(spriteBatch, handlePos - new Vector2(3.0f, 3.0f), new Vector2(6.0f, 6.0f), Color.White * (highlighted ? 1.0f : 0.6f), true);
GUI.DrawRectangle(spriteBatch, handlePos - new Vector2(3.0f, 3.0f), new Vector2(6.0f, 6.0f), Color.White * (highlighted ? 1.0f : 0.6f), true,0, (int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
if (highlighted)
{

View File

@@ -129,18 +129,14 @@ namespace Barotrauma
Category = MapEntityCategory.Structure;
}
public virtual void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
public virtual void UpdatePlacing(Camera cam)
{
Vector2 placeSize = Submarine.GridSize;
if (placePosition == Vector2.Zero)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
GUI.DrawLine(spriteBatch, new Vector2(position.X-GameMain.GraphicsWidth, -position.Y), new Vector2(position.X+GameMain.GraphicsWidth, -position.Y), Color.White);
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White);
if (PlayerInput.LeftButtonHeld()) placePosition = position;
}
else
@@ -167,7 +163,6 @@ namespace Barotrauma
}
newRect.Y = -newRect.Y;
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
}
if (PlayerInput.RightButtonHeld())
@@ -177,6 +172,39 @@ namespace Barotrauma
}
}
public virtual void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
{
Vector2 placeSize = Submarine.GridSize;
if (placePosition == Vector2.Zero)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
GUI.DrawLine(spriteBatch, new Vector2(position.X - GameMain.GraphicsWidth, -position.Y), new Vector2(position.X + GameMain.GraphicsWidth, -position.Y), Color.White,0,(int)(2.0f/cam.Zoom));
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White, 0, (int)(2.0f / cam.Zoom));
}
else
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
Rectangle newRect = Submarine.AbsRect(placePosition, placeSize);
newRect.Width = (int)Math.Max(newRect.Width, Submarine.GridSize.X);
newRect.Height = (int)Math.Max(newRect.Height, Submarine.GridSize.Y);
if (Submarine.MainSub != null)
{
newRect.Location -= Submarine.MainSub.Position.ToPoint();
}
newRect.Y = -newRect.Y;
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
}
}
protected virtual void CreateInstance(Rectangle rect)
{
object[] lobject = new object[] { this, rect };

View File

@@ -143,8 +143,24 @@ namespace Barotrauma
}
set
{
Rectangle oldRect = Rect;
base.Rect = value;
if (prefab.HasBody) CreateSections();
else
{
foreach (WallSection sec in sections)
{
Rectangle secRect = sec.rect;
secRect.X -= oldRect.X; secRect.Y -= oldRect.Y;
secRect.X *= value.Width; secRect.X /= oldRect.Width;
secRect.Y *= value.Height; secRect.Y /= oldRect.Height;
secRect.Width *= value.Width; secRect.Width /= oldRect.Width;
secRect.Height *= value.Height; secRect.Height /= oldRect.Height;
secRect.X += value.X; secRect.Y += value.Y;
sec.rect = secRect;
}
}
}
}

View File

@@ -162,7 +162,7 @@ namespace Barotrauma
return sp;
}
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
public override void UpdatePlacing(Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
//Vector2 placeSize = size;
@@ -183,7 +183,7 @@ namespace Barotrauma
else
{
Vector2 placeSize = size;
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
newRect = Submarine.AbsRect(placePosition, placeSize);
@@ -199,13 +199,41 @@ namespace Barotrauma
return;
}
}
if (PlayerInput.RightButtonHeld()) selected = null;
}
public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
//Vector2 placeSize = size;
Rectangle newRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
if (placePosition == Vector2.Zero)
{
if (PlayerInput.LeftButtonHeld())
placePosition = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
newRect.X = (int)position.X;
newRect.Y = (int)position.Y;
//sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y), placeSize, Color.White);
}
else
{
Vector2 placeSize = size;
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
newRect = Submarine.AbsRect(placePosition, placeSize);
}
sprite.DrawTiled(spriteBatch, new Vector2(newRect.X, -newRect.Y), new Vector2(newRect.Width, newRect.Height), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth*2, newRect.Height), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight*2), Color.White);
if (PlayerInput.RightButtonHeld()) selected = null;
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth * 2, newRect.Height), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight * 2), Color.White);
}
}
}