Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add singleplayer mission menu to ra/td #5133

Merged
merged 1 commit into from
Apr 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ NEW:
Removed Mobile Radar Jammer's jamming effect for allied missiles.
Increased the HP of husks from 140 to 280.
Fixed incorrect Red Alert dialog corners.
Added a singleplayer mission menu.
Tiberian Dawn:
Engineers can now regain control over husks.
Chinook rotors now counter-rotate.
Expand Down Expand Up @@ -132,6 +133,7 @@ NEW:
The chance of artillery exploding on death has been reduced from 100% to 75%.
Fixed Chinook being unable to land on tiberium.
Commando will no longer shoot at vehicles or buildings.
Added a singleplayer mission menu.
Engine:
The contents of OpenRA.FileFormats.dll have been merged into OpenRA.Game.exe, and namespaces reorganized.
Converted Aircraft CruiseAltitude to world coordinates.
Expand Down
8 changes: 5 additions & 3 deletions OpenRA.Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public static class Game

public static DatabaseReader GeoIpDatabase;

public static void JoinServer(string host, int port, string password)
public static OrderManager JoinServer(string host, int port, string password)
{
JoinInner(new OrderManager(host, port, password,
new ReplayRecorderConnection(new NetworkConnection(host, port), ChooseReplayFilename)));
var om = new OrderManager(host, port, password,
new ReplayRecorderConnection(new NetworkConnection(host, port), ChooseReplayFilename));
JoinInner(om);
return om;
}

static string ChooseReplayFilename()
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Game/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Manifest
Folders, MapFolders, Rules, ServerTraits,
Sequences, VoxelSequences, Cursors, Chrome, Assemblies, ChromeLayout,
Weapons, Voices, Notifications, Music, Movies, Translations, TileSets,
ChromeMetrics, PackageContents, LuaScripts, MapCompatibility;
ChromeMetrics, PackageContents, LuaScripts, MapCompatibility, Missions;

public readonly Dictionary<string, string> Packages;
public readonly MiniYaml LoadScreen;
Expand Down Expand Up @@ -62,6 +62,7 @@ public Manifest(string mod)
ChromeMetrics = YamlList(yaml, "ChromeMetrics");
PackageContents = YamlList(yaml, "PackageContents");
LuaScripts = YamlList(yaml, "LuaScripts");
Missions = YamlList(yaml, "Missions");

LoadScreen = yaml["LoadScreen"];
LobbyDefaults = yaml["LobbyDefaults"];
Expand Down
1 change: 1 addition & 0 deletions OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
25 changes: 23 additions & 2 deletions OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/
#endregion

using System.Linq;
using System.Net;
using OpenRA.Widgets;

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;
Expand All @@ -30,7 +31,7 @@ public MainMenuLogic(Widget widget, World world)
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 = () =>
{
Expand Down Expand Up @@ -61,6 +62,26 @@ public MainMenuLogic(Widget widget, World world)

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;
Expand Down
110 changes: 110 additions & 0 deletions OpenRA.Mods.RA/Widgets/Logic/MissionBrowserLogic.cs
Original file line number Diff line number Diff line change
@@ -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), "");
}
}
}
32 changes: 32 additions & 0 deletions mods/cnc/chrome/mainmenu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,38 @@ Container@MENU_BACKGROUND:
Width:140
Height:35
Text:Quit
Container@SINGLEPLAYER_MENU:
Width:PARENT_RIGHT
Visible:False
Children:
Label@SINGLEPLAYER_MENU_TITLE:
X:0
Y:0-30
Width:PARENT_RIGHT
Height:20
Text:Singleplayer
Align:Center
Font:Bold
Contrast:True
Button@SKIRMISH_BUTTON:
X:150
Y:0
Width:140
Height:35
Text:Skirmish
Button@MISSIONS_BUTTON:
X:300
Y:0
Width:140
Height:35
Text:Missions
Button@BACK_BUTTON:
Key:escape
X:600
Y:0
Width:140
Height:35
Text:Back
Container@EXTRAS_MENU:
Width:PARENT_RIGHT
Visible:False
Expand Down
82 changes: 82 additions & 0 deletions mods/cnc/chrome/missionbrowser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Container@MISSIONBROWSER_PANEL:
Logic:MissionBrowserLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:629
Height:399
Children:
Label@MISSIONBROWSER_LABEL_TITLE:
Y:0-25
Width:PARENT_RIGHT
Text:Missions
Align:Center
Font:BigBold
Background@BG:
Width:629
Height:360
Background:panel-black
Children:
ScrollPanel@MISSION_LIST:
X:15
Y:15
Width:260
Height:330
Children:
ScrollItem@MISSION_TEMPLATE:
Width:PARENT_RIGHT-27
Height:25
X:2
Y:0
Visible:False
Children:
Label@TITLE:
X:10
Width:PARENT_RIGHT-20
Height:25
Container@MISSION_INFO:
X:290
Y:15
Width:324
Height:334
Children:
Background@MISSION_BG:
X:0
Y:0
Width:324
Height:160
Background:panel-gray
Children:
MapPreview@MISSION_PREVIEW:
X:2
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
IgnoreMouseOver:True
IgnoreMouseInput:True
ShowSpawnPoints:False
ScrollPanel@MISSION_DESCRIPTION_PANEL:
X:0
Y:171
Width:324
Height:159
Children:
Label@MISSION_DESCRIPTION:
X:5
Y:5
Width:290
VAlign:Top
Button@BACK_BUTTON:
X:0
Y:359
Width:140
Height:35
Text:Back
Font:Bold
Key:escape
Button@STARTGAME_BUTTON:
X:PARENT_RIGHT - 140
Y:359
Width:140
Height:35
Text:Start Game
Font:Bold
Binary file added mods/cnc/maps/gdi01/map.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions mods/cnc/maps/gdi01/map.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Selectable: True
Selectable: False

MapFormat: 6

RequiresMod: cnc

Title: Storm the Beachhead

Description: Conversion of the first GDI Mission
Description: Use the units provided to protect the Mobile Construction Vehicle. (MCV)\n\nYou should then deploy the MCV by double clicking on it.\n\nThen you can begin to build up a base. Start with a Power Plant.\n\nFinally, search out and destroy all enemy Nod units in the surrounding area.

Author: Westwood Studios

Expand Down
Binary file added mods/cnc/maps/gdi02/map.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion mods/cnc/maps/gdi02/map.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Selectable: True
Selectable: False

MapFormat: 6

RequiresMod: cnc

Title: Knock out the Refinery

Description: Defend your position, deploy the MCV, then build a sizable force to search out and destroy the Nod base in the area.\n\nAll Nod units and structures must be either destroyed or captured to complete objective.

Author: Westwood Studios

Tileset: TEMPERAT
Expand Down
Binary file added mods/cnc/maps/gdi03/map.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions mods/cnc/maps/gdi03/map.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Selectable: True
Selectable: False

MapFormat: 6

RequiresMod: cnc

Title: Destroy The SAM Sites

Description: Build up forces to destroy Nod base. Once all Nod SAM sites are neutralized then air support will be provided to combat obstacles such as turrets. Destroy all units and structures to complete the mission objective.
Description: Build up forces to destroy Nod base.\n\nOnce all Nod SAM sites are neutralized then air support will be provided to combat obstacles such as turrets.\n\nDestroy all units and structures to complete the mission objective.

Author: Westwood Studios

Expand Down
Binary file added mods/cnc/maps/gdi04a/map.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.