From cd6b70986eb36b29466071f76b9ab645dd3fbd41 Mon Sep 17 00:00:00 2001
From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
Date: Sat, 14 Dec 2024 14:09:00 -0400
Subject: [PATCH 1/4] Salvage Magnet UI and Character Switching Height/Width
 Bug Fix (#1347)

<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

i fixed it

also added a button "Connect & Go to Lobby" for people testing lobby
stuff!

Resolves #1131

---

# Changelog

<!--
You can add an author after the `:cl:` to change the name that appears
in the changelog (ex: `:cl: Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

:cl:
- fix: Fixed the bug where switching characters made your width/height
change to incorrect values.
- fix: Fixed the salvage magnet opening ten times.

---------

Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
(cherry picked from commit c4c3e4283ae077fd0f55e4cce31710f31de046f7)
---
 .../Lobby/UI/HumanoidProfileEditor.xaml.cs    | 32 +++++++++++--------
 Content.Client/MainMenu/MainMenu.cs           | 26 +++++++++++++--
 .../MainMenu/UI/MainMenuControl.xaml          |  5 +++
 .../UI/SalvageMagnetBoundUserInterface.cs     |  4 +--
 .../Locale/en-US/main-menu/main-menu.ftl      |  1 +
 5 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
index 3f526981a4e..e89eab89eec 100644
--- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
+++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
@@ -94,7 +94,8 @@ public HumanoidProfileEditor(
             IPlayerManager playerManager,
             IPrototypeManager prototypeManager,
             JobRequirementsManager requirements,
-            MarkingManager markings)
+            MarkingManager markings
+            )
         {
             RobustXamlLoader.Load(this);
             _cfgManager = cfgManager;
@@ -113,7 +114,8 @@ public HumanoidProfileEditor(
             SaveButton.OnPressed += args => { Save?.Invoke(); };
             ResetButton.OnPressed += args =>
             {
-                SetProfile((HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter,
+                SetProfile(
+                    (HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter,
                     _preferencesManager.Preferences?.SelectedCharacterIndex);
             };
 
@@ -192,12 +194,11 @@ public HumanoidProfileEditor(
 
             #endregion Species
 
-            #region Height
+            #region Height and Width
 
             var prototype = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
 
             UpdateHeightWidthSliders();
-            UpdateDimensions(SliderUpdate.Both);
 
             HeightSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Height);
             WidthSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Width);
@@ -490,7 +491,7 @@ public void RefreshFlavorText()
                 if (_flavorText != null)
                     return;
 
-                _flavorText = new FlavorText.FlavorText();
+                _flavorText = new();
                 _flavorText.OnFlavorTextChanged += OnFlavorTextChange;
                 _flavorTextEdit = _flavorText.CFlavorTextInput;
                 CTabContainer.AddTab(_flavorText, Loc.GetString("humanoid-profile-editor-flavortext-tab"));
@@ -761,11 +762,11 @@ public void RefreshJobs()
                 foreach (var job in jobs)
                 {
                     var jobContainer = new BoxContainer { Orientation = LayoutOrientation.Horizontal, };
-                    var selector = new RequirementsSelector { Margin = new Thickness(3f, 3f, 3f, 0f) };
+                    var selector = new RequirementsSelector { Margin = new(3f, 3f, 3f, 0f) };
 
                     var icon = new TextureRect
                     {
-                        TextureScale = new Vector2(2, 2),
+                        TextureScale = new(2, 2),
                         VerticalAlignment = VAlignment.Center
                     };
                     var jobIcon = _prototypeManager.Index<StatusIconPrototype>(job.Icon);
@@ -1361,21 +1362,26 @@ private void UpdateSpawnPriorityControls()
 
         private void UpdateHeightWidthSliders()
         {
+            if (Profile is null)
+                return;
+
             var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
 
             HeightSlider.MinValue = species.MinHeight;
             HeightSlider.MaxValue = species.MaxHeight;
-            HeightSlider.Value = Profile?.Height ?? species.DefaultHeight;
+            HeightSlider.SetValueWithoutEvent(Profile?.Height ?? species.DefaultHeight);
 
             WidthSlider.MinValue = species.MinWidth;
             WidthSlider.MaxValue = species.MaxWidth;
-            WidthSlider.Value = Profile?.Width ?? species.DefaultWidth;
+            WidthSlider.SetValueWithoutEvent(Profile?.Width ?? species.DefaultWidth);
 
             var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
             HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));
 
             var width = MathF.Round(species.AverageWidth * WidthSlider.Value);
             WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));
+
+            UpdateDimensions(SliderUpdate.Both);
         }
 
         private enum SliderUpdate
@@ -1387,9 +1393,10 @@ private enum SliderUpdate
 
         private void UpdateDimensions(SliderUpdate updateType)
         {
-            var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
+            if (Profile == null)
+                return;
 
-            if (Profile == null) return;
+            var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
 
             var heightValue = Math.Clamp(HeightSlider.Value, species.MinHeight, species.MaxHeight);
             var widthValue = Math.Clamp(WidthSlider.Value, species.MinWidth, species.MaxWidth);
@@ -1398,13 +1405,12 @@ private void UpdateDimensions(SliderUpdate updateType)
 
             if (updateType == SliderUpdate.Height || updateType == SliderUpdate.Both)
                 if (ratio < 1 / sizeRatio || ratio > sizeRatio)
-                    widthValue = heightValue / (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);
+                    widthValue = heightValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);
 
             if (updateType == SliderUpdate.Width || updateType == SliderUpdate.Both)
                 if (ratio < 1 / sizeRatio || ratio > sizeRatio)
                     heightValue = widthValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);
 
-
             heightValue = Math.Clamp(heightValue, species.MinHeight, species.MaxHeight);
             widthValue = Math.Clamp(widthValue, species.MinWidth, species.MaxWidth);
 
diff --git a/Content.Client/MainMenu/MainMenu.cs b/Content.Client/MainMenu/MainMenu.cs
index 9c73af11583..6cd6408fb66 100644
--- a/Content.Client/MainMenu/MainMenu.cs
+++ b/Content.Client/MainMenu/MainMenu.cs
@@ -7,6 +7,7 @@
 using Robust.Client.UserInterface.Controls;
 using Robust.Shared;
 using Robust.Shared.Configuration;
+using Robust.Shared.Console;
 using Robust.Shared.Network;
 using Robust.Shared.Utility;
 using UsernameHelpers = Robust.Shared.AuthLib.UsernameHelpers;
@@ -26,9 +27,11 @@ public sealed class MainScreen : Robust.Client.State.State
         [Dependency] private readonly IGameController _controllerProxy = default!;
         [Dependency] private readonly IResourceCache _resourceCache = default!;
         [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
+        [Dependency] private readonly IConsoleHost _console = default!;
 
         private MainMenuControl _mainMenuControl = default!;
         private bool _isConnecting;
+        private bool _shouldGoLobby;
 
         // ReSharper disable once InconsistentNaming
         private static readonly Regex IPv6Regex = new(@"\[(.*:.*:.*)](?::(\d+))?");
@@ -39,15 +42,27 @@ protected override void Startup()
             _mainMenuControl = new MainMenuControl(_resourceCache, _configurationManager);
             _userInterfaceManager.StateRoot.AddChild(_mainMenuControl);
 
+            _client.PlayerJoinedGame += OnPlayerJoinedGame;
+
             _mainMenuControl.QuitButton.OnPressed += QuitButtonPressed;
             _mainMenuControl.OptionsButton.OnPressed += OptionsButtonPressed;
             _mainMenuControl.DirectConnectButton.OnPressed += DirectConnectButtonPressed;
+            _mainMenuControl.GoToLobbyButton.OnPressed += GoToLobbyButtonPressed;
             _mainMenuControl.AddressBox.OnTextEntered += AddressBoxEntered;
             _mainMenuControl.ChangelogButton.OnPressed += ChangelogButtonPressed;
 
             _client.RunLevelChanged += RunLevelChanged;
         }
 
+        private void OnPlayerJoinedGame(object? sender, PlayerEventArgs e)
+        {
+            if (_shouldGoLobby)
+            {
+                _console.ExecuteCommand("golobby");
+                _shouldGoLobby = false;
+            }
+        }
+
         /// <inheritdoc />
         protected override void Shutdown()
         {
@@ -78,12 +93,18 @@ private void DirectConnectButtonPressed(BaseButton.ButtonEventArgs args)
             TryConnect(input.Text);
         }
 
+        private void GoToLobbyButtonPressed(BaseButton.ButtonEventArgs obj)
+        {
+            var input = _mainMenuControl.AddressBox;
+            TryConnect(input.Text);
+
+            _shouldGoLobby = true;
+        }
+
         private void AddressBoxEntered(LineEdit.LineEditEventArgs args)
         {
             if (_isConnecting)
-            {
                 return;
-            }
 
             TryConnect(args.Text);
         }
@@ -197,6 +218,7 @@ private void _setConnectingState(bool state)
         {
             _isConnecting = state;
             _mainMenuControl.DirectConnectButton.Disabled = state;
+            _mainMenuControl.GoToLobbyButton.Disabled = state;
         }
     }
 }
diff --git a/Content.Client/MainMenu/UI/MainMenuControl.xaml b/Content.Client/MainMenu/UI/MainMenuControl.xaml
index d6c3f4b9415..e0242300fc2 100644
--- a/Content.Client/MainMenu/UI/MainMenuControl.xaml
+++ b/Content.Client/MainMenu/UI/MainMenuControl.xaml
@@ -30,6 +30,11 @@
                 Text="{Loc 'main-menu-direct-connect-button'}"
                 TextAlign="Center"
                 StyleIdentifier="mainMenu"/>
+        <Button Name="GoToLobbyButton"
+                Access="Public"
+                Text="{Loc 'main-menu-go-lobby-button'}"
+                TextAlign="Center"
+                StyleIdentifier="mainMenu"/>
         <Button Name="OptionsButton"
                 Access="Public"
                 Text="{Loc 'main-menu-options-button'}"
diff --git a/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs b/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
index d50839d9910..bee8092ea8e 100644
--- a/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
+++ b/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
@@ -20,9 +20,9 @@ public SalvageMagnetBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner
     protected override void Open()
     {
         base.Open();
-        _window = new OfferingWindow();
+
+        _window = this.CreateWindow<OfferingWindow>();
         _window.Title = Loc.GetString("salvage-magnet-window-title");
-        _window.OnClose += Close;
         _window.OpenCenteredLeft();
     }
 
diff --git a/Resources/Locale/en-US/main-menu/main-menu.ftl b/Resources/Locale/en-US/main-menu/main-menu.ftl
index ca81befaafe..d5f0c99295f 100644
--- a/Resources/Locale/en-US/main-menu/main-menu.ftl
+++ b/Resources/Locale/en-US/main-menu/main-menu.ftl
@@ -9,5 +9,6 @@ main-menu-address-label = Server Address:
 main-menu-join-public-server-button = Join Public Server
 main-menu-join-public-server-button-tooltip = Cannot connect to public server with a debug build.
 main-menu-direct-connect-button = Direct Connect
+main-menu-go-lobby-button = Connect & Go to Lobby
 main-menu-options-button = Options
 main-menu-quit-button = Quit

From fcd2e83fcc04f56c757ec28aa8be19bedb9e5814 Mon Sep 17 00:00:00 2001
From: Fansana <fansana95@googlemail.com>
Date: Sun, 15 Dec 2024 22:05:21 +0100
Subject: [PATCH 2/4] fix salvage magnet

---
 Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs  |  3 +--
 .../Salvage/UI/SalvageMagnetBoundUserInterface.cs      | 10 +++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
index e89eab89eec..e2782239bc7 100644
--- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
+++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
@@ -94,8 +94,7 @@ public HumanoidProfileEditor(
             IPlayerManager playerManager,
             IPrototypeManager prototypeManager,
             JobRequirementsManager requirements,
-            MarkingManager markings
-            )
+            MarkingManager markings)
         {
             RobustXamlLoader.Load(this);
             _cfgManager = cfgManager;
diff --git a/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs b/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
index bee8092ea8e..074df059629 100644
--- a/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
+++ b/Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
@@ -21,11 +21,19 @@ protected override void Open()
     {
         base.Open();
 
-        _window = this.CreateWindow<OfferingWindow>();
+        _window = new OfferingWindow();
         _window.Title = Loc.GetString("salvage-magnet-window-title");
+        _window.OnClose += Close;
         _window.OpenCenteredLeft();
     }
 
+    protected override void Dispose(bool disposing)
+    {
+        base.Dispose(disposing);
+        _window?.Dispose();
+        _window = null;
+    }
+
     protected override void UpdateState(BoundUserInterfaceState state)
     {
         base.UpdateState(state);

From cc8105bbade552885776e4c1a3fb07cad3c204d8 Mon Sep 17 00:00:00 2001
From: Fansana <fansana95@googlemail.com>
Date: Sun, 15 Dec 2024 23:23:41 +0100
Subject: [PATCH 3/4] actually fix sliders

---
 .../Lobby/UI/HumanoidProfileEditor.xaml.cs        | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
index e2782239bc7..48e7eaeb6b3 100644
--- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
+++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
@@ -1365,14 +1365,16 @@ private void UpdateHeightWidthSliders()
                 return;
 
             var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
-
-            HeightSlider.MinValue = species.MinHeight;
-            HeightSlider.MaxValue = species.MaxHeight;
-            HeightSlider.SetValueWithoutEvent(Profile?.Height ?? species.DefaultHeight);
+            var width1 = Profile?.Width ?? species.DefaultHeight;
+            var height1 = Profile?.Height ?? species.DefaultHeight;
 
             WidthSlider.MinValue = species.MinWidth;
             WidthSlider.MaxValue = species.MaxWidth;
-            WidthSlider.SetValueWithoutEvent(Profile?.Width ?? species.DefaultWidth);
+            WidthSlider.SetValueWithoutEvent(width1);
+
+            HeightSlider.MinValue = species.MinHeight;
+            HeightSlider.MaxValue = species.MaxHeight;
+            HeightSlider.SetValueWithoutEvent(height1);
 
             var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
             HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));
@@ -1410,9 +1412,6 @@ private void UpdateDimensions(SliderUpdate updateType)
                 if (ratio < 1 / sizeRatio || ratio > sizeRatio)
                     heightValue = widthValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);
 
-            heightValue = Math.Clamp(heightValue, species.MinHeight, species.MaxHeight);
-            widthValue = Math.Clamp(widthValue, species.MinWidth, species.MaxWidth);
-
             HeightSlider.Value = heightValue;
             WidthSlider.Value = widthValue;
 

From ed0f525410d9a409b4e78432e9657b1e6ec536fc Mon Sep 17 00:00:00 2001
From: Fansana <fansana95@googlemail.com>
Date: Sun, 15 Dec 2024 23:26:00 +0100
Subject: [PATCH 4/4] undo change

---
 Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
index 48e7eaeb6b3..f2d2513efab 100644
--- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
+++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
@@ -1412,6 +1412,9 @@ private void UpdateDimensions(SliderUpdate updateType)
                 if (ratio < 1 / sizeRatio || ratio > sizeRatio)
                     heightValue = widthValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);
 
+            heightValue = Math.Clamp(heightValue, species.MinHeight, species.MaxHeight);
+            widthValue = Math.Clamp(widthValue, species.MinWidth, species.MaxWidth);
+
             HeightSlider.Value = heightValue;
             WidthSlider.Value = widthValue;