Example #1
0
        public WorldTooltipLogic(Widget widget, World world, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
        {
            widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
            var label = widget.Get<LabelWidget>("LABEL");
            var flag = widget.Get<ImageWidget>("FLAG");
            var owner = widget.Get<LabelWidget>("OWNER");

            var font = Game.Renderer.Fonts[label.Font];
            var ownerFont = Game.Renderer.Fonts[owner.Font];
            var cachedWidth = 0;
            var labelText = "";
            var showOwner = false;
            var flagRace = "";
            var ownerName = "";
            var ownerColor = Color.White;

            var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
            var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;

            tooltipContainer.BeforeRender = () =>
            {
                if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
                    return;

                showOwner = false;

                Player o = null;
                switch (viewport.TooltipType)
                {
                    case WorldTooltipType.Unexplored:
                        labelText = "Unexplored Terrain";
                        break;
                    case WorldTooltipType.Actor:
                    {
                        o = viewport.ActorTooltip.Owner;
                        showOwner = !o.NonCombatant && viewport.ActorTooltip.TooltipInfo.IsOwnerRowVisible;

                        var stance = o == null || world.RenderPlayer == null? Stance.None : o.Stances[world.RenderPlayer];
                        labelText = viewport.ActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
                        break;
                    }
                    case WorldTooltipType.FrozenActor:
                    {
                        o = viewport.FrozenActorTooltip.TooltipOwner;
                        showOwner = !o.NonCombatant && viewport.FrozenActorTooltip.TooltipInfo.IsOwnerRowVisible;

                        var stance = o == null || world.RenderPlayer == null? Stance.None : o.Stances[world.RenderPlayer];
                        labelText = viewport.FrozenActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
                        break;
                    }
                }

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

                if (showOwner)
                {
                    flagRace = o.Country.Race;
                    ownerName = o.PlayerName;
                    ownerColor = o.Color.RGB;
                    widget.Bounds.Height = doubleHeight;
                    widget.Bounds.Width = Math.Max(widget.Bounds.Width,
                        owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
                }
                else
                    widget.Bounds.Height = singleHeight;
            };

            label.GetText = () => labelText;
            flag.IsVisible = () => showOwner;
            flag.GetImageCollection = () => "flags";
            flag.GetImageName = () => flagRace;
            owner.IsVisible = () => showOwner;
            owner.GetText = () => ownerName;
            owner.GetColor = () => ownerColor;
        }
Example #2
0
		public WorldTooltipLogic(Widget widget, World world, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
		{
			widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
			var label = widget.Get<LabelWidget>("LABEL");
			var flag = widget.Get<ImageWidget>("FLAG");
			var owner = widget.Get<LabelWidget>("OWNER");
			var extras = widget.Get<LabelWidget>("EXTRA");

			var font = Game.Renderer.Fonts[label.Font];
			var ownerFont = Game.Renderer.Fonts[owner.Font];
			var cachedWidth = 0;
			var labelText = "";
			var showOwner = false;
			var flagFaction = "";
			var ownerName = "";
			var ownerColor = Color.White;
			var extraText = "";

			var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
			var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
			var extraHeightOnDouble = extras.Bounds.Y;
			var extraHeightOnSingle = extraHeightOnDouble - (doubleHeight - singleHeight);

			tooltipContainer.BeforeRender = () =>
			{
				if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
					return;

				var index = 0;
				extraText = "";
				showOwner = false;

				Player o = null;
				switch (viewport.TooltipType)
				{
					case WorldTooltipType.Unexplored:
						labelText = "Unexplored Terrain";
						break;
					case WorldTooltipType.Actor:
						{
							o = viewport.ActorTooltip.Owner;
							showOwner = o != null && !o.NonCombatant && viewport.ActorTooltip.TooltipInfo.IsOwnerRowVisible;

							var stance = o == null || world.RenderPlayer == null ? Stance.None : o.Stances[world.RenderPlayer];
							labelText = viewport.ActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
							break;
						}

					case WorldTooltipType.FrozenActor:
						{
							o = viewport.FrozenActorTooltip.TooltipOwner;
							showOwner = o != null && !o.NonCombatant && viewport.FrozenActorTooltip.TooltipInfo.IsOwnerRowVisible;

							var stance = o == null || world.RenderPlayer == null ? Stance.None : o.Stances[world.RenderPlayer];
							labelText = viewport.FrozenActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
							break;
						}
				}

				if (viewport.ActorTooltipExtra != null)
				{
					foreach (var info in viewport.ActorTooltipExtra)
					{
						if (info.IsTooltipVisible(world.LocalPlayer))
						{
							if (index != 0)
								extraText += "\n";
							extraText += info.TooltipText;
							index++;
						}
					}
				}

				var textWidth = Math.Max(font.Measure(labelText).X, font.Measure(extraText).X);

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

				if (showOwner)
				{
					flagFaction = o.Faction.InternalName;
					ownerName = o.PlayerName;
					ownerColor = o.Color.RGB;
					widget.Bounds.Height = doubleHeight;
					widget.Bounds.Width = Math.Max(widget.Bounds.Width,
						owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
					index++;
				}
				else
					widget.Bounds.Height = singleHeight;

				if (extraText != "")
				{
					widget.Bounds.Height += font.Measure(extraText).Y + extras.Bounds.Height;
					if (showOwner)
						extras.Bounds.Y = extraHeightOnDouble;
					else
						extras.Bounds.Y = extraHeightOnSingle;
				}
			};

			label.GetText = () => labelText;
			flag.IsVisible = () => showOwner;
			flag.GetImageCollection = () => "flags";
			flag.GetImageName = () => flagFaction;
			owner.IsVisible = () => showOwner;
			owner.GetText = () => ownerName;
			owner.GetColor = () => ownerColor;
			extras.GetText = () => extraText;
		}