diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs index 43a0429e64..266515e2b6 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic : base(widget, world) { var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS"); - shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap && !newsBG.IsVisible(); + shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap; shellmapDecorations.Get("RECBLOCK").IsVisible = () => world.WorldTick / 25 % 2 == 0; var shellmapDisabledDecorations = widget.Get("SHELLMAP_DISABLED_DECORATIONS"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs index 60106a3b9f..68bf2c9513 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs @@ -23,14 +23,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic protected enum MenuType { Main, Singleplayer, Extras, None } protected MenuType menuType = MenuType.Main; - Widget rootMenu; - - protected readonly Widget newsBG; + readonly Widget rootMenu; readonly ScrollPanelWidget newsPanel; - readonly Widget newsItemTemplate; + readonly Widget newsTemplate; readonly LabelWidget newsStatus; - readonly ButtonWidget showNewsButton; - bool newsExpanded = false; + bool newsHighlighted = false; [ObjectCreator.UseCtor] public MainMenuLogic(Widget widget, World world) @@ -138,51 +135,43 @@ namespace OpenRA.Mods.RA.Widgets.Logic extrasMenu.Get("BACK_BUTTON").OnClick = () => menuType = MenuType.Main; - newsBG = widget.GetOrNull("NEWS_BG"); + var newsBG = widget.GetOrNull("NEWS_BG"); if (newsBG != null) { - var collapsedNewsBG = widget.Get("COLLAPSED_NEWS_BG"); + newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None; - if (!Game.Settings.Game.FetchNews) - collapsedNewsBG.Visible = false; - else + newsPanel = Ui.LoadWidget("NEWS_PANEL", null, new WidgetArgs()); + newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); + newsPanel.RemoveChild(newsTemplate); + + newsStatus = newsPanel.Get("NEWS_STATUS"); + SetNewsStatus("Loading news"); + + if (Game.modData.Manifest.NewsUrl != null) { - newsPanel = widget.Get("NEWS_PANEL"); - newsItemTemplate = widget.Get("NEWS_ITEM_TEMPLATE"); - newsStatus = widget.Get("NEWS_STATUS"); - showNewsButton = widget.Get("SHOW_NEWS_BUTTON"); + var cacheFile = GetNewsCacheFile(); + var cacheValid = File.Exists(cacheFile) && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate; - newsPanel.RemoveChildren(); - - newsBG.IsVisible = () => newsExpanded && menuType != MenuType.None; - collapsedNewsBG.IsVisible = () => !newsExpanded && menuType != MenuType.None; - - newsBG.Get("HIDE_NEWS_BUTTON").OnMouseDown = mi => newsExpanded = false; - collapsedNewsBG.Get("SHOW_NEWS_BUTTON").OnMouseDown = mi => - { - showNewsButton.IsHighlighted = () => false; - newsExpanded = true; - }; - - SetNewsStatus("Loading news"); - - if (Game.modData.Manifest.NewsUrl != null) - { - var cacheFile = GetNewsCacheFile(); - var cacheValid = File.Exists(cacheFile) && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate; - - if (cacheValid) - DisplayNews(ReadNews(File.ReadAllBytes(cacheFile))); - else - new Download(Game.modData.Manifest.NewsUrl, e => { }, NewsDownloadComplete); - } + if (cacheValid) + DisplayNews(ReadNews(File.ReadAllBytes(cacheFile))); + else + new Download(Game.modData.Manifest.NewsUrl, e => { }, NewsDownloadComplete); } + + var newsButton = newsBG.GetOrNull("NEWS_BUTTON"); + newsButton.OnClick = () => + { + newsButton.AttachPanel(newsPanel); + newsHighlighted = false; + }; + + newsButton.IsHighlighted = () => newsHighlighted && Game.LocalTick % 50 < 25;; } } string GetNewsCacheFile() { - var cacheDir = Path.Combine(Platform.SupportDir, "cache", Game.modData.Manifest.Mod.Id); + var cacheDir = Path.Combine(Platform.SupportDir, "Cache", Game.modData.Manifest.Mod.Id); Directory.CreateDirectory(cacheDir); return Path.Combine(cacheDir, "news.yaml"); } @@ -222,7 +211,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var item = i; - var newsItem = newsItemTemplate.Clone(); + var newsItem = newsTemplate.Clone(); var titleLabel = newsItem.Get("TITLE"); titleLabel.GetText = () => item.Title; @@ -273,10 +262,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var oldNews = ReadNews(File.ReadAllBytes(cacheFile)); if (newNews.Any(n => !oldNews.Select(c => c.DateTime).Contains(n.DateTime))) - showNewsButton.IsHighlighted = () => Game.LocalTick % 50 < 25; + newsHighlighted = true; } else - showNewsButton.IsHighlighted = () => Game.LocalTick % 50 < 25; + newsHighlighted = true; File.WriteAllBytes(cacheFile, e.Result); }); diff --git a/mods/cnc/chrome/dialogs.yaml b/mods/cnc/chrome/dialogs.yaml index 9689d26741..54c24f9260 100644 --- a/mods/cnc/chrome/dialogs.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -201,3 +201,38 @@ Container@TEXT_INPUT_PROMPT: Text: Cancel Font: Bold Key: escape + +ScrollPanel@NEWS_PANEL: + Width: 400 + Height: 265 + Background: panel-black + ItemSpacing: 5 + Children: + Container@NEWS_ITEM_TEMPLATE: + X: 10 + Y: 5 + Width: PARENT_RIGHT - 40 + Height: 45 + Children: + Label@TITLE: + Width: PARENT_RIGHT + Height: 25 + Align: Center + Font: Bold + Label@AUTHOR_DATETIME: + Y: 25 + Width: PARENT_RIGHT + Height: 15 + Align: Center + Text: by {0} at {1} + Font: TinyBold + Label@CONTENT: + Y: 45 + Width: PARENT_RIGHT + Label@NEWS_STATUS: + X: 80 + Y: 0 + Width: PARENT_RIGHT - 80 - 80 - 24 + Height: PARENT_BOTTOM + Align: Center + VAlign: Middle \ No newline at end of file diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 6dbe0c17a8..d161334142 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -184,81 +184,15 @@ Container@MENU_BACKGROUND: Width: 140 Height: 35 Text: Back - Container@COLLAPSED_NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 55 - Y: 136 - Width: 140 - Height: 45 + Container@NEWS_BG: Children: - DropDownButton@SHOW_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - Y: 10 - Width: 120 + DropDownButton@NEWS_BUTTON: + X: (WINDOW_RIGHT - WIDTH)/2 + Y: 50 + Width: 400 Height: 25 - Text: Show News + Text: Battlefield News Font: Bold - Background@NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 55 - Y: 170 - Width: 500 - Height: 265 - Background: panel-black - Children: - Label@NEWS_TITLE: - X: 0 - Y: 0 - 40 - Width: PARENT_RIGHT - Height: 30 - Text: News - Align: Center - Font: BigBold - Contrast: True - DropDownButton@HIDE_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - Y: 0 - 24 - Width: 120 - Height: 25 - Text: Hide News - Font: Bold - ScrollPanel@NEWS_PANEL: - X: 15 - Y: 15 - Width: PARENT_RIGHT - 30 - Height: 235 - ItemSpacing: 5 - Children: - Container@NEWS_ITEM_TEMPLATE: - X: 5 - Y: 5 - Width: PARENT_RIGHT - 30 - Height: 45 - Children: - Label@TITLE: - X: 0 - Y: 0 - Width: PARENT_RIGHT - Height: 25 - Align: Center - Font: Bold - Label@AUTHOR_DATETIME: - X: 0 - Y: 25 - Width: PARENT_RIGHT - Height: 15 - Align: Center - Text: by {0} at {1} - Font: TinyBold - Label@CONTENT: - X: 0 - Y: 45 - Width: PARENT_RIGHT - Label@NEWS_STATUS: - X: 80 - Y: 0 - Width: PARENT_RIGHT - 80 - 80 - 24 - Height: PARENT_BOTTOM - Align: Center - VAlign: Middle Container@PERFORMANCE_INFO: Logic: PerfDebugLogic Children: diff --git a/mods/d2k/chrome/dropdowns.yaml b/mods/d2k/chrome/dropdowns.yaml index 32308acc15..3acd9bb2ed 100644 --- a/mods/d2k/chrome/dropdowns.yaml +++ b/mods/d2k/chrome/dropdowns.yaml @@ -95,3 +95,36 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE: Width: PARENT_RIGHT Height: 25 +ScrollPanel@NEWS_PANEL: + Width: 370 + Height: 265 + ItemSpacing: 5 + Children: + Container@NEWS_ITEM_TEMPLATE: + X: 10 + Y: 5 + Width: PARENT_RIGHT - 40 + Height: 45 + Children: + Label@TITLE: + Width: PARENT_RIGHT + Height: 25 + Align: Center + Font: Bold + Label@AUTHOR_DATETIME: + Y: 25 + Width: PARENT_RIGHT + Height: 15 + Align: Center + Text: by {0} at {1} + Font: TinyBold + Label@CONTENT: + Y: 45 + Width: PARENT_RIGHT + Label@NEWS_STATUS: + X: 80 + Y: 0 + Width: PARENT_RIGHT - 80 - 80 - 24 + Height: PARENT_BOTTOM + Align: Center + VAlign: Middle diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index 220d20aa60..bf4d34afde 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -149,72 +149,19 @@ Container@MAINMENU: Height: 30 Text: Back Font: Bold - Background@COLLAPSED_NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 20 - Y: 20 - Width: 140 - Height: 45 - Children: - DropDownButton@SHOW_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - 10 - Y: 10 - Width: 120 - Height: 25 - Text: Show News - Font: Bold Background@NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 20 - Y: 20 - Width: 500 - Height: 300 + X: (WINDOW_RIGHT - WIDTH)/2 + Y: 35 + Width: 400 + Height: 55 Children: - Label@NEWS_TITLE: - X: 0 - Y: 20 - Width: PARENT_RIGHT - Height: 30 - Text: News - Align: Center - Font: Bold - DropDownButton@HIDE_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - 10 - Y: 10 - Width: 120 - Height: 25 - Text: Hide News - Font: Bold - ScrollPanel@NEWS_PANEL: + DropDownButton@NEWS_BUTTON: X: 15 - Y: 50 - Width: PARENT_RIGHT - 30 - Height: 235 - ItemSpacing: 5 - Children: - Container@NEWS_ITEM_TEMPLATE: - X: 5 - Y: 5 - Width: PARENT_RIGHT - 30 - Height: 45 - Children: - Label@TITLE: - X: 0 - Y: 0 - Width: PARENT_RIGHT - Height: 25 - Align: Center - Font: Bold - Label@AUTHOR_DATETIME: - X: 0 - Y: 25 - Width: PARENT_RIGHT - Height: 15 - Align: Center - Text: by {0} at {1} - Font: TinyBold - Label@CONTENT: - X: 0 - Y: 45 - Width: PARENT_RIGHT + Y: 15 + Width: 370 + Height: 25 + Text: Battlefield News + Font: Bold Label@NEWS_STATUS: X: 80 Y: 0 diff --git a/mods/ra/chrome/dropdowns.yaml b/mods/ra/chrome/dropdowns.yaml index 749ab3d071..f68bf029eb 100644 --- a/mods/ra/chrome/dropdowns.yaml +++ b/mods/ra/chrome/dropdowns.yaml @@ -95,3 +95,36 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE: Width: PARENT_RIGHT Height: 25 +ScrollPanel@NEWS_PANEL: + Width: 370 + Height: 265 + ItemSpacing: 5 + Children: + Container@NEWS_ITEM_TEMPLATE: + X: 10 + Y: 5 + Width: PARENT_RIGHT - 40 + Height: 45 + Children: + Label@TITLE: + Width: PARENT_RIGHT + Height: 25 + Align: Center + Font: Bold + Label@AUTHOR_DATETIME: + Y: 25 + Width: PARENT_RIGHT + Height: 15 + Align: Center + Text: by {0} at {1} + Font: TinyBold + Label@CONTENT: + Y: 45 + Width: PARENT_RIGHT + Label@NEWS_STATUS: + X: 80 + Y: 0 + Width: PARENT_RIGHT - 80 - 80 - 24 + Height: PARENT_BOTTOM + Align: Center + VAlign: Middle diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index a970371d22..0ede9ad0aa 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -184,76 +184,16 @@ Container@MAINMENU: Y: 5 Width: 200 Height: 200 - Background@COLLAPSED_NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 100 - Y: 320 - Width: 140 - Height: 45 - Children: - DropDownButton@SHOW_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - 10 - Y: 10 - Width: 120 - Height: 25 - Text: Show News - Font: Bold Background@NEWS_BG: - X: WINDOW_RIGHT - WIDTH - 100 - Y: 320 - Width: 500 - Height: 300 + X: (WINDOW_RIGHT - WIDTH)/2 + Y: 35 + Width: 400 + Height: 55 Children: - Label@NEWS_TITLE: - X: 0 - Y: 20 - Width: PARENT_RIGHT - Height: 30 - Text: News - Align: Center - Font: Bold - DropDownButton@HIDE_NEWS_BUTTON: - X: PARENT_RIGHT - WIDTH - 10 - Y: 10 - Width: 120 - Height: 25 - Text: Hide News - Font: Bold - ScrollPanel@NEWS_PANEL: + DropDownButton@NEWS_BUTTON: X: 15 - Y: 50 - Width: PARENT_RIGHT - 30 - Height: 235 - ItemSpacing: 5 - Children: - Container@NEWS_ITEM_TEMPLATE: - X: 5 - Y: 5 - Width: PARENT_RIGHT - 30 - Height: 45 - Children: - Label@TITLE: - X: 0 - Y: 0 - Width: PARENT_RIGHT - Height: 25 - Align: Center - Font: Bold - Label@AUTHOR_DATETIME: - X: 0 - Y: 25 - Width: PARENT_RIGHT - Height: 15 - Align: Center - Text: by {0} at {1} - Font: TinyBold - Label@CONTENT: - X: 0 - Y: 45 - Width: PARENT_RIGHT - Label@NEWS_STATUS: - X: 80 - Y: 0 - Width: PARENT_RIGHT - 80 - 80 - 24 - Height: PARENT_BOTTOM - Align: Center - VAlign: Middle + Y: 15 + Width: 370 + Height: 25 + Text: Battlefield News + Font: Bold \ No newline at end of file