1
0

StampWidget.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Numerics;
  2. using Content.Shared.Paper;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.Graphics;
  5. using Robust.Client.ResourceManagement;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Client.UserInterface.XAML;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Client.Paper.UI;
  10. [GenerateTypedNameReferences]
  11. public sealed partial class StampWidget : PanelContainer
  12. {
  13. private StyleBoxTexture _borderTexture;
  14. private ShaderInstance? _stampShader;
  15. public float Orientation
  16. {
  17. get => StampedByLabel.Orientation;
  18. set => StampedByLabel.Orientation = value;
  19. }
  20. public StampDisplayInfo StampInfo {
  21. set {
  22. StampedByLabel.Text = Loc.GetString(value.StampedName);
  23. StampedByLabel.FontColorOverride = value.StampedColor;
  24. ModulateSelfOverride = value.StampedColor;
  25. }
  26. }
  27. public StampWidget()
  28. {
  29. RobustXamlLoader.Load(this);
  30. var resCache = IoCManager.Resolve<IResourceCache>();
  31. var borderImage = resCache.GetResource<TextureResource>(
  32. "/Textures/Interface/Paper/paper_stamp_border.svg.96dpi.png");
  33. _borderTexture = new StyleBoxTexture {
  34. Texture = borderImage,
  35. };
  36. _borderTexture.SetPatchMargin(StyleBoxTexture.Margin.All, 7.0f);
  37. PanelOverride = _borderTexture;
  38. var prototypes = IoCManager.Resolve<IPrototypeManager>();
  39. _stampShader = prototypes.Index<ShaderPrototype>("PaperStamp").InstanceUnique();
  40. }
  41. protected override void Draw(DrawingHandleScreen handle)
  42. {
  43. _stampShader?.SetParameter("objCoord", GlobalPosition * UIScale * new Vector2(1, -1));
  44. handle.UseShader(_stampShader);
  45. handle.SetTransform(GlobalPosition * UIScale, Orientation, Vector2.One);
  46. base.Draw(handle);
  47. // Restore a sane transform+shader
  48. handle.SetTransform(Matrix3x2.Identity);
  49. handle.UseShader(null);
  50. }
  51. }