/* ==========================================================================
* 파    일 : QuickManager.h
* 목    적 : 퀵슬롯 매니저
* 작 성 자 : 김가람
* 작 성 일 : 2007-09-20
* 주의사항 :
*===========================================================================*/
#pragma once
#include "Icon.h"
#include "Player_Common.h"
#include "Item_Common.h"

const int QUICK_COUNT = 50;		/// 일반 퀵(30) + FS퀵(20)
const int QUICK_COUNT_MON = 3;	/// 몬스터퀵(3)
const int QUICK_TOTAL = QUICK_COUNT + QUICK_COUNT_MON;

const int ICON_COUNT = 20;		/// 연결된 아이콘 수
const int QUICKSLOT_COUNT = 10;	/// 출력되는 아이콘 수

/// 몬스터 스킬아이콘 이미지 인덱스 ( 3 ~ 5 )
const int MONICON_PARAMINDEX = 3; 

/// 슬롯 정의
enum eQuickSlotIndex
{
	/// 일반 퀵슬롯
	QUICKSLOT_BEGIN = 0,
	QUICKSLOT_END = QUICKSLOT_BEGIN + 30 - 1,

	/// FS 퀵슬롯
	QUICKSLOT_FS_BEGIN,				//QUICKSLOT_F
	QUICKSLOT_FS_END = QUICKSLOT_FS_BEGIN + 20 - 1,

	/// MONSTER 퀵슬롯
	QUICKSLOT_MON_BEGIN,
	QUICKSLOT_MON_END = QUICKSLOT_MON_BEGIN + 3 - 1,
};


class cIcon;
class cQuickData
{
public:
	cQuickData();
	cQuickData( cQuickData& other );

	/// 대입
	void operator=( const cQuickData& other );
	void operator=( unsigned int i );

public:
	/// 데이터 타입 ( 0 : 아이템류, 1 : 스킬류 )
	char mType;

	/// 고유 인덱스
	unsigned long mDBIndex;
	/// 아이템 인덱스
	unsigned long mItemIndex;

	/// 스킬 인덱스
	unsigned long mSkillIndex;
	unsigned char mSkillStep;
	
    /// 아이콘 컬러
	NiColorA mColor;

	/// 애니메이션
	sAniParam* mAniParam;

	/// 레어도 관련 팁 타입 ( 이미지 테두리 )
	unsigned int mTipType;

	unsigned long mStartTime;
	unsigned long mElapsedTime;
	unsigned long mMaintainTime;
};

inline cQuickData::cQuickData()
: mType( eSHORTCUT_NONE )
, mDBIndex(0)
, mItemIndex(0)
, mSkillIndex(0)
, mSkillStep(0)
, mColor( NiColorA::WHITE )
, mStartTime(0)
, mElapsedTime(0)
, mMaintainTime(0)
, mAniParam(0)
, mTipType( eTOOLTIP_NONE )
{
}

inline cQuickData::cQuickData( cQuickData& other )
: mType( eSHORTCUT_NONE )
, mDBIndex(0)
, mItemIndex(0)
, mSkillIndex(0)
, mSkillStep(0)
, mColor( NiColorA::WHITE )
, mStartTime(0)
, mElapsedTime(0)
, mMaintainTime(0)
, mAniParam(0)
, mTipType( eTOOLTIP_NONE )
{
	operator=( other );
}

inline void cQuickData::operator=( const cQuickData& other )
{
	mType = other.mType;
	mDBIndex = other.mDBIndex;
	mItemIndex = other.mItemIndex;
	mSkillIndex = other.mSkillIndex;
	mSkillStep = other.mSkillStep;
	mColor = other.mColor;
	mStartTime = other.mStartTime;
	mElapsedTime = other.mElapsedTime;
	mMaintainTime = other.mMaintainTime;
	mAniParam = other.mAniParam;
	mTipType = other.mTipType;
}

inline void cQuickData::operator=( unsigned int i )
{
	if( i <= 0 )
	{
		mType = eSHORTCUT_NONE;
		mDBIndex = 0;
		mItemIndex = 0;
		mSkillIndex = 0;
		mSkillStep = 0;
		mColor = NiColorA::WHITE;
		mStartTime = 0;
		mElapsedTime = 0;
		mMaintainTime = 0;
		mAniParam = 0;
		mTipType = eTOOLTIP_NONE;
	}
	else
	{
		assert(0);
	}
}

/// 아이콘 묶음
class cBindIcon
{
public:
	cBindIcon();

	/// 대입
	void operator=( const cBindIcon& other );
	void operator=( cIcon& other );
	
	void SetParam( cIconParam* param );
	void SetCount( unsigned int count );
	void ShowNumber( bool show );
	void SetColor( const NiColorA& color );
	void SetColor( float r, float g, float b, float a );
	void SetAniParam( sAniParam* param );
	void SetTipType( unsigned int type );
	void StopDelay();

public:
	cIcon* mRowIcon;
	cIcon* mColumnIcon;
};

inline cBindIcon::cBindIcon()
: mRowIcon(0)
, mColumnIcon(0)
{
}

inline void cBindIcon::operator=( const cBindIcon& other )
{
	cIcon* icon = other.mColumnIcon;
	operator=( *icon );
}

inline void cBindIcon::operator=( cIcon& other )
{
	SetParam( other.GetIconParam() );
	SetCount( other.GetNumber() );
	ShowNumber( other.IsShowNumber() );

	SetAniParam( other.GetAniParam() );
	SetTipType( other.GetTipType() );

	mRowIcon->ChangeGauge( other.GetGauge() );
	mColumnIcon->ChangeGauge( other.GetGauge() );
}

inline void cBindIcon::SetParam( cIconParam* param )
{
	mRowIcon->ChangeImage( param );
	mColumnIcon->ChangeImage( param );
}

inline void cBindIcon::SetCount( unsigned int count )
{
	mRowIcon->SetNumber( count );
	mColumnIcon->SetNumber( count );
}

inline void cBindIcon::SetColor( float r, float g, float b, float a )
{
	mRowIcon->SetColor( r, g, b, a );
	mColumnIcon->SetColor( r, g, b, a );
}

inline void cBindIcon::SetColor( const NiColorA& color )
{
	mRowIcon->SetColor( color );
	mColumnIcon->SetColor( color );
}

inline void cBindIcon::ShowNumber( bool show )
{
	mRowIcon->ShowNumber( show );
	mColumnIcon->ShowNumber( show );
}

inline void cBindIcon::SetAniParam( sAniParam* param )
{
	mRowIcon->SetAniParam( param );
	mColumnIcon->SetAniParam( param );
}

inline void cBindIcon::SetTipType( unsigned int type )
{
	mRowIcon->SetTipType( type );
	mColumnIcon->SetTipType( type );
}

inline void cBindIcon::StopDelay()
{
	mRowIcon->StopDelay();
	mColumnIcon->StopDelay();
}


/// 퀵슬롯 매니저 
class cQuickManager
{
public:
	static cQuickManager* mSingleton;

public:
	cQuickManager();
	~cQuickManager();

	///
	void Open();

	/// 모든 데이터 삭제
	void Clear();
	
	/// 네트워크 세팅 
	void NetSetData( unsigned int dataIndex, const sShortcut& shortcut );
	void NetUpdateData();

	/// 퀵슬롯 사용 - 단축키
	void OnKeyDown( eKeyCode code );
	void OnMouseDown( unsigned int iconId, bool IsFS = false );
	
	/// 퀵슬롯 업데이트
	void UpdateUI();
	void UpdateIcon( int i, int iconId, bool countCheck = true );

	/// hero의 착용 무기와 스킬 적합 여부 검사
	void CheckSkillIcon();
	void CheckItemIcon();

	/// 퀵슬롯 탭체인지
	void ChangeTab( unsigned int tabindex );
	void ChangeTabFS( unsigned int tabindex );

	/// 퀵슬롯의 아이콘 위치와 복사할 아이콘 정보
	void AddData( unsigned int iconId, cIcon* srcIcon, bool toIsFS );
	void MoveData( unsigned int iconId, cIcon* srcIcon, bool toIsFS );
	void DeleteData();
	void DeleteData( unsigned int iconId, unsigned int dataIndex );

	/// 등록 데이터가 있는지 여부
    bool IsUseSlot( unsigned int iconId, bool IsFS = false );
	eSHORTCUT_TYPE GetQuickType( unsigned int iconId, bool IsFS = false );
	unsigned int GetItemIndex( unsigned int iconId, bool IsFS = false );
	unsigned int GetSkillIndex( unsigned int iconId, bool IsFS = false );
	short GetMonSkillIndex( unsigned int iconId );

	void DragIcon( cIcon* icon );
	void UnDragIcon();

	/// UI 아이콘과 바인딩
	void BindRowIcon( unsigned int index, cIcon* icon );
	void BindColumnIcon( unsigned int index, cIcon* icon );
	void BindFSRowIcon( unsigned int index, cIcon* icon );
	void BindFSColumnIcon( unsigned int index, cIcon* icon );

	///
	unsigned int GetTabIndex() { return mTabIndex; }
	void SetRowQuick( bool IsRow );
	bool IsRowQuick() { return mIsRowQuick; }

	void SetRowQuickFS( bool IsRow );
	bool IsRowQuickFS() { return mIsRowQuickFS; }

	void SetTotalCount( unsigned int dataIndex, unsigned int iconId, unsigned long itemIndex );

	/// 아이콘 애니메이션 돌리기
	void SetSkillAniAura( unsigned long skillIndex, sAniParam* param );

	void SetCharge( unsigned long skillIndex, bool charge );
	void SetMonCharge( unsigned long skillIndex, bool charge );	/// 몬스터 스킬 챠지


	/// 게임접속시 모든 아이템 쿨타임 세팅
	void SetAllItemCool();
	void ClearCoolTime( unsigned int slottype, unsigned long index );
	void LoadCoolTime();
	void LoadCoolTimeMon();
    
	void SetItemCool( unsigned int quickIdx, unsigned long startTime, unsigned long restTime, unsigned long totalTime );
	void StartCoolTime( unsigned long itemIndex, unsigned long coolTime );
	void EndCoolTime( unsigned long itemIndex );

	/// 스킬관련 쿨타임
	void SaveSkillCool( unsigned int dataIdx, unsigned int iconId );
	void InitSkillCooltime( unsigned long skillindex, unsigned long restTime, unsigned long totalTime );
	void StartSkillCoolTime( unsigned long skillIndex, unsigned long cool );

	/// 몬스터 스킬 관련
	void ChangeMonster( unsigned long monIndex );

	/// 게임 접속시 몬스터 쿨타임 전체 세팅
	void SaveSkillCoolMon( unsigned int dataIdx, unsigned int iconId );
	void InitMonSkillCooltime( short skillindex, unsigned long restTime, unsigned long totalTime );
	void StartMonSkillCoolTime( short skillIdx, unsigned long cool );

protected:
	/// 퀵슬롯 사용
	void UseQuickSlot( unsigned int iconId, bool IsFS = false );
	void UseMonsterQuickSlot( unsigned int iconId );	

	bool UsableSkillIcon( eWEAPON_STATE heroWeaponState, unsigned long skillindex, unsigned char skillstep );
	bool UsableMonSkillIcon( unsigned long skillindex );

public:
	static cQuickManager* GetSingleton();

private:
	/// 퀵슬롯 정보
	/// 일반 퀵 + FS 퀵 + 몬스터 퀵
	cQuickData mQuick[QUICK_TOTAL];
	cBindIcon mBindIcon[ICON_COUNT];

	/// 몬스터 변신으로 인한 퀵슬롯 락
	bool mIsLockByMonster;

	/// 퀵슬롯 탭 인덱스
	unsigned int mTabIndex;
	unsigned int mTabIndexFS;		/// FS 슬롯

	/// 세로형 퀵슬롯 여부 ( 0 : 가로형, 1 : 세로형 )
	bool mIsRowQuick;
	bool mIsRowQuickFS;				/// FS 슬롯

	/// 드래그중인 아이콘 
	cIcon* mDragIcon;
};

inline void cQuickManager::BindRowIcon( unsigned int index, cIcon* icon )
{
	assert( icon );
	mBindIcon[index].mRowIcon = icon;
}

inline void cQuickManager::BindColumnIcon( unsigned int index, cIcon* icon )
{
	assert( icon );
	mBindIcon[index].mColumnIcon = icon;	
}

inline void cQuickManager::BindFSRowIcon( unsigned int index, cIcon* icon )
{
	assert( icon );
	mBindIcon[index+QUICKSLOT_COUNT].mRowIcon = icon;
}

inline void cQuickManager::BindFSColumnIcon( unsigned int index, cIcon* icon )
{
	assert( icon );
	mBindIcon[index+QUICKSLOT_COUNT].mColumnIcon = icon;	
}

inline 
cQuickManager* cQuickManager::GetSingleton()
{
	return mSingleton;
}

#define QUICKMAN cQuickManager::GetSingleton()
