protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     lastMap = other.lastMap;
     Map = other.Map;
     SpawnColors = other.SpawnColors;
 }
		public SpawnSelectorTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, MapPreviewWidget preview)
		{
			widget.IsVisible = () => preview.TooltipSpawnIndex != -1;
			var label = widget.Get<LabelWidget>("LABEL");
			var flag = widget.Get<ImageWidget>("FLAG");
			var team = widget.Get<LabelWidget>("TEAM");
			var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
			var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
			var ownerFont = Game.Renderer.Fonts[label.Font];
			var teamFont = Game.Renderer.Fonts[team.Font];

			// Width specified in YAML is used as the margin between flag / label and label / border
			var labelMargin = widget.Bounds.Width;

			var cachedWidth = 0;
			var labelText = "";
			string playerFaction = null;
			var playerTeam = -1;

			tooltipContainer.BeforeRender = () =>
			{
				var occupant = preview.SpawnOccupants().Values.FirstOrDefault(c => c.SpawnPoint == preview.TooltipSpawnIndex);

				var teamWidth = 0;
				if (occupant == null)
				{
					labelText = "Available spawn";
					playerFaction = null;
					playerTeam = 0;
					widget.Bounds.Height = singleHeight;
				}
				else
				{
					labelText = occupant.PlayerName;
					playerFaction = occupant.Faction;
					playerTeam = occupant.Team;
					widget.Bounds.Height = playerTeam > 0 ? doubleHeight : singleHeight;
					teamWidth = teamFont.Measure(team.GetText()).X;
				}

				label.Bounds.X = playerFaction != null ? flag.Bounds.Right + labelMargin : labelMargin;

				var textWidth = ownerFont.Measure(labelText).X;
				if (textWidth != cachedWidth)
				{
					label.Bounds.Width = textWidth;
					widget.Bounds.Width = 2 * label.Bounds.X + textWidth;
				}

				widget.Bounds.Width = Math.Max(teamWidth + 2 * labelMargin, label.Bounds.Right + labelMargin);
				team.Bounds.Width = widget.Bounds.Width;
			};

			label.GetText = () => labelText;
			flag.IsVisible = () => playerFaction != null;
			flag.GetImageCollection = () => "flags";
			flag.GetImageName = () => playerFaction;
			team.GetText = () => "Team {0}".F(playerTeam);
			team.IsVisible = () => playerTeam > 0;
		}
Beispiel #3
0
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     lastMap     = other.lastMap;
     Map         = other.Map;
     SpawnColors = other.SpawnColors;
 }
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     Preview          = other.Preview;
     SpawnOccupants   = other.SpawnOccupants;
     ShowSpawnPoints  = other.ShowSpawnPoints;
     TooltipTemplate  = other.TooltipTemplate;
     TooltipContainer = other.TooltipContainer;
     tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));
 }
Beispiel #5
0
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     Preview = other.Preview;
     SpawnOccupants = other.SpawnOccupants;
     ShowSpawnPoints = other.ShowSpawnPoints;
     TooltipTemplate = other.TooltipTemplate;
     TooltipContainer = other.TooltipContainer;
     tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
 }
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     lastMap = other.lastMap;
     Map = other.Map;
     SpawnClients = other.SpawnClients;
     ShowSpawnPoints = other.ShowSpawnPoints;
     TooltipTemplate = other.TooltipTemplate;
     TooltipContainer = other.TooltipContainer;
     tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
 }
Beispiel #7
0
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     lastMap          = other.lastMap;
     Map              = other.Map;
     SpawnClients     = other.SpawnClients;
     ShowSpawnPoints  = other.ShowSpawnPoints;
     TooltipTemplate  = other.TooltipTemplate;
     TooltipContainer = other.TooltipContainer;
     tooltipContainer = Lazy.New(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));
 }
        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)));
            }
        }
Beispiel #9
0
        protected MapPreviewWidget(MapPreviewWidget other)
            : base(other)
        {
            Preview = other.Preview;

            IgnoreMouseInput = other.IgnoreMouseInput;
            ShowSpawnPoints  = other.ShowSpawnPoints;
            TooltipTemplate  = other.TooltipTemplate;
            TooltipContainer = other.TooltipContainer;
            SpawnOccupants   = other.SpawnOccupants;

            tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));

            spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont          = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
            spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
            spawnLabelOffset   = ChromeMetrics.Get <int2>("SpawnLabelOffset");
        }
Beispiel #10
0
        protected MapPreviewWidget(MapPreviewWidget other)
            : base(other)
        {
            Preview = other.Preview;

            IgnoreMouseInput = other.IgnoreMouseInput;
            ShowSpawnPoints = other.ShowSpawnPoints;
            TooltipTemplate = other.TooltipTemplate;
            TooltipContainer = other.TooltipContainer;
            SpawnOccupants = other.SpawnOccupants;

            tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));

            spawnClaimed = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont = Game.Renderer.Fonts[ChromeMetrics.Get<string>("SpawnFont")];
            spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
            spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
        }
Beispiel #11
0
        public static void SelectSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, MapPreview preview, MouseInput mi)
        {
            if (mi.Button != MouseButton.Left)
                return;

            if (!orderManager.LocalClient.IsObserver && orderManager.LocalClient.State == Session.ClientState.Ready)
                return;

            var spawnSize = new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").Bounds.Size);
            var selectedSpawn = preview.SpawnPoints
                .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp, preview.GridType), i))
                .Where(a => ((a.First - mi.Location).ToFloat2() / spawnSize * 2).LengthSquared <= 1)
                .Select(a => a.Second + 1)
                .FirstOrDefault();

            var locals = orderManager.LobbyInfo.Clients.Where(c => c.Index == orderManager.LocalClient.Index || (Game.IsHost && c.Bot != null));
            var playerToMove = locals.FirstOrDefault(c => ((selectedSpawn == 0) ^ (c.SpawnPoint == 0) && !c.IsObserver));
            SetSpawnPoint(orderManager, playerToMove, selectedSpawn);
        }