]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Login tips (#22234)
authorVigers Ray <60344369+VigersRay@users.noreply.github.com>
Sat, 6 Jan 2024 06:06:49 +0000 (09:06 +0300)
committerGitHub <noreply@github.com>
Sat, 6 Jan 2024 06:06:49 +0000 (17:06 +1100)
* Init coomit

* meh

* okay

* Revert "okay"

This reverts commit bb638aa4baa8dbd0e285c3435aabf83171a4806a.

* enable-d

* Update Content.Client/Launcher/LauncherConnectingGui.xaml.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>
* review

---------

Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Launcher/LauncherConnecting.cs
Content.Client/Launcher/LauncherConnectingGui.xaml
Content.Client/Launcher/LauncherConnectingGui.xaml.cs
Content.Shared/CCVar/CCVars.cs
Resources/Locale/en-US/launcher/launcher-connecting.ftl

index 101a63a800d81d35d0c2a848d01479a7dc3cbe49..9625f9e31c52d44bca797cb31453ca072b01b902 100644 (file)
@@ -1,9 +1,12 @@
 using System;
 using Robust.Client;
 using Robust.Client.UserInterface;
+using Robust.Shared.Configuration;
 using Robust.Shared.IoC;
 using Robust.Shared.Log;
 using Robust.Shared.Network;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
 
 namespace Content.Client.Launcher
 {
@@ -13,6 +16,9 @@ namespace Content.Client.Launcher
         [Dependency] private readonly IClientNetManager _clientNetManager = default!;
         [Dependency] private readonly IGameController _gameController = default!;
         [Dependency] private readonly IBaseClient _baseClient = default!;
+        [Dependency] private readonly IRobustRandom _random = default!;
+        [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+        [Dependency] private readonly IConfigurationManager _cfg = default!;
 
         private LauncherConnectingGui? _control;
 
@@ -51,7 +57,7 @@ namespace Content.Client.Launcher
 
         protected override void Startup()
         {
-            _control = new LauncherConnectingGui(this);
+            _control = new LauncherConnectingGui(this, _random, _prototypeManager, _cfg);
 
             _userInterfaceManager.StateRoot.AddChild(_control);
 
index 430ae58d6e9a8cbb9fed816557956a392c632795..083e4ca8717a90f9234174aa291eae3279e5b3e1 100644 (file)
             </BoxContainer>
         </BoxContainer>
     </Control>
+    <!-- Bottom window for tips -->
+    <PanelContainer Name="LoginTips" StyleClasses="AngleRect" Margin="0 10" MaxWidth="600" VerticalExpand="True" VerticalAlignment="Bottom">
+        <BoxContainer Orientation="Vertical" VerticalExpand="True">
+            <controls:StripeBack>
+                <BoxContainer Orientation="Horizontal" HorizontalAlignment="Center">
+                    <Label Name="LoginTipTitle" Text="Tip" StyleClasses="LabelHeading" Align="Center"/>
+                </BoxContainer>
+            </controls:StripeBack>
+            <BoxContainer Orientation="Vertical" Margin="5 5 5 5" >
+                <RichTextLabel Name="LoginTip" VerticalExpand="True" />
+            </BoxContainer>
+        </BoxContainer>
+    </PanelContainer>
 </Control>
index 8a34da6898e127ed05f138d14ba83e1716763eb1..79fba7c285dff7e1498234a0f2b81eeb6e3d310d 100644 (file)
@@ -1,12 +1,18 @@
+using System.Linq;
 using Content.Client.Stylesheets;
+using Content.Shared.CCVar;
+using Content.Shared.Dataset;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Configuration;
 using Robust.Shared.IoC;
 using Robust.Shared.Timing;
 using Robust.Shared.Localization;
 using Robust.Shared.Network;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
 
 namespace Content.Client.Launcher
 {
@@ -15,11 +21,19 @@ namespace Content.Client.Launcher
     {
         private const float RedialWaitTimeSeconds = 15f;
         private readonly LauncherConnecting _state;
+        private readonly IRobustRandom _random;
+        private readonly IPrototypeManager _prototype;
+        private readonly IConfigurationManager _cfg;
+
         private float _redialWaitTime = RedialWaitTimeSeconds;
 
-        public LauncherConnectingGui(LauncherConnecting state)
+        public LauncherConnectingGui(LauncherConnecting state, IRobustRandom random,
+            IPrototypeManager prototype, IConfigurationManager config)
         {
             _state = state;
+            _random = random;
+            _prototype = prototype;
+            _cfg = config;
 
             RobustXamlLoader.Load(this);
 
@@ -27,6 +41,7 @@ namespace Content.Client.Launcher
 
             Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
 
+            ChangeLoginTip();
             ReconnectButton.OnPressed += _ => _state.RetryConnect();
             // Redial shouldn't fail, but if it does, try a reconnect (maybe we're being run from debug)
             RedialButton.OnPressed += _ =>
@@ -67,6 +82,29 @@ namespace Content.Client.Launcher
             ReconnectButton.Visible = !redialFlag;
         }
 
+        private void ChangeLoginTip()
+        {
+            var tipsDataset = _cfg.GetCVar(CCVars.LoginTipsDataset);
+            var loginTipsEnabled = _prototype.TryIndex<DatasetPrototype>(tipsDataset, out var tips);
+
+            LoginTips.Visible = loginTipsEnabled;
+            if (!loginTipsEnabled)
+            {
+                return;
+            }
+
+            var tipList = tips!.Values;
+
+            if (tipList.Count == 0)
+                return;
+
+            var randomIndex = _random.Next(tipList.Count);
+            var tip = tipList[randomIndex];
+            LoginTip.SetMessage(tip);
+
+            LoginTipTitle.Text = Loc.GetString("connecting-window-tip", ("numberTip", randomIndex));
+        }
+
         protected override void FrameUpdate(FrameEventArgs args)
         {
             base.FrameUpdate(args);
index a65bf1a420a8fcdc1131dc4f055a44e045b4234b..5a315f70557c199410df90cec1fd79af40b79931 100644 (file)
@@ -352,7 +352,7 @@ namespace Content.Shared.CCVar
             CVarDef.Create("game.round_restart_time", 120f, CVar.SERVERONLY);
 
         /// <summary>
-        /// The prototype to use for secret weights. 
+        /// The prototype to use for secret weights.
         /// </summary>
         public static readonly CVarDef<string> SecretWeightPrototype =
             CVarDef.Create("game.secret_weight_prototype", "Secret", CVar.SERVERONLY);
@@ -504,6 +504,9 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<float> TipFrequencyInRound =
             CVarDef.Create("tips.in_game_frequency", 60f * 60);
 
+        public static readonly CVarDef<string> LoginTipsDataset =
+            CVarDef.Create("tips.login_dataset", "Tips");
+
         /*
          * Console
          */
@@ -813,7 +816,7 @@ namespace Content.Shared.CCVar
 
         /// <summary>
         ///     The threshold of minutes to appear as a "new player" in the ahelp menu
-        ///     If 0, appearing as a new player is disabled. 
+        ///     If 0, appearing as a new player is disabled.
         /// </summary>
         public static readonly CVarDef<int> NewPlayerThreshold =
             CVarDef.Create("admin.new_player_threshold", 0, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
index c4fb51d266becbddd70223e61d8bb6c8f061320a..f9dff0c46a65d1d763668910f91b6eb57a21bada 100644 (file)
@@ -9,6 +9,7 @@ connecting-redial-wait = Please wait: { TOSTRING($time, "G3") }
 connecting-in-progress = Connecting to server...
 connecting-disconnected = Disconnected from server:
 connecting-tip = Don't die!
+connecting-window-tip = Tip { $numberTip }
 connecting-version = ver 0.1
 connecting-fail-reason = Failed to connect to server:
                          { $reason }