(f6f86c3b6) Use relative scales in store UI, gave more space to the amount input box

This commit is contained in:
Joonas Rikkonen
2019-05-16 07:00:14 +03:00
parent 9ba7dee1d7
commit 531c572216
12 changed files with 117 additions and 203 deletions
@@ -121,90 +121,7 @@ namespace Barotrauma
MainLimb.PullJointWorldAnchorB = Collider.SimPosition; MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
MainLimb.PullJointEnabled = true; MainLimb.PullJointEnabled = true;
} }
character.SelectedConstruction = character.MemState[0].SelectedItem;
} }
if (character.MemState[0].Animation == AnimController.Animation.CPR)
{
character.AnimController.Anim = AnimController.Animation.CPR;
}
else if (character.AnimController.Anim == AnimController.Animation.CPR)
{
character.AnimController.Anim = AnimController.Animation.None;
}
Vector2 newVelocity = Collider.LinearVelocity;
Vector2 newPosition = Collider.SimPosition;
float newRotation = Collider.Rotation;
float newAngularVelocity = Collider.AngularVelocity;
Collider.CorrectPosition(character.MemState, out newPosition, out newVelocity, out newRotation, out newAngularVelocity);
newVelocity = newVelocity.ClampLength(100.0f);
if (!MathUtils.IsValid(newVelocity)) { newVelocity = Vector2.Zero; }
overrideTargetMovement = newVelocity.LengthSquared() > 0.01f ? newVelocity : Vector2.Zero;
Collider.LinearVelocity = newVelocity;
Collider.AngularVelocity = newAngularVelocity;
float distSqrd = Vector2.DistanceSquared(newPosition, Collider.SimPosition);
float errorTolerance = character.AllowInput ? 0.01f : 0.2f;
if (distSqrd > errorTolerance)
{
if (distSqrd > 10.0f || !character.AllowInput)
{
Collider.TargetRotation = newRotation;
SetPosition(newPosition, lerp: distSqrd < 5.0f, ignorePlatforms: false);
}
else
{
Collider.TargetRotation = newRotation;
Collider.TargetPosition = newPosition;
Collider.MoveToTargetPosition(true);
}
}
//unconscious/dead characters can't correct their position using AnimController movement
// -> we need to correct it manually
if (!character.AllowInput)
{
float mainLimbDistSqrd = Vector2.DistanceSquared(MainLimb.PullJointWorldAnchorA, Collider.SimPosition);
float mainLimbErrorTolerance = 0.1f;
//if the main limb is roughly at the correct position and the collider isn't moving (much at least),
//don't attempt to correct the position.
if (mainLimbDistSqrd > mainLimbErrorTolerance || Collider.LinearVelocity.LengthSquared() > 0.05f)
{
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
MainLimb.PullJointEnabled = true;
}
}
}
character.MemLocalState.Clear();
}
else
{
//remove states with a timestamp (there may still timestamp-based states
//in the list if the controlled character switches from timestamp-based interpolation to ID-based)
character.MemState.RemoveAll(m => m.Timestamp > 0.0f);
for (int i = 0; i < character.MemLocalState.Count; i++)
{
if (character.Submarine == null)
{
//transform in-sub coordinates to outside coordinates
if (character.MemLocalState[i].Position.Y > lowestSubPos)
{
character.MemLocalState[i].TransformInToOutside();
}
}
else if (currentHull?.Submarine != null)
{
//transform outside coordinates to in-sub coordinates
if (character.MemLocalState[i].Position.Y < lowestSubPos)
{
character.MemLocalState[i].TransformOutToInside(currentHull.Submarine);
}
}
} }
character.MemLocalState.Clear(); character.MemLocalState.Clear();
} }
@@ -330,12 +330,7 @@ namespace Barotrauma
if (childrenNeedsRecalculation) if (childrenNeedsRecalculation)
{ {
foreach (GUIComponent child in Content.Children) RecalculateChildren();
{
ClampChildMouseRects(child);
}
RepositionChildren();
childrenNeedsRecalculation = false;
} }
UpdateOrder = order; UpdateOrder = order;
@@ -367,6 +362,16 @@ namespace Barotrauma
OnAddedToGUIUpdateList?.Invoke(this); OnAddedToGUIUpdateList?.Invoke(this);
} }
public void RecalculateChildren()
{
foreach (GUIComponent child in Content.Children)
{
ClampChildMouseRects(child);
}
RepositionChildren();
childrenNeedsRecalculation = false;
}
private void ClampChildMouseRects(GUIComponent child) private void ClampChildMouseRects(GUIComponent child)
{ {
child.ClampMouseRectToParent = true; child.ClampMouseRectToParent = true;
@@ -101,6 +101,12 @@ namespace Barotrauma
} }
} }
public GUILayoutGroup LayoutGroup
{
get;
private set;
}
public float valueStep; public float valueStep;
private float pressedTimer; private float pressedTimer;
@@ -109,9 +115,9 @@ namespace Barotrauma
public GUINumberInput(RectTransform rectT, NumberType inputType, string style = "", Alignment textAlignment = Alignment.Center) : base(style, rectT) public GUINumberInput(RectTransform rectT, NumberType inputType, string style = "", Alignment textAlignment = Alignment.Center) : base(style, rectT)
{ {
var layoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), isHorizontal: true) { Stretch = true }; LayoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), isHorizontal: true) { Stretch = true };
TextBox = new GUITextBox(new RectTransform(Vector2.One, layoutGroup.RectTransform), textAlignment: textAlignment, style: style) TextBox = new GUITextBox(new RectTransform(Vector2.One, LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
{ {
ClampText = false, ClampText = false,
// For some reason the caret in the number inputs is dimmer than it should. // For some reason the caret in the number inputs is dimmer than it should.
@@ -120,7 +126,7 @@ namespace Barotrauma
CaretColor = Color.White CaretColor = Color.White
}; };
TextBox.OnTextChanged += TextChanged; TextBox.OnTextChanged += TextChanged;
var buttonArea = new GUIFrame(new RectTransform(new Vector2(0.02f, 1.0f), layoutGroup.RectTransform, Anchor.CenterRight) { MinSize = new Point(Rect.Height, 0) }, style: null); var buttonArea = new GUIFrame(new RectTransform(new Vector2(0.02f, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight) { MinSize = new Point(Rect.Height, 0) }, style: null);
PlusButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.5f), buttonArea.RectTransform), "+"); PlusButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.5f), buttonArea.RectTransform), "+");
PlusButton.OnButtonDown += () => PlusButton.OnButtonDown += () =>
{ {
@@ -760,6 +760,8 @@ namespace Barotrauma
private GUILayoutGroup subPreviewContainer; private GUILayoutGroup subPreviewContainer;
private GUILayoutGroup subPreviewContainer;
private GUIButton loadGameButton; private GUIButton loadGameButton;
public Action<Submarine, string, string> StartNewGame; public Action<Submarine, string, string> StartNewGame;
@@ -637,49 +637,52 @@ namespace Barotrauma
private void CreateItemFrame(PurchasedItem pi, PriceInfo priceInfo, GUIListBox listBox, int width) private void CreateItemFrame(PurchasedItem pi, PriceInfo priceInfo, GUIListBox listBox, int width)
{ {
GUIFrame frame = new GUIFrame(new RectTransform(new Point(listBox.Rect.Width, 50), listBox.Content.RectTransform), style: "ListBoxElement") GUIFrame frame = new GUIFrame(new RectTransform(new Point(listBox.Content.Rect.Width, (int)(GUI.Scale * 50)), listBox.Content.RectTransform), style: "ListBoxElement")
{ {
UserData = pi, UserData = pi,
ToolTip = pi.ItemPrefab.Description ToolTip = pi.ItemPrefab.Description
}; };
var content = new GUILayoutGroup(new RectTransform(Vector2.One, frame.RectTransform), isHorizontal: true)
{
RelativeSpacing = 0.02f,
Stretch = true
};
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font; ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Point(listBox.Rect.Width - (pi.Quantity > 0 ? 160 : 120), 25), frame.RectTransform, Anchor.CenterLeft)
{
AbsoluteOffset = new Point(40, 0),
}, pi.ItemPrefab.Name, font: font)
{
ToolTip = pi.ItemPrefab.Description
};
textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
Sprite itemIcon = pi.ItemPrefab.InventoryIcon ?? pi.ItemPrefab.sprite; Sprite itemIcon = pi.ItemPrefab.InventoryIcon ?? pi.ItemPrefab.sprite;
if (itemIcon != null) if (itemIcon != null)
{ {
GUIImage img = new GUIImage(new RectTransform(new Point(40, 40), frame.RectTransform, Anchor.CenterLeft), itemIcon) GUIImage img = new GUIImage(new RectTransform(new Point((int)(content.Rect.Height * 0.8f)), content.RectTransform, Anchor.CenterLeft), itemIcon, scaleToFit: true)
{ {
Color = itemIcon == pi.ItemPrefab.InventoryIcon ? pi.ItemPrefab.InventoryIconColor : pi.ItemPrefab.SpriteColor Color = itemIcon == pi.ItemPrefab.InventoryIcon ? pi.ItemPrefab.InventoryIconColor : pi.ItemPrefab.SpriteColor
}; };
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f); img.RectTransform.MaxSize = img.Rect.Size;
//img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
} }
textBlock = new GUITextBlock(new RectTransform(new Point(60, 25), frame.RectTransform, Anchor.CenterRight) GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), content.RectTransform),
{ AbsoluteOffset = new Point(pi.Quantity > 0 ? 70 : 25, 0) }, pi.ItemPrefab.Name, font: font)
{
ToolTip = pi.ItemPrefab.Description
};
new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), content.RectTransform),
priceInfo.BuyPrice.ToString(), font: font, textAlignment: Alignment.CenterRight) priceInfo.BuyPrice.ToString(), font: font, textAlignment: Alignment.CenterRight)
{ {
ToolTip = pi.ItemPrefab.Description ToolTip = pi.ItemPrefab.Description
}; };
//If its the store menu, quantity will always be 0 //If its the store menu, quantity will always be 0
GUINumberInput amountInput = null;
if (pi.Quantity > 0) if (pi.Quantity > 0)
{ {
var amountInput = new GUINumberInput(new RectTransform(new Point(50, 40), frame.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(20, 0) }, amountInput = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), content.RectTransform),
GUINumberInput.NumberType.Int) GUINumberInput.NumberType.Int)
{ {
MinValueInt = 0, MinValueInt = 0,
MaxValueInt = 1000, MaxValueInt = 100,
UserData = pi, UserData = pi,
IntValue = pi.Quantity IntValue = pi.Quantity
}; };
@@ -711,6 +714,11 @@ namespace Barotrauma
} }
}; };
} }
listBox.RecalculateChildren();
content.Recalculate();
content.RectTransform.RecalculateChildren(true, true);
amountInput?.LayoutGroup.Recalculate();
textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
} }
private bool BuyItem(GUIComponent component, object obj) private bool BuyItem(GUIComponent component, object obj)
@@ -89,6 +89,21 @@ namespace Barotrauma
} }
} }
public override void Update(float deltaTime)
{
if (objectiveManager.CurrentObjective == this)
{
if (randomTimer > 0)
{
randomTimer -= deltaTime;
}
else
{
SetRandom();
}
}
}
public override bool IsCompleted() => false; public override bool IsCompleted() => false;
public override bool CanBeCompleted => true; public override bool CanBeCompleted => true;
@@ -921,6 +921,10 @@ namespace Barotrauma
{ {
isCompleted = true; isCompleted = true;
} }
if (component.AIOperate(deltaTime, character, this))
{
isCompleted = true;
}
} }
else else
{ {
@@ -1145,24 +1145,6 @@ namespace Barotrauma
SmoothedCursorPosition = cursorPosition - smoothedCursorDiff; SmoothedCursorPosition = cursorPosition - smoothedCursorDiff;
} }
if (!(this is AICharacter) || Controlled == this || IsRemotePlayer)
{
//apply some smoothing to the cursor positions of remote players when playing as a client
//to make aiming look a little less choppy
Vector2 smoothedCursorDiff = cursorPosition - SmoothedCursorPosition;
smoothedCursorDiff = NetConfig.InterpolateCursorPositionError(smoothedCursorDiff);
SmoothedCursorPosition = cursorPosition - smoothedCursorDiff;
}
if (!(this is AICharacter) || Controlled == this || IsRemotePlayer)
{
//apply some smoothing to the cursor positions of remote players when playing as a client
//to make aiming look a little less choppy
Vector2 smoothedCursorDiff = cursorPosition - SmoothedCursorPosition;
smoothedCursorDiff = NetConfig.InterpolateCursorPositionError(smoothedCursorDiff);
SmoothedCursorPosition = cursorPosition - smoothedCursorDiff;
}
if (!(this is AICharacter) || Controlled == this || IsRemotePlayer) if (!(this is AICharacter) || Controlled == this || IsRemotePlayer)
{ {
if (speedMultipliers.Count == 0) return 1f; if (speedMultipliers.Count == 0) return 1f;
@@ -753,6 +753,25 @@ namespace Barotrauma.Items.Components
} }
} }
if (targetItem.Prefab.DeconstructItems.Any())
{
inputContainer.Inventory.RemoveItem(targetItem);
Entity.Spawner.AddToRemoveQueue(targetItem);
MoveInputQueue();
PutItemsToLinkedContainer();
}
else
{
if (outputContainer.Inventory.Items.All(i => i != null))
{
targetItem.Drop(dropper: null);
}
else
{
outputContainer.Inventory.TryPutItem(targetItem, user: null, createNetworkEvent: true);
}
}
if (targetItem.Prefab.DeconstructItems.Any()) if (targetItem.Prefab.DeconstructItems.Any())
{ {
inputContainer.Inventory.RemoveItem(targetItem); inputContainer.Inventory.RemoveItem(targetItem);
@@ -144,6 +144,17 @@ namespace Barotrauma.Items.Components
} }
} }
public Vector2 SteeringInput
{
get { return steeringInput; }
set
{
if (!MathUtils.IsValid(value)) return;
steeringInput.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
steeringInput.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
}
}
public SteeringPath SteeringPath public SteeringPath SteeringPath
{ {
if (!CanBeSelected) return false; if (!CanBeSelected) return false;
@@ -164,12 +175,6 @@ namespace Barotrauma.Items.Components
set { posToMaintain = value; } set { posToMaintain = value; }
} }
public Vector2? PosToMaintain
{
get { return posToMaintain; }
set { posToMaintain = value; }
}
struct ObstacleDebugInfo struct ObstacleDebugInfo
{ {
public Vector2 Point1; public Vector2 Point1;
@@ -1171,70 +1171,6 @@ namespace Barotrauma
} }
} }
public void UpdateTransform()
{
Submarine prevSub = Submarine;
FindHull();
if (Submarine == null && prevSub != null)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub == null)
{
body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub != null && Submarine != prevSub)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition - Submarine.SimPosition, body.Rotation);
}
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
if (Math.Abs(body.LinearVelocity.X) > NetConfig.MaxPhysicsBodyVelocity ||
Math.Abs(body.LinearVelocity.Y) > NetConfig.MaxPhysicsBodyVelocity)
{
body.LinearVelocity = new Vector2(
MathHelper.Clamp(body.LinearVelocity.X, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity),
MathHelper.Clamp(body.LinearVelocity.Y, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity));
}
}
public void UpdateTransform()
{
Submarine prevSub = Submarine;
FindHull();
if (Submarine == null && prevSub != null)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub == null)
{
body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub != null && Submarine != prevSub)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition - Submarine.SimPosition, body.Rotation);
}
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
if (Math.Abs(body.LinearVelocity.X) > NetConfig.MaxPhysicsBodyVelocity ||
Math.Abs(body.LinearVelocity.Y) > NetConfig.MaxPhysicsBodyVelocity)
{
body.LinearVelocity = new Vector2(
MathHelper.Clamp(body.LinearVelocity.X, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity),
MathHelper.Clamp(body.LinearVelocity.Y, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity));
}
}
/// <summary> /// <summary>
/// Applies buoyancy, drag and angular drag caused by water /// Applies buoyancy, drag and angular drag caused by water
/// </summary> /// </summary>
+21 -6
View File
@@ -15,12 +15,6 @@ namespace Barotrauma
public static List<Hull> hullList = new List<Hull>(); public static List<Hull> hullList = new List<Hull>();
public static List<EntityGrid> EntityGrids { get; } = new List<EntityGrid>(); public static List<EntityGrid> EntityGrids { get; } = new List<EntityGrid>();
public string DisplayName
{
get;
private set;
}
public static bool EditWater, EditFire; public static bool EditWater, EditFire;
public const float OxygenDistributionSpeed = 500.0f; public const float OxygenDistributionSpeed = 500.0f;
public const float OxygenDeteriorationSpeed = 0.3f; public const float OxygenDeteriorationSpeed = 0.3f;
@@ -85,6 +79,27 @@ namespace Barotrauma
public readonly List<Gap> ConnectedGaps = new List<Gap>(); public readonly List<Gap> ConnectedGaps = new List<Gap>();
public readonly List<Gap> ConnectedGaps = new List<Gap>();
private string roomName;
[Editable, Serialize("", true, translationTextTag: "RoomName.")]
public string RoomName
{
get { return roomName; }
set
{
if (roomName == value) { return; }
roomName = value;
DisplayName = TextManager.Get(roomName, returnNull: true) ?? roomName;
}
}
public string DisplayName
{
get;
private set;
}
private string roomName; private string roomName;
[Editable, Serialize("", true, translationTextTag: "RoomName.")] [Editable, Serialize("", true, translationTextTag: "RoomName.")]
public string RoomName public string RoomName