improving minimap
This commit is contained in:
parent
16d4729f06
commit
0005119afe
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -22,7 +22,6 @@ function onMinimapMouseRelease(self, mousePosition, mouseButton)
|
|||
return false
|
||||
end
|
||||
|
||||
|
||||
function onMinimapMouseWheel(self, mousePos, direction)
|
||||
if direction == MouseWheelUp then
|
||||
self:zoomIn()
|
||||
|
@ -48,8 +47,8 @@ function Minimap.init()
|
|||
minimapWidget:setMultifloor(false)
|
||||
minimapWidget:setKeepAspectRatio(false)
|
||||
minimapWidget.onMouseRelease = onMinimapMouseRelease
|
||||
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
||||
|
||||
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
||||
|
||||
Minimap.reset()
|
||||
|
||||
-- load only the first time (avoid load/save between reloads)
|
||||
|
@ -103,3 +102,55 @@ function Minimap.reset()
|
|||
minimapWidget:setZoom(DEFAULT_ZOOM)
|
||||
end
|
||||
|
||||
function Minimap.isClickInRange(position, fromPosition, toPosition)
|
||||
return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y)
|
||||
end
|
||||
-- hooked functions
|
||||
local compassZones = {}
|
||||
compassZones.west = {x = 0, y = 30, posx = -1, posy = 0}
|
||||
compassZones.north = {x = 30, y = 0, posx = 0, posy = -1}
|
||||
compassZones.south = {x = 30, y = 57, posx = 0, posy = 1}
|
||||
compassZones.east = {x = 57, y = 30, posx = 1, posy = 0}
|
||||
compassZones.center = {x = 30, y = 30, posx = 0, posy = 0, center = true}
|
||||
function Minimap.compassClick(self, mousePos)
|
||||
local compassPos = self:getRect()
|
||||
local pos = {x = mousePos.x-compassPos.x, y = mousePos.y-compassPos.y}
|
||||
local move = {x = 0, y = 0}
|
||||
local center = false
|
||||
for i,v in pairs(compassZones) do
|
||||
local lowPos = {x = v.x-15, y = v.y-15}
|
||||
local highPos = {x = v.x+15, y = v.y+15}
|
||||
if Minimap.isClickInRange(pos, lowPos, highPos) then
|
||||
move.x = move.x + v.posx * minimapWidget:getZoom()/10
|
||||
move.y = move.y + v.posy * minimapWidget:getZoom()/10
|
||||
if v.center then center = true end
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if center then
|
||||
local player = g_game.getLocalPlayer()
|
||||
if not player then return end
|
||||
minimapWidget:followCreature(player)
|
||||
else
|
||||
local cameraPos = minimapWidget:getCameraPosition()
|
||||
local pos = {x = cameraPos.x + move.x, y = cameraPos.y + move.y, z = cameraPos.z}
|
||||
minimapWidget:setCameraPosition(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function Minimap.onButtonClick(id)
|
||||
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))
|
||||
elseif id == "levelUp" then
|
||||
local pos = minimapWidget:getCameraPosition()
|
||||
pos.z = pos.z - 1
|
||||
minimapWidget:setCameraPosition(pos)
|
||||
elseif id == "levelDown" then
|
||||
local pos = minimapWidget:getCameraPosition()
|
||||
pos.z = pos.z + 1
|
||||
minimapWidget:setCameraPosition(pos)
|
||||
end
|
||||
end
|
|
@ -10,4 +10,53 @@ MiniWindow
|
|||
padding: 3
|
||||
UIMap
|
||||
id: minimap
|
||||
anchors.fill: parent
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
size: 110 110
|
||||
|
||||
UIButton
|
||||
id: compass
|
||||
image-source: /game_minimap/compass.png
|
||||
anchors.left: minimap.right
|
||||
anchors.top: minimap.top
|
||||
size: 60 60
|
||||
margin-left: 5
|
||||
@onClick: function(...) Minimap.compassClick(...) end
|
||||
|
||||
Button
|
||||
id: zoomOut
|
||||
text: -
|
||||
size: 20 20
|
||||
anchors.left: minimap.right
|
||||
anchors.top: compass.bottom
|
||||
margin-top: 5
|
||||
margin-left: 15
|
||||
@onClick: Minimap.onButtonClick(self:getId())
|
||||
|
||||
Button
|
||||
id: zoomIn
|
||||
text: +
|
||||
size: 20 20
|
||||
anchors.left: zoomOut.left
|
||||
anchors.top: zoomOut.bottom
|
||||
margin-top: 2
|
||||
@onClick: Minimap.onButtonClick(self:getId())
|
||||
|
||||
Button
|
||||
id: levelUp
|
||||
text: /\
|
||||
size: 20 20
|
||||
anchors.left: zoomOut.right
|
||||
anchors.top: zoomOut.top
|
||||
margin-left: 2
|
||||
@onClick: Minimap.onButtonClick(self:getId())
|
||||
|
||||
Button
|
||||
id: levelDown
|
||||
text: \/
|
||||
size: 20 20
|
||||
anchors.left: zoomIn.right
|
||||
anchors.top: zoomIn.top
|
||||
margin-left: 2
|
||||
@onClick: Minimap.onButtonClick(self:getId())
|
||||
|
||||
|
|
Loading…
Reference in New Issue