Example #1
0
bool SoundEditDialog::Show(bool show)
{
    if (mSceneManipulator)
    {
        Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

        action->setParameter("ShowSoundItem", show ? "true" : "false");
    }

    mPlaySound = show;

    if (!mPlaySound)
        _StopAllSounds();

    return wxWindow::Show(show);
}
Example #2
0
void SoundEditDialog::ClearSoundData(void)
{
    _ClearSoundItems();

    _StopAllSounds();

    Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

    action->setParameter("ClearSoundEntity", "true");

    mCurrentSoundItem = NULL;
    mCurrentSoundHandle = -1;
    mCurrentRepeatTime = 0;
    mCurrentRepeatIntervalTime = 0;
    mCurrentPlayIntervalTime = 0;

    mCurrentFileName = "";
}
Example #3
0
void SoundEditDialog::_DeleteSoundItem(SoundItem* soundItem, int index)
{
    for (size_t i=0; i<mSoundItems.size(); ++i)
    {
        if (mSoundItems[i] == soundItem)
        {
            delete mSoundItems[i];

            mSoundItems.erase(mSoundItems.begin() + i);

            Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

            action->setParameter("DeleteSoundItem", Ogre::StringConverter::toString(index));

            _FillSoundListCtrl();
        }
    }
}
Example #4
0
void SoundEditDialog::LoadSoundInfoFromFile(const Ogre::String& filename)
{
    ClearSoundData();

    mCurrentFileName = filename;

    Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

    DBC::DBCFile excelDBFile(1);
    if(!excelDBFile.OpenFromTXT(filename.c_str()))
    {
        mSoundInfoFileChanged = false;
        return;
    }

    int iRecordCount = excelDBFile.GetRecordsNum(); 
    int iLastColum   = excelDBFile.GetFieldsNum();
    const DBC::DBCFile::FIELD* pInfo = NULL;	

    for(int i = 0; i < iRecordCount; i++)
    {
        SoundItem* soundItem = new SoundItem;
        // 读取ID
        pInfo = excelDBFile.Search_Posistion(i, 0);
        soundItem->mInstanceID = pInfo->iValue;

        // 类型id
        pInfo = excelDBFile.Search_Posistion(i, 1);
        soundItem->mSoundID = pInfo->iValue;

        // 位置x
        pInfo = excelDBFile.Search_Posistion(i, 2);
        soundItem->mXPos = pInfo->iValue;

        // 位置z
        pInfo = excelDBFile.Search_Posistion(i, 3);
        soundItem->mZPos = pInfo->iValue;

        // 有效半径
        pInfo = excelDBFile.Search_Posistion(i, 4);
        soundItem->mRadius = pInfo->iValue;

        // 连播次数
        pInfo = excelDBFile.Search_Posistion(i, 5);
        soundItem->mRepeatTime = pInfo->iValue;

        // 连播间隔时间
        pInfo = excelDBFile.Search_Posistion(i, 6);
        soundItem->mRepeatIntervalTime = pInfo->iValue;

        // 下次播放间隔时间
        pInfo = excelDBFile.Search_Posistion(i, 7);
        soundItem->mNextRepeatTime = pInfo->iValue;

        mSoundItems.push_back(soundItem);


        action->setParameter("CreateSoundEntity", Ogre::StringConverter::toString(soundItem->mXPos)
            + " " + Ogre::StringConverter::toString(soundItem->mZPos));
    }

    _FillSoundListCtrl();
}
Example #5
0
void SoundEditDialog::OnListBoxSoundItemDoubleClick( wxCommandEvent &event )
{
    _StopAllSounds();

    mPlaySoundInGame = false;

    int index = event.GetInt();

    if (index < (int)(mSoundItems.size()))
    {
        mWorkingSoundIndex = index;

        SoundItem* soundItem = mSoundItems[event.GetInt()];

        if (mSoundNameComboBox->IsEmpty())
            _FillSoundNameComboBox();

        SoundNames::iterator it = mSoundNames.find(soundItem->mSoundID);

        if (it != mSoundNames.end())
        {
            const Ogre::String& soundName = it->second;

            if (mSoundNameComboBox->FindString(soundName))
                mSoundNameComboBox->SetValue(soundName);
            else
                mSoundNameComboBox->SetSelection(0);

            mCurrentSoundHandle = _PlaySound(it->second, mCurrentSoundHandle, soundItem->mRepeatTime == 0);
        }
        else
        {
            mSoundNameComboBox->SetSelection(0);
        }

        mRadiusTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRadius) );
        mXPosTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mXPos) );
        mZPosTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mZPos) );
        mRepeatTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRepeatTime) );
        mRepeatIntervalTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mRepeatIntervalTime) );
        mNextRepeatTimeTextCtrl->SetValue( Ogre::StringConverter::toString(soundItem->mNextRepeatTime) );
        mSoundIDText->SetLabel( Ogre::StringConverter::toString(soundItem->mSoundID) );

        mCurrentSoundItem = soundItem;

        mCurrentRepeatTime = 0;
        mCurrentRepeatIntervalTime = 0;
        mCurrentPlayIntervalTime = 0;

        Ogre::Camera* camera = mSceneManipulator->getCamera();

        Fairy::TerrainData* terrainData = mSceneManipulator->getTerrainData();

        std::pair<float, float> worldPos = terrainData->gridToWorld(soundItem->mXPos, soundItem->mZPos);
        float worldHeight = terrainData->getHeightAt(worldPos.first, worldPos.second);

        Ogre::Vector3 direction = camera->getDirection();
        float v = Ogre::Math::Sin(Ogre::Math::DegreesToRadians(89.9f));
        float s = Ogre::Math::Sqrt((direction.x*direction.x + direction.z*direction.z) / (1-v*v));
        direction.x /= s;
        direction.z /= s;
        direction.y = -v;
        camera->setDirection(direction);

        camera->setPosition(worldPos.first, worldHeight + 2750.0f, worldPos.second);

        Fairy::Action* action = mSceneManipulator->_getAction("SoundEditAction");

        action->setParameter("ShowRadiusEntity", Ogre::StringConverter::toString(worldPos.first) + " " +
            Ogre::StringConverter::toString(worldHeight) + " " +
            Ogre::StringConverter::toString(worldPos.second) + " " +
            Ogre::StringConverter::toString(soundItem->mRadius));
    }
}
Example #6
0
void
BrushSelector::OnCheck( wxCommandEvent &event )
{
	if ( event.GetId() == feID_RANDOM )
	{
		// 禁止其他按钮
		if ( mRandom->IsChecked() )
		{
            mIsRandomOrientation = true;

			mFlipHorizontal->Enable(false);
			mFlipVertical->Enable(false);
			mRotateRightAngle->Enable(false);
            mMirrorDiagonal->Enable(false);
		}
		else
		{
            mIsRandomOrientation = false;

			mFlipHorizontal->Enable(true);
			mFlipVertical->Enable(true);
			mRotateRightAngle->Enable(true);
            mMirrorDiagonal->Enable(true);
		}
	}

	else
	{
		mCurrentOrientationType = 0;

		// 以下是checkbox状态的判断
		if ( mFlipHorizontal->IsChecked() == true )
		{
			mCurrentOrientationType |= 1;
		}

		if ( mFlipVertical->IsChecked() == true )
		{
			mCurrentOrientationType |= 2;
		}

		if ( mRotateRightAngle->IsChecked() == true )
		{
			mCurrentOrientationType |= 4;
		}

        if ( mMirrorDiagonal->IsChecked() == true )
        {
            mCurrentOrientationType |= 8;
        }
	}
	
	Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction");

    assert (action);

    action->setParameter( "%UseRandomOrientation", mIsRandomOrientation ? "true" : "false" );
	action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) );

	GetSceneManipulator()->setActiveAction(action);

 //   wxImage tempPreview;
	if ( mEnablePreview->IsChecked() )
	{
		// 选中按钮时,缩略图也要相应变化
		if ( event.GetId() == feID_FLIP_HORIZONTAL )
		{
			mCurrentPreviewImage = mCurrentPreviewImage.Mirror();
			mBrushesPreview->SetBitmap(mCurrentPreviewImage);
		}

		if ( event.GetId() == feID_FLIP_VERTICAL )
		{
			mCurrentPreviewImage = mCurrentPreviewImage.Mirror(false);
			mBrushesPreview->SetBitmap(mCurrentPreviewImage);
		}

		if ( event.GetId() == feID_ROTATE_RIGHT_ANGLE )
		{
			if ( mRotateRightAngle->IsChecked() == true )
			{
				mCurrentPreviewImage = mCurrentPreviewImage.Rotate90(false);
				mBrushesPreview->SetBitmap(mCurrentPreviewImage);
			}
			else
			{
				mCurrentPreviewImage = mCurrentPreviewImage.Rotate90();
				mBrushesPreview->SetBitmap(mCurrentPreviewImage);
			}
		}
	}
	else
	{
		// 如果不显示缩略图,就显示默认的黑白图
        mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
	}

    // 预览图的开关
	if ( event.GetId() == feID_ENABLE_PIXMAP_PREVIEW )
	{
		if ( mEnablePreview->IsChecked() )
		{
            // 如果用户打开开关,就用前面OnPixmapListSelected中计算好的预览图来显示
            // 这也是为什么前面OnPixmapListSelected中无论这个开关是否打开都要计算预览图的原因
            // 不然的话,这里打开开关后显示的是上次计算的预览图,而不是当前所选纹理的预览图
            mBrushesPreview->SetBitmap(mCurrentPreviewImage);
		}
		else
		{
            mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
		}
	}
}
Example #7
0
void
BrushSelector::OnPixmapListSelected(wxTreeEvent& event)
{
	try
	{
    // 以下是改成定义文件后的修改
    //  mPaintInOneGrid = false;
    // 保存当前选中的纹理的大小
    int selectedTexXSize = 0;
    int selectedTexZSize = 0;

    // 当画刷被选中时,要进行判断
    wxTreeItemId itemId = event.GetItem();

    wxTreeItemId rootId = mBrushesTree->GetRootItem();

    // 如果选中根,就返回
    if ( itemId == rootId )
    {
        // 选中根目录名时,所有选项都变灰
        mFlipHorizontal->Enable(false);
        mFlipVertical->Enable(false);
        mRotateRightAngle->Enable(false);
        mMirrorDiagonal->Enable(false);
        mRandom->Enable(false);
        mEnablePreview->Enable(false);

        // 缩略图用黑白图
        mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);

        return;
    }

    if (itemId.IsOk())
    {
        mCurrentOrientationType = 0;

        // 如果选项的父是root,说明该画刷是放在根目录下的,也有可能是根目录下的子目录
        if ( mBrushesTree->GetItemParent(itemId) == rootId )
        {
            mCurrentFileName = mBrushesTree->GetItemText(itemId);
        }
        else
        {
            // 以下处理不是放在根目录下的画刷

            wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId);
            mCurrentFileName = mBrushesTree->GetItemText(itemId);

            // 以此取出父目录的目录名,组合成相对路径名,并加上文件名
            while ( parentId != rootId )
            {
                wxString parentText = mBrushesTree->GetItemText(parentId);
                parentText += '/';
                mCurrentFileName.Prepend( parentText );

                parentId = mBrushesTree->GetItemParent(parentId);
            }		
        }

        // 如果名字中有.,说明是文件名,不是目录名
        if ( mCurrentFileName.find_first_of('|') != wxString::npos )
        {
            mFlipHorizontal->Enable(true);
            mFlipVertical->Enable(true);
            mRotateRightAngle->Enable(true);
            mMirrorDiagonal->Enable(true);
            mRandom->Enable(true);
            mEnablePreview->Enable(true);

            Ogre::String currentFileName(mCurrentFileName.c_str());

            size_t pos = currentFileName.find_last_of('/');

            // 取出brush名称
            Ogre::String brushName = currentFileName.substr(0,pos);
            Ogre::String textureName = currentFileName.substr(pos+1);

            const Fairy::TextureInfos &currentPaintInfos = 
                GetSceneManipulator()->getTextureInfos(brushName);

            const Fairy::TextureInfo &currentPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName);

            Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName);

            // 组成纹理信息字符串
            Ogre::String texInfoString;
            texInfoString += currentPaintInfo.ownerTextureName;
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getHeight());
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getWidth());
			texInfoString += "|";
			texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType);

            Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction");
            action->setParameter( "%TextureName", "InputBegin" );
            action->setParameter( "%TextureName", AS_STRING(texInfoString) );
            action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) );

            if ( (currentPaintInfo.width > 1 || currentPaintInfo.height > 1) && !mPaintInOneGrid )
            {               
                action->setParameter( "%TexNormalSize", "false" );
                mFlipHorizontal->Enable(false);
                mFlipVertical->Enable(false);
                mRotateRightAngle->Enable(false);
                mMirrorDiagonal->Enable(false);
                mRandom->Enable(false);
            }
            else
            {
                action->setParameter("%TexNormalSize","true");
            }

            GetSceneManipulator()->setActiveAction(action);

            buildPreviewBitmap(currentPaintInfo);
         
            if ( mEnablePreview->IsChecked() == false )
            {
                // 如果不显示缩略图,就显示默认的黑白图
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }
        }
        // 如果名字中有.,说明不是文件名,是目录名
        else
        {
            mFlipHorizontal->Enable(false);
            mFlipVertical->Enable(false);
            mRotateRightAngle->Enable(false);
            mMirrorDiagonal->Enable(false);
            mRandom->Enable(false);
            mEnablePreview->Enable(true);

            // 把整个目录的纹理进行判断,并加入到透明纹理列表

            const Fairy::Action* action = OnStartAutoTexAction(itemId, mCurrentFileName);

            if ( action != 0 )
            {
                // 从该组纹理的实心纹理中随机用一个来做为缩略图
                // 读取这张纹理,并缩放到mPreviewImageWidth*mPreviewImageHeight,用于缩略图
              //  Ogre::String tempTexName = action->getParameter( "%TextureName" );

                const Fairy::TextureInfos &currentPaintInfos = 
                    GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str());

              //  const Fairy::TextureInfo &currentPaintInfo = currentPaintInfos[0];

                // 构建preview image
                buildPreviewBitmap(currentPaintInfos[0]);                
            }
            else
            {
                mEnablePreview->Enable(false);
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }

            if ( mEnablePreview->IsChecked() == false )
            {
                // 如果不显示缩略图,就显示默认的黑白图
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }
        }
    }
   
    // 让所有的checkbox回复未选择的状态
    mFlipHorizontal->SetValue(false);
    mFlipVertical->SetValue(false);
    mRotateRightAngle->SetValue(false);
    mMirrorDiagonal->SetValue(false);
    mRandom->SetValue(false);
	}
	catch (Ogre::Exception &e)
	{
		wxMessageBox(
			e.getDescription().c_str(),
           /* _("Texture Wrong")*/wxT("纹理定义出错或找不到纹理图片"),
            wxOK|wxCENTRE|wxICON_ERROR, this);
	}
}
Example #8
0
const Fairy::Action * 
BrushSelector::OnStartAutoTexAction( const wxTreeItemId &itemId, const wxString &brushName )
{
    // 启动自动纹理拼接action
    Fairy::Action* action = GetSceneManipulator()->_getAction("AutoTexPaintAction");

    // 获取组的名称
    wxString groupName = mBrushesTree->GetItemText(itemId);

    // 设置当前组的名称
    action->setParameter( "%GroupName", AS_STRING(brushName) );
 
    // 把之前的路径加上去
    wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId);
    wxTreeItemId rootId = mBrushesTree->GetRootItem();

    while ( parentId != rootId )
    {
        wxString parentText = mBrushesTree->GetItemText(parentId);
        parentText += '/';
        groupName.Prepend( parentText );

        parentId = mBrushesTree->GetItemParent(parentId);   
    }

    groupName += "/";

    // 获取该目录下的第一个节点
    wxTreeItemIdValue dummy;
    wxTreeItemId childId = mBrushesTree->GetFirstChild(itemId,dummy);

    while ( childId.IsOk() == true )
    {
        // 遍历每个节点,设置纹理名称
        wxString texName = mBrushesTree->GetItemText(childId);

        childId = mBrushesTree->GetNextChild(itemId,dummy);

        if ( texName.find('|') == wxString::npos )
            continue;

        action->setParameter( "%TextureName", AS_STRING(texName) );        
    }

    // 输入InputFinish表示纹理名称输入完毕
    action->setParameter( "%TextureName", "InputFinish" );
    
    // 判断纹理是否正确地进行了初始化
    if ( action->getParameter("%IsInit") == "Yes" )
    {
        GetSceneManipulator()->setActiveAction(action);
        return action;
    }
    else
    {
        // 启用simplepaintAction
        action = GetSceneManipulator()->_getAction("SimplePaintAction");

        action->setParameter( "%TextureName", "InputBegin" );

        // 获取该目录下的第一个节点
        wxTreeItemIdValue dummy;
        wxTreeItemId childId = mBrushesTree->GetFirstChild(itemId,dummy);

        while ( childId.IsOk() == true )
        {
            // 遍历每个节点,设置纹理名称
            wxString texName = mBrushesTree->GetItemText(childId);

            childId = mBrushesTree->GetNextChild(itemId,dummy);

            if ( texName.find('|') == wxString::npos )
                continue;

            const Fairy::TextureInfos &currentPaintInfos = 
                GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str());

            const Fairy::TextureInfo &currentPaintInfo =
                GetSceneManipulator()->getTextureInfo(mCurrentFileName.c_str(), texName.c_str());

            Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName);

            // 组成纹理信息字符串
            Ogre::String texInfoString;
            texInfoString += currentPaintInfo.ownerTextureName;
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getHeight());
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getWidth());
			texInfoString += "|";
			texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType);

            action->setParameter( "%TextureName", AS_STRING(texInfoString) );  

            // 这里有个错误??,因为没有设置该纹理是否为普通纹理大小,所以如果这一个组中有一个大纹理,那么
            // 它可能会只缩放到一格
        }

        if ( action->getParameter("%IsInit") == "Yes" )
        {
            GetSceneManipulator()->setActiveAction(action);
            return action;
        }
        else
        {
            // 为能成功初始化,先把active action设为NULL
            GetSceneManipulator()->setActiveAction(NULL);
            return NULL;
        }
    }
}