From c4c3e4283ae077fd0f55e4cce31710f31de046f7 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 001/471] Salvage Magnet UI and Character Switching Height/Width Bug Fix (#1347) # Description i fixed it also added a button "Connect & Go to Lobby" for people testing lobby stuff! Resolves #1131 --- # 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> --- .../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 f23fd6b4a0..ce14882d16 100644 --- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs @@ -95,7 +95,8 @@ public HumanoidProfileEditor( IPlayerManager playerManager, IPrototypeManager prototypeManager, JobRequirementsManager requirements, - MarkingManager markings) + MarkingManager markings + ) { RobustXamlLoader.Load(this); _cfgManager = cfgManager; @@ -114,7 +115,8 @@ public HumanoidProfileEditor( SaveButton.OnPressed += args => { Save?.Invoke(); }; ResetButton.OnPressed += args => { - SetProfile((HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter, + SetProfile( + (HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter, _preferencesManager.Preferences?.SelectedCharacterIndex); }; @@ -193,12 +195,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); @@ -492,7 +493,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")); @@ -763,11 +764,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(job.Icon); @@ -1349,21 +1350,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 @@ -1375,9 +1381,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); @@ -1386,13 +1393,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 43c5bfe567..58d94adf22 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; @@ -25,9 +26,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+))?"); @@ -38,15 +41,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; + } + } + /// protected override void Shutdown() { @@ -77,12 +92,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); } @@ -185,6 +206,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 d6c3f4b941..e0242300fc 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"/> + + + + + + + + diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs new file mode 100644 index 0000000000..2e44b820df --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs @@ -0,0 +1,61 @@ +using Content.Shared.Silicons.Laws; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.Utility; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +[GenerateTypedNameReferences] +public sealed partial class SiliconLawContainer : BoxContainer +{ + public const string StyleClassSiliconLawPositionLabel = "SiliconLawPositionLabel"; + + public static readonly string CorruptedString = + Loc.GetString("ion-storm-law-scrambled-number", ("length", 5)); + + private SiliconLaw? _law; + + public event Action? MoveLawUp; + public event Action? MoveLawDown; + public event Action? DeleteAction; + + + public SiliconLawContainer() + { + RobustXamlLoader.Load(this); + + MoveUp.OnPressed += _ => MoveLawUp?.Invoke(_law!); + MoveDown.OnPressed += _ => MoveLawDown?.Invoke(_law!); + Corrupted.OnPressed += _ => + { + if (Corrupted.Pressed) + { + _law!.LawIdentifierOverride = CorruptedString; + } + else + { + _law!.LawIdentifierOverride = null; + } + }; + + LawContent.OnTextChanged += _ => _law!.LawString = Rope.Collapse(LawContent.TextRope).Trim(); + LawContent.Placeholder = new Rope.Leaf(Loc.GetString("silicon-law-ui-placeholder")); + Delete.OnPressed += _ => DeleteAction?.Invoke(_law!); + } + + public void SetLaw(SiliconLaw law) + { + _law = law; + LawContent.TextRope = new Rope.Leaf(Loc.GetString(law.LawString)); + PositionText.Text = law.Order.ToString(); + if (!string.IsNullOrEmpty(law.LawIdentifierOverride)) + { + Corrupted.Pressed = true; + } + else + { + Corrupted.Pressed = false; + } + } +} diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs new file mode 100644 index 0000000000..a4d59d1f31 --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs @@ -0,0 +1,38 @@ +using Content.Client.Eui; +using Content.Shared.Eui; +using Content.Shared.Silicons.Laws; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +public sealed class SiliconLawEui : BaseEui +{ + public readonly EntityManager _entityManager = default!; + + private SiliconLawUi _siliconLawUi; + private EntityUid _target; + + public SiliconLawEui() + { + _entityManager = IoCManager.Resolve(); + + _siliconLawUi = new SiliconLawUi(); + _siliconLawUi.OnClose += () => SendMessage(new CloseEuiMessage()); + _siliconLawUi.Save.OnPressed += _ => SendMessage(new SiliconLawsSaveMessage(_siliconLawUi.GetLaws(), _entityManager.GetNetEntity(_target))); + } + + public override void HandleState(EuiStateBase state) + { + if (state is not SiliconLawsEuiState s) + { + return; + } + + _target = _entityManager.GetEntity(s.Target); + _siliconLawUi.SetLaws(s.Laws); + } + + public override void Opened() + { + _siliconLawUi.OpenCentered(); + } +} diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml new file mode 100644 index 0000000000..19dcbac620 --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml @@ -0,0 +1,22 @@ + + + this shit does not layout properly unless I put the horizontal boxcontainer inside of a vertical one + ???? + + + + + + + + + + + + + diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs new file mode 100644 index 0000000000..372961ea9a --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs @@ -0,0 +1,89 @@ +using System.Linq; +using Content.Client.UserInterface.Controls; +using Content.Shared.FixedPoint; +using Content.Shared.Silicons.Laws; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.XAML; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +[GenerateTypedNameReferences] +public sealed partial class SiliconLawUi : FancyWindow +{ + private List _laws = new(); + + public SiliconLawUi() + { + RobustXamlLoader.Load(this); + NewLawButton.OnPressed += _ => AddNewLaw(); + } + + private void AddNewLaw() + { + var newLaw = new SiliconLaw(); + newLaw.Order = FixedPoint2.New(_laws.Count + 1); + _laws.Add(newLaw); + SetLaws(_laws); + } + + public void SetLaws(List sLaws) + { + _laws = sLaws; + LawContainer.RemoveAllChildren(); + foreach (var law in sLaws.OrderBy(l => l.Order)) + { + var lawControl = new SiliconLawContainer(); + lawControl.SetLaw(law); + lawControl.MoveLawDown += MoveLawDown; + lawControl.MoveLawUp += MoveLawUp; + lawControl.DeleteAction += DeleteLaw; + + LawContainer.AddChild(lawControl); + } + } + + public void DeleteLaw(SiliconLaw law) + { + _laws.Remove(law); + SetLaws(_laws); + } + + public void MoveLawDown(SiliconLaw law) + { + if (_laws.Count == 0) + { + return; + } + + var index = _laws.IndexOf(law); + if (index == -1) + { + return; + } + + _laws[index].Order += FixedPoint2.New(1); + SetLaws(_laws); + } + + public void MoveLawUp(SiliconLaw law) + { + if (_laws.Count == 0) + { + return; + } + + var index = _laws.IndexOf(law); + if (index == -1) + { + return; + } + + _laws[index].Order += FixedPoint2.New(-1); + SetLaws(_laws); + } + + public List GetLaws() + { + return _laws; + } +} diff --git a/Content.Client/Stylesheets/StyleNano.cs b/Content.Client/Stylesheets/StyleNano.cs index 67b81c1145..aa170c9cf5 100644 --- a/Content.Client/Stylesheets/StyleNano.cs +++ b/Content.Client/Stylesheets/StyleNano.cs @@ -4,6 +4,7 @@ using Content.Client.Examine; using Content.Client.PDA; using Content.Client.Resources; +using Content.Client.Silicons.Laws.SiliconLawEditUi; using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls.FancyTree; using Content.Client.Verbs.UI; @@ -1626,6 +1627,10 @@ public StyleNano(IResourceCache resCache) : base(resCache) { BackgroundColor = FancyTreeSelectedRowColor, }), + + // Silicon law edit ui + Element