Esempio n. 1
0
        public static List<HotkeySheet> LoadSheetsFromXML(string file)
        {
            var retList = new List<HotkeySheet>();

            var xElements = XDocument.Load(file);
            var sheetElements = xElements.Elements("hotkeysheets").Elements("sheet");

            foreach (var sheetElement in sheetElements)
            {
                var add = new HotkeySheet();
                add.Name = sheetElement.Attribute("name").Value;

                var keyElements = sheetElement.Elements("key");

                foreach (var keyElement in keyElements)
                {
                    var addKey = new Hotkey();
                    var intKey = (int) keyElement.Attribute("key").Value.ToLower()[0];
                    const int LETTERAOFFSET = 97;
                    intKey -= LETTERAOFFSET;

                    addKey.Key = (Keyboard.Key) intKey;
                    Console.WriteLine(addKey.Key);
                    addKey.RequiresClick = Convert.ToBoolean(keyElement.Attribute("usesClick").Value);
                    addKey.SpellId = (keyElement.Attribute("spellType").Value);
                    add.Hotkeys.Add(addKey);
                }
                retList.Add(add);
            }

            return retList;
        }
Esempio n. 2
0
        public StandardMelee(InputHandler handler)
        {
            _mousePosition = new Vector2f(500, 500);

            CurrentStatus = StatusState.WaitingForPlayers;

            uiState = UIStateTypes.Normal;
            currentHotkey = null;
            currentHotkeySheet = null;
            standardHotkeys = Settings.GetSheet("standard_game_mode_controls");

            InputHandler = handler;
            myId = 0;
            map = new TileMap();

            allowMinimapCameraMove = true;
            selectedUnits = null;
            controlGroups = new Dictionary<Keyboard.Key, List<EntityBase>>();

            for (int i = 27; i <= 35; i++)
            {
                controlGroups.Add((Keyboard.Key) i, new List<EntityBase>());
            }

            controlBoxP1 = new Vector2f(0, 0);
            controlBoxP2 = new Vector2f(0, 0);
            selectedAttackMove = false;
            releaseSelect = false;

            CameraPosition = new Vector2f(0, 0);

            miniMap = new MiniMap(map, Fog, entities);

            //Load Sprites
            bottomHUDGUI = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/BottomGUI.png"));
            alertHUDAlert = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_Alert.png"));
            alertHUDUnitCreated = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_UnitCreated.png"));
            alertHUDBuildingCreated =
                new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_BuildingFinished.png"));

            avatarWorker = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_AVATAR_WORKER.png"));

            hudBoxUnit = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Unit.png"));
            hudBoxBuilding = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Building.png"));

            hudControlBox = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/ControlGroupBox.png"));
            hudControlBox.Origin = new Vector2f(hudControlBox.TextureRect.Width/2, 0);

            viewBounds = new Sprite(ExternalResources.GTexture("Resources/Sprites/Hud/ViewBounds.png"));

            //Load Sounds
            moveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/MoveCommand/0.wav"));
            attackMoveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/AttackCommand/0.wav"));

            backgroundMusic = new Music("Resources/Audio/Music/In Game/mario.wav");
            backgroundMusic.Loop = true;
            backgroundMusic.Volume = Settings.MUSICVOLUME;
            backgroundMusic.Play();
        }
Esempio n. 3
0
        public override void KeyPress(KeyEventArgs keyEvent)
        {
            //Setting Control Groups
            if ((byte) keyEvent.Code >= 27 && (byte) keyEvent.Code <= 35)
            {
                if (keyEvent.Shift)
                {
                    if (selectedUnits != null)
                    {
                        var copy = new List<EntityBase>(controlGroups[keyEvent.Code]);

                        foreach (EntityBase selectedUnit in selectedUnits)
                        {
                            if (copy.Contains(selectedUnit) == false)
                            {
                                controlGroups[keyEvent.Code].Add(selectedUnit);
                            }
                        }
                    }
                }
                else if (keyEvent.Control)
                {
                    if (selectedUnits != null)
                        controlGroups[keyEvent.Code] = new List<EntityBase>(selectedUnits);
                }
                else if (controlGroups.ContainsKey(keyEvent.Code))
                {
                    if (controlGroups[keyEvent.Code].Count > 0)
                        selectedUnits = controlGroups[keyEvent.Code].ToArray();
                }
            }
            else if (keyEvent.Code == standardHotkeys.Hotkeys[0].Key)
            {
                //Attack hotkey was pressed
                selectedAttackMove = true;
            }
            else if(selectedAttackMove == false)
            {
                EntityBase priorEntity = prioritySelectedUnit();
                if (priorEntity == null) return;

                currentHotkeySheet = GetHotkeySheet(priorEntity);

                if (currentHotkeySheet != null)
                {
                    currentHotkey = currentHotkeySheet.ProcessInput(keyEvent.Code);
                    if (currentHotkey != null && currentHotkey.RequiresClick == false)
                    {
                        sendSpellCommand(0, 0);
                    }
                    else if (currentHotkey != null)
                    {
                        uiState = UIStateTypes.SpellCast;
                    }
                }
            }
        }