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");
|
var mapPreview = lobby.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||||
mapPreview.IsVisible = () => Map != null;
|
mapPreview.IsVisible = () => Map != null;
|
||||||
mapPreview.Map = () => Map;
|
mapPreview.Map = () => Map;
|
||||||
mapPreview.OnMouseDown = mi =>
|
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, 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)));
|
|
||||||
};
|
|
||||||
|
|
||||||
var mapTitle = lobby.GetWidget<LabelWidget>("MAP_TITLE");
|
var mapTitle = lobby.GetWidget<LabelWidget>("MAP_TITLE");
|
||||||
mapTitle.IsVisible = () => Map != null;
|
mapTitle.IsVisible = () => Map != null;
|
||||||
@@ -272,25 +257,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName;
|
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)
|
void ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||||
{
|
{
|
||||||
Action<ColorRamp> onSelect = c =>
|
Action<ColorRamp> onSelect = c =>
|
||||||
@@ -404,11 +370,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
team.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(team, client, orderManager, Map);
|
team.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(team, client, orderManager, Map);
|
||||||
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
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)
|
if (client.Bot == null)
|
||||||
{
|
{
|
||||||
// local player
|
// local player
|
||||||
|
|||||||
@@ -63,27 +63,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||||
mapPreview.Map = () => Map;
|
mapPreview.Map = () => Map;
|
||||||
mapPreview.OnMouseDown = mi =>
|
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, 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.SpawnColors = () => LobbyUtils.GetSpawnColors( orderManager, Map );
|
mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors( orderManager, Map );
|
||||||
|
|
||||||
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -128,5 +129,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
c => spawns[c.SpawnPoint - 1],
|
c => spawns[c.SpawnPoint - 1],
|
||||||
c => c.ColorRamp.GetColor(0));
|
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:
|
TextField@NAME:
|
||||||
Id:NAME
|
Id:NAME
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:150
|
Width:205
|
||||||
Height:25
|
Height:25
|
||||||
MaxLength:16
|
MaxLength:16
|
||||||
Visible:false
|
Visible:false
|
||||||
DropDownButton@BOT_DROPDOWN:
|
DropDownButton@BOT_DROPDOWN:
|
||||||
Id:BOT_DROPDOWN
|
Id:BOT_DROPDOWN
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:150
|
Width:205
|
||||||
Height:25
|
Height:25
|
||||||
Font:Regular
|
Font:Regular
|
||||||
Visible:false
|
Visible:false
|
||||||
@@ -80,7 +80,7 @@ Container@SERVER_LOBBY:
|
|||||||
Id:COLOR
|
Id:COLOR
|
||||||
Width:70
|
Width:70
|
||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:210
|
||||||
Font:Regular
|
Font:Regular
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
@@ -94,7 +94,7 @@ Container@SERVER_LOBBY:
|
|||||||
Id:FACTION
|
Id:FACTION
|
||||||
Width:100
|
Width:100
|
||||||
Height:25
|
Height:25
|
||||||
X:230
|
X:285
|
||||||
Font:Regular
|
Font:Regular
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
@@ -115,12 +115,6 @@ Container@SERVER_LOBBY:
|
|||||||
Id:TEAM
|
Id:TEAM
|
||||||
Width:50
|
Width:50
|
||||||
Height:25
|
Height:25
|
||||||
X:335
|
|
||||||
Font:Regular
|
|
||||||
DropDownButton@SPAWN:
|
|
||||||
Id:SPAWN
|
|
||||||
Width:50
|
|
||||||
Height:25
|
|
||||||
X:390
|
X:390
|
||||||
Font:Regular
|
Font:Regular
|
||||||
Image@STATUS_IMAGE:
|
Image@STATUS_IMAGE:
|
||||||
@@ -150,7 +144,7 @@ Container@SERVER_LOBBY:
|
|||||||
Label@NAME:
|
Label@NAME:
|
||||||
Id:NAME
|
Id:NAME
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:145
|
Width:200
|
||||||
Height:25
|
Height:25
|
||||||
X:5
|
X:5
|
||||||
Y:0-1
|
Y:0-1
|
||||||
@@ -159,12 +153,12 @@ Container@SERVER_LOBBY:
|
|||||||
Text:X
|
Text:X
|
||||||
Width:25
|
Width:25
|
||||||
Height:23
|
Height:23
|
||||||
X:125
|
X:180
|
||||||
Y:2
|
Y:2
|
||||||
Font:Bold
|
Font:Bold
|
||||||
ColorBlock@COLOR:
|
ColorBlock@COLOR:
|
||||||
Id:COLOR
|
Id:COLOR
|
||||||
X:160
|
X:215
|
||||||
Y:6
|
Y:6
|
||||||
Width:35
|
Width:35
|
||||||
Height:13
|
Height:13
|
||||||
@@ -172,7 +166,7 @@ Container@SERVER_LOBBY:
|
|||||||
Id:FACTION
|
Id:FACTION
|
||||||
Width:100
|
Width:100
|
||||||
Height:25
|
Height:25
|
||||||
X:230
|
X:285
|
||||||
Y:0
|
Y:0
|
||||||
Children:
|
Children:
|
||||||
Image@FACTIONFLAG:
|
Image@FACTIONFLAG:
|
||||||
@@ -193,13 +187,6 @@ Container@SERVER_LOBBY:
|
|||||||
Align:Center
|
Align:Center
|
||||||
Width:25
|
Width:25
|
||||||
Height:25
|
Height:25
|
||||||
X:335
|
|
||||||
Y:0
|
|
||||||
Label@SPAWN:
|
|
||||||
Id:SPAWN
|
|
||||||
Align:Center
|
|
||||||
Width:25
|
|
||||||
Height:25
|
|
||||||
X:390
|
X:390
|
||||||
Y:0
|
Y:0
|
||||||
Image@STATUS_IMAGE:
|
Image@STATUS_IMAGE:
|
||||||
@@ -222,14 +209,14 @@ Container@SERVER_LOBBY:
|
|||||||
DropDownButton@NAME_HOST:
|
DropDownButton@NAME_HOST:
|
||||||
Id:NAME_HOST
|
Id:NAME_HOST
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:150
|
Width:205
|
||||||
Height:25
|
Height:25
|
||||||
Font:Regular
|
Font:Regular
|
||||||
Visible:false
|
Visible:false
|
||||||
Label@NAME:
|
Label@NAME:
|
||||||
Id:NAME
|
Id:NAME
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:145
|
Width:200
|
||||||
Height:25
|
Height:25
|
||||||
X:5
|
X:5
|
||||||
Y:0-1
|
Y:0-1
|
||||||
@@ -238,9 +225,9 @@ Container@SERVER_LOBBY:
|
|||||||
Id:JOIN
|
Id:JOIN
|
||||||
Text:Play in this slot
|
Text:Play in this slot
|
||||||
Font:Regular
|
Font:Regular
|
||||||
Width:315
|
Width:315-55
|
||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:210
|
||||||
Y:0
|
Y:0
|
||||||
Container@TEMPLATE_EDITABLE_SPECTATOR:
|
Container@TEMPLATE_EDITABLE_SPECTATOR:
|
||||||
Id:TEMPLATE_EDITABLE_SPECTATOR
|
Id:TEMPLATE_EDITABLE_SPECTATOR
|
||||||
@@ -253,14 +240,14 @@ Container@SERVER_LOBBY:
|
|||||||
TextField@NAME:
|
TextField@NAME:
|
||||||
Id:NAME
|
Id:NAME
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:150
|
Width:205
|
||||||
Height:25
|
Height:25
|
||||||
MaxLength:16
|
MaxLength:16
|
||||||
DropDownButton@COLOR:
|
DropDownButton@COLOR:
|
||||||
Id:COLOR
|
Id:COLOR
|
||||||
Width:70
|
Width:70
|
||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:210
|
||||||
Font:Regular
|
Font:Regular
|
||||||
IgnoreChildMouseOver: true
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
@@ -272,9 +259,9 @@ Container@SERVER_LOBBY:
|
|||||||
Height:PARENT_BOTTOM-12
|
Height:PARENT_BOTTOM-12
|
||||||
Label@SPECTATOR:
|
Label@SPECTATOR:
|
||||||
Text:Spectator
|
Text:Spectator
|
||||||
Width:220
|
Width:220-55
|
||||||
Height:25
|
Height:25
|
||||||
X:225
|
X:280
|
||||||
Y:0
|
Y:0
|
||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
@@ -295,7 +282,7 @@ Container@SERVER_LOBBY:
|
|||||||
Label@NAME:
|
Label@NAME:
|
||||||
Id:NAME
|
Id:NAME
|
||||||
Text:Name
|
Text:Name
|
||||||
Width:145
|
Width:200
|
||||||
Height:25
|
Height:25
|
||||||
X:5
|
X:5
|
||||||
Y:0-1
|
Y:0-1
|
||||||
@@ -304,20 +291,20 @@ Container@SERVER_LOBBY:
|
|||||||
Text:X
|
Text:X
|
||||||
Width:25
|
Width:25
|
||||||
Height:23
|
Height:23
|
||||||
X:125
|
X:180
|
||||||
Y:2
|
Y:2
|
||||||
Font:Bold
|
Font:Bold
|
||||||
ColorBlock@COLOR:
|
ColorBlock@COLOR:
|
||||||
Id:COLOR
|
Id:COLOR
|
||||||
X:160
|
X:215
|
||||||
Y:6
|
Y:6
|
||||||
Width:35
|
Width:35
|
||||||
Height:13
|
Height:13
|
||||||
Label@SPECTATOR:
|
Label@SPECTATOR:
|
||||||
Text:Spectator
|
Text:Spectator
|
||||||
Width:220
|
Width:220-55
|
||||||
Height:25
|
Height:25
|
||||||
X:225
|
X:280
|
||||||
Y:0
|
Y:0
|
||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
@@ -351,7 +338,7 @@ Container@SERVER_LOBBY:
|
|||||||
Y:5
|
Y:5
|
||||||
Children:
|
Children:
|
||||||
Label@NAME:
|
Label@NAME:
|
||||||
Width:150
|
Width:200
|
||||||
Height:25
|
Height:25
|
||||||
Text:Player
|
Text:Player
|
||||||
Align:Center
|
Align:Center
|
||||||
@@ -359,29 +346,22 @@ Container@SERVER_LOBBY:
|
|||||||
Label@COLOR:
|
Label@COLOR:
|
||||||
Width:70
|
Width:70
|
||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:210
|
||||||
Text:Color
|
Text:Color
|
||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Label@FACTION:
|
Label@FACTION:
|
||||||
Width:100
|
Width:100
|
||||||
Height:25
|
Height:25
|
||||||
X:230
|
X:285
|
||||||
Text:Faction
|
Text:Faction
|
||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Label@TEAM:
|
Label@TEAM:
|
||||||
Width:50
|
|
||||||
Height:25
|
|
||||||
X:335
|
|
||||||
Text:Team
|
|
||||||
Align:Center
|
|
||||||
Font:Bold
|
|
||||||
Label@SPAWN:
|
|
||||||
Width:50
|
Width:50
|
||||||
Height:25
|
Height:25
|
||||||
X:390
|
X:390
|
||||||
Text:Spawn
|
Text:Team
|
||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Label@STATUS:
|
Label@STATUS:
|
||||||
@@ -467,4 +447,4 @@ Container@SERVER_LOBBY:
|
|||||||
Y:499
|
Y:499
|
||||||
Width:140
|
Width:140
|
||||||
Height:35
|
Height:35
|
||||||
Text:Start Game
|
Text:Start Game
|
||||||
|
|||||||
Reference in New Issue
Block a user