DefaultGameScreen.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Numerics;
  2. using Content.Client.UserInterface.Systems.Chat.Widgets;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.XAML;
  5. namespace Content.Client.UserInterface.Screens;
  6. [GenerateTypedNameReferences]
  7. public sealed partial class DefaultGameScreen : InGameScreen
  8. {
  9. public DefaultGameScreen()
  10. {
  11. RobustXamlLoader.Load(this);
  12. AutoscaleMaxResolution = new Vector2i(1080, 770);
  13. SetAnchorPreset(MainViewport, LayoutPreset.Wide);
  14. SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
  15. SetAnchorAndMarginPreset(TopLeft, LayoutPreset.TopLeft, margin: 10);
  16. SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
  17. SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomLeft, margin: 5);
  18. SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
  19. SetAnchorAndMarginPreset(Chat, LayoutPreset.TopRight, margin: 10);
  20. SetAnchorAndMarginPreset(Alerts, LayoutPreset.TopRight, margin: 10);
  21. Chat.OnResized += ChatOnResized;
  22. Chat.OnChatResizeFinish += ChatOnResizeFinish;
  23. MainViewport.OnResized += ResizeActionContainer;
  24. Inventory.OnResized += ResizeActionContainer;
  25. }
  26. private void ResizeActionContainer()
  27. {
  28. float indent = Inventory.Size.Y + TopBar.Size.Y + 40;
  29. Actions.ActionsContainer.MaxGridHeight = MainViewport.Size.Y - indent;
  30. }
  31. private void ChatOnResizeFinish(Vector2 _)
  32. {
  33. var marginBottom = Chat.GetValue<float>(MarginBottomProperty);
  34. var marginLeft = Chat.GetValue<float>(MarginLeftProperty);
  35. OnChatResized?.Invoke(new Vector2(marginBottom, marginLeft));
  36. }
  37. private void ChatOnResized()
  38. {
  39. var marginBottom = Chat.GetValue<float>(MarginBottomProperty);
  40. SetMarginTop(Alerts, marginBottom);
  41. }
  42. public override ChatBox ChatBox => Chat;
  43. //TODO: There's probably a better way to do this... but this is also the easiest way.
  44. public override void SetChatSize(Vector2 size)
  45. {
  46. SetMarginBottom(Chat, size.X);
  47. SetMarginLeft(Chat, size.Y);
  48. SetMarginTop(Alerts, size.X);
  49. }
  50. }