Exemple #1
0
void Render::keyboardDownEvent(KeyboardDownEvent *e)
{
  BindingManager *b = BindingManager::instance();
  int keysym = e->event().keysym.sym;
  if (b->findKey("ToggleFPS").check(keysym))
  {
    e->stop();
    _fpsLabel->setVisible(!_fpsLabel->visible());
  }
  else if (b->findKey("Quit").check(keysym))
  {
    e->stop();
    Application::instance()->quit(0);
  }
  else if (b->findKey("Console").check(keysym))
  {
    e->stop();
    if (!_console->visible())
    {
      _consoleSaveEvents.clear();
      WidgetChildren *c = children();
      for (WidgetChildrenIterator it = c->begin();
           it != c->end(); ++it)
      {
        _consoleSaveEvents.push_back((*it)->eventMask());
        if (*it != _console)
          (*it)->disableInput();
      }

      _console->show();
    }
    else
    {
      WidgetChildren *c = children();
      int i = 0;
      for (WidgetChildrenIterator it = c->begin();
           it != c->end(); ++it, ++i)
        (*it)->setEventMask(_consoleSaveEvents[i]);

      _console->hide();
    }
  }
}
Exemple #2
0
void Simulation::keyboardDownEvent(KeyboardDownEvent* e)
{
  if (_initializing)
    return;

  BindingManager *b = BindingManager::instance();
  int keysym = e->event().keysym.sym;
  if (b->findKey("RollNegative").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.z = -_player->maximumAngularControl().z;

    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("RollPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.z = _player->maximumAngularControl().z;

    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("PitchNegative").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.x = -_player->maximumAngularControl().x;

    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("PitchPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.x = _player->maximumAngularControl().x;

    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("YawNegative").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.y = -_player->maximumAngularControl().y;
    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("YawPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.y = _player->maximumAngularControl().y;

    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("Accelerate").check(keysym))
  {
    _player->setControl( _player->maximumAccelerationControl(),
                         _player->angularControl());
  }
  else if (b->findKey("Decelerate").check(keysym))
  {
    _player->setControl(-_player->maximumAccelerationControl(),
                         _player->angularControl());
  }
  else if (b->findKey("ViewYNegative").check(keysym))
  {
    _outsideViewAnglesAcc.y = -30.0f;
  }
  else if (b->findKey("ViewYPositive").check(keysym))
  {
    _outsideViewAnglesAcc.y = 30.0f;
  }
  else if (b->findKey("ViewXNegative").check(keysym))
  {
    _outsideViewAnglesAcc.x = -30.0f;
  }
  else if (b->findKey("ViewXPositive").check(keysym))
  {
    _outsideViewAnglesAcc.x = 30.0f;
  }
  else if (b->findKey("Fog").check(keysym))
  {
    _fog = !_fog;
    if (_fog)
      displayMessage(_("Fog: on"));
    else
      displayMessage(_("Fog: off"));
  }
  else if (b->findKey("Hud").check(keysym))
  {
    if (_hudMode == Hud_Full)
    {
      displayMessage(_("HUD: minimal"));
      _hudMode = Hud_Minimal;
    }
    else if (_hudMode == Hud_Minimal)
    {
      displayMessage(_("HUD: off"));
      _hudMode = Hud_None;
    }
    else if (_hudMode == Hud_None)
    {
      displayMessage(_("HUD: full"));
      _hudMode = Hud_Full;
    }
  }
  else if (b->findKey("View").check(keysym))
  {
    if (_viewMode == View_Cockpit)
    {
      displayMessage(_("View: outside"));
      _viewMode = View_Outside;
    }
    else if (_viewMode == View_Outside)
    {
      displayMessage(_("View: cockpit"));
      _viewMode = View_Cockpit;
    }
  }
  else if (b->findKey("GameMenu").check(keysym))
  {
    _menu->show();

    _updateTimer.setEnabled(false);

    e->stop();
  }

  if (_simulationType == Simulation_Game)
  {
    if (b->findKey("Fire").check(keysym))
    {
      _player->setFiring(true);
    }
  }
}
Exemple #3
0
void Simulation::keyboardUpEvent(KeyboardUpEvent* e)
{
  if (_initializing || _menu->visible())
    return;

  BindingManager *b = BindingManager::instance();
  int keysym = e->event().keysym.sym;
  if (b->findKey("RollNegative").check(keysym) ||
      b->findKey("RollPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.z = 0.0f;
    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("PitchNegative").check(keysym) ||
           b->findKey("PitchPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.x = 0.0f;
    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("YawNegative").check(keysym) ||
           b->findKey("YawPositive").check(keysym))
  {
    Vector3D angularControl = _player->angularControl();
    angularControl.y = 0.0f;
    _player->setControl(_player->accelerationControl(),
                        angularControl);
  }
  else if (b->findKey("Accelerate").check(keysym) ||
           b->findKey("Decelerate").check(keysym))
  {
    _player->setControl(0.0f, _player->angularControl());
  }
  else if (b->findKey("ViewZoomIn").check(keysym))
  {
    _outsideViewZoom -= 1.0f;
  }
  else if (b->findKey("ViewZoomOut").check(keysym))
  {
    _outsideViewZoom += 1.0f;
  }
  else if (b->findKey("ViewYNegative").check(keysym) ||
           b->findKey("ViewYPositive").check(keysym))
  {
    _outsideViewAnglesAcc.y = 0.0f;
  }
  else if (b->findKey("ViewXNegative").check(keysym) ||
           b->findKey("ViewXPositive").check(keysym))
  {
    _outsideViewAnglesAcc.x = 0.0f;
  }

  if (_simulationType == Simulation_Game)
  {
    if (b->findKey("Fire").check(keysym))
    {
      _player->setFiring(false);
    }
  }
}