diff --git a/Content.Client/GameObjects/Components/Items/ItemComponent.cs b/Content.Client/GameObjects/Components/Items/ItemComponent.cs index 5da0dfaec5..4b1b2b46be 100644 --- a/Content.Client/GameObjects/Components/Items/ItemComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ItemComponent.cs @@ -21,6 +21,8 @@ namespace Content.Client.GameObjects.Components.Items [ComponentReference(typeof(IItemComponent))] public class ItemComponent : Component, IItemComponent, IDraggable { + [Dependency] private IResourceCache _resourceCache = default!; + public override string Name => "Item"; public override uint? NetID => ContentNetIDs.ITEM; @@ -72,8 +74,7 @@ namespace Content.Client.GameObjects.Components.Items protected RSI GetRSI() { - var resourceCache = IoCManager.Resolve(); - return resourceCache.GetResource(SharedSpriteComponent.TextureRoot / RsiPath).RSI; + return _resourceCache.GetResource(SharedSpriteComponent.TextureRoot / RsiPath).RSI; } public override void HandleComponentState(ComponentState curState, ComponentState nextState) diff --git a/Content.Client/GameObjects/Components/Wires/WiresMenu.cs b/Content.Client/GameObjects/Components/Wires/WiresMenu.cs index a3fcda4861..7469f31a8d 100644 --- a/Content.Client/GameObjects/Components/Wires/WiresMenu.cs +++ b/Content.Client/GameObjects/Components/Wires/WiresMenu.cs @@ -21,6 +21,8 @@ namespace Content.Client.GameObjects.Components.Wires { public class WiresMenu : BaseWindow { + [Dependency] private IResourceCache _resourceCache = default!; + public WiresBoundUserInterface Owner { get; } private readonly Control _wiresHBox; @@ -34,7 +36,7 @@ namespace Content.Client.GameObjects.Components.Wires public WiresMenu(WiresBoundUserInterface owner) { - var resourceCache = IoCManager.Resolve(); + IoCManager.InjectDependencies(this); Owner = owner; var rootContainer = new LayoutContainer {Name = "WireRoot"}; @@ -42,7 +44,7 @@ namespace Content.Client.GameObjects.Components.Wires MouseFilter = MouseFilterMode.Stop; - var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png"); + var panelTex = _resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png"); var back = new StyleBoxTexture { Texture = panelTex, @@ -135,8 +137,8 @@ namespace Content.Client.GameObjects.Components.Wires LayoutContainer.SetAnchorPreset(topContainerWrap, LayoutContainer.LayoutPreset.Wide); - var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13); - var fontSmall = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 10); + var font = _resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13); + var fontSmall = _resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 10); Button helpButton; var topRow = new MarginContainer @@ -255,7 +257,7 @@ namespace Content.Client.GameObjects.Components.Wires var mirror = random.Next(2) == 0; var flip = random.Next(2) == 0; var type = random.Next(2); - var control = new WireControl(wire.Color, wire.Letter, wire.IsCut, flip, mirror, type) + var control = new WireControl(wire.Color, wire.Letter, wire.IsCut, flip, mirror, type, _resourceCache) { SizeFlagsVertical = SizeFlags.ShrinkEnd }; @@ -278,7 +280,7 @@ namespace Content.Client.GameObjects.Components.Wires { if (status.Value is StatusLightData statusLightData) { - _statusContainer.AddChild(new StatusLight(statusLightData)); + _statusContainer.AddChild(new StatusLight(statusLightData, _resourceCache)); } else { @@ -305,18 +307,20 @@ namespace Content.Client.GameObjects.Components.Wires private sealed class WireControl : Control { + private IResourceCache _resourceCache; + private const string TextureContact = "/Textures/Interface/WireHacking/contact.svg.96dpi.png"; public event Action WireClicked; public event Action ContactsClicked; - public WireControl(WireColor color, WireLetter letter, bool isCut, bool flip, bool mirror, int type) + public WireControl(WireColor color, WireLetter letter, bool isCut, bool flip, bool mirror, int type, IResourceCache resourceCache) { + _resourceCache = resourceCache; + SizeFlagsHorizontal = SizeFlags.ShrinkCenter; MouseFilter = MouseFilterMode.Stop; - var resourceCache = IoCManager.Resolve(); - var layout = new LayoutContainer(); AddChild(layout); @@ -326,7 +330,7 @@ namespace Content.Client.GameObjects.Components.Wires SizeFlagsVertical = SizeFlags.ShrinkEnd, SizeFlagsHorizontal = SizeFlags.ShrinkCenter, Align = Label.AlignMode.Center, - FontOverride = resourceCache.GetFont("/Fonts/NotoSansDisplay/NotoSansDisplay-Bold.ttf", 12), + FontOverride = _resourceCache.GetFont("/Fonts/NotoSansDisplay/NotoSansDisplay-Bold.ttf", 12), FontColorOverride = Color.Gray, ToolTip = letter.Name(), MouseFilter = MouseFilterMode.Stop @@ -337,7 +341,7 @@ namespace Content.Client.GameObjects.Components.Wires LayoutContainer.SetGrowVertical(greek, LayoutContainer.GrowDirection.Begin); LayoutContainer.SetGrowHorizontal(greek, LayoutContainer.GrowDirection.Both); - var contactTexture = resourceCache.GetTexture(TextureContact); + var contactTexture = _resourceCache.GetTexture(TextureContact); var contact1 = new TextureRect { Texture = contactTexture, @@ -356,7 +360,7 @@ namespace Content.Client.GameObjects.Components.Wires layout.AddChild(contact2); LayoutContainer.SetPosition(contact2, (0, 60)); - var wire = new WireRender(color, isCut, flip, mirror, type); + var wire = new WireRender(color, isCut, flip, mirror, type, _resourceCache); layout.AddChild(wire); LayoutContainer.SetPosition(wire, (2, 16)); @@ -420,8 +424,11 @@ namespace Content.Client.GameObjects.Components.Wires "/Textures/Interface/WireHacking/wire_2_copper.svg.96dpi.png" }; - public WireRender(WireColor color, bool isCut, bool flip, bool mirror, int type) + private IResourceCache _resourceCache; + + public WireRender(WireColor color, bool isCut, bool flip, bool mirror, int type, IResourceCache resourceCache) { + _resourceCache = resourceCache; _color = color; _isCut = isCut; _flip = flip; @@ -436,10 +443,8 @@ namespace Content.Client.GameObjects.Components.Wires protected override void Draw(DrawingHandleScreen handle) { - var resC = IoCManager.Resolve(); - var colorValue = _color.ColorValue(); - var tex = resC.GetTexture(_isCut ? TextureCut[_type] : TextureNormal[_type]); + var tex = _resourceCache.GetTexture(_isCut ? TextureCut[_type] : TextureNormal[_type]); var l = 0f; var r = tex.Width + l; @@ -465,7 +470,7 @@ namespace Content.Client.GameObjects.Components.Wires if (_isCut) { var copper = Color.Orange; - var copperTex = resC.GetTexture(TextureCopper[_type]); + var copperTex = _resourceCache.GetTexture(TextureCopper[_type]); handle.DrawTextureRect(copperTex, rect, copper); } @@ -516,9 +521,8 @@ namespace Content.Client.GameObjects.Components.Wires } }; - public StatusLight(StatusLightData data) + public StatusLight(StatusLightData data, IResourceCache resourceCache) { - var resC = IoCManager.Resolve(); var hsv = Color.ToHsv(data.Color); hsv.Z /= 2; var dimColor = Color.FromHsv(hsv); @@ -530,7 +534,7 @@ namespace Content.Client.GameObjects.Components.Wires { new TextureRect { - Texture = resC.GetTexture( + Texture = resourceCache.GetTexture( "/Textures/Interface/WireHacking/light_off_base.svg.96dpi.png"), Stretch = TextureRect.StretchMode.KeepCentered, ModulateSelfOverride = dimColor @@ -540,7 +544,7 @@ namespace Content.Client.GameObjects.Components.Wires ModulateSelfOverride = data.Color.WithAlpha(0.4f), Stretch = TextureRect.StretchMode.KeepCentered, Texture = - resC.GetTexture("/Textures/Interface/WireHacking/light_on_base.svg.96dpi.png"), + resourceCache.GetTexture("/Textures/Interface/WireHacking/light_on_base.svg.96dpi.png"), }) } }; @@ -577,7 +581,7 @@ namespace Content.Client.GameObjects.Components.Wires }; } - var font = IoCManager.Resolve().GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 12); + var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 12); var hBox = new HBoxContainer {SeparationOverride = 4}; hBox.AddChild(new Label diff --git a/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs b/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs index 3cfc1497f5..7c5411e20d 100644 --- a/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs +++ b/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs @@ -34,10 +34,8 @@ namespace Content.Shared.Prototypes.Cargo { if (_name.Trim().Length != 0) return _name; - var protoMan = IoCManager.Resolve(); - if (protoMan == null) - return _name; - protoMan.TryIndex(_product, out EntityPrototype prototype); + EntityPrototype prototype = null; + IoCManager.Resolve()?.TryIndex(_product, out prototype); if (prototype?.Name != null) _name = prototype.Name; return _name; @@ -54,10 +52,8 @@ namespace Content.Shared.Prototypes.Cargo { if (_description.Trim().Length != 0) return _description; - var protoMan = IoCManager.Resolve(); - if (protoMan == null) - return _description; - protoMan.TryIndex(_product, out EntityPrototype prototype); + EntityPrototype prototype = null; + IoCManager.Resolve()?.TryIndex(_product, out prototype); if (prototype?.Description != null) _description = prototype.Description; return _description; @@ -94,6 +90,11 @@ namespace Content.Shared.Prototypes.Cargo [ViewVariables] public string Group => _group; + public CargoProductPrototype() + { + IoCManager.InjectDependencies(this); + } + public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping);