#pragma once
#include "global.h"
#include "CMyTreeCtrl.h"
#include "MyStructDef.h"
#include "CAniEditorDraw.h"
#include "CAniEditorTimeLine.h"
#include "CMyPicButton.h"
#define CANIEDITOR_MENUINDEX_OPTION 0
#define CANIEDITOR_MENUINDEX_EDIT 1
class CAniEditor : public CDialog
{
	DECLARE_DYNAMIC(CAniEditor)
	DECLARE_MESSAGE_MAP()
public:
	CAniEditor(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CAniEditor();
	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_CANIEDITOR };
#endif
	void* pParentEditor = nullptr;
	int* pPid_tile_w = nullptr;
	int* pPid_tile_h = nullptr;
	void Load(CString filename);//载入贴图png文件
	void ResetContext();
	CString XMLSaved();
	void XMLLoad(CString xml);
	bool CheckSaved();
	void StepCopyToSaved();
	void UpdateMenuState();//更新菜单状态
	void UpdateWindowTitle();//更新窗口标题
	void Draw();
	void SetAniID(int id);//设置动画id
	void SetAniFrame(const MyAniFrame* frame);//设置动画frame
	void GetAniFrame(std::list<MyAniFrame>* frameList);//取绘制动画frame
	void GetSelectAniFrame(std::vector<MyAniFrame*>* frameList);//取绘制动画frame
	void GetSelectAniInfo(MyAniSet** as);
	MyUndoRedo* GetMyUndoRedo();
	CANIEDITOR_DATATYPE_ANI* GetStep();
	void AniIDSetRect(int id, MyRect* rc);
	bool IsLoaded();
	std::set<int>* GetHideTable();
	int GetSelectedLayerIndex();
	std::unordered_map<std::wstring, MyAniSet>* GetAniList();
	////////////////////热键//////////////////
	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 OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnAddAni();
	afx_msg void OnPrepAni();
	afx_msg void OnAniop();
	afx_msg void OnCopy();
	afx_msg void OnPaste();
	afx_msg void OnCut();
	afx_msg void OnDeleteAni();
	afx_msg void OnRedo();
	afx_msg void OnSaveFile();
	afx_msg void OnUndo();
	afx_msg void OnBkSetting();
	afx_msg void OnTvnSelchangedTreeAnilist(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg LRESULT OnMyPicButtonLButtonUp(WPARAM wParam, LPARAM lParam);
	afx_msg void OnNextframe();
	afx_msg void OnPrevframe();
	afx_msg void OnOpLayer();
	afx_msg void OnHideTable();
	afx_msg void OnChangeId();
private:
	CString pngfile;
	//控件
	CStatic* static_aniList;
	CMyTreeCtrl tree_aniList;
	CButton button_edit;
	CStatic* static_playView;
	CStatic* static_timeLine;
	//子窗口
	CAniEditorDraw pDrawWnd;
	CAniEditorTimeLine pTimeLineWnd;
	CMyPicButton btn_play, btn_pause, btn_stop, btn_refresh;
	//成员
	std::unordered_map<std::wstring, MyAniSet> anisetList;
	std::unordered_map<std::wstring, MyAniSet> saved;
	CString posCopyXML;//拷贝
	MyAniFrame copyFrame;
	UINT_PTR timeid;//计时器
	bool playing = false;//是否正在播放动画
	int timeCell = 0;
	HTREEITEM lastSelectItem = NULL;
	//显示隐藏表
	CString hideTable;
	CString hideTable_saved;
	std::set<int> hideIDTable;
};

