tibia-client/modules/game_minimap/minimap.lua

166 lines
4.1 KiB
Lua
Raw Normal View History

minimapWidget = nil
minimapButton = nil
minimapWindow = nil
2013-01-31 02:44:57 +01:00
otmm = true
2013-02-07 06:56:02 +01:00
preloaded = false
fullmapView = false
oldZoom = nil
oldPos = nil
2013-01-31 02:44:57 +01:00
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())
2012-08-21 01:56:16 +02:00
minimapWindow:setContentMinimumHeight(64)
2012-06-22 07:26:22 +02:00
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
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)
g_keyboard.bindKeyDown('Ctrl+Shift+M', toggleFullMap)
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,
})
connect(LocalPlayer, {
onPositionChange = updateCameraPosition
})
if g_game.isOnline() then
2013-01-31 17:20:04 +01:00
online()
end
end
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
disconnect(LocalPlayer, {
onPositionChange = updateCameraPosition
})
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')
g_keyboard.unbindKeyDown('Ctrl+Shift+M')
2012-06-22 07:26:22 +02:00
minimapWindow:destroy()
minimapButton:destroy()
end
2013-01-31 02:44:57 +01:00
function toggle()
if minimapButton:isOn() then
minimapWindow:close()
minimapButton:setOn(false)
else
2013-01-31 02:44:57 +01:00
minimapWindow:open()
minimapButton:setOn(true)
end
end
2013-01-31 02:44:57 +01:00
function onMiniWindowClose()
minimapButton:setOn(false)
end
2013-02-07 06:56:02 +01:00
function preload()
loadMap(false)
preloaded = true
end
2012-08-18 12:34:15 +02:00
function online()
2013-02-07 06:56:02 +01:00
loadMap(not preloaded)
2013-02-27 20:24:32 +01:00
updateCameraPosition()
2012-08-18 12:34:15 +02:00
end
function offline()
saveMap()
end
2013-02-07 06:56:02 +01:00
function loadMap(clean)
local clientVersion = g_game.getClientVersion()
2013-02-07 06:56:02 +01:00
if clean then
g_minimap.clean()
end
if otmm then
local minimapFile = '/minimap.otmm'
if g_resources.fileExists(minimapFile) then
g_minimap.loadOtmm(minimapFile)
end
else
local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
if g_resources.fileExists(minimapFile) then
g_map.loadOtcm(minimapFile)
end
end
2013-01-31 02:44:57 +01:00
minimapWidget:load()
2012-08-18 12:34:15 +02:00
end
function saveMap()
local clientVersion = g_game.getClientVersion()
if otmm then
local minimapFile = '/minimap.otmm'
g_minimap.saveOtmm(minimapFile)
else
local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
g_map.saveOtcm(minimapFile)
end
2013-01-31 02:44:57 +01:00
minimapWidget:save()
end
2013-01-31 04:09:56 +01:00
function updateCameraPosition()
local player = g_game.getLocalPlayer()
2013-02-27 20:24:32 +01:00
if not player then return end
local pos = player:getPosition()
if not pos then return end
if not minimapWidget:isDragging() then
if not fullmapView then
minimapWidget:setCameraPosition(player:getPosition())
end
minimapWidget:setCrossPosition(player:getPosition())
end
end
function toggleFullMap()
if not fullmapView then
fullmapView = true
minimapWindow:hide()
minimapWidget:setParent(modules.game_interface.getRootPanel())
minimapWidget:fill('parent')
minimapWidget:setAlternativeWidgetsVisible(true)
else
fullmapView = false
minimapWidget:setParent(minimapWindow:getChildById('contentsPanel'))
minimapWidget:fill('parent')
minimapWindow:show()
minimapWidget:setAlternativeWidgetsVisible(false)
end
local zoom = oldZoom or 0
local pos = oldPos or minimapWidget:getCameraPosition()
oldZoom = minimapWidget:getZoom()
oldPos = minimapWidget:getCameraPosition()
minimapWidget:setZoom(zoom)
minimapWidget:setCameraPosition(pos)
2013-01-31 04:09:56 +01:00
end