minimapWidget = nil minimapButton = nil minimapWindow = nil otmm = true function init() minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle) minimapButton:setOn(true) minimapWindow = g_ui.loadUI('minimap', modules.game_interface.getRightPanel()) minimapWindow:setContentMinimumHeight(64) minimapWidget = minimapWindow:recursiveGetChildById('minimap') local gameRootPanel = modules.game_interface.getRootPanel() 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) g_keyboard.bindKeyDown('Ctrl+M', toggle) minimapWindow:setup() connect(g_game, { onGameStart = online, onGameEnd = offline, }) if g_game.isOnline() then loadMap() end end function terminate() if g_game.isOnline() then saveMap() end disconnect(g_game, { onGameStart = online, onGameEnd = offline, }) 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) g_keyboard.unbindKeyDown('Ctrl+M') minimapButton:destroy() minimapWindow:destroy() end function toggle() if minimapButton:isOn() then minimapWindow:close() minimapButton:setOn(false) else minimapWindow:open() minimapButton:setOn(true) end end function onMiniWindowClose() minimapButton:setOn(false) end function online() loadMap() minimapWidget:followLocalPlayer() end function offline() saveMap() end function loadMap() local protocolVersion = g_game.getProtocolVersion() g_map.clean() 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 end minimapWidget:load() end function saveMap() local protocolVersion = g_game.getProtocolVersion() if otmm then local minimapFile = '/minimap.otmm' g_minimap.saveOtmm(minimapFile) else local minimapFile = '/minimap_' .. protocolVersion .. '.otcm' g_map.saveOtcm(minimapFile) end minimapWidget:save() end