News UI overhaul and PDA notifications (#19610)
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.CartridgeLoader.Cartridges;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
public sealed partial class NewsReadUi : UIFragment
|
||||
{
|
||||
private NewsReadUiFragment? _fragment;
|
||||
|
||||
public override Control GetUIFragmentRoot()
|
||||
{
|
||||
return _fragment!;
|
||||
}
|
||||
|
||||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
|
||||
{
|
||||
_fragment = new NewsReadUiFragment();
|
||||
|
||||
_fragment.OnNextButtonPressed += () =>
|
||||
{
|
||||
SendNewsReadMessage(NewsReadUiAction.Next, userInterface);
|
||||
};
|
||||
_fragment.OnPrevButtonPressed += () =>
|
||||
{
|
||||
SendNewsReadMessage(NewsReadUiAction.Prev, userInterface);
|
||||
};
|
||||
_fragment.OnNotificationSwithPressed += () =>
|
||||
{
|
||||
SendNewsReadMessage(NewsReadUiAction.NotificationSwith, userInterface);
|
||||
};
|
||||
}
|
||||
|
||||
public override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is NewsReadBoundUserInterfaceState cast)
|
||||
_fragment?.UpdateState(cast.Article, cast.TargetNum, cast.TotalNum, cast.NotificationOn);
|
||||
else if (state is NewsReadEmptyBoundUserInterfaceState empty)
|
||||
_fragment?.UpdateEmptyState(empty.NotificationOn);
|
||||
}
|
||||
|
||||
private void SendNewsReadMessage(NewsReadUiAction action, BoundUserInterface userInterface)
|
||||
{
|
||||
var newsMessage = new NewsReadUiMessageEvent(action);
|
||||
var message = new CartridgeUiMessage(newsMessage);
|
||||
userInterface.SendMessage(message);
|
||||
}
|
||||
}
|
||||
54
Content.Client/CartridgeLoader/Cartridges/NewsReaderUi.cs
Normal file
54
Content.Client/CartridgeLoader/Cartridges/NewsReaderUi.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.CartridgeLoader.Cartridges;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
public sealed partial class NewsReaderUi : UIFragment
|
||||
{
|
||||
private NewsReaderUiFragment? _fragment;
|
||||
|
||||
public override Control GetUIFragmentRoot()
|
||||
{
|
||||
return _fragment!;
|
||||
}
|
||||
|
||||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
|
||||
{
|
||||
_fragment = new NewsReaderUiFragment();
|
||||
|
||||
_fragment.OnNextButtonPressed += () =>
|
||||
{
|
||||
SendNewsReaderMessage(NewsReaderUiAction.Next, userInterface);
|
||||
};
|
||||
_fragment.OnPrevButtonPressed += () =>
|
||||
{
|
||||
SendNewsReaderMessage(NewsReaderUiAction.Prev, userInterface);
|
||||
};
|
||||
_fragment.OnNotificationSwithPressed += () =>
|
||||
{
|
||||
SendNewsReaderMessage(NewsReaderUiAction.NotificationSwitch, userInterface);
|
||||
};
|
||||
}
|
||||
|
||||
public override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NewsReaderBoundUserInterfaceState cast:
|
||||
_fragment?.UpdateState(cast.Article, cast.TargetNum, cast.TotalNum, cast.NotificationOn);
|
||||
break;
|
||||
case NewsReaderEmptyBoundUserInterfaceState empty:
|
||||
_fragment?.UpdateEmptyState(empty.NotificationOn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SendNewsReaderMessage(NewsReaderUiAction action, BoundUserInterface userInterface)
|
||||
{
|
||||
var newsMessage = new NewsReaderUiMessageEvent(action);
|
||||
var message = new CartridgeUiMessage(newsMessage);
|
||||
userInterface.SendMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,30 @@
|
||||
<cartridges:NewsReadUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
|
||||
<cartridges:NewsReaderUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns="https://spacestation14.io" Margin="1 0 2 0">
|
||||
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
xmlns="https://spacestation14.io"
|
||||
Margin="1 0 2 0"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5,5,5,5">
|
||||
<Button
|
||||
Name="Prev"
|
||||
MinWidth="64"
|
||||
Disabled="True"
|
||||
HorizontalAlignment="Left"
|
||||
Text="{Loc 'news-read-ui-past-text'}"
|
||||
Text="{Loc 'news-read-ui-prev-text'}"
|
||||
ToolTip="{Loc 'news-read-ui-prev-tooltip'}"
|
||||
Access="Public"
|
||||
HorizontalExpand="True"/>
|
||||
<Button
|
||||
Name="Next"
|
||||
MinWidth="64"
|
||||
Disabled="True"
|
||||
HorizontalAlignment="Right"
|
||||
Text="{Loc 'news-read-ui-next-text'}" />
|
||||
Text="{Loc 'news-read-ui-next-text'}"
|
||||
ToolTip="{Loc 'news-read-ui-next-tooltip'}"/>
|
||||
</BoxContainer>
|
||||
<controls:StripeBack Name="АrticleNameContainer">
|
||||
<PanelContainer>
|
||||
@@ -46,9 +55,11 @@
|
||||
</PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5,5,5,5">
|
||||
<Button
|
||||
Name="NotificationSwith"
|
||||
Name="NotificationSwitch"
|
||||
ToolTip="{Loc news-reader-ui-mute-tooltip}"
|
||||
MinWidth="20"/>
|
||||
<RichTextLabel Margin="5,2,2,2" Name="ShareTime" VerticalAlignment="Top"/>
|
||||
<customControls:VSeparator Margin="2 0"/>
|
||||
<RichTextLabel Margin="5,2,2,2" Name="Author" VerticalAlignment="Top" HorizontalAlignment="Right"/>
|
||||
</BoxContainer>
|
||||
</cartridges:NewsReadUiFragment>
|
||||
</cartridges:NewsReaderUiFragment>
|
||||
@@ -7,23 +7,20 @@ using Robust.Client.UserInterface.XAML;
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class NewsReadUiFragment : BoxContainer
|
||||
public sealed partial class NewsReaderUiFragment : BoxContainer
|
||||
{
|
||||
public event Action? OnNextButtonPressed;
|
||||
public event Action? OnPrevButtonPressed;
|
||||
|
||||
public event Action? OnNotificationSwithPressed;
|
||||
|
||||
public NewsReadUiFragment()
|
||||
public NewsReaderUiFragment()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
HorizontalExpand = true;
|
||||
VerticalExpand = true;
|
||||
|
||||
Next.OnPressed += _ => OnNextButtonPressed?.Invoke();
|
||||
Prev.OnPressed += _ => OnPrevButtonPressed?.Invoke();
|
||||
NotificationSwith.OnPressed += _ => OnNotificationSwithPressed?.Invoke();
|
||||
NotificationSwitch.OnPressed += _ => OnNotificationSwithPressed?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateState(NewsArticle article, int targetNum, int totalNum, bool notificationOn)
|
||||
@@ -33,17 +30,20 @@ public sealed partial class NewsReadUiFragment : BoxContainer
|
||||
ShareTime.Visible = true;
|
||||
Author.Visible = true;
|
||||
|
||||
PageName.Text = article.Name;
|
||||
PageName.Text = article.Title;
|
||||
PageText.SetMarkup(article.Content);
|
||||
|
||||
PageNum.Text = $"{targetNum}/{totalNum}";
|
||||
|
||||
NotificationSwith.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
|
||||
NotificationSwitch.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
|
||||
|
||||
string shareTime = article.ShareTime.ToString("hh\\:mm\\:ss");
|
||||
string shareTime = article.ShareTime.ToString(@"hh\:mm\:ss");
|
||||
ShareTime.SetMarkup(Loc.GetString("news-read-ui-time-prefix-text") + " " + shareTime);
|
||||
|
||||
Author.SetMarkup(Loc.GetString("news-read-ui-author-prefix") + " " + (article.Author != null ? article.Author : Loc.GetString("news-read-ui-no-author")));
|
||||
|
||||
Prev.Disabled = targetNum <= 1;
|
||||
Next.Disabled = targetNum >= totalNum;
|
||||
}
|
||||
|
||||
public void UpdateEmptyState(bool notificationOn)
|
||||
@@ -55,6 +55,6 @@ public sealed partial class NewsReadUiFragment : BoxContainer
|
||||
|
||||
PageName.Text = Loc.GetString("news-read-ui-not-found-text");
|
||||
|
||||
NotificationSwith.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
|
||||
NotificationSwitch.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user