Reduce the size of battlefield news when messages are short

(cherry picked from commit 2a1eeae7ca55e814a8a648b7306648d6585a26c3)
This commit is contained in:
Gustas
2024-12-10 23:43:17 +02:00
committed by Pavel Penev
parent 5edca87622
commit 5f6eecc1f6
5 changed files with 24 additions and 31 deletions

View File

@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
protected MenuType menuType = MenuType.Main; protected MenuType menuType = MenuType.Main;
readonly Widget rootMenu; readonly Widget rootMenu;
readonly ScrollPanelWidget newsPanel; readonly ScrollPanelWidget newsPanel;
readonly int maxNewsHeight;
readonly Widget newsTemplate; readonly Widget newsTemplate;
readonly LabelWidget newsStatus; readonly LabelWidget newsStatus;
readonly ModData modData; readonly ModData modData;
@@ -230,6 +231,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs()); newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs());
newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE");
newsPanel.RemoveChild(newsTemplate); newsPanel.RemoveChild(newsTemplate);
maxNewsHeight = newsPanel.Bounds.Height;
newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS"); newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS");
SetNewsStatus(FluentProvider.GetMessage(LoadingNews)); SetNewsStatus(FluentProvider.GetMessage(LoadingNews));
@@ -416,10 +418,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
newsPanel.RemoveChildren(); newsPanel.RemoveChildren();
SetNewsStatus(""); SetNewsStatus("");
foreach (var i in newsItems) foreach (var item in newsItems)
{ {
var item = i;
var newsItem = newsTemplate.Clone(); var newsItem = newsTemplate.Clone();
var titleLabel = newsItem.Get<LabelWidget>("TITLE"); var titleLabel = newsItem.Get<LabelWidget>("TITLE");
@@ -441,6 +441,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
newsPanel.AddChild(newsItem); newsPanel.AddChild(newsItem);
newsPanel.Layout.AdjustChildren(); newsPanel.Layout.AdjustChildren();
newsPanel.Bounds.Height = Math.Min(newsPanel.ContentHeight, maxNewsHeight);
} }
} }

View File

@@ -284,29 +284,27 @@ ScrollPanel@NEWS_PANEL:
Width: 400 Width: 400
Height: 265 Height: 265
Background: panel-black Background: panel-black
TopBottomSpacing: 5 TopBottomSpacing: 10
ItemSpacing: 5 ItemSpacing: 5
Children: Children:
Container@NEWS_ITEM_TEMPLATE: Container@NEWS_ITEM_TEMPLATE:
X: 10 X: 10
Y: 5
Width: PARENT_WIDTH - 40 Width: PARENT_WIDTH - 40
Height: 45 Height: 40
Children: Children:
Label@TITLE: Label@TITLE:
Y: 1
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 25 Height: 20
Align: Center Align: Center
Font: Bold Font: Bold
Label@AUTHOR_DATETIME: Label@AUTHOR_DATETIME:
Y: 26 Y: 21
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 15 Height: 15
Align: Center Align: Center
Font: TinyBold Font: TinyBold
Label@CONTENT: Label@CONTENT:
Y: 46 Y: 40
Width: PARENT_WIDTH Width: PARENT_WIDTH
Label@NEWS_STATUS: Label@NEWS_STATUS:
X: 80 X: 80

View File

@@ -152,32 +152,30 @@ ScrollPanel@SPECTATOR_LABEL_DROPDOWN_TEMPLATE:
ScrollPanel@NEWS_PANEL: ScrollPanel@NEWS_PANEL:
Width: 400 Width: 400
Height: 265 Height: 265
TopBottomSpacing: 5 TopBottomSpacing: 15
ItemSpacing: 5 ItemSpacing: 5
Children: Children:
Container@NEWS_ITEM_TEMPLATE: Container@NEWS_ITEM_TEMPLATE:
X: 10 X: 10
Y: 5
Width: PARENT_WIDTH - 40 Width: PARENT_WIDTH - 40
Height: 45 Height: 40
Children: Children:
Label@TITLE: Label@TITLE:
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 25 Height: 15
Align: Center Align: Center
Font: Bold Font: Bold
Label@AUTHOR_DATETIME: Label@AUTHOR_DATETIME:
Y: 25 Y: 20
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 15 Height: 15
Align: Center Align: Center
Font: TinyBold Font: TinyBold
Label@CONTENT: Label@CONTENT:
Y: 45 Y: 40
Width: PARENT_WIDTH Width: PARENT_WIDTH
Label@NEWS_STATUS: Label@NEWS_STATUS:
X: 80 X: 80
Y: 0
Width: PARENT_WIDTH - 80 - 80 - 24 Width: PARENT_WIDTH - 80 - 80 - 24
Height: PARENT_HEIGHT Height: PARENT_HEIGHT
Align: Center Align: Center

View File

@@ -116,32 +116,30 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
ScrollPanel@NEWS_PANEL: ScrollPanel@NEWS_PANEL:
Width: 400 Width: 400
Height: 265 Height: 265
TopBottomSpacing: 5 TopBottomSpacing: 15
ItemSpacing: 5 ItemSpacing: 5
Children: Children:
Container@NEWS_ITEM_TEMPLATE: Container@NEWS_ITEM_TEMPLATE:
X: 10 X: 10
Y: 5
Width: PARENT_WIDTH - 40 Width: PARENT_WIDTH - 40
Height: 45 Height: 40
Children: Children:
Label@TITLE: Label@TITLE:
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 25 Height: 15
Align: Center Align: Center
Font: Bold Font: Bold
Label@AUTHOR_DATETIME: Label@AUTHOR_DATETIME:
Y: 25 Y: 20
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 15 Height: 15
Align: Center Align: Center
Font: TinyBold Font: TinyBold
Label@CONTENT: Label@CONTENT:
Y: 45 Y: 40
Width: PARENT_WIDTH Width: PARENT_WIDTH
Label@NEWS_STATUS: Label@NEWS_STATUS:
X: 80 X: 80
Y: 0
Width: PARENT_WIDTH - 80 - 80 - 24 Width: PARENT_WIDTH - 80 - 80 - 24
Height: PARENT_HEIGHT Height: PARENT_HEIGHT
Align: Center Align: Center

View File

@@ -116,32 +116,30 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
ScrollPanel@NEWS_PANEL: ScrollPanel@NEWS_PANEL:
Width: 400 Width: 400
Height: 265 Height: 265
TopBottomSpacing: 5 TopBottomSpacing: 15
ItemSpacing: 5 ItemSpacing: 5
Children: Children:
Container@NEWS_ITEM_TEMPLATE: Container@NEWS_ITEM_TEMPLATE:
X: 10 X: 10
Y: 6
Width: PARENT_WIDTH - 40 Width: PARENT_WIDTH - 40
Height: 45 Height: 40
Children: Children:
Label@TITLE: Label@TITLE:
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 25 Height: 15
Align: Center Align: Center
Font: Bold Font: Bold
Label@AUTHOR_DATETIME: Label@AUTHOR_DATETIME:
Y: 25 Y: 20
Width: PARENT_WIDTH Width: PARENT_WIDTH
Height: 15 Height: 15
Align: Center Align: Center
Font: TinyBold Font: TinyBold
Label@CONTENT: Label@CONTENT:
Y: 45 Y: 40
Width: PARENT_WIDTH Width: PARENT_WIDTH
Label@NEWS_STATUS: Label@NEWS_STATUS:
X: 80 X: 80
Y: 1
Width: PARENT_WIDTH - 80 - 80 - 24 Width: PARENT_WIDTH - 80 - 80 - 24
Height: PARENT_HEIGHT Height: PARENT_HEIGHT
Align: Center Align: Center