Unstable 0.17.0.0
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using FarseerPhysics;
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Extensions;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -35,58 +38,175 @@ namespace Barotrauma
|
||||
public readonly Sprite Sprite;
|
||||
public readonly bool UseWhenAttached;
|
||||
public readonly DecorativeSpriteBehaviorType DecorativeSpriteBehavior;
|
||||
public readonly string[] AllowedContainerIdentifiers;
|
||||
public readonly string[] AllowedContainerTags;
|
||||
public readonly ImmutableHashSet<Identifier> AllowedContainerIdentifiers;
|
||||
public readonly ImmutableHashSet<Identifier> AllowedContainerTags;
|
||||
|
||||
public ContainedItemSprite(XElement element, string path = "", bool lazyLoad = false)
|
||||
public ContainedItemSprite(ContentXElement element, string path = "", bool lazyLoad = false)
|
||||
{
|
||||
Sprite = new Sprite(element, path, lazyLoad: lazyLoad);
|
||||
UseWhenAttached = element.GetAttributeBool("usewhenattached", false);
|
||||
Enum.TryParse(element.GetAttributeString("decorativespritebehavior", "None"), ignoreCase: true, out DecorativeSpriteBehavior);
|
||||
AllowedContainerIdentifiers = element.GetAttributeStringArray("allowedcontaineridentifiers", new string[0], convertToLowerInvariant: true);
|
||||
AllowedContainerTags = element.GetAttributeStringArray("allowedcontainertags", new string[0], convertToLowerInvariant: true);
|
||||
AllowedContainerIdentifiers = element.GetAttributeIdentifierArray("allowedcontaineridentifiers", Array.Empty<Identifier>()).ToImmutableHashSet();
|
||||
AllowedContainerTags = element.GetAttributeIdentifierArray("allowedcontainertags", Array.Empty<Identifier>()).ToImmutableHashSet();
|
||||
}
|
||||
|
||||
public bool MatchesContainer(Item container)
|
||||
{
|
||||
if (container == null) { return false; }
|
||||
return AllowedContainerIdentifiers.Contains(container.prefab.Identifier) ||
|
||||
AllowedContainerTags.Any(t => container.prefab.Tags.Contains(t));
|
||||
return AllowedContainerIdentifiers.Contains(container.Prefab.Identifier) ||
|
||||
AllowedContainerTags.Any(t => container.Prefab.Tags.Contains(t));
|
||||
}
|
||||
}
|
||||
|
||||
partial class ItemPrefab : MapEntityPrefab
|
||||
partial class ItemPrefab : MapEntityPrefab, IImplementsVariants<ItemPrefab>
|
||||
{
|
||||
public List<BrokenItemSprite> BrokenSprites = new List<BrokenItemSprite>();
|
||||
public List<DecorativeSprite> DecorativeSprites = new List<DecorativeSprite>();
|
||||
public List<ContainedItemSprite> ContainedSprites = new List<ContainedItemSprite>();
|
||||
public Dictionary<int, List<DecorativeSprite>> DecorativeSpriteGroups = new Dictionary<int, List<DecorativeSprite>>();
|
||||
public Sprite InventoryIcon;
|
||||
public Sprite MinimapIcon;
|
||||
public Sprite UpgradePreviewSprite;
|
||||
public Sprite InfectedSprite;
|
||||
public Sprite DamagedInfectedSprite;
|
||||
public ImmutableDictionary<Identifier, ImmutableArray<DecorativeSprite>> UpgradeOverrideSprites { get; private set; }
|
||||
public ImmutableArray<BrokenItemSprite> BrokenSprites { get; private set; }
|
||||
public ImmutableArray<DecorativeSprite> DecorativeSprites { get; private set; }
|
||||
public ImmutableArray<ContainedItemSprite> ContainedSprites { get; private set; }
|
||||
public ImmutableDictionary<int, ImmutableArray<DecorativeSprite>> DecorativeSpriteGroups { get; private set; }
|
||||
public Sprite InventoryIcon { get; private set; }
|
||||
public Sprite MinimapIcon { get; private set; }
|
||||
public Sprite UpgradePreviewSprite { get; private set; }
|
||||
public Sprite InfectedSprite { get; private set; }
|
||||
public Sprite DamagedInfectedSprite { get; private set; }
|
||||
|
||||
public float UpgradePreviewScale = 1.0f;
|
||||
|
||||
//only used to display correct color in the sub editor, item instances have their own property that can be edited on a per-item basis
|
||||
[Serialize("1.0,1.0,1.0,1.0", false)]
|
||||
public Color InventoryIconColor
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
[Serialize("1.0,1.0,1.0,1.0", IsPropertySaveable.No)]
|
||||
public Color InventoryIconColor { get; protected set; }
|
||||
|
||||
[Serialize(true, false)]
|
||||
[Serialize("", IsPropertySaveable.No)]
|
||||
public string ImpactSoundTag { get; private set; }
|
||||
|
||||
[Serialize(true, IsPropertySaveable.No)]
|
||||
public bool ShowInStatusMonitor
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
private void ParseSubElementsClient(ContentXElement element, ItemPrefab variantOf)
|
||||
{
|
||||
UpgradePreviewSprite = null;
|
||||
UpgradePreviewScale = 1f;
|
||||
InventoryIcon = null;
|
||||
MinimapIcon = null;
|
||||
InfectedSprite = null;
|
||||
DamagedInfectedSprite = null;
|
||||
|
||||
var upgradeOverrideSprites = new Dictionary<Identifier, List<DecorativeSprite>>();
|
||||
var brokenSprites = new List<BrokenItemSprite>();
|
||||
var decorativeSprites = new List<DecorativeSprite>();
|
||||
var containedSprites = new List<ContainedItemSprite>();
|
||||
var decorativeSpriteGroups = new Dictionary<int, List<DecorativeSprite>>();
|
||||
|
||||
[Serialize("", false)]
|
||||
public string ImpactSoundTag { get; private set; }
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.LocalName.ToLowerInvariant())
|
||||
{
|
||||
case "upgradeoverride":
|
||||
{
|
||||
|
||||
var sprites = new List<DecorativeSprite>();
|
||||
foreach (var decorSprite in subElement.Elements())
|
||||
{
|
||||
if (decorSprite.NameAsIdentifier() == "decorativesprite")
|
||||
{
|
||||
sprites.Add(new DecorativeSprite(decorSprite));
|
||||
}
|
||||
}
|
||||
upgradeOverrideSprites.Add(subElement.GetAttributeIdentifier("identifier", Identifier.Empty), sprites);
|
||||
break;
|
||||
}
|
||||
case "upgradepreviewsprite":
|
||||
{
|
||||
string iconFolder = GetTexturePath(subElement, variantOf);
|
||||
UpgradePreviewSprite = new Sprite(subElement, iconFolder, lazyLoad: true);
|
||||
UpgradePreviewScale = subElement.GetAttributeFloat("scale", 1.0f);
|
||||
}
|
||||
break;
|
||||
case "inventoryicon":
|
||||
{
|
||||
string iconFolder = GetTexturePath(subElement, variantOf);
|
||||
InventoryIcon = new Sprite(subElement, iconFolder, lazyLoad: true);
|
||||
}
|
||||
break;
|
||||
case "minimapicon":
|
||||
{
|
||||
string iconFolder = GetTexturePath(subElement, variantOf);
|
||||
MinimapIcon = new Sprite(subElement, iconFolder, lazyLoad: true);
|
||||
}
|
||||
break;
|
||||
case "infectedsprite":
|
||||
{
|
||||
string iconFolder = GetTexturePath(subElement, variantOf);
|
||||
|
||||
InfectedSprite = new Sprite(subElement, iconFolder, lazyLoad: true);
|
||||
}
|
||||
break;
|
||||
case "damagedinfectedsprite":
|
||||
{
|
||||
string iconFolder = GetTexturePath(subElement, variantOf);
|
||||
|
||||
DamagedInfectedSprite = new Sprite(subElement, iconFolder, lazyLoad: true);
|
||||
}
|
||||
break;
|
||||
case "brokensprite":
|
||||
string brokenSpriteFolder = GetTexturePath(subElement, variantOf);
|
||||
|
||||
var brokenSprite = new BrokenItemSprite(
|
||||
new Sprite(subElement, brokenSpriteFolder, lazyLoad: true),
|
||||
subElement.GetAttributeFloat("maxcondition", 0.0f),
|
||||
subElement.GetAttributeBool("fadein", false),
|
||||
subElement.GetAttributePoint("offset", Point.Zero));
|
||||
|
||||
int spriteIndex = 0;
|
||||
for (int i = 0; i < brokenSprites.Count && brokenSprites[i].MaxConditionPercentage < brokenSprite.MaxConditionPercentage; i++)
|
||||
{
|
||||
spriteIndex = i;
|
||||
}
|
||||
brokenSprites.Insert(spriteIndex, brokenSprite);
|
||||
break;
|
||||
case "decorativesprite":
|
||||
string decorativeSpriteFolder = GetTexturePath(subElement, variantOf);
|
||||
|
||||
int groupID = 0;
|
||||
DecorativeSprite decorativeSprite = null;
|
||||
if (subElement.Attribute("texture") == null)
|
||||
{
|
||||
groupID = subElement.GetAttributeInt("randomgroupid", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
decorativeSprite = new DecorativeSprite(subElement, decorativeSpriteFolder, lazyLoad: true);
|
||||
decorativeSprites.Add(decorativeSprite);
|
||||
groupID = decorativeSprite.RandomGroupID;
|
||||
}
|
||||
if (!decorativeSpriteGroups.ContainsKey(groupID))
|
||||
{
|
||||
decorativeSpriteGroups.Add(groupID, new List<DecorativeSprite>());
|
||||
}
|
||||
decorativeSpriteGroups[groupID].Add(decorativeSprite);
|
||||
|
||||
break;
|
||||
case "containedsprite":
|
||||
string containedSpriteFolder = GetTexturePath(subElement, variantOf);
|
||||
var containedSprite = new ContainedItemSprite(subElement, containedSpriteFolder, lazyLoad: true);
|
||||
if (containedSprite.Sprite != null)
|
||||
{
|
||||
containedSprites.Add(containedSprite);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeOverrideSprites = upgradeOverrideSprites.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableDictionary();
|
||||
BrokenSprites = brokenSprites.ToImmutableArray();
|
||||
DecorativeSprites = decorativeSprites.ToImmutableArray();
|
||||
ContainedSprites = containedSprites.ToImmutableArray();
|
||||
DecorativeSpriteGroups = decorativeSpriteGroups.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableDictionary();
|
||||
}
|
||||
|
||||
public override void UpdatePlacing(Camera cam)
|
||||
{
|
||||
@@ -94,7 +214,7 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.SecondaryMouseButtonClicked())
|
||||
{
|
||||
selected = null;
|
||||
Selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,7 +224,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (PlayerInput.PrimaryMouseButtonClicked())
|
||||
{
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)(sprite.size.X * Scale), (int)(sprite.size.Y * Scale)), this, Submarine.MainSub)
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)(Sprite.size.X * Scale), (int)(Sprite.size.Y * Scale)), this, Submarine.MainSub)
|
||||
{
|
||||
Submarine = Submarine.MainSub
|
||||
};
|
||||
@@ -128,7 +248,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 placeSize = size * Scale;
|
||||
Vector2 placeSize = Size * Scale;
|
||||
|
||||
if (placePosition == Vector2.Zero)
|
||||
{
|
||||
@@ -137,9 +257,9 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
if (ResizeHorizontal)
|
||||
placeSize.X = Math.Max(position.X - placePosition.X, size.X);
|
||||
placeSize.X = Math.Max(position.X - placePosition.X, Size.X);
|
||||
if (ResizeVertical)
|
||||
placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
|
||||
placeSize.Y = Math.Max(placePosition.Y - position.Y, Size.Y);
|
||||
|
||||
if (PlayerInput.PrimaryMouseButtonReleased())
|
||||
{
|
||||
@@ -174,24 +294,24 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.SecondaryMouseButtonClicked())
|
||||
{
|
||||
selected = null;
|
||||
Selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ResizeHorizontal && !ResizeVertical)
|
||||
{
|
||||
sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y) + sprite.size / 2.0f * Scale, SpriteColor, scale: Scale);
|
||||
Sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y) + Sprite.size / 2.0f * Scale, SpriteColor, scale: Scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 placeSize = size * Scale;
|
||||
Vector2 placeSize = Size * Scale;
|
||||
if (placePosition != Vector2.Zero)
|
||||
{
|
||||
if (ResizeHorizontal) { placeSize.X = Math.Max(position.X - placePosition.X, placeSize.X); }
|
||||
if (ResizeVertical) { placeSize.Y = Math.Max(placePosition.Y - position.Y, placeSize.Y); }
|
||||
position = placePosition;
|
||||
}
|
||||
sprite?.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
|
||||
Sprite?.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,19 +319,19 @@ namespace Barotrauma
|
||||
{
|
||||
if (!ResizeHorizontal && !ResizeVertical)
|
||||
{
|
||||
sprite.Draw(spriteBatch, new Vector2(placeRect.Center.X, -(placeRect.Y - placeRect.Height / 2)), SpriteColor * 0.8f, scale: scale);
|
||||
Sprite.Draw(spriteBatch, new Vector2(placeRect.Center.X, -(placeRect.Y - placeRect.Height / 2)), SpriteColor * 0.8f, scale: scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(Screen.Selected.Cam, Submarine.MainSub);
|
||||
Vector2 placeSize = size * Scale;
|
||||
Vector2 placeSize = Size * Scale;
|
||||
if (placePosition != Vector2.Zero)
|
||||
{
|
||||
if (ResizeHorizontal) { placeSize.X = Math.Max(position.X - placePosition.X, placeSize.X); }
|
||||
if (ResizeVertical) { placeSize.Y = Math.Max(placePosition.Y - position.Y, placeSize.Y); }
|
||||
position = placePosition;
|
||||
}
|
||||
sprite?.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
|
||||
Sprite?.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user