From 3322f34e7bdea0cf2f01215570eb455bdc81cb7c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 6 Sep 2015 18:55:59 +0100 Subject: [PATCH] Add game speed option for missions. --- .../Widgets/Logic/MissionBrowserLogic.cs | 70 ++++++++++++++----- mods/cnc/chrome/missionbrowser.yaml | 36 +++++++--- mods/d2k/chrome/missionbrowser.yaml | 35 +++++++--- mods/ra/chrome/missionbrowser.yaml | 37 +++++++--- 4 files changed, 134 insertions(+), 44 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index 1f2cfadb07..d2c2a23f06 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -30,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly LabelWidget description; readonly SpriteFont descriptionFont; readonly DropDownButtonWidget difficultyButton; + readonly DropDownButtonWidget gameSpeedButton; readonly ButtonWidget startBriefingVideoButton; readonly ButtonWidget stopBriefingVideoButton; readonly ButtonWidget startInfoVideoButton; @@ -46,6 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic PlayingVideo playingVideo; string difficulty; + string gameSpeed; [ObjectCreator.UseCtor] public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit) @@ -77,6 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic descriptionFont = Game.Renderer.Fonts[description.Font]; difficultyButton = widget.Get("DIFFICULTY_DROPDOWNBUTTON"); + gameSpeedButton = widget.GetOrNull("GAMESPEED_DROPDOWNBUTTON"); startBriefingVideoButton = widget.Get("START_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton = widget.Get("STOP_BRIEFING_VIDEO_BUTTON"); @@ -186,27 +189,57 @@ namespace OpenRA.Mods.Common.Widgets.Logic descriptionPanel.ScrollToTop(); descriptionPanel.Layout.AdjustChildren(); - difficultyButton.IsVisible = () => map.Options.Difficulties.Any(); - if (!map.Options.Difficulties.Any()) - return; - - difficulty = map.Options.Difficulties.First(); - difficultyButton.OnMouseDown = _ => + if (difficultyButton != null) { - var options = map.Options.Difficulties.Select(d => new DropDownOption + difficultyButton.IsDisabled = () => !map.Options.Difficulties.Any(); + + difficulty = map.Options.Difficulties.FirstOrDefault(); + difficultyButton.GetText = () => difficulty ?? "Normal"; + difficultyButton.OnMouseDown = _ => { - Title = d, - IsSelected = () => difficulty == d, - OnClick = () => difficulty = d - }); - Func setupItem = (option, template) => - { - var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); - item.Get("LABEL").GetText = () => option.Title; - return item; + var options = map.Options.Difficulties.Select(d => new DropDownOption + { + Title = d, + IsSelected = () => difficulty == d, + OnClick = () => difficulty = d + }); + + Func setupItem = (option, template) => + { + var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); + item.Get("LABEL").GetText = () => option.Title; + return item; + }; + + difficultyButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; - difficultyButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); - }; + } + + if (gameSpeedButton != null) + { + var speeds = Game.ModData.Manifest.Get().Speeds; + gameSpeed = "default"; + + gameSpeedButton.GetText = () => speeds[gameSpeed].Name; + gameSpeedButton.OnMouseDown = _ => + { + var options = speeds.Select(s => new DropDownOption + { + Title = s.Value.Name, + IsSelected = () => gameSpeed == s.Key, + OnClick = () => gameSpeed = s.Key + }); + + Func setupItem = (option, template) => + { + var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); + item.Get("LABEL").GetText = () => option.Title; + return item; + }; + + gameSpeedButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); + }; + } } float cachedSoundVolume; @@ -280,6 +313,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Action lobbyReady = null; lobbyReady = () => { + om.IssueOrder(Order.Command("gamespeed {0}".F(gameSpeed))); om.IssueOrder(Order.Command("difficulty {0}".F(difficulty))); Game.LobbyInfoChanged -= lobbyReady; onStart(); diff --git a/mods/cnc/chrome/missionbrowser.yaml b/mods/cnc/chrome/missionbrowser.yaml index b38435c7e2..e1ce1cb06e 100644 --- a/mods/cnc/chrome/missionbrowser.yaml +++ b/mods/cnc/chrome/missionbrowser.yaml @@ -21,7 +21,7 @@ Container@MISSIONBROWSER_PANEL: X: 15 Y: 15 Width: 239 - Height: 307 + Height: 347 Children: ScrollItem@HEADER: Width: PARENT_RIGHT-27 @@ -66,7 +66,7 @@ Container@MISSIONBROWSER_PANEL: ScrollPanel@MISSION_DESCRIPTION_PANEL: Y: 213 Width: PARENT_RIGHT - Height: 134 + Height: 99 Children: Label@MISSION_DESCRIPTION: X: 4 @@ -74,13 +74,31 @@ Container@MISSIONBROWSER_PANEL: Width: PARENT_RIGHT - 32 VAlign: Top Font: Small - DropDownButton@DIFFICULTY_DROPDOWNBUTTON: - X: 15 - Y: 337 - Width: 239 - Height: 25 - Text: Difficulty - Font: Regular + Label@DIFFICULTY_DESC: + Y: 322 + Width: 56 + Height: 25 + Text: Difficulty: + Align: Right + DropDownButton@DIFFICULTY_DROPDOWNBUTTON: + X: 61 + Y: 322 + Width: 120 + Height: 25 + Font: Regular + Label@GAMESPEED_DESC: + X: PARENT_RIGHT - WIDTH - 125 + Y: 322 + Width: 120 + Height: 25 + Text: Speed: + Align: Right + DropDownButton@GAMESPEED_DROPDOWNBUTTON: + X: PARENT_RIGHT - WIDTH + Y: 322 + Width: 120 + Height: 25 + Font: Regular Button@BACK_BUTTON: Y: 376 Width: 140 diff --git a/mods/d2k/chrome/missionbrowser.yaml b/mods/d2k/chrome/missionbrowser.yaml index 290406cc5a..d87e8394df 100644 --- a/mods/d2k/chrome/missionbrowser.yaml +++ b/mods/d2k/chrome/missionbrowser.yaml @@ -16,7 +16,7 @@ Background@MISSIONBROWSER_PANEL: X: 20 Y: 50 Width: 270 - Height: 542 + Height: 504 Children: ScrollItem@HEADER: BaseName: scrollheader @@ -39,6 +39,32 @@ Background@MISSIONBROWSER_PANEL: X: 10 Width: PARENT_RIGHT-20 Height: 25 + Label@DIFFICULTY_DESC: + X: 290 - WIDTH - 125 + Y: 567 + Width: 56 + Height: 25 + Text: Mission Difficulty: + Align: Right + DropDownButton@DIFFICULTY_DROPDOWNBUTTON: + X: 290 - WIDTH + Y: 567 + Width: 120 + Height: 25 + Font: Regular + Label@GAMESPEED_DESC: + X: 290 - WIDTH - 125 + Y: 607 + Width: 120 + Height: 25 + Text: Mission Speed: + Align: Right + DropDownButton@GAMESPEED_DROPDOWNBUTTON: + X: 290 - WIDTH + Y: 607 + Width: 120 + Height: 25 + Font: Regular Container@MISSION_INFO: X: 300 Y: 50 @@ -112,13 +138,6 @@ Background@MISSIONBROWSER_PANEL: Text: Back Font: Bold Key: escape - DropDownButton@DIFFICULTY_DROPDOWNBUTTON: - X: 20 - Y: 632 - HEIGHT - Width: 270 - Height: 25 - Text: Difficulty - Font: Bold Background@MISSION_BIN: X: 300 Y: 50 diff --git a/mods/ra/chrome/missionbrowser.yaml b/mods/ra/chrome/missionbrowser.yaml index 573016812a..b7a155a255 100644 --- a/mods/ra/chrome/missionbrowser.yaml +++ b/mods/ra/chrome/missionbrowser.yaml @@ -16,7 +16,7 @@ Background@MISSIONBROWSER_PANEL: X: 20 Y: 50 Width: 270 - Height: 332 + Height: 377 Children: ScrollItem@HEADER: BaseName: scrollheader @@ -61,7 +61,7 @@ Background@MISSIONBROWSER_PANEL: ScrollPanel@MISSION_DESCRIPTION_PANEL: Y: 212 Width: PARENT_RIGHT - Height: 165 + Height: 130 Children: Label@MISSION_DESCRIPTION: X: 4 @@ -69,6 +69,32 @@ Background@MISSIONBROWSER_PANEL: Width: PARENT_RIGHT - 32 VAlign: Top Font: Small + Label@DIFFICULTY_DESC: + Y: 352 + Width: 56 + Height: 25 + Text: Difficulty: + Align: Right + DropDownButton@DIFFICULTY_DROPDOWNBUTTON: + X: 61 + Y: 352 + Width: 120 + Height: 25 + Font: Regular + Label@GAMESPEED_DESC: + X: PARENT_RIGHT - WIDTH - 125 + Y: 352 + Width: 120 + Height: 25 + Text: Speed: + Align: Right + DropDownButton@GAMESPEED_DROPDOWNBUTTON: + X: PARENT_RIGHT - WIDTH + Y: 352 + Width: 120 + Height: 25 + Font: Regular + Button@START_BRIEFING_VIDEO_BUTTON: X: 20 Y: PARENT_BOTTOM - 45 @@ -112,13 +138,6 @@ Background@MISSIONBROWSER_PANEL: Text: Back Font: Bold Key: escape - DropDownButton@DIFFICULTY_DROPDOWNBUTTON: - X: 20 - Y: 427 - HEIGHT - Width: 270 - Height: 25 - Text: Difficulty - Font: Bold Background@MISSION_BIN: X: 20 Y: 50