convert News read tab to PDA Cartridge (#18368)
* Add Console, PDA news tab, and ringstone popup * Add English localization * Add mass-media console board to Advanced Entertainment resrarch * Fix misprint * Deleting unused libraries * Fix round restart problem * Fixing restart problem * Just another fix * Сode optimization * Code optimization * Convert News read tab to cartridge Convert the News read tab into a cartridge, and fix a couple of bugs * Just another fix * Some updates * More fixing!! Fix cooldown, add author label to read menu * Again, fix cooldown bug * Some minor changes * Revert "Some minor changes" This reverts commit 470c8d727629ac79994f70e56162adae8659e944. * Some minor updates
This commit is contained in:
50
Content.Client/CartridgeLoader/Cartridges/NewsReadUi.cs
Normal file
50
Content.Client/CartridgeLoader/Cartridges/NewsReadUi.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<cartridges:NewsReadUiFragment 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">
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5,5,5,5">
|
||||
<Button
|
||||
Name="Prev"
|
||||
MinWidth="64"
|
||||
HorizontalAlignment="Left"
|
||||
Text="{Loc 'news-read-ui-past-text'}"
|
||||
Access="Public"
|
||||
HorizontalExpand="True"/>
|
||||
<Button
|
||||
Name="Next"
|
||||
MinWidth="64"
|
||||
HorizontalAlignment="Right"
|
||||
Text="{Loc 'news-read-ui-next-text'}" />
|
||||
</BoxContainer>
|
||||
<controls:StripeBack Name="АrticleNameContainer">
|
||||
<PanelContainer>
|
||||
<Label Name="PageNum" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,0,0"/>
|
||||
<Label Name="PageName" Align="Center"/>
|
||||
</PanelContainer>
|
||||
</controls:StripeBack>
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#80808005" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<ScrollContainer
|
||||
Name="PageTextScroll"
|
||||
HScrollEnabled="False"
|
||||
HorizontalExpand="True"
|
||||
MinSize="0 0"
|
||||
SizeFlagsStretchRatio="2"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer
|
||||
Name="PageTextContainer"
|
||||
MinSize="0 0"
|
||||
Orientation="Vertical"
|
||||
SizeFlagsStretchRatio="2"
|
||||
VerticalExpand="True">
|
||||
</BoxContainer>
|
||||
<RichTextLabel Margin="8,8,8,8" Name="PageText" VerticalAlignment="Top"/>
|
||||
</ScrollContainer>
|
||||
</PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5,5,5,5">
|
||||
<Button
|
||||
Name="NotificationSwith"
|
||||
MinWidth="20"/>
|
||||
<RichTextLabel Margin="5,2,2,2" Name="ShareTime" VerticalAlignment="Top"/>
|
||||
<RichTextLabel Margin="5,2,2,2" Name="Author" VerticalAlignment="Top" HorizontalAlignment="Right"/>
|
||||
</BoxContainer>
|
||||
</cartridges:NewsReadUiFragment>
|
||||
@@ -0,0 +1,60 @@
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.MassMedia.Systems;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.CartridgeLoader.Cartridges;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class NewsReadUiFragment : BoxContainer
|
||||
{
|
||||
public event Action? OnNextButtonPressed;
|
||||
public event Action? OnPrevButtonPressed;
|
||||
|
||||
public event Action? OnNotificationSwithPressed;
|
||||
|
||||
public NewsReadUiFragment()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
HorizontalExpand = true;
|
||||
VerticalExpand = true;
|
||||
|
||||
Next.OnPressed += _ => OnNextButtonPressed?.Invoke();
|
||||
Prev.OnPressed += _ => OnPrevButtonPressed?.Invoke();
|
||||
NotificationSwith.OnPressed += _ => OnNotificationSwithPressed?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateState(NewsArticle article, int targetNum, int totalNum, bool notificationOn)
|
||||
{
|
||||
PageNum.Visible = true;
|
||||
PageText.Visible = true;
|
||||
ShareTime.Visible = true;
|
||||
Author.Visible = true;
|
||||
|
||||
PageName.Text = article.Name;
|
||||
PageText.SetMarkup(article.Content);
|
||||
|
||||
PageNum.Text = $"{targetNum}/{totalNum}";
|
||||
|
||||
NotificationSwith.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
public void UpdateEmptyState(bool notificationOn)
|
||||
{
|
||||
PageNum.Visible = false;
|
||||
PageText.Visible = false;
|
||||
ShareTime.Visible = false;
|
||||
Author.Visible = false;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<cartridges:NotekeeperUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
|
||||
<cartridges:NotekeeperUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
|
||||
xmlns="https://spacestation14.io" Margin="1 0 2 0">
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
||||
|
||||
Reference in New Issue
Block a user