private static void ApplyCommandSets(Player player, GeneralsControlBar controlBar)
        {
            var rank1 = player.Template.PurchaseScienceCommandSetRank1;

            ApplyRankCommandSet(rank1.Value, 1, player, controlBar);

            var rank3 = player.Template.PurchaseScienceCommandSetRank3;

            ApplyRankCommandSet(rank3.Value, 3, player, controlBar);

            var rank8 = player.Template.PurchaseScienceCommandSetRank8;

            ApplyRankCommandSet(rank8.Value, 8, player, controlBar);
        }
        public static void Update(Player player, GeneralsControlBar controlBar)
        {
            if (_window == null)
            {
                return;
            }

            var currentRank = player.Rank.CurrentRank;
            //Update title
            var lblTitle = _window.Controls.FindControl("GeneralsExpPoints.wnd:StaticTextTitle") as Label;

            lblTitle.Text = ("SCIENCE:Rank" + currentRank).Translate();

            var lblLevel = _window.Controls.FindControl("GeneralsExpPoints.wnd:StaticTextLevel") as Label;

            lblLevel.Text = ("SCIENCE:Rank").TranslateFormatted(currentRank); // TODO: this doesn't replace %d correctly yet

            ApplyCommandSets(player, controlBar);
        }
        private static void ApplyRankCommandSet(CommandSet commandSet, int rank, Player player, GeneralsControlBar controlBar)
        {
            for (int i = 0; i < commandSet.Buttons.Count; i++)
            {
                var buttonControl = _window.Controls.FindControl($"GeneralsExpPoints.wnd:ButtonRank{rank}Number" + i) as Button;
                if (commandSet != null && commandSet.Buttons.TryGetValue(i + 1, out var commandButtonReference))
                {
                    var commandButton = commandButtonReference.Value;

                    CommandButtonUtils.SetCommandButton(buttonControl, commandButton, controlBar);

                    switch (commandButton.Command)
                    {
                    case CommandType.PurchaseScience:
                        buttonControl.Enabled = player.ScienceAvailable(commandButton.Science[0].Value);
                        break;
                    }
                }
            }
        }
Example #4
0
        public static void SetCommandButton(Button buttonControl, CommandButton commandButton, GeneralsControlBar controlBar)
        {
            buttonControl.BackgroundImage = buttonControl.Window.ImageLoader.CreateFromMappedImageReference(commandButton.ButtonImage);

            buttonControl.DisabledBackgroundImage = buttonControl.BackgroundImage?.WithGrayscale(true);

            buttonControl.BorderColor = GetBorderColor(commandButton.ButtonBorderType, controlBar.Scheme).ToColorRgbaF();
            buttonControl.BorderWidth = 1;

            buttonControl.HoverOverlayImage  = controlBar.CommandButtonHover;
            buttonControl.PushedOverlayImage = controlBar.CommandButtonPush;

            var objectDefinition = commandButton.Object?.Value;

            buttonControl.SystemCallback = (control, message, context) =>
            {
                Logger.Debug($"Button callback: {control.Name}, {commandButton.Command}");
                Logger.Debug($"Relevant object: {objectDefinition?.Name}");

                CommandButtonCallback.HandleCommand(context.Game, commandButton, objectDefinition, false);
            };

            buttonControl.InputCallback = (control, message, context) =>
            {
                //TODO: fix the commandbutton description
                var windowManager = buttonControl.Window.Game.Scene2D.WndWindowManager;
                if (message.MessageType == WndWindowMessageType.MouseEnter)
                {
                    var name        = commandButton.TextLabel.Translate();
                    var description = commandButton.DescriptLabel.Translate();
                    var cost        = "";

                    // TODO: set the string correctly
                    switch (commandButton.Command)
                    {
                    case CommandType.DozerConstruct:
                    case CommandType.UnitBuild:
                        cost = commandButton.Object.Value.BuildCost.ToString();
                        break;

                    case CommandType.PurchaseScience:
                        cost        = commandButton.Science[0].Value.SciencePurchasePointCost.ToString();
                        description = commandButton.Science[0].Value.Description.Translate();
                        break;
                    }
                    controlBar.ShowDescription(name, cost, description);
                }
                else if (message.MessageType == WndWindowMessageType.MouseExit)
                {
                    controlBar.HideDescription();
                }

                control.DefaultInput(control, message, context);
            };
        }