diff --git a/OpenRA.FileFormats/Mod.cs b/OpenRA.FileFormats/Mod.cs index d12f9e72de..b2c80f3666 100644 --- a/OpenRA.FileFormats/Mod.cs +++ b/OpenRA.FileFormats/Mod.cs @@ -18,6 +18,7 @@ namespace OpenRA.FileFormats { public class Mod { + public string Id; public string Title; public string Description; public string Version; @@ -40,6 +41,7 @@ namespace OpenRA.FileFormats continue; ret.Add(m, FieldLoader.Load(yaml.NodesDict["Metadata"])); + ret[m].Id = m; } return ret; } diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index a09be31a4d..beca7c62e1 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -82,6 +82,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs index 0da650442a..aeb45e82a1 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs @@ -44,7 +44,14 @@ namespace OpenRA.Mods.Cnc.Widgets panel.GetWidget("QUIT_BUTTON").OnClick = Game.Exit; // TODO: - panel.GetWidget("MODS_BUTTON").IsDisabled = () => true; + panel.GetWidget("MODS_BUTTON").OnClick = () => + { + Widget.OpenWindow("MODS_PANEL", new Dictionary() + { + { "onExit", new Action(Widget.CloseWindow) }, + { "onSwitch", new Action(Widget.CloseWindow) }, + }); + }; } } diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs index 4be5310c24..35b7528104 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs @@ -98,13 +98,22 @@ namespace OpenRA.Mods.Cnc.Widgets var settingsMenu = widget.GetWidget("SETTINGS_MENU"); settingsMenu.IsVisible = () => Menu == MenuType.Settings; - settingsMenu.GetWidget("MODS_BUTTON").IsDisabled = () => true; + settingsMenu.GetWidget("MODS_BUTTON").OnClick = () => + { + Menu = MenuType.None; + Widget.OpenWindow("MODS_PANEL", new Dictionary() + { + { "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, + { "onSwitch", new Action(RemoveShellmapUI) } + }); + }; + settingsMenu.GetWidget("MUSIC_BUTTON").OnClick = () => { Menu = MenuType.None; Widget.OpenWindow("MUSIC_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Main)) }, + { "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs new file mode 100644 index 0000000000..b2d5633963 --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs @@ -0,0 +1,88 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * 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. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Mods.RA.Widgets.Delegates; +using OpenRA.Server; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public class CncModBrowserLogic : IWidgetDelegate + { + Mod currentMod; + + [ObjectCreator.UseCtor] + public CncModBrowserLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] Action onSwitch, + [ObjectCreator.Param] Action onExit) + { + var panel = widget.GetWidget("MODS_PANEL"); + var modList = panel.GetWidget("MOD_LIST"); + var loadButton = panel.GetWidget("LOAD_BUTTON"); + loadButton.OnClick = () => + { + // TODO: This is crap + var mods = new List() { currentMod.Id }; + var m = currentMod; + while (!string.IsNullOrEmpty(m.Requires)) + { + m = Mod.AllMods[currentMod.Requires]; + mods.Add(m.Id); + } + + Game.RunAfterTick(() => + { + Widget.CloseWindow(); + onSwitch(); + Game.InitializeWithMods(mods.ToArray()); + }); + }; + loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First(); + + panel.GetWidget("BACK_BUTTON").OnClick = onExit; + currentMod = Mod.AllMods[Game.modData.Manifest.Mods[0]]; + + // Mod list + var modTemplate = modList.GetWidget("MOD_TEMPLATE"); + + foreach (var m in Mod.AllMods) + { + var mod = m.Value; + var template = modTemplate.Clone() as ContainerWidget; + template.GetBackground = () => (template.RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" : (currentMod == mod) ? "button-pressed" : null); + template.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; currentMod = mod; return true; }; + template.IsVisible = () => true; + template.GetWidget("TITLE").GetText = () => mod.Title; + template.GetWidget("VERSION").GetText = () => mod.Version; + template.GetWidget("AUTHOR").GetText = () => mod.Author; + modList.AddChild(template); + } + + + /* + // Server info + var infoPanel = panel.GetWidget("SERVER_INFO"); + infoPanel.IsVisible = () => currentServer != null; + infoPanel.GetWidget("SERVER_IP").GetText = () => currentServer.Address; + infoPanel.GetWidget("SERVER_MODS").GetText = () => ServerBrowserDelegate.GenerateModsLabel(currentServer); + infoPanel.GetWidget("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown"; + infoPanel.GetWidget("MAP_PLAYERS").GetText = () => GetPlayersLabel(currentServer); + */ + } + } +} diff --git a/mods/cnc/chrome/modchooser.yaml b/mods/cnc/chrome/modchooser.yaml new file mode 100644 index 0000000000..e1cd0de76d --- /dev/null +++ b/mods/cnc/chrome/modchooser.yaml @@ -0,0 +1,94 @@ +Container@MODS_PANEL: + Id:MODS_PANEL + Delegate:CncModBrowserLogic + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - 500)/2 + Width:740 + Height:535 + Children: + Label@TITLE: + Text:Select Mod + Width:740 + Y:0-25 + Font:BigBold + Contrast:true + Align:Center + Background@bg: + Width:740 + Height:500 + Background:panel-black + Children: + CncScrollPanel@MOD_LIST: + Id:MOD_LIST + X:15 + Y:30 + Width:710 + Height:455 + Children: + Container@MOD_TEMPLATE: + Id:MOD_TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@TITLE: + X:10 + Id:TITLE + Width:200 + Height:25 + Label@AUTHOR: + Id:AUTHOR + X:PARENT_RIGHT-300 + Align:Center + Width:50 + Height:25 + Label@VERSION: + Id:VERSION + Width:140 + X:PARENT_RIGHT-150 + Align:Center + Height:25 + Container@MOD_LABELS: + Width:710-25 + Height:25 + X:15 + Y:5 + Children: + Label@TITLE: + Width:125 + Height:25 + X:0 + Y:0 + Text:Title + Align:Center + Font:Bold + Label@AUTHOR: + X:PARENT_RIGHT-300 + Align:Center + Width:50 + Height:25 + Text:Author + Font:Bold + Label@VERSION: + Width:140 + X:PARENT_RIGHT-150 + Align:Center + Height:25 + Text:Version + Font:Bold + CncMenuButton@BACK_BUTTON: + Id:BACK_BUTTON + X:0 + Y:499 + Width:140 + Height:35 + Text:Back + CncMenuButton@LOAD_BUTTON: + Id:LOAD_BUTTON + X:600 + Y:499 + Width:140 + Height:35 + Text:Load Mod \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 5174895fd1..64000646d5 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -73,6 +73,7 @@ ChromeLayout: mods/cnc/chrome/ingame.yaml mods/cnc/chrome/ingamemenu.yaml mods/cnc/chrome/music.yaml + mods/cnc/chrome/modchooser.yaml Weapons: mods/cnc/weapons.yaml