From f1e1b0b4f04e6ff6a46e2229c8833dc77f49ed32 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 25 Nov 2015 17:58:17 +0200 Subject: [PATCH] Stair improvements, inventory "tooltip" & condition progressbar, reactor tries to match the highest load of the connected junction boxes (instead of the sum of the loads) --- .../Source/Characters/AnimController.cs | 4 +- Subsurface/Source/Characters/Character.cs | 18 -- .../Characters/HumanoidAnimController.cs | 2 +- Subsurface/Source/Characters/Ragdoll.cs | 5 + Subsurface/Source/Items/CharacterInventory.cs | 154 ++---------------- .../Items/Components/Machines/Reactor.cs | 4 +- .../Items/Components/Power/PowerContainer.cs | 4 +- Subsurface/Source/Items/Inventory.cs | 61 ++++--- Subsurface_Solution.v12.suo | Bin 831488 -> 830976 bytes 9 files changed, 65 insertions(+), 187 deletions(-) diff --git a/Subsurface/Source/Characters/AnimController.cs b/Subsurface/Source/Characters/AnimController.cs index 2c6b911b6..551b0c245 100644 --- a/Subsurface/Source/Characters/AnimController.cs +++ b/Subsurface/Source/Characters/AnimController.cs @@ -6,8 +6,6 @@ namespace Barotrauma { class AnimController : Ragdoll { - public bool IsStanding; - public enum Animation { None, Climbing, UsingConstruction, Struggle }; public Animation Anim; @@ -32,7 +30,7 @@ namespace Barotrauma get { return stunTimer; } set { - if (float.IsNaN(value) || float.IsInfinity(value)) return; + if (!MathUtils.IsValid(value)) return; stunTimer = value; } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index f75d75bfe..127d9c9d1 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -573,7 +573,6 @@ namespace Barotrauma Vector2 targetMovement = GetTargetMovement(); AnimController.TargetMovement = targetMovement; - AnimController.IsStanding = true; AnimController.IgnorePlatforms = targetMovement.Y < 0.0f; @@ -721,8 +720,6 @@ namespace Barotrauma /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { - AnimController.IsStanding = true; - Limb head = AnimController.GetLimb(LimbType.Head); Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition); @@ -733,19 +730,6 @@ namespace Barotrauma { keys[i].SetState(); } - - // keys[(int)InputType.Left].SetState(GameMain.Config.KeyBind(inpu)); - //keys[(int)InputType.Right].SetState(PlayerInput.KeyDown(Keys.D)); - //keys[(int)InputType.Up].SetState(PlayerInput.KeyDown(Keys.W)); - //keys[(int)InputType.Down].SetState(PlayerInput.KeyDown(Keys.S)); - - //keys[(int)InputType.Select].SetState(PlayerInput.KeyHit(Keys.E)); - //keys[(int)InputType.ActionHit].SetState(PlayerInput.LeftButtonClicked()); - //keys[(int)InputType.ActionHeld].SetState(PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed); - //keys[(int)InputType.SecondaryHit].SetState(PlayerInput.RightButtonClicked()); - //keys[(int)InputType.SecondaryHeld].SetState(PlayerInput.GetMouseState.RightButton == ButtonState.Pressed); - - //keys[(int)InputType.Run].SetState(PlayerInput.KeyDown(Keys.LeftShift)); } else { @@ -1458,8 +1442,6 @@ namespace Barotrauma return; } - AnimController.IsStanding = true; - keys[(int)InputType.Use].Held = actionKeyState; keys[(int)InputType.Use].SetState(false, actionKeyState); diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index 3fea8f485..e9f21c2f9 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -155,7 +155,7 @@ namespace Barotrauma default: if (inWater) UpdateSwimming(); - else if (IsStanding) + else UpdateStanding(); break; diff --git a/Subsurface/Source/Characters/Ragdoll.cs b/Subsurface/Source/Characters/Ragdoll.cs index 870e9c459..2428fa4d4 100644 --- a/Subsurface/Source/Characters/Ragdoll.cs +++ b/Subsurface/Source/Characters/Ragdoll.cs @@ -303,6 +303,11 @@ namespace Barotrauma } else if (structure.StairDirection!=Direction.None && lowestLimb != null) { + float stairPosY = structure.StairDirection == Direction.Right ? + lowestLimb.Position.X - structure.Rect.X : structure.Rect.Width - (lowestLimb.Position.X - structure.Rect.X); + + if (lowestLimb.Position.Y < stairPosY) return; + if (targetMovement.Y < 0.5f) { if (inWater || lowestLimb.Position.Y < structure.Rect.Y - structure.Rect.Height + 50.0f) diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 8bdf72dfb..f3e2ec843 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -102,12 +102,6 @@ namespace Barotrauma /// public override bool TryPutItem(Item item, List allowedSlots, bool createNetworkEvent = true) { - //for (int i = 0; i < capacity; i++) - //{ - // //item is already in the inventory! - // if (items[i] == item) return true; - //} - //try to place the item in LimBlot.Any slot if that's allowed if (allowedSlots.Contains(LimbSlot.Any)) { @@ -147,9 +141,6 @@ namespace Barotrauma } if (placed) return true; - - //if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent); - } @@ -164,15 +155,8 @@ namespace Barotrauma if (Items[index] == item) return false; bool combined = false; - //if (item.Combine(items[i])) - //{ - // //PutItem(item, i, false, false); - // combined = true; - //} - //else if (Items[index].Combine(item)) { - //PutItem(items[i], i, false, false); if (Items[index]==null) { System.Diagnostics.Debug.Assert(false); @@ -222,127 +206,13 @@ namespace Barotrauma if (!slotsFree) return false; return TryPutItem(item, new List() {placeToSlots}, createNetworkEvent); - - - ////there's already an item in the slot - //if (items[i] != null) - //{ - // bool combined = false; - // //if (item.Combine(items[i])) - // //{ - // // //PutItem(item, i, false, false); - // // combined = true; - // //} - // //else - // if (items[i].Combine(item)) - // { - // //PutItem(items[i], i, false, false); - // Inventory otherInventory = items[i].inventory; - // if (otherInventory!=null && createNetworkEvent) - // { - // new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true, true); - // } - - // combined = true; - // } - - // if (!combined) return false; - - // //if (usedSlots.HasFlag(LimbSlot.BothHands)) - // //{ - // // if (limbSlots[i] == LimbSlot.LeftHand) - // // { - // // PutItem(item, FindLimbSlot(LimbSlot.RightHand), createNetworkEvent, false); - // // } - // // else if (limbSlots[i] == LimbSlot.RightHand) - // // { - // // PutItem(item, FindLimbSlot(LimbSlot.LeftHand), createNetworkEvent, false); - // // } - // //} - // if (limbSlots[i] == LimbSlot.Any) - // { - // item.Unequip(character); - // return true; - // } - //} - - - //bool placed = false; - //foreach (LimbSlot allowedSlot in usedSlots) - //{ - // if () - //} - - //foreach (LimbSlot allowedSlot in usedSlots) - //{ - // //check if all the required slots are free - // for (int n = 0; n < capacity; i++) - // { - // if (allowedSlot.HasFlag(limbSlots[n]) && items[n] != null && items[n] != item) continue; - // } - - // for (int n = 0; n < capacity; n++) - // { - // if (allowedSlot.HasFlag(limbSlots[i]) && items[i] == null) - // { - // PutItem(item, i, createNetworkEvent, !placed); - // item.Equip(character); - // placed = true; - // } - // } - - // if (placed) return true; - - // //if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent); - - //} - - //if (limbSlots[i]==LimbSlot.Any) - //{ - // if (usedSlots.HasFlag(LimbSlot.Any)) - // { - // item.Unequip(character); - // PutItem(item, i, createNetworkEvent); - // return true; - // } - // else - // { - // return false; - // } - //} - //else - //{ - - // if (limbSlots[i] != LimbSlot.Any && usedSlots.HasFlag(limbSlots[i]) && items[i] == null) - // { - // item.Unequip(character); - // PutItem(item, i, createNetworkEvent); - // item.Equip(character); - // return true; - // } - - // if (usedSlots.HasFlag(LimbSlot.BothHands) && (limbSlots[i]==LimbSlot.LeftHand || limbSlots[i]==LimbSlot.RightHand)) - // { - // int rightHandSlot = FindLimbSlot(LimbSlot.LeftHand); - // int leftHandSlot = FindLimbSlot(LimbSlot.RightHand); - - // if (items[rightHandSlot] != null) return false; - // if (items[leftHandSlot] != null) return false; - - // PutItem(item, rightHandSlot, createNetworkEvent, true); - // PutItem(item, leftHandSlot, createNetworkEvent, false); - // item.Equip(character); - // return true; - // } - - - // return false; - //} - } public void DrawOwn(SpriteBatch spriteBatch) { + string toolTip = ""; + Rectangle highlightedSlot = Rectangle.Empty; + if (doubleClickedItem!=null && doubleClickedItem.inventory!=this) { TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true); @@ -394,6 +264,11 @@ namespace Barotrauma if (multiSlot) continue; UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4); + if (Items[i]!=null && slotRect.Contains(PlayerInput.MousePosition)) + { + toolTip = Items[i].Name; + highlightedSlot = slotRect; + } if (draggingItem!=null && draggingItem == Items[i]) draggingItemSlot = slotRect; } @@ -431,18 +306,15 @@ namespace Barotrauma if (!multiSlot) continue; UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4); - - //if (multiSlot && i == first) - //{ - // multiSlotPos = multiSlotPos / count; - // items[i].Sprite.Draw(spriteBatch, new Vector2(multiSlotPos.X + rectWidth / 2, multiSlotPos.Y + rectHeight / 2), items[i].Color); - //} - } slotRect.Width = rectWidth; slotRect.Height = rectHeight; + if (!string.IsNullOrWhiteSpace(toolTip)) + { + DrawToolTip(spriteBatch, toolTip, highlightedSlot); + } if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition)) { @@ -450,8 +322,6 @@ namespace Barotrauma { slotRect.X = PlayerInput.GetMouseState.X - slotRect.Width / 2; slotRect.Y = PlayerInput.GetMouseState.Y - slotRect.Height / 2; - //GUI.DrawRectangle(spriteBatch, rect, Color.White, true); - //draggingItem.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White); DrawSlot(spriteBatch, slotRect, draggingItem, false, false); } diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index b708d2e21..5a4acda62 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -198,7 +198,9 @@ namespace Barotrauma.Items.Components if (it == null) continue; PowerTransfer pt = it.GetComponent(); - if (pt != null) load += pt.PowerLoad; + if (pt == null) continue; + + load = Math.Max(load,pt.PowerLoad); } } } diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index e1e3386a6..43f78eefc 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -39,14 +39,14 @@ namespace Barotrauma.Items.Components } } - [HasDefaultValue(10.0f, false), Editable] + [HasDefaultValue(10.0f, true), Editable] public float Capacity { get { return capacity; } set { capacity = Math.Max(value, 1.0f); } } - [HasDefaultValue(10.0f, false), Editable] + [HasDefaultValue(10.0f, true), Editable] public float RechargeSpeed { get { return rechargeSpeed; } diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index 33e73244a..249f0cfae 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -165,8 +165,11 @@ namespace Barotrauma { doubleClickedItem = null; + string toolTip = ""; + int rectWidth = 40, rectHeight = 40; + Rectangle highlightedSlot = Rectangle.Empty; int spacing = 10; int rows = (int)Math.Ceiling((double)capacity / slotsPerRow); @@ -184,7 +187,12 @@ namespace Barotrauma if (draggingItem == Items[i]) draggingItemSlot = slotRect; - UpdateSlot(spriteBatch, slotRect, i, Items[i], false); + UpdateSlot(spriteBatch, slotRect, i, Items[i], false); + if (slotRect.Contains(PlayerInput.MousePosition) && Items[i] != null) + { + highlightedSlot = slotRect; + toolTip = Items[i].Name; + } } if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.container == this.Owner) @@ -208,7 +216,29 @@ namespace Barotrauma DropItem(draggingItem); //draggingItem = null; } - } + } + + if (!string.IsNullOrWhiteSpace(toolTip)) + { + DrawToolTip(spriteBatch, toolTip, highlightedSlot); + } + } + + protected void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot) + { + Vector2 textSize = GUI.Font.MeasureString(toolTip); + Vector2 rectSize = textSize * 1.2f; + + Vector2 pos = new Vector2(highlightedSlot.Center.X, highlightedSlot.Bottom); + pos.X = (int)pos.X; + pos.Y = (int)pos.Y; + + GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true); + spriteBatch.DrawString(GUI.Font, toolTip, + new Vector2((int)pos.X + rectSize.X * 0.5f, (int)pos.Y + rectSize.Y * 0.5f), + Color.White, 0.0f, + new Vector2((int)textSize.X * 0.5f, (int)textSize.Y * 0.5f), + 1.0f, SpriteEffects.None, 0.0f); } protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, bool drawItem=true) @@ -294,29 +324,20 @@ namespace Barotrauma protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, bool drawItem=true) { GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.1f : 0.3f), true); + + if (item != null && item.Condition < 100.0f) + { + GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Bottom - 4, rect.Width, 4), Color.Black, true); + GUI.DrawRectangle(spriteBatch, + new Rectangle(rect.X, rect.Bottom - 4, (int)(rect.Width * item.Condition / 100.0f), 4), + Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f), true); + } + GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.2f : 0.4f), false); if (item == null || !drawItem) return; item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color); - - if (isHighLighted) - { - Vector2 pos = new Vector2(rect.X + rect.Width / 2, rect.Y - rect.Height + 20) - GUI.Font.MeasureString(item.Name) * 0.5f; - pos.X = (int)pos.X; - pos.Y = (int)pos.Y; -#if DEBUG - spriteBatch.DrawString(GUI.Font, item.Name+" - "+item.ID, pos - new Vector2(1.0f, 1.0f), Color.Black); - spriteBatch.DrawString(GUI.Font, item.Name+" - "+item.ID, pos, Color.White); -#else - spriteBatch.DrawString(GUI.Font, item.Name, pos - new Vector2(1.0f, 1.0f), Color.Black); - spriteBatch.DrawString(GUI.Font, item.Name, pos, Color.White); -#endif - - } - - if (item.Condition < 100.0f) - spriteBatch.DrawString(GUI.Font, (int)item.Condition + " %", new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.Red); } public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data) diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 1bffe684d319a261108ac845730565d36fd8944b..57f3bbb4933d98ca2f7936e395caca01d8d7993a 100644 GIT binary patch delta 1173 zcmaKqe{54#6vyAW_qM*by^eylbga=QEBcZd)^%mkI5rK$71prAU=A2M6$Q*Bm@FiM zkP`Jp4MORI9WWCUel#=UGU@DlMnkr+KO})n6N3p^v?L}*V-zEQ3}MCdT6OhDe93wD z-ke|G`?)8Xk0hreskO>Fkfg`RT!%K*xaToRLilj+PvH7|`S^ElWnXk31gJDY)Wb}+ zL7s%PyU!JVC_b2STrN*slB8cLdk)!s=$VFxF}4a4cyt;rnzo_hjvEm49wYDVvJVGu zz~-}6%_7@eF##uh?B8{M1{r6jVasfhPpMT|joVI6m4{3jZ#hJOl-vk5ZYJaDg zp*VBMKjJee=OWoVB;XjWhsn&o`J-7anE&NO70Y=+TY%aDR?FcDh8>M!kr`$R_8(v! z=6TkD*J-1`2Eww*K{LLL-DUR9xfA;jvi<3kAuIF%M1#VSW%a}$1>zKSvaYQFuNYX# z!!Uylwy0AbL3jTF0k_&B%&tiIwk?`UsbAV64wjaHJWs1fMH@w$gX+t&Q@5V_nwlqC zj5NDFaVVIlJsWdfp!Hf>l-B~6)|X3P!V_{2C2c7e?7HA4`S?;NtFuBjOtlU~`DdcH zJOr;t`C44vC~8Xx{=C`V{RnfTcc&u*gKNG+Dr zI*J}!b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