Skip to content

Commit

Permalink
Interact API bugfix for x4 4.10 beta 5 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvbohnen committed Jul 28, 2021
1 parent 474b62f commit eb145df
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Support/steam_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sn_interact_collection": "1.1",
"sn_extra_game_options": "1.12",
"sn_better_target_monitor": "2.0",
"sn_mod_support_apis": "1.86",
"sn_mod_support_apis": "1.87",
"sn_remove_dock_glow": "1.2",
"sn_quiet_target_range_clicks": "1.1",
"sn_remove_blinking_lights": "1.4",
Expand Down
2 changes: 2 additions & 0 deletions X4_Python_Pipe_Server/Classes/Pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def __init__(self, pipe_name, buffer_size = None, verbose = False):
# One user indicated the printed account name for them was blank,
# followed by perms not working. Warn in that case, and leave
# perms at default.
# TODO: this didn't fix the problem; would need more input from
# the user to figure out exactly what is going on.
if not account_name.strip():
if self.verbose:
print(f'Failed to retrieve account name with win32api.GetUserName')
Expand Down
8 changes: 8 additions & 0 deletions extensions/sn_extra_game_options/lua/Custom_Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ end
Note: importMenuParameters is called by onShowMenu just prior to
restoring prior state, so hopefully this doesn't interfere with
restoring a minimized menu that focuses on something else.
TODO: noticed in 4.10b5: map tries to open on last focused object, and
this code no longer works. Map behavior janky, eg getting insistent on
a particular object and not wanting to change defaults, so ignore
initially.
]]
L.mapfocus = {
onplayer = true,
Expand Down Expand Up @@ -801,6 +806,9 @@ end
menu.onUpdate()
If menu.mapstate found, sends to C.SetMapState.
TODO: noticed in 4.10b5: map always opens with prior zoom level, and
this does nothing. Maybe remove.
]]
L.mapzoom = {
distance = 0,
Expand Down
4 changes: 3 additions & 1 deletion extensions/sn_mod_support_apis/change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ Change Log for overall api package.
* 1.85
- Improved hotkey api support various keyboard layouts.
* 1.86
- Hotkey pipe server bugfix.
- Hotkey pipe server bugfix.
* 1.87
- Update/fix to interact api for x4 4.10 beta 5.
2 changes: 1 addition & 1 deletion extensions/sn_mod_support_apis/content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name="Mod Support APIs"
description=" "
author="SirNukes"
version="186"
version="187"
date="2019-07-23"
save="false"
sync="false">
Expand Down
39 changes: 33 additions & 6 deletions extensions/sn_mod_support_apis/lua/interact_menu/Interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ menu.onShowMenu()
- Calls menu.display()
menu.display()
- Records mouse position (not use anywhere?)
- Records mouse position (not used anywhere?)
- Calls menu.prepareActions()
- Calls menu.draw()
- Can potentially intercept and delay this one frame to get md responses.
Expand All @@ -26,7 +26,8 @@ menu.display()
menu.draw()
- Sets up widget stuff.
- Records menu.mouseOutBox.
- Records menu.mouseOutBox, used in update function to close the menu if the
mouse is outside the box.
menu.onUpdate()
- Checks menu.mouseOutBox.
Expand All @@ -46,6 +47,7 @@ menu.prepareActions()
- Makes many conditional calls to insertInteractionContent()
to register the actions.
- Can be followed with adding new actions.
- Returns "anydisplayed", true if there are any menu entries.
insertInteractionContent(section, entry)
Expand Down Expand Up @@ -354,21 +356,38 @@ function L.Init_Patch_Menu()
ego_draw(...)
end
end

-- Delay the update function, since it wants to check if the mouse is over
-- the menu, but the menu box isn't known yet (not until draw() finishes).
local ego_onUpdate = menu.onUpdate
menu.onUpdate = function(...)
if not L.delaying_menu then
ego_onUpdate(...)
end
end

-- Patch prepareActions to slot in the custom function afterward.
local ego_prepareActions = menu.prepareActions
menu.prepareActions = function (...)
if not L.delaying_menu then
-- Run the standard setup first.
ego_prepareActions(...)
-- Return arg added in 4.10b5 (will be nil on pre-beta branch).
local hasanydisplayed = ego_prepareActions(...)

-- Safety call to add in the new actions.
if not L.settings.disabled then
local success, error = pcall(L.Add_Actions, ...)
local success, has_added_actions_or_error = pcall(L.Add_Actions, ...)
if not success then
DebugError("Interact API prepareActions error: "..tostring(error))
DebugError("Interact API prepareActions error: "..tostring(has_added_actions_or_error))
elseif has_added_actions_or_error then
hasanydisplayed = true
end
end
return hasanydisplayed
else
-- Act as if the menu will have something to display, so it
-- doesn't get closed early (checked in the display() func).
return true
end
end

Expand Down Expand Up @@ -412,7 +431,7 @@ function L.Delayed_Draw()

-- Run the suppressed functions.
menu.prepareActions()
menu.draw()
menu.draw()
end

-- Function called when a menu is first opened.
Expand Down Expand Up @@ -512,6 +531,10 @@ function L.Add_Actions()

local convertedComponent = ConvertStringTo64Bit(tostring(menu.componentSlot.component))

-- Flag set true if any actions are added, to be merged with the egosoft
-- hasanydisplayed flag.
local has_added_actions = false

-- Update object flags.
L.Update_Flags(menu.componentSlot.component)

Expand Down Expand Up @@ -542,8 +565,12 @@ function L.Add_Actions()
local success, error = pcall(L.Process_Action, action)
if not success then
DebugError("Interact API error in Process_Action: "..tostring(error))
else
has_added_actions = true
end
end

return has_added_actions
end

-- Process a single action. This should be pcalled for safety.
Expand Down
5 changes: 5 additions & 0 deletions extensions/sn_mod_support_apis/lua/time/Interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ local E = {}
-- Table of local functions and data.
local L = {
debug = false,

-- Flag, if true then alarms are being checked every cycle.
checking_alarms = false,

Expand Down Expand Up @@ -433,6 +434,10 @@ function L.Poll_For_Alarm()

-- Note this id for list removal.
table.insert(ids_to_remove, id)

if L.debug then
DebugError("Time Alarm triggered: "..tostring(id))
end
else
-- Otherwise count down the frames.
alarm_data[2] = alarm_data[2] - 1
Expand Down

0 comments on commit eb145df

Please sign in to comment.