Map chooser
This commit is contained in:
@@ -30,6 +30,7 @@ namespace OpenRA.FileFormats
|
|||||||
public class Map
|
public class Map
|
||||||
{
|
{
|
||||||
public IFolder Package;
|
public IFolder Package;
|
||||||
|
public string Uid;
|
||||||
|
|
||||||
// Yaml map data
|
// Yaml map data
|
||||||
public int MapFormat = 1;
|
public int MapFormat = 1;
|
||||||
@@ -63,7 +64,7 @@ namespace OpenRA.FileFormats
|
|||||||
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
|
public IEnumerable<int2> SpawnPoints {get {return Waypoints.Select(kv => kv.Value);}}
|
||||||
|
|
||||||
static List<string> SimpleFields = new List<string>() {
|
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() {}
|
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="FileFormats\IniFile.cs" />
|
||||||
<Compile Include="Graphics\ShpReader.cs" />
|
<Compile Include="Graphics\ShpReader.cs" />
|
||||||
<Compile Include="Primitives\int2.cs" />
|
<Compile Include="Primitives\int2.cs" />
|
||||||
|
<Compile Include="Map\MapStub.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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;
|
bool showMapChooser = false;
|
||||||
MapInfo currentMap;
|
MapStub currentMap;
|
||||||
bool mapPreviewDirty = true;
|
bool mapPreviewDirty = true;
|
||||||
*/
|
|
||||||
void AddUiButton(int2 pos, string text, Action<bool> a)
|
void AddUiButton(int2 pos, string text, Action<bool> a)
|
||||||
{
|
{
|
||||||
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
|
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
|
||||||
@@ -294,7 +273,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void DrawMapChooser()
|
public void DrawMapChooser()
|
||||||
{
|
{
|
||||||
/*var w = 800;
|
var w = 800;
|
||||||
var h = 600;
|
var h = 600;
|
||||||
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
|
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
|
||||||
DrawDialogBackground(r, "dialog");
|
DrawDialogBackground(r, "dialog");
|
||||||
@@ -306,7 +285,7 @@ namespace OpenRA
|
|||||||
AddUiButton(new int2(r.Left + 200, r.Bottom - 40), "OK",
|
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;
|
showMapChooser = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -315,7 +294,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
showMapChooser = false;
|
showMapChooser = false;
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
if (mapPreviewDirty)
|
if (mapPreviewDirty)
|
||||||
{
|
{
|
||||||
if (mapChooserSheet == null || mapChooserSheet.Size.Width != currentMap.Map.MapSize.X || mapChooserSheet.Size.Height != currentMap.Map.MapSize.Y)
|
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);
|
Minimap.MakeMinimapBounds(currentMap.Map), TextureChannel.Alpha);
|
||||||
mapPreviewDirty = false;
|
mapPreviewDirty = false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
var mapRect = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
|
var mapRect = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
|
||||||
|
/*
|
||||||
DrawDialogBackground(mapRect, "dialog2");
|
DrawDialogBackground(mapRect, "dialog2");
|
||||||
rgbaRenderer.DrawSprite(mapChooserSprite,
|
rgbaRenderer.DrawSprite(mapChooserSprite,
|
||||||
new float2(mapRect.Location) + new float2(4, 4),
|
new float2(mapRect.Location) + new float2(4, 4),
|
||||||
"chrome",
|
"chrome",
|
||||||
new float2(mapRect.Size) - new float2(8, 8));
|
new float2(mapRect.Size) - new float2(8, 8));
|
||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
|
*/
|
||||||
var y = r.Top + 50;
|
var y = r.Top + 50;
|
||||||
|
|
||||||
int maxListItems = ((r.Bottom - 60 - y ) / 20);
|
int maxListItems = ((r.Bottom - 60 - y ) / 20);
|
||||||
|
|
||||||
for(int i = mapOffset; i < Math.Min(maxListItems + mapOffset, mapList.Value.Count()); i++, y += 20){
|
//for(int i = mapOffset; i < Math.Min(maxListItems + mapOffset, Game.AvailableMaps.Count()); i++, y += 20)
|
||||||
|
|
||||||
var map = mapList.Value.ElementAt(i);
|
// 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);
|
var itemRect = new Rectangle(r.Left + 50, y - 2, r.Width - 340, 20);
|
||||||
if (map == currentMap)
|
if (map == currentMap)
|
||||||
DrawDialogBackground(itemRect, "dialog2");
|
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;
|
var closureMap = map;
|
||||||
AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; });
|
AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; });
|
||||||
|
|
||||||
|
y += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
y = mapRect.Bottom + 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);
|
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||||
y += 20;
|
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);
|
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||||
y += 20;
|
y += 20;
|
||||||
|
|
||||||
var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Map.Theater);
|
var theaterInfo = Game.world.WorldActor.Info.Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Tileset);
|
||||||
DrawCentered("Theater: {0}".F(theaterInfo.Name, currentMap.Map.Height),
|
DrawCentered("Theater: {0}".F(theaterInfo.Name),
|
||||||
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||||
y += 20;
|
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);
|
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
|
||||||
|
|
||||||
|
/*
|
||||||
y += 30;
|
y += 30;
|
||||||
AddUiButton(new int2(mapRect.Left + mapRect.Width / 2, y), "^",
|
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;
|
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 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); }
|
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||||
@@ -439,13 +424,12 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
buttons.Clear();
|
buttons.Clear();
|
||||||
DrawDownloadBar();
|
DrawDownloadBar();
|
||||||
/*
|
|
||||||
if (showMapChooser)
|
if (showMapChooser)
|
||||||
{
|
{
|
||||||
DrawMapChooser();
|
DrawMapChooser();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
var w = 800;
|
var w = 800;
|
||||||
var h = 600;
|
var h = 600;
|
||||||
@@ -459,19 +443,18 @@ namespace OpenRA
|
|||||||
world.Minimap.Update();
|
world.Minimap.Update();
|
||||||
world.Minimap.Draw(minimapRect, true);
|
world.Minimap.Draw(minimapRect, true);
|
||||||
world.Minimap.DrawSpawnPoints(minimapRect);
|
world.Minimap.DrawSpawnPoints(minimapRect);
|
||||||
/*
|
|
||||||
if (Game.IsHost)
|
if (Game.IsHost)
|
||||||
{
|
{
|
||||||
AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map",
|
AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map",
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
showMapChooser = true;
|
showMapChooser = true;
|
||||||
currentMap = mapList.Value.Single(
|
currentMap = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant()];
|
||||||
m => m.Filename == Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant());
|
|
||||||
mapPreviewDirty = true;
|
mapPreviewDirty = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
var f = renderer.BoldFont;
|
var f = renderer.BoldFont;
|
||||||
f.DrawText(rgbaRenderer, "Name", new int2(r.Left + 40, r.Top + 50), Color.White);
|
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));
|
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)
|
public static void ChangeMap(string mapName)
|
||||||
{
|
{
|
||||||
Timer.Time( "----ChangeMap" );
|
Timer.Time( "----ChangeMap" );
|
||||||
|
|
||||||
var manifest = new Manifest(LobbyInfo.GlobalSettings.Mods);
|
var manifest = new Manifest(LobbyInfo.GlobalSettings.Mods);
|
||||||
Timer.Time( "manifest: {0}" );
|
Timer.Time( "manifest: {0}" );
|
||||||
|
|
||||||
|
// TODO: Only do this on mod change
|
||||||
|
AvailableMaps = FindMaps(LobbyInfo.GlobalSettings.Mods);
|
||||||
|
Timer.Time( "maplist: {0}" );
|
||||||
|
|
||||||
Game.LoadModAssemblies(manifest);
|
Game.LoadModAssemblies(manifest);
|
||||||
Game.changePending = false;
|
Game.changePending = false;
|
||||||
Game.mapName = mapName;
|
Game.mapName = mapName;
|
||||||
|
|||||||
@@ -79,27 +79,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
Timer.Time( "----World.ctor" );
|
Timer.Time( "----World.ctor" );
|
||||||
|
|
||||||
// TODO: Do this properly
|
Map = new Map( Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Package );
|
||||||
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) );
|
|
||||||
|
|
||||||
|
|
||||||
customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
|
customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
|
||||||
Timer.Time( "new Map: {0}" );
|
Timer.Time( "new Map: {0}" );
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
MapFormat: 1
|
MapFormat: 1
|
||||||
|
Uid: testmap
|
||||||
Title: GDI Mission 2
|
Title: GDI Mission 2
|
||||||
Author: Westwood Studios
|
Author: Westwood Studios
|
||||||
PlayerCount: 1
|
PlayerCount: 1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
MapFormat: 1
|
MapFormat: 1
|
||||||
|
Uid: testmap
|
||||||
Title: Lesson in Blood
|
Title: Lesson in Blood
|
||||||
|
|
||||||
Author: Westwood Studios
|
Author: Westwood Studios
|
||||||
|
|||||||
Reference in New Issue
Block a user