Add a tab to the credits panel for mod-specific text.
Enabled by adding a ModCredits block to mod.yaml.
This commit is contained in:
@@ -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<string> modLines;
|
||||
readonly IEnumerable<string> 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<ButtonWidget>("BACK_BUTTON").OnClick = () =>
|
||||
@@ -28,19 +40,55 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onExit();
|
||||
};
|
||||
|
||||
var scrollPanel = panel.Get<ScrollPanelWidget>("CREDITS_DISPLAY");
|
||||
var template = scrollPanel.Get<LabelWidget>("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<ButtonWidget>("MOD_TAB");
|
||||
modTab.IsHighlighted = () => showMod;
|
||||
modTab.OnClick = () => ShowCredits(true);
|
||||
|
||||
var engineTab = tabContainer.Get<ButtonWidget>("ENGINE_TAB");
|
||||
engineTab.IsHighlighted = () => !showMod;
|
||||
engineTab.OnClick = () => ShowCredits(false);
|
||||
|
||||
scrollPanel = panel.Get<ScrollPanelWidget>("CREDITS_DISPLAY");
|
||||
template = scrollPanel.Get<LabelWidget>("CREDITS_TEMPLATE");
|
||||
|
||||
var hasModCredits = modData.Manifest.Contains<ModCredits>();
|
||||
if (hasModCredits)
|
||||
{
|
||||
var modCredits = modData.Manifest.Get<ModCredits>();
|
||||
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<string> ParseLines(string file)
|
||||
{
|
||||
return modData.DefaultFileSystem.Open(file)
|
||||
.ReadAllLines()
|
||||
.Select(l => l.Replace("\t", " ").Replace("*", "\u2022"))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user