mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
Added easy menu hooking, fixed terminal default size/pos & more:
* Added autowalk style option to Minimap style. * Added onCreate for setting up variables before styling is applied etc.
This commit is contained in:
@@ -16,6 +16,7 @@ currentViewMode = 0
|
||||
smartWalkDirs = {}
|
||||
smartWalkDir = nil
|
||||
walkFunction = nil
|
||||
hookedMenuOptions = {}
|
||||
|
||||
function init()
|
||||
g_ui.importStyle('styles/countwindow')
|
||||
@@ -104,6 +105,8 @@ function terminate()
|
||||
save()
|
||||
hide()
|
||||
|
||||
hookedMenuOptions = {}
|
||||
|
||||
stopSmartWalk()
|
||||
|
||||
disconnect(g_game, {
|
||||
@@ -409,6 +412,17 @@ function startTradeWith(thing)
|
||||
g_mouse.pushCursor('target')
|
||||
end
|
||||
|
||||
function addMenuHook(category, name, callback, condition, shortcut)
|
||||
if not hookedMenuOptions[category] then
|
||||
hookedMenuOptions[category] = {}
|
||||
end
|
||||
hookedMenuOptions[category][name] = {
|
||||
callback = callback,
|
||||
condition = condition,
|
||||
shortcut = shortcut
|
||||
}
|
||||
end
|
||||
|
||||
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
if not g_game.isOnline() then return end
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
@@ -440,7 +454,6 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
if useThing:isRotateable() then
|
||||
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
|
||||
@@ -550,6 +563,16 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
|
||||
end
|
||||
|
||||
-- hooked menu options
|
||||
for _,category in pairs(hookedMenuOptions) do
|
||||
menu:addSeparator()
|
||||
for name,opt in pairs(category) do
|
||||
if opt.condition(menuPosition, lookThing, useThing, creatureThing) then
|
||||
menu:addOption(name, opt.callback, opt.shortcut)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
menu:display(menuPosition)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user