Measure() public method

public Measure ( string text ) : int2
text string
return int2
Ejemplo n.º 1
0
        public void Render(WorldRenderer wr)
        {
            var screenPos   = Game.viewport.Zoom * (wr.ScreenPosition(pos) - Game.viewport.Location) - 0.5f * font.Measure(text).ToFloat2();
            var screenPxPos = new float2((float)Math.Round(screenPos.X), (float)Math.Round(screenPos.Y));

            font.DrawTextWithContrast(text, screenPxPos, color, Color.Black, 1);
        }
Ejemplo n.º 2
0
 public CashTick(string value, int lifetime, int velocity, float2 pos, Color color)
 {
     this.color = color;
     this.velocity = velocity;
     this.pos = pos;
     s = value;
     font = Game.Renderer.Fonts["TinyBold"];
     offset = 0.5f*font.Measure(s).ToFloat2();
     remaining = lifetime;
 }
        public SupportPowersWidget(World world, WorldRenderer worldRenderer)
        {
            this.worldRenderer = worldRenderer;
            spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
            tooltipContainer = Lazy.New(() =>
                Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));

            iconSprites = Rules.Info.Values.SelectMany( u => u.Traits.WithInterface<SupportPowerInfo>() )
                .Select(u => u.Image).Distinct()
                .ToDictionary(
                    u => u,
                    u => Game.modData.SpriteLoader.LoadAllSprites(u)[0]);

            clock = new Animation("clock");

            overlayFont = Game.Renderer.Fonts["TinyBold"];
            holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
            readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
            timeOffset = new float2(32,24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
        }
Ejemplo n.º 4
0
        public override void Draw()
        {
            overlayFont = Game.Renderer.Fonts["TinyBold"];
            holdOffset = new float2(32, 24) - overlayFont.Measure(HoldText) / 2;
            readyOffset = new float2(32, 24) - overlayFont.Measure(ReadyText) / 2;
            timeOffset = new float2(32, 24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;

            // Background
            foreach (var rect in icons.Keys)
                WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));

            // Icons
            foreach (var p in icons.Values)
            {
                WidgetUtils.DrawSHP(p.Sprite, p.Pos, worldRenderer);

                // Charge progress
                clock.PlayFetchIndex("idle",
                    () => (p.Power.TotalTime - p.Power.RemainingTime)
                        * (clock.CurrentSequence.Length - 1) / p.Power.TotalTime);
                clock.Tick();
                WidgetUtils.DrawSHP(clock.Image, p.Pos, worldRenderer);
            }

            // Overlay
            foreach (var p in icons.Values)
            {
                if (p.Power.Ready)
                    overlayFont.DrawTextWithContrast(ReadyText,
                        p.Pos + readyOffset,
                        Color.White, Color.Black, 1);
                else if (!p.Power.Active)
                    overlayFont.DrawTextWithContrast(HoldText,
                        p.Pos + holdOffset,
                        Color.White, Color.Black, 1);
                else
                    overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTime),
                        p.Pos + timeOffset,
                        Color.White, Color.Black, 1);
            }
        }
Ejemplo n.º 5
0
        public ProductionPaletteWidget(World world, WorldRenderer worldRenderer)
        {
            this.world = world;
            this.worldRenderer = worldRenderer;
            tooltipContainer = Lazy.New(() =>
                Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));

            cantBuild = new Animation("clock");
            cantBuild.PlayFetchIndex("idle", () => 0);
            clock = new Animation("clock");

            iconSprites = Rules.Info.Values
                .Where(u => u.Traits.Contains<BuildableInfo>() && u.Name[0] != '^')
                .ToDictionary(
                    u => u.Name,
                    u => Game.modData.SpriteLoader.LoadAllSprites(
                        u.Traits.Get<TooltipInfo>().Icon ?? (u.Name + "icon"))[0]);

            overlayFont = Game.Renderer.Fonts["TinyBold"];
            holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
            readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
            timeOffset = new float2(32,24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
            queuedOffset = new float2(4,2);
        }
Ejemplo n.º 6
0
        public override void Display()
        {
            if (r == null || loadTimer.Elapsed.TotalSeconds < 0.25)
                return;

            loadTimer.Restart();

            loadTick = ++loadTick % 8;
            r.BeginFrame(int2.Zero, 1f);
            r.RgbaSpriteRenderer.DrawSprite(gdiLogo, gdiPos);
            r.RgbaSpriteRenderer.DrawSprite(nodLogo, nodPos);
            r.RgbaSpriteRenderer.DrawSprite(evaLogo, evaPos);

            WidgetUtils.DrawPanelPartial(bounds, PanelSides.Edges,
                borderTop, borderBottom, borderLeft, borderRight,
                cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight,
                null);
            var barY = bounds.Height - 78;

            if (!setup && r.Fonts != null)
            {
                loadingFont = r.Fonts["BigBold"];
                loadingText = loadInfo["Text"];
                loadingPos = new float2((bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY);

                versionFont = r.Fonts["Regular"];
                var versionSize = versionFont.Measure(versionText);
                versionPos = new float2(bounds.Width - 107 - versionSize.X / 2, 115 - versionSize.Y / 2);

                setup = true;
            }

            if (loadingFont != null)
                loadingFont.DrawText(loadingText, loadingPos, Color.Gray);
            if (versionFont != null)
                versionFont.DrawTextWithContrast(versionText, versionPos, Color.White, Color.Black, 2);

            for (var i = 0; i <= 8; i++)
            {
                var block = loadTick == i ? brightBlock : dimBlock;
                r.RgbaSpriteRenderer.DrawSprite(block,
                    new float2(bounds.Width / 2 - 114 - i * 32, barY));
                r.RgbaSpriteRenderer.DrawSprite(block,
                    new float2(bounds.Width / 2 + 114 + i * 32 - 16, barY));
            }

            r.EndFrame(nih);
        }
Ejemplo n.º 7
0
        public void Display()
        {
            if (r == null || loadTimer.ElapsedTime() < 0.25)
                return;

            loadTimer.Reset();

            loadTick = ++loadTick % 8;
            r.BeginFrame(float2.Zero, 1f);
            r.RgbaSpriteRenderer.DrawSprite(gdiLogo, gdiPos);
            r.RgbaSpriteRenderer.DrawSprite(nodLogo, nodPos);
            r.RgbaSpriteRenderer.DrawSprite(evaLogo, evaPos);

            WidgetUtils.DrawPanelPartial(ss, Bounds, PanelSides.Edges);
            var barY = Bounds.Height - 78;

            if (!setup && r.Fonts != null)
            {
                loadingFont = r.Fonts["BigBold"];
                loadingText = "Loading";
                loadingPos = new float2((Bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY);

                versionFont = r.Fonts["Regular"];
                versionText = WidgetUtils.ActiveModVersion();
                var versionSize = versionFont.Measure(versionText);
                versionPos = new float2(Bounds.Width - 107 - versionSize.X/2, 115 - versionSize.Y/2);

                setup = true;
            }

            if (loadingFont != null)
                loadingFont.DrawText(loadingText, loadingPos, Color.Gray);
            if (versionFont != null)
                versionFont.DrawTextWithContrast(versionText, versionPos, Color.White, Color.Black, 2);

            for (var i = 0; i <= 8; i++)
            {
                var block = loadTick == i ? brightBlock : dimBlock;
                r.RgbaSpriteRenderer.DrawSprite(block,
                    new float2(Bounds.Width / 2 - 114 - i * 32, barY));
                r.RgbaSpriteRenderer.DrawSprite(block,
                    new float2(Bounds.Width / 2 + 114 + i * 32 - 16, barY));
            }

            r.EndFrame(nih);
        }
Ejemplo n.º 8
0
		public override void Draw()
		{
			var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset;

			overlayFont = Game.Renderer.Fonts["TinyBold"];
			timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0, World.Timestep)) / 2;
			queuedOffset = new float2(4, 2);
			holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
			readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;

			if (CurrentQueue == null)
				return;

			var buildableItems = CurrentQueue.BuildableItems();

			var pios = currentQueue.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>();

			// Icons
			foreach (var icon in icons.Values)
			{
				WidgetUtils.DrawSHPCentered(icon.Sprite, icon.Pos + iconOffset, icon.Palette);

				// Draw the ProductionIconOverlay's sprite
				var pio = pios.FirstOrDefault(p => p.IsOverlayActive(icon.Actor));
				if (pio != null)
					WidgetUtils.DrawSHPCentered(pio.Sprite, icon.Pos + iconOffset + pio.Offset(IconSize), worldRenderer.Palette(pio.Palette), 1f);

				// Build progress
				if (icon.Queued.Count > 0)
				{
					var first = icon.Queued[0];
					clock.PlayFetchIndex(ClockSequence,
						() => (first.TotalTime - first.RemainingTime)
							* (clock.CurrentSequence.Length - 1) / first.TotalTime);
					clock.Tick();

					WidgetUtils.DrawSHPCentered(clock.Image, icon.Pos + iconOffset, icon.IconClockPalette);
				}
				else if (!buildableItems.Any(a => a.Name == icon.Name))
					WidgetUtils.DrawSHPCentered(cantBuild.Image, icon.Pos + iconOffset, icon.IconDarkenPalette);
			}

			// Overlays
			foreach (var icon in icons.Values)
			{
				var total = icon.Queued.Count;
				if (total > 0)
				{
					var first = icon.Queued[0];
					var waiting = first != CurrentQueue.CurrentItem() && !first.Done;
					if (first.Done)
					{
						if (ReadyTextStyle == ReadyTextStyleOptions.Solid || orderManager.LocalFrameNumber * worldRenderer.World.Timestep / 360 % 2 == 0)
							overlayFont.DrawTextWithContrast(ReadyText, icon.Pos + readyOffset, Color.White, Color.Black, 1);
						else if (ReadyTextStyle == ReadyTextStyleOptions.AlternatingColor)
							overlayFont.DrawTextWithContrast(ReadyText, icon.Pos + readyOffset, ReadyTextAltColor, Color.Black, 1);
					}
					else if (first.Paused)
						overlayFont.DrawTextWithContrast(HoldText,
							icon.Pos + holdOffset,
							Color.White, Color.Black, 1);
					else if (!waiting)
						overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(first.RemainingTimeActual, World.Timestep),
							icon.Pos + timeOffset,
							Color.White, Color.Black, 1);

					if (total > 1 || waiting)
						overlayFont.DrawTextWithContrast(total.ToString(),
							icon.Pos + queuedOffset,
							Color.White, Color.Black, 1);
				}
			}
		}
Ejemplo n.º 9
0
		public override void Draw()
		{
			var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset;
			overlayFont = Game.Renderer.Fonts["TinyBold"];

			holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
			readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;
			timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0, worldRenderer.World.Timestep)) / 2;

			// Icons
			foreach (var p in icons.Values)
			{
				WidgetUtils.DrawSHPCentered(p.Sprite, p.Pos + iconOffset, p.Palette);

				// Charge progress
				var sp = p.Power;
				clock.PlayFetchIndex(ClockSequence,
					() => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime)
					* (clock.CurrentSequence.Length - 1) / sp.TotalTime);

				clock.Tick();
				WidgetUtils.DrawSHPCentered(clock.Image, p.Pos + iconOffset, p.IconClockPalette);
			}

			// Overlay
			foreach (var p in icons.Values)
			{
				if (p.Power.Ready)
					overlayFont.DrawTextWithContrast(ReadyText,
						p.Pos + readyOffset,
						Color.White, Color.Black, 1);
				else if (!p.Power.Active)
					overlayFont.DrawTextWithContrast(HoldText,
						p.Pos + holdOffset,
						Color.White, Color.Black, 1);
				else
					overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTime, worldRenderer.World.Timestep),
						p.Pos + timeOffset,
						Color.White, Color.Black, 1);
			}
		}
Ejemplo n.º 10
0
        public static string WrapText(string text, int width, SpriteFont font)
        {
            var textSize = font.Measure(text);
            if (textSize.X > width)
            {
                var lines = text.Split('\n').ToList();

                for (var i=0; i<lines.Count; i++)
                {
                    var line = lines[i];
                    var m = font.Measure(line);

                    if (m.X <= width)
                        continue;

                    var bestSpaceIndex = -1;
                    var start = line.Length - 1;

                    while (m.X > width)
                    {
                        var spaceIndex = line.LastIndexOf(' ', start);
                        if (spaceIndex == -1)
                            break;
                        bestSpaceIndex = spaceIndex;

                        start = spaceIndex - 1;
                        m = font.Measure(line.Substring(0, spaceIndex));
                    }

                    if (bestSpaceIndex != -1)
                    {
                        lines[i] = line.Substring(0, bestSpaceIndex);
                        lines.Insert(i + 1, line.Substring(bestSpaceIndex + 1));
                    }
                }

                return string.Join("\n", lines);
            }
            return text;
        }
Ejemplo n.º 11
0
        public static string WrapText(string text, int width, SpriteFont font)
        {
            var textSize = font.Measure(text);
            if (textSize.X > width)
            {
                var lines = text.Split('\n');
                var newLines = new List<string>();
                var i = 0;
                var line = lines[i++];

                for(;;)
                {
                    newLines.Add(line);
                    var m = font.Measure(line);
                    var spaceIndex = 0;
                    var start = line.Length - 1;

                    if (m.X <= width)
                    {
                        if (i < lines.Length - 1)
                        {
                            line = lines[i++];
                            continue;
                        }
                        else
                            break;
                    }

                    while (m.X > width)
                    {
                        if (-1 == (spaceIndex = line.LastIndexOf(' ', start)))
                            break;
                        start = spaceIndex - 1;
                        m = font.Measure(line.Substring(0, spaceIndex));
                    }

                    if (spaceIndex != -1)
                    {
                        newLines.RemoveAt(newLines.Count - 1);
                        newLines.Add(line.Substring(0, spaceIndex));
                        line = line.Substring(spaceIndex + 1);
                    }
                    else if (i < lines.Length - 1)
                    {
                        line = lines[i++];
                        continue;
                    }
                    else
                        break;
                }
                return string.Join("\n", newLines.ToArray());
            }
            return text;
        }
Ejemplo n.º 12
0
        public override void Draw()
        {
            overlayFont = Game.Renderer.Fonts["TinyBold"];
            timeOffset = new float2(32,24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
            queuedOffset = new float2(4,2);
            holdOffset = new float2(32,24) - overlayFont.Measure(HoldText) / 2;
            readyOffset = new float2(32,24) - overlayFont.Measure(ReadyText) / 2;

            if (CurrentQueue == null)
                return;

            var buildableItems = CurrentQueue.BuildableItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);

            // Background
            foreach (var rect in Icons.Keys)
                WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1,1,1,1));

            // Icons
            foreach (var icon in Icons.Values)
            {
                WidgetUtils.DrawSHP(icon.Sprite, icon.Pos, worldRenderer);

                // Build progress
                if (icon.Queued.Count > 0)
                {
                    var first = icon.Queued[0];
                    clock.PlayFetchIndex("idle",
                        () => (first.TotalTime - first.RemainingTime)
                            * (clock.CurrentSequence.Length - 1) / first.TotalTime);
                    clock.Tick();
                    WidgetUtils.DrawSHP(clock.Image, icon.Pos, worldRenderer);
                }
                else if (!buildableItems.Any(a => a.Name == icon.Name))
                    WidgetUtils.DrawSHP(cantBuild.Image, icon.Pos, worldRenderer);
            }

            // Overlays
            foreach (var icon in Icons.Values)
            {
                var total = icon.Queued.Count;
                if (total > 0)
                {
                    var first = icon.Queued[0];
                    var waiting = first != CurrentQueue.CurrentItem() && !first.Done;
                    if (first.Done)
                        overlayFont.DrawTextWithContrast(ReadyText,
                                                         icon.Pos + readyOffset,
                                                         Color.White, Color.Black, 1);
                    else if (first.Paused)
                        overlayFont.DrawTextWithContrast(HoldText,
                                                         icon.Pos + holdOffset,
                                                         Color.White, Color.Black, 1);
                    else if (!waiting)
                        overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(first.RemainingTimeActual),
                                                         icon.Pos + timeOffset,
                                                         Color.White, Color.Black, 1);

                    if (total > 1 || waiting)
                        overlayFont.DrawTextWithContrast(total.ToString(),
                                                         icon.Pos + queuedOffset,
                                                         Color.White, Color.Black, 1);
                }
            }
        }
Ejemplo n.º 13
0
		public override void Draw()
		{
			var iconSize = new float2(64, 48);
			var iconOffset = 0.5f * iconSize;

			overlayFont = Game.Renderer.Fonts["TinyBold"];
			timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
			queuedOffset = new float2(4, 2);
			holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
			readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;

			if (CurrentQueue == null)
				return;

			var buildableItems = CurrentQueue.BuildableItems();

			// Background
			foreach (var rect in icons.Keys)
				WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));

			// Icons
			foreach (var icon in icons.Values)
			{
				WidgetUtils.DrawSHPCentered(icon.Sprite, icon.Pos + iconOffset, worldRenderer);

				// Build progress
				if (icon.Queued.Count > 0)
				{
					var first = icon.Queued[0];
					clock.PlayFetchIndex("idle",
						() => (first.TotalTime - first.RemainingTime)
							* (clock.CurrentSequence.Length - 1) / first.TotalTime);
					clock.Tick();
					WidgetUtils.DrawSHPCentered(clock.Image, icon.Pos + iconOffset, worldRenderer);
				}
				else if (!buildableItems.Any(a => a.Name == icon.Name))
					WidgetUtils.DrawSHPCentered(cantBuild.Image, icon.Pos + iconOffset, worldRenderer);
			}

			// Overlays
			foreach (var icon in icons.Values)
			{
				var total = icon.Queued.Count;
				if (total > 0)
				{
					var first = icon.Queued[0];
					var waiting = first != CurrentQueue.CurrentItem() && !first.Done;
					if (first.Done)
					{
						if (ReadyTextStyle == ReadyTextStyleOptions.Solid || orderManager.LocalFrameNumber / 9 % 2 == 0)
							overlayFont.DrawTextWithContrast(ReadyText,
							                                 icon.Pos + readyOffset,
							                                 Color.White, Color.Black, 1);
						else if (ReadyTextStyle == ReadyTextStyleOptions.AlternatingColor)
								overlayFont.DrawTextWithContrast(ReadyText,
								                                 icon.Pos + readyOffset,
								                                 ReadyTextAltColor, Color.Black, 1);
					}
					else if (first.Paused)
						overlayFont.DrawTextWithContrast(HoldText,
														 icon.Pos + holdOffset,
														 Color.White, Color.Black, 1);
					else if (!waiting)
						overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(first.RemainingTimeActual),
														 icon.Pos + timeOffset,
														 Color.White, Color.Black, 1);

					if (total > 1 || waiting)
						overlayFont.DrawTextWithContrast(total.ToString(),
														 icon.Pos + queuedOffset,
														 Color.White, Color.Black, 1);
				}
			}
		}