diff --git a/desmume/src/windows/hotkey.cpp b/desmume/src/windows/hotkey.cpp index 00cdb49fc..0782b34ad 100644 --- a/desmume/src/windows/hotkey.cpp +++ b/desmume/src/windows/hotkey.cpp @@ -244,6 +244,19 @@ void HK_StopMovie(int) FCEUI_StopMovie(); } +void HK_NewLuaScriptDown(int) +{ + SendMessage(MainWindow->getHWnd(), WM_COMMAND, IDC_NEW_LUA_SCRIPT, 0); +} +void HK_CloseLuaScriptsDown(int) +{ + SendMessage(MainWindow->getHWnd(), WM_COMMAND, IDC_CLOSE_LUA_SCRIPTS, 0); +} +void HK_MostRecentLuaScriptDown(int) +{ + SendMessage(MainWindow->getHWnd(), WM_COMMAND, IDD_LUARECENT_RESERVE_START, 0); +} + void HK_AutoHoldKeyDown(int) {AutoHoldPressed = true;} void HK_AutoHoldKeyUp(int) {AutoHoldPressed = false;} @@ -582,6 +595,24 @@ void InitCustomKeys (SCustomKeys *keys) keys->Rewind.page = HOTKEY_PAGE_MOVIE; keys->Rewind.key = NULL; + keys->NewLuaScript.handleKeyDown = HK_NewLuaScriptDown; + keys->NewLuaScript.code = "NewLuaScript"; + keys->NewLuaScript.name = L"New Lua Window"; + keys->NewLuaScript.page = HOTKEY_PAGE_MOVIE; + keys->NewLuaScript.key = NULL; + + keys->CloseLuaScripts.handleKeyDown = HK_CloseLuaScriptsDown; + keys->CloseLuaScripts.code = "CloseLuaScripts"; + keys->CloseLuaScripts.name = L"Close Lua Windows"; + keys->CloseLuaScripts.page = HOTKEY_PAGE_MOVIE; + keys->CloseLuaScripts.key = NULL; + + keys->MostRecentLuaScript.handleKeyDown = HK_MostRecentLuaScriptDown; + keys->MostRecentLuaScript.code = "MostRecentLuaScript"; + keys->MostRecentLuaScript.name = L"Most Recent Lua Script"; + keys->MostRecentLuaScript.page = HOTKEY_PAGE_MOVIE; + keys->MostRecentLuaScript.key = NULL; + keys->NextSaveSlot.handleKeyDown = HK_NextSaveSlot; keys->NextSaveSlot.code = "NextSaveSlot"; keys->NextSaveSlot.name = L"Next Save Slot"; diff --git a/desmume/src/windows/hotkey.h b/desmume/src/windows/hotkey.h index 490c91bc6..1d2219428 100644 --- a/desmume/src/windows/hotkey.h +++ b/desmume/src/windows/hotkey.h @@ -38,7 +38,7 @@ enum HotkeyPage { static LPCTSTR hotkeyPageTitle[] = { _T("Main"), - _T("Movie"), + _T("Movie / Tools"), _T("Savestates"), _T("Savestate Slots"), _T("Turbo"), @@ -82,6 +82,8 @@ struct SCustomKeys SCustomKey Rewind; + SCustomKey NewLuaScript, CloseLuaScripts, MostRecentLuaScript; + SCustomKey ToggleFrameCounter; SCustomKey ToggleFPS; SCustomKey ToggleInput; diff --git a/desmume/src/windows/luaconsole.cpp b/desmume/src/windows/luaconsole.cpp index 587638009..fc16adeec 100644 --- a/desmume/src/windows/luaconsole.cpp +++ b/desmume/src/windows/luaconsole.cpp @@ -16,10 +16,9 @@ #include "..\lua-engine.h" #define MAX_RECENT_SCRIPTS 15 +char Recent_Scripts[MAX_RECENT_SCRIPTS][1024] = {0}; -static char Str_Tmp [1024]; // shadow added because the global one is completely unreliable - -char Recent_Scripts[MAX_RECENT_SCRIPTS][1024]; +static char Str_Tmp [1024]; struct ControlLayoutInfo { @@ -141,7 +140,7 @@ void KillWatcherThread (HWND hDlg) // some extensions that might commonly be near lua files that almost certainly aren't lua files. -static const char* s_nonLuaExtensions [] = {"txt", "nfo", "htm", "html", "jpg", "jpeg", "png", "bmp", "gif", "mp3", "wav", "lnk", "exe", "bat", "gmv", "gm2", "luasav", "sav", "srm", "brm", "cfg", "wch", "gs*", "bin","smd","gen","32x","cue","iso","raw"}; +static const char* s_nonLuaExtensions [] = {"txt", "nfo", "htm", "html", "jpg", "jpeg", "png", "bmp", "gif", "mp3", "wav", "lnk", "exe", "bat", "luasav", "sav", "srm", "brm", "cfg", "wch", "ds*", "nds","bin","raw"}; void Update_Recent_Script(const char* Path, bool dontPutAtTop) diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index b620ddef7..61e2f4e68 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -222,6 +222,9 @@ static bool FrameLimit = true; std::vector LuaScriptHWnds; LRESULT CALLBACK LuaScriptProc(HWND, UINT, WPARAM, LPARAM); +#define MAX_RECENT_SCRIPTS 15 // must match value in luaconsole.cpp (belongs in a header, but I didn't want to create one just for this) +extern char Recent_Scripts[MAX_RECENT_SCRIPTS][1024]; + //=========================== view tools TOOLSCLASS *ViewDisasm_ARM7 = NULL; TOOLSCLASS *ViewDisasm_ARM9 = NULL; @@ -704,6 +707,82 @@ void ClearRecentRoms() UpdateRecentRomsMenu(); } +static HMENU GetMenuItemParent(UINT itemId, HMENU hMenu = mainMenu) +{ + MENUITEMINFO moo = {sizeof(MENUITEMINFO)}; + if(!GetMenuItemInfo(hMenu, itemId, FALSE, &moo)) + return NULL; + int nItems = GetMenuItemCount(hMenu); + for(int i = 0; i < nItems; i++) + { + MENUITEMINFO mii = {sizeof(MENUITEMINFO), MIIM_SUBMENU | MIIM_ID}; + GetMenuItemInfo(hMenu, i, TRUE, &mii); + if(mii.wID == itemId) + return hMenu; + if(mii.hSubMenu) + if(HMENU innerResult = GetMenuItemParent(itemId, mii.hSubMenu)) + return innerResult; + } + return NULL; +} + +static void PopulateLuaSubmenu() +{ + static HMENU luasubmenu = GetMenuItemParent(IDC_NEW_LUA_SCRIPT); + static int luasubmenuOriginalSize = GetMenuItemCount(luasubmenu); + + // delete any previously-dynamically-added menu items + int i = luasubmenuOriginalSize; + while(GetMenuItemCount(luasubmenu) > i) + DeleteMenu(luasubmenu, i, MF_BYPOSITION); + + // add menu items for currently-open scripts + char Str_Tmp [1024]; + int Flags = MF_BYPOSITION | MF_STRING; + if(!LuaScriptHWnds.empty()) + { + InsertMenu(luasubmenu, i++, MF_SEPARATOR, NULL, NULL); + for(unsigned int j = 0; j < LuaScriptHWnds.size(); j++) + { + GetWindowText(LuaScriptHWnds[j], Str_Tmp, 1024); + InsertMenu(luasubmenu, i++, MF_BYPOSITION | MF_STRING, IDC_LUASCRIPT_RESERVE_START+j, Str_Tmp); + } + } + + // add menu items for recently-opened-but-not-currently-open scripts + int dividerI = i; + for(unsigned int j = 0; j < MAX_RECENT_SCRIPTS; j++) + { + const char* pathPtr = Recent_Scripts[j]; + if(!*pathPtr) + continue; + + HWND IsScriptFileOpen(const char* Path); + if(IsScriptFileOpen(pathPtr)) + continue; + + // only show some of the path + const char* pathPtrSearch; + int slashesLeft = 2; + for(pathPtrSearch = pathPtr + strlen(pathPtr) - 1; + pathPtrSearch != pathPtr && slashesLeft >= 0; + pathPtrSearch--) + { + char c = *pathPtrSearch; + if(c == '\\' || c == '/') + slashesLeft--; + } + if(slashesLeft < 0) + pathPtr = pathPtrSearch + 2; + strcpy(Str_Tmp, pathPtr); + + if(i == dividerI) + InsertMenu(luasubmenu, i++, MF_SEPARATOR, NULL, NULL); + + InsertMenu(luasubmenu, i++, MF_BYPOSITION | MF_STRING, IDD_LUARECENT_RESERVE_START+j, Str_Tmp); + } +} + int CreateDDrawBuffers() @@ -1869,6 +1948,15 @@ int _main() GetPrivateProfileString("Watches", str, "", &rw_recent_files[i][0], 1024, IniName); } + + for(int i = 0; i < MAX_RECENT_SCRIPTS; i++) + { + char str[256]; + sprintf(str, "Recent Lua Script %d", i+1); + GetPrivateProfileString("Scripting", str, "", &Recent_Scripts[i][0], 1024, IniName); + } + + //i think we should override the ini file with anything from the commandline CommandLine cmdline; cmdline.loadCommonOptions(); @@ -3027,6 +3115,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM MainWindow->checkMenu(savelist[i], false); MainWindow->checkMenu(savelist[CommonSettings.manualBackupType], true); + // recent/active scripts menu + PopulateLuaSubmenu(); return 0; } @@ -3082,7 +3172,16 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM sprintf(str, "Recent Watch %d", i+1); WritePrivateProfileString("Watches", str, &rw_recent_files[i][0], IniName); } - + + + for(int i = 0; i < MAX_RECENT_SCRIPTS; i++) + { + char str[256]; + sprintf(str, "Recent Lua Script %d", i+1); + WritePrivateProfileString("Scripting", str, &Recent_Scripts[i][0], IniName); + } + + ExitRunLoop(); } else @@ -3390,6 +3489,31 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM ClearRecentRoms(); } + if(wParam >= IDD_LUARECENT_RESERVE_START && + wParam <= IDD_LUARECENT_RESERVE_END && + wParam - IDD_LUARECENT_RESERVE_START < MAX_RECENT_SCRIPTS) + { + if(LuaScriptHWnds.size() < 16) + { + char temp [1024]; + strcpy(temp, Recent_Scripts[wParam - IDD_LUARECENT_RESERVE_START]); + HWND IsScriptFileOpen(const char* Path); + if(!IsScriptFileOpen(temp)) + { + HWND hDlg = CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc); + SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); + } + } + } + + if(wParam >= IDC_LUASCRIPT_RESERVE_START && + wParam <= IDC_LUASCRIPT_RESERVE_END) + { + unsigned int index = wParam - IDC_LUASCRIPT_RESERVE_START; + if(LuaScriptHWnds.size() > index) + SetForegroundWindow(LuaScriptHWnds[index]); + } + } switch(LOWORD(wParam)) { @@ -4005,13 +4129,14 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM } } return 0; - case IDC_NEW_LUA_SCRIPT: - if(LuaScriptHWnds.size() < 16) - { - CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc); - // DialogsOpen++; - } - break; + case IDC_NEW_LUA_SCRIPT: + if(LuaScriptHWnds.size() < 16) + CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc); + break; + case IDC_CLOSE_LUA_SCRIPTS: + for(int i=(int)LuaScriptHWnds.size()-1; i>=0; i--) + SendMessage(LuaScriptHWnds[i], WM_CLOSE, 0,0); + break; case IDC_LANGENGLISH: SaveLanguage(0); ChangeLanguage(0); @@ -4974,7 +5099,6 @@ const char* OpenLuaScript(const char* filename, const char* extraDirToCheck, boo HWND hDlg = CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc); SendMessage(hDlg,WM_COMMAND,IDC_NOTIFY_SUBSERVIENT,TRUE); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)filename); -// DialogsOpen++; SetActiveWindow(prevWindow); } diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 29884cbf6..4583e01f1 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -138,6 +138,7 @@ #define IDC_BROWSELUA 365 #define IDD_PATHSETTINGS 366 #define IDC_STATEREWINDING 367 +#define IDC_CLOSE_LUA_SCRIPTS 368 #define IDC_DES_BOX 402 #define IDC_R0 403 #define IDC_R1 404 @@ -760,6 +761,10 @@ #define IDC_LABEL_BLUE 50036 #define IDC_LID 50037 #define IDD_INPUTCONFIG 50038 +#define IDC_LUASCRIPT_RESERVE_START 58000 +#define IDC_LUASCRIPT_RESERVE_END 58099 +#define IDD_LUARECENT_RESERVE_START 58100 +#define IDD_LUARECENT_RESERVE_END 58199 #define IDC_LABEL_HK1 60001 #define IDC_LABEL_HK2 60002 #define IDC_LABEL_HK3 60003 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 21cdd34c0..4089fe3c1 100644 Binary files a/desmume/src/windows/resources.rc and b/desmume/src/windows/resources.rc differ