mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Game control precision edits and many other fixes:
* Updated the walking(mouse/keys) control to be a lot more responsive/smooth! * Updated creature diagonal steps to animate faster (due to demand). * Added a warning popup for boost walker option in cipsoft servers. * Added KeyUp event controls in the g_keyboard class. * Fixed an issue with the minimap not reconfiguring. * Fixed a bug with creature lights drawing properly. * Fixed refreshContainer method. * Some layout edits. * Some minor typo fixes. TODO: * Add walk event stack. * Test new walking edits extensively. * Finish pending state feature.
This commit is contained in:
@@ -171,6 +171,9 @@ KeyNumpad7 = 148
|
||||
KeyNumpad8 = 149
|
||||
KeyNumpad9 = 150
|
||||
|
||||
FirstKey = KeyUnknown
|
||||
LastKey = KeyNumpad9
|
||||
|
||||
ExtendedActivate = 0
|
||||
ExtendedLocales = 1
|
||||
ExtendedParticles = 2
|
||||
|
@@ -80,6 +80,17 @@ local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onWidgetKeyUp(widget, keyCode, keyboardModifiers)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
local callback = widget.boundKeyUpCombos[keyComboDesc]
|
||||
if callback then
|
||||
callback()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
@@ -97,6 +108,12 @@ local function connectKeyDownEvent(widget)
|
||||
widget.boundKeyDownCombos = {}
|
||||
end
|
||||
|
||||
local function connectKeyUpEvent(widget)
|
||||
if widget.boundKeyUpCombos then return end
|
||||
connect(widget, { onKeyUp = onWidgetKeyUp })
|
||||
widget.boundKeyUpCombos = {}
|
||||
end
|
||||
|
||||
local function connectKeyPressEvent(widget)
|
||||
if widget.boundKeyPressCombos then return end
|
||||
connect(widget, { onKeyPress = onWidgetKeyPress })
|
||||
@@ -114,6 +131,16 @@ function g_keyboard.bindKeyDown(keyComboDesc, callback, widget)
|
||||
widget.boundKeyDownCombos[keyComboDesc] = callback
|
||||
end
|
||||
|
||||
function g_keyboard.bindKeyUp(keyComboDesc, callback, widget)
|
||||
widget = widget or rootWidget
|
||||
connectKeyUpEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyUpCombos[keyComboDesc] then
|
||||
pwarning('KeyUp event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
widget.boundKeyUpCombos[keyComboDesc] = callback
|
||||
end
|
||||
|
||||
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
|
||||
autoRepeatDelay = autoRepeatDelay or 500
|
||||
widget = widget or rootWidget
|
||||
@@ -135,6 +162,15 @@ function g_keyboard.unbindKeyDown(keyComboDesc, widget)
|
||||
end
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyUp(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
if widget.boundKeyUpCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyUpCombos[keyComboDesc] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyPress(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
if widget.boundKeyPressCombos == nil then return end
|
||||
@@ -155,6 +191,32 @@ function g_keyboard.isKeyPressed(key)
|
||||
return g_window.isKeyPressed(key)
|
||||
end
|
||||
|
||||
function g_keyboard.isKeySetPressed(keys, all)
|
||||
all = all or false
|
||||
local result = {}
|
||||
for k,v in pairs(keys) do
|
||||
if type(v) == 'string' then
|
||||
key = getKeyCode(v)
|
||||
end
|
||||
if g_window.isKeyPressed(key) then
|
||||
if not all then
|
||||
return true
|
||||
end
|
||||
table.insert(result, true)
|
||||
end
|
||||
end
|
||||
return #result == #keys
|
||||
end
|
||||
|
||||
function g_keyboard.isInUse()
|
||||
for i = FirstKey, LastKey do
|
||||
if g_window.isKeyPressed(key) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function g_keyboard.isCtrlPressed()
|
||||
return bit32.band(g_window.getKeyboardModifiers(), KeyboardCtrlModifier) ~= 0
|
||||
end
|
||||
|
Reference in New Issue
Block a user