2012-07-24 07:30:08 +02:00
|
|
|
minimapWidget = nil
|
|
|
|
minimapButton = nil
|
|
|
|
minimapWindow = nil
|
2013-01-31 02:44:57 +01:00
|
|
|
otmm = true
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2013-01-31 02:44:57 +01:00
|
|
|
function init()
|
2013-01-18 23:39:11 +01:00
|
|
|
minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
|
2012-06-23 16:26:18 +02:00
|
|
|
minimapButton:setOn(true)
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
minimapWindow = g_ui.loadUI('minimap', modules.game_interface.getRightPanel())
|
2012-08-21 01:56:16 +02:00
|
|
|
minimapWindow:setContentMinimumHeight(64)
|
2012-06-22 07:26:22 +02:00
|
|
|
|
|
|
|
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
|
2012-07-05 14:38:48 +02:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
local gameRootPanel = modules.game_interface.getRootPanel()
|
2013-01-31 04:09:56 +01:00
|
|
|
g_keyboard.bindKeyPress('Alt+Left', function() minimapWidget:move(1,0) end, gameRootPanel)
|
|
|
|
g_keyboard.bindKeyPress('Alt+Right', function() minimapWidget:move(-1,0) end, gameRootPanel)
|
|
|
|
g_keyboard.bindKeyPress('Alt+Up', function() minimapWidget:move(0,1) end, gameRootPanel)
|
|
|
|
g_keyboard.bindKeyPress('Alt+Down', function() minimapWidget:move(0,-1) end, gameRootPanel)
|
2013-01-31 02:44:57 +01:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+M', toggle)
|
2013-01-26 23:20:26 +01:00
|
|
|
|
2012-08-21 23:40:47 +02:00
|
|
|
minimapWindow:setup()
|
2013-01-31 02:44:57 +01:00
|
|
|
|
|
|
|
connect(g_game, {
|
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
})
|
|
|
|
|
2012-10-11 17:36:00 +02:00
|
|
|
if g_game.isOnline() then
|
2013-01-31 17:20:04 +01:00
|
|
|
online()
|
2012-10-11 17:36:00 +02:00
|
|
|
end
|
2012-04-07 01:12:46 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function terminate()
|
2013-01-31 02:44:57 +01:00
|
|
|
if g_game.isOnline() then
|
|
|
|
saveMap()
|
|
|
|
end
|
2013-01-27 10:44:15 +01:00
|
|
|
|
2012-08-18 12:34:15 +02:00
|
|
|
disconnect(g_game, {
|
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
})
|
2012-07-12 21:16:23 +02:00
|
|
|
|
2013-01-31 02:44:57 +01:00
|
|
|
local gameRootPanel = modules.game_interface.getRootPanel()
|
|
|
|
g_keyboard.unbindKeyPress('Alt+Left', gameRootPanel)
|
|
|
|
g_keyboard.unbindKeyPress('Alt+Right', gameRootPanel)
|
|
|
|
g_keyboard.unbindKeyPress('Alt+Up', gameRootPanel)
|
|
|
|
g_keyboard.unbindKeyPress('Alt+Down', gameRootPanel)
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+M')
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-06-24 13:20:17 +02:00
|
|
|
minimapButton:destroy()
|
2012-06-22 07:26:22 +02:00
|
|
|
minimapWindow:destroy()
|
2012-04-07 01:12:46 +02:00
|
|
|
end
|
|
|
|
|
2013-01-31 02:44:57 +01:00
|
|
|
function toggle()
|
|
|
|
if minimapButton:isOn() then
|
|
|
|
minimapWindow:close()
|
|
|
|
minimapButton:setOn(false)
|
2012-10-11 17:36:00 +02:00
|
|
|
else
|
2013-01-31 02:44:57 +01:00
|
|
|
minimapWindow:open()
|
|
|
|
minimapButton:setOn(true)
|
2012-10-11 17:36:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-31 02:44:57 +01:00
|
|
|
function onMiniWindowClose()
|
|
|
|
minimapButton:setOn(false)
|
2012-10-11 17:36:00 +02:00
|
|
|
end
|
|
|
|
|
2012-08-18 12:34:15 +02:00
|
|
|
function online()
|
|
|
|
loadMap()
|
2013-01-31 02:44:57 +01:00
|
|
|
minimapWidget:followLocalPlayer()
|
2012-08-18 12:34:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function offline()
|
|
|
|
saveMap()
|
|
|
|
end
|
|
|
|
|
|
|
|
function loadMap()
|
2012-12-28 12:05:45 +01:00
|
|
|
local protocolVersion = g_game.getProtocolVersion()
|
2013-01-27 17:06:47 +01:00
|
|
|
g_minimap.clean()
|
|
|
|
|
|
|
|
if otmm then
|
|
|
|
local minimapFile = '/minimap.otmm'
|
|
|
|
if g_resources.fileExists(minimapFile) then
|
|
|
|
g_minimap.loadOtmm(minimapFile)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
|
|
|
|
if g_resources.fileExists(minimapFile) then
|
|
|
|
g_map.loadOtcm(minimapFile)
|
|
|
|
end
|
2012-08-18 19:08:05 +02:00
|
|
|
end
|
2013-01-31 02:44:57 +01:00
|
|
|
minimapWidget:load()
|
2012-08-18 12:34:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function saveMap()
|
2012-12-28 12:05:45 +01:00
|
|
|
local protocolVersion = g_game.getProtocolVersion()
|
2013-01-27 17:06:47 +01:00
|
|
|
if otmm then
|
|
|
|
local minimapFile = '/minimap.otmm'
|
|
|
|
g_minimap.saveOtmm(minimapFile)
|
|
|
|
else
|
|
|
|
local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
|
|
|
|
g_map.saveOtcm(minimapFile)
|
|
|
|
end
|
2013-01-31 02:44:57 +01:00
|
|
|
minimapWidget:save()
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
2013-01-31 04:09:56 +01:00
|
|
|
|
|
|
|
function getMinimap()
|
|
|
|
return minimapWidget
|
|
|
|
end
|