unify bot spawn choosers in CNC and RA
This commit is contained in:
@@ -116,22 +116,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var mapPreview = lobby.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||
mapPreview.IsVisible = () => Map != null;
|
||||
mapPreview.Map = () => Map;
|
||||
mapPreview.OnMouseDown = mi =>
|
||||
{
|
||||
if (Map == null || mi.Button != MouseButton.Left
|
||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||
return;
|
||||
|
||||
var p = Map.GetSpawnPoints()
|
||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < 64)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
||||
if (p == 0 || !owned)
|
||||
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p)));
|
||||
};
|
||||
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
|
||||
|
||||
var mapTitle = lobby.GetWidget<LabelWidget>("MAP_TITLE");
|
||||
mapTitle.IsVisible = () => Map != null;
|
||||
@@ -272,25 +257,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName;
|
||||
}
|
||||
|
||||
void ShowSpawnDropDown(DropDownButtonWidget dropdown, Session.Client client)
|
||||
{
|
||||
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => client.SpawnPoint == ii,
|
||||
() => orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(client.Index, ii))));
|
||||
item.GetWidget<LabelWidget>("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString();
|
||||
return item;
|
||||
};
|
||||
|
||||
var taken = orderManager.LobbyInfo.Clients
|
||||
.Where(c => c.SpawnPoint != 0 && c.SpawnPoint != client.SpawnPoint && c.Slot != null)
|
||||
.Select(c => c.SpawnPoint).ToList();
|
||||
|
||||
var options = Graphics.Util.MakeArray(Map.GetSpawnPoints().Length + 1, i => i).Except(taken).ToList();
|
||||
dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
}
|
||||
|
||||
void ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||
{
|
||||
Action<ColorRamp> onSelect = c =>
|
||||
@@ -404,11 +370,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
team.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(team, client, orderManager, Map);
|
||||
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
||||
|
||||
var spawn = template.GetWidget<DropDownButtonWidget>("SPAWN");
|
||||
spawn.IsDisabled = () => slot.LockSpawn || ready;
|
||||
spawn.OnMouseDown = _ => ShowSpawnDropDown(spawn, client);
|
||||
spawn.GetText = () => (client.SpawnPoint == 0) ? "-" : client.SpawnPoint.ToString();
|
||||
|
||||
if (client.Bot == null)
|
||||
{
|
||||
// local player
|
||||
|
||||
@@ -63,27 +63,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||
mapPreview.Map = () => Map;
|
||||
mapPreview.OnMouseDown = mi =>
|
||||
{
|
||||
if (Map == null || mi.Button != MouseButton.Left
|
||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||
return;
|
||||
|
||||
var selectedSpawn = Map.GetSpawnPoints()
|
||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < 64)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == selectedSpawn);
|
||||
if (selectedSpawn == 0 || !owned)
|
||||
{
|
||||
var locals = orderManager.LobbyInfo.Clients.Where(c => c.Index == orderManager.LocalClient.Index || (Game.IsHost && c.Bot != null));
|
||||
var playerToMove = locals.Where(c => (selectedSpawn == 0) ^ (c.SpawnPoint == 0)).FirstOrDefault();
|
||||
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F((playerToMove ?? orderManager.LocalClient).Index, selectedSpawn)));
|
||||
}
|
||||
};
|
||||
|
||||
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
|
||||
mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors( orderManager, Map );
|
||||
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
@@ -128,5 +129,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
c => spawns[c.SpawnPoint - 1],
|
||||
c => c.ColorRamp.GetColor(0));
|
||||
}
|
||||
|
||||
public static void SelectSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, Map map, MouseInput mi)
|
||||
{
|
||||
if (map == null || mi.Button != MouseButton.Left
|
||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||
return;
|
||||
|
||||
var selectedSpawn = map.GetSpawnPoints()
|
||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < 64)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == selectedSpawn);
|
||||
if (selectedSpawn == 0 || !owned)
|
||||
{
|
||||
var locals = orderManager.LobbyInfo.Clients.Where(c => c.Index == orderManager.LocalClient.Index || (Game.IsHost && c.Bot != null));
|
||||
var playerToMove = locals.Where(c => (selectedSpawn == 0) ^ (c.SpawnPoint == 0)).FirstOrDefault();
|
||||
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F((playerToMove ?? orderManager.LocalClient).Index, selectedSpawn)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ Container@SERVER_LOBBY:
|
||||
TextField@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:150
|
||||
Width:205
|
||||
Height:25
|
||||
MaxLength:16
|
||||
Visible:false
|
||||
DropDownButton@BOT_DROPDOWN:
|
||||
Id:BOT_DROPDOWN
|
||||
Text:Name
|
||||
Width:150
|
||||
Width:205
|
||||
Height:25
|
||||
Font:Regular
|
||||
Visible:false
|
||||
@@ -80,7 +80,7 @@ Container@SERVER_LOBBY:
|
||||
Id:COLOR
|
||||
Width:70
|
||||
Height:25
|
||||
X:155
|
||||
X:210
|
||||
Font:Regular
|
||||
IgnoreChildMouseOver: true
|
||||
Children:
|
||||
@@ -94,7 +94,7 @@ Container@SERVER_LOBBY:
|
||||
Id:FACTION
|
||||
Width:100
|
||||
Height:25
|
||||
X:230
|
||||
X:285
|
||||
Font:Regular
|
||||
IgnoreChildMouseOver: true
|
||||
Children:
|
||||
@@ -115,12 +115,6 @@ Container@SERVER_LOBBY:
|
||||
Id:TEAM
|
||||
Width:50
|
||||
Height:25
|
||||
X:335
|
||||
Font:Regular
|
||||
DropDownButton@SPAWN:
|
||||
Id:SPAWN
|
||||
Width:50
|
||||
Height:25
|
||||
X:390
|
||||
Font:Regular
|
||||
Image@STATUS_IMAGE:
|
||||
@@ -150,7 +144,7 @@ Container@SERVER_LOBBY:
|
||||
Label@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:145
|
||||
Width:200
|
||||
Height:25
|
||||
X:5
|
||||
Y:0-1
|
||||
@@ -159,12 +153,12 @@ Container@SERVER_LOBBY:
|
||||
Text:X
|
||||
Width:25
|
||||
Height:23
|
||||
X:125
|
||||
X:180
|
||||
Y:2
|
||||
Font:Bold
|
||||
ColorBlock@COLOR:
|
||||
Id:COLOR
|
||||
X:160
|
||||
X:215
|
||||
Y:6
|
||||
Width:35
|
||||
Height:13
|
||||
@@ -172,7 +166,7 @@ Container@SERVER_LOBBY:
|
||||
Id:FACTION
|
||||
Width:100
|
||||
Height:25
|
||||
X:230
|
||||
X:285
|
||||
Y:0
|
||||
Children:
|
||||
Image@FACTIONFLAG:
|
||||
@@ -193,13 +187,6 @@ Container@SERVER_LOBBY:
|
||||
Align:Center
|
||||
Width:25
|
||||
Height:25
|
||||
X:335
|
||||
Y:0
|
||||
Label@SPAWN:
|
||||
Id:SPAWN
|
||||
Align:Center
|
||||
Width:25
|
||||
Height:25
|
||||
X:390
|
||||
Y:0
|
||||
Image@STATUS_IMAGE:
|
||||
@@ -222,14 +209,14 @@ Container@SERVER_LOBBY:
|
||||
DropDownButton@NAME_HOST:
|
||||
Id:NAME_HOST
|
||||
Text:Name
|
||||
Width:150
|
||||
Width:205
|
||||
Height:25
|
||||
Font:Regular
|
||||
Visible:false
|
||||
Label@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:145
|
||||
Width:200
|
||||
Height:25
|
||||
X:5
|
||||
Y:0-1
|
||||
@@ -238,9 +225,9 @@ Container@SERVER_LOBBY:
|
||||
Id:JOIN
|
||||
Text:Play in this slot
|
||||
Font:Regular
|
||||
Width:315
|
||||
Width:315-55
|
||||
Height:25
|
||||
X:155
|
||||
X:210
|
||||
Y:0
|
||||
Container@TEMPLATE_EDITABLE_SPECTATOR:
|
||||
Id:TEMPLATE_EDITABLE_SPECTATOR
|
||||
@@ -253,14 +240,14 @@ Container@SERVER_LOBBY:
|
||||
TextField@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:150
|
||||
Width:205
|
||||
Height:25
|
||||
MaxLength:16
|
||||
DropDownButton@COLOR:
|
||||
Id:COLOR
|
||||
Width:70
|
||||
Height:25
|
||||
X:155
|
||||
X:210
|
||||
Font:Regular
|
||||
IgnoreChildMouseOver: true
|
||||
Children:
|
||||
@@ -272,9 +259,9 @@ Container@SERVER_LOBBY:
|
||||
Height:PARENT_BOTTOM-12
|
||||
Label@SPECTATOR:
|
||||
Text:Spectator
|
||||
Width:220
|
||||
Width:220-55
|
||||
Height:25
|
||||
X:225
|
||||
X:280
|
||||
Y:0
|
||||
Align:Center
|
||||
Font:Bold
|
||||
@@ -295,7 +282,7 @@ Container@SERVER_LOBBY:
|
||||
Label@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:145
|
||||
Width:200
|
||||
Height:25
|
||||
X:5
|
||||
Y:0-1
|
||||
@@ -304,20 +291,20 @@ Container@SERVER_LOBBY:
|
||||
Text:X
|
||||
Width:25
|
||||
Height:23
|
||||
X:125
|
||||
X:180
|
||||
Y:2
|
||||
Font:Bold
|
||||
ColorBlock@COLOR:
|
||||
Id:COLOR
|
||||
X:160
|
||||
X:215
|
||||
Y:6
|
||||
Width:35
|
||||
Height:13
|
||||
Label@SPECTATOR:
|
||||
Text:Spectator
|
||||
Width:220
|
||||
Width:220-55
|
||||
Height:25
|
||||
X:225
|
||||
X:280
|
||||
Y:0
|
||||
Align:Center
|
||||
Font:Bold
|
||||
@@ -351,7 +338,7 @@ Container@SERVER_LOBBY:
|
||||
Y:5
|
||||
Children:
|
||||
Label@NAME:
|
||||
Width:150
|
||||
Width:200
|
||||
Height:25
|
||||
Text:Player
|
||||
Align:Center
|
||||
@@ -359,29 +346,22 @@ Container@SERVER_LOBBY:
|
||||
Label@COLOR:
|
||||
Width:70
|
||||
Height:25
|
||||
X:155
|
||||
X:210
|
||||
Text:Color
|
||||
Align:Center
|
||||
Font:Bold
|
||||
Label@FACTION:
|
||||
Width:100
|
||||
Height:25
|
||||
X:230
|
||||
X:285
|
||||
Text:Faction
|
||||
Align:Center
|
||||
Font:Bold
|
||||
Label@TEAM:
|
||||
Width:50
|
||||
Height:25
|
||||
X:335
|
||||
Text:Team
|
||||
Align:Center
|
||||
Font:Bold
|
||||
Label@SPAWN:
|
||||
Width:50
|
||||
Height:25
|
||||
X:390
|
||||
Text:Spawn
|
||||
Text:Team
|
||||
Align:Center
|
||||
Font:Bold
|
||||
Label@STATUS:
|
||||
|
||||
Reference in New Issue
Block a user