Fetch battlefield news once per game launch.

This commit is contained in:
Paul Chote
2015-11-07 11:27:44 +00:00
parent 3539095ea1
commit b235e244a4
2 changed files with 7 additions and 8 deletions

View File

@@ -179,7 +179,6 @@ namespace OpenRA
public bool FetchNews = true; public bool FetchNews = true;
public string NewsUrl = "http://www.openra.net/gamenews"; public string NewsUrl = "http://www.openra.net/gamenews";
public DateTime NewsFetchedDate;
} }
public class KeySettings public class KeySettings

View File

@@ -28,6 +28,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Widget newsTemplate; readonly Widget newsTemplate;
readonly LabelWidget newsStatus; readonly LabelWidget newsStatus;
// Update news once per game launch
static bool fetchedNews;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MainMenuLogic(Widget widget, World world) public MainMenuLogic(Widget widget, World world)
{ {
@@ -207,11 +210,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (newsButton != null) if (newsButton != null)
{ {
// Only query for news once per day. if (!fetchedNews)
var cacheValid = currentNews != null && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate;
if (!cacheValid)
new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { }, new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { },
(e, c) => NewsDownloadComplete(e, cacheFile, currentNews, () => newsButton.AttachPanel(newsPanel))); (e, c) => NewsDownloadComplete(e, cacheFile, currentNews,
() => newsButton.AttachPanel(newsPanel)));
newsButton.OnClick = () => newsButton.AttachPanel(newsPanel); newsButton.OnClick = () => newsButton.AttachPanel(newsPanel);
} }
@@ -292,6 +294,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return; return;
} }
fetchedNews = true;
var newNews = ParseNews(cacheFile); var newNews = ParseNews(cacheFile);
if (newNews == null) if (newNews == null)
return; return;
@@ -300,9 +303,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (oldNews == null || newNews.Any(n => !oldNews.Select(c => c.DateTime).Contains(n.DateTime))) if (oldNews == null || newNews.Any(n => !oldNews.Select(c => c.DateTime).Contains(n.DateTime)))
onNewsDownloaded(); onNewsDownloaded();
Game.Settings.Game.NewsFetchedDate = DateTime.Today.ToUniversalTime();
Game.Settings.Save();
}); });
} }