Unhardcoded engine credits file
Moved the file name/path to ModCredits, read from mod.yaml
This commit is contained in:
committed by
Matthias Mailänder
parent
9b1cec7712
commit
a71da0a25a
@@ -15,7 +15,8 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public readonly string ModTabTitle = "Game";
|
public readonly string ModTabTitle = "Game";
|
||||||
|
|
||||||
[FieldLoader.Require]
|
|
||||||
public readonly string ModCreditsFile = null;
|
public readonly string ModCreditsFile = null;
|
||||||
|
|
||||||
|
public readonly string EngineCreditsFile = "^EngineDir|AUTHORS";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
public class CreditsLogic : ChromeLogic
|
public class CreditsLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
readonly ModData modData;
|
|
||||||
readonly ScrollPanelWidget scrollPanel;
|
readonly ScrollPanelWidget scrollPanel;
|
||||||
readonly LabelWidget template;
|
readonly LabelWidget template;
|
||||||
|
|
||||||
|
bool showModTab;
|
||||||
|
bool showEngineTab;
|
||||||
readonly IEnumerable<string> modLines;
|
readonly IEnumerable<string> modLines;
|
||||||
readonly IEnumerable<string> engineLines;
|
readonly IEnumerable<string> engineLines;
|
||||||
bool showMod = false;
|
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public CreditsLogic(Widget widget, ModData modData, Action onExit)
|
public CreditsLogic(Widget widget, ModData modData, Action onExit)
|
||||||
{
|
{
|
||||||
this.modData = modData;
|
|
||||||
|
|
||||||
var panel = widget.Get("CREDITS_PANEL");
|
var panel = widget.Get("CREDITS_PANEL");
|
||||||
|
|
||||||
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
|
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
|
||||||
@@ -40,42 +38,48 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
onExit();
|
onExit();
|
||||||
};
|
};
|
||||||
|
|
||||||
engineLines = ParseLines(File.OpenRead(Platform.ResolvePath("./AUTHORS")));
|
var modCredits = modData.Manifest.Get<ModCredits>();
|
||||||
|
|
||||||
var tabContainer = panel.Get("TAB_CONTAINER");
|
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");
|
if (modCredits.ModCreditsFile != null)
|
||||||
engineTab.IsHighlighted = () => !showMod;
|
{
|
||||||
engineTab.OnClick = () => ShowCredits(false);
|
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");
|
scrollPanel = panel.Get<ScrollPanelWidget>("CREDITS_DISPLAY");
|
||||||
template = scrollPanel.Get<LabelWidget>("CREDITS_TEMPLATE");
|
template = scrollPanel.Get<LabelWidget>("CREDITS_TEMPLATE");
|
||||||
|
|
||||||
var hasModCredits = modData.Manifest.Contains<ModCredits>();
|
// Make space to show the tabs
|
||||||
if (hasModCredits)
|
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.Y += tabContainer.Bounds.Height;
|
||||||
scrollPanel.Bounds.Height -= tabContainer.Bounds.Height;
|
scrollPanel.Bounds.Height -= tabContainer.Bounds.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowCredits(hasModCredits);
|
ShowCredits(showModTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowCredits(bool modCredits)
|
void ShowCredits(bool modCredits)
|
||||||
{
|
{
|
||||||
showMod = modCredits;
|
|
||||||
|
|
||||||
scrollPanel.RemoveChildren();
|
scrollPanel.RemoveChildren();
|
||||||
foreach (var line in showMod ? modLines : engineLines)
|
foreach (var line in modCredits ? modLines : engineLines)
|
||||||
{
|
{
|
||||||
var label = template.Clone() as LabelWidget;
|
var label = template.Clone() as LabelWidget;
|
||||||
label.GetText = () => line;
|
label.GetText = () => line;
|
||||||
|
|||||||
Reference in New Issue
Block a user