Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
Trajan von Olb
Posts: 544
Joined: Wed, 4. Feb 04, 21:39
x3tc

Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by Trajan von Olb » Wed, 29. Dec 21, 15:18

Hi,

Ego seems to have changed something in the Lua code for the map menu call, which I call via SirNukes modsupportapi. Since 4.1 or 4.2 e.g. in the called LUA code

Code: Select all

mapMenu = Lib.Get_Egosoft_Menu("MapMenu")
.
.
.
mapMenu.infoTableMode = "propertyowned"
doesn't work anymore... The menu simply does not open. Also

Code: Select all

mapMenu.updateMapAndInfoFrame ()
does not solve the problem, but at least another menu item is opened if the menu is already open.
Curious: with the parameter "mission" the menu opens, but not with other parameters. :gruebel:
Does anyone have an idea what is going wrong? Thank you very much.
Background: In the extension of my "more-Hotkeys"-series I'm trying to reliably jump to different tabs in the map menu with hotkeys or to turn the trade info on and off with hotkeys...
Here is my complete code so far, which still worked under 3.x (probably also 4.0):
Spoiler
Show

Code: Select all

-- ffi setup
local ffi = require("ffi")
local C = ffi.C

local Lib = require("extensions.sn_mod_support_apis.lua_library")
local mapMenu = {}
local mhk_menu = {}
local selectedcomponent = nil

local function init()
    DebugError("More Hotkeys MAM Init")

    mapMenu = Lib.Get_Egosoft_Menu("MapMenu")

    RegisterEvent("MoreHotkeys.openObjectListWithHotkey", mhk_menu.openObjectListWithHotkey)
    RegisterEvent("MoreHotkeys.openPropertyOwnedWithHotkey", mhk_menu.openPropertyOwnedWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionOffersWithHotkey", mhk_menu.openMissionOffersWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMissionManagerWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap1)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap2)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap3)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.closeMap)
end

function mhk_menu.openObjectListWithHotkey(_, event)
    if event == "onPress" then
        mapMenu.infoTableMode = "objectlist"
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.updateMapAndInfoFrame ()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openPropertyOwnedWithHotkey(_, event)
    if event == "onPress" then
        mapMenu.infoTableMode = "propertyowned"
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.updateMapAndInfoFrame ()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openMissionOffersWithHotkey(_, event)
    if event == "onPress" then
        mapMenu.infoTableMode = "missionoffer"
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.updateMapAndInfoFrame ()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openMissionManagerWithHotkey(_, event)
    if event == "onPress" then
		mapMenu.infoTableMode = "mission"
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.updateMapAndInfoFrame ()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openMap1(_, event)
    if event == "onPress" then
		mapMenu.infoTableMode = "info"
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.updateMapAndInfoFrame ()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openMap1(_, event)
    if event == "onPress" then
		mapMenu.infoTableMode = "mission"
		mapMenu.refreshMainFrame = true
		mapMenu.refreshInfoFrame()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.openMap1(_, event)
    if event == "onPress" then
		mapMenu.infoTableMode = "mission"
		mapMenu.refreshMainFrame = true
		mapMenu.refreshInfoFrame()
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

function mhk_menu.closeMap(_, event)
    if event == "onPress" then
		mapMenu.onCloseElement("close")
        OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

init()
Many thanks for answers, I'm just not getting anywhere....

Trajan von Olb
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by kuertee » Wed, 29. Dec 21, 16:04

any errors in the debug log, trajan?
apart from the multiple declarations of the same function, mhk_menu.openMap1 (), i don't see anything wrong with the code.

maybe look at the function, Helper.closeMenuAndOpenNewMenu (), for some clues.
it can be found in "ui\addons\ego_detailmonitorhelper\helper.lua"
it may be good to investigate bits of that file as well, actually.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 544
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by Trajan von Olb » Wed, 29. Dec 21, 22:04

Thank you, that looks interesting. Unfortunately, I'm not that fit in Lua (Forloyer sent me the code back then), so I suspect that I'm basically doing something wrong. Because no matter how I use the helper, there is no additional effect.... Hence the newbie question:
1. how do I call such a function from my code? And how do I pass parameters?
2. do I have to declare something in the Lua code at the beginning? So the function or something?
At the moment it looks like this (no extra entries at the beginning of the code above):

Code: Select all

-- ffi setup
local ffi = require("ffi")
local C = ffi.C

local Lib = require("extensions.sn_mod_support_apis.lua_library")
local mapMenu = {}
local mhk_menu = {}
local selectedcomponent = nil

local function init()
    DebugError("More Hotkeys MAM Init")

    mapMenu = Lib.Get_Egosoft_Menu("MapMenu")

    RegisterEvent("MoreHotkeys.openObjectListWithHotkey", mhk_menu.openObjectListWithHotkey)
    RegisterEvent("MoreHotkeys.openPropertyOwnedWithHotkey", mhk_menu.openPropertyOwnedWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionOffersWithHotkey", mhk_menu.openMissionOffersWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMissionManagerWithHotkey)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap1)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap2)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.openMap3)
    RegisterEvent("MoreHotkeys.openMissionManagerWithHotkey", mhk_menu.closeMap)
end

function mhk_menu.openObjectListWithHotkey(_, event)
    if event == "onPress" then
--		mapMenu.refreshMainFrame = true
--		mapMenu.refreshInfoFrame()
		mapMenu.infoTableMode = "objectlist"
		mapMenu.updateMapAndInfoFrame ()
		Helper.closeMenuAndOpenNewMenu("MapMenu", "MapMenu", { 0, 0 }, nil)
		OpenMenu("MapMenu", { 0, 0 }, nil)
    end
end

.
.
.

init()
Am I doing something wrong?

Thanks for answers.

Trajan
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by kuertee » Thu, 30. Dec 21, 04:30

yeah, that looks about right.

were there no errors in the logs before you changed it?

i noticed that Forleyor updated infocenter on nexus with this change log:
Version 2.8.4
Disabled Hotkey code because its broken in X4 4.20 (I have no idea why it makes Egosofts code fail).
if that's the same problem that you are experiencing, then it's likely unfixable. sorry.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by kuertee » Thu, 30. Dec 21, 09:12

yup, sorry to say it.
opening the map with a specific info panel open with OpenMenu () is unreliable.
i just tried it and, the map menu does open, but always with NO info panel open - except one time and never again.
the only real way to debug this is to step through the mod (e.g. with DebugError ()) and see what needs to be done.
sorrry.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 544
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by Trajan von Olb » Thu, 30. Dec 21, 21:57

Hmmm... That's crazy. How exactly do you make the map menu open at all? Because for me, with the above code, it's exactly the opposite: the map menu does NOT open. IF, however, it is open (e.g. through Egosoft's menu call "Own property", then you can call up the respective info panel with the corresponding code. It is also interesting to note that although the correct info panel opens, the mouse button for the panel does not look like the panel is selected. Maybe this will help: if we find the routine that renders the menu interface, we might find the error...

To "debug": How do I do that? Sure, start the game with "-logfile debuglog.txt" and then work my way through the extremely many constant messages, but do I have to write anything in my own code? Where does "DebugError ()" belong? In the Lua code? In the MD code? At the beginning of the routine? Before each line I want to "debug"? Or is it entered in the command window (where reloadUI also goes, for example)?

Thanks for the help with debugging.... I also wrote to Lino in the German forum (he's always quite talkative) and asked who at Ego is responsible for the Lua code, then I'll ask there again. But I don't expect any answers until January...

Greetings Trajan

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by kuertee » Tue, 4. Jan 22, 10:34

while building a new feature for one of my mods, i encountered this line in conversations.xml:

Code: Select all

<open_menu menu="MapMenu" param="[0, 0, true, null, null, 'infomode', [ 'info', event.param2 ]]" />
and there's this bit of note at the top of map_menu.lua:

Code: Select all

-- section == gMain_map
-- param == { 0, 0, showzone, focuscomponent [, history] [, mode, modeparam] }
 
-- modes: - "orderparam_object",	param: { returnfunction, paramdata, toprow, ordercontrollable } 
--		  - "orderparam_position",	param: { returnfunction, paramdata, toprow, ordercontrollable } 
--		  - "selectbuildlocation",	param: { returnsection, { 0, 0, trader, buildership_or_module, object, macro } }
--		  - "tradecontext",			param: { station, initialtradingship, iswareexchange, shadyOnly, loop, trader }
--		  - "selectCV",				param: { buildstorage }
--		  - "infomode",				param: { mode, ... }
--		  - "boardingcontext",		param: { target, boardingships }
--		  - "hire",					param: { returnsection, npc_or_context, ishiring[, npctemplate] }
--		  - "sellships",			param: { shipyard, ships }
--		  - "dropwarescontext",		param: { mode, entity }
--		  - "renamecontext",		param: { component, renamefleet }
--		  - "selectComponent",		param: { returnsection, classlist[, category][, playerowned][, customheading] }
--		  - "crewtransfercontext",	param: { othership, ship }
--		  - "ventureconsole",		param: { ventureplatform }
--		  - "venturepatroninfo",	param: { ventureplatform }
and ... i got the map to open from the MissionDirector (MD/XML) with a component's (i.e. station or ship) info panel open.
in this example, the map opens with the player's ship info panel open.

Code: Select all

<!-- param == { 0, 0, showzone, focuscomponent [, history] [, mode, modeparam] } -->
<!-- <open_menu menu="MapMenu" param="[0, 0, true, null, null, 'infomode', [ 'info', event.param2 ]]" /> -->
<set_value name="$isShowZone" exact="true" />
<set_value name="$focusComponent" exact="player.ship" />
<set_value name="$history" exact="null" />
<set_value name="$mode" exact="'infomode'" />
<set_value name="$modeParam" exact="['info', player.ship]" />
<open_menu menu="MapMenu" param="[0, 0, $isShowZone, $focusComponent, $history, $mode, $modeParam]" />"
EDIT: I think this is used when you ask one of your ai pilots to show his ship's info. END EDIT.

that's one way to open the map.
but, *i think* there's still a way to open the map reliably with X4 Lua's OpenMap ().
the way just needs to be found by researching, debugging, coding, researching, debugging, coding, * n^when it's found - i.e.: "by programming". :-D
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 544
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by Trajan von Olb » Tue, 4. Jan 22, 22:43

How cool! Thank you! That will certainly help. I'll have to get to grips with it a bit and see what all goes in the right-hand menus and generally, but it looks like it's going to be something with the hotkey operation of the menu after all. Then the mod will finally be ready in a first version.... Great.
Remains quite other questions, e.g. how to turn on and off the trade offers on the map with a hotkey or how to make the amount of goods to be bought completely full or empty (the slider) with one key, which probably really only works with Lua, but one thing at a time.

Greetings Trajan

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

Trajan von Olb
Posts: 544
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by Trajan von Olb » Wed, 5. Jan 22, 23:14

Ok, I have made some progress today. With the XML command you can open the menu, but if it's already open, the tabs don't change when you press the key. I now solve this by executing both the XML call to the menu and then directly the Lua code:

Code: Select all

<open_menu menu="MapMenu" param="[0, 0, $isShowZone, $focusComponent, $history, $mode, $modeParam]" />"
<raise_lua_event name="'MoreHotkeys.openObjectListWithHotkey'" param="event.param.$event"/>.
In Lua you then don't have to open a menu anymore but just do the refresh (not open), this works great:

Code: Select all

mapMenu.infoTableMode = "objectlist"
mapMenu.refreshMainFrame = true
mapMenu.updateMapAndInfoFrame ()
So far, so good. BUT: Again, the missions menu is buggy - it can also be called via XML, but the Lua code afterwards opens the info menu, not the mission menu, despite >infoTableMode = "mission"<... Could it be that a parameter is missing there that would actually be mandatory? So in Lua, xml works, but does not update as described above...

And another question: With the XML command I can give "Param2" as well as "Param" (in your code $modeParam) - so you have given "player.ship", and I have already succeeded in displaying the current target with "player.target". But is there more to it? Can I perhaps somehow pass parameters that I find in the map-menu.lua? And above all: How do I format this? For example, I tried to use the Lua code

Code: Select all

displayedFilterLayer = "layer_trade"
with the param2 by changing your command at so:

Code: Select all

.
.
.
<set_value name="$modeParam" exact="['objectlist', player.ship, displayedFilterLayer = 'layer_trade']" />
<open_menu menu="MapMenu" param="[0, 0, $isShowZone, $focusComponent, $history, $mode, $modeParam]" />"
But it doesn't work, the whole command breaks and doesn't work anymore - am I doing something wrong with the format?
Or maybe you found a place where the param2 possibilities are listed depending on the param?

And finally: What is "$history"?

Hmmm... Is really try and error...

Thanks as always.

Trajan

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Lua calls of the map menu broken (>Lib.Get_Egosoft_Menu("MapMenu")<) (SN mod-support-api)

Post by kuertee » Thu, 6. Jan 22, 01:44

i'm sorry that i can't answer your questions directly except that i don't know what "history" is.
it's just one of the parameters for MD's "open_menu". i set it to null as you can see.

what i can suggest instead is to investigate menu_map.lua file to see:
1. what it does to those parameters
2. investigate exactly what you can use in regards to this info that is at the top of the menu_map.lua

Code: Select all

-- section == gMain_map
-- param == { 0, 0, showzone, focuscomponent [, history] [, mode, modeparam] }
 
-- modes: - "orderparam_object",	param: { returnfunction, paramdata, toprow, ordercontrollable } 
--		  - "orderparam_position",	param: { returnfunction, paramdata, toprow, ordercontrollable } 
--		  - "selectbuildlocation",	param: { returnsection, { 0, 0, trader, buildership_or_module, object, macro } }
--		  - "tradecontext",			param: { station, initialtradingship, iswareexchange, shadyOnly, loop, trader }
--		  - "selectCV",				param: { buildstorage }
--		  - "infomode",				param: { mode, ... }
--		  - "boardingcontext",		param: { target, boardingships }
--		  - "hire",					param: { returnsection, npc_or_context, ishiring[, npctemplate] }
--		  - "sellships",			param: { shipyard, ships }
--		  - "dropwarescontext",		param: { mode, entity }
--		  - "renamecontext",		param: { component, renamefleet }
--		  - "selectComponent",		param: { returnsection, classlist[, category][, playerowned][, customheading] }
--		  - "crewtransfercontext",	param: { othership, ship }
--		  - "ventureconsole",		param: { ventureplatform }
--		  - "venturepatroninfo",	param: { ventureplatform }
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Post Reply

Return to “X4: Foundations - Scripts and Modding”