/* ==========================================================================
* 파    일 : TradeWindow.h
* 목    적 : 
* 작 성 자 : 김가람
* 작 성 일 : 2008-04-17
* 주의사항 :
*===========================================================================*/
#pragma once
#include "UIWindow.h"
#include "ItemManager.h"

class cLabel;
class cPushButton;
class cButton;
class cItemIcon;
struct sTradeItem
{
	unsigned int mSlotIndex;
	cItemIcon* mMyIcon;

	sTradeItem()
	{
		mMyIcon = 0;
		mSlotIndex = UINT_MAX;
	}
};

struct sThatInvetory
{
	sInventory mThatInv;
	cItemIcon* mThatIcon;

	sThatInvetory()
	{
		mThatIcon = 0;
		mThatInv.idx		= 0;
		mThatInv.ItemIndex	= 0;
		mThatInv.number		= 0;
		mThatInv.count		= 0;
		mThatInv.enhanced	= 0;
		mThatInv.seal		= 0;
	}
};

/// 거래 윈도우
class cTradeWindow : public cUIWindow
{
public:
	cTradeWindow();
	virtual ~cTradeWindow();

	void Clear();

	/// 상태 세팅
	//void SetStatus( eItemExchangeStatus status );
	//void SetThatStatus( eItemExchangeStatus status );

	void SetStatus( eItemExchangeStatus status, bool myTurn );
	unsigned char GetStatus() { return mStatus; }

	/// 두명 아이디 세팅
	void SetNames( LPCTSTR otherName );

	/// 아이템 삽입
	bool AddMyItem( unsigned int slot );
	bool DeleteMyItem( unsigned int arrIndex );	/// 트레이드 슬롯

	/// 상대방아이템 삽입
	bool AddThatItem( sInventory* inv );
	bool DeleteThatItem( sInventory* inv );

	/// 
	void AddMyMoney( unsigned long money );
	void AddThatMoney( unsigned long money );

	/// 참조한 인벤의 슬롯인덱스 획득
	int GetInvenSlot( unsigned int arrIndex ); 

	/// 
	unsigned int GetMyLastSlot() { return mMyLastSlot; }
	sTradeItem* GetMyItem();

	/// 
	bool IsNetLock();

protected:
	bool OnCreate( cUINodeProperty* property );
	void OnCommand( cUINode* node, unsigned int id );
	void OnPushButtonPressed( cUINode* , unsigned int id );
	void OnIconDragged( cUINode* caller, unsigned int id, const cUIPos& pos, bool shift );
	void OnIconHovered( cUINode* caller, unsigned int id, const cUIPos& pos );
	void OnHide();
	void HideESC( bool onsound );
	void OnNetLock( int lockTry );
	void OnNetUnLock( int lockTry );

	void UpdateMyData( unsigned int index );
	void UpdateThatData( unsigned int index );

protected:
	/// 내 등록아이템
	sTradeItem mMyItem[MAX_ITEM_EXCHANGE];

	/// 상대방 등록 아이템
	sThatInvetory mThatItem[MAX_ITEM_EXCHANGE];

	/// 마지막으로 채워진 아이템 트레이드 슬롯인덱스
	unsigned int mMyLastSlot;
	unsigned int mThatLastSlot;

	/// 아이디
	cLabel* mpName;
	cLabel* mpOtherName;

	/// 금액
	cLabel* mpMyMoney;
	cLabel* mpThatMoney;

	/// 버튼 : [press: 물품완료상태, not press: 물품수정상태]
	cButton* mTradeButton;
	cPushButton* mpMyOk;
	cPushButton* mpThatOk;

	/// 거래상태 (내상태, 상대방상태)
	eItemExchangeStatus mStatus;
	eItemExchangeStatus mThatStatus;
};

inline
sTradeItem* cTradeWindow::GetMyItem()
{
	return mMyItem;
}
