#pragma once
#include "global.h"
#include "CMyListBox.h"
#include "CPidEditorDraw.h"
#include "CPidEditorBrush.h"
#include "CAniEditor.h"
#define CPIDEDITOR_MENUINDEX_FILE 0
#define CPIDEDITOR_MENUINDEX_EDIT 1
#define CPIDEDITOR_MENUINDEX_OPTION 2
#define CPIDEDITOR_MENUINDEX_WINDOW 3
#define CPIDEDITOR_DATATYPE_PID_STR "std::unordered_map<int, MyRect>"
#define CPIDEDITOR_DATATYPE_PID std::unordered_map<int, MyRect>
//Pid编辑器
class CPidEditor : public CDialog
{
	DECLARE_DYNAMIC(CPidEditor)
	DECLARE_MESSAGE_MAP()
public:
	CPidEditor(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CPidEditor();
	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_CPIDEDITOR };
#endif
	void* pMainEditor = nullptr;
	//变量
	bool showGrid = false;//显示网格
	bool showBk = false;//显示透明背景
	bool showID = false;//显示id
	//图像输出比例
	int pid_tile_w = 16;
	int pid_tile_h = 16;
	bool bInterArea = false;//是否是线性采样
	int lineShow = 16;//每行显示数量
	void Draw();//绘制
	void Load(CString filename);//载入文件
	void Save();//保存
	bool Close();
	CPIDEDITOR_DATATYPE_PID* GetStep();
	void UpdateMenuState();//更新菜单状态
	void UpdateWindowTitle();//更新窗口标题
	bool CheckSaved();
	bool IsLoaded();
	void ResetContext();
	CString GetPngFile();
	MyUndoRedo* GetMyUndoRedo();
	void XMLLoad(CString xml);
	CString XMLSaved();
	CString GetPidFile();
	void SetAni(int id);//设置动画矩形
	void AniIDSetRect(int id, MyRect* rc);
	bool IsBrushWndShow();
	bool IsAniWndShow();
	////////////////////热键//////////////////
	HACCEL hAccel = nullptr;//热键
	BOOL PreTranslateMessage(MSG* pMsg) override;
protected:
	void DoDataExchange(CDataExchange* pDX) override;
	BOOL OnInitDialog() override;
	void OnCancel() override;
	void OnEnterKey();//空函数 阻止回车键退出
public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnEditPid();
	afx_msg void OnEditPng();
	afx_msg void OnOpenFolder();
	afx_msg void OnUpdateList();
	afx_msg void OnOpenFile();
	afx_msg void OnSaveFile();
	afx_msg void OnCloseFile();
	afx_msg void OnUndo();
	afx_msg void OnRedo();
	afx_msg void OnCopy();
	afx_msg void OnPaste();
	afx_msg void OnCut();
	afx_msg void OnShowBk();
	afx_msg void OnShowGrid();
	afx_msg void OnGridSetting();
	afx_msg void OnShowId();
	afx_msg void OnBrushWnd();
	afx_msg void OnAniEditor();
	afx_msg void OnResetWndPos();
	afx_msg void OnLbnDblclkListPnglist();
	afx_msg void OnSwitchLanguage();
	afx_msg void OnPidShowUsing();
	afx_msg void OnNextframe();
	afx_msg void OnPrevframe();
private:
	//控件
	CStatic* static_pngList;
	CMyListBox listbox_pngList;
	CStatic* static_idEditor;
	//子窗口
	CPidEditorDraw pDrawWnd;
	CPidEditorBrush pBrushWnd;
	CAniEditor pAniWnd;
	//变量
	CString pngfile;
	CString pidfile;
	int pid_tile_w_saved = 16;
	int pid_tile_h_saved = 16;
	bool bInterArea_saved = false;//是否是线性采样
	int lineShow_saved = 16;//每行显示数量
	//撤销和重做功能
	MyUndoRedo undoRedo;
	CPIDEDITOR_DATATYPE_PID saved;

	//复制粘贴功能
	MyRect rcCopy;
	void StepCopyToSaved();
	//语言目录
	CString languageSel;
};

