Example #1
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);
            };
        }
Example #2
0
        public bool HandleMouseCursor(InputMessage message)
        {
            if (!IsVisible)
            {
                return(false);
            }

            switch (message.MessageType)
            {
            case InputMessageType.MouseMove:
                var distance = (message.Value.MousePosition.ToVector2() - _center).Length();
                if (distance <= _width / 2)
                {
                    _isHovered = true;
                    return(true);
                }
                _isHovered = false;
                break;

            case InputMessageType.MouseLeftButtonUp:
                if (_isHovered)
                {
                    if (_enabled)
                    {
                        CommandButtonCallback.HandleCommand(_game, CommandButton, _objectDefinition);
                        _game.Audio.PlayAudioEvent("Gui_PalantirCommandButtonClick");
                    }
                    return(true);
                }
                break;

            case InputMessageType.MouseRightButtonUp:
                if (_isHovered)
                {
                    if (_count > 0)
                    {
                        var index = 0;
                        // upgrades first!!
                        if (CommandButton.Upgrade != null && CommandButton.Upgrade.Value != null)
                        {
                            index = CommandButton.Upgrade.Value.InternalId;
                        }
                        else if (CommandButton.Object != null && CommandButton.Object.Value != null)
                        {
                            for (var i = 0; i < _owner.ProductionUpdate.ProductionQueue.Count; i++)
                            {
                                var job = _owner.ProductionUpdate.ProductionQueue[i];
                                if (job.ObjectDefinition != null && job.ObjectDefinition.Name == CommandButton.Object.Value.Name)
                                {
                                    index = i;
                                }
                            }
                        }

                        CommandButtonCallback.HandleCommand(_game, CommandButton, _objectDefinition, true, index);
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }