Launcher info links. (#12781)

This commit is contained in:
Pieter-Jan Briers
2022-12-03 02:23:43 +01:00
committed by GitHub
parent 083ef009d6
commit a6045e4538
12 changed files with 147 additions and 36 deletions

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Content.Client.Links;
using Content.Client.Stylesheets;
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
@@ -68,7 +67,8 @@ namespace Content.Client.Credits
// Do not show "become a patron" button on Steam builds
// since Patreon violates Valve's rules about alternative storefronts.
if (!_cfg.GetCVar(CCVars.BrandingSteam))
var linkPatreon = _cfg.GetCVar(CCVars.InfoLinksPatreon);
if (!_cfg.GetCVar(CCVars.BrandingSteam) && linkPatreon != "")
{
Button patronButton;
patronsContainer.AddChild(patronButton = new Button
@@ -78,7 +78,7 @@ namespace Content.Client.Credits
});
patronButton.OnPressed +=
_ => IoCManager.Resolve<IUriOpener>().OpenUri(UILinks.Patreon);
_ => IoCManager.Resolve<IUriOpener>().OpenUri(linkPatreon);
}
var first = true;
@@ -158,8 +158,13 @@ namespace Content.Client.Credits
AddSection(Loc.GetString("credits-window-original-remake-team-section-title"), "OriginalRemake.txt");
AddSection(Loc.GetString("credits-window-special-thanks-section-title"), "SpecialThanks.txt", true);
var linkGithub = _cfg.GetCVar(CCVars.InfoLinksGithub);
contributeButton.OnPressed += _ =>
IoCManager.Resolve<IUriOpener>().OpenUri(UILinks.GitHub);
IoCManager.Resolve<IUriOpener>().OpenUri(linkGithub);
if (linkGithub == "")
contributeButton.Visible = false;
}
private sealed class PatronEntry

View File

@@ -1,8 +1,9 @@
using Content.Client.Changelog;
using Content.Client.Credits;
using Content.Client.Links;
using Content.Shared.CCVar;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
@@ -19,13 +20,18 @@ namespace Content.Client.Info
AddChild(buttons);
var uriOpener = IoCManager.Resolve<IUriOpener>();
var cfg = IoCManager.Resolve<IConfigurationManager>();
var reportButton = new Button {Text = Loc.GetString("server-info-report-button")};
reportButton.OnPressed += args => uriOpener.OpenUri(UILinks.BugReport);
var bugReport = cfg.GetCVar(CCVars.InfoLinksBugReport);
if (bugReport != "")
{
var reportButton = new Button {Text = Loc.GetString("server-info-report-button")};
reportButton.OnPressed += args => uriOpener.OpenUri(bugReport);
buttons.AddChild(reportButton);
}
var creditsButton = new Button {Text = Loc.GetString("server-info-credits-button")};
creditsButton.OnPressed += args => new CreditsWindow().Open();
buttons.AddChild(reportButton);
buttons.AddChild(creditsButton);
}
}

View File

@@ -1,9 +1,10 @@
using Content.Client.Changelog;
using Content.Client.Credits;
using Content.Client.Links;
using Content.Client.UserInterface.Systems.EscapeMenu;
using Content.Shared.CCVar;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
@@ -21,25 +22,31 @@ namespace Content.Client.Info
AddChild(buttons);
var uriOpener = IoCManager.Resolve<IUriOpener>();
var cfg = IoCManager.Resolve<IConfigurationManager>();
var rulesButton = new Button() {Text = Loc.GetString("server-info-rules-button")};
rulesButton.OnPressed += args => new RulesAndInfoWindow().Open();
buttons.AddChild(rulesButton);
var discordButton = new Button {Text = Loc.GetString("server-info-discord-button")};
discordButton.OnPressed += args => uriOpener.OpenUri(UILinks.Discord);
AddInfoButton("server-info-discord-button", CCVars.InfoLinksDiscord);
AddInfoButton("server-info-website-button", CCVars.InfoLinksWebsite);
AddInfoButton("server-info-wiki-button", CCVars.InfoLinksWiki);
AddInfoButton("server-info-forum-button", CCVars.InfoLinksForum);
var websiteButton = new Button {Text = Loc.GetString("server-info-website-button")};
websiteButton.OnPressed += args => uriOpener.OpenUri(UILinks.Website);
var wikiButton = new Button {Text = Loc.GetString("server-info-wiki-button")};
wikiButton.OnPressed += args => uriOpener.OpenUri(UILinks.Wiki);
var changelogButton = new ChangelogButton();
changelogButton.OnPressed += args => UserInterfaceManager.GetUIController<ChangelogUIController>().ToggleWindow();
buttons.AddChild(changelogButton);
buttons.AddChild(rulesButton);
buttons.AddChild(discordButton);
buttons.AddChild(websiteButton);
buttons.AddChild(wikiButton);
void AddInfoButton(string loc, CVarDef<string> cVar)
{
var link = cfg.GetCVar(cVar);
if (link == "")
return;
var button = new Button { Text = Loc.GetString(loc) };
button.OnPressed += _ => uriOpener.OpenUri(link);
buttons.AddChild(button);
}
}
}
}

View File

@@ -1,6 +1,5 @@
using Content.Client.Changelog;
using Content.Client.Credits;
using Content.Client.Links;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;

View File

@@ -1,13 +0,0 @@
namespace Content.Client.Links
{
public static class UILinks
{
public const string GitHub = "https://github.com/space-wizards/space-station-14/";
public const string Patreon = "https://www.patreon.com/spacestation14";
public const string Discord = "https://discord.ss14.io/";
public const string BugReport = "https://github.com/space-wizards/space-station-14/issues/new/choose";
public const string Website = "https://spacestation14.io";
public const string Wiki = "https://wiki.spacestation14.io";
}
}

View File

@@ -1,13 +1,14 @@
using Content.Client.Gameplay;
using Content.Client.Info;
using Content.Client.Links;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Info;
using Content.Shared.CCVar;
using JetBrains.Annotations;
using Robust.Client.Console;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Configuration;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Utility;
@@ -20,6 +21,7 @@ public sealed class EscapeUIController : UIController, IOnStateEntered<GameplayS
{
[Dependency] private readonly IClientConsoleHost _console = default!;
[Dependency] private readonly IUriOpener _uri = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ChangelogUIController _changelog = default!;
[Dependency] private readonly InfoUIController _info = default!;
[Dependency] private readonly OptionsUIController _options = default!;
@@ -93,9 +95,12 @@ public sealed class EscapeUIController : UIController, IOnStateEntered<GameplayS
_escapeWindow.WikiButton.OnPressed += _ =>
{
_uri.OpenUri(UILinks.Wiki);
_uri.OpenUri(_cfg.GetCVar(CCVars.InfoLinksWiki));
};
// Hide wiki button if we don't have a link for it.
_escapeWindow.WikiButton.Visible = _cfg.GetCVar(CCVars.InfoLinksWiki) != "";
CommandBinds.Builder
.Bind(EngineKeyFunctions.EscapeMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow()))

View File

@@ -16,6 +16,7 @@ using Content.Server.Maps;
using Content.Server.NodeContainer.NodeGroups;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Preferences.Managers;
using Content.Server.ServerInfo;
using Content.Server.ServerUpdates;
using Content.Server.Voting.Managers;
using Content.Shared.Administration;
@@ -96,6 +97,7 @@ namespace Content.Server.Entry
IoCManager.Resolve<IGamePrototypeLoadManager>().Initialize();
IoCManager.Resolve<NetworkResourceManager>().Initialize();
IoCManager.Resolve<GhostKickManager>().Initialize();
IoCManager.Resolve<ServerInfoManager>().Initialize();
_voteManager.Initialize();
_updateManager.Initialize();

View File

@@ -16,6 +16,7 @@ using Content.Server.Objectives;
using Content.Server.Objectives.Interfaces;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Preferences.Managers;
using Content.Server.ServerInfo;
using Content.Server.ServerUpdates;
using Content.Server.Voting.Managers;
using Content.Shared.Administration;
@@ -55,6 +56,7 @@ namespace Content.Server.IoC
IoCManager.Register<IAdminLogManager, AdminLogManager>();
IoCManager.Register<PlayTimeTrackingManager>();
IoCManager.Register<UserDbDataManager>();
IoCManager.Register<ServerInfoManager>();
}
}
}

View File

@@ -0,0 +1,44 @@
using System.Text.Json.Nodes;
using Content.Shared.CCVar;
using Robust.Server.ServerStatus;
using Robust.Shared.Configuration;
namespace Content.Server.ServerInfo;
/// <summary>
/// Adds additional data like info links to the server info endpoint
/// </summary>
public sealed class ServerInfoManager
{
private static readonly (CVarDef<string> cVar, string icon, string name)[] Vars =
{
// @formatter:off
(CCVars.InfoLinksDiscord, "discord", "info-link-discord"),
(CCVars.InfoLinksForum, "forum", "info-link-forum"),
(CCVars.InfoLinksGithub, "github", "info-link-github"),
(CCVars.InfoLinksWebsite, "web", "info-link-website"),
(CCVars.InfoLinksWiki, "wiki", "info-link-wiki")
// @formatter:on
};
[Dependency] private readonly IStatusHost _statusHost = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
public void Initialize()
{
_statusHost.OnInfoRequest += OnInfoRequest;
}
private void OnInfoRequest(JsonNode json)
{
foreach (var (cVar, icon, name) in Vars)
{
var url = _cfg.GetCVar(cVar);
if (string.IsNullOrEmpty(url))
continue;
StatusHostHelpers.AddLink(json, _loc.GetString(name), url, icon);
}
}
}

View File

@@ -1348,5 +1348,51 @@ namespace Content.Shared.CCVar
/// </summary>
public static readonly CVarDef<float>
PlayTimeSaveInterval = CVarDef.Create("playtime.save_interval", 900f, CVar.SERVERONLY);
/*
* INFOLINKS
*/
/// <summary>
/// Link to Discord server to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksDiscord =
CVarDef.Create("infolinks.discord", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to website to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksForum =
CVarDef.Create("infolinks.forum", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to GitHub page to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksGithub =
CVarDef.Create("infolinks.github", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to website to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksWebsite =
CVarDef.Create("infolinks.website", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to wiki to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksWiki =
CVarDef.Create("infolinks.wiki", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to Patreon. Not shown in the launcher currently.
/// </summary>
public static readonly CVarDef<string> InfoLinksPatreon =
CVarDef.Create("infolinks.patreon", "", CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Link to the bug report form.
/// </summary>
public static readonly CVarDef<string> InfoLinksBugReport =
CVarDef.Create("infolinks.bug_report", "", CVar.SERVER | CVar.REPLICATED);
}
}

View File

@@ -2,5 +2,6 @@ server-info-rules-button = Rules
server-info-discord-button = Discord
server-info-website-button = Website
server-info-wiki-button = Wiki
server-info-forum-button = Forum
server-info-report-button = Report Bugs
server-info-credits-button = Credits

View File

@@ -0,0 +1,7 @@
### Strings for link buttons shown in the launcher's server description.
info-link-discord = Discord
info-link-forum = Forum
info-link-github = GitHub
info-link-website = Website
info-link-wiki = Wiki