#pragma once

#include "../interface.h"

#define TRADE_ITEM_MAX_SIZE			8

class CTradeFrame;
extern CTradeFrame*				g_pTradeFrame;

// 交易物品來源類型
enum TradeItemType {
	eTradeItemType_None			= 0,
	eTradeItemType_Bag,
	eTradeItemType_Bank,
	eTradeItemType_Equipment,
};

// 交易狀態
enum TradeState {
	eTradeState_None			= 0,
	eTradeState_Request_Made,				// 初步要跟對方交易
	eTradeState_Request_Receive,			// 被要求與對方交易,出現訊問題示
	eTradeState_Agree,						// 同意與對方交易
	eTradeState_Disagree,					// 不同意與對方交易
	eTradeState_Traded,						// 交易過程中
};

struct TradeItem {
	int type;								// 來源
	int pos;								// 位置
	int id;
};

class CTradeFrame : public CInterfaceBase
{
public:
	CTradeFrame(CInterface* object);
	virtual ~CTradeFrame();

	virtual	void				RegisterFunc();
	virtual	void				Update(float elapsedTime);
	virtual	int					SetProcess(TradeState state, int playerId, const char* name=NULL);
	virtual	void				Cancel();	
	virtual	int					Trade();
	virtual	int					PlayerItemLock();
	virtual	int					PlayerItemUnlock();
	virtual	int					RecipientItemLock();
	virtual	int					RecipientItemUnlock();
	virtual	TradeItem*			GetItem(int index);
	virtual	void				Cut(int index);
	virtual	void				Paste(int index);
	virtual	void				Refresh();
	virtual	int					GetPlayerId()							{ return m_playerId; }
	virtual	TradeState			GetTradeState()							{ return m_tradeState; }
	virtual	int					GetTradeMoney()							{ return m_money; }

protected:
	virtual	void				Clear();
	virtual	void				ClearItem();
	virtual	void				PutItem(int type, int index, int pos);

protected:
	TradeState					m_tradeState;
	int							m_playerId;
	int							m_money;
	bool						m_isConfirm;
	float						m_time;			
	TradeItem					m_items[TRADE_ITEM_MAX_SIZE];
};