Scene::EntityWeakPtr Water::GetActiveWater() { Scene::ScenePtr scene = owner_->GetFramework()->GetDefaultWorldScene(); // Check that is current water entity still valid. if ( !activeWaterEntity_.expired() ) if(scene->GetEntity(activeWaterEntity_.lock()->GetId()).get() != 0) return activeWaterEntity_; // Current is not valid so search new, takes first entity which has water for(Scene::SceneManager::iterator iter = scene->begin(); iter != scene->end(); ++iter) { Scene::Entity &entity = **iter; activeWaterComponent_ = entity.GetComponent<EC_Water>().get(); if (activeWaterComponent_ != 0) { activeWaterEntity_ = scene->GetEntity(entity.GetId()); if ( !activeWaterEntity_.expired()) return activeWaterEntity_; } } // There was any water entity so reset it to null state. activeWaterEntity_.reset(); activeWaterComponent_ = 0; return Scene::EntityWeakPtr(); }
void UICanvasTestEdit::RefreshSubmeshes() { if (!editor_widget_) return; uint numsubmeshes = 0; Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); if (scene.get()) { Scene::EntityPtr entity = scene->GetEntity(last_entity_id_); if (entity.get()) { OgreRenderer::EC_OgreMesh* mesh = entity->GetComponent<OgreRenderer::EC_OgreMesh>().get(); OgreRenderer::EC_OgreCustomObject* custom = entity->GetComponent<OgreRenderer::EC_OgreCustomObject>().get(); if (mesh) numsubmeshes = mesh->GetNumMaterials(); if (custom) numsubmeshes = custom->GetNumMaterials(); } } QComboBox* combo = editor_widget_->findChild<QComboBox*>("combo_subobject"); if (!combo) return; combo->clear(); for (uint i = 0; i < numsubmeshes; ++i) combo->addItem(QString::fromStdString(ToString<uint>(i))); }
void UICanvasTestEdit::UnbindCanvas() { Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); if (scene.get()) { Scene::EntityPtr entity = scene->GetEntity(last_entity_id_); if (entity.get()) { EC_UICanvas* ec = entity->GetComponent<EC_UICanvas>().get(); if (ec) { // Get proxy widget from 3D canvas boost::shared_ptr<QtUI::UICanvas> canvas = ec->GetCanvas(); QGraphicsProxyWidget *proxy_widget = canvas->Remove3DProxyWidget(); proxy_widget->widget()->setWindowFlags(Qt::Dialog); ec->ClearSubmeshes(); // Remove proxy widget from local QList so it we wont try to delete in decostructor proxy_widget_canvases_.removeOne(canvas); // Get QtModule and delete the 3D canvas Foundation::ModuleSharedPtr qt_module = framework_->GetModuleManager()->GetModule("QtModule").lock(); QtUI::QtModule *qt_ui = dynamic_cast<QtUI::QtModule*>(qt_module.get()); if (qt_ui) qt_ui->DeleteCanvas(canvas->GetID()); // Add proxy widget back to 2D scene boost::shared_ptr<UiServices::UiModule> ui_module = framework_->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock(); ui_module->GetSceneManager()->AddProxyWidget((UiServices::UiProxyWidget *)proxy_widget); } } } }
void NoteCardManager::Update(f64 frametime) { if (!entity_create_pending_) return; // See if we have a potential entity to check if (new_entity_id_) { NoteCardModule::LogInfo("Checking new entity"); Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); Scene::EntityPtr entity; if (scene) entity = scene->GetEntity(new_entity_id_); if (entity) { boost::shared_ptr<RexLogic::EC_NetworkPosition> netpos = entity->GetComponent<RexLogic::EC_NetworkPosition>(); if (netpos) { // See if error in position is small enough to be a match // Note: for some reason we can't trust the sim to give the Z position even remotely the same if ((fabs(netpos->position_.x - new_entity_pos_.x) < 0.001f) && (fabs(netpos->position_.y - new_entity_pos_.y) < 0.001f) && (fabs(netpos->position_.z - new_entity_pos_.z) < 1.0f)) { // Yes, it has to be that entity! entity_create_pending_ = false; // Create a new notecard EC to the entity and set its initial title, will cause sync to network entity->AddComponent(framework_->GetComponentManager()->CreateComponent(EC_NoteCard::TypeNameStatic())); boost::shared_ptr<EC_NoteCard> notecard = entity->GetComponent<EC_NoteCard>(); if (notecard) notecard->SetTitle(QApplication::translate("NoteCardManager", "New notecard").toStdString()); else NoteCardModule::LogError("Could not create notecard component to entity"); } else { NoteCardModule::LogInfo("Distance was too great"); std::cout << netpos->position_.x << " " << netpos->position_.y << " " << netpos->position_.z << std::endl; std::cout << "VS: " << new_entity_pos_.x << " " << new_entity_pos_.y << " " << new_entity_pos_.z << std::endl; } } else NoteCardModule::LogInfo("No networkposition EC"); } new_entity_id_ = 0; } // If didn't succeed yet, increment time and see if it's time to give up if (entity_create_pending_) { entity_wait_time_ += frametime; if (entity_wait_time_ >= entity_max_wait_time_) { entity_create_pending_ = false; NoteCardModule::LogWarning("Wait time expired, notecard entity was not created"); } } }
void UICanvasTestEdit::BindCanvas() { // Get ui elements QComboBox* combo_s = editor_widget_->findChild<QComboBox*>("combo_subobject"); if (!combo_s) return; QComboBox* combo_c = editor_widget_->findChild<QComboBox*>("combo_canvas"); if (!combo_c) return; // Get QtModule Foundation::ModuleSharedPtr qt_module = framework_->GetModuleManager()->GetModule("QtModule").lock(); QtUI::QtModule *qt_ui = dynamic_cast<QtUI::QtModule*>(qt_module.get()); // Get UiModule boost::shared_ptr<UiServices::UiModule> ui_module = framework_->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock(); // Get Scene Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); if (scene.get()) { Scene::EntityPtr entity = scene->GetEntity(last_entity_id_); if (entity.get()) { uint submesh = combo_s->currentIndex(); QString proxy_widget_name = combo_c->currentText(); boost::shared_ptr<QtUI::UICanvas> canvas; // Get proxy widget for selected name UiServices::UiProxyWidget *proxy_widget = ui_module->GetSceneManager()->GetProxyWidget(proxy_widget_name); if (proxy_widget) { ui_module->GetSceneManager()->RemoveProxyWidgetFromScene(proxy_widget); proxy_widget->widget()->setWindowFlags(Qt::Widget); canvas = qt_ui->CreateCanvas(QtUI::UICanvas::Internal).lock(); canvas->SetSize(proxy_widget->size().width(), proxy_widget->size().height()); canvas->SetPosition(100,100); canvas->AddProxyWidget(proxy_widget); canvas->Show(); proxy_widget->show(); proxy_widget_canvases_.append(canvas); EC_UICanvas* ec = dynamic_cast<EC_UICanvas*>(qt_ui->CreateEC_UICanvasToEntity(entity.get(), canvas).get()); if (ec) ec->SetSubmeshes(submesh); } } } }
void NoteCardManager::SelectNoteCard() { Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); if (!scene) return; NoteCardTreeWidgetItem* item = dynamic_cast<NoteCardTreeWidgetItem*>(tree_->currentItem()); if (item) { entity_id_t id = item->GetId(); Scene::EntityPtr entity = scene->GetEntity(id); if (!entity) return; boost::shared_ptr<EC_NoteCard> card = entity->GetComponent<EC_NoteCard>(); if (card) { // Show the notecard if it was hidden card->Show(); } } }
void NoteCardManager::OnEntityModified(entity_id_t id) { if (!tree_) return; Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); if (!scene) return; Scene::EntityPtr entity = scene->GetEntity(id); if (!entity) return; boost::shared_ptr<EC_NoteCard> card = entity->GetComponent<EC_NoteCard>(); // If entity no longer has the notecard component, trigger remove from list instead //! \todo this is triggered any time any entity with any serializable EC is modified. A bit unnecessary if (!card) { OnEntityRemoved(id); return; } // See if we already have this entity on our list for (uint i = 0; i < tree_->topLevelItemCount(); ++i) { NoteCardTreeWidgetItem* item = dynamic_cast<NoteCardTreeWidgetItem*>(tree_->topLevelItem(i)); if (item) { // Update title from the EC if (item->GetId() == id) { item->setText(0, QString::fromStdString(card->GetTitle())); return; } } } // If not, create new NoteCardTreeWidgetItem* item = new NoteCardTreeWidgetItem(id); item->setText(0, QString::fromStdString(card->GetTitle())); tree_->addTopLevelItem(item); }