Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Credits view crashing and unhardcoded AUTHORS file name/path #19739

Merged
merged 1 commit into from Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/ModCredits.cs
Expand Up @@ -15,7 +15,8 @@ public class ModCredits : IGlobalModData
{
public readonly string ModTabTitle = "Game";

[FieldLoader.Require]
public readonly string ModCreditsFile = null;

public readonly string EngineCreditsFile = "^EngineDir|AUTHORS";
}
}
52 changes: 28 additions & 24 deletions OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs
Expand Up @@ -19,19 +19,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class CreditsLogic : ChromeLogic
{
readonly ModData modData;
readonly ScrollPanelWidget scrollPanel;
readonly LabelWidget template;

bool showModTab;
bool showEngineTab;
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 = () =>
Expand All @@ -40,42 +38,48 @@ public CreditsLogic(Widget widget, ModData modData, Action onExit)
onExit();
};

engineLines = ParseLines(File.OpenRead(Platform.ResolvePath("./AUTHORS")));

var modCredits = modData.Manifest.Get<ModCredits>();
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);
if (modCredits.ModCreditsFile != null)
abcdefg30 marked this conversation as resolved.
Show resolved Hide resolved
{
showModTab = true;
modLines = ParseLines(modData.DefaultFileSystem.Open(modCredits.ModCreditsFile));

var modTab = tabContainer.Get<ButtonWidget>("MOD_TAB");
modTab.IsHighlighted = () => showModTab;
modTab.OnClick = () => ShowCredits(true);
modTab.GetText = () => modCredits.ModTabTitle;
}

if (modCredits.EngineCreditsFile != null)
{
showEngineTab = true;
engineLines = ParseLines(File.OpenRead(Platform.ResolvePath(modCredits.EngineCreditsFile)));

var engineTab = tabContainer.Get<ButtonWidget>("ENGINE_TAB");
engineTab.IsHighlighted = () => !showModTab;
engineTab.OnClick = () => ShowCredits(false);
}

scrollPanel = panel.Get<ScrollPanelWidget>("CREDITS_DISPLAY");
template = scrollPanel.Get<LabelWidget>("CREDITS_TEMPLATE");

var hasModCredits = modData.Manifest.Contains<ModCredits>();
if (hasModCredits)
// Make space to show the tabs
tabContainer.IsVisible = () => showModTab && showEngineTab;
if (showModTab && showEngineTab)
{
var modCredits = modData.Manifest.Get<ModCredits>();
modLines = ParseLines(modData.DefaultFileSystem.Open(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);
ShowCredits(showModTab);
}

void ShowCredits(bool modCredits)
{
showMod = modCredits;

scrollPanel.RemoveChildren();
foreach (var line in showMod ? modLines : engineLines)
foreach (var line in modCredits ? modLines : engineLines)
{
var label = template.Clone() as LabelWidget;
label.GetText = () => line;
Expand Down