Further separation of client-specific code
Still not done here, just gonna push a commit now so I can pull this from elsewhere.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Barotrauma
|
||||
None = 0, Any = 1, RightHand = 2, LeftHand = 4, Head = 8, Torso = 16, Legs = 32, Face=64
|
||||
};
|
||||
|
||||
class CharacterInventory : Inventory
|
||||
partial class CharacterInventory : Inventory
|
||||
{
|
||||
private static Texture2D icons;
|
||||
|
||||
@@ -26,81 +26,26 @@ namespace Barotrauma
|
||||
InvSlotType.Head, InvSlotType.Torso, InvSlotType.Legs, InvSlotType.LeftHand, InvSlotType.RightHand, InvSlotType.Face,
|
||||
InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any,
|
||||
InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any};
|
||||
|
||||
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];
|
||||
|
||||
int rectWidth = 40, rectHeight = 40;
|
||||
int spacing = 10;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
//head, torso, legs
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing,
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * (3 - i));
|
||||
break;
|
||||
//lefthand, righthand
|
||||
case 3:
|
||||
case 4:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 2),
|
||||
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", "")
|
||||
{
|
||||
UserData = i,
|
||||
OnClicked = UseItemOnSelf
|
||||
};
|
||||
|
||||
|
||||
break;
|
||||
case 5:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 5),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
|
||||
|
||||
break;
|
||||
default:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 6)%5),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * ((i>10) ? 2 : 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
InitProjSpecific();
|
||||
}
|
||||
|
||||
private bool UseItemOnSelf(GUIButton button, object obj)
|
||||
private bool UseItemOnSelf(int slotIndex)
|
||||
{
|
||||
if (!(obj is int)) return false;
|
||||
|
||||
int slotIndex = (int)obj;
|
||||
|
||||
if (Items[slotIndex] == null) return false;
|
||||
|
||||
|
||||
#if CLIENT
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect });
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
#if CLIENT
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Barotrauma.Particles;
|
||||
#endif
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class Propulsion : ItemComponent
|
||||
{
|
||||
enum UsableIn
|
||||
{
|
||||
Air,Water,Both
|
||||
};
|
||||
|
||||
private float force;
|
||||
|
||||
private string particles;
|
||||
|
||||
private float useState;
|
||||
|
||||
private ParticlePrefab.DrawTargetType usableIn;
|
||||
|
||||
private UsableIn usableIn;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float Force
|
||||
@@ -21,13 +28,15 @@ namespace Barotrauma.Items.Components
|
||||
get { return force; }
|
||||
set { force = value; }
|
||||
}
|
||||
|
||||
|
||||
#if CLIENT
|
||||
[HasDefaultValue("", false)]
|
||||
public string Particles
|
||||
{
|
||||
get { return particles; }
|
||||
set { particles = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
public Propulsion(Item item, XElement element)
|
||||
: base(item,element)
|
||||
@@ -35,14 +44,14 @@ namespace Barotrauma.Items.Components
|
||||
switch (ToolBox.GetAttributeString(element, "usablein", "both").ToLowerInvariant())
|
||||
{
|
||||
case "air":
|
||||
usableIn = ParticlePrefab.DrawTargetType.Air;
|
||||
usableIn = UsableIn.Air;
|
||||
break;
|
||||
case "water":
|
||||
usableIn = ParticlePrefab.DrawTargetType.Water;
|
||||
usableIn = UsableIn.Water;
|
||||
break;
|
||||
case "both":
|
||||
default:
|
||||
usableIn = ParticlePrefab.DrawTargetType.Both;
|
||||
usableIn = UsableIn.Both;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -58,11 +67,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (character.AnimController.InWater)
|
||||
{
|
||||
if (usableIn == ParticlePrefab.DrawTargetType.Air) return true;
|
||||
if (usableIn == UsableIn.Air) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (usableIn == ParticlePrefab.DrawTargetType.Water) return true;
|
||||
if (usableIn == UsableIn.Water) return true;
|
||||
}
|
||||
|
||||
Vector2 dir = Vector2.Normalize(character.CursorPosition - character.Position);
|
||||
@@ -82,13 +91,14 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (character.SelectedItems[0] == item) character.AnimController.GetLimb(LimbType.RightHand).body.ApplyForce(propulsion);
|
||||
if (character.SelectedItems[1] == item) character.AnimController.GetLimb(LimbType.LeftHand).body.ApplyForce(propulsion);
|
||||
|
||||
|
||||
#if CLIENT
|
||||
if (!string.IsNullOrWhiteSpace(particles))
|
||||
{
|
||||
GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition,
|
||||
item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi), 0.0f, item.CurrentHull);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
interface IDrawableComponent
|
||||
{
|
||||
#if CLIENT
|
||||
void Draw(SpriteBatch spriteBatch, bool editing);
|
||||
#endif
|
||||
}
|
||||
|
||||
class ItemSound
|
||||
|
||||
@@ -1,87 +1,8 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class ItemLabel : ItemComponent, IDrawableComponent
|
||||
partial class ItemLabel : ItemComponent, IDrawableComponent
|
||||
{
|
||||
private GUITextBlock textBlock;
|
||||
|
||||
[HasDefaultValue("", true), Editable(100)]
|
||||
public string Text
|
||||
{
|
||||
get { return textBlock.Text.Replace("\n", ""); }
|
||||
set
|
||||
{
|
||||
if (value == TextBlock.Text || item.Rect.Width < 5) return;
|
||||
|
||||
if (textBlock.Rect.Width != item.Rect.Width || textBlock.Rect.Height != item.Rect.Height)
|
||||
{
|
||||
textBlock = null;
|
||||
}
|
||||
|
||||
TextBlock.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Color textColor;
|
||||
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
|
||||
public string TextColor
|
||||
{
|
||||
get { return ToolBox.Vector4ToString(textColor.ToVector4()); }
|
||||
set
|
||||
{
|
||||
textColor = new Color(ToolBox.ParseToVector4(value));
|
||||
if (textBlock != null) textBlock.TextColor = textColor;
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(1.0f, true)]
|
||||
public float TextScale
|
||||
{
|
||||
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
|
||||
set
|
||||
{
|
||||
if (textBlock != null) textBlock.TextScale = MathHelper.Clamp(value, 0.1f, 10.0f);
|
||||
}
|
||||
}
|
||||
|
||||
private GUITextBlock TextBlock
|
||||
{
|
||||
get
|
||||
{
|
||||
if (textBlock == null)
|
||||
{
|
||||
textBlock = new GUITextBlock(new Rectangle(item.Rect.X,-item.Rect.Y,item.Rect.Width, item.Rect.Height), "",
|
||||
Color.Transparent, textColor,
|
||||
Alignment.TopLeft, Alignment.Center,
|
||||
null, null, true);
|
||||
textBlock.Font = GUI.SmallFont;
|
||||
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
textBlock.TextDepth = item.Sprite.Depth - 0.0001f;
|
||||
textBlock.TextScale = TextScale;
|
||||
}
|
||||
return textBlock;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
textBlock.Rect = new Rectangle(item.Rect.X, -item.Rect.Y, item.Rect.Width, item.Rect.Height);
|
||||
}
|
||||
|
||||
public ItemLabel(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||
{
|
||||
var drawPos = new Vector2(
|
||||
item.DrawPosition.X - item.Rect.Width/2.0f,
|
||||
-(item.DrawPosition.Y + item.Rect.Height/2.0f));
|
||||
|
||||
textBlock.Draw(spriteBatch, drawPos - textBlock.Rect.Location.ToVector2());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,10 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class FixRequirement
|
||||
partial class FixRequirement
|
||||
{
|
||||
string name;
|
||||
|
||||
private static GUIFrame frame;
|
||||
|
||||
List<Skill> requiredSkills;
|
||||
List<string> requiredItems;
|
||||
|
||||
@@ -46,7 +44,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeFixed(Character character, GUIComponent reqFrame = null)
|
||||
public bool CanBeFixed(Character character)
|
||||
{
|
||||
if (character == null) return false;
|
||||
|
||||
@@ -57,13 +55,6 @@ namespace Barotrauma
|
||||
bool itemFound = (item != null);
|
||||
|
||||
if (!itemFound) success = false;
|
||||
|
||||
if (reqFrame != null)
|
||||
{
|
||||
GUIComponent component = reqFrame.children.Find(c => c.UserData as string == itemName);
|
||||
GUITextBlock text = component as GUITextBlock;
|
||||
if (text != null) text.TextColor = itemFound ? Color.LightGreen : Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Skill skill in requiredSkills)
|
||||
@@ -72,160 +63,9 @@ namespace Barotrauma
|
||||
bool sufficientSkill = characterSkill >= skill.Level;
|
||||
|
||||
if (!sufficientSkill) success = false;
|
||||
|
||||
if (reqFrame != null)
|
||||
{
|
||||
GUIComponent component = reqFrame.children.Find(c => c.UserData as Skill == skill);
|
||||
GUITextBlock text = component as GUITextBlock;
|
||||
if (text != null) text.TextColor = sufficientSkill ? Color.LightGreen : Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private static void CreateGUIFrame(Item item)
|
||||
{
|
||||
int width = 400, height = 500;
|
||||
int y = 0;
|
||||
|
||||
frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "");
|
||||
frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
frame.UserData = item;
|
||||
|
||||
new GUITextBlock(new Rectangle(0,0,200,20), "Attempting to fix " + item.Name, "", frame);
|
||||
|
||||
y = y + 40;
|
||||
foreach (FixRequirement requirement in item.FixRequirements)
|
||||
{
|
||||
GUIFrame reqFrame = new GUIFrame(
|
||||
new Rectangle(0, y, 0, 20 + Math.Max(requirement.requiredItems.Count, requirement.requiredSkills.Count) * 15),
|
||||
Color.Transparent, null, frame);
|
||||
reqFrame.UserData = requirement;
|
||||
|
||||
|
||||
var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), "Fix", "", reqFrame);
|
||||
fixButton.OnClicked = FixButtonPressed;
|
||||
fixButton.UserData = requirement;
|
||||
|
||||
var tickBox = new GUITickBox(new Rectangle(70, 0, 20,20), requirement.name, Alignment.Left, reqFrame);
|
||||
tickBox.Enabled = false;
|
||||
|
||||
int y2 = 20;
|
||||
foreach (string itemName in requirement.requiredItems)
|
||||
{
|
||||
var itemBlock = new GUITextBlock(new Rectangle(30, y2, 200, 15), itemName, "", reqFrame);
|
||||
itemBlock.Font = GUI.SmallFont;
|
||||
itemBlock.UserData = itemName;
|
||||
|
||||
y2 += 15;
|
||||
}
|
||||
|
||||
y2 = 20;
|
||||
foreach (Skill skill in requirement.requiredSkills)
|
||||
{
|
||||
var skillBlock = new GUITextBlock(new Rectangle(0, y2, 200, 15), skill.Name + " - " + skill.Level, "", Alignment.Right, Alignment.TopLeft, reqFrame);
|
||||
skillBlock.Font = GUI.SmallFont;
|
||||
skillBlock.UserData = skill;
|
||||
|
||||
|
||||
y2 += 15;
|
||||
}
|
||||
|
||||
y += reqFrame.Rect.Height;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool FixButtonPressed(GUIButton button, object obj)
|
||||
{
|
||||
FixRequirement requirement = obj as FixRequirement;
|
||||
if (requirement == null) return true;
|
||||
|
||||
Item item = frame.UserData as Item;
|
||||
if (item == null) return true;
|
||||
|
||||
if (!requirement.CanBeFixed(Character.Controlled, button.Parent)) return true;
|
||||
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Repair, item.FixRequirements.IndexOf(requirement)});
|
||||
}
|
||||
else if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Status });
|
||||
requirement.Fixed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
requirement.Fixed = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void UpdateGUIFrame(Item item, Character character)
|
||||
{
|
||||
if (frame == null) return;
|
||||
|
||||
bool unfixedFound = false;
|
||||
foreach (GUIComponent child in frame.children)
|
||||
{
|
||||
FixRequirement requirement = child.UserData as FixRequirement;
|
||||
if (requirement == null) continue;
|
||||
|
||||
if (requirement.Fixed)
|
||||
{
|
||||
child.Color = Color.LightGreen * 0.3f;
|
||||
child.GetChild<GUITickBox>().Selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool canBeFixed = requirement.CanBeFixed(character, child);
|
||||
unfixedFound = true;
|
||||
//child.GetChild<GUITickBox>().Selected = canBeFixed;
|
||||
GUITickBox tickBox = child.GetChild<GUITickBox>();
|
||||
if (tickBox.Selected)
|
||||
{
|
||||
tickBox.Selected = canBeFixed;
|
||||
requirement.Fixed = canBeFixed;
|
||||
|
||||
}
|
||||
child.Color = Color.Red * 0.2f;
|
||||
//tickBox.State = GUIComponent.ComponentState.None;
|
||||
}
|
||||
}
|
||||
if (!unfixedFound)
|
||||
{
|
||||
item.Condition = 100.0f;
|
||||
frame = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawHud(SpriteBatch spriteBatch, Item item, Character character)
|
||||
{
|
||||
if (frame == null) return;
|
||||
|
||||
frame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public static void AddToGUIUpdateList()
|
||||
{
|
||||
if (frame == null) return;
|
||||
|
||||
frame.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
public static void UpdateHud(Item item, Character character)
|
||||
{
|
||||
if (frame == null || frame.UserData != item)
|
||||
{
|
||||
CreateGUIFrame(item);
|
||||
}
|
||||
UpdateGUIFrame(item, character);
|
||||
|
||||
if (frame == null) return;
|
||||
|
||||
frame.Update((float)Timing.Step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Linq;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,65 +8,26 @@ using Barotrauma.Items.Components;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class InventorySlot
|
||||
partial class InventorySlot
|
||||
{
|
||||
public Rectangle Rect;
|
||||
|
||||
public GUIComponent.ComponentState State;
|
||||
|
||||
|
||||
public bool Disabled;
|
||||
|
||||
public bool IsHighlighted
|
||||
{
|
||||
get
|
||||
{
|
||||
return State == GUIComponent.ComponentState.Hover;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color;
|
||||
|
||||
public Color BorderHighlightColor;
|
||||
private CoroutineHandle BorderHighlightCoroutine;
|
||||
|
||||
public InventorySlot(Rectangle rect)
|
||||
{
|
||||
Rect = rect;
|
||||
|
||||
#if CLIENT
|
||||
State = GUIComponent.ComponentState.None;
|
||||
|
||||
Color = Color.White * 0.4f;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ShowBorderHighlight(Color color, float fadeInDuration, float fadeOutDuration)
|
||||
{
|
||||
if (BorderHighlightCoroutine != null)
|
||||
{
|
||||
BorderHighlightCoroutine = null;
|
||||
}
|
||||
|
||||
BorderHighlightCoroutine = CoroutineManager.StartCoroutine(UpdateBorderHighlight(color, fadeInDuration, fadeOutDuration));
|
||||
}
|
||||
|
||||
private IEnumerable<object> UpdateBorderHighlight(Color color, float fadeInDuration, float fadeOutDuration)
|
||||
{
|
||||
float t = 0.0f;
|
||||
while (t < fadeInDuration + fadeOutDuration)
|
||||
{
|
||||
BorderHighlightColor = (t < fadeInDuration) ?
|
||||
Color.Lerp(Color.Transparent, color, t / fadeInDuration) :
|
||||
Color.Lerp(color, Color.Transparent, (t - fadeInDuration) / fadeOutDuration);
|
||||
|
||||
t += CoroutineManager.DeltaTime;
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
}
|
||||
|
||||
class Inventory : IServerSerializable, IClientSerializable
|
||||
partial class Inventory : IServerSerializable, IClientSerializable
|
||||
{
|
||||
public static InventorySlot draggingSlot;
|
||||
public static Item draggingItem;
|
||||
@@ -86,8 +45,6 @@ namespace Barotrauma
|
||||
|
||||
protected int capacity;
|
||||
|
||||
private Vector2 centerPos;
|
||||
|
||||
protected int selectedSlot = -1;
|
||||
|
||||
protected InventorySlot[] slots;
|
||||
@@ -101,14 +58,18 @@ namespace Barotrauma
|
||||
private float syncItemsDelay;
|
||||
private CoroutineHandle syncItemsCoroutine;
|
||||
|
||||
private Vector2 centerPos;
|
||||
|
||||
public Vector2 CenterPos
|
||||
{
|
||||
get { return centerPos; }
|
||||
set
|
||||
{
|
||||
centerPos = value;
|
||||
#if CLIENT
|
||||
centerPos.X *= GameMain.GraphicsWidth;
|
||||
centerPos.Y *= GameMain.GraphicsHeight;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +156,9 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
#if CLIENT
|
||||
if (slots != null && createNetworkEvent) slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -213,7 +176,9 @@ namespace Barotrauma
|
||||
Items[i] = item;
|
||||
item.ParentInventory = this;
|
||||
|
||||
#if CLIENT
|
||||
if (slots != null) slots[i].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
|
||||
#endif
|
||||
|
||||
if (item.body != null)
|
||||
{
|
||||
@@ -232,10 +197,12 @@ namespace Barotrauma
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(Owner as IServerSerializable, new object[] { NetEntityEvent.Type.InventoryState });
|
||||
}
|
||||
#if CLIENT
|
||||
else if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(Owner as IClientSerializable, new object[] { NetEntityEvent.Type.InventoryState });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Item FindItem(string itemName)
|
||||
@@ -311,79 +278,13 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false)
|
||||
{
|
||||
if (slots == null || isSubInventory != subInventory) return;
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (slots[i].Disabled) continue;
|
||||
|
||||
//don't draw the item if it's being dragged out of the slot
|
||||
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
|
||||
|
||||
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
|
||||
}
|
||||
|
||||
if (draggingItem != null &&
|
||||
(draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
|
||||
{
|
||||
Rectangle dragRect = new Rectangle(
|
||||
(int)PlayerInput.MousePosition.X - 10,
|
||||
(int)PlayerInput.MousePosition.Y - 10,
|
||||
40, 40);
|
||||
|
||||
DrawSlot(spriteBatch, new InventorySlot(dragRect), draggingItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (slots[i].IsHighlighted && !slots[i].Disabled && Items[i] != null)
|
||||
{
|
||||
string toolTip = "";
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
toolTip = Items[i].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ?
|
||||
Items[i].Name :
|
||||
Items[i].Name + '\n' + Items[i].Description;
|
||||
}
|
||||
|
||||
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot)
|
||||
{
|
||||
int maxWidth = 300;
|
||||
|
||||
toolTip = ToolBox.WrapText(toolTip, maxWidth, GUI.Font);
|
||||
|
||||
Vector2 textSize = GUI.Font.MeasureString(toolTip);
|
||||
Vector2 rectSize = textSize * 1.2f;
|
||||
|
||||
Vector2 pos = new Vector2(highlightedSlot.Right, highlightedSlot.Y-rectSize.Y);
|
||||
pos.X = (int)(pos.X + 3);
|
||||
pos.Y = (int)pos.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true);
|
||||
GUI.Font.DrawString(spriteBatch, 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(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
|
||||
{
|
||||
bool mouseOn = slot.Rect.Contains(PlayerInput.MousePosition) && !Locked;
|
||||
|
||||
#if CLIENT
|
||||
slot.State = GUIComponent.ComponentState.None;
|
||||
#endif
|
||||
|
||||
if (!(this is CharacterInventory) && !mouseOn && selectedSlot==slotIndex)
|
||||
{
|
||||
@@ -393,7 +294,9 @@ namespace Barotrauma
|
||||
if (mouseOn &&
|
||||
(draggingItem!=null || selectedSlot==slotIndex || selectedSlot==-1))
|
||||
{
|
||||
#if CLIENT
|
||||
slot.State = GUIComponent.ComponentState.Hover;
|
||||
#endif
|
||||
|
||||
if (!isSubSlot && selectedSlot == -1)
|
||||
{
|
||||
@@ -420,11 +323,15 @@ namespace Barotrauma
|
||||
//selectedSlot = slotIndex;
|
||||
if (TryPutItem(draggingItem, slotIndex, true))
|
||||
{
|
||||
#if CLIENT
|
||||
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if CLIENT
|
||||
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||
#endif
|
||||
}
|
||||
draggingItem = null;
|
||||
draggingSlot = null;
|
||||
@@ -460,83 +367,11 @@ namespace Barotrauma
|
||||
|
||||
container.Inventory.isSubInventory = true;
|
||||
|
||||
#if CLIENT
|
||||
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
|
||||
|
||||
container.Inventory.Update(deltaTime, true);
|
||||
}
|
||||
|
||||
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
|
||||
{
|
||||
var item = Items[slotIndex];
|
||||
if (item == null) return;
|
||||
|
||||
var container = item.GetComponent<ItemContainer>();
|
||||
if (container == null) return;
|
||||
|
||||
if (container.Inventory.slots == null || !container.Inventory.isSubInventory) return;
|
||||
|
||||
int itemCapacity = container.Capacity;
|
||||
|
||||
#if DEBUG
|
||||
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
|
||||
#else
|
||||
if (slotIndex < 0 || slotIndex >= Items.Length) return;
|
||||
#endif
|
||||
|
||||
var slot = slots[slotIndex];
|
||||
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
||||
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
|
||||
|
||||
container.Inventory.Draw(spriteBatch, true);
|
||||
|
||||
if (!containerRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
if (draggingItem == null || draggingItem.Container != item) selectedSlot = -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawSlot(SpriteBatch spriteBatch, InventorySlot slot, Item item, bool drawItem=true)
|
||||
{
|
||||
Rectangle rect = slot.Rect;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), true);
|
||||
|
||||
if (item != null && drawItem)
|
||||
{
|
||||
if (item.Condition < 100.0f)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Bottom - 8, rect.Width, 8), Color.Black*0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Rectangle(rect.X, rect.Bottom - 8, (int)(rect.Width * item.Condition / 100.0f), 8),
|
||||
Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f)*0.8f, true);
|
||||
}
|
||||
|
||||
var containedItems = item.ContainedItems;
|
||||
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
|
||||
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f)*0.8f, true);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
|
||||
|
||||
if (slot.BorderHighlightColor != Color.Transparent)
|
||||
{
|
||||
Rectangle highlightRect = slot.Rect;
|
||||
highlightRect.Inflate(3,3);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, highlightRect, slot.BorderHighlightColor, false, 0, 5);
|
||||
}
|
||||
|
||||
if (item == null || !drawItem) return;
|
||||
|
||||
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||
container.Inventory.Update(deltaTime, true);
|
||||
}
|
||||
|
||||
public void ClientWrite(NetBuffer msg, object[] extraData = null)
|
||||
|
||||
Reference in New Issue
Block a user