bool OgreAssetEditorModule::HandleEvent(event_category_id_t category_id, event_id_t event_id, Foundation::EventDataInterface* data) { if (category_id == frameworkEventCategory_) { if (event_id == Foundation::NETWORKING_REGISTERED) { networkStateEventCategory_ = eventManager_->QueryEventCategory("NetworkState"); if (networkStateEventCategory_ == 0) LogError("Failed to query \"NetworkState\" event category"); return false; } } if (category_id == inventoryEventCategory_) { if (event_id == Inventory::Events::EVENT_INVENTORY_ITEM_OPEN) { // Inventory item requested for opening. Check if we have editor for its type. if (uiModule_.expired()) return false; Inventory::InventoryItemOpenEventData *open_item = dynamic_cast<Inventory::InventoryItemOpenEventData *>(data); if(!open_item) return false; /*switch(open_item->assetType) { case RexTypes::RexAT_Texture: { open_item->overrideDefaultHandler = true; break; } }*/ } if (event_id == Inventory::Events::EVENT_INVENTORY_ITEM_DOWNLOADED) { if (uiModule_.expired()) return false; // Asset downloaded, pass asset data to the right editor and bring it to front. // This event is sent also when asset is already in cache and doens't need to be // downloaded. Hence, if there is no editor created yet, create it now. Inventory::InventoryItemDownloadedEventData *downloaded = checked_static_cast<Inventory::InventoryItemDownloadedEventData *>(data); assert(downloaded); asset_type_t at = downloaded->assetType; switch(at) { case RexTypes::RexAT_ParticleScript: case RexTypes::RexAT_MaterialScript: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if (!editorManager_->Exists(id, at)) { // Editor not created, create it now. OgreScriptEditor *editor = new OgreScriptEditor(framework_, id, at, name); connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); editor->HandleAssetReady(downloaded->asset); // Add widget to scene, show and bring to front uiModule_.lock()->GetInworldSceneController()->AddWidgetToScene( editor, UiServices::UiWidgetProperties("Ogre Script Editor", UiServices::SceneWidget)); uiModule_.lock()->GetInworldSceneController()->ShowProxyForWidget(editor); uiModule_.lock()->GetInworldSceneController()->BringProxyToFront(editor); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) uiModule_.lock()->GetInworldSceneController()->BringProxyToFront(editor); } // Surpress this event. downloaded->handled = true; return true; } case RexTypes::RexAT_SoundVorbis: case RexTypes::RexAT_SoundWav: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { AudioPreviewEditor *editor = new AudioPreviewEditor(framework_, id, at, name); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); editor->HandleAssetReady(downloaded->asset); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) { uiModule_.lock()->GetInworldSceneController()->BringProxyToFront(editor); AudioPreviewEditor *audioWidget = qobject_cast<AudioPreviewEditor*>(editor); if(audioWidget) audioWidget->HandleAssetReady(downloaded->asset); } } downloaded->handled = true; return true; } case RexTypes::RexAT_Mesh: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { MeshPreviewEditor *editor = new MeshPreviewEditor(framework_, id, at, name); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); editor->HandleAssetReady(downloaded->asset); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) { uiModule_.lock()->GetInworldSceneController()->BringProxyToFront(editor); AudioPreviewEditor *audioWidget = qobject_cast<AudioPreviewEditor*>(editor); if(audioWidget) audioWidget->HandleAssetReady(downloaded->asset); } } downloaded->handled = true; return true; } case RexTypes::RexAT_Texture: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { TexturePreviewEditor *editor = new TexturePreviewEditor(framework_, id, at, name, downloaded->asset->GetId().c_str()); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); //editor->RequestTextureAsset(downloaded->asset->GetId()); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) uiModule_.lock()->GetInworldSceneController()->BringProxyToFront(editor); } downloaded->handled = true; return true; } default: return false; } } } else if (category_id == networkStateEventCategory_) { if (event_id == ProtocolUtilities::Events::EVENT_SERVER_DISCONNECTED) editorManager_->DeleteAll(); } else if (category_id == resourceEventCategory_) { Resource::Events::ResourceReady *res = dynamic_cast<Resource::Events::ResourceReady*>(data); assert(res); if (!res) return false; if(res->resource_->GetType() == "Texture") { QVector<QWidget*> editorList = editorManager_->GetEditorListByAssetType(RexTypes::RexAT_Texture); for(uint i = 0; i < editorList.size(); i++) { TexturePreviewEditor *editorWidget = qobject_cast<TexturePreviewEditor*>(editorList[i]); if(editorWidget) editorWidget->HandleResouceReady(res); } } else if(res->resource_->GetType() == "Sound") { QVector<QWidget*> editorList = editorManager_->GetEditorListByAssetType(RexTypes::RexAT_SoundVorbis); for(uint i = 0; i < editorList.size(); i++) { AudioPreviewEditor *editorWidget = qobject_cast<AudioPreviewEditor*>(editorList[i]); if(editorWidget) editorWidget->HandleResouceReady(res); } } } return false; }
bool OgreAssetEditorModule::HandleEvent(event_category_id_t category_id, event_id_t event_id, Foundation::EventDataInterface* data) { if (category_id == frameworkEventCategory_) { if (event_id == Foundation::NETWORKING_REGISTERED) { networkStateEventCategory_ = eventManager_->QueryEventCategory("NetworkState"); return false; } } if ( category_id == assetEventCategory_ ) { if (event_id == Asset::Events::ASSET_OPEN) { // Search first editor Asset::Events::AssetOpen* open = static_cast<Asset::Events::AssetOpen* >(data); int asset_type = open->asset_type_.toUInt(); switch ( asset_type ) { case RexTypes::RexAT_Mesh: { QString id = open->asset_id_; QString name = open->asset_type_; if(!editorManager_->Exists(id, name.toUInt())) { MeshPreviewEditor *editor = new MeshPreviewEditor(framework_); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, name.toUInt(), editor); editor->Open(id, name); return true; } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, name.toUInt()); if (editor != 0) { uiService_.lock()->BringWidgetToFront(editor); MeshPreviewEditor *editorWidget = qobject_cast<MeshPreviewEditor*>(editor); if ( editorWidget != 0) editorWidget->Open(id, name); return true; } } break; } case RexTypes::RexAT_Texture: { QString id = open->asset_id_; QString type = open->asset_type_; if(!editorManager_->Exists(id, type.toUInt())) { TexturePreviewEditor *editor = new TexturePreviewEditor(framework_); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, type.toUInt(), editor); editor->RequestTextureAsset(id); return true; } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, type.toUInt()); if (editor != 0) { uiService_.lock()->BringWidgetToFront(editor); return true; } } break; } default: break; } } } if (category_id == inventoryEventCategory_) { if (event_id == Inventory::Events::EVENT_INVENTORY_ITEM_OPEN) { // Inventory item requested for opening. Check if we have editor for its type. if (uiService_.expired()) return false; Inventory::InventoryItemOpenEventData *open_item = dynamic_cast<Inventory::InventoryItemOpenEventData *>(data); if(!open_item) return false; } if (event_id == Inventory::Events::EVENT_INVENTORY_ITEM_DOWNLOADED) { if (uiService_.expired()) return false; // Asset downloaded, pass asset data to the right editor and bring it to front. // This event is sent also when asset is already in cache and doens't need to be // downloaded. Hence, if there is no editor created yet, create it now. Inventory::InventoryItemDownloadedEventData *downloaded = checked_static_cast<Inventory::InventoryItemDownloadedEventData *>(data); assert(downloaded); asset_type_t at = downloaded->assetType; switch(at) { case RexTypes::RexAT_ParticleScript: case RexTypes::RexAT_MaterialScript: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if (!editorManager_->Exists(id, at)) { // Editor not created, create it now. OgreScriptEditor *editor = new OgreScriptEditor(id, at, name); connect(editor, SIGNAL(UploadNewScript(Inventory::InventoryUploadBufferEventData *)), this, SLOT(UploadBuffer(Inventory::InventoryUploadBufferEventData *))); connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); editor->HandleAssetReady(downloaded->asset); // Add widget to scene, show and bring to front uiService_.lock()->AddWidgetToScene(editor); uiService_.lock()->ShowWidget(editor); uiService_.lock()->BringWidgetToFront(editor); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) uiService_.lock()->BringWidgetToFront(editor); } // Surpress this event. downloaded->handled = true; return true; } case RexTypes::RexAT_SoundVorbis: case RexTypes::RexAT_SoundWav: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { AudioPreviewEditor *editor = new AudioPreviewEditor(framework_, id, at, name); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); editor->HandleAssetReady(downloaded->asset); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) { uiService_.lock()->BringWidgetToFront(editor); AudioPreviewEditor *audioWidget = qobject_cast<AudioPreviewEditor*>(editor); if(audioWidget) audioWidget->HandleAssetReady(downloaded->asset); } } downloaded->handled = true; return true; } case RexTypes::RexAT_Mesh: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { MeshPreviewEditor *editor = new MeshPreviewEditor(framework_, id, at, name, downloaded->asset->GetId().c_str()); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); //editor->HandleAssetReady(downloaded->asset); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor != 0) { uiService_.lock()->BringWidgetToFront(editor); MeshPreviewEditor *editorWidget = qobject_cast<MeshPreviewEditor*>(editor); if(editorWidget) editorWidget->RequestMeshAsset(downloaded->asset->GetId().c_str()); } } downloaded->handled = true; return true; } case RexTypes::RexAT_Texture: { const QString &id = downloaded->inventoryId.ToString().c_str(); const QString &name = downloaded->name.c_str(); if(!editorManager_->Exists(id, at)) { TexturePreviewEditor *editor = new TexturePreviewEditor(framework_, id, at, name, downloaded->asset->GetId().c_str()); QObject::connect(editor, SIGNAL(Closed(const QString &, asset_type_t)), editorManager_, SLOT(Delete(const QString &, asset_type_t))); editorManager_->Add(id, at, editor); } else { // Editor already exists, bring it to front. QWidget *editor = editorManager_->GetEditor(id, at); if (editor) uiService_.lock()->BringWidgetToFront(editor); } downloaded->handled = true; return true; } default: return false; } }