Example #1
0
        public ClassicProductionLogic(Widget widget, OrderManager orderManager, World world)
        {
            this.world = world;
            palette    = widget.Get <ProductionPaletteWidget>("PRODUCTION_PALETTE");


            var typesContainer = widget.Get("PRODUCTION_TYPES");

            foreach (var i in typesContainer.Children)
            {
                SetupProductionGroupButton(orderManager, i as ProductionTypeButtonWidget);
            }


            var ticker = widget.Get <LogicTickerWidget>("PRODUCTION_TICKER");

            ticker.OnTick = () =>
            {
                if (palette.CurrentQueue == null || palette.DisplayedIconCount == 0)
                {
                    // Select the first active tab
                    foreach (var b in typesContainer.Children)
                    {
                        var button = b as ProductionTypeButtonWidget;
                        if (button == null || button.IsDisabled())
                        {
                            continue;
                        }

                        button.OnClick();
                        break;
                    }
                }
            };
        }
Example #2
0
        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
        {
            var pm = palette.world.LocalPlayer.PlayerActor.Trait<PowerManager>();
            var pr = palette.world.LocalPlayer.PlayerActor.Trait<PlayerResources>();

            widget.IsVisible = () => palette.TooltipActor != null;
            var nameLabel = widget.GetWidget<LabelWidget>("NAME");
            var requiresLabel = widget.GetWidget<LabelWidget>("REQUIRES");
            var powerLabel = widget.GetWidget<LabelWidget>("POWER");
            var timeLabel = widget.GetWidget<LabelWidget>("TIME");
            var costLabel = widget.GetWidget<LabelWidget>("COST");

            var font = Game.Renderer.Fonts[nameLabel.Font];
            var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            string lastActor = null;

            tooltipContainer.BeforeRender = () =>
            {
                var actor = palette.TooltipActor;
                if (actor == null || actor == lastActor)
                    return;

                var info = Rules.Info[actor];
                var tooltip = info.Traits.Get<TooltipInfo>();
                var buildable = info.Traits.Get<BuildableInfo>();
                var cost = info.Traits.Get<ValuedInfo>().Cost;
                var bi = info.Traits.GetOrDefault<BuildingInfo>();

                nameLabel.GetText = () => tooltip.Name;

                var prereqs = buildable.Prerequisites.Select(a => ActorName(a));
                var requiresString = prereqs.Any() ? "Requires {0}".F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power = bi != null ? bi.Power : 0;
                var powerString = "P: {0}".F(power);
                powerLabel.GetText = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                    ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;

                var timeString = "T: {0}".F(WidgetUtils.FormatTime(palette.CurrentQueue.GetBuildTime(actor)));
                timeLabel.GetText = () => timeString;

                var costString = "$: {0}".F(cost);
                costLabel.GetText = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayOre >= cost
                    ? Color.White : Color.Red;

                var leftWidth = Math.Max(font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X);
                var rightWidth = new [] {font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X}.Aggregate(Math.Max);
                timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2*nameLabel.Bounds.X;
                widget.Bounds.Width = leftWidth + rightWidth + 3*nameLabel.Bounds.X;

                widget.Bounds.Height = power != 0 ? 65 : 45;
                lastActor = actor;
            };
        }
Example #3
0
        static void SetMaximumVisibleRows(ProductionPaletteWidget productionPalette)
        {
            var screenHeight = Game.Renderer.Resolution.Height;

            // Get height of currently displayed icons
            var containerWidget = Ui.Root.GetOrNull <ContainerWidget>("SIDEBAR_PRODUCTION");

            if (containerWidget == null)
            {
                return;
            }

            var sidebarProductionHeight = containerWidget.Bounds.Y;

            // Check if icon heights exceed y resolution
            var maxItemsHeight = screenHeight - sidebarProductionHeight;

            var maxIconRowOffest = (maxItemsHeight / productionPalette.IconSize.Y) - 1;

            productionPalette.MaxIconRowOffset = Math.Min(maxIconRowOffest, productionPalette.MaximumRows);
        }
Example #4
0
        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette, World world)
        {
            var mapRules = palette.World.Map.Rules;
            var pm       = palette.World.LocalPlayer.PlayerActor.Trait <PowerManager>();
            var pr       = palette.World.LocalPlayer.PlayerActor.Trait <PlayerResources>();

            widget.IsVisible = () => palette.TooltipIcon != null;
            var nameLabel     = widget.Get <LabelWidget>("NAME");
            var hotkeyLabel   = widget.Get <LabelWidget>("HOTKEY");
            var requiresLabel = widget.Get <LabelWidget>("REQUIRES");
            var powerLabel    = widget.Get <LabelWidget>("POWER");
            var powerIcon     = widget.Get <ImageWidget>("POWER_ICON");
            var timeLabel     = widget.Get <LabelWidget>("TIME");
            var timeIcon      = widget.Get <ImageWidget>("TIME_ICON");
            var costLabel     = widget.Get <LabelWidget>("COST");
            var costIcon      = widget.Get <ImageWidget>("COST_ICON");
            var descLabel     = widget.Get <LabelWidget>("DESC");

            var iconMargin = timeIcon.Bounds.X;

            var       font         = Game.Renderer.Fonts[nameLabel.Font];
            var       descFont     = Game.Renderer.Fonts[descLabel.Font];
            var       requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            ActorInfo lastActor    = null;

            tooltipContainer.BeforeRender = () =>
            {
                if (palette.TooltipIcon == null)
                {
                    return;
                }

                var actor = palette.TooltipIcon.Actor;
                if (actor == null || actor == lastActor)
                {
                    return;
                }

                var tooltip   = actor.TraitInfo <TooltipInfo>();
                var buildable = actor.TraitInfo <BuildableInfo>();
                var cost      = actor.TraitInfo <ValuedInfo>().Cost;

                nameLabel.GetText = () => tooltip.Name;

                var hotkey      = palette.TooltipIcon.Hotkey;
                var nameWidth   = font.Measure(tooltip.Name).X;
                var hotkeyText  = "({0})".F(hotkey.DisplayString());
                var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
                hotkeyLabel.GetText  = () => hotkeyText;
                hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
                hotkeyLabel.Visible  = hotkey.IsValid();

                var prereqs        = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
                var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power       = actor.TraitInfos <PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(i => i.Amount);
                var powerString = power.ToString();
                powerLabel.GetText  = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                                        ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;
                powerIcon.IsVisible  = () => power != 0;

                var lowpower = pm.PowerState != PowerState.Normal;
                var time     = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor.Name)
                               * (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
                var timeString = WidgetUtils.FormatTime(time, world.Timestep);
                timeLabel.GetText  = () => timeString;
                timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;

                var costString = cost.ToString();
                costLabel.GetText  = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayResources >= cost
                                        ? Color.White : Color.Red;

                var descString = tooltip.Description.Replace("\\n", "\n");
                descLabel.GetText = () => descString;

                var leftWidth = new[] { nameWidth + hotkeyWidth, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
                var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);

                timeIcon.Bounds.X   = powerIcon.Bounds.X = costIcon.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
                timeLabel.Bounds.X  = powerLabel.Bounds.X = costLabel.Bounds.X = timeIcon.Bounds.Right + iconMargin;
                widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X + timeIcon.Bounds.Width + iconMargin;

                var leftHeight  = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y;
                var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y;
                widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;

                lastActor = actor;
            };
        }
Example #5
0
        public ClassicProductionLogic(Widget widget, OrderManager orderManager, World world)
        {
            this.world = world;
            palette    = widget.Get <ProductionPaletteWidget>("PRODUCTION_PALETTE");

            var background = widget.GetOrNull("PALETTE_BACKGROUND");
            var foreground = widget.GetOrNull("PALETTE_FOREGROUND");

            if (background != null || foreground != null)
            {
                Widget backgroundTemplate = null;
                Widget backgroundBottom   = null;
                Widget foregroundTemplate = null;

                if (background != null)
                {
                    backgroundTemplate = background.Get("ROW_TEMPLATE");
                    backgroundBottom   = background.GetOrNull("BOTTOM_CAP");
                }

                if (foreground != null)
                {
                    foregroundTemplate = foreground.Get("ROW_TEMPLATE");
                }

                Action <int, int> updateBackground = (_, icons) =>
                {
                    var rows = Math.Max(palette.MinimumRows, (icons + palette.Columns - 1) / palette.Columns);
                    rows = Math.Min(rows, palette.MaximumRows);

                    if (background != null)
                    {
                        background.RemoveChildren();

                        var rowHeight = backgroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = backgroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            background.AddChild(row);
                        }

                        if (backgroundBottom == null)
                        {
                            return;
                        }

                        backgroundBottom.Bounds.Y = rows * rowHeight;
                        background.AddChild(backgroundBottom);
                    }

                    if (foreground != null)
                    {
                        foreground.RemoveChildren();

                        var rowHeight = foregroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = foregroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            foreground.AddChild(row);
                        }
                    }
                };

                palette.OnIconCountChanged += updateBackground;

                // Set the initial palette state
                updateBackground(0, 0);
            }

            var typesContainer = widget.Get("PRODUCTION_TYPES");

            foreach (var i in typesContainer.Children)
            {
                SetupProductionGroupButton(orderManager, i as ProductionTypeButtonWidget);
            }

            var ticker = widget.Get <LogicTickerWidget>("PRODUCTION_TICKER");

            ticker.OnTick = () =>
            {
                if (palette.CurrentQueue == null || palette.DisplayedIconCount == 0)
                {
                    // Select the first active tab
                    foreach (var b in typesContainer.Children)
                    {
                        var button = b as ProductionTypeButtonWidget;
                        if (button == null || button.IsDisabled())
                        {
                            continue;
                        }

                        button.OnClick();
                        break;
                    }
                }
            };

            // Hook up scroll up and down buttons on the palette
            var scrollDown = widget.GetOrNull <ButtonWidget>("SCROLL_DOWN_BUTTON");

            if (scrollDown != null)
            {
                scrollDown.OnClick    = palette.ScrollDown;
                scrollDown.IsVisible  = () => palette.TotalIconCount > (palette.MaxIconRowOffset * palette.Columns);
                scrollDown.IsDisabled = () => !palette.CanScrollDown;
            }

            var scrollUp = widget.GetOrNull <ButtonWidget>("SCROLL_UP_BUTTON");

            if (scrollUp != null)
            {
                scrollUp.OnClick    = palette.ScrollUp;
                scrollUp.IsVisible  = () => palette.TotalIconCount > (palette.MaxIconRowOffset * palette.Columns);
                scrollUp.IsDisabled = () => !palette.CanScrollUp;
            }

            SetMaximumVisibleRows(palette);
        }
Example #6
0
        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
        {
            var mapRules = palette.World.Map.Rules;
            var pm       = palette.World.LocalPlayer.PlayerActor.Trait <PowerManager>();
            var pr       = palette.World.LocalPlayer.PlayerActor.Trait <PlayerResources>();

            widget.IsVisible = () => palette.TooltipActor != null;
            var nameLabel     = widget.Get <LabelWidget>("NAME");
            var requiresLabel = widget.Get <LabelWidget>("REQUIRES");
            var powerLabel    = widget.Get <LabelWidget>("POWER");
            var timeLabel     = widget.Get <LabelWidget>("TIME");
            var costLabel     = widget.Get <LabelWidget>("COST");
            var descLabel     = widget.Get <LabelWidget>("DESC");

            var    font         = Game.Renderer.Fonts[nameLabel.Font];
            var    descFont     = Game.Renderer.Fonts[descLabel.Font];
            var    requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            string lastActor    = null;

            tooltipContainer.BeforeRender = () =>
            {
                var actor = palette.TooltipActor;
                if (actor == null || actor == lastActor)
                {
                    return;
                }

                var info      = mapRules.Actors[actor];
                var tooltip   = info.Traits.Get <TooltipInfo>();
                var buildable = info.Traits.Get <BuildableInfo>();
                var cost      = info.Traits.Get <ValuedInfo>().Cost;
                var bi        = info.Traits.GetOrDefault <BuildingInfo>();

                nameLabel.GetText = () => tooltip.Name;

                var prereqs        = buildable.Prerequisites.Select(a => ActorName(mapRules, a));
                var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power       = bi != null ? bi.Power : 0;
                var powerString = "P: {0}".F(power);
                powerLabel.GetText  = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                                        ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;

                var lowpower = pm.PowerState != PowerState.Normal;
                var time     = palette.CurrentQueue.GetBuildTime(actor)
                               * ((lowpower) ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
                var timeString = "T: {0}".F(WidgetUtils.FormatTime(time));
                timeLabel.GetText  = () => timeString;
                timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;

                var costString = "$: {0}".F(cost);
                costLabel.GetText  = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayOre >= cost
                                        ? Color.White : Color.Red;

                var descString = tooltip.Description.Replace("\\n", "\n");
                descLabel.GetText = () => descString;

                var leftWidth = new[] { font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
                var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
                timeLabel.Bounds.X  = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
                widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;

                var leftHeight  = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y;
                var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y;
                widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;

                lastActor = actor;
            };
        }
		public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
		{
			var mapRules = palette.World.Map.Rules;
			var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
			var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();

			widget.IsVisible = () => palette.TooltipActor != null;
			var nameLabel = widget.Get<LabelWidget>("NAME");
			var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
			var powerLabel = widget.Get<LabelWidget>("POWER");
			var timeLabel = widget.Get<LabelWidget>("TIME");
			var costLabel = widget.Get<LabelWidget>("COST");
			var descLabel = widget.Get<LabelWidget>("DESC");

			var font = Game.Renderer.Fonts[nameLabel.Font];
			var descFont = Game.Renderer.Fonts[descLabel.Font];
			var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
			string lastActor = null;

			tooltipContainer.BeforeRender = () =>
			{
				var actor = palette.TooltipActor;
				if (actor == null || actor == lastActor)
					return;

				var info = mapRules.Actors[actor];
				var tooltip = info.Traits.Get<TooltipInfo>();
				var buildable = info.Traits.Get<BuildableInfo>();
				var cost = info.Traits.Get<ValuedInfo>().Cost;
				var bi = info.Traits.GetOrDefault<BuildingInfo>();

				nameLabel.GetText = () => tooltip.Name;

				var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
				var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
				requiresLabel.GetText = () => requiresString;

				var power = bi != null ? bi.Power : 0;
				var powerString = "P: {0}".F(power);
				powerLabel.GetText = () => powerString;
				powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
					? Color.White : Color.Red;
				powerLabel.IsVisible = () => power != 0;

				var lowpower = pm.PowerState != PowerState.Normal;
				var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor)
					* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
				var timeString = "T: {0}".F(WidgetUtils.FormatTime(time));
				timeLabel.GetText = () => timeString;
				timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;

				var costString = "$: {0}".F(cost);
				costLabel.GetText = () => costString;
				costLabel.GetColor = () => pr.DisplayCash + pr.DisplayResources >= cost
					? Color.White : Color.Red;

				var descString = tooltip.Description.Replace("\\n", "\n");
				descLabel.GetText = () => descString;

				var leftWidth = new[] { font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
				var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
				timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
				widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;

				var leftHeight = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y;
				var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y;
				widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;

				lastActor = actor;
			};
		}
        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
        {
            var mapRules = palette.World.Map.Rules;
            var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
            var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();

            widget.IsVisible = () => palette.TooltipIcon != null;
            var nameLabel = widget.Get<LabelWidget>("NAME");
            var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
            var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
            var powerLabel = widget.Get<LabelWidget>("POWER");
            var powerIcon = widget.Get<ImageWidget>("POWER_ICON");
            var timeLabel = widget.Get<LabelWidget>("TIME");
            var timeIcon = widget.Get<ImageWidget>("TIME_ICON");
            var costLabel = widget.Get<LabelWidget>("COST");
            var costIcon = widget.Get<ImageWidget>("COST_ICON");
            var descLabel = widget.Get<LabelWidget>("DESC");

            var iconMargin = timeIcon.Bounds.X;

            var font = Game.Renderer.Fonts[nameLabel.Font];
            var descFont = Game.Renderer.Fonts[descLabel.Font];
            var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            ActorInfo lastActor = null;

            tooltipContainer.BeforeRender = () =>
            {
                if (palette.TooltipIcon == null)
                    return;

                var actor = palette.TooltipIcon.Actor;
                if (actor == null || actor == lastActor)
                    return;

                var tooltip = actor.Traits.Get<TooltipInfo>();
                var buildable = actor.Traits.Get<BuildableInfo>();
                var cost = actor.Traits.Get<ValuedInfo>().Cost;
                var pi = actor.Traits.GetOrDefault<PowerInfo>();

                nameLabel.GetText = () => tooltip.Name;

                var hotkey = palette.TooltipIcon.Hotkey;
                var nameWidth = font.Measure(tooltip.Name).X;
                var hotkeyText = "({0})".F(hotkey.DisplayString());
                var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
                hotkeyLabel.GetText = () => hotkeyText;
                hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
                hotkeyLabel.Visible = hotkey.IsValid();

                var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
                var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power = pi != null ? pi.Amount : 0;
                var powerString = power.ToString();
                powerLabel.GetText = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                    ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;
                powerIcon.IsVisible = () => power != 0;

                var lowpower = pm.PowerState != PowerState.Normal;
                var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor.Name)
                    * (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
                var timeString = WidgetUtils.FormatTime(time);
                timeLabel.GetText = () => timeString;
                timeLabel.GetColor = () => lowpower ? Color.Red : Color.White;

                var costString = cost.ToString();
                costLabel.GetText = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayResources >= cost
                    ? Color.White : Color.Red;

                var descString = tooltip.Description.Replace("\\n", "\n");
                descLabel.GetText = () => descString;

                var leftWidth = new[] { nameWidth + hotkeyWidth, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
                var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);

                timeIcon.Bounds.X = powerIcon.Bounds.X = costIcon.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
                timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = timeIcon.Bounds.Right + iconMargin;
                widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X + timeIcon.Bounds.Width + iconMargin;

                var leftHeight = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y;
                var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y;
                widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;

                lastActor = actor;
            };
        }
Example #9
0
        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
        {
            var pm = palette.world.LocalPlayer.PlayerActor.Trait <PowerManager>();
            var pr = palette.world.LocalPlayer.PlayerActor.Trait <PlayerResources>();

            widget.IsVisible = () => palette.TooltipActor != null;
            var nameLabel     = widget.GetWidget <LabelWidget>("NAME");
            var requiresLabel = widget.GetWidget <LabelWidget>("REQUIRES");
            var powerLabel    = widget.GetWidget <LabelWidget>("POWER");
            var timeLabel     = widget.GetWidget <LabelWidget>("TIME");
            var costLabel     = widget.GetWidget <LabelWidget>("COST");

            var    font         = Game.Renderer.Fonts[nameLabel.Font];
            var    requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            string lastActor    = null;

            tooltipContainer.BeforeRender = () =>
            {
                var actor = palette.TooltipActor;
                if (actor == null || actor == lastActor)
                {
                    return;
                }

                var info      = Rules.Info[actor];
                var tooltip   = info.Traits.Get <TooltipInfo>();
                var buildable = info.Traits.Get <BuildableInfo>();
                var cost      = info.Traits.Get <ValuedInfo>().Cost;
                var bi        = info.Traits.GetOrDefault <BuildingInfo>();

                nameLabel.GetText = () => tooltip.Name;

                var prereqs        = buildable.Prerequisites.Select(a => ActorName(a));
                var requiresString = prereqs.Any() ? "Requires {0}".F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power       = bi != null ? bi.Power : 0;
                var powerString = "P: {0}".F(power);
                powerLabel.GetText  = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                                        ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;

                var timeString = "T: {0}".F(WidgetUtils.FormatTime(palette.CurrentQueue.GetBuildTime(actor)));
                timeLabel.GetText = () => timeString;

                var costString = "$: {0}".F(cost);
                costLabel.GetText  = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayOre >= cost
                                        ? Color.White : Color.Red;

                var leftWidth = Math.Max(font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X);
                var rightWidth = new [] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
                timeLabel.Bounds.X  = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
                widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;

                widget.Bounds.Height = power != 0 ? 65 : 45;
                lastActor            = actor;
            };
        }
        public ClassicProductionLogic(Widget widget, OrderManager orderManager, World world)
        {
            this.world = world;
            palette = widget.Get<ProductionPaletteWidget>("PRODUCTION_PALETTE");

            var background = widget.GetOrNull("PALETTE_BACKGROUND");
            var foreground = widget.GetOrNull("PALETTE_FOREGROUND");
            if (background != null || foreground != null)
            {
                Widget backgroundTemplate = null;
                Widget backgroundBottom = null;
                Widget foregroundTemplate = null;

                if (background != null)
                {
                    backgroundTemplate = background.Get("ROW_TEMPLATE");
                    backgroundBottom = background.GetOrNull("BOTTOM_CAP");
                }

                if (foreground != null)
                    foregroundTemplate = foreground.Get("ROW_TEMPLATE");

                Action<int, int> updateBackground = (_, icons) =>
                {
                    // Minimum of four rows to make space for the production buttons.
                    var rows = Math.Max(4, (icons + palette.Columns - 1) / palette.Columns);

                    if (background != null)
                    {
                        background.RemoveChildren();

                        var rowHeight = backgroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = backgroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            background.AddChild(row);
                        }

                        if (backgroundBottom == null)
                            return;

                        backgroundBottom.Bounds.Y = rows * rowHeight;
                        background.AddChild(backgroundBottom);
                    }

                    if (foreground != null)
                    {
                        foreground.RemoveChildren();

                        var rowHeight = foregroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = foregroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            foreground.AddChild(row);
                        }
                    }
                };

                palette.OnIconCountChanged += updateBackground;

                // Set the initial palette state
                updateBackground(0, 0);
            }

            var typesContainer = widget.Get("PRODUCTION_TYPES");
            foreach (var i in typesContainer.Children)
                SetupProductionGroupButton(orderManager, i as ProductionTypeButtonWidget);

            var ticker = widget.Get<LogicTickerWidget>("PRODUCTION_TICKER");
            ticker.OnTick = () =>
            {
                if (palette.CurrentQueue == null || palette.IconCount == 0)
                {
                    // Select the first active tab
                    foreach (var b in typesContainer.Children)
                    {
                        var button = b as ProductionTypeButtonWidget;
                        if (button == null || button.IsDisabled())
                            continue;

                        button.OnClick();
                        break;
                    }
                }
            };
        }
Example #11
0
        public ClassicProductionLogic(Widget widget, OrderManager orderManager, World world)
        {
            this.world = world;
            palette    = widget.Get <ProductionPaletteWidget>("PRODUCTION_PALETTE");

            var background = widget.GetOrNull("PALETTE_BACKGROUND");
            var foreground = widget.GetOrNull("PALETTE_FOREGROUND");

            if (background != null || foreground != null)
            {
                Widget backgroundTemplate = null;
                Widget backgroundBottom   = null;
                Widget foregroundTemplate = null;

                if (background != null)
                {
                    backgroundTemplate = background.Get("ROW_TEMPLATE");
                    backgroundBottom   = background.GetOrNull("BOTTOM_CAP");
                }

                if (foreground != null)
                {
                    foregroundTemplate = foreground.Get("ROW_TEMPLATE");
                }

                Action <int, int> updateBackground = (_, icons) =>
                {
                    // Minimum of four rows to make space for the production buttons.
                    var rows = Math.Max(4, (icons + palette.Columns - 1) / palette.Columns);

                    if (background != null)
                    {
                        background.RemoveChildren();

                        var rowHeight = backgroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = backgroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            background.AddChild(row);
                        }

                        if (backgroundBottom == null)
                        {
                            return;
                        }

                        backgroundBottom.Bounds.Y = rows * rowHeight;
                        background.AddChild(backgroundBottom);
                    }

                    if (foreground != null)
                    {
                        foreground.RemoveChildren();

                        var rowHeight = foregroundTemplate.Bounds.Height;
                        for (var i = 0; i < rows; i++)
                        {
                            var row = foregroundTemplate.Clone();
                            row.Bounds.Y = i * rowHeight;
                            foreground.AddChild(row);
                        }
                    }
                };

                palette.OnIconCountChanged += updateBackground;

                // Set the initial palette state
                updateBackground(0, 0);
            }

            var typesContainer = widget.Get("PRODUCTION_TYPES");

            foreach (var i in typesContainer.Children)
            {
                SetupProductionGroupButton(orderManager, i as ProductionTypeButtonWidget);
            }

            var ticker = widget.Get <LogicTickerWidget>("PRODUCTION_TICKER");

            ticker.OnTick = () =>
            {
                if (palette.CurrentQueue == null || palette.IconCount == 0)
                {
                    // Select the first active tab
                    foreach (var b in typesContainer.Children)
                    {
                        var button = b as ProductionTypeButtonWidget;
                        if (button == null || button.IsDisabled())
                        {
                            continue;
                        }

                        button.OnClick();
                        break;
                    }
                }
            };
        }