Expand Battlefield News when a new news post has been downloaded

This commit is contained in:
bean601
2015-05-10 20:17:42 -06:00
committed by penev92
parent c22f15de55
commit 730cec3974

View File

@@ -14,7 +14,6 @@ using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
@@ -28,7 +27,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ScrollPanelWidget newsPanel; readonly ScrollPanelWidget newsPanel;
readonly Widget newsTemplate; readonly Widget newsTemplate;
readonly LabelWidget newsStatus; readonly LabelWidget newsStatus;
bool newsHighlighted = false;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MainMenuLogic(Widget widget, World world) public MainMenuLogic(Widget widget, World world)
@@ -200,21 +198,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (currentNews != null) if (currentNews != null)
DisplayNews(currentNews); DisplayNews(currentNews);
// Only query for new stories once per day
var cacheValid = currentNews != null && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate;
if (!cacheValid)
new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { }, (e, c) => NewsDownloadComplete(e, c, cacheFile, currentNews));
var newsButton = newsBG.GetOrNull<DropDownButtonWidget>("NEWS_BUTTON"); var newsButton = newsBG.GetOrNull<DropDownButtonWidget>("NEWS_BUTTON");
if (newsButton != null) if (newsButton != null)
{ {
newsButton.OnClick = () => // Only query for news once per day.
{ var cacheValid = currentNews != null && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate;
newsButton.AttachPanel(newsPanel); if (!cacheValid)
newsHighlighted = false; new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { },
}; (e, c) => NewsDownloadComplete(e, cacheFile, currentNews, () => newsButton.AttachPanel(newsPanel)));
newsButton.IsHighlighted = () => newsHighlighted && Game.LocalTick % 50 < 25; newsButton.OnClick = () => newsButton.AttachPanel(newsPanel);
} }
} }
@@ -281,7 +275,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return null; return null;
} }
void NewsDownloadComplete(AsyncCompletedEventArgs e, bool cancelled, string cacheFile, NewsItem[] oldNews) void NewsDownloadComplete(AsyncCompletedEventArgs e, string cacheFile, NewsItem[] oldNews, Action onNewsDownloaded)
{ {
Game.RunAfterTick(() => // run on the main thread Game.RunAfterTick(() => // run on the main thread
{ {
@@ -298,7 +292,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
DisplayNews(newNews); DisplayNews(newNews);
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)))
newsHighlighted = true; onNewsDownloaded();
Game.Settings.Game.NewsFetchedDate = DateTime.Today.ToUniversalTime(); Game.Settings.Game.NewsFetchedDate = DateTime.Today.ToUniversalTime();
Game.Settings.Save(); Game.Settings.Save();