Пример #1
0
        void checkForLeftClick(GameTime gameTime)
        {
            // check if clicked on unit portrait
            if (SelectedUnits.Count == 1)
            {
                if (mouseState.LeftButton == ButtonState.Pressed &&
                    unitPictureRectangle.Contains(mouseState.X, mouseState.Y))
                {
                    centerCameraOnSelectedUnits();
                    return;
                }
            }
            // check if clicked on a unit box
            foreach (UnitButton box in unitButtons)
            {
                if (box.Triggered)
                {
                    // holding shift
                    if (usingShift)
                    {
                        SelectedUnits.Remove(box.Unit);
                    }
                    // not holding shift
                    else
                    {
                        SelectedUnits.Clear();
                        SelectedUnits.Add(box.Unit);
                    }
                    selectedUnitsChanged = true;
                    return;
                }
            }
            //check if clicked on structure queue item
            if (QueuedItems != null)
            {
                if (mouseState.LeftButton == ButtonState.Released)
                {
                    allowRemoveFromQueue = true;
                }
                else if (allowRemoveFromQueue)
                {
                    allowRemoveFromQueue = false;
                    //foreach (SimpleButton item in QueuedItems)
                    for (int i = 0; i < QueuedItems.Length; i++)
                    {
                        Structure s = SelectedUnits[0] as Structure;
                        if (mouseState.LeftButton == ButtonState.Pressed && QueuedItems[i].Contains(mouseState.X, mouseState.Y) && s.BuildQueue.Count > i)
                        //if (QueuedItems[i].Triggered)
                        {
                            //s.BuildQueue.RemoveAt(i);
                            s.RemoveFromBuildQueue(i);
                            ScheduledStructureCommand cancelCommand = new ScheduledStructureCommand(currentScheduleTime, s, CommandButtonType.Cancel);
                            cancelCommand.Index = (short)i;
                            Player.Me.ScheduledActions.Add(cancelCommand);
                            TransmitStructureCommand(s, cancelCommand.CommandType, short.MinValue, (short)i);
                        }
                    }
                }
            }

            if ((usingTargetedCommand && mouseState.LeftButton == ButtonState.Pressed) || selecting)
            {
                allowMiniMapClick = false;
            }
            else if (mouseState.LeftButton == ButtonState.Released)
            {
                allowMiniMapClick = true;
            }

            // clicked on bottom ui
            if (mouseState.Y > worldViewport.Height)
            {
                if (!selecting)
                {
                    SelectBox.Enabled = false;
                    //SelectBox.Clear();
                    //SelectingUnits.Clear();
                }
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    if (minimap.Contains(mouseState.X, mouseState.Y))
                    {
                        if (allowMiniMapClick)
                        {
                            //Vector2 mousePosition = Vector2.Transform(new Vector2((mouseState.X - minimapPosX) / minimapToMapRatioX, (mouseState.Y - minimapPosY) / minimapToMapRatioY), camera.get_transformation(worldViewport));

                            Vector2 mousePosition      = new Vector2(mouseState.X, mouseState.Y);
                            Vector2 minimapCenterPoint = new Vector2(minimap.X + minimap.Width / 2f, minimap.Y + minimap.Height / 2f);

                            float distance = Vector2.Distance(mousePosition, minimapCenterPoint);
                            float angle    = (float)Math.Atan2(mousePosition.Y - minimapCenterPoint.Y, mousePosition.X - minimapCenterPoint.X);

                            mousePosition = new Vector2(minimapCenterPoint.X + distance * (float)Math.Cos(angle - camera.Rotation), minimapCenterPoint.Y + distance * (float)Math.Sin(angle - camera.Rotation));

                            camera.Pos = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY);

                            //Matrix transform = camera.get_minimap_transformation(minimapViewport);
                            //Vector2 mousePosition = Vector2.Transform(new Vector2(mouseState.X - minimapPosX, mouseState.Y - minimapPosY), transform);

                            //camera.Pos = new Vector2((mouseState.X - minimapPosX) / minimapToMapRatioX, (mouseState.Y - minimapPosY) / minimapToMapRatioY);

                            //float asdf = minimapToMapRatioX - minimapToMapRatioY;
                            //float smallest = minimapToMapRatioY;

                            //camera.Pos = new Vector2(mousePosition.X / minimapToMapRatioX, mousePosition.Y / minimapToMapRatioY);
                            //camera.Pos = mousePosition;
                            stopTargetedCommands();
                        }
                    }
                    else
                    {
                        stopTargetedCommands();
                        //SimpleButton.PressingHotkey = false;
                    }
                }
            }
            // clicked somewhere above bottom ui
            else
            {
                if (mouseState.LeftButton == ButtonState.Released)
                {
                    SelectBox.Enabled = true;
                }
            }

            if (usingTargetedCommand)
            {
                if (mouseState.LeftButton == ButtonState.Released)
                {
                    allowTargetedCommand = true;
                }
                else if (allowTargetedCommand && mouseState.LeftButton == ButtonState.Pressed)
                {
                    allowTargetedCommand = false;

                    allowSelect       = false;
                    SelectBox.Enabled = false;

                    Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
                    if (minimap.Contains(mouseState.X, mouseState.Y))
                    {
                        mousePosition = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY);
                    }
                    else
                    {
                        mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(worldViewport)));
                    }

                    if (usingAttackCommand)
                    {
                        giveAttackCommand(mousePosition);
                    }
                    else if (usingRallyPointCommand)
                    {
                        setRallyPoint(mousePosition);
                    }

                    if (usingShift)
                    {
                        queueingTargetedCommand = true;
                    }
                    else
                    {
                        stopTargetedCommands();
                    }
                }
            }
            else if (placingStructure)
            {
                if (mouseState.LeftButton == ButtonState.Released)
                {
                    allowClickToPlaceStructure = true;
                }
                else if (allowClickToPlaceStructure && mouseState.LeftButton == ButtonState.Pressed)
                {
                    allowClickToPlaceStructure = false;

                    allowSelect       = false;
                    SelectBox.Enabled = false;

                    if (allowPlacingStructure)
                    {
                        //new Barracks(placingStructureLocation, myTeam);
                        giveBuildCommand();

                        if (usingShift)
                        {
                            queueingPlacingStructure = true;
                        }
                        else
                        {
                            placingStructure = false;
                        }
                    }
                    else
                    {
                        playErrorSound();
                    }
                }
            }
            else
            {
                if (mouseState.LeftButton == ButtonState.Released)
                {
                    allowSelect       = true;
                    SelectBox.Enabled = true;
                }

                if (allowSelect)
                {
                    SelectUnits(gameTime);
                }
            }
        }