(eba811de) Unstable 0.9.703.0

This commit is contained in:
Juan Pablo Arce
2020-02-04 11:54:57 -03:00
parent 15499cb704
commit 08ab6185c4
100 changed files with 2162 additions and 1520 deletions
@@ -184,7 +184,7 @@ namespace Barotrauma.Items.Components
x = (int)(x + width / 2 - step * (panel.DisconnectedWires.Count() - 1) / 2);
foreach (Wire wire in panel.DisconnectedWires)
{
if (wire == DraggingConnected && mouseInRect) { continue; }
if (wire == DraggingConnected && !mouseInRect) { continue; }
Connection recipient = wire.OtherConnection(null);
string label = recipient == null ? "" : recipient.item.Name + $" ({recipient.DisplayName})";
@@ -197,7 +197,10 @@ namespace Barotrauma.Items.Components
//stop dragging a wire item if the cursor is within any connection panel
//(so we don't drop the item when dropping the wire on a connection)
if (mouseInRect || GUI.MouseOn?.UserData is ConnectionPanel) { Inventory.draggingItem = null; }
if (mouseInRect || (GUI.MouseOn?.UserData is ConnectionPanel && GUI.MouseOn.MouseRect.Contains(PlayerInput.MousePosition)))
{
Inventory.draggingItem = null;
}
}
private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 scale)
@@ -10,33 +10,52 @@ namespace Barotrauma.Items.Components
{
partial class CustomInterface
{
private List<GUIComponent> uiElements = new List<GUIComponent>();
private readonly List<GUIComponent> uiElements = new List<GUIComponent>();
private GUILayoutGroup uiElementContainer;
private Point ElementMaxSize => new Point(uiElementContainer.Rect.Width, (int)(60 * GUI.yScale));
partial void InitProjSpecific(XElement element)
{
CreateGUI();
GameMain.Instance.OnResolutionChanged += RecreateGUI;
}
private void RecreateGUI()
{
GuiFrame.ClearChildren();
CreateGUI();
}
private void CreateGUI()
{
uiElements.Clear();
var visibleElements = customInterfaceElementList.Where(ciElement => !string.IsNullOrEmpty(ciElement.Label));
uiElementContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.75f, 0.65f), GuiFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.025f) },
uiElementContainer = new GUILayoutGroup(new RectTransform(GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center)
{
AbsoluteOffset = GUIStyle.ItemFrameOffset
},
childAnchor: customInterfaceElementList.Count > 1 ? Anchor.TopCenter : Anchor.Center)
{
RelativeSpacing = 0.05f,
Stretch = visibleElements.Count() > 2
Stretch = visibleElements.Count() > 2,
};
float elementSize = Math.Min(1.0f / visibleElements.Count(), 0.5f);
float elementSize = Math.Min(1.0f / visibleElements.Count(), 1);
var textBlocks = new List<GUITextBlock>();
foreach (CustomInterfaceElement ciElement in visibleElements)
{
if (ciElement.ContinuousSignal)
{
var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform),
var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform)
{
MaxSize = ElementMaxSize
},
TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label)
{
UserData = ciElement
};
tickBox.TextBlock.AutoScale = true;
textBlocks.Add(tickBox.TextBlock);
tickBox.OnSelected += (tBox) =>
{
if (GameMain.Client == null)
@@ -56,12 +75,12 @@ namespace Barotrauma.Items.Components
}
else
{
var btn = new GUIButton(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform),
var btn = new GUIButton(new RectTransform(new Vector2(1.0f, elementSize), uiElementContainer.RectTransform),
TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label, style: "DeviceButton")
{
UserData = ciElement
};
btn.TextBlock.AutoScale = true;
textBlocks.Add(btn.TextBlock);
btn.OnClicked += (_, userdata) =>
{
if (GameMain.Client == null)
@@ -77,11 +96,12 @@ namespace Barotrauma.Items.Components
//reset size restrictions set by the Style to make sure the elements can fit the interface
btn.RectTransform.MinSize = btn.Frame.RectTransform.MinSize = new Point(0, 0);
btn.RectTransform.MaxSize = btn.Frame.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue);
btn.RectTransform.MaxSize = btn.Frame.RectTransform.MaxSize = ElementMaxSize;
btn.TextBlock.Wrap = true;
uiElements.Add(btn);
}
GUITextBlock.AutoScaleAndNormalize(textBlocks);
}
}
@@ -128,12 +148,8 @@ namespace Barotrauma.Items.Components
int visibleElementCount = 0;
foreach (var uiElement in uiElements)
{
CustomInterfaceElement element = uiElement.UserData as CustomInterfaceElement;
if (element == null) { continue; }
bool visible =
Screen.Selected == GameMain.SubEditorScreen ||
element.StatusEffects.Any() ||
(element.Connection != null && element.Connection.Wires.Any(w => w != null));
if (!(uiElement.UserData is CustomInterfaceElement element)) { continue; }
bool visible = Screen.Selected == GameMain.SubEditorScreen || element.StatusEffects.Any() || (element.Connection != null && element.Connection.Wires.Any(w => w != null));
if (visible) { visibleElementCount++; }
if (uiElement.Visible != visible)
{
@@ -146,11 +162,12 @@ namespace Barotrauma.Items.Components
{
uiElementContainer.Stretch = visibleElementCount > 2;
uiElementContainer.ChildAnchor = visibleElementCount > 1 ? Anchor.TopCenter : Anchor.Center;
float elementSize = Math.Min(1.0f / visibleElementCount, 0.5f);
float elementSize = Math.Min(1.0f / visibleElementCount, 1);
foreach (var uiElement in uiElements)
{
uiElement.RectTransform.RelativeSize = new Vector2(1.0f, elementSize);
}
GuiFrame.Visible = visibleElementCount > 0;
}
}
@@ -94,8 +94,8 @@ namespace Barotrauma.Items.Components
Submarine sub = item.Submarine;
if (IsActive && sub == null) // currently being rewired, we need to get the sub from the connections in case the wire has been taken outside
{
if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine;
if (connections[1] != null && connections[1].Item.Submarine != null) sub = connections[1].Item.Submarine;
if (connections[0] != null && connections[0].Item.Submarine != null) { sub = connections[0].Item.Submarine; }
if (connections[1] != null && connections[1].Item.Submarine != null) { sub = connections[1].Item.Submarine; }
}
if (sub != null)
@@ -253,11 +253,15 @@ namespace Barotrauma.Items.Components
{
MapEntity.DisableSelect = true;
Submarine sub = null;
Submarine sub = draggingWire.item.Submarine;
if (draggingWire.connections[0] != null && draggingWire.connections[0].Item.Submarine != null) sub = draggingWire.connections[0].Item.Submarine;
if (draggingWire.connections[1] != null && draggingWire.connections[1].Item.Submarine != null) sub = draggingWire.connections[1].Item.Submarine;
Vector2 nodeWorldPos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition) - sub.HiddenSubPosition - sub.Position;// Nodes[(int)selectedNodeIndex];
Vector2 nodeWorldPos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
if (sub != null)
{
nodeWorldPos = nodeWorldPos - sub.HiddenSubPosition - sub.Position;
}
if (selectedNodeIndex.HasValue)
{
@@ -352,7 +356,7 @@ namespace Barotrauma.Items.Components
foreach (Wire w in wires)
{
Vector2 mousePos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
if (w.item.Submarine != null) mousePos -= (w.item.Submarine.Position + w.item.Submarine.HiddenSubPosition);
if (w.item.Submarine != null) { mousePos -= (w.item.Submarine.Position + w.item.Submarine.HiddenSubPosition); }
int highlightedNode = w.GetClosestNodeIndex(mousePos, highlighted == null ? nodeSelectDist : closestDist, out float dist);
if (highlightedNode > -1)