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 int PlayerCount;
|
||||||
public string Tileset;
|
public string Tileset;
|
||||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
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 TopLeft;
|
||||||
public int2 BottomRight;
|
public int2 BottomRight;
|
||||||
|
|||||||
@@ -171,33 +171,5 @@ namespace OpenRA.Graphics
|
|||||||
(int)(bounds.Width * fx + bounds.Left),
|
(int)(bounds.Width * fx + bounds.Left),
|
||||||
(int)(bounds.Height * fy + bounds.Top));
|
(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;
|
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
|
||||||
|
|
||||||
Dictionary<string,string> CountryNames;
|
Dictionary<string,string> CountryNames;
|
||||||
public LobbyDelegate ()
|
public LobbyDelegate()
|
||||||
{
|
{
|
||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||||
@@ -39,6 +39,32 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||||
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
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 = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
|
||||||
CountryNames.Add("random", "Random");
|
CountryNames.Add("random", "Random");
|
||||||
|
|
||||||
@@ -231,20 +257,6 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
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)
|
bool CycleTeam(MouseInput mi)
|
||||||
{
|
{
|
||||||
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var bg = r.GetWidget("MAP_CHOOSER");
|
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_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_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;};
|
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Game.chrome.currentMap.Tileset].Name;};
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ namespace OpenRA.Widgets
|
|||||||
bool mapPreviewDirty = true;
|
bool mapPreviewDirty = true;
|
||||||
MapStub lastMap;
|
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() : base() { }
|
||||||
|
|
||||||
public MapPreviewWidget(Widget other)
|
public MapPreviewWidget(Widget other)
|
||||||
@@ -23,28 +27,25 @@ namespace OpenRA.Widgets
|
|||||||
lastMap = (other as MapPreviewWidget).lastMap;
|
lastMap = (other as MapPreviewWidget).lastMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Session.Client ClientForSpawnpoint(int i)
|
|
||||||
{
|
|
||||||
return Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int closeEnough = 50;
|
const int closeEnough = 50;
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (Game.LocalClient.State == Session.ClientState.Ready) return false;
|
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)
|
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var container = new Rectangle(DrawPosition().X, DrawPosition().Y, Parent.Bounds.Width, Parent.Bounds.Height);
|
var container = new Rectangle(DrawPosition().X, DrawPosition().Y, Parent.Bounds.Width, Parent.Bounds.Height);
|
||||||
|
|
||||||
var p = Game.chrome.currentMap.Waypoints
|
var p = map.Waypoints
|
||||||
.Select((sp, i) => Pair.New(Game.chrome.currentMap.ConvertToPreview(sp.Value, container), i))
|
.Select((sp, i) => Pair.New(map.ConvertToPreview(sp.Value, container), i))
|
||||||
.Where(a => ClientForSpawnpoint(a.Second) == null && (a.First - mi.Location).LengthSquared < closeEnough)
|
.Where(a => (a.First - mi.Location).LengthSquared < closeEnough)
|
||||||
.Select(a => a.Second + 1)
|
.Select(a => a.Second + 1)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
OnSpawnClick(p);
|
||||||
Game.IssueOrder(Order.Chat("/spawn {0}".F(p)));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,14 +56,14 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public override void DrawInner( World world )
|
public override void DrawInner( World world )
|
||||||
{
|
{
|
||||||
var map = Game.chrome.currentMap;
|
var map = Map();
|
||||||
if( map == null ) return;
|
if( map == null ) return;
|
||||||
|
|
||||||
if (lastMap != map)
|
if (lastMap != map)
|
||||||
{
|
{
|
||||||
mapPreviewDirty = true;
|
mapPreviewDirty = true;
|
||||||
lastMap = map;
|
lastMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pos = DrawPosition();
|
var pos = DrawPosition();
|
||||||
var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
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 ) );
|
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)
|
void DrawSpawnPoints(MapStub map, Rectangle container, World world)
|
||||||
{
|
{
|
||||||
var points = map.Waypoints
|
var colors = SpawnColors();
|
||||||
.Select((sp, i) => Pair.New(sp, Game.LobbyInfo.Clients.FirstOrDefault(
|
foreach (var p in map.SpawnPoints)
|
||||||
c => c.SpawnPoint == i + 1)))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
foreach (var p in points)
|
|
||||||
{
|
{
|
||||||
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)
|
if (colors.ContainsKey(p))
|
||||||
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite(
|
|
||||||
ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", "unowned"), pos, "chrome");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var playerColors = Game.world.PlayerColors();
|
|
||||||
Game.chrome.lineRenderer.FillRect(new RectangleF(
|
Game.chrome.lineRenderer.FillRect(new RectangleF(
|
||||||
Game.viewport.Location.X + pos.X + 2,
|
Game.viewport.Location.X + pos.X + 2,
|
||||||
Game.viewport.Location.Y + pos.Y + 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(
|
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();
|
Game.chrome.lineRenderer.Flush();
|
||||||
|
|||||||
@@ -430,6 +430,7 @@ Container:
|
|||||||
Background:dialog3
|
Background:dialog3
|
||||||
Children:
|
Children:
|
||||||
MapPreview@LOBBY_MAP_PREVIEW:
|
MapPreview@LOBBY_MAP_PREVIEW:
|
||||||
|
Id:LOBBY_MAP_PREVIEW
|
||||||
X:4
|
X:4
|
||||||
Y:4
|
Y:4
|
||||||
Width:244
|
Width:244
|
||||||
@@ -744,6 +745,7 @@ Container:
|
|||||||
Background:dialog3
|
Background:dialog3
|
||||||
Children:
|
Children:
|
||||||
MapPreview@MAPCHOOSER_MAP_PREVIEW:
|
MapPreview@MAPCHOOSER_MAP_PREVIEW:
|
||||||
|
Id:MAPCHOOSER_MAP_PREVIEW
|
||||||
X:4
|
X:4
|
||||||
Y:4
|
Y:4
|
||||||
Width:244
|
Width:244
|
||||||
|
|||||||
Reference in New Issue
Block a user