#pragma once
#include "global.h"
#include "MyStructDef.h"
#include "CPxaEditor.h"
#include "EntityRes.h"
class CMapEditorDraw : public CDialog
{
	DECLARE_DYNAMIC(CMapEditorDraw)
	DECLARE_MESSAGE_MAP()
public:
	CMapEditorDraw(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CMapEditorDraw();
	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_CMAPEDITOR_DRAW };
#endif
	void* pParentEditor = nullptr;
	MyView* pBrushView = nullptr;
	int* pTimeCounter = nullptr;
	float* pWindAniIndex = nullptr;
	float* pWindAniIndex2 = nullptr;
	int* pMapW = nullptr;
	int* pMapH = nullptr;
	float* pWallShadow = nullptr;
	float* pStageLight = nullptr;
	std::wstring* pVS = nullptr;
	std::wstring* pPS = nullptr;
	std::list<MyMapLayer*>* pDrawLayer = nullptr;//需要上锁访问的变量
	std::mutex* pMtx = nullptr;
	bool* pPlaying = nullptr;
	//实体编辑
	bool* pDragEntity = nullptr;
	//录制系统
	int* pRecordEndPos_x = 0, *pRecordEndPos_y = 0;
	MyView* GetMyView();
	void Draw(bool timeCounterDraw = false);
	void ResetContext();
	void RefreshImage();
	void ResetEntityPlay();
	void SetCursorToCopyBuffSize();
	EntityRes* GetEntityRes();
	void GetCopyBoard(CMAPEDITOR_DATATYPE_PXM** outCopyBuff, int** outCopyBuff_w, int** outCopyBuff_h);
	void UpdateMapCache();
	PxaData* GetPxa(CString pxaName);
	void SetScreenShot();
	std::string GenerateFileName(const char* layerName, bool bStageOrEntity, bool fBkOrbBk) const;
	void MergePNGsWithAseprite(const std::string& asepritePath,
		const std::string& luaScriptPath,
		const std::string& outputAsepriteFile,
		const std::vector<std::string>& pngFiles);
protected:
	void DoDataExchange(CDataExchange* pDX) override;
	BOOL OnInitDialog() override;
public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
private:
	//渲染器
	MyDX11Renderer pRenderer;
	TTF_Font* pFont_sourcesun20 = nullptr;//字体
	std::unordered_map<wchar_t, MyFontData> pFontMap28;
	MyView view;
	//贴图
	std::unordered_map<std::wstring, MyTextureAndSRV> loadedTexture;
	std::unordered_map<std::wstring, PxaData> loadedPxa;
	MyTextureAndSRV tas_pxatype;
	MyTextureAndSRV tas_nullpxa;
	ID3D11ShaderResourceView* GetTexture(CString pngName);
	bool painting = false;//正在绘制
	int paintStartCursorPosX = 0, paintStartCursorPosY = 0;//涂画模式用
	CMAPEDITOR_DATATYPE_PXM copyBuff;//复制用
	int copyBuff_w = 0, copyBuff_h = 0;//复制用
	//实体编辑
	CPoint rclick_last_pt;
	//实体播放
	EntityRes entityRes;
	void DrawTile();//涂画
	void DrawLayerBack(MyMapLayer* pLayer);//绘制里层地形
	void DrawLayerFront(MyMapLayer* pLayer);//绘制表层地形
	void DrawLoopLayer(MyMapLayer* pLayer, MyMapLayer* selectLayer);//绘制循环背景层
	void DrawPxa(MyMapLayer* pLayer);
	bool IsBackPxa(int pxaID);
	bool IsWindPxa(int pxaID);
	void DrawEntityGrid(MyMapLayer* pLayer);//绘制实体网格
	void DrawEntityLabel(MyMapLayer* pLayer);//绘制实体标签
	void DrawClipRect(MyMapLayer* pLayer);//绘制剪切区域
	void DrawStage(bool timeCounterDraw, MyMapLayer* selectLayer);
	//光照
	ExTextureBuffer stageBuffer, entityLight;
	void DrawRecordGoal();
	//其他
	CString snapshot_aseApp;
	CString snapshot_saveAs;
	CString snapshot_path;
};
