Fetch battlefield news once per game launch.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user