mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
Minimap, hotkeys and lot of other changes
* Begin working on a new layout system for UIMinimap and later UIMap, this new layout system allows to add widgets to the minimap * Add option to disable motd * Rework hotkey binding * Lots of fixes in hotkeys manager * Add fullmap view using Ctrl+Shift+M * Prevent some crashs in ThingType draw * Add function to load minimap from PNG files * Fixes in minimap saving * Fixes in Tile::isClickable * Add UIMapAnchorLayout, new layout for maps * Fix freezes in win32 when pressing alt key
This commit is contained in:
@@ -4,7 +4,6 @@ g_keyboard = {}
|
||||
-- private functions
|
||||
function translateKeyCombo(keyCombo)
|
||||
if not keyCombo or #keyCombo == 0 then return nil end
|
||||
table.sort(keyCombo)
|
||||
local keyComboDesc = ''
|
||||
for k,v in pairs(keyCombo) do
|
||||
local keyDesc = KeyCodeDescs[v]
|
||||
@@ -65,47 +64,29 @@ function determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
end
|
||||
table.insert(keyCombo, keyCode)
|
||||
end
|
||||
table.sort(keyCombo)
|
||||
return translateKeyCombo(keyCombo)
|
||||
end
|
||||
|
||||
local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local callback = widget.boundAloneKeyDownCombos[determineKeyComboDesc(keyCode, KeyboardNoModifier)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
end
|
||||
signalcall(callback, widget, keyCode)
|
||||
callback = widget.boundKeyDownCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
return signalcall(callback, widget, keyCode)
|
||||
end
|
||||
|
||||
local function onWidgetKeyUp(widget, keyCode, keyboardModifiers)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local callback = widget.boundAloneKeyUpCombos[determineKeyComboDesc(keyCode, KeyboardNoModifier)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
end
|
||||
signalcall(callback, widget, keyCode)
|
||||
callback = widget.boundKeyUpCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
return signalcall(callback, widget, keyCode)
|
||||
end
|
||||
|
||||
local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
local comboConf = widget.boundKeyPressCombos[keyComboDesc]
|
||||
if comboConf and (autoRepeatTicks >= comboConf.autoRepeatDelay or autoRepeatTicks == 0) and comboConf.callback then
|
||||
comboConf.callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
local callback = widget.boundKeyPressCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
return signalcall(callback, widget, keyCode, autoRepeatTicks)
|
||||
end
|
||||
|
||||
local function connectKeyDownEvent(widget)
|
||||
@@ -133,13 +114,10 @@ function g_keyboard.bindKeyDown(keyComboDesc, callback, widget, alone)
|
||||
widget = widget or rootWidget
|
||||
connectKeyDownEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyDownCombos[keyComboDesc] then
|
||||
pwarning('KeyDown event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
if alone then
|
||||
widget.boundAloneKeyDownCombos[keyComboDesc] = callback
|
||||
connect(widget.boundAloneKeyDownCombos, keyComboDesc, callback)
|
||||
else
|
||||
widget.boundKeyDownCombos[keyComboDesc] = callback
|
||||
connect(widget.boundKeyDownCombos, keyComboDesc, callback)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -147,53 +125,50 @@ function g_keyboard.bindKeyUp(keyComboDesc, callback, widget, alone)
|
||||
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
|
||||
if alone then
|
||||
widget.boundAloneKeyUpCombos[keyComboDesc] = callback
|
||||
connect(widget.boundAloneKeyUpCombos, keyComboDesc, callback)
|
||||
else
|
||||
widget.boundKeyUpCombos[keyComboDesc] = callback
|
||||
connect(widget.boundKeyUpCombos, keyComboDesc, callback)
|
||||
end
|
||||
end
|
||||
|
||||
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
|
||||
autoRepeatDelay = autoRepeatDelay or 500
|
||||
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget)
|
||||
widget = widget or rootWidget
|
||||
connectKeyPressEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyPressCombos[keyComboDesc] then
|
||||
pwarning('KeyPress event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
widget.boundKeyPressCombos[keyComboDesc] = { callback = callback, autoRepeatDelay = autoRepeatDelay }
|
||||
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
|
||||
connect(widget.boundKeyPressCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyDown(keyComboDesc, widget)
|
||||
local function getUnbindArgs(arg1, arg2)
|
||||
local callback
|
||||
local widget
|
||||
if type(arg1) == 'function' then callback = arg1
|
||||
elseif type(arg2) == 'function' then callback = arg2 end
|
||||
if type(arg1) == 'userdata' then widget = arg1
|
||||
elseif type(arg2) == 'userdata' then widget = arg2 end
|
||||
widget = widget or rootWidget
|
||||
return callback, widget
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyDown(keyComboDesc, arg1, arg2)
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyDownCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyDownCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyDownCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyUp(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyUpCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyUpCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyUpCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyPress(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
function g_keyboard.unbindKeyPress(keyComboDesc, widget, callback)
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyPressCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyPressCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyPressCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.getModifiers()
|
||||
|
@@ -13,6 +13,12 @@ function table.dump(t, depth)
|
||||
end
|
||||
end
|
||||
|
||||
function table.clear(t)
|
||||
for k,v in pairs(t) do
|
||||
t[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function table.copy(t)
|
||||
local res = {}
|
||||
for k,v in pairs(t) do
|
||||
|
@@ -224,7 +224,9 @@ end
|
||||
|
||||
function UIScrollBar:setText(text)
|
||||
local valueLabel = self:getChildById('valueLabel')
|
||||
valueLabel:setText(text)
|
||||
if valueLabel then
|
||||
valueLabel:setText(text)
|
||||
end
|
||||
end
|
||||
|
||||
function UIScrollBar:onGeometryChange()
|
||||
|
@@ -67,6 +67,11 @@ function connect(object, arg1, arg2, arg3)
|
||||
elseif type(object[signal]) == 'function' then
|
||||
object[signal] = { object[signal] }
|
||||
end
|
||||
|
||||
if type(slot) ~= 'function' then
|
||||
perror(debug.traceback('unable to connect a non function value'))
|
||||
end
|
||||
|
||||
if type(object[signal]) == 'table' then
|
||||
if pushFront then
|
||||
table.insert(object[signal], 1, slot)
|
||||
@@ -80,9 +85,15 @@ end
|
||||
function disconnect(object, arg1, arg2)
|
||||
local signalsAndSlots
|
||||
if type(arg1) == 'string' then
|
||||
if arg2 == nil then
|
||||
object[arg1] = nil
|
||||
return
|
||||
end
|
||||
signalsAndSlots = { [arg1] = arg2 }
|
||||
else
|
||||
elseif type(arg1) == 'table' then
|
||||
signalsAndSlots = arg1
|
||||
else
|
||||
perror(debug.traceback('unable to disconnect'))
|
||||
end
|
||||
|
||||
for signal,slot in pairs(signalsAndSlots) do
|
||||
|
Reference in New Issue
Block a user