#pragma once
#include "global.h"
//前置声明
struct MyFPS;
struct MyView;
struct InputSetting_Keyboard;
struct InputSetting_Joystick;
struct GameFunc;
struct PlayerUIData;
class MyGame;
class Entity;
class EntityRes;
class GameMap;
class GameScript;
class GameUI;
class OrganyaPlayer;
class DmgNum;
class ScriptCmd;
class SlotDrawer;
class GameFlash;
struct MapLayer;
void MyCreateSDLWindow(SDL_Window** outSDL_Window, HWND* outHwnd);
void SystemTask();
MyTextureAndSRV* GetPxaTexture(const wchar_t* pxaName);
MyTextureAndSRV* GetPxaTextureInterArea(const wchar_t* pxaName, float scaleW, float scaleH);
MyTextureAndSRV* GetPidTexture(const wchar_t* pidName);
MyTextureAndSRV* GetPidTextureInterArea(const wchar_t* pidName, float scaleW, float scaleH);
MyTextureAndSRV* GetMsgboxTexture(const wchar_t* msgboxName);
MyTextureAndSRV* GetFaceTexture(const wchar_t* faceName);
MyTextureAndSRV* GetFaceTextureInterArea(const wchar_t* faceName, float scaleW, float scaleH);
MyTextureAndSRV* GetSysTexture(const wchar_t* sysName);
MyTextureAndSRV* GetMcuiTexture(const wchar_t* mcuiName);
MyTextureAndSRV* GetResTexture(UINT resID);
Mix_Chunk* GetSoundByName(const wchar_t* soundName);//取需要的声音
void* GetDrumByIndex(int drumIndex);//取鼓
void InitGameFunc(GameFunc* gameFunc);
void SwitchEnglishInput();
void ClearTexture(std::unordered_map<std::wstring, MyTextureAndSRV>* textureRes);
/*-----------------------------GameFunc----------------------------------------*/
void PlaySound(const wchar_t* soundName);//播放wav声音
int PlayLoopSound(const wchar_t* soundName);//播放循环声音
void StopLoopSound(int channelID);//停止循环声音
bool GetFullScreen();//是否全屏
void SetFullScreen(bool bFullScreen);//设置显示全屏
bool GetShowDebug();//是否显示调试信息
void SetShowDebug(bool bShowDebug);//设置显示调试信息
void EnlargeWindow();//放大窗口
void ReduceWindow();//缩小窗口
int GetMusicVolume();//取音乐音量[0-10]
void SetMusicVolume(int vol);//设置音乐音量
int GetSoundVolume();//取音效音量[0-10]
void SetSoundVolume(int vol);//设置音效音量
void OpenGameController();//重新打开所有链接的手柄设备
void GetScanCodeName(std::vector<wchar_t>* outName, SDL_Scancode key);//取键盘扫描码名
void GetGameControllerKeyName(std::vector<wchar_t>* outName, SDL_GameControllerButtonBind* keyBind);//取手柄键绑定名
void GetGameControllerName(std::vector<wchar_t>* outName, SDL_GameController* pGameController);//取手柄设备名
void ResetKeyboard();//重置键盘状态
bool GetAnyKeyPress(SDL_Scancode* outKey);//取键盘上任意按键
bool GetAnyGameControllerKeyPress(SDL_GameController* pGameController, SDL_GameControllerButtonBind* keyBind);//取手柄上任意按键
bool GetKey(SDL_Scancode key);//取键盘扫描码是否按下
void ResetKeySetting_Player1Keyboard();//重置玩家1所有键盘按键设置
void ResetKeySetting_Player1Joystick();//重置玩家1所有手柄按键设置
void ResetKeySetting_Player2Keyboard();//重置玩家2所有键盘按键设置
void ResetKeySetting_Player2Joystick();//重置玩家2所有手柄按键设置
InputSetting_Keyboard* GetInputSetting_Player1Keyboard();//取玩家1按键设置
InputSetting_Joystick* GetInputSetting_Player1Joystick();//取玩家1手柄设置
InputSetting_Keyboard* GetInputSetting_Player2Keyboard();//取玩家2按键设置
InputSetting_Joystick* GetInputSetting_Player2Joystick();//取玩家2手柄设置
SDL_GameController* GetGameControllerFromIndex(int index);//从连接下标取手柄设备
int GetPlayer1ControllerType();//取玩家1控制器类型
int GetPlayer2ControllerType();//取玩家2控制器类型
void SetPlayer1ControllerType(int type);//设置玩家1控制器类型
void SetPlayer2ControllerType(int type);//设置玩家2控制器类型
void LoadConfig();//载入游戏选项配置
void SaveConfig();//保存游戏选项配置
std::weak_ptr<Entity> GetMyChar_Player1(EntityRes* entityRes);//取玩家1实体
std::weak_ptr<Entity> GetMyChar_Player1_menuKeyboard(EntityRes* entityRes);//取玩家1的菜单键盘实体
std::weak_ptr<Entity> GetMyChar_Player2(EntityRes* entityRes);//取玩家2实体
std::weak_ptr<Entity> GetMyChar_Player2_menuKeyboard(EntityRes* entityRes);//取玩家2的菜单键盘实体
MapLayer* GetMapLayer(GameMap* gameMap, const wchar_t* layerName);//取地图图层
void GetMapSize(GameMap* gameMap, int* outMapW, int* outMapH);//取房间尺寸
void SetNewNameOption(const wchar_t* gameName, int playerNum, int difficulty);//设置新游戏参数
void SetSaveName(const wchar_t* saveName);//设置当前存档文件名
void DelSave(const wchar_t* saveName);//删除存档
void SaveNameGetRoomName(std::wstring* outRoomName, const wchar_t* saveName);//存档取房间名
int SaveNameGetGameDifficulty(const wchar_t* saveName);//存档取游戏难度
void WriteData(const wchar_t* eid, const wchar_t* field, const wchar_t* value);//写入数据
const wchar_t* ReadData(const wchar_t* eid, const wchar_t* field, const wchar_t* defaultVal);//读取数据
void SetPauseMenuBackGame(bool bBack);//暂停菜单返回游戏
void SetPauseMenuBackTitle(bool bBack);//暂停菜单返回标题画面
void SetDmgNum(DmgNum* dmgNum, int val, float x, float y, int style, std::weak_ptr<Entity> e);//设置一个伤害数值显示
void SetEntity(std::shared_ptr<Entity> parent, std::shared_ptr<Entity> newE);//放置一个实体
void StartEvent(GameScript* gameScript, const wchar_t* eventName, const wchar_t* triggerType);//启动事件
bool IsLockKeyboard(GameScript* gameScript);//键盘是否锁定
bool ScriptIsRunning(GameScript* gameScript);//是否正在运行事件
PlayerUIData* GetPlayerUIData(GameUI* gameUI, int playerIndex);//取玩家UI显示数据
void StopMusic();//立即停止音乐
void ScreenShot();//取截图
void QuitGame();//退出游戏
const wchar_t* GetLanguage();//取游戏的语言设置
void SetLanguage(const wchar_t* lang);//设置语言
void GetAllLanguage(std::vector<std::wstring>* languageList);//取所有的语言
void ReloadLanguage();//生效语言设置
void SetLastPlaySlot(int slotPage, int index);//设置最后游玩的存档位置
void GetLastPlaySlot(int* outSlotPage, int* outIndex);//取最后游玩的存档位置
void SetMyChar_Player1(MyGame* game, std::weak_ptr<Entity> e);//设置玩家1的控制实体
void SetMyChar_Player2(MyGame* game, std::weak_ptr<Entity> e);//设置玩家2的控制实体
void SetGlobalEntity(MyGame* game, std::shared_ptr<Entity> e, const wchar_t* globalEntityID);//将实体设置到全局运行
std::weak_ptr<Entity> GetGlobalEntity(MyGame* game, const wchar_t* globalEntityID);//取出全局实体指针
std::unordered_map<std::wstring, std::weak_ptr<Entity>>* GetGlobalEntityTable(MyGame* game);//取全局实体指针表
int GetPlayerIndex(MyGame* game, std::weak_ptr<Entity> e);//取当前实体的玩家下标
std::weak_ptr<Entity> GetPlayerDistance(MyGame* game, float x, float y);//取离该点最近的玩家
std::weak_ptr<Entity>GetPlayerDistanceLR(MyGame* game, float x, float y, int lr);//取离该点一侧最近的玩家
std::weak_ptr<Entity>GetPlayerDistanceWithLineTest(MyGame* game, float x, float y);//取离该点最近的可以直接射击的玩家
std::weak_ptr<Entity>GetPlayerDistanceLRWithLineTest(MyGame* game, float x, float y, int lr);//取离该点一侧最近的可以直接射击的玩家
void SetQuake(MyGame* game, int times, int mode);//mode:0小抖动、1大抖动
void SetLocalCamera(MyGame* game, std::weak_ptr<Entity> e, float focusTimes);//设置相机聚焦到这个单位
void UnsetLocalCamera(MyGame* game, std::weak_ptr<Entity> e);//取消该单位的聚焦
bool InBossFight(MyGame* game);//是否在Boss战中
std::weak_ptr<Entity> GetCheckEventPlayer(MyGame* game);//取最后一次正在调查事件的玩家
int PlayerHaveItem(MyGame* game, const wchar_t* regID);//返回玩家拥有某物品的数量
int PlayerAddItem(MyGame* game, const wchar_t* regID, int num);//添加物品，返回该物品总数量
int PlayerDeleteItem(MyGame* game, const wchar_t* regID, int num);//移除物品（-1为移除全部）,返回剩余数量
void DecodeRecord(const wchar_t* recordStr, const void** outInputArr, size_t* outDataSize);//解码操作记录
void SlotPageEnableDraw(SlotDrawer* slotDrawer, bool bEnable);//启用存档页绘制
void SlotPageDrawClear(SlotDrawer* slotDrawer);//清除存档页绘制列表
void SlotPageAddDraw(SlotDrawer* slotDrawer, const wchar_t* saveName, std::weak_ptr<Entity> player1Icon, std::weak_ptr<Entity> player2Icon);//添加要绘制的玩家存档信息到绘制列表
void SlotPageReset(SlotDrawer* slotDrawer);//重置存档页绘制器
void SetScreenFlash(GameFlash* gameFlash, int times);//设置屏幕闪烁
/*-----------------------------------系统----------------------------------*/
void SysKeyBoard();//键盘过程函数
void ResetScale();//scale调整
void ClearDbgFont();
void ClearLoadedTexture();
void ClearLoadedSound();
void DrawDebug(MyGame* pGame);
void MapTest(const wchar_t* mapName, const wchar_t* mycharName, int xPos, int yPos);
void Record(const wchar_t* mapName, const wchar_t* mycharName, int xPos, int yPos, int endPosX, int endPosY);
void IntroStage();
bool TitleStage();
bool GameStage();
bool PauseMenu(float delteTime_MainGame);
void Quit();
void LoadEntityDll();
std::shared_ptr<Entity> GameCreateEntity(const wchar_t* name);
void SplitString(std::vector<std::wstring>* outList, const wchar_t* splitStr, wchar_t delimiter);//拆分字符串
void SaveGameToFile();//保存游戏进度
bool LoadGameFromFile();//读取游戏进度
void GameRestart();//重新载入游戏
void GameBackTitle();//返回标题画面
void LoadSoundTable();
void LoadFontTable();
void LoadFaceTable();
void PlaySoundProc();
void EntityInitCheck(std::shared_ptr<Entity>& we);
void EntitySharedPtrCheck(std::shared_ptr<Entity>& we);
void FreezeGame();
void ActivateGame();
LRESULT CALLBACK SubclassedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern bool bShowDebug;
extern HWND hwnd;
extern TTF_Font* dbgFont;
extern std::vector<std::wstring> cmdList;
extern std::unordered_map<std::wstring, std::unordered_map<std::wstring, std::wstring>> entitySaveVar;//实体数据存档变量
extern InputSetting_Keyboard inputSetting_player1Keyboard;
extern InputSetting_Joystick inputSetting_player1Joystick;
extern InputSetting_Keyboard inputSetting_player2Keyboard;
extern InputSetting_Joystick inputSetting_player2Joystick;
extern int player1ControllerType;//0键盘、1手柄
extern int player2ControllerType;//0键盘、1手柄
extern std::wstring language_now;//当前语言设置
extern std::map<std::wstring, std::wstring> roomNameTable;//翻译好的房间名表
extern std::unordered_map<std::wstring, std::wstring> soundTable;//音效表
extern std::unordered_map<int, std::wstring> drumTable;//鼓表
extern std::string pixelFont_size12;
extern int pixelFont_size12_arg;
extern std::string pixelFont_size14;
extern int pixelFont_size14_arg;
extern std::string highQualityFont;
extern float msgboxTextOffy;
extern std::wstring gameOption_gameName;
extern int gameOption_playerNum;
extern int gameOption_difficulty;
extern MusicPlayer pMusic;
extern OrganyaPlayer orgPlayer;
extern bool gameSpeedX3;//3倍游戏速度
extern bool bLockCamera;//锁住相机镜头
extern ScriptCmd* mainGameCmd;//主游戏脚本指令
extern bool bDisableSound;//只在跳帧时启用
//面孔表
struct FaceDisplayInfo
{
	std::wstring facefile;//面孔在的文件名称
	MyRect src;
};
extern std::unordered_map<std::wstring, bool> facefileTable;
extern std::unordered_map<std::wstring, FaceDisplayInfo> faceIDTable;