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:
parent
0b5654f870
commit
0f362f80e3
|
@ -202,9 +202,9 @@ function popWindow()
|
||||||
else
|
else
|
||||||
terminalWindow:breakAnchors()
|
terminalWindow:breakAnchors()
|
||||||
terminalWindow:setOn(true)
|
terminalWindow:setOn(true)
|
||||||
local size = oldSize or { width = g_window.getWidth()/2, height = g_window.getHeight()/2 }
|
local size = oldSize or { width = g_window.getWidth()/2.5, height = g_window.getHeight()/4 }
|
||||||
terminalWindow:setSize(size)
|
terminalWindow:setSize(size)
|
||||||
local pos = oldPos or { x = (g_window.getWidth() - terminalWindow:getWidth())/2, y = (g_window.getHeight() - terminalWindow:getHeight())/2 }
|
local pos = oldPos or { x = 0, y = g_window.getHeight() }
|
||||||
terminalWindow:setPosition(pos)
|
terminalWindow:setPosition(pos)
|
||||||
terminalWindow:getChildById('bottomResizeBorder'):enable()
|
terminalWindow:getChildById('bottomResizeBorder'):enable()
|
||||||
terminalWindow:getChildById('rightResizeBorder'):enable()
|
terminalWindow:getChildById('rightResizeBorder'):enable()
|
||||||
|
|
|
@ -16,6 +16,7 @@ currentViewMode = 0
|
||||||
smartWalkDirs = {}
|
smartWalkDirs = {}
|
||||||
smartWalkDir = nil
|
smartWalkDir = nil
|
||||||
walkFunction = nil
|
walkFunction = nil
|
||||||
|
hookedMenuOptions = {}
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
g_ui.importStyle('styles/countwindow')
|
g_ui.importStyle('styles/countwindow')
|
||||||
|
@ -104,6 +105,8 @@ function terminate()
|
||||||
save()
|
save()
|
||||||
hide()
|
hide()
|
||||||
|
|
||||||
|
hookedMenuOptions = {}
|
||||||
|
|
||||||
stopSmartWalk()
|
stopSmartWalk()
|
||||||
|
|
||||||
disconnect(g_game, {
|
disconnect(g_game, {
|
||||||
|
@ -409,6 +412,17 @@ function startTradeWith(thing)
|
||||||
g_mouse.pushCursor('target')
|
g_mouse.pushCursor('target')
|
||||||
end
|
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)
|
function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
if not g_game.isOnline() then return end
|
if not g_game.isOnline() then return end
|
||||||
local menu = g_ui.createWidget('PopupMenu')
|
local menu = g_ui.createWidget('PopupMenu')
|
||||||
|
@ -440,7 +454,6 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
if useThing:isRotateable() then
|
if useThing:isRotateable() then
|
||||||
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
|
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
|
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)
|
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(creatureThing:getName()) end)
|
||||||
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)
|
menu:display(menuPosition)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
function UIMinimap:onCreate()
|
||||||
|
self.autowalk = true
|
||||||
|
end
|
||||||
|
|
||||||
function UIMinimap:onSetup()
|
function UIMinimap:onSetup()
|
||||||
self.flagWindow = nil
|
self.flagWindow = nil
|
||||||
self.floorUpWidget = self:getChildById('floorUp')
|
self.floorUpWidget = self:getChildById('floorUp')
|
||||||
|
@ -6,7 +10,6 @@ function UIMinimap:onSetup()
|
||||||
self.zoomOutWidget = self:getChildById('zoomOut')
|
self.zoomOutWidget = self:getChildById('zoomOut')
|
||||||
self.flags = {}
|
self.flags = {}
|
||||||
self.alternatives = {}
|
self.alternatives = {}
|
||||||
self.autowalk = true
|
|
||||||
self.onAddAutomapFlag = function(pos, icon, description) self:addFlag(pos, icon, description) end
|
self.onAddAutomapFlag = function(pos, icon, description) self:addFlag(pos, icon, description) end
|
||||||
self.onRemoveAutomapFlag = function(pos, icon, description) self:removeFlag(pos, icon, description) end
|
self.onRemoveAutomapFlag = function(pos, icon, description) self:removeFlag(pos, icon, description) end
|
||||||
connect(g_game, {
|
connect(g_game, {
|
||||||
|
@ -251,6 +254,16 @@ function UIMinimap:onDragLeave(widget, pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UIMinimap:onStyleApply(styleName, styleNode)
|
||||||
|
for name,value in pairs(styleNode) do
|
||||||
|
print(name)
|
||||||
|
if name == 'autowalk' then
|
||||||
|
print(value)
|
||||||
|
self.autowalk = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UIMinimap:createFlagWindow(pos)
|
function UIMinimap:createFlagWindow(pos)
|
||||||
if self.flagWindow then return end
|
if self.flagWindow then return end
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
|
|
|
@ -447,6 +447,8 @@ UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const
|
||||||
if(parent)
|
if(parent)
|
||||||
parent->addChild(widget);
|
parent->addChild(widget);
|
||||||
|
|
||||||
|
widget->callLuaField("onCreate");
|
||||||
|
|
||||||
if(widget) {
|
if(widget) {
|
||||||
widget->setStyleFromNode(styleNode);
|
widget->setStyleFromNode(styleNode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue