⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guicellarrayctrl.h

📁 五行MMORPG引擎系统V1.0
💻 H
字号:
//guiCellArrayCtrl.h
/*/////////////////////////////////////////////////////////////////

   李亦 liease@163.com 4040719
	2006-7-8
/*/////////////////////////////////////////////////////////////////
#ifndef _GUICELLARRAYCTRL_H_
#define _GUICELLARRAYCTRL_H_


#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif

#ifndef _CONSOLETYPES_H_
#include "console/consoleTypes.h"
#endif

#ifndef _DGL_H_
#include "dgl/dgl.h"
#endif

#ifndef _CONSOLE_H_
#include "console/console.h"
#endif

#ifndef _RPG__GGOODSARRAY_H_
#include "rpg/gobjects/GGoodsArray.h"
#endif

//namespace RPG
//{
//	class GGoodsArray{
//		struct GGoodsInfo;};
//};

class GuiCellButtonCtrl;

class GuiCellArrayControl : public GuiControl
{
	friend class GuiCellButtonCtrl;
	friend class GuiCellArrayControl;
private:
   typedef GuiControl Parent;


   Vector<GuiCellButtonCtrl*>		m_arCellBtns;
   Vector<StringTableEntry>		m_arCellNames;
   Vector<StringTableEntry>		m_arCellBlanks;
   Vector<StringTableEntry>		m_arCellAccels;//加速键列表
   Vector<StringTableEntry>		m_arCellCursors;//光标

	GuiControlProfile*				m_pCellProfile;

	StringTableEntry					m_pText;
	StringTableEntry					m_pEndCallback;
	StringTableEntry					m_pPrefName;	//pref保存名称
	//StringTableEntry					m_pToolTipGui;	
	GuiControl*							m_pToolTipCtrl;//提示面板名称
	U32									m_nToolTipStyle;

	S32			m_nIconBase;
   S32			mRowSpacing;
   S32			mColSpacing;

	Point2I		m_cellNumBak;
   S32			m_nCols;
   S32			m_nRows;
	S32			m_nCellAmount;
	Point2I		m_cellSize;
	Point2I		m_cellAreaSize;
	bool			m_bCellBorder;
	bool			m_bNeedCreateCells;
	STE			m_sSupplyKey;	//是否为提供者


	U32			m_uCellAlign;	//文字与图标的对齐方式 左 右 上 下
	U32			m_uMaxStrWidth;
	//bool			m_bCanDragDrop;
	U32			m_uDragMode;	//拖曳模式

	StringTableEntry	m_pIconTexture;		//没指定图标纹理的话,则查询全局的GameIcon
	TextureHandle		m_iconTextureHandle;
	

protected:
	static	StringTableEntry  ms_sCellNamesLabel;
public:
	enum CellDragTypes
	{
		CDT_NONE				= 0,
		CDT_DRAG		= BIT(0),
		CDT_MOVE				= BIT(1),
		CDT_DROP				= BIT(2),
		CDT_SELFMOVE		= BIT(3),
		CDT_SELFDROP		= BIT(4),

		CDT_DRAGDROP		= CDT_DRAG | CDT_DROP,
		CDT_DRAGSELFDROP	= CDT_DRAG | CDT_SELFDROP,

		CDT_DRAGMOVE		= CDT_DRAG | CDT_MOVE,
		CDT_MOVEDROP		= CDT_DRAG | CDT_MOVE | CDT_DROP,
		CDT_MOVESELFDROP	= CDT_DRAG | CDT_MOVE | CDT_SELFDROP,

		CDT_DRAGSELFMOVE		= CDT_DRAG | CDT_SELFMOVE,
		CDT_SELFMOVEDROP		= CDT_DRAG | CDT_SELFMOVE | CDT_DROP,
		CDT_SELFMOVESELFDROP	= CDT_DRAG | CDT_SELFMOVE | CDT_SELFDROP,

		CDT_CANMOVE			= CDT_MOVE|CDT_SELFMOVE,
		CDT_CANDROP			= CDT_DROP|CDT_SELFDROP,

	};

	enum CellPutStates
	{
		GPS_FAILED,
		GPS_OK,
		GPS_SWAP,
	};

	enum CellAlignTypes
	{
		ALIGN_NONE,
		ALIGN_LEFT,	//	奇数为水平对齐,偶数为竖直对齐
		ALIGN_TOP,
		ALIGN_RIGHT,
		ALIGN_BOTTOM,
	};

	enum ToolTipStyle
	{
		TTS_NONE,
		TTS_TOOLTIP,
		TTS_TEXTTIP,
		TTS_AMOUNT
	};

protected:
	void refreshCell(GuiCellButtonCtrl* pCell);
public:
   GuiCellArrayControl();

public:
	Vector<StringTableEntry>&		GetCellNames()	{return m_arCellNames;}
	Vector<GuiCellButtonCtrl*>&	GetCellBtns()	{return m_arCellBtns;}
	
	////////////////////////////////////////////////////////////////////
	///@name 拖曳模式存取
	///@{
#define DECLARE_DRAG_MODE(NAME)\
	BOOL DragIs##NAME(){return (m_uDragMode & CDT_##NAME) == CDT_##NAME;}
#define DECLARE_DRAG_MODE2(NAME)\
	BOOL DragCheck##NAME(){return (m_uDragMode & CDT_##NAME);}

	DECLARE_DRAG_MODE(DRAG);
	DECLARE_DRAG_MODE(DRAGDROP);
	DECLARE_DRAG_MODE(MOVE);
	DECLARE_DRAG_MODE(SELFMOVE);
	DECLARE_DRAG_MODE(SELFDROP);
	DECLARE_DRAG_MODE(DROP);
	DECLARE_DRAG_MODE(MOVEDROP);
	DECLARE_DRAG_MODE2(CANMOVE);
	DECLARE_DRAG_MODE2(CANDROP);

	BOOL DragIsNONE(){return m_uDragMode == CDT_NONE;}
	/// @}



	////////////////////////////////////////////////////////////////////
	/// @name 数据源管理
	/// @{
protected:
	RPG::GGoodsArray*		m_pDataSource;	//数据源
	U32						m_uBaseIndex;

public:
	void attachDataSource(RPG::GGoodsArray*	pDatSrc, U32 uBase, U32 uAmount);
	void loadSourceData();
	inline const U32 GetBaseIndex() const{return m_uBaseIndex;}
	/// @}



		/// @name 高亮Cell操作
	/// @{
public:
	enum CellHilightModes
	{
		CHLM_NORMAL,
		CHLM_CONTINUE,
		CHLM_AMOUNT
	};
protected:
	enum CellHilightStates
	{
		CHLS_NONE,
		CHLS_ENTER,
		CHLS_ENTERSHOWING,
		CHLS_SHOWING,
		CHLS_SHOWED,
		CHLS_LEAVE,
		CHLS_HIDDING,
	};
	BOOL						m_bMouseDown;
	GuiCursor*				m_pCursorCaret;
	GuiCellButtonCtrl*	m_pDragCell;
	GuiCellButtonCtrl*	m_pHilightCell;	//高亮Cell
	U32						m_dwHilightTimer;
	CellHilightStates		m_dwHilightState;
	U32						m_dwHilightDelay;
	U32						m_dwHideDelay;
	U32						m_dwHilightMode;

	void updateHilightCell();
public:
	bool isMouseDown();
	bool isCellDragged();
	bool isCellDraging(GuiCellButtonCtrl* pCell);
	void readyDragCell(GuiCellButtonCtrl* pCell);
	void beginDragCell(GuiCellButtonCtrl* pCell);
	bool showToolTip(GuiCellButtonCtrl* pCell);
	bool showToolTip();
	bool toggleShowToolTip();
	void toggleHilightMode();
	void hideToolTip();
	bool isHilightShow(){return m_dwHilightState == CHLS_SHOWING || m_dwHilightState == CHLS_SHOWED;}
	/// @}

	void loadPrefData();
	void savePrefData();

	void destroyCells();
	void initCells(U32 uAmount);
	void createCells(U32 uBase=0);
	bool setCellName(U32 nIndex, StringTableEntry pCellName); 

	bool processGoodsInfos(RPG::GGoodsArray::GGoodsInfo goodsInfo[],U32 nNum);
	void clearCell(GuiCellButtonCtrl* pCell,bool bDiscard);
	void swapCellTo(GuiCellButtonCtrl* pCell, GuiCellButtonCtrl* pDest);
	U32  putCellTo(GuiCellButtonCtrl* pCell, GuiCellButtonCtrl* pDest);


   void resize(const Point2I &newPosition, const Point2I &newExtent);
   void updateCell(GuiCellButtonCtrl* pCell);
   void updateCells();
	void calcMaxStrWidth();
   
	void onPreRender();
	void onRender(Point2I offset, const RectI &updateRect);

	void updateGameIcon(U32 nIndex);
	void updateGameIcons();
	virtual void onCellAction(GuiCellButtonCtrl* pCell,bool bRight=false);
	virtual void ToggleVH(bool bToVerticalBar,GuiControl *pDispatch);

   void write(Stream &stream, U32 tabStop, U32 flags = 0);
   SimObject* duplicate(bool bWithChildren=true,bool bRegister=false);


	/////////////////////////////////////////////////////////
	//Parent event

	void onMouseDown(const GuiEvent &);
	void onRightMouseDown(const GuiEvent &);
	void onMouseUp(const GuiEvent &);

	bool onAdd();
	void onRemove();

   bool onWake();
   void onSleep();
	void inspectPreApply();
   void inspectPostApply();

   //void onNameChange(const char *name);         ///< Called when the object's name is changed.
   //void onStaticModified(const char* slotName); ///< Called when a static field is modified.

	//void getCursor(GuiCursor *&cursor, bool &visible, const GuiEvent &event);
	//void onCellMouseDragged(GuiCellButtonCtrl* pCell,const GuiEvent &event);


   static void initPersistFields();
   DECLARE_CONOBJECT(GuiCellArrayControl);
};//GuiCellArrayControl

//////////////////////////////////////////////////
//
inline bool GuiCellArrayControl::isMouseDown()
{
	return m_bMouseDown;
}
inline bool GuiCellArrayControl::isCellDragged()
{
	return m_pCursorCaret != NULL;
}
inline bool GuiCellArrayControl::isCellDraging(GuiCellButtonCtrl* pCell)
{
	return m_pDragCell == pCell;
}


#endif //_GUICELLARRAYCTRL_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -