Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/ItemInventory.cs
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
4 using System.Linq;
5 
6 namespace Barotrauma
7 {
8  partial class ItemInventory : Inventory
9  {
10  protected override void ControlInput(Camera cam)
11  {
12  base.ControlInput(cam);
13  cam.OffsetAmount = 0;
14  //if this is used, we need to implement syncing this inventory with the server
15  /*Character.DisableControls = true;
16  if (Character.Controlled != null)
17  {
18  if (PlayerInput.KeyHit(InputType.Select))
19  {
20  Character.Controlled.SelectedItem = null;
21  }
22  }*/
23  }
24 
25  protected override void CalculateBackgroundFrame()
26  {
27  var firstSlot = visualSlots.FirstOrDefault();
28  if (firstSlot == null) { return; }
29  Rectangle frame = firstSlot.Rect;
30  frame.Location += firstSlot.DrawOffset.ToPoint();
31  for (int i = 1; i < capacity; i++)
32  {
33  Rectangle slotRect = visualSlots[i].Rect;
34  slotRect.Location += visualSlots[i].DrawOffset.ToPoint();
35  frame = Rectangle.Union(frame, slotRect);
36  }
38  frame.X - (int)padding.X,
39  frame.Y - (int)padding.Y,
40  frame.Width + (int)(padding.X + padding.Z),
41  frame.Height + (int)(padding.Y + padding.W));
42  }
43 
44  public override void Draw(SpriteBatch spriteBatch, bool subInventory = false)
45  {
46  if (visualSlots != null && visualSlots.Length > 0)
47  {
49  if (container.InventoryBackSprite == null)
50  {
51  //draw a black baground for item inventories that don't have a RectTransform
52  //(= ItemContainers that have no GUIFrame or aren't a part of another component's UI)
53  if (RectTransform == null)
54  {
55  GUI.DrawRectangle(spriteBatch, BackgroundFrame, Color.Black * 0.8f, true);
56  }
57  }
58  else
59  {
60  container.InventoryBackSprite.Draw(
61  spriteBatch, BackgroundFrame.Location.ToVector2(),
62  Color.White, Vector2.Zero, 0,
63  new Vector2(
64  BackgroundFrame.Width / container.InventoryBackSprite.size.X,
65  BackgroundFrame.Height / container.InventoryBackSprite.size.Y));
66  }
67 
68  base.Draw(spriteBatch, subInventory);
69 
70  if (container.InventoryBottomSprite != null && !subInventory)
71  {
72  container.InventoryBottomSprite.Draw(spriteBatch,
73  new Vector2(BackgroundFrame.Center.X, BackgroundFrame.Bottom) + visualSlots[0].DrawOffset,
74  0.0f, UIScale);
75  }
76 
77  if (container.InventoryTopSprite != null && !subInventory)
78  {
79  container.InventoryTopSprite.Draw(spriteBatch, new Vector2(BackgroundFrame.Center.X, BackgroundFrame.Y), 0.0f, UIScale);
80  }
81  }
82  else
83  {
84  base.Draw(spriteBatch, subInventory);
85  }
86  }
87 
89  {
90  SharedWrite(msg, extraData.SlotRange);
91  syncItemsDelay = 1.0f;
92  }
93  }
94 }
float OffsetAmount
Definition: Camera.cs:118
readonly int capacity
Capacity, or the number of slots in the inventory.
void SharedWrite(IWriteMessage msg, Range slotRange)
override void Draw(SpriteBatch spriteBatch, bool subInventory=false)
void ClientEventWrite(IWriteMessage msg, Item.InventoryStateEventData extraData)