move ActiveModVersion,ActiveModTitle out of cnc-specific code

This commit is contained in:
Chris Forbes
2011-09-24 21:19:05 +12:00
parent 15d846bfb0
commit e7900d069d
6 changed files with 31 additions and 38 deletions

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets
@@ -208,6 +209,18 @@ namespace OpenRA.Widgets
}
public static Action Once( Action a ) { return () => { if (a != null) { a(); a = null; } }; }
public static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
}
public static string ActiveModTitle()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Title;
}
}
[Flags]

View File

@@ -33,16 +33,17 @@ namespace OpenRA.Mods.Cnc
public void Init(Dictionary<string, string> info)
{
Info = info;
// Avoid standard loading mechanisms so we
// can display loadscreen as early as possible
r = Game.Renderer;
if (r == null) return;
var s = new Sheet("mods/cnc/uibits/chrome.png");
var res = Renderer.Resolution;
Bounds = new Rectangle(0, 0, res.Width, res.Height);
ss = new Sprite[]
ss = new []
{
new Sprite(s, new Rectangle(161,128,62,33), TextureChannel.Alpha),
new Sprite(s, new Rectangle(161,223,62,33), TextureChannel.Alpha),
@@ -53,6 +54,7 @@ namespace OpenRA.Mods.Cnc
new Sprite(s, new Rectangle(128,223,33,33), TextureChannel.Alpha),
new Sprite(s, new Rectangle(223,223,33,33), TextureChannel.Alpha)
};
nodLogo = new Sprite(s, new Rectangle(0, 256, 256, 256), TextureChannel.Alpha);
gdiLogo = new Sprite(s, new Rectangle(256, 256, 256, 256), TextureChannel.Alpha);
evaLogo = new Sprite(s, new Rectangle(256, 64, 128, 64), TextureChannel.Alpha);
@@ -73,6 +75,7 @@ namespace OpenRA.Mods.Cnc
{
if (r == null || loadTimer.ElapsedTime() < 0.25)
return;
loadTimer.Reset();
loadTick = ++loadTick % 8;
@@ -91,7 +94,7 @@ namespace OpenRA.Mods.Cnc
loadingPos = new float2((Bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY);
versionFont = r.Fonts["Regular"];
versionText = CncWidgetUtils.ActiveModVersion();
versionText = WidgetUtils.ActiveModVersion();
var versionSize = versionFont.Measure(versionText);
versionPos = new float2(Bounds.Width - 107 - versionSize.X/2, 115 - versionSize.Y/2);

View File

@@ -17,12 +17,6 @@ namespace OpenRA.Mods.Cnc.Widgets
{
public static class CncWidgetUtils
{
public static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
}
public static string ChooseInitialMap(string map)
{
var availableMaps = Game.modData.AvailableMaps;
@@ -37,13 +31,13 @@ namespace OpenRA.Mods.Cnc.Widgets
var prompt = Widget.OpenWindow("CONFIRM_PROMPT");
prompt.GetWidget<LabelWidget>("PROMPT_TITLE").GetText = () => title;
prompt.GetWidget<LabelWidget>("PROMPT_TEXT").GetText = () => text;
prompt.GetWidget<ButtonWidget>("CONFIRM_BUTTON").OnClick = () =>
{
Widget.CloseWindow();
onConfirm();
};
prompt.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Widget.CloseWindow();

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
menu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = WidgetUtils.ActiveModVersion;
bool hideButtons = false;
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
rootMenu = widget.GetWidget("MENU_BACKGROUND");
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = CncWidgetUtils.ActiveModVersion;
rootMenu.GetWidget<LabelWidget>("VERSION_LABEL").GetText = WidgetUtils.ActiveModVersion;
// Menu buttons
var mainMenu = widget.GetWidget("MAIN_MENU");

View File

@@ -40,20 +40,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var selector = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "QUICKMODSWITCHER" );
var switcher = selector.GetWidget<DropDownButtonWidget>("SWITCHER");
switcher.OnMouseDown = _ => ShowModsDropDown(switcher);
switcher.GetText = ActiveModTitle;
selector.GetWidget<LabelWidget>("VERSION").GetText = ActiveModVersion;
}
static string ActiveModTitle()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Title;
}
static string ActiveModVersion()
{
var mod = Game.modData.Manifest.Mods[0];
return Mod.AllMods[mod].Version;
switcher.GetText = WidgetUtils.ActiveModTitle;
selector.GetWidget<LabelWidget>("VERSION").GetText = WidgetUtils.ActiveModVersion;
}
static void LoadMod(string mod)
@@ -64,23 +52,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic
mods.Add(mod);
mod = Mod.AllMods[mod].Requires;
}
if (!Game.CurrentMods.Keys.ToArray().SymmetricDifference(mods.ToArray()).Any())
return;
Game.RunAfterTick(() =>
{
Game.InitializeWithMods(mods.ToArray());
});
if (Game.CurrentMods.Keys.ToArray().SymmetricDifference(mods.ToArray()).Any())
Game.RunAfterTick(() => Game.InitializeWithMods(mods.ToArray()));
}
static void ShowModsDropDown(DropDownButtonWidget dropdown)
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (m, itemTemplate) =>
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => m == Game.CurrentMods.Keys.First(),
() => LoadMod(m));
() => m == Game.CurrentMods.Keys.First(),
() => LoadMod(m));
item.GetWidget<LabelWidget>("LABEL").GetText = () => Mod.AllMods[m].Title;
return item;
};