Add singleplayer mission menu to ra/td

This commit is contained in:
ScottNZ
2014-04-18 22:12:00 +12:00
parent abe06b24b4
commit 22dd2b0a92
35 changed files with 443 additions and 23 deletions

View File

@@ -381,6 +381,7 @@
<Compile Include="Widgets\BuildPaletteWidget.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
<Compile Include="Widgets\Logic\KickSpectatorsLogic.cs" />
<Compile Include="Widgets\Logic\MissionBrowserLogic.cs" />
<Compile Include="Widgets\Logic\IngameMenuLogic.cs" />
<Compile Include="Widgets\Logic\IrcLogic.cs" />
<Compile Include="Widgets\Logic\KickClientLogic.cs" />

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Linq;
using System.Net;
using OpenRA.Widgets;
@@ -15,7 +16,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MainMenuLogic
{
protected enum MenuType { Main, Extras, None }
protected enum MenuType { Main, Singleplayer, Extras, None }
protected MenuType menuType = MenuType.Main;
Widget rootMenu;
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var mainMenu = widget.Get("MAIN_MENU");
mainMenu.IsVisible = () => menuType == MenuType.Main;
mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = StartSkirmishGame;
mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = () => menuType = MenuType.Singleplayer;
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () =>
{
@@ -61,6 +62,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
// Singleplayer menu
var singleplayerMenu = widget.Get("SINGLEPLAYER_MENU");
singleplayerMenu.IsVisible = () => menuType == MenuType.Singleplayer;
var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON");
missionsButton.OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Singleplayer },
{ "onStart", RemoveShellmapUI }
});
};
missionsButton.Disabled = !Game.modData.Manifest.Missions.Any();
singleplayerMenu.Get<ButtonWidget>("SKIRMISH_BUTTON").OnClick = StartSkirmishGame;
singleplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
// Extras menu
var extrasMenu = widget.Get("EXTRAS_MENU");
extrasMenu.IsVisible = () => menuType == MenuType.Extras;

View File

@@ -0,0 +1,110 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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.IO;
using System.Linq;
using System.Net;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MissionBrowserLogic
{
readonly Action onStart;
readonly ScrollPanelWidget descriptionPanel;
readonly LabelWidget description;
readonly SpriteFont descriptionFont;
MapPreview selectedMapPreview;
[ObjectCreator.UseCtor]
public MissionBrowserLogic(Widget widget, Action onStart, Action onExit)
{
this.onStart = onStart;
var missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
var template = widget.Get<ScrollItemWidget>("MISSION_TEMPLATE");
widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
previewWidget.Preview = () => selectedMapPreview;
descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL");
description = widget.Get<LabelWidget>("MISSION_DESCRIPTION");
descriptionFont = Game.Renderer.Fonts[description.Font];
var yaml = new MiniYaml(null, Game.modData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal)).NodesDict;
var missionMapPaths = yaml["Missions"].Nodes.Select(n => Path.GetFullPath(n.Key));
var maps = Game.modData.MapCache
.Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Map.Path)))
.Select(p => p.Map);
missionList.RemoveChildren();
foreach (var m in maps)
{
var map = m;
var item = ScrollItemWidget.Setup(template,
() => selectedMapPreview != null && selectedMapPreview.Uid == map.Uid,
() => SelectMap(map),
StartMission);
item.Get<LabelWidget>("TITLE").GetText = () => map.Title;
missionList.AddChild(item);
}
if (maps.Any())
SelectMap(maps.First());
widget.Get<ButtonWidget>("STARTGAME_BUTTON").OnClick = StartMission;
widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{
Game.Disconnect();
Ui.CloseWindow();
onExit();
};
}
void SelectMap(Map map)
{
selectedMapPreview = Game.modData.MapCache[map.Uid];
var text = map.Description != null ? map.Description.Replace("\\n", "\n") : "";
text = WidgetUtils.WrapText(text, description.Bounds.Width, descriptionFont);
description.Text = text;
description.Bounds.Height = descriptionFont.Measure(text).Y;
descriptionPanel.Layout.AdjustChildren();
}
void StartMission()
{
OrderManager om = null;
Action lobbyReady = null;
lobbyReady = () =>
{
Game.LobbyInfoChanged -= lobbyReady;
onStart();
om.IssueOrder(Order.Command("state {0}".F(Session.ClientState.Ready)));
};
Game.LobbyInfoChanged += lobbyReady;
om = Game.JoinServer(IPAddress.Loopback.ToString(), Game.CreateLocalServer(selectedMapPreview.Uid), "");
}
}
}