Skip to content

Commit

Permalink
Extract version label chrome logic to a dedicated class
Browse files Browse the repository at this point in the history
  • Loading branch information
dragunoff authored and PunkPun committed Oct 3, 2024
1 parent fff41a4 commit c0839d4
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ public GameSaveLoadingLogic(Widget widget, ModData modData, World world)
{
widget.Get<ProgressBarWidget>("PROGRESS").GetPercentage = () => world.GameSaveLoadingPercentage;

var versionLabel = widget.GetOrNull<LabelWidget>("VERSION_LABEL");
if (versionLabel != null)
{
var versionText = modData.Manifest.Metadata.Version;
versionLabel.GetText = () => versionText;
}

var keyhandler = widget.Get<LogicKeyListenerWidget>("CANCEL_HANDLER");
keyhandler.AddHandler(e =>
{
Expand Down
3 changes: 0 additions & 3 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExi
mpe = world.WorldActor.TraitOrDefault<MenuPostProcessEffect>();
mpe?.Fade(mpe.Info.MenuEffect);

var versionText = modData.Manifest.Metadata.Version;
menu.Get<LabelWidget>("VERSION_LABEL").GetText = () => versionText;

buttonContainer = menu.Get("MENU_BUTTONS");
buttonTemplate = buttonContainer.Get<ButtonWidget>("BUTTON_TEMPLATE");
buttonContainer.RemoveChild(buttonTemplate);
Expand Down
2 changes: 0 additions & 2 deletions OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public MainMenuLogic(Widget widget, World world, ModData modData)
this.modData = modData;

rootMenu = widget;
var versionText = modData.Manifest.Metadata.Version;
rootMenu.Get<LabelWidget>("VERSION_LABEL").GetText = () => versionText;

// Menu buttons
var mainMenu = widget.Get("MAIN_MENU");
Expand Down
25 changes: 25 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/VersionLabelLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using OpenRA.Widgets;

namespace OpenRA.Mods.Common.Widgets.Logic
{
public class VersionLabelLogic : ChromeLogic
{
[ObjectCreator.UseCtor]
public VersionLabelLogic(LabelWidget widget, ModData modData)
{
var versionText = modData.Manifest.Metadata.Version;
widget.GetText = () => versionText;
}
}
}
1 change: 1 addition & 0 deletions mods/cnc/chrome/gamesave-loading.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Container@GAMESAVE_LOADING_SCREEN:
ImageCollection: logos
ImageName: eva
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 128 - 43
Y: 116
Width: 128
Expand Down
1 change: 1 addition & 0 deletions mods/cnc/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Container@INGAME_MENU:
ImageCollection: logos
ImageName: eva
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 128 - 43
Y: 116
Width: 128
Expand Down
1 change: 1 addition & 0 deletions mods/cnc/chrome/mainmenu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Container@MENU_BACKGROUND:
ImageCollection: logos
ImageName: eva
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 128 - 43
Y: 116
Width: 128
Expand Down
1 change: 1 addition & 0 deletions mods/common/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Container@INGAME_MENU:
ImageCollection: logos
ImageName: logo
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 296
Y: 296 - 19
Width: 296 - 20
Expand Down
1 change: 1 addition & 0 deletions mods/common/chrome/mainmenu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Container@MAINMENU:
ImageCollection: logos
ImageName: logo
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 296
Y: 296 - 20
Width: 296 - 20
Expand Down
1 change: 1 addition & 0 deletions mods/d2k/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Container@INGAME_MENU:
ButtonStride: 0, 40
Children:
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 10
Y: WINDOW_BOTTOM - 19
Align: Right
Expand Down
1 change: 1 addition & 0 deletions mods/d2k/chrome/mainmenu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Container@MAINMENU:
TakeScreenshotKey: TakeScreenshot
MuteAudioKey: ToggleMute
Label@VERSION_LABEL:
Logic: VersionLabelLogic
X: WINDOW_RIGHT - 10
Y: WINDOW_BOTTOM - 19
Align: Right
Expand Down

0 comments on commit c0839d4

Please sign in to comment.