Adjust news dialog layout.
This commit is contained in:
@@ -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<ImageWidget>("RECBLOCK").IsVisible = () => world.WorldTick / 25 % 2 == 0;
|
||||
|
||||
var shellmapDisabledDecorations = widget.Get("SHELLMAP_DISABLED_DECORATIONS");
|
||||
|
||||
@@ -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<ButtonWidget>("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<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs());
|
||||
newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE");
|
||||
newsPanel.RemoveChild(newsTemplate);
|
||||
|
||||
newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS");
|
||||
SetNewsStatus("Loading news");
|
||||
|
||||
if (Game.modData.Manifest.NewsUrl != null)
|
||||
{
|
||||
newsPanel = widget.Get<ScrollPanelWidget>("NEWS_PANEL");
|
||||
newsItemTemplate = widget.Get("NEWS_ITEM_TEMPLATE");
|
||||
newsStatus = widget.Get<LabelWidget>("NEWS_STATUS");
|
||||
showNewsButton = widget.Get<ButtonWidget>("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<DropDownButtonWidget>("HIDE_NEWS_BUTTON").OnMouseDown = mi => newsExpanded = false;
|
||||
collapsedNewsBG.Get<DropDownButtonWidget>("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<DropDownButtonWidget>("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<LabelWidget>("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);
|
||||
});
|
||||
|
||||
@@ -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
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user