#pragma once
#include "global.h"
struct MyView;
struct GameInput;
class Entity;
//前置声明
struct CmdTextFormat;
//游戏文本框
class GameMsgbox
{
public:
	virtual ~GameMsgbox();
	void Init(MyDX11Renderer* pRenderer, MyView* pView, void* pGameScript, std::weak_ptr<Entity>* mychar_ptr_Player1, std::weak_ptr<Entity>* mychar_ptr_Player2);
	void Step();
	void Draw(float deltaTime);
	void OnResetScale();
	void MSG(const wchar_t* text, int mode);//下方文本框
	void MS2(const wchar_t* text, int mode);//上方隐藏文本框
	void MS3(const wchar_t* text, int mode);//上方文本框
	void AutoMSG(const wchar_t* text, int mode, float entity_y);//上下自动文本框
	void MSS(int speed);
	void TUR(bool tur);
	void NOD();
	void CAT(const wchar_t* text, int mode);
	void CLR();
	void CLO();
	void FAC(std::wstring faceID);
	void FNT(const wchar_t* fontFamily);
	void FCL(BYTE r, BYTE g, BYTE b, BYTE a);
	void FSZ();
	void FSZ(int fontSize);
	void STY(const wchar_t* msgboxStyle);
	void EndEvent();
	void YNJ();
	void JNYSetYesNo(bool bYes);
	void YNJEnd();
	const wchar_t* GetMsgBoxStyle();
	void SetSideMode(int sideMode);
private:
	MyDX11Renderer* pRenderer = nullptr;
	MyView* pView = nullptr;
	void* pGameScript = nullptr;
	std::weak_ptr<Entity>* mychar_ptr_Player1 = nullptr;
	std::weak_ptr<Entity>* mychar_ptr_Player2 = nullptr;
	bool bShow = false;//是否显示消息盒和文本
	bool bShowYNJ = true;//是否显示选择框
	bool bYesNo = true;//YNJ选择默认Yes
	//消息盒
	std::wstring msgbox_now;
	int msgbox_mode = 0;//0下方 1上方 2上方隐藏
	float msgbox_x = 0, msgbox_y = 0;
	int msgbox_count_w = 24;
	int msgbox_count_h = 5;
	float face_offx = 0;
	//文本显示
	MyTextureAndSRV textBuffer1;//文字显示缓冲区
	ID3D11RenderTargetView* pRTV_textBuffer1 = nullptr;
	float text_cursorX1 = 0, text_cursorY1 = 0;//文本输出坐标
	MyTextureAndSRV textBuffer2;//文字显示缓冲区
	ID3D11RenderTargetView* pRTV_textBuffer2 = nullptr;
	float text_cursorX2 = 0, text_cursorY2 = 0;//文本输出坐标
	bool bufferSwitch = false;//缓冲区切换显示
	bool bufferOutSwitch = false;//输出缓冲区切换显示
	int text_interval = 5;//文字显示间隔
	int text_interval_counter = 0;//文字显示计时器
	int text_lineheight;//行高
	bool text_rolling = false;//文本是否在滚动
	int text_rolling_speed = 0;//文本滚动速度
	int text_rolling_counter = 0;//文本滚动计时器
	float dst_drawbuffer1_y_set = 0;//文本缓冲区1绘制y坐标
	float dst_drawbuffer1_y_set_last = 0;//文本缓冲区1绘制y坐标
	float dst_drawbuffer2_y_set = 0;//文本缓冲区2绘制y坐标
	float dst_drawbuffer2_y_set_last = 0;//文本缓冲区2绘制y坐标
	bool text_tur = false;
	bool text_tur_temp = false;
	//光标
	int text_nod_linecounter = 0;
	int text_nod_counter = 0;
	int text_nod_counter_max = 30;
	//字体
	std::wstring text_fontFamily_default;
	std::wstring text_fontFamily = text_fontFamily_default;//字体名称
	int text_fontSize, text_fontSize_default;//字体大小
	SDL_Color text_color_default;
	SDL_Color text_color;//字体颜色
	//文本
	std::wstring msg;//待输出的文本
	int msg_index = 0;//文本下标
	std::unordered_map<int, CmdTextFormat> msg_format;
	//头像
	std::wstring face_id;//正在显示的面孔ID
	float face_counter_set = 0;
	float face_counter_set_last = 0;
	//其他
	std::vector<char> utf8;
	void DrawFrame();//绘制文本框框架
	void DrawMsgboxText(float deltaTime);//绘制文字
	void DrawCursor();//绘制光标
	void DrawFace(float deltaTime);//绘制头像
	void RenderText();
	void ClearText();
	//文本声音
	std::wstring text_soundName = L"MSGNormal";
	bool scaleChanging = false;
	//特殊
	int sideMode = 0;//物品栏特殊的两侧文本显示模式（文本框贴-1左侧、1文本框贴右侧）
	int CalcSpaceNum(const wchar_t* text, int mode);
};
//文本颜色
struct CmdTextFormat
{
	SDL_Color text_color;
	int text_fontSize;
	std::wstring text_fontFamily;
};
