Xaml Rules and Info (#5741)
* XAMLify rules and info * Fix errors * Combine AddSection methods * Readd AddSection
This commit is contained in:
11
Content.Client/Info/Info.xaml
Normal file
11
Content.Client/Info/Info.xaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<ScrollContainer xmlns="https://spacestation14.io"
|
||||
HScrollEnabled="False"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer Name="InfoContainer"
|
||||
Orientation="Vertical"
|
||||
Margin="2 2 0 0"
|
||||
SeparationOverride="10"
|
||||
Access="Public">
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
14
Content.Client/Info/Info.xaml.cs
Normal file
14
Content.Client/Info/Info.xaml.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Info;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class Info : ScrollContainer
|
||||
{
|
||||
public Info()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
11
Content.Client/Info/InfoControlsSection.xaml
Normal file
11
Content.Client/Info/InfoControlsSection.xaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<BoxContainer xmlns="https://spacestation14.io"
|
||||
Orientation="Vertical">
|
||||
<Label Text="{Loc 'ui-info-header-controls'}" StyleClasses="LabelHeading"/>
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
SeparationOverride="5">
|
||||
<Label Text="{Loc 'ui-info-text-controls'}"/>
|
||||
<Button Name="ControlsButton"
|
||||
Text="{Loc 'ui-info-button-controls'}"
|
||||
Access="Public"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
15
Content.Client/Info/InfoControlsSection.xaml.cs
Normal file
15
Content.Client/Info/InfoControlsSection.xaml.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Info;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class InfoControlsSection : BoxContainer
|
||||
{
|
||||
public InfoControlsSection()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
5
Content.Client/Info/InfoSection.xaml
Normal file
5
Content.Client/Info/InfoSection.xaml
Normal file
@@ -0,0 +1,5 @@
|
||||
<BoxContainer xmlns="https://spacestation14.io"
|
||||
Orientation="Vertical">
|
||||
<Label Name="TitleLabel" StyleClasses="LabelHeading"/>
|
||||
<RichTextLabel Name="Content"/>
|
||||
</BoxContainer>
|
||||
23
Content.Client/Info/InfoSection.xaml.cs
Normal file
23
Content.Client/Info/InfoSection.xaml.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Utility.Markup;
|
||||
|
||||
namespace Content.Client.Info;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class InfoSection : BoxContainer
|
||||
{
|
||||
public InfoSection(string title, string text, bool markup = false)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
TitleLabel.Text = title;
|
||||
|
||||
if (markup)
|
||||
Content.SetMessage(Basic.RenderMarkup(text.Trim()));
|
||||
else
|
||||
Content.SetMessage(text);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,9 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Content.Client.EscapeMenu.UI;
|
||||
using Content.Client.Stylesheets;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Utility.Markup;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Info
|
||||
{
|
||||
@@ -33,15 +24,8 @@ namespace Content.Client.Info
|
||||
|
||||
var rootContainer = new TabContainer();
|
||||
|
||||
var rulesList = new ScrollContainer
|
||||
{
|
||||
HScrollEnabled = false
|
||||
};
|
||||
var tutorialList = new ScrollContainer
|
||||
{
|
||||
HScrollEnabled = false
|
||||
};
|
||||
|
||||
var rulesList = new Info();
|
||||
var tutorialList = new Info();
|
||||
|
||||
rootContainer.AddChild(rulesList);
|
||||
rootContainer.AddChild(tutorialList);
|
||||
@@ -57,112 +41,26 @@ namespace Content.Client.Info
|
||||
SetSize = (650, 650);
|
||||
}
|
||||
|
||||
private void PopulateRules(Control rulesList)
|
||||
private void PopulateRules(Info rulesList)
|
||||
{
|
||||
var vBox = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Margin = new Thickness(2, 2, 0, 0)
|
||||
};
|
||||
|
||||
var first = true;
|
||||
|
||||
void AddSection(string title, string path, bool markup = false)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
vBox.AddChild(new Control { MinSize = (0, 10) });
|
||||
}
|
||||
|
||||
first = false;
|
||||
vBox.AddChild(new Label { StyleClasses = { StyleBase.StyleClassLabelHeading }, Text = title });
|
||||
|
||||
var label = new RichTextLabel();
|
||||
var text = _resourceManager.ContentFileReadAllText($"/Server Info/{path}");
|
||||
if (markup)
|
||||
{
|
||||
label.SetMessage(Basic.RenderMarkup(text.Trim()));
|
||||
}
|
||||
else
|
||||
{
|
||||
label.SetMessage(text);
|
||||
}
|
||||
|
||||
vBox.AddChild(label);
|
||||
}
|
||||
|
||||
AddSection(Loc.GetString("ui-info-header-rules"), "Rules.txt", true);
|
||||
|
||||
rulesList.AddChild(vBox);
|
||||
|
||||
AddSection(rulesList, Loc.GetString("ui-info-header-rules"), "Rules.txt", true);
|
||||
}
|
||||
|
||||
private void PopulateTutorial(Control tutorialList)
|
||||
private void PopulateTutorial(Info tutorialList)
|
||||
{
|
||||
Button controlsButton;
|
||||
AddSection(tutorialList, Loc.GetString("ui-info-header-intro"), "Intro.txt");
|
||||
var infoControlSection = new InfoControlsSection();
|
||||
tutorialList.InfoContainer.AddChild(infoControlSection);
|
||||
AddSection(tutorialList, Loc.GetString("ui-info-header-gameplay"), "Gameplay.txt", true);
|
||||
AddSection(tutorialList, Loc.GetString("ui-info-header-sandbox"), "Sandbox.txt", true);
|
||||
|
||||
var vBox = new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
Margin = new Thickness(2, 2, 0, 0)
|
||||
};
|
||||
infoControlSection.ControlsButton.OnPressed += _ => optionsMenu.OpenCentered();
|
||||
}
|
||||
|
||||
var first = true;
|
||||
|
||||
void AddSection(string title, string path, bool markup = false)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
vBox.AddChild(new Control { MinSize = (0, 10) });
|
||||
}
|
||||
|
||||
first = false;
|
||||
vBox.AddChild(new Label { StyleClasses = { StyleBase.StyleClassLabelHeading }, Text = title });
|
||||
|
||||
var label = new RichTextLabel();
|
||||
var text = _resourceManager.ContentFileReadAllText($"/Server Info/{path}");
|
||||
if (markup)
|
||||
{
|
||||
label.SetMessage(Basic.RenderMarkup(text.Trim()));
|
||||
}
|
||||
else
|
||||
{
|
||||
label.SetMessage(text);
|
||||
}
|
||||
|
||||
vBox.AddChild(label);
|
||||
}
|
||||
|
||||
AddSection(Loc.GetString("ui-info-header-intro"), "Intro.txt");
|
||||
|
||||
vBox.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
MinSize = (0, 10),
|
||||
Children =
|
||||
{
|
||||
new Label {StyleClasses = { StyleBase.StyleClassLabelHeading }, Text = Loc.GetString("ui-info-header-controls")},
|
||||
}
|
||||
});
|
||||
|
||||
vBox.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 5,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = Loc.GetString("ui-info-text-controls")},
|
||||
(controlsButton = new Button {Text = Loc.GetString("ui-info-button-controls")})
|
||||
}
|
||||
});
|
||||
|
||||
AddSection(Loc.GetString("ui-info-header-gameplay"), "Gameplay.txt", true);
|
||||
AddSection(Loc.GetString("ui-info-header-sandbox"), "Sandbox.txt", true);
|
||||
|
||||
tutorialList.AddChild(vBox);
|
||||
|
||||
controlsButton.OnPressed += _ =>
|
||||
optionsMenu.OpenCentered();
|
||||
private void AddSection(Info info, string title, string path, bool markup = false)
|
||||
{
|
||||
info.InfoContainer.AddChild(new InfoSection(title,
|
||||
_resourceManager.ContentFileReadAllText($"/Server Info/{path}"), markup));
|
||||
}
|
||||
|
||||
protected override void Opened()
|
||||
@@ -171,19 +69,5 @@ namespace Content.Client.Info
|
||||
|
||||
_rulesManager.SaveLastReadTime();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Lines(TextReader reader)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
if (line == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user