From f958f5fb44415e4fbf118e186d67a96bfbd7e074 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 6 Apr 2019 17:46:42 +0300 Subject: [PATCH] (248ac43ed) Added inventory icons for Physicorium items armor, helmet, ammunition box and spear + normal and explosive spear (not yet implemented) --- .../Source/GameSession/CrewManager.cs | 37 +++++ .../Source/Items/Components/ItemComponent.cs | 136 ------------------ .../Source/Items/Components/Turret.cs | 13 +- .../Source/Characters/AI/HumanAIController.cs | 2 - .../Characters/AI/IndoorsSteeringManager.cs | 83 +---------- 5 files changed, 49 insertions(+), 222 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 4333dc5c4..91bb79c26 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -66,6 +66,33 @@ namespace Barotrauma CanBeFocused = false }; + Point scrollButtonSize = new Point((int)(200 * GUI.Scale), (int)(30 * GUI.Scale)); + + crewArea = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.CrewArea, guiFrame.RectTransform), "", Color.Transparent) + { + CanBeFocused = false + }; + toggleCrewButton = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), HUDLayoutSettings.CrewArea.Height), guiFrame.RectTransform) + { AbsoluteOffset = HUDLayoutSettings.CrewArea.Location }, + "", style: "UIToggleButton"); + toggleCrewButton.OnClicked += (GUIButton btn, object userdata) => + { + toggleCrewAreaOpen = !toggleCrewAreaOpen; + foreach (GUIComponent child in btn.Children) + { + child.SpriteEffects = toggleCrewAreaOpen ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + } + return true; + }; + + characterListBox = new GUIListBox(new RectTransform(new Point(100, (int)(crewArea.Rect.Height - scrollButtonSize.Y * 1.6f)), crewArea.RectTransform, Anchor.CenterLeft), false, Color.Transparent, null) + { + //Spacing = (int)(3 * GUI.Scale), + ScrollBarEnabled = false, + ScrollBarVisible = false, + CanBeFocused = false + }; + var characterInfo = new CharacterInfo(subElement); characterInfos.Add(characterInfo); foreach (XElement invElement in subElement.Elements()) @@ -81,6 +108,16 @@ namespace Barotrauma prevUIScale = GUI.Scale; } + + #endregion + + #region Character list management + + public Rectangle GetCharacterListArea() + { + return characterListBox.Rect; + } + partial void InitProjectSpecific() { guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs index 5cd9780b0..cc9829018 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs @@ -175,142 +175,6 @@ namespace Barotrauma.Items.Components } } } - - public void ApplyTo(RectTransform target) - { - if (RelativeOffset.HasValue) - { - target.RelativeOffset = RelativeOffset.Value; - } - else if (AbsoluteOffset.HasValue) - { - target.AbsoluteOffset = AbsoluteOffset.Value; - } - if (RelativeSize.HasValue) - { - target.RelativeSize = RelativeSize.Value; - } - else if (AbsoluteSize.HasValue) - { - target.NonScaledSize = AbsoluteSize.Value; - } - if (Anchor.HasValue) - { - target.Anchor = Anchor.Value; - } - if (Pivot.HasValue) - { - target.Pivot = Pivot.Value; - } - else - { - target.Pivot = RectTransform.MatchPivotToAnchor(target.Anchor); - } - target.RecalculateChildren(true, true); - } - } - - public GUIFrame GuiFrame { get; protected set; } - - [Serialize(false, false)] - public bool AllowUIOverlap - { - get; - set; - } - - private ItemComponent linkToUIComponent; - [Serialize("", false)] - public string LinkUIToComponent - { - get; - set; - } - - [Serialize(0, false)] - public int HudPriority - { - get; - private set; - } - - private bool useAlternativeLayout; - public bool UseAlternativeLayout - { - get { return useAlternativeLayout; } - set - { - if (AlternativeLayout != null) - { - if (value == useAlternativeLayout) { return; } - useAlternativeLayout = value; - if (useAlternativeLayout) - { - AlternativeLayout?.ApplyTo(GuiFrame.RectTransform); - } - else - { - DefaultLayout?.ApplyTo(GuiFrame.RectTransform); - } - } - } - - public void ApplyTo(RectTransform target) - { - if (RelativeOffset.HasValue) - { - target.RelativeOffset = RelativeOffset.Value; - } - else if (AbsoluteOffset.HasValue) - { - target.AbsoluteOffset = AbsoluteOffset.Value; - } - if (RelativeSize.HasValue) - { - target.RelativeSize = RelativeSize.Value; - } - else if (AbsoluteSize.HasValue) - { - target.NonScaledSize = AbsoluteSize.Value; - } - if (Anchor.HasValue) - { - target.Anchor = Anchor.Value; - } - if (Pivot.HasValue) - { - target.Pivot = Pivot.Value; - } - else - { - target.Pivot = RectTransform.MatchPivotToAnchor(target.Anchor); - } - target.RecalculateChildren(true, true); - } - } - - public GUIFrame GuiFrame { get; protected set; } - - [Serialize(false, false)] - public bool AllowUIOverlap - { - get; - set; - } - - private ItemComponent linkToUIComponent; - [Serialize("", false)] - public string LinkUIToComponent - { - get; - set; - } - - [Serialize(0, false)] - public int HudPriority - { - get; - private set; } private bool shouldMuffleLooping; diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs index 479c724d4..6e42a2949 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs @@ -339,14 +339,11 @@ namespace Barotrauma.Items.Components } } - float zoom = cam == null ? 1.0f : (float)Math.Sqrt(cam.Zoom); - - crosshairSprite?.Draw(spriteBatch, crosshairPos, readyToFire ? Color.White : Color.White * 0.2f, 0, zoom); - crosshairPointerSprite?.Draw(spriteBatch, crosshairPointerPos, 0, zoom); - } - - crosshairSprite?.Draw(spriteBatch, crosshairPos, readyToFire ? Color.White : Color.White * 0.2f, 0, zoom); - crosshairPointerSprite?.Draw(spriteBatch, crosshairPointerPos, 0, zoom); + if (crosshairSprite != null) + { + crosshairSprite.Draw(spriteBatch, crosshairPos, readyToFire ? Color.White : Color.White * 0.2f, 0, (float)Math.Sqrt(cam.Zoom)); + } + if (crosshairPointerSprite != null) crosshairPointerSprite.Draw(spriteBatch, crosshairPointerPos, 0, (float)Math.Sqrt(cam.Zoom)); } public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs index f62bc7629..495ba8a2f 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs @@ -289,8 +289,6 @@ namespace Barotrauma public override void OnAttacked(Character attacker, AttackResult attackResult) { - // Damage from falling etc. - if (Character.LastDamageSource == null) { return; } float damage = attackResult.Damage; if (damage <= 0) { return; } if (attacker == null || attacker.IsDead || attacker.Removed) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/IndoorsSteeringManager.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/IndoorsSteeringManager.cs index 6c3d6ba8a..4d0cc72bc 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/IndoorsSteeringManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/IndoorsSteeringManager.cs @@ -43,80 +43,11 @@ namespace Barotrauma private set; } - /// - /// Returns true if the current or the next node is in ladders. - /// - public bool InLadders => - currentPath != null && - currentPath.CurrentNode != null && (currentPath.CurrentNode.Ladders != null || - (currentPath.NextNode != null && currentPath.NextNode.Ladders != null)); + public bool InLadders => currentPath != null && currentPath.CurrentNode != null && currentPath.CurrentNode.Ladders != null; + public bool IsNextNodeLadder => currentPath.NextNode != null && currentPath.CurrentNode.Ladders != null; + public bool IsNextLadderSameAsCurrent => IsNextNodeLadder && currentPath.CurrentNode.Ladders == currentPath.NextNode.Ladders; - /// - /// Returns true if the current or the next node is in stairs. - /// - public bool InStairs => - currentPath != null && - currentPath.CurrentNode != null && (currentPath.CurrentNode.Stairs != null || - (currentPath.NextNode != null && currentPath.NextNode.Stairs != null)); - - public bool IsNextNodeLadder - { - get - { - if (currentPath == null) { return false; } - if (currentPath.NextNode == null) { return false; } - if (currentPath.NextNode.Ladders != null) - { - return true; - } - else - { - // Check if the node after the next node is ladder. - int index = currentPath.CurrentIndex + 2; - if (currentPath.Nodes.Count > index) - { - var node = currentPath.Nodes[index]; - if (node == null) { return false; } - // Only applied if the node is close enough to the current node. - if (Vector2.DistanceSquared(currentPath.CurrentNode.WorldPosition, node.WorldPosition) > 100) { return false; } - return node.Ladders != null; - } - return false; - } - } - } - - public bool IsNextLadderSameAsCurrent - { - get - { - if (currentPath == null) { return false; } - if (currentPath.CurrentNode == null) { return false; } - if (currentPath.NextNode == null) { return false; } - var currentLadder = currentPath.CurrentNode.Ladders; - if (currentLadder == null) { return false; } - var nextLadder = currentPath.NextNode.Ladders; - if (nextLadder != null) - { - return currentLadder == nextLadder; - } - else - { - // Check if the node after the next node is in the same ladder as the current. - int index = currentPath.CurrentIndex + 2; - if (currentPath.Nodes.Count > index) - { - var node = currentPath.Nodes[index]; - if (node == null) { return false; } - // Only applied if the node is close enough to the current node. - if (Vector2.DistanceSquared(currentPath.CurrentNode.WorldPosition, node.WorldPosition) > 100) { return false; } - nextLadder = node.Ladders; - return nextLadder != null && nextLadder == currentLadder; - } - return false; - } - } - } + public bool InStairs => currentPath != null && currentPath.CurrentNode != null && currentPath.CurrentNode.Stairs != null; public IndoorsSteeringManager(ISteerable host, bool canOpenDoors, bool canBreakDoors) : base(host) { @@ -242,7 +173,7 @@ namespace Barotrauma Vector2 diff = currentPath.CurrentNode.SimPosition - pos; bool nextLadderSamesCurrent = IsNextLadderSameAsCurrent; - if (nextLadderSamesCurrent) + if (IsNextLadderSameAsCurrent) { //climbing ladders -> don't move horizontally diff.X = 0.0f; @@ -260,14 +191,14 @@ namespace Barotrauma bool aboveFloor = heightFromFloor > 0.0f && heightFromFloor < collider.height * 1.5f; if (aboveFloor || IsNextNodeLadder) { - if (!nextLadderSamesCurrent) + if (!IsNextLadderSameAsCurrent) { character.AnimController.Anim = AnimController.Animation.None; } currentPath.SkipToNextNode(); } } - else if (nextLadderSamesCurrent) + else if (IsNextLadderSameAsCurrent) { //if the current node is below the character and the next one is above (or vice versa) //and both are on ladders, we can skip directly to the next one