MainMenuControl to XAML (#4642)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Client.Changelog;
|
||||
using Content.Client.EscapeMenu.UI;
|
||||
using Content.Client.Parallax;
|
||||
using Content.Client.MainMenu.UI;
|
||||
using Robust.Client;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -14,7 +13,6 @@ using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
using UsernameHelpers = Robust.Shared.AuthLib.UsernameHelpers;
|
||||
|
||||
namespace Content.Client.MainMenu
|
||||
@@ -196,136 +194,5 @@ namespace Content.Client.MainMenu
|
||||
_mainMenuControl.JoinPublicServerButton.Disabled = state;
|
||||
#endif
|
||||
}
|
||||
|
||||
private sealed class MainMenuControl : Control
|
||||
{
|
||||
private readonly IResourceCache _resourceCache;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
|
||||
public LineEdit UserNameBox { get; }
|
||||
public Button JoinPublicServerButton { get; }
|
||||
public LineEdit AddressBox { get; }
|
||||
public Button DirectConnectButton { get; }
|
||||
public Button OptionsButton { get; }
|
||||
public Button QuitButton { get; }
|
||||
public Label VersionLabel { get; }
|
||||
|
||||
public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
|
||||
{
|
||||
_resourceCache = resCache;
|
||||
_configurationManager = configMan;
|
||||
|
||||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
AddChild(new ParallaxControl());
|
||||
|
||||
var layout = new LayoutContainer();
|
||||
AddChild(layout);
|
||||
|
||||
var vBox = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
StyleIdentifier = "mainMenuVBox"
|
||||
};
|
||||
|
||||
layout.AddChild(vBox);
|
||||
LayoutContainer.SetAnchorPreset(vBox, LayoutContainer.LayoutPreset.TopRight);
|
||||
LayoutContainer.SetMarginRight(vBox, -25);
|
||||
LayoutContainer.SetMarginTop(vBox, 30);
|
||||
LayoutContainer.SetGrowHorizontal(vBox, LayoutContainer.GrowDirection.Begin);
|
||||
|
||||
var logoTexture = _resourceCache.GetResource<TextureResource>("/Textures/Logo/logo.png");
|
||||
var logo = new TextureRect
|
||||
{
|
||||
Texture = logoTexture,
|
||||
Stretch = TextureRect.StretchMode.KeepCentered,
|
||||
};
|
||||
vBox.AddChild(logo);
|
||||
|
||||
var userNameHBox = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 4
|
||||
};
|
||||
vBox.AddChild(userNameHBox);
|
||||
userNameHBox.AddChild(new Label {Text = Loc.GetString("main-menu-username-label") });
|
||||
|
||||
var currentUserName = _configurationManager.GetCVar(CVars.PlayerName);
|
||||
UserNameBox = new LineEdit
|
||||
{
|
||||
Text = currentUserName, PlaceHolder = Loc.GetString("main-menu-username-text"),
|
||||
HorizontalExpand = true
|
||||
};
|
||||
|
||||
userNameHBox.AddChild(UserNameBox);
|
||||
|
||||
JoinPublicServerButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("main-menu-join-public-server-button"),
|
||||
StyleIdentifier = "mainMenu",
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
#if !FULL_RELEASE
|
||||
Disabled = true,
|
||||
ToolTip = Loc.GetString("main-menu-join-public-server-button-tooltip")
|
||||
#endif
|
||||
};
|
||||
|
||||
vBox.AddChild(JoinPublicServerButton);
|
||||
|
||||
// Separator.
|
||||
vBox.AddChild(new Control {MinSize = (0, 2)});
|
||||
|
||||
AddressBox = new LineEdit
|
||||
{
|
||||
Text = "localhost",
|
||||
PlaceHolder = "server address:port",
|
||||
HorizontalExpand = true
|
||||
};
|
||||
|
||||
vBox.AddChild(AddressBox);
|
||||
|
||||
DirectConnectButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("main-menu-direct-connect-button"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
StyleIdentifier = "mainMenu",
|
||||
};
|
||||
|
||||
vBox.AddChild(DirectConnectButton);
|
||||
|
||||
// Separator.
|
||||
vBox.AddChild(new Control {MinSize = (0, 2)});
|
||||
|
||||
OptionsButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("main-menu-options-button"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
StyleIdentifier = "mainMenu",
|
||||
};
|
||||
|
||||
vBox.AddChild(OptionsButton);
|
||||
|
||||
QuitButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("main-menu-quit-button"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
StyleIdentifier = "mainMenu",
|
||||
};
|
||||
|
||||
vBox.AddChild(QuitButton);
|
||||
|
||||
vBox.AddChild(new ChangelogButton());
|
||||
|
||||
VersionLabel = new Label
|
||||
{
|
||||
Text = "v0.1"
|
||||
};
|
||||
|
||||
LayoutContainer.SetAnchorPreset(VersionLabel, LayoutContainer.LayoutPreset.BottomRight);
|
||||
LayoutContainer.SetGrowHorizontal(VersionLabel, LayoutContainer.GrowDirection.Begin);
|
||||
LayoutContainer.SetGrowVertical(VersionLabel, LayoutContainer.GrowDirection.Begin);
|
||||
layout.AddChild(VersionLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
Content.Client/MainMenu/UI/MainMenuControl.xaml
Normal file
44
Content.Client/MainMenu/UI/MainMenuControl.xaml
Normal file
@@ -0,0 +1,44 @@
|
||||
<Control xmlns="https://spacestation14.io"
|
||||
xmlns:pllax="clr-namespace:Content.Client.Parallax"
|
||||
xmlns:clog="clr-namespace:Content.Client.Changelog">
|
||||
<pllax:ParallaxControl />
|
||||
<LayoutContainer>
|
||||
<BoxContainer Name="VBox"
|
||||
Orientation="Vertical"
|
||||
StyleIdentifier="mainMenuVBox">
|
||||
<TextureRect Name="Logo"
|
||||
Stretch="KeepCentered" />
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
SeparationOverride="4">
|
||||
<Label Text="{Loc 'main-menu-username-label'}" />
|
||||
<LineEdit Name="UsernameBoxProtected"
|
||||
PlaceHolder="{Loc 'main-menu-username-text'}"
|
||||
HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<Button Name="JoinPublicServerButtonProtected"
|
||||
Text="{Loc 'main-menu-join-public-server-button'}"
|
||||
StyleIdentifier="mainMenu"
|
||||
TextAlign="Center" />
|
||||
<Control MinSize="0 2" />
|
||||
<LineEdit Name="AddressBoxProtected"
|
||||
Text="localhost"
|
||||
PlaceHolder="server address:port"
|
||||
HorizontalExpand="True" />
|
||||
<Button Name="DirectConnectButtonProtected"
|
||||
Text="{Loc 'main-menu-direct-connect-button'}"
|
||||
TextAlign="Center"
|
||||
StyleIdentifier="mainMenu" />
|
||||
<Control MinSize="0 2" />
|
||||
<Button Name="OptionsButtonProtected"
|
||||
Text="{Loc 'main-menu-options-button'}"
|
||||
TextAlign="Center"
|
||||
StyleIdentifier="mainMenu" />
|
||||
<Button Name="QuitButtonProtected"
|
||||
Text="{Loc 'main-menu-quit-button'}"
|
||||
TextAlign="Center"
|
||||
StyleIdentifier="mainMenu" />
|
||||
<clog:ChangelogButton />
|
||||
</BoxContainer>
|
||||
<Label Name="VersionLabel" Text="v0.1" />
|
||||
</LayoutContainer>
|
||||
</Control>
|
||||
51
Content.Client/MainMenu/UI/MainMenuControl.xaml.cs
Normal file
51
Content.Client/MainMenu/UI/MainMenuControl.xaml.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Client.Changelog;
|
||||
using Content.Client.Parallax;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.MainMenu.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class MainMenuControl : Control
|
||||
{
|
||||
public LineEdit UserNameBox => UsernameBoxProtected;
|
||||
public Button JoinPublicServerButton => JoinPublicServerButtonProtected;
|
||||
public LineEdit AddressBox => AddressBoxProtected;
|
||||
public Button DirectConnectButton => DirectConnectButtonProtected;
|
||||
public Button OptionsButton => OptionsButtonProtected;
|
||||
public Button QuitButton => QuitButtonProtected;
|
||||
|
||||
public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.TopRight);
|
||||
LayoutContainer.SetMarginRight(VBox, -25);
|
||||
LayoutContainer.SetMarginTop(VBox, 30);
|
||||
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Begin);
|
||||
|
||||
var logoTexture = resCache.GetResource<TextureResource>("/Textures/Logo/logo.png");
|
||||
Logo.Texture = logoTexture;
|
||||
|
||||
var currentUserName = configMan.GetCVar(CVars.PlayerName);
|
||||
UserNameBox.Text = currentUserName;
|
||||
|
||||
#if !FULL_RELEASE
|
||||
JoinPublicServerButton.Disabled = true;
|
||||
JoinPublicServerButton.ToolTip = Loc.GetString("main-menu-join-public-server-button-tooltip");
|
||||
#endif
|
||||
|
||||
LayoutContainer.SetAnchorPreset(VersionLabel, LayoutContainer.LayoutPreset.BottomRight);
|
||||
LayoutContainer.SetGrowHorizontal(VersionLabel, LayoutContainer.GrowDirection.Begin);
|
||||
LayoutContainer.SetGrowVertical(VersionLabel, LayoutContainer.GrowDirection.Begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user