Performing CPR on unconscious players, a "use on self" button for some items
This commit is contained in:
@@ -27,11 +27,15 @@ namespace Barotrauma
|
||||
|
||||
public Vector2[] SlotPositions;
|
||||
|
||||
private GUIButton[] useOnSelfButton;
|
||||
|
||||
public CharacterInventory(int capacity, Character character)
|
||||
: base(character, capacity)
|
||||
{
|
||||
this.character = character;
|
||||
|
||||
useOnSelfButton = new GUIButton[2];
|
||||
|
||||
if (icons == null) icons = TextureLoader.FromFile("Content/UI/inventoryIcons.png");
|
||||
|
||||
SlotPositions = new Vector2[limbSlots.Length];
|
||||
@@ -56,6 +60,16 @@ namespace Barotrauma
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 3),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight)*3);
|
||||
|
||||
useOnSelfButton[i - 3] = new GUIButton(
|
||||
new Rectangle((int) SlotPositions[i].X, (int) (SlotPositions[i].Y - spacing - rectHeight),
|
||||
rectWidth, rectHeight), "Use", GUI.Style)
|
||||
{
|
||||
UserData = i,
|
||||
OnClicked = UseItemOnSelf
|
||||
};
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
SlotPositions[i] = new Vector2(
|
||||
@@ -66,6 +80,19 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private bool UseItemOnSelf(GUIButton button, object obj)
|
||||
{
|
||||
if (!(obj is int)) return false;
|
||||
|
||||
int slotIndex = (int)obj;
|
||||
|
||||
if (Items[slotIndex] == null) return false;
|
||||
|
||||
Items[slotIndex].ApplyStatusEffects(ActionType.OnUse, 0.016f, character);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void DropItem(Item item)
|
||||
{
|
||||
bool enabled = item.body!=null && item.body.Enabled;
|
||||
@@ -240,13 +267,14 @@ namespace Barotrauma
|
||||
string toolTip = "";
|
||||
Rectangle highlightedSlot = Rectangle.Empty;
|
||||
|
||||
|
||||
if (doubleClickedItem!=null && doubleClickedItem.ParentInventory!=this)
|
||||
{
|
||||
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
|
||||
}
|
||||
doubleClickedItem = null;
|
||||
|
||||
int rectWidth = 40, rectHeight = 40;
|
||||
const int rectWidth = 40, rectHeight = 40;
|
||||
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
|
||||
Rectangle draggingItemSlot = slotRect;
|
||||
|
||||
@@ -340,15 +368,28 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (!multiSlot) continue;
|
||||
|
||||
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
|
||||
|
||||
if (multiSlot)
|
||||
{
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
|
||||
highlightedSlot = slotRect;
|
||||
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
|
||||
highlightedSlot = slotRect;
|
||||
}
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
|
||||
}
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
|
||||
|
||||
if (character==Character.Controlled && selectedSlot != i &&
|
||||
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
|
||||
{
|
||||
useOnSelfButton[i - 3].Update(0.016f);
|
||||
useOnSelfButton[i - 3].Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
slotRect.Width = rectWidth;
|
||||
@@ -359,7 +400,9 @@ namespace Barotrauma
|
||||
DrawToolTip(spriteBatch, toolTip, highlightedSlot);
|
||||
}
|
||||
|
||||
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
|
||||
if (draggingItem == null) return;
|
||||
|
||||
if (!draggingItemSlot.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
@@ -372,10 +415,10 @@ namespace Barotrauma
|
||||
{
|
||||
DropItem(draggingItem);
|
||||
|
||||
new Networking.NetworkEvent(Barotrauma.Networking.NetworkEventType.DropItem, draggingItem.ID, true);
|
||||
new NetworkEvent(NetworkEventType.DropItem, draggingItem.ID, true);
|
||||
//draggingItem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace Barotrauma
|
||||
Vector2 textSize = GUI.Font.MeasureString(toolTip);
|
||||
Vector2 rectSize = textSize * 1.2f;
|
||||
|
||||
Vector2 pos = new Vector2(highlightedSlot.Center.X, highlightedSlot.Y-rectSize.Y);
|
||||
Vector2 pos = new Vector2(highlightedSlot.Right, highlightedSlot.Y-rectSize.Y);
|
||||
pos.X = (int)pos.X;
|
||||
pos.Y = (int)pos.Y;
|
||||
|
||||
|
||||
@@ -189,6 +189,11 @@ namespace Barotrauma
|
||||
get { return prefab.FireProof; }
|
||||
}
|
||||
|
||||
public bool CanUseOnSelf
|
||||
{
|
||||
get { return prefab.CanUseOnSelf; }
|
||||
}
|
||||
|
||||
public bool InWater
|
||||
{
|
||||
get
|
||||
@@ -1056,7 +1061,6 @@ namespace Barotrauma
|
||||
|
||||
public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false)
|
||||
{
|
||||
|
||||
bool hasRequiredSkills = true;
|
||||
|
||||
bool picked = false, selected = false;
|
||||
|
||||
@@ -87,6 +87,12 @@ namespace Barotrauma
|
||||
get { return offsetOnSelected; }
|
||||
}
|
||||
|
||||
public bool CanUseOnSelf
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Vector2 Size
|
||||
{
|
||||
get { return size; }
|
||||
@@ -204,6 +210,8 @@ namespace Barotrauma
|
||||
focusOnSelected = ToolBox.GetAttributeBool(element, "focusonselected", false);
|
||||
|
||||
offsetOnSelected = ToolBox.GetAttributeFloat(element, "offsetonselected", 0.0f);
|
||||
|
||||
CanUseOnSelf = ToolBox.GetAttributeBool(element, "canuseonself", false);
|
||||
|
||||
FireProof = ToolBox.GetAttributeBool(element, "fireproof", false);
|
||||
|
||||
|
||||
@@ -77,9 +77,13 @@ namespace Barotrauma
|
||||
{
|
||||
case RelationType.Contained:
|
||||
if (parentItem == null) return false;
|
||||
foreach (Item contained in parentItem.ContainedItems)
|
||||
|
||||
var containedItems = parentItem.ContainedItems;
|
||||
if (containedItems == null) return false;
|
||||
|
||||
foreach (Item contained in containedItems)
|
||||
{
|
||||
if (contained.Condition>0.0f && MatchesItem(contained)) return true;
|
||||
if (contained.Condition > 0.0f && MatchesItem(contained)) return true;
|
||||
}
|
||||
break;
|
||||
case RelationType.Equipped:
|
||||
|
||||
Reference in New Issue
Block a user