Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Fixed FWL script reload menu bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
JT8D-17 committed Aug 19, 2021
1 parent a8762dd commit 8bc9c95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
22 changes: 10 additions & 12 deletions Modules/EC_Controller/Lua/ECC_Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
--[[
Expand All @@ -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 ]]
Expand All @@ -93,4 +92,3 @@ function ECC_Menu_Watchdog(index)
elseif ECC_SettingsValGet("AutoLoad") == 1 then ECC_Menu_CheckItem(index,"Activate") end
end
end

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ The path to the settings file is: `FlyWithLua/Modules/EC_Controller/UI_Prefs.cfg
<a name="issues"></a>
## 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)

Expand Down
2 changes: 2 additions & 0 deletions Scripts/EC_Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bc9c95

Please sign in to comment.