#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 Definition");
}

XMenuDef::~XMenuDef()
{

}

void XMenuDef::Clear()
{

}

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

    mFont.ParsePtr(aStream, false);

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

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

    mFadeCycle = aStream->ParseInt32(QString("%1 fade cycle").arg(GetName()));
    mFadeClamp = aStream->ParseSingle(QString("%1 fade clamp").arg(GetName()));
    mFadeAmount = aStream->ParseSingle(QString("%1 fade amount").arg(GetName()));
    mFadeInAmount = aStream->ParseSingle(QString("%1 fade in amount").arg(GetName()));
    mBlurRadius = aStream->ParseSingle(QString("%1 blur radius").arg(GetName()));

    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 = aStream->ParseSingle(QString("%1 focus color r").arg(GetName()));
    float focusG = aStream->ParseSingle(QString("%1 focus color g").arg(GetName()));
    float focusB = aStream->ParseSingle(QString("%1 focus color b").arg(GetName()));
    float focusA = aStream->ParseSingle(QString("%1 focus color a").arg(GetName()));

    float disableR = aStream->ParseSingle(QString("%1 disable color r").arg(GetName()));
    float disableG = aStream->ParseSingle(QString("%1 disable color g").arg(GetName()));
    float disableB = aStream->ParseSingle(QString("%1 disable color b").arg(GetName()));
    float disableA = aStream->ParseSingle(QString("%1 disable color a").arg(GetName()));

    mFocusColor = QColor::fromRgbF(focusR, focusG, focusB, focusA);
    mDisableColor = QColor::fromRgbF(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);
        }
    }
}
