bool PlayerComponent::onMessageReceived(gameobjects::Message * message, int messageType)
    {
        switch (messageType)
        {
        case Messages::Type::PostSimulationUpdate:
            onPostSimulationUpdate(PostSimulationUpdateMessage(message)._elapsedTime);
            break;
        case Messages::Type::SimulationUpdate:
            onSimulationUpdate(SimulationUpdateMessage(message)._elapsedTime);
            break;
        default:
            break;
        }

        return true;
    }
Пример #2
0
MainWindow::MainWindow(MainController& ctrl, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, mController(ctrl)
, mCurrentBodyWidget(0)
, mIsTerminated(false)
{
    irr::IrrlichtDevice* device = 0;
    ui->setupUi(this);

    /* Configure Irrlicht */
    mIrrlichtWidget = new IrrlichtWidget(mController.getConfiguration().getGraphicsConfiguration(),
                                         ui->irrlichtContainer);
    ui->irrlichtLayout->addWidget(mIrrlichtWidget);

    device = mIrrlichtWidget->getIrrlichtDevice();
    Engine::PlanetariumEngine* engine = mController.createEngine(device);
    mIrrlichtWidget->setEngine(engine);
    onNewCamera();
    /* Add label to the status bar */
    mStatusLabel = new QLabel(ui->statusBar);
    ui->statusBar->addWidget(mStatusLabel);

    /* Set status bar message */
    mStatusLabel->setText(tr("Uninitialized"));

    /* Set initial values */
    ui->speedSpin->setValue(ctrl.getSpeed());
    ui->stepSpin->setValue(ctrl.getStep());
    ui->scaleSpinBox->setValue(ctrl.getEngine()->getScale());

    /* Connect GUI to controller */
    // menu actions
    connect(ui->quitAction, SIGNAL(triggered()),
            this, SLOT(close()));
    connect(ui->actionPreferences, SIGNAL(triggered()),
            this, SLOT(onPreferences()));
    connect(ui->openAction, SIGNAL(triggered()),
        this, SLOT(onOpen()));
    connect(ui->actionStart, SIGNAL(triggered()),
            this, SLOT(onPlayTriggered()));
    connect(ui->actionStop, SIGNAL(triggered()),
            this, SLOT(onStopTriggered()));


    // spin buttons
    connect(ui->speedSpin, SIGNAL(valueChanged(double)),
            &ctrl, SLOT(setSpeed(double)));
    connect(ui->stepSpin, SIGNAL(valueChanged(double)),
            &ctrl, SLOT(setStep(double)));
    connect(ui->scaleSpinBox, SIGNAL(valueChanged(double)),
            ctrl.getEngine(), SLOT(setScale(double)));
    connect(ui->xCamPos, SIGNAL(valueChanged(double)),
            this, SLOT(onCameraPositionChanged(double)));
    connect(ui->yCamPos, SIGNAL(valueChanged(double)),
            this, SLOT(onCameraPositionChanged(double)));
    connect(ui->zCamPos, SIGNAL(valueChanged(double)),
            this, SLOT(onCameraPositionChanged(double)));

    // control buttons
    connect(ui->playButton, SIGNAL(clicked()),
            this, SLOT(onPlayTriggered()));
    connect(ui->stopButton, SIGNAL(clicked()),
            this, SLOT(onStopTriggered()));

    // List
    connect(ui->objectList, SIGNAL(currentRowChanged(int)),
            this, SLOT(onListSelectionChanged(int)));

    /* Connect controller event */
    connect(&ctrl, SIGNAL(simulationStateChanged()),
            this, SLOT(simulationStateChanged()));
    connect(&ctrl, SIGNAL(model_updated()),
            this, SLOT(onSimulationUpdate()));

    connect(engine, SIGNAL(newCamera()),
            this, SLOT(onNewCamera()));
}