Unstable 1.2.1.0
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Barotrauma.Lights;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -65,9 +66,7 @@ namespace Barotrauma
|
||||
disableSelect = value;
|
||||
if (disableSelect)
|
||||
{
|
||||
startMovingPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
selectionPos = Vector2.Zero;
|
||||
StopSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,6 +493,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static void StopSelection()
|
||||
{
|
||||
startMovingPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
selectionPos = Vector2.Zero;
|
||||
}
|
||||
|
||||
public static Vector2 GetNudgeAmount(bool doHold = true)
|
||||
{
|
||||
Vector2 nudgeAmount = Vector2.Zero;
|
||||
@@ -792,12 +798,16 @@ namespace Barotrauma
|
||||
foreach (MapEntity e in SelectedList)
|
||||
{
|
||||
SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
float spriteRotation = 0.0f;
|
||||
float rectangleRotation = 0.0f;
|
||||
switch (e)
|
||||
{
|
||||
case Item item:
|
||||
{
|
||||
if (item.FlippedX && item.Prefab.CanSpriteFlipX) { spriteEffects ^= SpriteEffects.FlipHorizontally; }
|
||||
if (item.flippedY && item.Prefab.CanSpriteFlipY) { spriteEffects ^= SpriteEffects.FlipVertically; }
|
||||
if (item.FlippedY && item.Prefab.CanSpriteFlipY) { spriteEffects ^= SpriteEffects.FlipVertically; }
|
||||
spriteRotation = MathHelper.ToRadians(item.Rotation);
|
||||
rectangleRotation = spriteRotation;
|
||||
var wire = item.GetComponent<Wire>();
|
||||
if (wire != null && wire.Item.body != null && !wire.Item.body.Enabled)
|
||||
{
|
||||
@@ -809,7 +819,10 @@ namespace Barotrauma
|
||||
case Structure structure:
|
||||
{
|
||||
if (structure.FlippedX && structure.Prefab.CanSpriteFlipX) { spriteEffects ^= SpriteEffects.FlipHorizontally; }
|
||||
if (structure.flippedY && structure.Prefab.CanSpriteFlipY) { spriteEffects ^= SpriteEffects.FlipVertically; }
|
||||
if (structure.FlippedY && structure.Prefab.CanSpriteFlipY) { spriteEffects ^= SpriteEffects.FlipVertically; }
|
||||
spriteRotation = MathHelper.ToRadians(structure.Rotation);
|
||||
rectangleRotation = spriteRotation;
|
||||
if (structure.FlippedX != structure.FlippedY) { rectangleRotation = -rectangleRotation; }
|
||||
break;
|
||||
}
|
||||
case WayPoint wayPoint:
|
||||
@@ -831,11 +844,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
e.Prefab?.DrawPlacing(spriteBatch,
|
||||
new Rectangle(e.WorldRect.Location + new Point((int)moveAmount.X, (int)-moveAmount.Y), e.WorldRect.Size), e.Scale, spriteEffects);
|
||||
new Rectangle(e.WorldRect.Location + new Point((int)moveAmount.X, (int)-moveAmount.Y), e.WorldRect.Size), e.Scale, spriteRotation, spriteEffects: spriteEffects);
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount,
|
||||
new Vector2(e.rect.Width, e.rect.Height),
|
||||
Color.White, false, 0, (int)Math.Max(3.0f / GameScreen.Selected.Cam.Zoom, 2.0f));
|
||||
center: e.WorldRect.Center.ToVector2().FlipY() + moveAmount + new Vector2(0f, e.WorldRect.Height),
|
||||
width: e.WorldRect.Width, height: e.WorldRect.Height,
|
||||
rotation: rectangleRotation, clr: Color.White,
|
||||
depth: 0f, thickness: Math.Max(3.0f / GameScreen.Selected.Cam.Zoom, 2.0f));
|
||||
}
|
||||
|
||||
//stop dragging the "selection rectangle"
|
||||
@@ -877,6 +891,23 @@ namespace Barotrauma
|
||||
spriteBatch.DrawLine(corners[3] + offset, corners[0] - offset, color, thickness);
|
||||
}
|
||||
|
||||
protected static void ColorFlipButton(GUIButton btn, bool flip)
|
||||
{
|
||||
var color = flip ? GUIStyle.Green : Color.White;
|
||||
var hsv = ToolBox.RGBToHSV(color);
|
||||
|
||||
// Boost saturation and reduce value a bit because our default colors are too muted for this button's style
|
||||
var hsvBase = hsv;
|
||||
hsvBase.Y *= 4f;
|
||||
hsvBase.Z *= 0.8f;
|
||||
btn.Color = ToolBox.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
|
||||
btn.SelectedColor = ToolBox.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
|
||||
|
||||
var hsvHover = hsv;
|
||||
hsvHover.Z *= 1.2f;
|
||||
btn.HoverColor = ToolBox.HSVToRGB(hsvHover.X, hsvHover.Y, hsvHover.Z);
|
||||
}
|
||||
|
||||
public static List<MapEntity> FilteredSelectedList { get; private set; } = new List<MapEntity>();
|
||||
|
||||
public static void UpdateEditor(Camera cam, float deltaTime)
|
||||
@@ -1105,6 +1136,25 @@ namespace Barotrauma
|
||||
|
||||
public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) { }
|
||||
|
||||
private float RotationRad
|
||||
=> MathHelper.ToRadians(
|
||||
this switch
|
||||
{
|
||||
Structure s => s.Rotation,
|
||||
Item it => it.Rotation,
|
||||
_ => 0.0f
|
||||
});
|
||||
|
||||
private Vector2 GetEditingHandlePos(int x, int y, Camera cam)
|
||||
{
|
||||
Vector2 handleDiff = new Vector2(x * (rect.Width * 0.5f), y * (rect.Height * 0.5f));
|
||||
var rotation = -RotationRad;
|
||||
handleDiff = MathUtils.RotatePoint(handleDiff, rotation);
|
||||
if (FlippedX) { handleDiff = handleDiff.FlipX(); }
|
||||
if (FlippedY) { handleDiff = handleDiff.FlipY(); }
|
||||
return cam.WorldToScreen(Position + handleDiff);
|
||||
}
|
||||
|
||||
float ResizeHandleSize => 10 * GUI.Scale;
|
||||
float ResizeHandleHighlightDistance => 8 * GUI.Scale;
|
||||
|
||||
@@ -1119,9 +1169,10 @@ namespace Barotrauma
|
||||
{
|
||||
for (int y = startY; y < 2; y += 2)
|
||||
{
|
||||
Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f), y * (rect.Height * 0.5f)));
|
||||
Vector2 handlePos = GetEditingHandlePos(x, y, cam);
|
||||
|
||||
bool highlighted = Vector2.DistanceSquared(PlayerInput.MousePosition, handlePos) < ResizeHandleHighlightDistance * ResizeHandleHighlightDistance;
|
||||
|
||||
if (highlighted && PlayerInput.PrimaryMouseButtonDown())
|
||||
{
|
||||
selectionPos = Vector2.Zero;
|
||||
@@ -1138,44 +1189,83 @@ namespace Barotrauma
|
||||
{
|
||||
if (prevRect == null)
|
||||
{
|
||||
prevRect = new Rectangle(Rect.Location, Rect.Size);
|
||||
prevRect = Rect;
|
||||
}
|
||||
|
||||
Vector2 placePosition = new Vector2(rect.X, rect.Y);
|
||||
Vector2 placeSize = new Vector2(rect.Width, rect.Height);
|
||||
Vector2 placePosition = prevRect.Value.Location.ToVector2();
|
||||
Vector2 placeSize = prevRect.Value.Size.ToVector2();
|
||||
|
||||
Vector2 mousePos = Submarine.MouseToWorldGrid(cam, Submarine.MainSub, round: true);
|
||||
|
||||
if (PlayerInput.IsShiftDown())
|
||||
static Vector2 flipThenRotate(Vector2 point, Vector2 center, float angle, bool flipX, bool flipY)
|
||||
{
|
||||
mousePos = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
if (flipX) { point = (point - center).FlipX() + center; }
|
||||
if (flipY) { point = (point - center).FlipY() + center; }
|
||||
|
||||
point = MathUtils.RotatePointAroundTarget(point, center, angle);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
static Vector2 rotateThenFlip(Vector2 point, Vector2 center, float angle, bool flipX, bool flipY)
|
||||
{
|
||||
point = MathUtils.RotatePointAroundTarget(point, center, angle);
|
||||
|
||||
if (flipX) { point = (point - center).FlipX() + center; }
|
||||
if (flipY) { point = (point - center).FlipY() + center; }
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
Vector2 mousePos = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
Vector2 prevPos = placePosition;
|
||||
Vector2 prevOppositeCorner = prevPos + placeSize.FlipY();
|
||||
Vector2 prevCenter = placePosition + placeSize.FlipY() * 0.5f;
|
||||
mousePos = flipThenRotate(mousePos, prevCenter, RotationRad, FlippedX, FlippedY);
|
||||
|
||||
if (!PlayerInput.IsShiftDown())
|
||||
{
|
||||
mousePos = Submarine.VectorToWorldGrid(mousePos, Submarine.MainSub, round: true);
|
||||
}
|
||||
|
||||
if (resizeDirX > 0)
|
||||
{
|
||||
mousePos.X = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X);
|
||||
mousePos.X = Math.Max(mousePos.X, prevRect.Value.X + Submarine.GridSize.X);
|
||||
placeSize.X = mousePos.X - placePosition.X;
|
||||
}
|
||||
else if (resizeDirX < 0)
|
||||
{
|
||||
mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X);
|
||||
mousePos.X = Math.Min(mousePos.X, prevRect.Value.Right - Submarine.GridSize.X);
|
||||
|
||||
placeSize.X = MathF.Round((placePosition.X + placeSize.X) - mousePos.X);
|
||||
placePosition.X = MathF.Round(mousePos.X);
|
||||
}
|
||||
if (resizeDirY < 0)
|
||||
{
|
||||
mousePos.Y = Math.Min(mousePos.Y, rect.Y - Submarine.GridSize.Y);
|
||||
mousePos.Y = Math.Min(mousePos.Y, prevRect.Value.Y - Submarine.GridSize.Y);
|
||||
placeSize.Y = placePosition.Y - mousePos.Y;
|
||||
}
|
||||
else if (resizeDirY > 0)
|
||||
{
|
||||
mousePos.Y = Math.Max(mousePos.Y, rect.Y - rect.Height + Submarine.GridSize.X);
|
||||
mousePos.Y = Math.Max(mousePos.Y, prevRect.Value.Y - prevRect.Value.Height + Submarine.GridSize.Y);
|
||||
|
||||
placeSize.Y = mousePos.Y - (rect.Y - rect.Height);
|
||||
placeSize.Y = mousePos.Y - (prevRect.Value.Y - prevRect.Value.Height);
|
||||
placePosition.Y = mousePos.Y;
|
||||
}
|
||||
|
||||
Vector2 newPos = placePosition;
|
||||
Vector2 newOppositeCorner = placePosition + placeSize.FlipY();
|
||||
|
||||
Vector2 transformedCornerDiff = rotateThenFlip(newPos-prevPos, Vector2.Zero, -RotationRad, FlippedX, FlippedY);
|
||||
Vector2 transformedOppositeCornerDiff = rotateThenFlip(newOppositeCorner-prevOppositeCorner, Vector2.Zero, -RotationRad, FlippedX, FlippedY);
|
||||
|
||||
Vector2 newPosTransformed = rotateThenFlip(prevPos, prevCenter, -RotationRad, FlippedX, FlippedY)
|
||||
+ transformedCornerDiff;
|
||||
Vector2 newOppositeTransformed = rotateThenFlip(prevOppositeCorner, prevCenter, -RotationRad, FlippedX, FlippedY)
|
||||
+ transformedOppositeCornerDiff;
|
||||
Vector2 newTransformedCenter = (newPosTransformed + newOppositeTransformed) * 0.5f;
|
||||
|
||||
var newDiff = (newOppositeCorner - newPos) * 0.5f;
|
||||
placePosition = newTransformedCenter - newDiff;
|
||||
|
||||
if ((int)placePosition.X != rect.X || (int)placePosition.Y != rect.Y || (int)placeSize.X != rect.Width || (int)placeSize.Y != rect.Height)
|
||||
{
|
||||
Rect = new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y);
|
||||
@@ -1210,15 +1300,16 @@ namespace Barotrauma
|
||||
IsHighlighted = true;
|
||||
|
||||
int startX = ResizeHorizontal ? -1 : 0;
|
||||
int StartY = ResizeVertical ? -1 : 0;
|
||||
int startY = ResizeVertical ? -1 : 0;
|
||||
|
||||
for (int x = startX; x < 2; x += 2)
|
||||
{
|
||||
for (int y = StartY; y < 2; y += 2)
|
||||
for (int y = startY; y < 2; y += 2)
|
||||
{
|
||||
Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f), y * (rect.Height * 0.5f)));
|
||||
Vector2 handlePos = GetEditingHandlePos(x, y, cam);
|
||||
|
||||
bool highlighted = Vector2.DistanceSquared(PlayerInput.MousePosition, handlePos) < ResizeHandleHighlightDistance * ResizeHandleHighlightDistance;
|
||||
var color = Color.White * (highlighted ? 1.0f : 0.6f);
|
||||
if (highlighted && !PlayerInput.PrimaryMouseButtonHeld())
|
||||
{
|
||||
GUI.MouseCursor = CursorState.Hand;
|
||||
@@ -1226,7 +1317,7 @@ namespace Barotrauma
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
handlePos - new Vector2(ResizeHandleSize / 2),
|
||||
new Vector2(ResizeHandleSize),
|
||||
Color.White * (highlighted ? 1.0f : 0.6f),
|
||||
color,
|
||||
true, 0,
|
||||
(int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user