#include "xmenudef.h"
#include "xitemdef.h"

XMenuDef::XMenuDef()
    : XAsset()
    , mWindow()
    , mFont()
    , mFullScreen(0)
    , mItemCount(0)
    , mFontIndex(0)
    , mCursorItem(4)
    , mFadeCycle(0)
    , mFadeClamp(0.0f)
    , mFadeAmount(0.0f)
    , mFadeInAmount(0.0f)
    , mBlurRadius(0.0f)
    , mOnOpen()
    , mOnClose()
    , mOnESC()
    , mOnKey()
    , mVisibleExp()
    , mAllowedBinding()
    , mSoundName()
    , mImageTrack(0)
    , mFocusColor()
    , mDisableColor()
    , mRectXExp()
    , mRectYExp()
    , mItems()
{
    SetType(ASSET_TYPE_MENU);
    SetName("Menu Def");
}

XMenuDef::~XMenuDef()
{

}

void XMenuDef::Clear()
{

}

void XMenuDef::ParseData(QDataStream *aStream)
{
    mWindow.ParseData(aStream);

    mFont.ParsePtr(aStream, false);

    *aStream
        >> mFullScreen
        >> mItemCount
        >> mFontIndex;

    for (int i = 0; i < 4; i++)
    {
        *aStream >> mCursorItem[i];
    }

    *aStream
        >> mFadeCycle
        >> mFadeClamp
        >> mFadeAmount
        >> mFadeInAmount
        >> mBlurRadius;

    mOnOpen.ParsePtr(aStream, false);
    mOnClose.ParsePtr(aStream, false);
    mOnESC.ParsePtr(aStream, false);
    mOnKey.ParsePtr(aStream, false);

    mVisibleExp.ParseData(aStream);

    mAllowedBinding.ParsePtr(aStream, false);
    mSoundName.ParsePtr(aStream, false);

    *aStream >> mImageTrack;

    float focusR, focusG, focusB, focusA,
        disableR, disableG, disableB, disableA;

    *aStream
        >> focusR
        >> focusG
        >> focusB
        >> focusA
        >> disableR
        >> disableG
        >> disableB
        >> disableA;

    mRectXExp.ParseData(aStream);
    mRectYExp.ParseData(aStream);

    qint32 itemsPtr;
    *aStream >> itemsPtr;

    mFont.ParseData(aStream);
    mOnOpen.ParseData(aStream);
    mOnClose.ParseData(aStream);
    mOnESC.ParseData(aStream);
    mOnKey.ParseData(aStream);
    mVisibleExp.ParseData(aStream);
    mAllowedBinding.ParseData(aStream);
    mSoundName.ParseData(aStream);
    mRectXExp.ParseData(aStream);
    mRectYExp.ParseData(aStream);

    if (itemsPtr)
    {
        for (int i = 0; i < mItemCount; i++)
        {
            XItemDef newItemDef;
            newItemDef.ParsePtr(aStream);
            mItems.append(newItemDef);
        }
    }
}
