Пример #1
0
        void checkHotKeyGroups(GameTime gameTime)
        {
            int elapsedMilliseconds = (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            for (int i = 0; i < 10; i++)
            {
                timeSinceLastHotkeyGroupSelect[i] += elapsedMilliseconds;

                if (keyboardState.IsKeyUp(hotKeyGroupKeys[i]))
                    allowHotkeyGroupSelect[i] = true;
                else if (allowHotkeyGroupSelect[i] && keyboardState.IsKeyDown(hotKeyGroupKeys[i]))
                {
                    allowHotkeyGroupSelect[i] = false;
                    if (usingTargetedCommand)
                    {
                        stopTargetedCommands();
                    }
                    if (placingStructure)
                        placingStructure = false;

                    // assign hotkey group
                    if (keyboardState.IsKeyDown(Keys.LeftControl))
                    {
                        selectedUnitsChanged = true;

                        //HotkeyGroups[i] = new List<RtsObject>(SelectedUnits.ToArray<RtsObject>());
                        HotkeyGroups[i] = new List<RtsObject>(SelectedUnits.ToArray());
                    }
                    // select hotkey group
                    else
                    {
                        selectedUnitsChanged = true;
                        if (HotkeyGroups[i].Count > 0)
                        {
                            //SelectedUnits = new List<Unit>(HotkeyGroups[i].ToArray<Unit>());
                            SelectedUnits = new Selection(HotkeyGroups[i]);
                            if (lastHotKeyGroupSelected == i &&
                                timeSinceLastHotkeyGroupSelect[i] <= doubleHotkeySelectDelay)
                                centerCameraOnSelectedUnits();
                            timeSinceLastHotkeyGroupSelect[i] = 0;
                            lastHotKeyGroupSelected = i;
                        }
                    }
                }
            }

            /*timeSinceLastHotkeyGroupSelect += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (keyboardState.IsKeyUp(Keys.D0) && keyboardState.IsKeyUp(Keys.D1) &&
                keyboardState.IsKeyUp(Keys.D2) && keyboardState.IsKeyUp(Keys.D3) &&
                keyboardState.IsKeyUp(Keys.D4) && keyboardState.IsKeyUp(Keys.D5) &&
                keyboardState.IsKeyUp(Keys.D6) && keyboardState.IsKeyUp(Keys.D7) &&
                keyboardState.IsKeyUp(Keys.D8) && keyboardState.IsKeyUp(Keys.D9))
                allowHotkeyGroupSelect = true;
            else if (allowHotkeyGroupSelect &&
                (keyboardState.IsKeyDown(Keys.D0) || keyboardState.IsKeyDown(Keys.D1) ||
                keyboardState.IsKeyDown(Keys.D2) || keyboardState.IsKeyDown(Keys.D3) ||
                keyboardState.IsKeyDown(Keys.D4) || keyboardState.IsKeyDown(Keys.D5) ||
                keyboardState.IsKeyDown(Keys.D6) || keyboardState.IsKeyDown(Keys.D7) ||
                keyboardState.IsKeyDown(Keys.D8) || keyboardState.IsKeyDown(Keys.D9)))
            {
                allowHotkeyGroupSelect = false;
                if (usingAttackCommand)
                {
                    usingAttackCommand = false;
                    winForm.Cursor = normalCursor;
                }

                if (keyboardState.IsKeyDown(Keys.LeftControl))
                {
                    selectedUnitsChanged = true;
                    if (keyboardState.IsKeyDown(Keys.D0))
                        HotkeyGroups[0] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D1))
                        HotkeyGroups[1] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D2))
                        HotkeyGroups[2] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D3))
                        HotkeyGroups[3] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D4))
                        HotkeyGroups[4] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D5))
                        HotkeyGroups[5] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D6))
                        HotkeyGroups[6] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D7))
                        HotkeyGroups[7] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D8))
                        HotkeyGroups[8] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else if (keyboardState.IsKeyDown(Keys.D9))
                        HotkeyGroups[9] = new List<Unit>(SelectedUnits.ToArray<Unit>());
                    else
                        selectedUnitsChanged = false;
                }
                else
                {
                    selectedUnitsChanged = true;
                    if (keyboardState.IsKeyDown(Keys.D0) && HotkeyGroups[0].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[0].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 0 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 0;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D1) && HotkeyGroups[1].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[1].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 1 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 1;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D2) && HotkeyGroups[2].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[2].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 2 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 2;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D3) && HotkeyGroups[3].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[3].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 3 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 3;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D4) && HotkeyGroups[4].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[4].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 4 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 4;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D5) && HotkeyGroups[5].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[5].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 5 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 5;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D6) && HotkeyGroups[6].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[6].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 6 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 6;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D7) && HotkeyGroups[7].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[7].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 7 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 7;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D8) && HotkeyGroups[8].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[8].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 8 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 8;
                    }
                    else if (keyboardState.IsKeyDown(Keys.D9) && HotkeyGroups[9].Count > 0)
                    {
                        SelectedUnits = new List<Unit>(HotkeyGroups[9].ToArray<Unit>());
                        if (lastHotkeyGroupSelected == 9 && timeSinceLastHotkeyGroupSelect <= doubleHotkeySelectDelay)
                            centerCameraOnSelectedUnits();
                        timeSinceLastHotkeyGroupSelect = 0;
                        lastHotkeyGroupSelected = 9;
                    }
                    else
                        selectedUnitsChanged = false;
                }
            }*/
        }
Пример #2
0
 public Selection(Selection s)
     : this(s.objects)
 {
 }