Esempio n. 1
0
        /// <summary>
        /// Updates the command panel and the target position input slots.
        /// </summary>
        private void UpdateSlots()
        {
            this.commandPanelSlots       = new CommandPanelSlot[BUTTON_ARRAY_ROWS, BUTTON_ARRAY_COLS];
            this.targetPositionInputSlot = null;
            foreach (CommandInputListener activeListener in this.activeListeners)
            {
                this.TryAttachAsButtonListener(activeListener);
                this.TryAttachAsTargetPositionListener(activeListener);
            }

            /// Highlight the button with the highest priority.
            CommandPanelSlot slotToHighlight = null;

            for (int row = 0; row < BUTTON_ARRAY_ROWS; row++)
            {
                for (int col = 0; col < BUTTON_ARRAY_COLS; col++)
                {
                    if (this.commandPanelSlots[row, col] == null)
                    {
                        continue;
                    }
                    if (this.commandPanelSlots[row, col].ButtonState != CommandButtonStateEnum.Enabled)
                    {
                        continue;
                    }
                    if (!this.commandPanelSlots[row, col].ButtonListener.IsHighlighted)
                    {
                        continue;
                    }
                    if (slotToHighlight == null || this.commandPanelSlots[row, col].ButtonListener.Priority > slotToHighlight.ButtonListener.Priority)
                    {
                        slotToHighlight = this.commandPanelSlots[row, col];
                    }
                    else if (this.commandPanelSlots[row, col].ButtonListener.Priority == slotToHighlight.ButtonListener.Priority)
                    {
                        throw new InvalidOperationException(string.Format("IButtonListeners with the same priority should be highlighted at command panel slots {0} and {1}!", new RCIntVector(row, col), slotToHighlight.ButtonListener.CommandPanelSlot));
                    }
                }
            }
            if (slotToHighlight != null)
            {
                slotToHighlight.ButtonState = CommandButtonStateEnum.Highlighted;
            }
        }
Esempio n. 2
0
        /// <see cref="ICommandManagerBC.PressCommandButton"/>
        public void PressCommandButton(RCIntVector panelPosition)
        {
            if (panelPosition == RCIntVector.Undefined)
            {
                throw new ArgumentNullException("panelPosition");
            }

            CommandPanelSlot slot = this.commandPanelSlots[panelPosition.X, panelPosition.Y];

            if (slot == null)
            {
                throw new InvalidOperationException(string.Format("There is no command button on the command panel at {0}!", panelPosition));
            }
            if (slot.ButtonState == CommandButtonStateEnum.Disabled)
            {
                throw new InvalidOperationException(string.Format("The command button at {0} is disabled!", panelPosition));
            }

            this.CompleteListener(slot.Listener);
        }