Skip to content

Commit

Permalink
Merge pull request #411 from Fansana/ui-fixes
Browse files Browse the repository at this point in the history
Salvage Magnet UI and Character Switching Height/Width Bug Fix (#1347)
  • Loading branch information
FoxxoTrystan authored Dec 15, 2024
2 parents 01834f1 + ed0f525 commit 0cb2514
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
37 changes: 22 additions & 15 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public HumanoidProfileEditor(
SaveButton.OnPressed += args => { Save?.Invoke(); };
ResetButton.OnPressed += args =>
{
SetProfile((HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter,
SetProfile(
(HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter,
_preferencesManager.Preferences?.SelectedCharacterIndex);
};

Expand Down Expand Up @@ -192,12 +193,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);
Expand Down Expand Up @@ -490,7 +490,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"));
Expand Down Expand Up @@ -761,11 +761,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);
Expand Down Expand Up @@ -1361,21 +1361,28 @@ private void UpdateSpawnPriorityControls()

private void UpdateHeightWidthSliders()
{
var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
if (Profile is null)
return;

HeightSlider.MinValue = species.MinHeight;
HeightSlider.MaxValue = species.MaxHeight;
HeightSlider.Value = Profile?.Height ?? species.DefaultHeight;
var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();
var width1 = Profile?.Width ?? species.DefaultHeight;
var height1 = Profile?.Height ?? species.DefaultHeight;

WidthSlider.MinValue = species.MinWidth;
WidthSlider.MaxValue = species.MaxWidth;
WidthSlider.Value = 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));

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
Expand All @@ -1387,9 +1394,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);
Expand All @@ -1398,13 +1406,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);

Expand Down
26 changes: 24 additions & 2 deletions Content.Client/MainMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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+))?");
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -197,6 +218,7 @@ private void _setConnectingState(bool state)
{
_isConnecting = state;
_mainMenuControl.DirectConnectButton.Disabled = state;
_mainMenuControl.GoToLobbyButton.Disabled = state;
}
}
}
5 changes: 5 additions & 0 deletions Content.Client/MainMenu/UI/MainMenuControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'}"
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ public SalvageMagnetBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner
protected override void Open()
{
base.Open();

_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);
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/main-menu/main-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0cb2514

Please sign in to comment.