Skip to content

Commit

Permalink
Merge pull request #1616 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored Dec 8, 2023
2 parents 52ddb40 + 8e82b67 commit 7968bdc
Show file tree
Hide file tree
Showing 264 changed files with 127,784 additions and 122,421 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ protected string ExtractSpeechSubstring(ChatMessage message, string tag)
var rawmsg = message.WrappedMessage;
var tagStart = rawmsg.IndexOf($"[{tag}]");
var tagEnd = rawmsg.IndexOf($"[/{tag}]");
if (tagStart < 0 || tagEnd < 0) //the above return -1 if the tag's not found, which in turn will cause the below to throw an exception. a blank speech bubble is far more noticeably broken than the bubble not appearing at all -bhijn
return "";
tagStart += tag.Length + 2;
return rawmsg.Substring(tagStart, tagEnd - tagStart);
}
Expand Down
12 changes: 5 additions & 7 deletions Content.Client/Clothing/ClientClothingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,15 @@ private void OnDidUnequip(EntityUid uid, SpriteComponent component, DidUnequipEv
revealedLayers.Clear();
}

public void InitClothing(EntityUid uid, InventoryComponent? component = null, SpriteComponent? sprite = null)
public void InitClothing(EntityUid uid, InventoryComponent component)
{
if (!Resolve(uid, ref sprite, ref component) || !_inventorySystem.TryGetSlots(uid, out var slots, component))
if (!TryComp(uid, out SpriteComponent? sprite))
return;

foreach (var slot in slots)
var enumerator = _inventorySystem.GetSlotEnumerator((uid, component));
while (enumerator.NextItem(out var item, out var slot))
{
if (!_inventorySystem.TryGetSlotContainer(uid, slot.Name, out var containerSlot, out _, component) ||
!containerSlot.ContainedEntity.HasValue) continue;

RenderEquipment(uid, containerSlot.ContainedEntity.Value, slot.Name, component, sprite);
RenderEquipment(uid, item, slot.Name, component, sprite);
}
}

Expand Down
66 changes: 10 additions & 56 deletions Content.Client/Inventory/ClientInventorySystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Content.Client.Clothing;
using Content.Client.Examine;
using Content.Client.UserInterface.Controls;
using Content.Client.Verbs.UI;
using Content.Shared.Clothing.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
Expand All @@ -15,14 +13,12 @@
using Robust.Shared.Containers;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

namespace Content.Client.Inventory
{
[UsedImplicitly]
public sealed class ClientInventorySystem : InventorySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IUserInterfaceManager _ui = default!;

Expand Down Expand Up @@ -89,7 +85,7 @@ private void OnUseInHand(EntityUid uid, ClothingComponent component, UseInHandEv
private void OnDidUnequip(InventorySlotsComponent component, DidUnequipEvent args)
{
UpdateSlot(args.Equipee, component, args.Slot);
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
if (args.Equipee != _playerManager.LocalEntity)
return;
var update = new SlotSpriteUpdate(null, args.SlotGroup, args.Slot, false);
OnSpriteUpdate?.Invoke(update);
Expand All @@ -98,7 +94,7 @@ private void OnDidUnequip(InventorySlotsComponent component, DidUnequipEvent arg
private void OnDidEquip(InventorySlotsComponent component, DidEquipEvent args)
{
UpdateSlot(args.Equipee, component, args.Slot);
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
if (args.Equipee != _playerManager.LocalEntity)
return;
var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
HasComp<StorageComponent>(args.Equipment));
Expand All @@ -107,10 +103,8 @@ private void OnDidEquip(InventorySlotsComponent component, DidEquipEvent args)

private void OnShutdown(EntityUid uid, InventoryComponent component, ComponentShutdown args)
{
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return;

OnUnlinkInventory?.Invoke();
if (uid == _playerManager.LocalEntity)
OnUnlinkInventory?.Invoke();
}

private void OnPlayerDetached(EntityUid uid, InventorySlotsComponent component, LocalPlayerDetachedEvent args)
Expand Down Expand Up @@ -151,21 +145,18 @@ protected override void OnInit(EntityUid uid, InventoryComponent component, Comp
base.OnInit(uid, component, args);
_clothingVisualsSystem.InitClothing(uid, component);

if (!_prototypeManager.TryIndex(component.TemplateId, out InventoryTemplatePrototype? invTemplate) ||
!TryComp(uid, out InventorySlotsComponent? inventorySlots))
{
if (!TryComp(uid, out InventorySlotsComponent? inventorySlots))
return;
}

foreach (var slot in invTemplate.Slots)
foreach (var slot in component.Slots)
{
TryAddSlotDef(uid, inventorySlots, slot);
}
}

public void ReloadInventory(InventorySlotsComponent? component = null)
{
var player = _playerManager.LocalPlayer?.ControlledEntity;
var player = _playerManager.LocalEntity;
if (player == null || !Resolve(player.Value, ref component, false))
{
return;
Expand All @@ -179,7 +170,7 @@ public void SetSlotHighlight(EntityUid owner, InventorySlotsComponent component,
{
var oldData = component.SlotData[slotName];
var newData = component.SlotData[slotName] = new SlotData(oldData, state);
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
if (owner == _playerManager.LocalEntity)
EntitySlotUpdate?.Invoke(newData);
}

Expand All @@ -198,7 +189,7 @@ public void UpdateSlot(EntityUid owner, InventorySlotsComponent component, strin

var newData = component.SlotData[slotName] =
new SlotData(component.SlotData[slotName], newHighlight, newBlocked);
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
if (owner == _playerManager.LocalEntity)
EntitySlotUpdate?.Invoke(newData);
}

Expand All @@ -208,48 +199,11 @@ public bool TryAddSlotDef(EntityUid owner, InventorySlotsComponent component, Sl
if (!component.SlotData.TryAdd(newSlotDef.Name, newSlotData))
return false;

if (owner == _playerManager.LocalPlayer?.ControlledEntity)
if (owner == _playerManager.LocalEntity)
OnSlotAdded?.Invoke(newSlotData);
return true;
}

public void RemoveSlotDef(EntityUid owner, InventorySlotsComponent component, SlotData slotData)
{
if (component.SlotData.Remove(slotData.SlotName))
{
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
OnSlotRemoved?.Invoke(slotData);
}
}

public void RemoveSlotDef(EntityUid owner, InventorySlotsComponent component, string slotName)
{
if (!component.SlotData.TryGetValue(slotName, out var slotData))
return;

component.SlotData.Remove(slotName);

if (owner == _playerManager.LocalPlayer?.ControlledEntity)
OnSlotRemoved?.Invoke(slotData);
}

// TODO hud refactor This should also live in a UI Controller
private void HoverInSlotButton(EntityUid uid, string slot, SlotControl control,
InventoryComponent? inventoryComponent = null, HandsComponent? hands = null)
{
if (!Resolve(uid, ref inventoryComponent))
return;

if (!Resolve(uid, ref hands, false))
return;

if (hands.ActiveHandEntity is not EntityUid heldEntity)
return;

if (!TryGetSlotContainer(uid, slot, out var containerSlot, out var slotDef, inventoryComponent))
return;
}

public void UIInventoryActivate(string slot)
{
EntityManager.RaisePredictiveEvent(new UseSlotNetworkMessage(slot));
Expand Down
8 changes: 4 additions & 4 deletions Content.Client/Inventory/StrippableBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public void UpdateMenu()

_strippingMenu.ClearButtons();

if (EntMan.TryGetComponent<InventoryComponent>(Owner, out var inv) && _protoMan.TryIndex<InventoryTemplatePrototype>(inv.TemplateId, out var template))
if (EntMan.TryGetComponent<InventoryComponent>(Owner, out var inv))
{
foreach (var slot in template.Slots)
foreach (var slot in inv.Slots)
{
AddInventoryButton(Owner, slot.Name, template, inv);
AddInventoryButton(Owner, slot.Name, inv);
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ private void SlotPressed(GUIBoundKeyEventArgs ev, SlotControl slot)
_ui.GetUIController<VerbMenuUIController>().OpenVerbMenu(slot.Entity.Value);
}

private void AddInventoryButton(EntityUid invUid, string slotId, InventoryTemplatePrototype _, InventoryComponent inv)
private void AddInventoryButton(EntityUid invUid, string slotId, InventoryComponent inv)
{
if (!_inv.TryGetSlotContainer(invUid, slotId, out var container, out var slotDef, inv))
return;
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/GraphicsTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</BoxContainer>
<CheckBox Name="ShowHeldItemCheckBox" Text="{Loc 'ui-options-show-held-item'}" />
<CheckBox Name="ShowCombatModeIndicatorsCheckBox" Text="{Loc 'ui-options-show-combat-mode-indicators'}" />
<CheckBox Name="OpaqueStorageWindowCheckBox" Text="{Loc 'ui-options-opaque-storage-window'}" />
<CheckBox Name="ShowLoocAboveHeadCheckBox" Text="{Loc 'ui-options-show-looc-on-head'}" />
<CheckBox Name="FancySpeechBubblesCheckBox" Text="{Loc 'ui-options-fancy-speech'}" />
<CheckBox Name="FancyNameBackgroundsCheckBox" Text="{Loc 'ui-options-fancy-name-background'}" />
Expand Down
6 changes: 6 additions & 0 deletions Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public GraphicsTab()

ShowHeldItemCheckBox.OnToggled += OnCheckBoxToggled;
ShowCombatModeIndicatorsCheckBox.OnToggled += OnCheckBoxToggled;
OpaqueStorageWindowCheckBox.OnToggled += OnCheckBoxToggled;
ShowLoocAboveHeadCheckBox.OnToggled += OnCheckBoxToggled;
ShowLoocAboveHeadCheckBox.OnToggled += OnCheckBoxToggled;
FancySpeechBubblesCheckBox.OnToggled += OnCheckBoxToggled;
FancyNameBackgroundsCheckBox.OnToggled += OnCheckBoxToggled;
Expand All @@ -124,6 +126,7 @@ public GraphicsTab()
FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible);
ShowHeldItemCheckBox.Pressed = _cfg.GetCVar(CCVars.HudHeldItemShow);
ShowCombatModeIndicatorsCheckBox.Pressed = _cfg.GetCVar(CCVars.CombatModeIndicatorsPointShow);
OpaqueStorageWindowCheckBox.Pressed = _cfg.GetCVar(CCVars.OpaqueStorageWindow);
ShowLoocAboveHeadCheckBox.Pressed = _cfg.GetCVar(CCVars.LoocAboveHeadShow);
FancySpeechBubblesCheckBox.Pressed = _cfg.GetCVar(CCVars.ChatEnableFancyBubbles);
FancyNameBackgroundsCheckBox.Pressed = _cfg.GetCVar(CCVars.ChatFancyNameBackground);
Expand Down Expand Up @@ -174,6 +177,7 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed);
_cfg.SetCVar(CCVars.HudHeldItemShow, ShowHeldItemCheckBox.Pressed);
_cfg.SetCVar(CCVars.CombatModeIndicatorsPointShow, ShowCombatModeIndicatorsCheckBox.Pressed);
_cfg.SetCVar(CCVars.OpaqueStorageWindow, OpaqueStorageWindowCheckBox.Pressed);
_cfg.SetCVar(CCVars.LoocAboveHeadShow, ShowLoocAboveHeadCheckBox.Pressed);
_cfg.SetCVar(CCVars.ChatEnableFancyBubbles, FancySpeechBubblesCheckBox.Pressed);
_cfg.SetCVar(CCVars.ChatFancyNameBackground, FancyNameBackgroundsCheckBox.Pressed);
Expand Down Expand Up @@ -214,6 +218,7 @@ private void UpdateApplyButton()
var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality);
var isShowHeldItemSame = ShowHeldItemCheckBox.Pressed == _cfg.GetCVar(CCVars.HudHeldItemShow);
var isCombatModeIndicatorsSame = ShowCombatModeIndicatorsCheckBox.Pressed == _cfg.GetCVar(CCVars.CombatModeIndicatorsPointShow);
var isOpaqueStorageWindow = OpaqueStorageWindowCheckBox.Pressed == _cfg.GetCVar(CCVars.OpaqueStorageWindow);
var isLoocShowSame = ShowLoocAboveHeadCheckBox.Pressed == _cfg.GetCVar(CCVars.LoocAboveHeadShow);
var isFancyChatSame = FancySpeechBubblesCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatEnableFancyBubbles);
var isFancyBackgroundSame = FancyNameBackgroundsCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatFancyNameBackground);
Expand All @@ -233,6 +238,7 @@ private void UpdateApplyButton()
isHudThemeSame &&
isShowHeldItemSame &&
isCombatModeIndicatorsSame &&
isOpaqueStorageWindow &&
isLoocShowSame &&
isFancyChatSame &&
isFancyBackgroundSame &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using System.Linq;
using System.Numerics;
using Content.Client.Items.Systems;
using Content.Shared.Item;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;

namespace Content.Client.UserInterface.Systems.Storage.Controls;

public sealed class ItemGridPiece : Control
{
private readonly ItemSystem _itemSystem;
private readonly SpriteSystem _spriteSystem;
private readonly IEntityManager _entityManager;
private readonly StorageUIController _storageController;

private readonly List<(Texture, Vector2)> _texturesPositions = new();
Expand Down Expand Up @@ -49,8 +47,7 @@ public ItemGridPiece(Entity<ItemComponent> entity, ItemStorageLocation location,
{
IoCManager.InjectDependencies(this);

_itemSystem = entityManager.System<ItemSystem>();
_spriteSystem = entityManager.System<SpriteSystem>();
_entityManager = entityManager;
_storageController = UserInterfaceManager.GetUIController<StorageUIController>();

Entity = entity.Owner;
Expand All @@ -59,9 +56,22 @@ public ItemGridPiece(Entity<ItemComponent> entity, ItemStorageLocation location,
Visible = true;
MouseFilter = MouseFilterMode.Pass;

TooltipSupplier = SupplyTooltip;

OnThemeUpdated();
}

private Control? SupplyTooltip(Control sender)
{
if (_storageController.IsDragging)
return null;

return new Tooltip
{
Text = _entityManager.GetComponent<MetaDataComponent>(Entity).EntityName
};
}

protected override void OnThemeUpdated()
{
base.OnThemeUpdated();
Expand All @@ -81,10 +91,17 @@ protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);

// really just an "oh shit" catch.
if (!_entityManager.EntityExists(Entity) || !_entityManager.TryGetComponent<ItemComponent>(Entity, out var itemComponent))
{
Dispose();
return;
}

if (_storageController.IsDragging && _storageController.CurrentlyDragging == this)
return;

var adjustedShape = _itemSystem.GetAdjustedItemShape((Entity, null), Location.Rotation, Vector2i.Zero);
var adjustedShape = _entityManager.System<ItemSystem>().GetAdjustedItemShape((Entity, itemComponent), Location.Rotation, Vector2i.Zero);
var boundingGrid = adjustedShape.GetBoundingBox();
var size = _centerTexture!.Size * 2 * UIScale;

Expand Down Expand Up @@ -127,15 +144,37 @@ protected override void Draw(DrawingHandleScreen handle)
}

// typically you'd divide by two, but since the textures are half a tile, this is done implicitly
var iconOffset = new Vector2((boundingGrid.Width + 1) * size.X ,
var iconPosition = new Vector2((boundingGrid.Width + 1) * size.X ,
(boundingGrid.Height + 1) * size.Y);
var iconRotation = Location.Rotation + Angle.FromDegrees(itemComponent.StoredRotation);

_spriteSystem.ForceUpdate(Entity);
handle.DrawEntity(Entity,
PixelPosition + iconOffset,
Vector2.One * 2 * UIScale,
Angle.Zero,
overrideDirection: Direction.South);
if (itemComponent.StoredSprite is { } storageSprite)
{
var scale = 2 * UIScale;
var offset = (((Box2) boundingGrid).Size - Vector2.One) * size;
var sprite = _entityManager.System<SpriteSystem>().Frame0(storageSprite);

var spriteBox = new Box2Rotated(new Box2(0f, sprite.Height * scale, sprite.Width * scale, 0f), -iconRotation, Vector2.Zero);
var root = spriteBox.CalcBoundingBox().BottomLeft;
var pos = PixelPosition * 2
+ (Parent?.GlobalPixelPosition ?? Vector2.Zero)
+ offset;

handle.SetTransform(pos, iconRotation);
var box = new UIBox2(root, root + sprite.Size * scale);
handle.DrawTextureRect(sprite, box);
handle.SetTransform(Matrix3.Identity);
}
else
{
_entityManager.System<SpriteSystem>().ForceUpdate(Entity);
handle.DrawEntity(Entity,
PixelPosition + iconPosition,
Vector2.One * 2 * UIScale,
Angle.Zero,
eyeRotation: iconRotation,
overrideDirection: Direction.South);
}
}

protected override bool HasPoint(Vector2 point)
Expand Down
Loading

0 comments on commit 7968bdc

Please sign in to comment.