_I tried reporting this bug to the G.A.M.M.A. discord, but I was told this it was engine related, even though it could be resolved from inside the [ui_loaddialog.script] file which is used by the modpack.
When a player dies and reloads a save file from the menu, the function call to key_state(DIK_keys.MOUSE_1) reports an incorrect state of 1 even though LMB is not held down. The state resolves itself if you press LMB again.
How to:
die ingame
press escape to open the menu
click Load Game
double-click on a save file (row)
from this point on, dont click LMB
once ingame, debug key_state(DIK_keys.MOUSE_1) and it will report 1, instead of 0.
Bug
At first sight, the bug occurs, because when you die and try to load a save file from the menu, no prompt window is triggered, which forces a on_pressed on the list_window clicks.
The buttons from the prompt window execute based on a on_released key event.
The items in the list window (without prompt) execute based on a on_pressed key event (bug).
Internally, its because the file ui_load_dialog.script adds a callback to WINDOW_LBUTTON_DB_CLICK that is an on_pressed key event that does not get updated right after a save file gets executed.
As to why the keystate is not updated right after loading a save file is unknown to me. Perhaps code is not executed during a loading screen? Unfortunately I have limited time to debug this in the engine as it is a time-consuming (and horrible) process.
The relevant code snippets I could find are listed below:
// UIButton.cpp
bool CUIButton::OnMouseAction(float x, float y, EUIMessages mouse_action)
{
if (inherited::OnMouseAction(x, y, mouse_action)) return true;
switch (m_eButtonState)
{
case BUTTON_NORMAL:
{
if (mouse_action == WINDOW_LBUTTON_DOWN || mouse_action == WINDOW_LBUTTON_DB_CLICK)
{
SetButtonState(BUTTON_PUSHED); //this line!
GetMessageTarget()->SendMessage(this, BUTTON_DOWN, NULL);
return true;
}
}
break;
Solution: 1
The 2nd best solution (1st being a fix to the engine's keystate function) would be to add a new key event to the engine, named WINDOW_LBUTTON_DB_CLICKED, that would trigger based of a on_released key event. Note the ED at the end.
That way we could modify the AddCallback line in ui_load_dialog.script from this:
which will force the keystate to be saved as 0 and when the game loads it will have the correct (or better said, "initial") keystate.
Solution: 2
As an alternative solution one could also use a custom Lua implementation of keystate that forces LMB to always be 0 on game start until the engine itself registers a state of 1
local KEY_STATE_FIX = { [DIK_keys.MOUSE_1] = 0x1 }
local function GetKeyState(keycode)
if (KEY_STATE_FIX[keycode] == 0x1) then
return false
end
return key_state(keycode) == 1
end
local function WINDOW_LBUTTON_DB_CLICK_FIX(c)
if not KEY_STATE_FIX[c] then return end
KEY_STATE_FIX[c] = 0x2
UnregisterScriptCallback("on_key_press", WINDOW_LBUTTON_DB_CLICK_FIX)
end
RegisterScriptCallback("on_key_press", WINDOW_LBUTTON_DB_CLICK_FIX)
Solution: 3
Finally, we could force a prompt window for ALL save-file loads, which will resolve the issue on its own, because the prompt buttons are based of on_released key events.
_I tried reporting this bug to the G.A.M.M.A. discord, but I was told this it was engine related, even though it could be resolved from inside the [ui_loaddialog.script] file which is used by the modpack.
When a player dies and reloads a save file from the menu, the function call to
key_state(DIK_keys.MOUSE_1)
reports an incorrect state of1
even though LMB is not held down. The state resolves itself if you press LMB again.How to:
escape
to open the menuLoad Game
key_state(DIK_keys.MOUSE_1)
and it will report1
, instead of0
.Bug
At first sight, the bug occurs, because when you die and try to load a save file from the menu, no prompt window is triggered, which forces a
on_pressed
on thelist_window
clicks.on_released
key event.on_pressed
key event (bug).Internally, its because the file
ui_load_dialog.script
adds a callback toWINDOW_LBUTTON_DB_CLICK
that is anon_pressed
key event that does not get updated right after a save file gets executed.As to why the keystate is not updated right after loading a save file is unknown to me. Perhaps code is not executed during a loading screen? Unfortunately I have limited time to debug this in the engine as it is a time-consuming (and horrible) process.
The relevant code snippets I could find are listed below:
Solution: 1
The 2nd best solution (1st being a fix to the engine's keystate function) would be to add a new key event to the engine, named
WINDOW_LBUTTON_DB_CLICKED
, that would trigger based of aon_released
key event. Note theED
at the end.That way we could modify the
AddCallback
line inui_load_dialog.script
from this:to this:
which will force the keystate to be saved as
0
and when the game loads it will have the correct (or better said, "initial") keystate.Solution: 2
As an alternative solution one could also use a custom Lua implementation of
keystate
that forces LMB to always be0
on game start until the engine itself registers a state of1
Solution: 3
Finally, we could force a prompt window for ALL save-file loads, which will resolve the issue on its own, because the prompt buttons are based of
on_released
key events.