Map chooser
This commit is contained in:
@@ -30,7 +30,8 @@ namespace OpenRA.FileFormats
|
||||
public class Map
|
||||
{
|
||||
public IFolder Package;
|
||||
|
||||
public string Uid;
|
||||
|
||||
// Yaml map data
|
||||
public int MapFormat = 1;
|
||||
public string Title;
|
||||
@@ -63,7 +64,7 @@ namespace OpenRA.FileFormats
|
||||
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
|
||||
|
||||
static List<string> SimpleFields = new List<string>() {
|
||||
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
|
||||
"Uid", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
|
||||
};
|
||||
|
||||
public Map() {}
|
||||
|
||||
62
OpenRA.FileFormats/Map/MapStub.cs
Normal file
62
OpenRA.FileFormats/Map/MapStub.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it 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.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public class MapStub
|
||||
{
|
||||
public IFolder Package;
|
||||
|
||||
// Yaml map data
|
||||
public string Uid;
|
||||
public string Title;
|
||||
public string Description;
|
||||
public string Author;
|
||||
public int PlayerCount;
|
||||
public string Preview;
|
||||
public string Tileset;
|
||||
|
||||
public int2 TopLeft;
|
||||
public int2 BottomRight;
|
||||
public int Width {get {return BottomRight.X - TopLeft.X;}}
|
||||
public int Height {get {return BottomRight.Y - TopLeft.Y;}}
|
||||
|
||||
static List<string> Fields = new List<string>() {
|
||||
"Uid", "Title", "Description", "Author", "PlayerCount", "Tileset", "Preview", "TopLeft", "BottomRight"
|
||||
};
|
||||
|
||||
public MapStub() {}
|
||||
|
||||
public MapStub(IFolder package)
|
||||
{
|
||||
Package = package;
|
||||
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
|
||||
|
||||
FieldLoader.LoadFields(this,yaml,Fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,7 @@
|
||||
<Compile Include="FileFormats\IniFile.cs" />
|
||||
<Compile Include="Graphics\ShpReader.cs" />
|
||||
<Compile Include="Primitives\int2.cs" />
|
||||
<Compile Include="Map\MapStub.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -258,32 +258,11 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
class MapInfo
|
||||
{
|
||||
public readonly string Filename;
|
||||
public readonly Map Map;
|
||||
|
||||
public MapInfo(string filename)
|
||||
{
|
||||
Filename = filename.ToLowerInvariant();
|
||||
Map = new Map(Filename);
|
||||
}
|
||||
};
|
||||
|
||||
Lazy<List<MapInfo>> mapList = Lazy.New(
|
||||
() =>
|
||||
{
|
||||
var builtinMaps = new IniFile(FileSystem.Open("missions.pkt")).GetSection("Missions").Select(a => a.Key);
|
||||
var mapsFolderMaps = Directory.GetFiles("maps/");
|
||||
return builtinMaps.Concat(mapsFolderMaps).Select(a => new MapInfo(a)).ToList();
|
||||
});
|
||||
|
||||
|
||||
bool showMapChooser = false;
|
||||
MapInfo currentMap;
|
||||
MapStub currentMap;
|
||||
bool mapPreviewDirty = true;
|
||||
*/
|
||||
|
||||
void AddUiButton(int2 pos, string text, Action<bool> a)
|
||||
{
|
||||
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
|
||||
@@ -294,7 +273,7 @@ namespace OpenRA
|
||||
|
||||
public void DrawMapChooser()
|
||||
{
|
||||
/*var w = 800;
|
||||
var w = 800;
|
||||
var h = 600;
|
||||
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
|
||||
DrawDialogBackground(r, "dialog");
|
||||
@@ -302,11 +281,11 @@ namespace OpenRA
|
||||
|
||||
DrawDialogBackground(new Rectangle(r.Right - 200 - 160 / 2,
|
||||
r.Bottom - 50 + 6, 160, 24), "dialog2");
|
||||
|
||||
|
||||
AddUiButton(new int2(r.Left + 200, r.Bottom - 40), "OK",
|
||||
_ =>
|
||||
{
|
||||
Game.IssueOrder(Order.Chat("/map " + currentMap.Filename));
|
||||
Game.IssueOrder(Order.Chat("/map " + currentMap.Uid));
|
||||
showMapChooser = false;
|
||||
});
|
||||
|
||||
@@ -315,7 +294,7 @@ namespace OpenRA
|
||||
{
|
||||
showMapChooser = false;
|
||||
});
|
||||
|
||||
/*
|
||||
if (mapPreviewDirty)
|
||||
{
|
||||
if (mapChooserSheet == null || mapChooserSheet.Size.Width != currentMap.Map.MapSize.X || mapChooserSheet.Size.Height != currentMap.Map.MapSize.Y)
|
||||
@@ -327,46 +306,53 @@ namespace OpenRA
|
||||
Minimap.MakeMinimapBounds(currentMap.Map), TextureChannel.Alpha);
|
||||
mapPreviewDirty = false;
|
||||
}
|
||||
|
||||
*/
|
||||
var mapRect = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
|
||||
/*
|
||||
DrawDialogBackground(mapRect, "dialog2");
|
||||
rgbaRenderer.DrawSprite(mapChooserSprite,
|
||||
new float2(mapRect.Location) + new float2(4, 4),
|
||||
"chrome",
|
||||
new float2(mapRect.Size) - new float2(8, 8));
|
||||
rgbaRenderer.Flush();
|
||||
|
||||
*/
|
||||
var y = r.Top + 50;
|
||||
|
||||
int maxListItems = ((r.Bottom - 60 - y ) / 20);
|
||||
|
||||
for(int i = mapOffset; i < Math.Min(maxListItems + mapOffset, mapList.Value.Count()); i++, y += 20){
|
||||
|
||||
var map = mapList.Value.ElementAt(i);
|
||||
//for(int i = mapOffset; i < Math.Min(maxListItems + mapOffset, Game.AvailableMaps.Count()); i++, y += 20)
|
||||
|
||||
// TODO: Show the appropriate subset of data
|
||||
foreach (var kv in Game.AvailableMaps)
|
||||
{
|
||||
var map = kv.Value;
|
||||
var itemRect = new Rectangle(r.Left + 50, y - 2, r.Width - 340, 20);
|
||||
if (map == currentMap)
|
||||
DrawDialogBackground(itemRect, "dialog2");
|
||||
|
||||
renderer.RegularFont.DrawText(rgbaRenderer, map.Map.Title, new int2(r.Left + 60, y), Color.White);
|
||||
renderer.RegularFont.DrawText(rgbaRenderer, map.Title, new int2(r.Left + 60, y), Color.White);
|
||||
var closureMap = map;
|
||||
AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; });
|
||||
|
||||
y += 20;
|
||||
}
|
||||
|
||||
y = mapRect.Bottom + 20;
|
||||
DrawCentered("Title: {0}".F(currentMap.Map.Title, currentMap.Map.Height),
|
||||
DrawCentered("Title: {0}".F(currentMap.Title),
|
||||
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||
y += 20;
|
||||
DrawCentered("Size: {0}x{1}".F(currentMap.Map.Width, currentMap.Map.Height),
|
||||
DrawCentered("Size: {0}x{1}".F(currentMap.Width, currentMap.Height),
|
||||
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||
y += 20;
|
||||
|
||||
var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Map.Theater);
|
||||
DrawCentered("Theater: {0}".F(theaterInfo.Name, currentMap.Map.Height),
|
||||
var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Tileset);
|
||||
DrawCentered("Theater: {0}".F(theaterInfo.Name),
|
||||
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||
y += 20;
|
||||
DrawCentered("Spawnpoints: {0}".F(currentMap.Map.SpawnPoints.Count()),
|
||||
DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount),
|
||||
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||
|
||||
|
||||
/*
|
||||
y += 30;
|
||||
AddUiButton(new int2(mapRect.Left + mapRect.Width / 2, y), "^",
|
||||
_ =>
|
||||
@@ -380,9 +366,8 @@ namespace OpenRA
|
||||
{
|
||||
mapOffset = (mapOffset + 1 > mapList.Value.Count() - maxListItems) ? mapOffset : mapOffset + 1;
|
||||
});
|
||||
|
||||
AddButton(r, _ => { });
|
||||
*/
|
||||
AddButton(r, _ => { });
|
||||
}
|
||||
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
|
||||
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||
@@ -439,13 +424,12 @@ namespace OpenRA
|
||||
{
|
||||
buttons.Clear();
|
||||
DrawDownloadBar();
|
||||
/*
|
||||
|
||||
if (showMapChooser)
|
||||
{
|
||||
DrawMapChooser();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
var w = 800;
|
||||
var h = 600;
|
||||
@@ -459,19 +443,18 @@ namespace OpenRA
|
||||
world.Minimap.Update();
|
||||
world.Minimap.Draw(minimapRect, true);
|
||||
world.Minimap.DrawSpawnPoints(minimapRect);
|
||||
/*
|
||||
|
||||
if (Game.IsHost)
|
||||
{
|
||||
AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map",
|
||||
_ =>
|
||||
{
|
||||
showMapChooser = true;
|
||||
currentMap = mapList.Value.Single(
|
||||
m => m.Filename == Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant());
|
||||
showMapChooser = true;
|
||||
currentMap = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant()];
|
||||
mapPreviewDirty = true;
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
var f = renderer.BoldFont;
|
||||
f.DrawText(rgbaRenderer, "Name", new int2(r.Left + 40, r.Top + 50), Color.White);
|
||||
|
||||
@@ -100,12 +100,42 @@ namespace OpenRA
|
||||
throw new InvalidOperationException("Cannot locate type: {0}".F(classname));
|
||||
}
|
||||
|
||||
public static Dictionary<string,MapStub> AvailableMaps;
|
||||
|
||||
// TODO: Do this nicer
|
||||
public static Dictionary<string,MapStub> FindMaps(string[] mods)
|
||||
{
|
||||
Console.WriteLine("Finding maps");
|
||||
foreach (var mod in mods)
|
||||
Console.WriteLine(mod);
|
||||
|
||||
|
||||
List<string> paths = new List<string>();
|
||||
foreach (var mod in mods)
|
||||
paths.AddRange(Directory.GetDirectories("mods/"+mod+"/maps/"));
|
||||
|
||||
paths.AddRange(Directory.GetDirectories("maps/"));
|
||||
|
||||
Dictionary<string,MapStub> maps = new Dictionary<string, MapStub>();
|
||||
foreach (var path in paths)
|
||||
{
|
||||
MapStub stub = new MapStub(new Folder(path));
|
||||
maps.Add(stub.Uid,stub);
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
public static void ChangeMap(string mapName)
|
||||
{
|
||||
Timer.Time( "----ChangeMap" );
|
||||
|
||||
|
||||
var manifest = new Manifest(LobbyInfo.GlobalSettings.Mods);
|
||||
Timer.Time( "manifest: {0}" );
|
||||
|
||||
// TODO: Only do this on mod change
|
||||
AvailableMaps = FindMaps(LobbyInfo.GlobalSettings.Mods);
|
||||
Timer.Time( "maplist: {0}" );
|
||||
|
||||
Game.LoadModAssemblies(manifest);
|
||||
Game.changePending = false;
|
||||
Game.mapName = mapName;
|
||||
@@ -133,7 +163,7 @@ namespace OpenRA
|
||||
|
||||
Timer.Time( "----end ChangeMap" );
|
||||
Debug("Map change {0} -> {1}".F(Game.mapName, mapName));
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer, Controller controller)
|
||||
{
|
||||
|
||||
@@ -74,32 +74,12 @@ namespace OpenRA
|
||||
|
||||
public readonly WorldRenderer WorldRenderer;
|
||||
internal readonly Minimap Minimap;
|
||||
|
||||
|
||||
public World()
|
||||
{
|
||||
Timer.Time( "----World.ctor" );
|
||||
|
||||
// TODO: Do this properly
|
||||
string mapPath = null;
|
||||
foreach (var mod in Game.LobbyInfo.GlobalSettings.Mods)
|
||||
{
|
||||
var path = "mods/"+mod+"/maps/"+Game.LobbyInfo.GlobalSettings.Map+"/";
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
mapPath = path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mapPath == null)
|
||||
{
|
||||
var path = "maps/"+Game.LobbyInfo.GlobalSettings.Map+"/";
|
||||
if (!Directory.Exists(path))
|
||||
throw new InvalidDataException("Unknown map `{0}`".F(Game.LobbyInfo.GlobalSettings.Map));
|
||||
mapPath = path;
|
||||
}
|
||||
Map = new Map( new Folder(mapPath) );
|
||||
|
||||
|
||||
Map = new Map( Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Package );
|
||||
customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
|
||||
Timer.Time( "new Map: {0}" );
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
MapFormat: 1
|
||||
Uid: testmap
|
||||
Title: GDI Mission 2
|
||||
Author: Westwood Studios
|
||||
PlayerCount: 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
MapFormat: 1
|
||||
|
||||
Uid: testmap
|
||||
Title: Lesson in Blood
|
||||
|
||||
Author: Westwood Studios
|
||||
|
||||
Reference in New Issue
Block a user