(bf212a41f) v0.9.2.0 pre-release test version
This commit is contained in:
@@ -20,6 +20,8 @@ namespace Barotrauma
|
||||
private GUIFrame bottomPanel;
|
||||
private GUIFrame backgroundColorPanel;
|
||||
|
||||
private bool drawGrid, snapToGrid;
|
||||
|
||||
private GUIFrame topPanelContents;
|
||||
private GUITextBlock texturePathText;
|
||||
private GUITextBlock xmlPathText;
|
||||
@@ -137,7 +139,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
};
|
||||
new GUIButton(new RectTransform(new Vector2(0.05f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.055f, 0.3f) }, "Reset Zoom")
|
||||
var resetBtn = new GUIButton(new RectTransform(new Vector2(0.05f, 0.35f), topPanelContents.RectTransform, Anchor.TopCenter, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.055f, 0.3f) }, "Reset Zoom")
|
||||
{
|
||||
OnClicked = (box, data) =>
|
||||
{
|
||||
@@ -145,6 +147,26 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
};
|
||||
resetBtn.TextBlock.AutoScale = true;
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.BottomCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0, 0.3f) }, "Show grid")
|
||||
{
|
||||
Selected = drawGrid,
|
||||
OnSelected = (tickBox) =>
|
||||
{
|
||||
drawGrid = tickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), topPanelContents.RectTransform, Anchor.BottomCenter, Pivot.CenterRight) { RelativeOffset = new Vector2(0.17f, 0.3f) }, "Snap to grid")
|
||||
{
|
||||
Selected = snapToGrid,
|
||||
OnSelected = (tickBox) =>
|
||||
{
|
||||
snapToGrid = tickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
texturePathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.BottomCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray);
|
||||
xmlPathText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.4f), topPanelContents.RectTransform, Anchor.Center, Pivot.TopCenter) { RelativeOffset = new Vector2(0.4f, 0) }, "", Color.LightGray);
|
||||
@@ -230,8 +252,7 @@ namespace Barotrauma
|
||||
}, style: null, color: Color.Black * 0.6f);
|
||||
var colorLabel = new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), colorComponentLabels[i],
|
||||
font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
|
||||
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
|
||||
GUINumberInput.NumberType.Int)
|
||||
var numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight), GUINumberInput.NumberType.Int)
|
||||
{
|
||||
Font = GUI.SmallFont
|
||||
};
|
||||
@@ -259,26 +280,32 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<Sprite> loadedSprites = new HashSet<Sprite>();
|
||||
private readonly HashSet<Sprite> loadedSprites = new HashSet<Sprite>();
|
||||
private void LoadSprites()
|
||||
{
|
||||
loadedSprites.ForEach(s => s.Remove());
|
||||
loadedSprites.Clear();
|
||||
//foreach (string filePath in ContentPackage.GetAllContentFiles(GameMain.SelectedPackages))
|
||||
//{
|
||||
// XDocument doc = XMLExtensions.TryLoadXml(filePath);
|
||||
// if (doc != null && doc.Root != null)
|
||||
// {
|
||||
// LoadSprites(doc.Root);
|
||||
// }
|
||||
//}
|
||||
var contentPackages = GameMain.Config.SelectedContentPackages.ToList();
|
||||
|
||||
foreach (string filePath in Directory.GetFiles("Content/", "*.xml", SearchOption.AllDirectories))
|
||||
#if !DEBUG
|
||||
var vanilla = GameMain.VanillaContent;
|
||||
if (vanilla != null)
|
||||
{
|
||||
XDocument doc = XMLExtensions.TryLoadXml(filePath);
|
||||
if (doc != null && doc.Root != null)
|
||||
contentPackages.Remove(vanilla);
|
||||
}
|
||||
#endif
|
||||
foreach (var contentPackage in contentPackages)
|
||||
{
|
||||
foreach (var file in contentPackage.Files)
|
||||
{
|
||||
LoadSprites(doc.Root);
|
||||
if (file.Path.EndsWith(".xml"))
|
||||
{
|
||||
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
|
||||
if (doc != null && doc.Root != null)
|
||||
{
|
||||
LoadSprites(doc.Root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +331,12 @@ namespace Barotrauma
|
||||
{
|
||||
string spriteFolder = "";
|
||||
string textureElement = element.GetAttributeString("texture", "");
|
||||
// TODO: parse and create
|
||||
// TODO: parse and create?
|
||||
if (textureElement.Contains("[GENDER]") || textureElement.Contains("[HEADID]") || textureElement.Contains("[RACE]")) { return; }
|
||||
if (!textureElement.Contains("/"))
|
||||
{
|
||||
spriteFolder = Path.GetDirectoryName(element.ParseContentPathFromUri());
|
||||
var parsedPath = element.ParseContentPathFromUri();
|
||||
spriteFolder = Path.GetDirectoryName(parsedPath);
|
||||
}
|
||||
// Uncomment if we do multiple passes -> there can be duplicates
|
||||
//string identifier = Sprite.GetID(element);
|
||||
@@ -344,7 +372,7 @@ namespace Barotrauma
|
||||
xmlPathText.TextColor = Color.LightGreen;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
public override void AddToGUIUpdateList()
|
||||
@@ -466,6 +494,11 @@ namespace Barotrauma
|
||||
//GUI.DrawRectangle(spriteBatch, viewArea, Color.Green, isFilled: false);
|
||||
GUI.DrawRectangle(spriteBatch, textureRect, Color.Gray, isFilled: false);
|
||||
|
||||
if (drawGrid)
|
||||
{
|
||||
DrawGrid(spriteBatch, textureRect, zoom, Submarine.GridSize);
|
||||
}
|
||||
|
||||
foreach (GUIComponent element in spriteList.Content.Children)
|
||||
{
|
||||
Sprite sprite = element.UserData as Sprite;
|
||||
@@ -507,8 +540,11 @@ namespace Barotrauma
|
||||
w.tooltip = $"Position: {sprite.SourceRect.Location}";
|
||||
w.MouseHeld += dTime =>
|
||||
{
|
||||
w.DrawPos = PlayerInput.MousePosition;
|
||||
sprite.SourceRect = new Rectangle(((w.DrawPos + new Vector2(w.size / 2) - textureRect.Location.ToVector2()) / zoom).ToPoint(), sprite.SourceRect.Size);
|
||||
w.DrawPos = (drawGrid && snapToGrid) ?
|
||||
SnapToGrid(PlayerInput.MousePosition, textureRect, zoom, Submarine.GridSize, Submarine.GridSize.X / 4.0f * zoom) :
|
||||
PlayerInput.MousePosition;
|
||||
w.DrawPos = new Vector2((float)Math.Ceiling(w.DrawPos.X), (float)Math.Ceiling(w.DrawPos.Y));
|
||||
sprite.SourceRect = new Rectangle(((w.DrawPos - textureRect.Location.ToVector2()) / zoom).ToPoint(), sprite.SourceRect.Size);
|
||||
if (spriteList.SelectedComponent is GUITextBlock textBox)
|
||||
{
|
||||
// TODO: cache the sprite name?
|
||||
@@ -516,15 +552,18 @@ namespace Barotrauma
|
||||
}
|
||||
w.tooltip = $"Position: {sprite.SourceRect.Location}";
|
||||
};
|
||||
w.refresh = () => w.DrawPos = textureRect.Location.ToVector2() + sprite.SourceRect.Location.ToVector2() * zoom - new Vector2(w.size / 2);
|
||||
w.refresh = () => w.DrawPos = textureRect.Location.ToVector2() + sprite.SourceRect.Location.ToVector2() * zoom;
|
||||
});
|
||||
var sizeWidget = GetWidget($"{id}_size", sprite, widgetSize, Widget.Shape.Rectangle, initMethod: w =>
|
||||
{
|
||||
w.tooltip = $"Size: {sprite.SourceRect.Size}";
|
||||
w.MouseHeld += dTime =>
|
||||
{
|
||||
w.DrawPos = PlayerInput.MousePosition;
|
||||
sprite.SourceRect = new Rectangle(sprite.SourceRect.Location, ((w.DrawPos - new Vector2(w.size) - positionWidget.DrawPos) / zoom).ToPoint());
|
||||
w.DrawPos = (drawGrid && snapToGrid) ?
|
||||
SnapToGrid(PlayerInput.MousePosition, textureRect, zoom, Submarine.GridSize, Submarine.GridSize.X / 4.0f * zoom) :
|
||||
PlayerInput.MousePosition;
|
||||
w.DrawPos = new Vector2((float)Math.Ceiling(w.DrawPos.X), (float)Math.Ceiling(w.DrawPos.Y));
|
||||
sprite.SourceRect = new Rectangle(sprite.SourceRect.Location, ((w.DrawPos - positionWidget.DrawPos) / zoom).ToPoint());
|
||||
// TODO: allow to lock the origin
|
||||
sprite.RelativeOrigin = sprite.RelativeOrigin;
|
||||
if (spriteList.SelectedComponent is GUITextBlock textBox)
|
||||
@@ -534,7 +573,7 @@ namespace Barotrauma
|
||||
}
|
||||
w.tooltip = $"Size: {sprite.SourceRect.Size}";
|
||||
};
|
||||
w.refresh = () => w.DrawPos = textureRect.Location.ToVector2() + new Vector2(sprite.SourceRect.Right, sprite.SourceRect.Bottom) * zoom + new Vector2(w.size / 2);
|
||||
w.refresh = () => w.DrawPos = textureRect.Location.ToVector2() + new Vector2(sprite.SourceRect.Right, sprite.SourceRect.Bottom) * zoom;
|
||||
});
|
||||
if (isSelected)
|
||||
{
|
||||
@@ -553,6 +592,58 @@ namespace Barotrauma
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawGrid(SpriteBatch spriteBatch, Rectangle gridArea, float zoom, Vector2 gridSize)
|
||||
{
|
||||
gridSize *= zoom;
|
||||
if (gridSize.X < 1.0f) { return; }
|
||||
if (gridSize.Y < 1.0f) { return; }
|
||||
int xLines = (int)(gridArea.Width / gridSize.X);
|
||||
int yLines = (int)(gridArea.Height / gridSize.Y);
|
||||
|
||||
for (int x = 0; x <= xLines; x++)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(gridArea.X + x * gridSize.X, gridArea.Y),
|
||||
new Vector2(gridArea.X + x * gridSize.X, gridArea.Bottom),
|
||||
Color.White * 0.25f);
|
||||
}
|
||||
for (int y = 0; y <= yLines; y++)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(gridArea.X, gridArea.Y + y * gridSize.Y),
|
||||
new Vector2(gridArea.Right, gridArea.Y + y * gridSize.Y),
|
||||
Color.White * 0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 SnapToGrid(Vector2 position, Rectangle gridArea, float zoom, Vector2 gridSize, float tolerance)
|
||||
{
|
||||
gridSize *= zoom;
|
||||
if (gridSize.X < 1.0f) { return position; }
|
||||
if (gridSize.Y < 1.0f) { return position; }
|
||||
|
||||
Vector2 snappedPos = position;
|
||||
snappedPos.X -= gridArea.X;
|
||||
snappedPos.Y -= gridArea.Y;
|
||||
|
||||
Vector2 gridPos = new Vector2(
|
||||
MathUtils.RoundTowardsClosest(snappedPos.X, gridSize.X),
|
||||
MathUtils.RoundTowardsClosest(snappedPos.Y, gridSize.Y));
|
||||
|
||||
if (Math.Abs(gridPos.X - snappedPos.X) < tolerance)
|
||||
{
|
||||
snappedPos.X = gridPos.X;
|
||||
}
|
||||
if (Math.Abs(gridPos.Y - snappedPos.Y) < tolerance)
|
||||
{
|
||||
snappedPos.Y = gridPos.Y;
|
||||
}
|
||||
|
||||
snappedPos.X += gridArea.X;
|
||||
snappedPos.Y += gridArea.Y;
|
||||
return snappedPos;
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
base.Select();
|
||||
@@ -706,7 +797,7 @@ namespace Barotrauma
|
||||
zoomBar.BarScroll = GetBarScrollValue();
|
||||
viewAreaOffset = Point.Zero;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
private Point viewAreaOffset;
|
||||
@@ -750,7 +841,7 @@ namespace Barotrauma
|
||||
// Keeps the relative origin unchanged. The absolute origin will be recalculated.
|
||||
sprite.RelativeOrigin = sprite.RelativeOrigin;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Widgets
|
||||
private Dictionary<string, Widget> widgets = new Dictionary<string, Widget>();
|
||||
@@ -792,6 +883,6 @@ namespace Barotrauma
|
||||
widgets.Clear();
|
||||
Widget.selectedWidgets.Clear();
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user