// // SET CONTROL CUSTOM DATA // internal void SetControlKbdCustomData(Key key, Interface.KeyboardModifier keybMod) { if (isCustomisingControl) { Interface.CurrentControls[CustomControlIdx].Method = Interface.ControlMethod.Keyboard; Interface.CurrentControls[CustomControlIdx].Key = key; Interface.CurrentControls[CustomControlIdx].Modifier = keybMod; Interface.SaveControls(null); PopMenu(); isCustomisingControl = false; } }
// // SET CONTROL CUSTOM DATA // internal void SetControlKbdCustomData(Key key, Interface.KeyboardModifier keybMod) { //Check that we are customising a key, and that our key is NOT the menu back key if (isCustomisingControl && key != MenuBackKey && CustomControlIdx < Interface.CurrentControls.Length) { Interface.CurrentControls[CustomControlIdx].Method = Interface.ControlMethod.Keyboard; Interface.CurrentControls[CustomControlIdx].Key = key; Interface.CurrentControls[CustomControlIdx].Modifier = keybMod; Interface.SaveControls(null, Interface.CurrentControls); } PopMenu(); isCustomisingControl = false; }
private static void ProcessEvents() { Sdl.SDL_Event Event; while (Sdl.SDL_PollEvent(out Event) != 0) { switch (Event.type) { // quit case Sdl.SDL_QUIT: Quit = true; return; // resize case Sdl.SDL_VIDEORESIZE: Screen.Width = Event.resize.w; Screen.Height = Event.resize.h; UpdateViewport(MainLoop.ViewPortChangeMode.NoChange); InitializeMotionBlur(); break; // key down case Sdl.SDL_KEYDOWN: if (Event.key.keysym.sym == Sdl.SDLK_LSHIFT | Event.key.keysym.sym == Sdl.SDLK_RSHIFT) CurrentKeyboardModifier |= Interface.KeyboardModifier.Shift; if (Event.key.keysym.sym == Sdl.SDLK_LCTRL | Event.key.keysym.sym == Sdl.SDLK_RCTRL) CurrentKeyboardModifier |= Interface.KeyboardModifier.Ctrl; if (Event.key.keysym.sym == Sdl.SDLK_LALT | Event.key.keysym.sym == Sdl.SDLK_RALT) CurrentKeyboardModifier |= Interface.KeyboardModifier.Alt; for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard) { if (Interface.CurrentControls[i].Element == Event.key.keysym.sym & Interface.CurrentControls[i].Modifier == CurrentKeyboardModifier) { Interface.CurrentControls[i].AnalogState = 1.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed; AddControlRepeat(i); } } } break; // key up case Sdl.SDL_KEYUP: if (Event.key.keysym.sym == Sdl.SDLK_LSHIFT | Event.key.keysym.sym == Sdl.SDLK_RSHIFT) CurrentKeyboardModifier &= ~Interface.KeyboardModifier.Shift; if (Event.key.keysym.sym == Sdl.SDLK_LCTRL | Event.key.keysym.sym == Sdl.SDLK_RCTRL) CurrentKeyboardModifier &= ~Interface.KeyboardModifier.Ctrl; if (Event.key.keysym.sym == Sdl.SDLK_LALT | Event.key.keysym.sym == Sdl.SDLK_RALT) CurrentKeyboardModifier &= ~Interface.KeyboardModifier.Alt; for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Keyboard) { if (Interface.CurrentControls[i].Element == Event.key.keysym.sym) { Interface.CurrentControls[i].AnalogState = 0.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released; RemoveControlRepeat(i); } } } break; // joystick button down case Sdl.SDL_JOYBUTTONDOWN: if (Interface.CurrentOptions.UseJoysticks) { for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Joystick) { if (Interface.CurrentControls[i].Component == Interface.JoystickComponent.Button) { if (Interface.CurrentControls[i].Device == (int)Event.jbutton.which & Interface.CurrentControls[i].Element == (int)Event.jbutton.button) { Interface.CurrentControls[i].AnalogState = 1.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed; AddControlRepeat(i); } } } } } break; // joystick button up case Sdl.SDL_JOYBUTTONUP: if (Interface.CurrentOptions.UseJoysticks) { for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Joystick) { if (Interface.CurrentControls[i].Component == Interface.JoystickComponent.Button) { if (Interface.CurrentControls[i].Device == (int)Event.jbutton.which & Interface.CurrentControls[i].Element == (int)Event.jbutton.button) { Interface.CurrentControls[i].AnalogState = 0.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released; RemoveControlRepeat(i); } } } } } break; // joystick hat case Sdl.SDL_JOYHATMOTION: if (Interface.CurrentOptions.UseJoysticks) { for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Joystick) { if (Interface.CurrentControls[i].Component == Interface.JoystickComponent.Hat) { if (Interface.CurrentControls[i].Device == (int)Event.jhat.which) { if (Interface.CurrentControls[i].Element == (int)Event.jhat.hat) { if (Interface.CurrentControls[i].Direction == (int)Event.jhat.val) { Interface.CurrentControls[i].AnalogState = 1.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed; } else { Interface.CurrentControls[i].AnalogState = 0.0; Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released; } } } } } } } break; // joystick axis case Sdl.SDL_JOYAXISMOTION: if (Interface.CurrentOptions.UseJoysticks) { for (int i = 0; i < Interface.CurrentControls.Length; i++) { if (Interface.CurrentControls[i].Method == Interface.ControlMethod.Joystick) { if (Interface.CurrentControls[i].Component == Interface.JoystickComponent.Axis) { if (Interface.CurrentControls[i].Device == (int)Event.jaxis.which & Interface.CurrentControls[i].Element == (int)Event.jaxis.axis) { double a = (double)Event.jaxis.val / 32768.0; if (Interface.CurrentControls[i].InheritedType == Interface.CommandType.AnalogHalf) { if (Math.Sign(a) == Math.Sign(Interface.CurrentControls[i].Direction)) { a = Math.Abs(a); if (a < Interface.CurrentOptions.JoystickAxisThreshold) { Interface.CurrentControls[i].AnalogState = 0.0; } else if (Interface.CurrentOptions.JoystickAxisThreshold != 1.0) { Interface.CurrentControls[i].AnalogState = (a - Interface.CurrentOptions.JoystickAxisThreshold) / (1.0 - Interface.CurrentOptions.JoystickAxisThreshold); } else { Interface.CurrentControls[i].AnalogState = 1.0; } } } else if (Interface.CurrentControls[i].InheritedType == Interface.CommandType.AnalogFull) { a *= (double)Interface.CurrentControls[i].Direction; if (a > -Interface.CurrentOptions.JoystickAxisThreshold & a < Interface.CurrentOptions.JoystickAxisThreshold) { Interface.CurrentControls[i].AnalogState = 0.0; } else if (Interface.CurrentOptions.JoystickAxisThreshold != 1.0) { if (a < 0.0) { Interface.CurrentControls[i].AnalogState = (a + Interface.CurrentOptions.JoystickAxisThreshold) / (1.0 - Interface.CurrentOptions.JoystickAxisThreshold); } else if (a > 0.0) { Interface.CurrentControls[i].AnalogState = (a - Interface.CurrentOptions.JoystickAxisThreshold) / (1.0 - Interface.CurrentOptions.JoystickAxisThreshold); } else { Interface.CurrentControls[i].AnalogState = 0.0; } } else { Interface.CurrentControls[i].AnalogState = (double)Math.Sign(a); } } else { if (Math.Sign(a) == Math.Sign(Interface.CurrentControls[i].Direction)) { a = Math.Abs(a); if (a < Interface.CurrentOptions.JoystickAxisThreshold) { a = 0.0; } else if (Interface.CurrentOptions.JoystickAxisThreshold != 1.0) { a = (a - Interface.CurrentOptions.JoystickAxisThreshold) / (1.0 - Interface.CurrentOptions.JoystickAxisThreshold); } else { a = 1.0; } if (Interface.CurrentControls[i].DigitalState == Interface.DigitalControlState.Released | Interface.CurrentControls[i].DigitalState == Interface.DigitalControlState.ReleasedAcknowledged) { if (a > 0.67) Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Pressed; } else { if (a < 0.33) Interface.CurrentControls[i].DigitalState = Interface.DigitalControlState.Released; } } } } } } } } break; case Sdl.SDL_MOUSEBUTTONDOWN: // mouse button down if (Event.button.button == Sdl.SDL_BUTTON_RIGHT) { // mouse grab World.MouseGrabEnabled = !World.MouseGrabEnabled; if (World.MouseGrabEnabled) { World.MouseGrabTarget = new World.Vector2D(0.0, 0.0); Sdl.SDL_WM_GrabInput(Sdl.SDL_GRAB_ON); Game.AddMessage(Interface.GetInterfaceString("notification_mousegrab_on"), Game.MessageDependency.None, Interface.GameMode.Expert, Game.MessageColor.Blue, Game.SecondsSinceMidnight + 5.0); } else { Sdl.SDL_WM_GrabInput(Sdl.SDL_GRAB_OFF); Game.AddMessage(Interface.GetInterfaceString("notification_mousegrab_off"), Game.MessageDependency.None, Interface.GameMode.Expert, Game.MessageColor.Blue, Game.SecondsSinceMidnight + 5.0); } } break; case Sdl.SDL_MOUSEMOTION: // mouse motion if (World.MouseGrabIgnoreOnce) { World.MouseGrabIgnoreOnce = false; } else if (World.MouseGrabEnabled) { World.MouseGrabTarget = new World.Vector2D((double)Event.motion.xrel, (double)Event.motion.yrel); } break; } } }