2012-07-24 07:30:08 +02:00
|
|
|
DEFAULT_ZOOM = 60
|
|
|
|
MAX_FLOOR_UP = 0
|
|
|
|
MAX_FLOOR_DOWN = 15
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
G.minimapFirstLoad = true
|
2012-07-15 13:49:28 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
navigating = false
|
|
|
|
minimapWidget = nil
|
|
|
|
minimapButton = nil
|
|
|
|
minimapWindow = nil
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-07-09 13:37:47 +02:00
|
|
|
--[[
|
2012-07-12 21:16:23 +02:00
|
|
|
Known Issue (TODO):
|
|
|
|
If you move the minimap compass directions and
|
2012-07-09 13:37:47 +02:00
|
|
|
you change floor it will not update the minimap.
|
|
|
|
]]
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
|
|
|
connect(g_game, { onGameStart = reset,
|
|
|
|
onForceWalk = center })
|
2012-07-12 21:16:23 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+M', toggle)
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
minimapButton = TopMenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', 'minimap.png', toggle)
|
2012-06-23 16:26:18 +02:00
|
|
|
minimapButton:setOn(true)
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
minimapWindow = g_ui.loadUI('minimap.otui', modules.game_interface.getRightPanel())
|
2012-06-22 07:26:22 +02:00
|
|
|
|
|
|
|
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
|
2012-07-24 07:30:08 +02:00
|
|
|
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseRightButton)
|
|
|
|
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton)
|
2012-06-22 07:26:22 +02:00
|
|
|
minimapWidget:setAutoViewMode(false)
|
|
|
|
minimapWidget:setViewMode(1) -- mid view
|
|
|
|
minimapWidget:setDrawMinimapColors(true)
|
|
|
|
minimapWidget:setMultifloor(false)
|
|
|
|
minimapWidget:setKeepAspectRatio(false)
|
2012-04-07 01:12:46 +02:00
|
|
|
minimapWidget.onMouseRelease = onMinimapMouseRelease
|
2012-07-05 14:38:48 +02:00
|
|
|
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
reset()
|
2012-06-22 07:26:22 +02:00
|
|
|
|
|
|
|
-- load only the first time (avoid load/save between reloads)
|
2012-07-26 17:42:15 +02:00
|
|
|
--[[
|
2012-07-24 07:30:08 +02:00
|
|
|
if G.minimapFirstLoad then
|
|
|
|
G.minimapFirstLoad = false
|
2012-06-22 07:26:22 +02:00
|
|
|
if g_resources.fileExists('/minimap.otcm') then
|
|
|
|
if g_game.isOnline() then
|
|
|
|
perror('cannot load minimap while online')
|
|
|
|
else
|
|
|
|
g_map.loadOtcm('/minimap.otcm')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- save only when closing the client
|
|
|
|
connect(g_app, { onTerminate = function()
|
|
|
|
g_map.saveOtcm('/minimap.otcm')
|
|
|
|
end})
|
2012-07-26 17:42:15 +02:00
|
|
|
end]]--
|
2012-04-07 01:12:46 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function terminate()
|
|
|
|
disconnect(g_game, { onGameStart = reset,
|
|
|
|
onForceWalk = center })
|
2012-07-12 21:16:23 +02:00
|
|
|
|
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
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function toggle()
|
2012-06-24 14:41:39 +02:00
|
|
|
if minimapButton:isOn() then
|
2012-06-22 07:26:22 +02:00
|
|
|
minimapWindow:close()
|
|
|
|
minimapButton:setOn(false)
|
2012-06-24 14:41:39 +02:00
|
|
|
else
|
|
|
|
minimapWindow:open()
|
|
|
|
minimapButton:setOn(true)
|
2012-06-22 07:26:22 +02:00
|
|
|
end
|
2012-04-07 01:12:46 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function isClickInRange(position, fromPosition, toPosition)
|
|
|
|
return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y)
|
2012-06-24 14:41:39 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function reset()
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if not player then return end
|
|
|
|
minimapWidget:followCreature(player)
|
|
|
|
minimapWidget:setZoom(DEFAULT_ZOOM)
|
2012-06-26 07:54:55 +02:00
|
|
|
end
|
2012-07-12 21:16:23 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function center()
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if not player then return end
|
|
|
|
minimapWidget:followCreature(player)
|
|
|
|
end
|
|
|
|
|
|
|
|
function compassClick(self, mousePos, mouseButton, elapsed)
|
2012-07-13 01:40:55 +02:00
|
|
|
if elapsed < 300 then return end
|
|
|
|
|
|
|
|
navigating = true
|
2012-07-12 21:16:23 +02:00
|
|
|
local px = mousePos.x - self:getX()
|
|
|
|
local py = mousePos.y - self:getY()
|
|
|
|
local dx = px - self:getWidth()/2
|
|
|
|
local dy = -(py - self:getHeight()/2)
|
|
|
|
local radius = math.sqrt(dx*dx+dy*dy)
|
2012-07-13 10:24:52 +02:00
|
|
|
local movex = 0
|
|
|
|
local movey = 0
|
2012-07-12 21:16:23 +02:00
|
|
|
dx = dx/radius
|
|
|
|
dy = dy/radius
|
|
|
|
|
|
|
|
if dx > 0.5 then movex = 1 end
|
|
|
|
if dx < -0.5 then movex = -1 end
|
|
|
|
if dy > 0.5 then movey = -1 end
|
|
|
|
if dy < -0.5 then movey = 1 end
|
2012-07-05 14:38:48 +02:00
|
|
|
|
2012-07-09 13:37:47 +02:00
|
|
|
local cameraPos = minimapWidget:getCameraPosition()
|
2012-07-12 21:16:23 +02:00
|
|
|
local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z}
|
2012-07-09 13:37:47 +02:00
|
|
|
minimapWidget:setCameraPosition(pos)
|
2012-06-26 07:54:55 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onButtonClick(id)
|
2012-06-26 07:54:55 +02:00
|
|
|
if id == "zoomIn" then
|
|
|
|
minimapWidget:setZoom(math.max(minimapWidget:getMaxZoomIn(), minimapWidget:getZoom()-15))
|
|
|
|
elseif id == "zoomOut" then
|
|
|
|
minimapWidget:setZoom(math.min(minimapWidget:getMaxZoomOut(), minimapWidget:getZoom()+15))
|
2012-07-12 19:29:44 +02:00
|
|
|
elseif id == "floorUp" then
|
2012-06-26 07:54:55 +02:00
|
|
|
local pos = minimapWidget:getCameraPosition()
|
|
|
|
pos.z = pos.z - 1
|
2012-07-15 13:49:28 +02:00
|
|
|
if pos.z > MAX_FLOOR_UP then
|
2012-07-13 08:31:05 +02:00
|
|
|
minimapWidget:setCameraPosition(pos)
|
|
|
|
end
|
2012-07-12 19:29:44 +02:00
|
|
|
elseif id == "floorDown" then
|
2012-06-26 07:54:55 +02:00
|
|
|
local pos = minimapWidget:getCameraPosition()
|
|
|
|
pos.z = pos.z + 1
|
2012-07-15 13:49:28 +02:00
|
|
|
if pos.z < MAX_FLOOR_DOWN then
|
2012-07-13 08:31:05 +02:00
|
|
|
minimapWidget:setCameraPosition(pos)
|
|
|
|
end
|
2012-06-26 07:54:55 +02:00
|
|
|
end
|
2012-07-10 14:15:31 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onMinimapMouseRelease(self, mousePosition, mouseButton)
|
|
|
|
if navigating then
|
|
|
|
navigating = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local tile = self:getTile(mousePosition)
|
|
|
|
if tile and mouseButton == MouseLeftButton and self:isPressed() then
|
|
|
|
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), tile:getPosition(), 127)
|
|
|
|
if #dirs == 0 then
|
2012-07-26 11:12:20 +02:00
|
|
|
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
|
2012-07-24 07:30:08 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
g_game.autoWalk(dirs)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2012-07-10 14:15:31 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onMinimapMouseWheel(self, mousePos, direction)
|
|
|
|
if direction == MouseWheelUp then
|
|
|
|
self:zoomIn()
|
|
|
|
else
|
|
|
|
self:zoomOut()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function onMiniWindowClose()
|
|
|
|
minimapButton:setOn(false)
|
|
|
|
end
|