Remove hardcoded map references from MapPreviewWidget; prevents information leakage between lobby and map selector and provides groundwork for future patches
This commit is contained in:
@@ -39,6 +39,7 @@ namespace OpenRA.FileFormats
|
||||
public int PlayerCount;
|
||||
public string Tileset;
|
||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
|
||||
|
||||
public int2 TopLeft;
|
||||
public int2 BottomRight;
|
||||
|
||||
@@ -171,33 +171,5 @@ namespace OpenRA.Graphics
|
||||
(int)(bounds.Width * fx + bounds.Left),
|
||||
(int)(bounds.Height * fy + bounds.Top));
|
||||
}
|
||||
|
||||
public void DrawSpawnPoints(RectangleF rect)
|
||||
{
|
||||
var points = world.Map.SpawnPoints
|
||||
.Select( (sp,i) => Pair.New(sp, Game.LobbyInfo.Clients.FirstOrDefault(
|
||||
c => c.SpawnPoint == i + 1 ) ))
|
||||
.ToList();
|
||||
|
||||
foreach (var p in points)
|
||||
{
|
||||
var pos = CellToMinimapPixel(rect, p.First) - new int2(8, 8);
|
||||
|
||||
if (p.Second == null)
|
||||
rgbaRenderer.DrawSprite(unownedSpawnPoint, pos, "chrome");
|
||||
else
|
||||
{
|
||||
lineRenderer.FillRect(new RectangleF(
|
||||
Game.viewport.Location.X + pos.X + 2,
|
||||
Game.viewport.Location.Y + pos.Y + 2,
|
||||
12, 12), Game.world.PlayerColors()[p.Second.PaletteIndex % Game.world.PlayerColors().Count()].Color);
|
||||
|
||||
rgbaRenderer.DrawSprite(ownedSpawnPoint, pos, "chrome");
|
||||
}
|
||||
}
|
||||
|
||||
lineRenderer.Flush();
|
||||
rgbaRenderer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
|
||||
|
||||
Dictionary<string,string> CountryNames;
|
||||
public LobbyDelegate ()
|
||||
public LobbyDelegate()
|
||||
{
|
||||
var r = Chrome.rootWidget;
|
||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||
@@ -39,6 +39,32 @@ namespace OpenRA.Widgets.Delegates
|
||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
||||
|
||||
|
||||
var map = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||
map.Map = () => {return Game.chrome.currentMap;};
|
||||
map.OnSpawnClick = sp =>
|
||||
{
|
||||
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
|
||||
if (sp == 0 || !owned)
|
||||
Game.IssueOrder(Order.Chat("/spawn {0}".F(sp)));
|
||||
};
|
||||
|
||||
map.SpawnColors = () =>
|
||||
{
|
||||
var spawns = Game.chrome.currentMap.SpawnPoints;
|
||||
var playerColors = Game.world.PlayerColors();
|
||||
var sc = new Dictionary<int2,Color>();
|
||||
|
||||
for (int i = 1; i <= spawns.Count(); i++)
|
||||
{
|
||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
||||
if (client == null)
|
||||
continue;
|
||||
sc.Add(spawns.ElementAt(i-1),playerColors[client.PaletteIndex % playerColors.Count()].Color);
|
||||
}
|
||||
return sc;
|
||||
};
|
||||
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
|
||||
CountryNames.Add("random", "Random");
|
||||
|
||||
@@ -231,20 +257,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleSpawnPoint(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.SpawnPoints.Count();
|
||||
|
||||
var newIndex = (Game.LocalClient.SpawnPoint + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
while (!SpawnPointAvailable(newIndex) && newIndex != (int)Game.LocalClient.SpawnPoint)
|
||||
newIndex = (newIndex + d) % (Game.world.Map.SpawnPoints.Count()+1);
|
||||
|
||||
Game.IssueOrder(
|
||||
Order.Chat("/spawn " + newIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleTeam(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
var r = Chrome.rootWidget;
|
||||
var bg = r.GetWidget("MAP_CHOOSER");
|
||||
|
||||
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Game.chrome.currentMap;};
|
||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Game.chrome.currentMap.Title;};
|
||||
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Game.chrome.currentMap.Width, Game.chrome.currentMap.Height);};
|
||||
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Game.chrome.currentMap.Tileset].Name;};
|
||||
|
||||
@@ -15,6 +15,10 @@ namespace OpenRA.Widgets
|
||||
bool mapPreviewDirty = true;
|
||||
MapStub lastMap;
|
||||
|
||||
public Func<MapStub> Map = () => {return null;};
|
||||
public Action<int> OnSpawnClick = spawn => {};
|
||||
public Func<Dictionary<int2,Color>> SpawnColors = () => {return new Dictionary<int2, Color>(); };
|
||||
|
||||
public MapPreviewWidget() : base() { }
|
||||
|
||||
public MapPreviewWidget(Widget other)
|
||||
@@ -23,28 +27,25 @@ namespace OpenRA.Widgets
|
||||
lastMap = (other as MapPreviewWidget).lastMap;
|
||||
}
|
||||
|
||||
Session.Client ClientForSpawnpoint(int i)
|
||||
{
|
||||
return Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i + 1);
|
||||
}
|
||||
|
||||
const int closeEnough = 50;
|
||||
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
{
|
||||
if (Game.LocalClient.State == Session.ClientState.Ready) return false;
|
||||
|
||||
var map = Map();
|
||||
if (map == null)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left)
|
||||
{
|
||||
var container = new Rectangle(DrawPosition().X, DrawPosition().Y, Parent.Bounds.Width, Parent.Bounds.Height);
|
||||
|
||||
var p = Game.chrome.currentMap.Waypoints
|
||||
.Select((sp, i) => Pair.New(Game.chrome.currentMap.ConvertToPreview(sp.Value, container), i))
|
||||
.Where(a => ClientForSpawnpoint(a.Second) == null && (a.First - mi.Location).LengthSquared < closeEnough)
|
||||
var p = map.Waypoints
|
||||
.Select((sp, i) => Pair.New(map.ConvertToPreview(sp.Value, container), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < closeEnough)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
Game.IssueOrder(Order.Chat("/spawn {0}".F(p)));
|
||||
OnSpawnClick(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,14 +56,14 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void DrawInner( World world )
|
||||
{
|
||||
var map = Game.chrome.currentMap;
|
||||
var map = Map();
|
||||
if( map == null ) return;
|
||||
|
||||
if (lastMap != map)
|
||||
{
|
||||
mapPreviewDirty = true;
|
||||
lastMap = map;
|
||||
}
|
||||
|
||||
var pos = DrawPosition();
|
||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) );
|
||||
@@ -87,29 +88,24 @@ namespace OpenRA.Widgets
|
||||
|
||||
void DrawSpawnPoints(MapStub map, Rectangle container, World world)
|
||||
{
|
||||
var points = map.Waypoints
|
||||
.Select((sp, i) => Pair.New(sp, Game.LobbyInfo.Clients.FirstOrDefault(
|
||||
c => c.SpawnPoint == i + 1)))
|
||||
.ToList();
|
||||
|
||||
foreach (var p in points)
|
||||
var colors = SpawnColors();
|
||||
foreach (var p in map.SpawnPoints)
|
||||
{
|
||||
var pos = map.ConvertToPreview(p.First.Value, container) - new int2(8, 8);
|
||||
var pos = map.ConvertToPreview(p, container) - new int2(8, 8);
|
||||
var sprite = "unowned";
|
||||
|
||||
if (p.Second == null)
|
||||
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite(
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", "unowned"), pos, "chrome");
|
||||
else
|
||||
if (colors.ContainsKey(p))
|
||||
{
|
||||
var playerColors = Game.world.PlayerColors();
|
||||
Game.chrome.lineRenderer.FillRect(new RectangleF(
|
||||
Game.viewport.Location.X + pos.X + 2,
|
||||
Game.viewport.Location.Y + pos.Y + 2,
|
||||
12, 12), playerColors[p.Second.PaletteIndex % playerColors.Count()].Color);
|
||||
12, 12), colors[p]);
|
||||
|
||||
sprite = "owned";
|
||||
}
|
||||
|
||||
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite(
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", "owned"), pos, "chrome");
|
||||
}
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", sprite), pos, "chrome");
|
||||
}
|
||||
|
||||
Game.chrome.lineRenderer.Flush();
|
||||
|
||||
@@ -430,6 +430,7 @@ Container:
|
||||
Background:dialog3
|
||||
Children:
|
||||
MapPreview@LOBBY_MAP_PREVIEW:
|
||||
Id:LOBBY_MAP_PREVIEW
|
||||
X:4
|
||||
Y:4
|
||||
Width:244
|
||||
@@ -744,6 +745,7 @@ Container:
|
||||
Background:dialog3
|
||||
Children:
|
||||
MapPreview@MAPCHOOSER_MAP_PREVIEW:
|
||||
Id:MAPCHOOSER_MAP_PREVIEW
|
||||
X:4
|
||||
Y:4
|
||||
Width:244
|
||||
|
||||
Reference in New Issue
Block a user