示例#1
0
        int DrawPalette(ProductionQueue queue)
        {
            buttons.Clear();

            string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
            float2 origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
            var x = 0;
            var y = 0;

            if (queue != null)
            {
                var buildableItems = queue.BuildableItems().ToArray();
                var allBuildables = queue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder).ToArray();

                var overlayBits = new List<Pair<Sprite, float2>>();
                var textBits = new List<Pair<float2, string>>();
                numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows);

                // Palette Background
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "top"), new float2(origin.X - 9, origin.Y - 9));
                for (var w = 0; w < numActualRows; w++)
                    WidgetUtils.DrawRGBA(
                        ChromeProvider.GetImage(paletteCollection, "bg-" + (w % 4).ToString()),
                        new float2(origin.X - 9, origin.Y + 48 * w));
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"),
                    new float2(origin.X - 9, origin.Y - 1 + 48 * numActualRows));

                // Icons
                string tooltipItem = null;
                foreach (var item in allBuildables)
                {
                    var rect = new RectangleF(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
                    var drawPos = new float2(rect.Location);
                    WidgetUtils.DrawSHP(iconSprites[item.Name], drawPos, worldRenderer);

                    var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);

                    if (rect.Contains(Viewport.LastMousePos))
                        tooltipItem = item.Name;

                    var overlayPos = drawPos + new float2(32, 16);

                    if (firstOfThis != null)
                    {
                        clock.PlayFetchIndex("idle",
                            () => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
                                * (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
                        clock.Tick();
                        WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);

                        if (queue.CurrentItem() == firstOfThis)
                            textBits.Add( Pair.New( overlayPos, GetOverlayForItem(firstOfThis) ) );

                        var repeats = queue.AllQueued().Count(a => a.Item == item.Name);
                        if (repeats > 1 || queue.CurrentItem() != firstOfThis)
                        {
                            var offset = -40;
                            var digits = repeats.ToString();
                            foreach (var d in digits)
                            {
                                ready.PlayFetchIndex("groups", () => d - '0');
                                ready.Tick();
                                overlayBits.Add(Pair.New(ready.Image, overlayPos + new float2(offset, -14)));
                                offset += 6;
                            }
                        }
                    }
                    else
                        if (!buildableItems.Any(a => a.Name == item.Name))
                            overlayBits.Add(Pair.New(cantBuild.Image, drawPos));

                    var closureName = buildableItems.Any(a => a.Name == item.Name) ? item.Name : null;
                    buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));

                    if (++x == Columns) { x = 0; y++; }
                }
                if (x != 0) y++;

                foreach (var ob in overlayBits)
                    WidgetUtils.DrawSHP(ob.First, ob.Second, worldRenderer);

                var font = Game.Renderer.Fonts["TinyBold"];
                foreach (var tb in textBits)
                {
                    var size = font.Measure(tb.Second);
                    font.DrawTextWithContrast(tb.Second, tb.First - new float2( size.X / 2, 0 ),
                        Color.White, Color.Black, 1);
                }

                // Tooltip
                if (tooltipItem != null && !paletteAnimating && paletteOpen)
                    DrawProductionTooltip(world, tooltipItem,
                        new float2(Game.viewport.Width, origin.Y + numActualRows * 48 + 9).ToInt2());
            }

            // Palette Dock
            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"),
                new float2(Game.viewport.Width - 14, origin.Y - 23));

            for (int i = 0; i < numActualRows; i++)
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4).ToString()),
                    new float2(Game.viewport.Width - 14, origin.Y + 48 * i));

            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
                new float2(Game.viewport.Width - 14, origin.Y - 1 + 48 * numActualRows));

            return 48 * y + 9;
        }
示例#2
0
		int DrawPalette(ProductionQueue queue)
		{
			buttons.Clear();

			var paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
			var origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
			var iconOffset = 0.5f * new float2(IconWidth, IconHeight);
			var x = 0;
			var y = 0;

			if (queue != null)
			{
				var buildableItems = queue.BuildableItems().ToArray();
				var allBuildables = queue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder).ToArray();

				var overlayBits = new List<Pair<Sprite, float2>>();
				var textBits = new List<Pair<float2, string>>();
				numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows);

				// Palette Background
				WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "top"), new float2(origin.X - 9, origin.Y - 9));
				for (var w = 0; w < numActualRows; w++)
					WidgetUtils.DrawRGBA(
						ChromeProvider.GetImage(paletteCollection, "bg-" + (w % 4)),
						new float2(origin.X - 9, origin.Y + IconHeight * w));
				WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"),
					new float2(origin.X - 9, origin.Y - 1 + IconHeight * numActualRows));


				// Icons
				string tooltipItem = null;
				foreach (var item in allBuildables)
				{
					var rect = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight);
					var drawPos = new float2(rect.Location);
					var icon = new Animation(world, RenderSimple.GetImage(item));
					icon.Play(item.Traits.Get<TooltipInfo>().Icon);
					WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);

					var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);

					if (rect.Contains(Viewport.LastMousePos))
						tooltipItem = item.Name;

					var overlayPos = drawPos + new float2(32, 16);

					if (firstOfThis != null)
					{
						clock.PlayFetchIndex("idle",
							() => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
								* (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
						clock.Tick();
						WidgetUtils.DrawSHPCentered(clock.Image, drawPos + iconOffset, worldRenderer);

						if (queue.CurrentItem() == firstOfThis)
							textBits.Add(Pair.New(overlayPos, GetOverlayForItem(firstOfThis)));

						var repeats = queue.AllQueued().Count(a => a.Item == item.Name);
						if (repeats > 1 || queue.CurrentItem() != firstOfThis)
							textBits.Add(Pair.New(overlayPos + new float2(-24, -14), repeats.ToString()));
					}
					else
						if (buildableItems.All(a => a.Name != item.Name))
							overlayBits.Add(Pair.New(cantBuild.Image, drawPos));

					var closureName = buildableItems.Any(a => a.Name == item.Name) ? item.Name : null;
					buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));

					if (++x == Columns) { x = 0; y++; }
				}
				if (x != 0) y++;

				foreach (var ob in overlayBits)
					WidgetUtils.DrawSHPCentered(ob.First, ob.Second + iconOffset, worldRenderer);

				var font = Game.Renderer.Fonts["TinyBold"];
				foreach (var tb in textBits)
				{
					var size = font.Measure(tb.Second);
					if (ReadyTextStyle == ReadyTextStyleOptions.Solid || orderManager.LocalFrameNumber / 9 % 2 == 0 || tb.Second != ReadyText)
						font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
						                          Color.White, Color.Black, 1);
					else if (ReadyTextStyle == ReadyTextStyleOptions.AlternatingColor)
						font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
							                  ReadyTextAltColor, Color.Black, 1);
				}

				// Tooltip
				if (tooltipItem != null && !paletteAnimating && paletteOpen)
					DrawProductionTooltip(world, tooltipItem,
						new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2());
			}

			// Palette Dock
			WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"),
				new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23));

			for (var i = 0; i < numActualRows; i++)
				WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4)),
					new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i));

			WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
				new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 1 + IconHeight * numActualRows));

			return IconHeight * y + 9;
		}