diff --git a/Modules/EC_Controller/Lua/ECC_Menu.lua b/Modules/EC_Controller/Lua/ECC_Menu.lua index f219252..5a22372 100644 --- a/Modules/EC_Controller/Lua/ECC_Menu.lua +++ b/Modules/EC_Controller/Lua/ECC_Menu.lua @@ -39,18 +39,18 @@ MENU INITALIZATION AND CLEANUP ]] --[[ Variables for FFI ]] -local Menu_ID = nil local Menu_Pointer = ECC_ffi.new("const char") --[[ Menu initialization ]] function ECC_Menu_Init() if ECC_XPLM ~= nil then - Menu_ID = ECC_XPLM.XPLMCreateMenu(Menu_Name,nil,0, function(inMenuRef,inItemRef) Menu_Callback(inItemRef) end,ECC_ffi.cast("void *",Menu_Pointer)) + ECC_Menu_Index = ECC_XPLM.XPLMAppendMenuItem(ECC_XPLM.XPLMFindPluginsMenu(),Menu_Name,ECC_ffi.cast("void *","None"),1) + ECC_Menu_ID = ECC_XPLM.XPLMCreateMenu(Menu_Name,ECC_XPLM.XPLMFindPluginsMenu(),ECC_Menu_Index, function(inMenuRef,inItemRef) Menu_Callback(inItemRef) end,ECC_ffi.cast("void *",Menu_Pointer)) for i=1,#Menu_Items do if Menu_Items[i] ~= "[Separator]" then Menu_Pointer = Menu_Items[i] - Menu_Indices[i] = ECC_XPLM.XPLMAppendMenuItem(Menu_ID,Menu_Items[i],ECC_ffi.cast("void *",Menu_Pointer),1) + Menu_Indices[i] = ECC_XPLM.XPLMAppendMenuItem(ECC_Menu_ID,Menu_Items[i],ECC_ffi.cast("void *",Menu_Pointer),1) else - ECC_XPLM.XPLMAppendMenuSeparator(Menu_ID) + ECC_XPLM.XPLMAppendMenuSeparator(ECC_Menu_ID) end end ECC_Menu_Watchdog(1) -- Watchdog for menu item 1 @@ -60,8 +60,7 @@ function ECC_Menu_Init() end --[[ Menu cleanup upon script reload or session exit ]] function ECC_Menu_CleanUp() - ECC_XPLM.XPLMClearAllMenuItems(ECC_XPLM.XPLMFindPluginsMenu()) - --ECC_XPLM.XPLMDestroyMenu(Menu_ID) + ECC_XPLM.XPLMRemoveMenuItem(ECC_XPLM.XPLMFindPluginsMenu(),ECC_Menu_Index) end --[[ @@ -70,16 +69,16 @@ MENU MANIPULATION WRAPPERS ]] --[[ Menu item name change ]] local function ECC_Menu_ChangeItemPrefix(index,prefix) - ECC_XPLM.XPLMSetMenuItemName(Menu_ID,index-1,prefix.." "..Menu_Items[index],1) + ECC_XPLM.XPLMSetMenuItemName(ECC_Menu_ID,index-1,prefix.." "..Menu_Items[index],1) end --[[ Menu item check status change ]] function ECC_Menu_CheckItem(index,state) index = index - 1 local out = ECC_ffi.new("XPLMMenuCheck[1]") - ECC_XPLM.XPLMCheckMenuItemState(Menu_ID,index-1,ECC_ffi.cast("XPLMMenuCheck *",out)) - if tonumber(out[0]) == 0 then ECC_XPLM.XPLMCheckMenuItem(Menu_ID,index,1) end - if state == "Activate" and tonumber(out[0]) ~= 2 then ECC_XPLM.XPLMCheckMenuItem(Menu_ID,index,2) - elseif state == "Deactivate" and tonumber(out[0]) ~= 1 then ECC_XPLM.XPLMCheckMenuItem(Menu_ID,index,1) + ECC_XPLM.XPLMCheckMenuItemState(ECC_Menu_ID,index-1,ECC_ffi.cast("XPLMMenuCheck *",out)) + if tonumber(out[0]) == 0 then ECC_XPLM.XPLMCheckMenuItem(ECC_Menu_ID,index,1) end + if state == "Activate" and tonumber(out[0]) ~= 2 then ECC_XPLM.XPLMCheckMenuItem(ECC_Menu_ID,index,2) + elseif state == "Deactivate" and tonumber(out[0]) ~= 1 then ECC_XPLM.XPLMCheckMenuItem(ECC_Menu_ID,index,1) end end --[[ Watchdog to track window state changes ]] @@ -93,4 +92,3 @@ function ECC_Menu_Watchdog(index) elseif ECC_SettingsValGet("AutoLoad") == 1 then ECC_Menu_CheckItem(index,"Activate") end end end - diff --git a/README.md b/README.md index 77a916a..61edaff 100755 --- a/README.md +++ b/README.md @@ -181,11 +181,11 @@ The path to the settings file is: `FlyWithLua/Modules/EC_Controller/UI_Prefs.cfg ## 6 - Known issues +- If you reload all FlyWithLua scripts, an empty "Enhanced Cloudscapes" menu may be left over in the plugins menu or the "FlyWithLua" menu may disappear. In both cases, restart X-Plane. - Altering a plugin parameter and reloading the Lua script will set that parameter as default. Workaround: Restart X-Plane so that the plugin will be reset - Input boxes will not let go of focus upon pressing "Enter". This is an Imgui limitation. Click anywhere into the window (except for another input field) to unfocus. -- The main _"Enhanced Cloudscapes"_ menu item in the "Plugins" menu will not be removed if you reload all Lua script files in FlyWithLua. [Back to table of contents](#toc) diff --git a/Scripts/EC_Controller.lua b/Scripts/EC_Controller.lua index 8460015..a071bfd 100644 --- a/Scripts/EC_Controller.lua +++ b/Scripts/EC_Controller.lua @@ -38,6 +38,8 @@ local ECC_PageInitStatus = 0 -- Has the window been initialized? ECC_Check_Autoload = false -- Enables check of the autoloading condition ECC_Window_Pos={0,0} -- Window position x,y ECC_ImguiColors={0x33FFAE00,0xBBFFAE00,0xFFC8C8C8,0xFF0000FF,0xFF19CF17,0xFFB6CDBA,0xFF40aee5} -- Imgui: Control elements passive, control elements active, text, negative, positive, neutral, caution +ECC_Menu_ID = nil -- ID of the main ECC menu +ECC_Menu_Index = nil -- Index of the ECC menu in the plugins menu --[[ INITIALIZATION