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)

This commit is contained in:
Regalis
2015-11-25 17:58:17 +02:00
parent 4b5126675c
commit f1e1b0b4f0
9 changed files with 65 additions and 187 deletions

View File

@@ -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;
}
}

View File

@@ -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
/// </summary>
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);

View File

@@ -155,7 +155,7 @@ namespace Barotrauma
default:
if (inWater)
UpdateSwimming();
else if (IsStanding)
else
UpdateStanding();
break;

View File

@@ -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)

View File

@@ -102,12 +102,6 @@ namespace Barotrauma
/// </summary>
public override bool TryPutItem(Item item, List<LimbSlot> 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<LimbSlot>() {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);
}

View File

@@ -198,7 +198,9 @@ namespace Barotrauma.Items.Components
if (it == null) continue;
PowerTransfer pt = it.GetComponent<PowerTransfer>();
if (pt != null) load += pt.PowerLoad;
if (pt == null) continue;
load = Math.Max(load,pt.PowerLoad);
}
}
}

View File

@@ -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; }

View File

@@ -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)

Binary file not shown.