#pragma once
#include "global.h"
#include "MyStructDef.h"
#include "CMCEditor.h"
#include "CWorldEditor.h"
#include "CPidEditor.h"
#include "CPxaEditor.h"
#include "CMapEditor.h"
#define CMAINEDITOR_MENUINDEX_FILE 0
#define CMAINEDITOR_MENUINDEX_OPTION 1
#define CMAINEDITOR_MENUINDEX_STORYEDITOR 2
#define CMAINEDITOR_MENUINDEX_GAMEEDITOR 3
#define MAINEDITOR_WIDTH 1251
#define MAINEDITOR_HEIGHT 942
//数据库定义的系统表名
#define DBTABLENAME_INFO L"ocsys_info"
#define DBTABLENAME_OPTION L"ocsys_option"
#define DBTABLENAME_CALENDAR L"ocsys_calendar"
#define DBTABLENAME_MYCHAR_POSITION L"ocsys_mcpos"
#define DBTABLENAME_MYCHAR_CHARACTER L"ocsys_mcchar"
#define DBTABLENAME_MYCHARACTER L"ocsys_mycharacter"
#define DBTABLENAME_WORLDSET L"ocsys_worldset"
#define DBTABLENAME_SPORTBODY L"ocsys_sportbody"
//特殊文件名
#define NULLFACE L"null_face.png"
class CMainEditor : public CDialog
{
	DECLARE_DYNAMIC(CMainEditor)
	DECLARE_MESSAGE_MAP()
public:
	CMainEditor(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CMainEditor();
	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_CMAINEDITOR };
#endif
	static void CloseDB(sqlite3* db);//关闭数据库
	sqlite3* OpenDB();//打开数据库
	CString GetDBFieldValue(CString table, CString field, CString field_val, CString value);//取某个表中某个字段的值
	void SetDBFieldValue(CString table, CString field, CString field_val, CString value, CString value_val);//设置某个表中某个字段的值
	void DelDBField(CString table, CString field, CString field_val);//删除某个表中某个字段的值
	void SetDBField(CString table, CString field, CString field_val, CString field_val_new);//设置某个表中某个字段的值
	void GetDBField_List(std::vector<CString>* outList, CString table, CString field);//取某个表某个字段所有的数据
	int GetDBTabelCount(CString table);//取某个表的数据数量
	void GetDBMyCharacter_List(std::vector<MyCharacterInfo>* outList);//取DBTABLENAME_MYCHARACTER表的所有数据
	bool GetDBTableExist(CString table);//检查某个表是否存在
	CString GetDBWorldSet();//取worldset表的xml数据
	void SetDBWorldSet(CString xml);//设置world表的xml数据
	static void GetXMLLabel_Map(std::unordered_map<std::wstring, MyLabelXML>* outMap, CString xml);//读取设定实现表的xml，返回设定表
	static CString GetXMLString(std::unordered_map<std::wstring, MyLabelXML>& xmlMap);//设定表输出xml字符串
	void UpdateWindowTitle();//更新窗口标题
	void UpdateDisplayDiary();
	void Draw();//绘制
	CString GetBasePath();
	void UpdateContext();//更新内容
	CString ImportPNG(CString filepath);//把图像文件导入到本地目录，并返回文件名
	MyDX11Renderer pRenderer;//渲染器
	ID3D11Texture2D* pTextureBk = nullptr;//正在使用的背景贴图
	ID3D11ShaderResourceView* pSRV = nullptr;
	BYTE alpha = 0xff;//背景贴图alpha
	ID3D11Texture2D* pTextureBk_bkup = nullptr;//正在预览的背景贴图
	ID3D11ShaderResourceView* pSRV_bkup = nullptr;
	BYTE alpha_bkup = 0xff;
	CString osName;//仓库名称
	CString osAuthor;//作者名
	CString osFilePath;//数据库文件目录
protected:
	void DoDataExchange(CDataExchange* pDX) override;
	BOOL OnInitDialog() override;
	void Load(CString string);//载入
	void DrawCalendar(float x, float y,int year,int month);//绘制日历
	void UpdateDisplayYear(int year);
public:
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnNewOS();
	afx_msg void OnOpenOs();
	afx_msg void OnCloseOs();
	afx_msg void OnCalentarBk();
	afx_msg void OnOsinfo();
	afx_msg void OnMcEditor();
	afx_msg void OnWorldEditor();
	afx_msg void OnPidEditor();
	afx_msg void OnPxaEditor();
	afx_msg void OnMapEditor();
	afx_msg void OnGameSetting();
	afx_msg void OnBootGame();
	afx_msg void OnYearDown();
	afx_msg void OnYearUp();
private:
	TTF_Font* pFont_sourcesun28 = nullptr;//字体
	std::unordered_map<wchar_t, MyFontData> pFontMap28;
	int yearDisplay;//目前显示的年份
	bool setClickRectArr = false;
	std::vector<MyCalendarClickZone> clickRectArr;
	int dayCount = 0;//制作天数
	UINT_PTR timeId = 0;
	bool sportRemind = false;
	time_t workMinute = 0;
	/*---------------子窗口-----------------*/
	CMCEditor pMCEditor;
	CWorldEditor pWorldEditor;
	CPidEditor pPidEditor;
	CPxaEditor pPxaEditor;
	CMapEditor pMapEditor;
	void LockMenu();//锁定菜单
	void UnlockMenu();//解锁菜单
	void SaveLastFile();//保存最后一次的文件
	void OpenLastFile(CString& str);//打开最后一次的文件
	void InitDBTable();//初始化表
	void SportBody();//运动身体提醒
	////////////////////热键//////////////////
	HACCEL hAccel = nullptr;//热键
	BOOL PreTranslateMessage(MSG* pMsg) override;
};
