mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
experimental minimap
* a lot of rework in MapView * new APIs for UIMap
This commit is contained in:
64
modules/game_minimap/minimap.lua
Normal file
64
modules/game_minimap/minimap.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
Minimap = {}
|
||||
|
||||
-- private variables
|
||||
local minimapWidget
|
||||
local minimapButton
|
||||
|
||||
-- private functions
|
||||
function onMinimapMouseRelease(self, mousePosition, mouseButton)
|
||||
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(), 255)
|
||||
if #dirs == 0 then
|
||||
TextMessage.displayStatus('There is no way.')
|
||||
return true
|
||||
end
|
||||
g_game.autoWalk(dirs)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function onMinimapMouseWheel(self, mousePos, direction)
|
||||
if direction == MouseWheelUp then
|
||||
self:zoomIn()
|
||||
else
|
||||
self:zoomOut()
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Minimap.init()
|
||||
connect(g_game, { onLogin = Minimap.reset })
|
||||
Keyboard.bindKeyDown('Ctrl+M', Minimap.toggle)
|
||||
|
||||
minimapButton = TopMenu.addGameToggleButton('minimapButton', 'Minimap (Ctrl+M)', 'minimap.png', Minimap.toggle)
|
||||
minimapButton:setOn(true)
|
||||
|
||||
minimapWidget = loadUI('minimap.otui', GameInterface.getMapPanel())
|
||||
minimapWidget.onMouseRelease = onMinimapMouseRelease
|
||||
minimapWidget.onMouseWheel = onMinimapMouseWheel
|
||||
end
|
||||
|
||||
function Minimap.terminate()
|
||||
Keyboard.unbindKeyDown('Ctrl+M')
|
||||
disconnect(g_game, { onLogin = Minimap.reset })
|
||||
|
||||
minimapWidget:destroy()
|
||||
minimapWidget = nil
|
||||
minimapButton:destroy()
|
||||
minimapButton = nil
|
||||
end
|
||||
|
||||
function Minimap.toggle()
|
||||
local visible = not minimapWidget:isExplicitlyVisible()
|
||||
minimapWidget:setVisible(visible)
|
||||
minimapButton:setOn(visible)
|
||||
end
|
||||
|
||||
function Minimap.reset()
|
||||
minimapWidget:followCreature(g_game.getLocalPlayer())
|
||||
for i=1,10 do minimapWidget:zoomOut() end
|
||||
end
|
||||
|
15
modules/game_minimap/minimap.otmod
Normal file
15
modules/game_minimap/minimap.otmod
Normal file
@@ -0,0 +1,15 @@
|
||||
Module
|
||||
name: game_minimap
|
||||
description: Manage minimap
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
dependecies:
|
||||
- game
|
||||
|
||||
@onLoad: |
|
||||
dofile 'minimap'
|
||||
Minimap.init()
|
||||
|
||||
@onUnload:
|
||||
Minimap.terminate()
|
21
modules/game_minimap/minimap.otui
Normal file
21
modules/game_minimap/minimap.otui
Normal file
@@ -0,0 +1,21 @@
|
||||
UIMap
|
||||
id: minimap
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
size: 256 192
|
||||
margin-top: 2
|
||||
margin-right: 2
|
||||
border-width: 1
|
||||
border-color: #888888
|
||||
padding: 1
|
||||
//draw-minimap-colors: true
|
||||
multifloor: false
|
||||
draw-texts: false
|
||||
|
||||
CheckBox
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin-top: 2
|
||||
margin-right: 2
|
||||
size: 16 16
|
||||
@onCheckChange: self:getParent():setDrawMinimapColors(self:isChecked())
|
BIN
modules/game_minimap/minimap.png
Normal file
BIN
modules/game_minimap/minimap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 910 B |
Reference in New Issue
Block a user