private void OnKeyUp(dynamic e)
        {
            Keys xnaKey = KeyboardUtil.ToXna(e.keyCode, e.location);

            if (_keys.Contains(xnaKey))
                _keys.Remove(xnaKey);
        }
示例#2
0
 public void update()
 {
     if (KeyboardUtil.KeyPressed(Keys.W))
     {
         X++;
     }
 }
        private void OnKeyDown(dynamic e)
        {
            Keys xnaKey = KeyboardUtil.ToXna(e.keyCode, e.location);

            if (!_keys.Contains(xnaKey))
                _keys.Add(xnaKey);
        }
        private bool Canvas_KeyUp(KeyboardEvent e)
        {
            _keys.Remove(KeyboardUtil.ToXna((int)e.keyCode, int.Parse(e.location.ToString())));

            EnsureFullscreen();
            return(true);
        }
示例#5
0
文件: Menu.cs 项目: Jag-Men/Jag-Game
 public void Update(GameTime gameTime)
 {
     if (KeyboardUtil.KeyPressed(Keys.Escape))
     {
         Game1.CloseMenu();
         return;
     }
 }
示例#6
0
        async void DelayReleaseMouse(int delay)
        {
            await Task.Delay(delay * 1000);

            KeyboardUtil.MouseClick(MouseButton.Left, true);

            _mouseClickOn = false;
        }
示例#7
0
 public override void Update(GameTime gameTime)
 {
     if (KeyboardUtil.KeyPressed(Keys.Enter) && Vector2.Distance(this.XandY, Game1.Player.XandY) < Game1.TileSize * 3)
     {
         Game1.OpenMenu(new ChestInventory(this));
     }
     base.Update(gameTime);
 }
示例#8
0
 private void Keyboard_KeyUp(object sender, KeyboardKeyEventArgs e)
 {
     Microsoft.Xna.Framework.Input.Keys keys = KeyboardUtil.ToXna(e.Key);
     if (!this.keys.Contains(keys))
     {
         return;
     }
     this.keys.Remove(keys);
 }
示例#9
0
        protected override void OnElementChanged(ElementChangedEventArgs <GeckoViewForms> e)
        {
            base.OnElementChanged(e);

            if (keyboardHelper == null)
            {
                keyboardHelper = new KeyboardUtil(BlazorWebViewService.GetCurrentActivity(), Control);
            }
        }
示例#10
0
        private void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            Keys xnaKey = KeyboardUtil.ToXna(e.Key);

            if (keys.Contains(xnaKey))
            {
                keys.Remove(xnaKey);
            }
        }
示例#11
0
        private void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            Keys xnaKey = KeyboardUtil.ToXna(e.Key);

            if (!keys.Contains(xnaKey))
            {
                keys.Add(xnaKey);
            }
        }
示例#12
0
        private void Keyboard_KeyUp(object sender, KeyboardKeyEventArgs e)
        {
            Keys keys = KeyboardUtil.ToXna(e.Key);

            if (!this.keys.Contains(keys))
            {
                return;
            }
            this.keys.Remove(keys);
        }
示例#13
0
 public override void UpdateEvenWhenPaused(GameTime gameTime)
 {
     if (KeyboardUtil.KeyPressed(Keys.E))
     {
         color = Color.Blue;
     }
     else if (KeyboardUtil.KeyReleased(Keys.E))
     {
         color = Color.Purple;
     }
 }
示例#14
0
        private void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.F4 && keys.Contains(Keys.LeftAlt))
            {
                window.Close();
                return;
            }
            Keys xnaKey = KeyboardUtil.ToXna(e.Key);

            if (!keys.Contains(xnaKey))
            {
                keys.Add(xnaKey);
            }
        }
示例#15
0
        public void UpdateDialogueCheck()
        {
            if (timesgrooled >= 400)
            {
                return;
            }

            if (league != league + league)
            {
                league = league * league - league;
            }
            if (league - league != league * league)
            {
                league = league - league;
            }

            float joaje = Vector2.Distance(Game1.Player.XandY, this.XandY);

            if (KeyboardUtil.KeyPressed(Keys.Enter) && Game1.CurrentMenu == null && joaje <= Game1.TileSize * (fringus - jingus))
            {
                grool = true;
                timesgrooled++;
                emotion = Game1.Random.Next(5);
                switch (emotion)
                {
                case 0:
                    jajetron = "manawyrm";
                    break;

                case 1:
                    jajetron = "happy";
                    break;

                case 2:
                    jajetron = "sad";
                    break;

                case 3:
                    jajetron = "o";
                    break;

                case 4:
                    jajetron = "angry";
                    break;
                }
                Game1.OpenMenu(new DialogueBox("MadokaPortrait", jajetron, emotion));
            }
        }
示例#16
0
 private void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e)
 {
     if (e.Key == Key.F4 && this.keys.Contains(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
     {
         this.window.Close();
     }
     else
     {
         Microsoft.Xna.Framework.Input.Keys keys = KeyboardUtil.ToXna(e.Key);
         if (this.keys.Contains(keys))
         {
             return;
         }
         this.keys.Add(keys);
     }
 }
示例#17
0
        private bool Canvas_KeyDown(KeyboardEvent e)
        {
            e.preventDefault();

            var xnaKey = KeyboardUtil.ToXna((int)e.keyCode, (int)e.location);

            if (!_keys.Contains(xnaKey))
            {
                _keys.Add(xnaKey);
            }

            Keyboard.CapsLock = ((int)e.keyCode == 20) ? !Keyboard.CapsLock : e.getModifierState("CapsLock");
            Keyboard.NumLock  = ((int)e.keyCode == 144) ? !Keyboard.NumLock : e.getModifierState("NumLock");

            EnsureFullscreen();
            return(true);
        }
示例#18
0
        public override void Update(GameTime gameTime)
        {
            if (KeyboardUtil.KeyPressed(Keys.H) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.Sosda, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }
            if (KeyboardUtil.KeyPressed(Keys.X) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.Sword, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }
            if (KeyboardUtil.KeyPressed(Keys.P) && Vector2.Distance(this.XandY, Game1.Player.XandY) <= Game1.TileSize * 4)
            {
                Owner.AddEntity(new ItemDrop(Item.doritos, this.X + (Game1.TileSize / 2), this.Y + (Game1.TileSize / 2)));
            }

            base.Update(gameTime);
        }
示例#19
0
        private static void AutoAnimateWithCopyPasteShapesSuccessfully()
        {
            PpOperations.SelectSlide(8);
            PpOperations.SelectShapes(new List <string> {
                "Notched Right Arrow 3", "Group 2"
            });
            // use keyboard to copy & paste,
            // otherwise API's copy & paste won't trigger special clipboard event.
            KeyboardUtil.Copy();

            PpOperations.SelectSlide(9);
            KeyboardUtil.Paste();

            Assert.IsNotNull(PpOperations.SelectShape("Notched Right Arrow 3"),
                             "Copy-Paste failed, this task is flaky so please re-run.");
            var sh1 = PpOperations.SelectShape("Notched Right Arrow 3")[1];

            sh1.Rotation += 90;
            var sh2 = PpOperations.SelectShape("Group 2")[1];

            sh2.Rotation += 90;

            // go back to slide 8
            PpOperations.SelectSlide(8);

            PplFeatures.AutoAnimate();

            var actualSlide = PpOperations.SelectSlide(9);

            // remove elements that affect comparing slides
            PpOperations.SelectShapesByPrefix("text").Delete();

            var expSlide = PpOperations.SelectSlide(11);

            // remove elements that affect comparing slides
            PpOperations.SelectShapesByPrefix("text").Delete();

            // TODO: actually this expected slide looks a bit strange..
            SlideUtil.IsSameAnimations(expSlide, actualSlide);
            SlideUtil.IsSameLooking(expSlide, actualSlide);
        }
示例#20
0
文件: Program.cs 项目: shangshen/cozy
 private static void Main(string[] args)
 {
     while (true)
     {
         if (KeyboardUtil.QueryKeyState(VirtualKey.VK_SPACE))
         {
             KeyboardUtil.SendKeyEvent(VirtualKey.K_H);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_E);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_L);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_L);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_O);
             KeyboardUtil.SendKeyEvent(VirtualKey.VK_SPACE);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_W);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_O);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_R);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_L);
             KeyboardUtil.SendKeyEvent(VirtualKey.K_D);
             break;
         }
     }
     Console.ReadLine();
 }
示例#21
0
        /// <summary>
        /// "Key Up" midi event handler
        /// </summary>
        /// <param name="msg"></param>
        private void MidiIn_NoteOff(NoteOffMessage msg)
        {
            try
            {
                var maps = NoteControl.Mappings.Where(p => p.Value == msg.Pitch);
                foreach (var map in maps)
                {
                    KeyboardUtil.Send(map.Key, true);
                }

                var mouseMaps = NoteControl.MouseMappings.Where(p => p.Value == msg.Pitch);
                foreach (var map in mouseMaps)
                {
                    if (map.Key == Models.MouseBindType.LeftClick || map.Key == Models.MouseBindType.MiddleClick || map.Key == Models.MouseBindType.RightClick)
                    {
                        MouseButton btn = MouseButton.Left;
                        if (map.Key == Models.MouseBindType.LeftClick && (ConfigUtil.AppConfig.HoldLeftMouseClick || ConfigUtil.AppConfig.ToggleLeftMouseClick))
                        {
                            return;
                        }
                        if (map.Key == Models.MouseBindType.MiddleClick)
                        {
                            btn = MouseButton.Middle;
                        }
                        else if (map.Key == Models.MouseBindType.RightClick)
                        {
                            btn = MouseButton.Right;
                        }

                        KeyboardUtil.MouseClick(btn, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Midi note conversion failed(keyup): ");
            }
        }
示例#22
0
        private static Keys ToKey(ref Sdl.Keyboard.Keysym key)
        {
            Keys retVal;

            //if (UseScancodes)
            //{
            //	if (INTERNAL_scanMap.TryGetValue((int)key.scancode, out retVal))
            //	{
            //		return retVal;
            //	}
            //}
            //else
            {
                retVal = KeyboardUtil.ToKey((int)key.Sym);
                if (retVal != Keys.None)
                {
                    return(retVal);
                }
            }
            Debug.WriteLine("KEY/SCANCODE MISSING FROM SDL2->XNA DICTIONARY: " +
                            key.Sym.ToString() + " " +
                            key.Scancode.ToString());
            return(Keys.None);
        }
示例#23
0
        WPFToolbar(ToolBar toolbar) : base(toolbar)
        {
            this.toolbar = toolbar;

            toolbar.ConfigurationMenu.SelectionChanged += (o, e) => {
                var comboMenu = (ComboMenu <IConfigurationModel>)o;
                var newModel  = e.Added;
                if (newModel == null)
                {
                    return;
                }

                DispatchService.GuiDispatch(() => {
                    ActiveConfiguration = newModel;

                    if (ConfigurationChanged != null)
                    {
                        ConfigurationChanged(o, e);
                    }
                });
            };

            toolbar.RuntimeMenu.SelectionChanged += (o, e) => {
                var newModel = e.Added;
                if (newModel == null)
                {
                    return;
                }

                using (var mutableModel = newModel.GetMutableModel()) {
                    DispatchService.GuiDispatch(() => {
                        ActiveRuntime = newModel;

                        var ea = new MonoDevelop.Components.MainToolbar.HandledEventArgs();
                        if (RuntimeChanged != null)
                        {
                            RuntimeChanged(o, ea);
                        }

                        if (ea.Handled)
                        {
                            ActiveRuntime = e.Removed;
                        }
                    });
                }
            };

            toolbar.RunButton.Click += (o, e) => {
                if (RunButtonClicked != null)
                {
                    RunButtonClicked(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.TextChanged += (o, e) => {
                if (string.IsNullOrEmpty(SearchText) || SearchText == SearchPlaceholderMessage)
                {
                    return;
                }

                if (SearchEntryChanged != null)
                {
                    SearchEntryChanged(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.LostKeyboardFocus += (o, e) => {
                if (SearchEntryLostFocus != null)
                {
                    SearchEntryLostFocus(o, e);
                }
                toolbar.SearchBar.SearchText = toolbar.SearchBar.PlaceholderText;
            };

            toolbar.SearchBar.SearchBar.SizeChanged += (o, e) => {
                if (SearchEntryResized != null)
                {
                    SearchEntryResized(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.PreviewKeyDown += (o, e) => {
                var ka = new KeyEventArgs(KeyboardUtil.TranslateToXwtKey(e.Key), KeyboardUtil.GetModifiers(), e.IsRepeat, e.Timestamp);
                SendKeyPress(ka);
                e.Handled = ka.Handled;
            };

            toolbar.SearchBar.ClearIconClicked += (o, e) =>
            {
                SendKeyPress(new KeyEventArgs(Xwt.Key.Escape, KeyboardUtil.GetModifiers(), false, 0));
            };
        }
示例#24
0
        public void Update(GameTime gameTime)
        {
            if (KeyboardUtil.KeyPressed(Keys.E) || KeyboardUtil.KeyPressed(Keys.Escape))
            {
                Game1.CloseMenu();
                return;
            }

            Vector2 mouseRelative = MouseUtil.XandY - Position;

            if (MouseUtil.X >= Position.X && MouseUtil.X < Position.X + GetSize().X&&
                MouseUtil.Y >= Position.Y && MouseUtil.Y < Position.Y + GetSize().Y)
            {
                int slot = (int)((Math.Floor(mouseRelative.Y / 128) * 4) + Math.Floor(mouseRelative.X / 128));
                if (KeyboardUtil.IsKeyDown(Keys.LeftShift) && this.heldSlot == -1)
                {
                    if (originalSelected == -1)
                    {
                        originalSelected = slot;
                    }
                    currentSelected = slot;
                    Rectangle originRect  = new Rectangle((originalSelected % 4) * 128, (originalSelected / 4) * 128, 128, 128);
                    Rectangle currentRect = new Rectangle((currentSelected % 4) * 128, (currentSelected / 4) * 128, 128, 128);
                    slotSelection = Rectangle.Union(originRect, currentRect);
                    if (MouseUtil.ButtonPressed(MouseButton.LeftButton))
                    {
                        List <int> slots = new List <int>();
                        for (int i = 0; i < Game1.Player.Inventory.Length; i++)
                        {
                            int slotX = (i % 4) * 128;
                            int slotY = (i / 4) * 128;
                            if (slotSelection.Value.Contains(slotX, slotY))
                            {
                                if (Game1.Player.Inventory[i] != null)
                                {
                                    slots.Add(i);
                                }
                            }
                        }
                        List <Item> craftItems = new List <Item>();
                        slots.ForEach(_ => craftItems.Add(Game1.Player.Inventory[_]));
                        Item craft = Crafting.Craft(craftItems);
                        if (craft != null)
                        {
                            foreach (var i in slots)
                            {
                                Game1.Player.Inventory[i] = null;
                            }
                            Game1.Player.Inventory[slot] = craft;
                        }
                    }
                }
                else if (MouseUtil.ButtonPressed(MouseButton.LeftButton))
                {
                    if (Game1.Player.Inventory[slot] != null)
                    {
                        this.heldSlot = slot;
                    }
                }
                else if (MouseUtil.IsButtonUp(MouseButton.LeftButton) && this.heldSlot != -1)
                {
                    Item replacedWith = Game1.Player.Inventory[slot];
                    Game1.Player.Inventory[slot]          = Game1.Player.Inventory[this.heldSlot];
                    Game1.Player.Inventory[this.heldSlot] = replacedWith;
                    this.heldSlot = -1;
                }
            }
            else
            {
                if (MouseUtil.IsButtonUp(MouseButton.LeftButton) && this.heldSlot != -1)
                {
                    if (this.overTrash)
                    {
                        Game1.PlaySound("trash", 0.2f);
                        Game1.Player.Inventory[this.heldSlot] = null;
                        this.heldSlot = -1;
                    }
                    else
                    {
                        this.heldSlot = -1;
                    }
                }
            }
            if (this.heldSlot != -1 && Game1.Player.Inventory[this.heldSlot] == null)
            {
                this.heldSlot = -1;
            }

            if (this.heldSlot != -1)
            {
                Texture2D trash = ContentLibrary.Sprites["ui:trash1"];
                if (MouseUtil.X >= Position.X + GetSize().X&& MouseUtil.X < Position.X + GetSize().X + trash.Width &&
                    MouseUtil.Y >= Position.Y + GetSize().Y - trash.Height && MouseUtil.Y < Position.Y + GetSize().Y)
                {
                    overTrash = true;
                }
                else
                {
                    overTrash = false;
                }
            }
            else
            {
                overTrash = false;
            }

            if (KeyboardUtil.IsKeyUp(Keys.LeftShift))
            {
                slotSelection    = null;
                currentSelected  = -1;
                originalSelected = -1;
            }
        }
示例#25
0
        private void SdlRunLoop()
        {
            Sdl.Event ev;

            while (Sdl.PollEvent(out ev) == 1)
            {
                if (ev.Type == Sdl.EventType.Quit)
                {
                    _isExiting++;
                }
                else if (ev.Type == Sdl.EventType.JoyDeviceAdded)
                {
                    Joystick.AddDevice(ev.JoystickDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.ControllerDeviceRemoved)
                {
                    GamePad.RemoveDevice(ev.ControllerDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.JoyDeviceRemoved)
                {
                    Joystick.RemoveDevice(ev.JoystickDevice.Which);
                }
                else if (ev.Type == Sdl.EventType.MouseWheel)
                {
                    const int wheelDelta = 120;
                    Mouse.ScrollY += ev.Wheel.Y * wheelDelta;
                    Mouse.ScrollX += ev.Wheel.X * wheelDelta;
                }
                else if (ev.Type == Sdl.EventType.MouseMotion)
                {
                    Window.MouseState.X = ev.Motion.X;
                    Window.MouseState.Y = ev.Motion.Y;
                }
                else if (ev.Type == Sdl.EventType.KeyDown)
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
                    if (!_keys.Contains(key))
                    {
                        _keys.Add(key);
                    }
                    char character = (char)ev.Key.Keysym.Sym;
                    if (char.IsControl(character))
                    {
                        _view.CallTextInput(character, key);
                    }
                }
                else if (ev.Type == Sdl.EventType.KeyUp)
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
                    _keys.Remove(key);
                }
                else if (ev.Type == Sdl.EventType.TextInput)
                {
                    int    len  = 0;
                    string text = String.Empty;
                    unsafe
                    {
                        while (Marshal.ReadByte((IntPtr)ev.Text.Text, len) != 0)
                        {
                            len++;
                        }
                        var buffer = new byte[len];
                        Marshal.Copy((IntPtr)ev.Text.Text, buffer, 0, len);
                        text = System.Text.Encoding.UTF8.GetString(buffer);
                    }
                    if (text.Length == 0)
                    {
                        continue;
                    }
                    foreach (var c in text)
                    {
                        var key = KeyboardUtil.ToXna((int)c);
                        _view.CallTextInput(c, key);
                    }
                }
                else if (ev.Type == Sdl.EventType.DropFile)
                {
                    _view.CallFileDrop(Sdl.GetString(ev.Drop.File));
                }
                else if (ev.Type == Sdl.EventType.WindowEvent)
                {
                    if (ev.Window.WindowID == _view.Id)
                    {
                        if (ev.Window.EventID == Sdl.Window.EventId.Resized || ev.Window.EventID == Sdl.Window.EventId.SizeChanged)
                        {
                            _view.ClientResize(ev.Window.Data1, ev.Window.Data2);
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.FocusGained)
                        {
                            IsActive = true;
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.FocusLost)
                        {
                            IsActive = false;
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.Moved)
                        {
                            _view.Moved();
                        }
                        else if (ev.Window.EventID == Sdl.Window.EventId.Close)
                        {
                            _isExiting++;
                        }
                    }
                }
            }
        }
示例#26
0
        public override void Update(GameTime gameTime)
        {
            if (this != Game1.Player)
            {
                return;
            }

            if (KeyboardUtil.KeyPressed(Keys.L))
            {
                weapon = new Gunderwear();
            }

            if (KeyboardUtil.KeyPressed(Keys.H))
            {
                health--;
            }
            if (health < 0)
            {
                health++;
            }

            if (siegeOfMadoka)
            {
                somSpawnTime += gameTime.ElapsedGameTime.Milliseconds;
                if (somSpawnTime >= 1750)
                {
                    var rsm = new Reallystupidmadoka();
                    Owner.AddEntity(rsm);
                    somSpawnTime = 0;
                }
                float shortestDist = Game1.TileSize * 16;
                foreach (var i in Owner.Entities.Values)
                {
                    if (i is Reallystupidmadoka)
                    {
                        float dist = Vector2.Distance(i.XandY, this.XandY);
                        if (dist < shortestDist)
                        {
                            shortestDist = dist;
                        }
                    }
                }
                Music.Volume(Math.Max(0, (1 - (shortestDist / (Game1.TileSize * 14))) * 0.3f));
            }

            if (KeyboardUtil.KeyPressed(Keys.F2))
            {
                var tilePos = Utility.GetTilePos(X, Y);
                Owner.AddEntity(new Stupidmadoka(tilePos.X, tilePos.Y));
            }
            if (KeyboardUtil.KeyPressed(Keys.F3))
            {
                var tilePos = Utility.GetTilePos(X, Y);
                Owner.AddEntity(new Enemy(tilePos.X, tilePos.Y));
            }
            if (KeyboardUtil.KeyPressed(Keys.F4))
            {
                siegeOfMadoka = !siegeOfMadoka;
            }

            int speed = 3;

            if (KeyboardUtil.IsKeyDown(Keys.LeftShift))
            {
                speed = 24;
            }

            Vector2 move = new Vector2(0, 0);

            if (KeyboardUtil.IsKeyDown(Keys.W))
            {
                move.Y -= 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.S))
            {
                move.Y += 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.A))
            {
                move.X -= 1;
            }
            if (KeyboardUtil.IsKeyDown(Keys.D))
            {
                move.X += 1;
            }
            if (KeyboardUtil.KeyPressed(Keys.Y))
            {
                Buffs.AddBuff(BuffType.Speed, 1000, 2);
            }
            if (Game1.Player.Inventory[1] == Item.Sword2 && (weapon is Gunderwear))
            {
                weapon = new Crossbow();
            }
            if (Game1.Player.Inventory[1] == Item.Sword && !(weapon is Gunderwear))
            {
                weapon = new Gunderwear();
            }
            if (move.X > 0)
            {
                this.facing = 0;
            }
            if (move.X < 0)
            {
                this.facing = 1;
            }

            if (weapon != null)
            {
                weapon.Update(gameTime);
            }

            move *= (speed * speedMult);
            if (move.X != 0 && move.Y != 0)
            {
                move.X /= (float)Math.Sqrt(2);
                move.Y /= (float)Math.Sqrt(2);
            }

            if (move.X != 0 || move.Y != 0)
            {
                if (this.frameCount == 0)
                {
                    this.frameCount = 32;
                }
                else
                {
                    this.frameCount += 3;
                }
            }
            else
            {
                this.frameCount = 0;
            }
            this.frame = (int)Math.Floor(frameCount / 32.0) % 4;

            if (speed == 24)
            {
                Owner.AddEntity(new FakePlayer(this.X, this.Y, this.facing, this.frame));
            }

            string[] collisions = new string[] { "Solid", "NPC" };
            var      cbox       = GetCollisionBox();

            if (move.X != 0 && move.Y != 0)
            {
                float prevX = this.X;
                float prevY = this.Y;
                if (!Owner.RectCollidesWith(new Rectangle(cbox.X + (int)move.X, cbox.Y, cbox.Width, cbox.Height), collisions))
                {
                    this.X += move.X;
                }
                if (!Owner.RectCollidesWith(new Rectangle(cbox.X, cbox.Y + (int)move.Y, cbox.Width, cbox.Height), collisions))
                {
                    this.Y += move.Y;
                }
                if (Owner.RectCollidesWith(GetCollisionBox(), collisions))
                {
                    this.X = prevX;
                    this.Y = prevY;
                }
            }
            else
            {
                float prevX = this.X;
                float prevY = this.Y;
                this.X += move.X;
                this.Y += move.Y;
                if (Owner.RectCollidesWith(GetCollisionBox(), collisions))
                {
                    this.X = prevX;
                    this.Y = prevY;
                }
            }
        }
示例#27
0
        private void SdlRunLoop()
        {
            Sdl.Event ev;

            while (Sdl.PollEvent(out ev) == 1)
            {
                switch (ev.Type)
                {
                case Sdl.EventType.Quit:
                    _isExiting++;
                    break;

                case Sdl.EventType.JoyDeviceAdded:
                    Joystick.AddDevice(ev.JoystickDevice.Which);
                    break;

                case Sdl.EventType.JoyDeviceRemoved:
                    Joystick.RemoveDevice(ev.JoystickDevice.Which);
                    break;

                case Sdl.EventType.ControllerDeviceRemoved:
                    GamePad.RemoveDevice(ev.ControllerDevice.Which);
                    break;

                case Sdl.EventType.ControllerButtonUp:
                case Sdl.EventType.ControllerButtonDown:
                case Sdl.EventType.ControllerAxisMotion:
                    GamePad.UpdatePacketInfo(ev.ControllerDevice.Which, ev.ControllerDevice.TimeStamp);
                    break;

                case Sdl.EventType.MouseWheel:
                    const int wheelDelta = 120;
                    Mouse.ScrollY += ev.Wheel.Y * wheelDelta;
                    Mouse.ScrollX += ev.Wheel.X * wheelDelta;
                    break;

                case Sdl.EventType.MouseMotion:
                    Window.MouseState.X = ev.Motion.X;
                    Window.MouseState.Y = ev.Motion.Y;
                    break;

                case Sdl.EventType.KeyDown:
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
                    if (!_keys.Contains(key))
                    {
                        _keys.Add(key);
                    }
                    char character = (char)ev.Key.Keysym.Sym;
                    _view.OnKeyDown(new InputKeyEventArgs(key));
                    if (char.IsControl(character))
                    {
                        _view.OnTextInput(new TextInputEventArgs(character, key));
                    }
                    break;
                }

                case Sdl.EventType.KeyUp:
                {
                    var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
                    _keys.Remove(key);
                    _view.OnKeyUp(new InputKeyEventArgs(key));
                    break;
                }

                case Sdl.EventType.TextInput:
                    if (_view.IsTextInputHandled)
                    {
                        int  len            = 0;
                        int  utf8character  = 0;  // using an int to encode multibyte characters longer than 2 bytes
                        byte currentByte    = 0;
                        int  charByteSize   = 0;  // UTF8 char lenght to decode
                        int  remainingShift = 0;
                        unsafe
                        {
                            while ((currentByte = Marshal.ReadByte((IntPtr)ev.Text.Text, len)) != 0)
                            {
                                // we're reading the first UTF8 byte, we need to check if it's multibyte
                                if (charByteSize == 0)
                                {
                                    if (currentByte < 192)
                                    {
                                        charByteSize = 1;
                                    }
                                    else if (currentByte < 224)
                                    {
                                        charByteSize = 2;
                                    }
                                    else if (currentByte < 240)
                                    {
                                        charByteSize = 3;
                                    }
                                    else
                                    {
                                        charByteSize = 4;
                                    }

                                    utf8character  = 0;
                                    remainingShift = 4;
                                }

                                // assembling the character
                                utf8character <<= 8;
                                utf8character  |= currentByte;

                                charByteSize--;
                                remainingShift--;

                                if (charByteSize == 0)                    // finished decoding the current character
                                {
                                    utf8character <<= remainingShift * 8; // shifting it to full UTF8 scope

                                    // SDL returns UTF8-encoded characters while C# char type is UTF16-encoded (and limited to the 0-FFFF range / does not support surrogate pairs)
                                    // so we need to convert it to Unicode codepoint and check if it's within the supported range
                                    int codepoint = UTF8ToUnicode(utf8character);

                                    if (codepoint >= 0 && codepoint < 0xFFFF)
                                    {
                                        _view.OnTextInput(new TextInputEventArgs((char)codepoint, KeyboardUtil.ToXna(codepoint)));
                                        // UTF16 characters beyond 0xFFFF are not supported (and would require a surrogate encoding that is not supported by the char type)
                                    }
                                }

                                len++;
                            }
                        }
                    }
                    break;

                case Sdl.EventType.WindowEvent:

                    switch (ev.Window.EventID)
                    {
                    case Sdl.Window.EventId.Resized:
                    case Sdl.Window.EventId.SizeChanged:
                        _view.ClientResize(ev.Window.Data1, ev.Window.Data2);
                        break;

                    case Sdl.Window.EventId.FocusGained:
                        IsActive = true;
                        break;

                    case Sdl.Window.EventId.FocusLost:
                        IsActive = false;
                        break;

                    case Sdl.Window.EventId.Moved:
                        _view.Moved();
                        break;

                    case Sdl.Window.EventId.Close:
                        _isExiting++;
                        break;
                    }
                    break;
                }
            }
        }
示例#28
0
        /// <summary>
        /// "Key Down" midi event handler
        /// </summary>
        /// <param name="msg"></param>
        private void MidiIn_NoteOn(NoteOnMessage msg)
        {
            try
            {
                var maps = NoteControl.Mappings.Where(p => p.Value == msg.Pitch);
                foreach (var map in maps)
                {
                    KeyboardUtil.Send(map.Key);
                }

                var mouseMaps = NoteControl.MouseMappings.Where(p => p.Value == msg.Pitch);
                foreach (var map in mouseMaps)
                {
                    if (map.Key == Models.MouseBindType.LeftClick || map.Key == Models.MouseBindType.MiddleClick || map.Key == Models.MouseBindType.RightClick)
                    {
                        MouseButton btn = MouseButton.Left;
                        if (btn == MouseButton.Left)
                        {
                            if (ConfigUtil.AppConfig.ToggleLeftMouseClick)
                            {
                                KeyboardUtil.MouseClick(btn, !_mouseClickOn);
                                _mouseClickOn = !_mouseClickOn;

                                return;
                            }
                            else if (ConfigUtil.AppConfig.HoldLeftMouseClick)
                            {
                                if (_mouseClickOn)
                                {
                                    return;
                                }
                                _mouseClickOn = true;

                                var delay = ConfigUtil.AppConfig.HoldLeftMouseDelay;
                                DelayReleaseMouse(delay);
                            }
                        }
                        else if (map.Key == Models.MouseBindType.MiddleClick)
                        {
                            btn = MouseButton.Middle;
                        }
                        else if (map.Key == Models.MouseBindType.RightClick)
                        {
                            btn = MouseButton.Right;
                        }

                        KeyboardUtil.MouseClick(btn, false);
                    }
                    else if (map.Key == Models.MouseBindType.WheelUp || map.Key == Models.MouseBindType.WheelDown)
                    {
                        ScrollWheelDirection dn = (map.Key == Models.MouseBindType.WheelUp) ? ScrollWheelDirection.Up : ScrollWheelDirection.Down;

                        KeyboardUtil.ScrollMouseWheel(dn, ConfigUtil.AppConfig.ScrollWheelClicks);
                    }
                    else
                    {
                        MouseMoveDirection md = MouseMoveDirection.Left;

                        if (map.Key == Models.MouseBindType.MoveLeft)
                        {
                            md = MouseMoveDirection.Left;
                        }

                        else if (map.Key == Models.MouseBindType.MoveRight)
                        {
                            md = MouseMoveDirection.Right;
                        }
                        else if (map.Key == Models.MouseBindType.MoveUp)
                        {
                            md = MouseMoveDirection.Up;
                        }
                        else if (map.Key == Models.MouseBindType.MoveDown)
                        {
                            md = MouseMoveDirection.Down;
                        }

                        KeyboardUtil.MouseMove(md, ConfigUtil.AppConfig.MouseSensitivity);
                    }
                }

                _noteViewer.AddNote(msg);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Midi note conversion failed(keydown): ");
            }
        }
示例#29
0
文件: Platform.cs 项目: masums/Shift
        public static void ProcessEvents()
        {
            SDL.SDL_Event ev;

            while (SDL.SDL_PollEvent(out ev) == 1)
            {
                if (ev.type == EventType.SDL_QUIT)
                {
                    _game.Running = false;
                    break;
                }

                /*else if (ev.type == EventType.JoyDeviceAdded)
                 *  Joystick.AddDevice(ev.JoystickDevice.Which);
                 * else if (ev.type == EventType.ControllerDeviceRemoved)
                 *  GamePad.RemoveDevice(ev.ControllerDevice.Which);
                 * else if (ev.type == EventType.JoyDeviceRemoved)
                 *  Joystick.RemoveDevice(ev.JoystickDevice.Which);*/
                else if (ev.type == EventType.SDL_MOUSEWHEEL)
                {
                    Mouse.ScrollY += ev.wheel.y * 120;
                }
                else if (ev.type == EventType.SDL_KEYDOWN)
                {
                    var key = KeyboardUtil.KeyFromSDLCode((int)ev.key.keysym.sym);
                    if (!_keys.Contains(key))
                    {
                        _keys.Add(key);
                    }
                    char character = (char)ev.key.keysym.sym;
                    // TODO: Input events

                    /*if (char.IsControl(character))
                    *   CallTextInput(character, key);*/
                }
                else if (ev.type == EventType.SDL_KEYUP)
                {
                    var key = KeyboardUtil.KeyFromSDLCode((int)ev.key.keysym.sym);
                    _keys.Remove(key);
                }
                else if (ev.type == EventType.SDL_TEXTINPUT)
                {
                    string text;
                    unsafe
                    {
                        text = new string((char *)ev.text.text);
                    }
                    if (text.Length == 0)
                    {
                        continue;
                    }
                    foreach (var c in text)
                    {
                        var key = KeyboardUtil.KeyFromSDLCode((int)c);
                        // TODO: Text input again
                        /*_view.CallTextInput(c, key);*/
                    }
                }
                else if (ev.type == EventType.SDL_WINDOWEVENT)
                {
                    //if (ev.window.windowEvent == Sdl.Window.EventId.Resized || ev.Window.EventID == Sdl.Window.EventId.SizeChanged)
                    //_view.ClientResize(ev.Window.Data1, ev.Window.Data2);
                    if (ev.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED)
                    {
                        IsActive = true;
                    }
                    else if (ev.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST)
                    {
                        IsActive = false;
                    }
                }
            }
        }
        private void PollSDLEvents()
        {
            Span <char> textEditingBuffer = stackalloc char[SDL.Keyboard.TextEditingEvent.TextSize];

            while (SDL.PollEvent(out SDL.Event ev) == 1)
            {
                switch (ev.Type)
                {
                case SDL.EventType.Quit:
                    Interlocked.Increment(ref _isExiting);
                    break;

                    #region Joystick

                case SDL.EventType.JoyDeviceAdded:
                    Joystick.AddDevice(ev.JoystickDevice.Which);
                    break;

                case SDL.EventType.JoyDeviceRemoved:
                    Joystick.RemoveDevice(ev.JoystickDevice.Which);
                    break;

                    #endregion

                    #region GameController

                case SDL.EventType.ControllerDeviceRemoved:
                    GamePad.RemoveDevice(ev.ControllerDevice.Which);
                    break;

                case SDL.EventType.ControllerButtonUp:
                case SDL.EventType.ControllerButtonDown:
                case SDL.EventType.ControllerAxisMotion:
                    GamePad.UpdatePacketInfo(ev.ControllerDevice.Which, ev.ControllerDevice.TimeStamp);
                    break;

                    #endregion

                    #region Mouse

                case SDL.EventType.MouseWheel:
                    _window.Mouse.ScrollX += ev.MouseWheel.X * MouseWheelDelta;
                    _window.Mouse.ScrollY += ev.MouseWheel.Y * MouseWheelDelta;
                    break;

                case SDL.EventType.MouseMotion:
                    _window.Mouse.State.X = ev.MouseMotion.X;
                    _window.Mouse.State.Y = ev.MouseMotion.Y;
                    break;

                    #endregion

                    #region Keyboard

                case SDL.EventType.KeyDown:
                {
                    bool hasMapping = KeyboardUtil.ToXna(ev.KeyboardKey.Keysym.Sym, out var key);
                    if (hasMapping)
                    {
                        if (!Keyboard._keysDown.Contains(key))
                        {
                            Keyboard._keysDown.Add(key);
                        }
                    }

                    // TODO: validate rune?
                    Rune.TryCreate(ev.KeyboardKey.Keysym.Sym, out var rune);

                    var inputEv = new TextInputEventArgs(rune, hasMapping ? key : (Keys?)null);
                    _window.OnKeyDown(inputEv);
                    break;
                }

                case SDL.EventType.KeyUp:
                {
                    bool hasMapping = KeyboardUtil.ToXna(ev.KeyboardKey.Keysym.Sym, out var key);
                    if (hasMapping)
                    {
                        Keyboard._keysDown.Remove(key);
                    }

                    // TODO: validate rune?
                    Rune.TryCreate(ev.KeyboardKey.Keysym.Sym, out var rune);

                    _window.OnKeyUp(new TextInputEventArgs(rune, hasMapping ? key : (Keys?)null));
                    break;
                }

                    #endregion

                    #region Text-Input/Editing

                case SDL.EventType.TextInput:
                    unsafe
                    {
                        var utf8 = new Span <byte>(ev.TextInput.Text, SDL.Keyboard.TextInputEvent.TextSize);
                        utf8 = SliceToNullTerminator(utf8);
                        while (!utf8.IsEmpty)
                        {
                            var status = Rune.DecodeFromUtf8(utf8, out Rune rune, out int bytesConsumed);
                            if (status != OperationStatus.Done)
                            {
                                // This should never occur if SDL gives use valid data.
                                throw new InvalidDataException("Failed to decode UTF-8 text input: " + status);
                            }
                            utf8 = utf8[bytesConsumed..];