From e4dd78c5cdee2eced29e67aab8f9a8a988a4a5e3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 2 Jun 2018 15:57:25 +0000 Subject: [PATCH] Add a tab to the credits panel for mod-specific text. Enabled by adding a ModCredits block to mod.yaml. --- OpenRA.Mods.Common/ModCredits.cs | 21 +++++++ OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../Widgets/Logic/CreditsLogic.cs | 62 ++++++++++++++++--- mods/cnc/chrome/credits.yaml | 18 +++++- mods/common/chrome/credits.yaml | 20 +++++- 5 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 OpenRA.Mods.Common/ModCredits.cs diff --git a/OpenRA.Mods.Common/ModCredits.cs b/OpenRA.Mods.Common/ModCredits.cs new file mode 100644 index 0000000000..308529c72f --- /dev/null +++ b/OpenRA.Mods.Common/ModCredits.cs @@ -0,0 +1,21 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +namespace OpenRA +{ + public class ModCredits : IGlobalModData + { + public readonly string ModTabTitle = "Game"; + + [FieldLoader.Require] + public readonly string ModCreditsFile = null; + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 41f456d308..0b3275c61e 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -882,6 +882,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs index e63671ecb7..bdb36d339d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs @@ -11,15 +11,27 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic { public class CreditsLogic : ChromeLogic { + readonly ModData modData; + readonly ScrollPanelWidget scrollPanel; + readonly LabelWidget template; + + readonly IEnumerable modLines; + readonly IEnumerable engineLines; + bool showMod = false; + [ObjectCreator.UseCtor] public CreditsLogic(Widget widget, ModData modData, Action onExit) { + this.modData = modData; + var panel = widget.Get("CREDITS_PANEL"); panel.Get("BACK_BUTTON").OnClick = () => @@ -28,19 +40,55 @@ namespace OpenRA.Mods.Common.Widgets.Logic onExit(); }; - var scrollPanel = panel.Get("CREDITS_DISPLAY"); - var template = scrollPanel.Get("CREDITS_TEMPLATE"); - scrollPanel.RemoveChildren(); + engineLines = ParseLines("AUTHORS"); - var lines = modData.DefaultFileSystem.Open("AUTHORS").ReadAllLines(); - foreach (var l in lines) + var tabContainer = panel.Get("TAB_CONTAINER"); + var modTab = tabContainer.Get("MOD_TAB"); + modTab.IsHighlighted = () => showMod; + modTab.OnClick = () => ShowCredits(true); + + var engineTab = tabContainer.Get("ENGINE_TAB"); + engineTab.IsHighlighted = () => !showMod; + engineTab.OnClick = () => ShowCredits(false); + + scrollPanel = panel.Get("CREDITS_DISPLAY"); + template = scrollPanel.Get("CREDITS_TEMPLATE"); + + var hasModCredits = modData.Manifest.Contains(); + if (hasModCredits) + { + var modCredits = modData.Manifest.Get(); + modLines = ParseLines(modCredits.ModCreditsFile); + modTab.GetText = () => modCredits.ModTabTitle; + + // Make space to show the tabs + tabContainer.IsVisible = () => true; + scrollPanel.Bounds.Y += tabContainer.Bounds.Height; + scrollPanel.Bounds.Height -= tabContainer.Bounds.Height; + } + + ShowCredits(hasModCredits); + } + + void ShowCredits(bool modCredits) + { + showMod = modCredits; + + scrollPanel.RemoveChildren(); + foreach (var line in showMod ? modLines : engineLines) { - // Improve the formatting - var line = l.Replace("\t", " ").Replace("*", "\u2022"); var label = template.Clone() as LabelWidget; label.GetText = () => line; scrollPanel.AddChild(label); } } + + IEnumerable ParseLines(string file) + { + return modData.DefaultFileSystem.Open(file) + .ReadAllLines() + .Select(l => l.Replace("\t", " ").Replace("*", "\u2022")) + .ToList(); + } } } diff --git a/mods/cnc/chrome/credits.yaml b/mods/cnc/chrome/credits.yaml index 30c8bf09de..0a8e72a7cd 100644 --- a/mods/cnc/chrome/credits.yaml +++ b/mods/cnc/chrome/credits.yaml @@ -17,15 +17,31 @@ Container@CREDITS_PANEL: Height: 400 Background: panel-black Children: + Container@TAB_CONTAINER: + Visible: False + X: 15 + Y: 15 + Width: PARENT_RIGHT - 30 + Height: 34 + Children: + Button@MOD_TAB: + Width: 140 + Height: 35 + Button@ENGINE_TAB: + X: 150 + Width: 140 + Height: 35 + Text: OpenRA ScrollPanel@CREDITS_DISPLAY: X: 15 Y: 15 Width: PARENT_RIGHT - 30 Height: PARENT_BOTTOM - 30 - TopBottomSpacing: 18 + TopBottomSpacing: 6 Children: Label@CREDITS_TEMPLATE: X: 8 + Width: PARENT_RIGHT - 25 Height: 16 VAlign: Top Button@BACK_BUTTON: diff --git a/mods/common/chrome/credits.yaml b/mods/common/chrome/credits.yaml index ba9c73f76f..e6496a6e65 100644 --- a/mods/common/chrome/credits.yaml +++ b/mods/common/chrome/credits.yaml @@ -12,15 +12,33 @@ Background@CREDITS_PANEL: Font: Bold Align: Center Text: Credits + Container@TAB_CONTAINER: + Visible: False + X: 15 + Y: 50 + Width: PARENT_RIGHT - 30 + Height: 30 + Children: + Button@MOD_TAB: + Width: 140 + Height: 31 + Font: Bold + Button@ENGINE_TAB: + X: 140 + Width: 140 + Height: 31 + Text: OpenRA + Font: Bold ScrollPanel@CREDITS_DISPLAY: X: 15 Y: 50 Width: PARENT_RIGHT - 30 Height: 345 - TopBottomSpacing: 18 + TopBottomSpacing: 6 Children: Label@CREDITS_TEMPLATE: X: 8 + Width: PARENT_RIGHT - 25 Height: 16 VAlign: Top Button@BACK_BUTTON: