After Width: | Height: | Size: 335 B |
After Width: | Height: | Size: 397 B |
After Width: | Height: | Size: 387 B |
After Width: | Height: | Size: 444 B |
After Width: | Height: | Size: 362 B |
After Width: | Height: | Size: 373 B |
After Width: | Height: | Size: 397 B |
After Width: | Height: | Size: 412 B |
After Width: | Height: | Size: 418 B |
After Width: | Height: | Size: 399 B |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 418 B |
After Width: | Height: | Size: 431 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 354 B |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 400 B |
After Width: | Height: | Size: 423 B |
Before Width: | Height: | Size: 2.8 KiB |
@ -0,0 +1,247 @@
|
||||
MinimapFlag < UIWidget
|
||||
size: 11 11
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
|
||||
MinimapFlags < UIWidget
|
||||
anchors.fill: parent
|
||||
|
||||
MinimapFloorUpButton < Button
|
||||
size: 20 20
|
||||
margin-right: 28
|
||||
margin-bottom: 28
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
icon-source: /images/game/minimap/floor_up
|
||||
icon-clip: 0 32 16 16
|
||||
$pressed:
|
||||
icon-clip: 0 0 16 16
|
||||
$hover !pressed:
|
||||
icon-clip: 0 16 16 16
|
||||
|
||||
MinimapFloorDownButton < Button
|
||||
size: 20 20
|
||||
margin-right: 28
|
||||
margin-bottom: 4
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
icon-source: /images/game/minimap/floor_down
|
||||
icon-clip: 0 32 16 16
|
||||
$pressed:
|
||||
icon-clip: 0 0 16 16
|
||||
$hover !pressed:
|
||||
icon-clip: 0 16 16 16
|
||||
|
||||
MinimapZoomInButton < Button
|
||||
text: +
|
||||
size: 20 20
|
||||
margin-right: 4
|
||||
margin-bottom: 28
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
//icon-source: /images/game/minimap/zoom_in
|
||||
|
||||
MinimapZoomOutButton < Button
|
||||
text: -
|
||||
size: 20 20
|
||||
margin-right: 4
|
||||
margin-bottom: 4
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
//icon-source: /images/game/minimap/zoom_out
|
||||
|
||||
MinimapResetButton < Button
|
||||
!text: tr('Center')
|
||||
size: 44 20
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin: 4
|
||||
|
||||
Minimap < UIMinimap
|
||||
draggable: true
|
||||
focusable: false
|
||||
cross: true
|
||||
@onGeometryChange: self:updateFlags()
|
||||
|
||||
MinimapFlags
|
||||
id: flags
|
||||
phantom: true
|
||||
focusable: false
|
||||
|
||||
MinimapFloorUpButton
|
||||
id: floorUp
|
||||
@onClick: self:getParent():floorUp(1)
|
||||
|
||||
MinimapFloorDownButton
|
||||
id: floorDown
|
||||
@onClick: self:getParent():floorDown(1)
|
||||
|
||||
MinimapZoomInButton
|
||||
id: zoomIn
|
||||
@onClick: self:getParent():zoomIn()
|
||||
|
||||
MinimapZoomOutButton
|
||||
id: zoomOut
|
||||
@onClick: self:getParent():zoomOut()
|
||||
|
||||
MinimapResetButton
|
||||
id: reset
|
||||
@onClick: self:getParent():reset()
|
||||
|
||||
|
||||
// Minimap Flag Create Window
|
||||
|
||||
|
||||
MinimapFlagCheckBox < CheckBox
|
||||
size: 15 15
|
||||
margin-left: 2
|
||||
image-source: /images/game/minimap/flagcheckbox
|
||||
image-size: 15 15
|
||||
image-border: 3
|
||||
icon-source: /images/game/minimap/mapflags
|
||||
icon-size: 11 11
|
||||
icon-offset: 2 4
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
$!checked:
|
||||
image-clip: 26 0 26 26
|
||||
$hover !checked:
|
||||
image-clip: 78 0 26 26
|
||||
$checked:
|
||||
image-clip: 0 0 26 26
|
||||
$hover checked:
|
||||
image-clip: 52 0 26 26
|
||||
|
||||
MinimapFlagWindow < MainWindow
|
||||
!text: tr('Create Map Mark')
|
||||
size: 196 185
|
||||
|
||||
Label
|
||||
!text: tr('Position') .. ':'
|
||||
text-auto-resize: true
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin-top: 2
|
||||
|
||||
Label
|
||||
id: position
|
||||
text-auto-resize: true
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin-top: 2
|
||||
|
||||
Label
|
||||
!text: tr('Description') .. ':'
|
||||
anchors.left: parent.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 7
|
||||
|
||||
TextEdit
|
||||
id: description
|
||||
margin-top: 3
|
||||
anchors.left: parent.left
|
||||
anchors.top: prev.bottom
|
||||
width: 158
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag0
|
||||
icon-source: /images/game/minimap/flag0
|
||||
anchors.left: parent.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 6
|
||||
margin-left: 0
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag1
|
||||
icon-source: /images/game/minimap/flag1
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag2
|
||||
icon-source: /images/game/minimap/flag2
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag3
|
||||
icon-source: /images/game/minimap/flag3
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag4
|
||||
icon-source: /images/game/minimap/flag4
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag5
|
||||
icon-source: /images/game/minimap/flag5
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag6
|
||||
icon-source: /images/game/minimap/flag6
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag7
|
||||
icon-source: /images/game/minimap/flag7
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag8
|
||||
icon-source: /images/game/minimap/flag8
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag9
|
||||
icon-source: /images/game/minimap/flag9
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag10
|
||||
icon-source: /images/game/minimap/flag10
|
||||
anchors.left: parent.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 6
|
||||
margin-left: 0
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag11
|
||||
icon-source: /images/game/minimap/flag11
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag12
|
||||
icon-source: /images/game/minimap/flag12
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag13
|
||||
icon-source: /images/game/minimap/flag13
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag14
|
||||
icon-source: /images/game/minimap/flag14
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag15
|
||||
icon-source: /images/game/minimap/flag15
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag16
|
||||
icon-source: /images/game/minimap/flag16
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag17
|
||||
icon-source: /images/game/minimap/flag17
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag18
|
||||
icon-source: /images/game/minimap/flag18
|
||||
|
||||
MinimapFlagCheckBox
|
||||
id: flag19
|
||||
icon-source: /images/game/minimap/flag19
|
||||
|
||||
Button
|
||||
id: okButton
|
||||
!text: tr('Ok')
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 10
|
||||
|
||||
Button
|
||||
id: cancelButton
|
||||
!text: tr('Cancel')
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
@ -0,0 +1,280 @@
|
||||
function UIMinimap:onSetup()
|
||||
self.flagWindow = nil
|
||||
self.flagsWidget = self:getChildById('flags')
|
||||
self.floorUpWidget = self:getChildById('floorUp')
|
||||
self.floorDownWidget = self:getChildById('floorDown')
|
||||
self.zoomInWidget = self:getChildById('zoomIn')
|
||||
self.zoomOutWidget = self:getChildById('zoomOut')
|
||||
self.dx = 0
|
||||
self.dy = 0
|
||||
self.onPositionChange = function() self:followLocalPlayer() end
|
||||
self.onAddAutomapFlag = function(pos, icon, description) self:addFlag(pos, icon, description) end
|
||||
self.onRemoveAutomapFlag = function(pos, icon, description) self:addFlag(pos, icon, description) end
|
||||
connect(g_game, {
|
||||
onAddAutomapFlag = self.onAddAutomapFlag,
|
||||
onRemoveAutomapFlag = self.onRemoveAutomapFlag,
|
||||
})
|
||||
connect(LocalPlayer, { onPositionChange = self.onPositionChange })
|
||||
end
|
||||
|
||||
function UIMinimap:onDestroy()
|
||||
disconnect(LocalPlayer, { onPositionChange = self.onPositionChange })
|
||||
disconnect(g_game, {
|
||||
onAddAutomapFlag = self.onAddAutomapFlag,
|
||||
onRemoveAutomapFlag = self.onRemoveAutomapFlag,
|
||||
})
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
|
||||
function UIMinimap:load()
|
||||
local settings = g_settings.getNode('Minimap')
|
||||
if settings then
|
||||
if settings.flags then
|
||||
for i=1,#settings.flags do
|
||||
local flag = settings.flags[i]
|
||||
self:addFlag(flag.position, flag.icon, flag.description)
|
||||
end
|
||||
end
|
||||
self:setZoom(settings.zoom)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:save()
|
||||
local settings = { flags={} }
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
local flag = children[i]
|
||||
table.insert(settings.flags, {
|
||||
position = flag.pos,
|
||||
icon = flag.icon,
|
||||
description = flag.description,
|
||||
})
|
||||
end
|
||||
settings.zoom = self:getZoom()
|
||||
g_settings.setNode('Minimap', settings)
|
||||
end
|
||||
|
||||
function UIMinimap:addFlag(pos, icon, description)
|
||||
local flag = self:getFlag(pos, icon, description)
|
||||
if flag then
|
||||
return
|
||||
end
|
||||
|
||||
flag = g_ui.createWidget('MinimapFlag', self.flagsWidget)
|
||||
flag.pos = pos
|
||||
flag.icon = icon
|
||||
flag.description = description
|
||||
flag:setIcon('/images/game/minimap/flag' .. icon)
|
||||
flag:setTooltip(description)
|
||||
flag.onMouseRelease = function(widget, pos, button)
|
||||
if button == MouseRightButton then
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
menu:addOption(tr('Delete mark'), function() widget:destroy() end)
|
||||
menu:display(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self:updateFlag(flag)
|
||||
end
|
||||
|
||||
function UIMinimap:getFlag(pos, icon, description)
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
local flag = children[i]
|
||||
if flag.pos.x == pos.x and flag.pos.y == pos.y and flag.pos.z == pos.z and flag.icon == icon and flag.description == description then
|
||||
return flag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:removeFlag(pos, icon, description)
|
||||
local flag = self:getFlag(pos, icon, description)
|
||||
if flag then
|
||||
flag:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:updateFlag(flag)
|
||||
local topLeft, bottomRight = self:getArea()
|
||||
if self:isFlagVisible(flag, topLeft, bottomRight) then
|
||||
flag:setVisible(true)
|
||||
flag:setMarginLeft(-5.5 + (self:getWidth() / (bottomRight.x - topLeft.x)) * (flag.pos.x - topLeft.x))
|
||||
flag:setMarginTop(-5.5 + (self:getHeight() / (bottomRight.y - topLeft.y)) * (flag.pos.y - topLeft.y))
|
||||
else
|
||||
flag:setVisible(false)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:updateFlags()
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
self:updateFlag(children[i])
|
||||
end
|
||||
end
|
||||
|
||||
UIMinimap.realZoomIn = UIMinimap.zoomIn
|
||||
function UIMinimap:zoomIn()
|
||||
self:realZoomIn()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realZoomOut = UIMinimap.zoomOut
|
||||
function UIMinimap:zoomOut()
|
||||
self:realZoomOut()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:floorUp(floors)
|
||||
local pos = self:getCameraPosition()
|
||||
pos.z = pos.z - floors
|
||||
if pos.z >= FloorHigher then
|
||||
self:setCameraPosition(pos)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:floorDown(floors)
|
||||
local pos = self:getCameraPosition()
|
||||
pos.z = pos.z + floors
|
||||
if pos.z <= FloorLower then
|
||||
self:setCameraPosition(pos)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:followLocalPlayer()
|
||||
local player = g_game.getLocalPlayer()
|
||||
self:followCreature(player)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:reset()
|
||||
self:followLocalPlayer()
|
||||
self:setZoom(0)
|
||||
end
|
||||
|
||||
function UIMinimap:move(x, y)
|
||||
local topLeft, bottomRight = self:getArea()
|
||||
self.dx = self.dx + ((bottomRight.x - topLeft.x) / self:getWidth() ) * x
|
||||
self.dy = self.dy + ((bottomRight.y - topLeft.y) / self:getHeight()) * y
|
||||
local dx = math.floor(self.dx)
|
||||
local dy = math.floor(self.dy)
|
||||
self.dx = self.dx - dx
|
||||
self.dy = self.dy - dy
|
||||
|
||||
local cameraPos = self:getCameraPosition()
|
||||
local pos = {x = cameraPos.x - dx, y = cameraPos.y - dy, z = cameraPos.z}
|
||||
self:setCameraPosition(pos)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:onMouseWheel(mousePos, direction)
|
||||
local keyboardModifiers = g_keyboard.getModifiers()
|
||||
if direction == MouseWheelUp and keyboardModifiers == KeyboardNoModifier then
|
||||
self:zoomIn()
|
||||
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardNoModifier then
|
||||
self:zoomOut()
|
||||
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardCtrlModifier then
|
||||
self:floorUp(1)
|
||||
elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then
|
||||
self:floorDown(1)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:onMousePress(pos, button)
|
||||
if not self:isDragging() then
|
||||
self.allowNextRelease = true
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:onMouseRelease(pos, button)
|
||||
-- TODO:
|
||||
--if not self.allowNextRelease then return true end
|
||||
self.allowNextRelease = false
|
||||
|
||||
local mapPos = self:getPosition(pos)
|
||||
if not mapPos then return end
|
||||
|
||||
if button == MouseLeftButton then
|
||||
local player = g_game.getLocalPlayer()
|
||||
if not player:autoWalk(mapPos) then
|
||||
player.onAutoWalkFail = function() modules.game_textmessage.displayFailureMessage(tr('There is no way.')) end
|
||||
end
|
||||
return true
|
||||
elseif button == MouseRightButton then
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
menu:addOption(tr('Create mark'), function()
|
||||
self:createFlagWindow(mapPos)
|
||||
end)
|
||||
menu:display(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function UIMinimap:onDragEnter(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMinimap:onDragMove(pos, moved)
|
||||
self:move(moved.x, moved.y)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMinimap:onDragLeave(widget, pos)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMinimap:createFlagWindow(pos)
|
||||
if self.flagWindow then return end
|
||||
if not pos then return end
|
||||
|
||||
self.flagWindow = g_ui.createWidget('MinimapFlagWindow', rootWidget)
|
||||
|
||||
local positionLabel = self.flagWindow:getChildById('position')
|
||||
local description = self.flagWindow:getChildById('description')
|
||||
local okButton = self.flagWindow:getChildById('okButton')
|
||||
local cancelButton = self.flagWindow:getChildById('cancelButton')
|
||||
|
||||
positionLabel:setText(string.format('%i, %i, %i', pos.x, pos.y, pos.z))
|
||||
|
||||
local flagRadioGroup = UIRadioGroup.create()
|
||||
for i=0,19 do
|
||||
local checkbox = self.flagWindow:getChildById('flag' .. i)
|
||||
checkbox.icon = i
|
||||
flagRadioGroup:addWidget(checkbox)
|
||||
end
|
||||
|
||||
flagRadioGroup:selectWidget(flagRadioGroup:getFirstWidget())
|
||||
|
||||
okButton.onClick = function()
|
||||
self:addFlag(pos, flagRadioGroup:getSelectedWidget().icon, description:getText())
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
cancelButton.onClick = function()
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
|
||||
self.flagWindow.onDestroy = function() flagRadioGroup:destroy() end
|
||||
end
|
||||
|
||||
function UIMinimap:destroyFlagWindow()
|
||||
if self.flagWindow then
|
||||
self.flagWindow:destroy()
|
||||
self.flagWindow = nil
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:getArea()
|
||||
local topLeft = self:getPosition({ x = self:getX() + 1, y = self:getY() + 1 })
|
||||
local bottomRight = self:getPosition({ x = self:getX() + self:getWidth() - 2, y = self:getY() + self:getHeight() - 2 })
|
||||
return topLeft, bottomRight
|
||||
end
|
||||
|
||||
function UIMinimap:isFlagVisible(flag, topLeft, bottomRight)
|
||||
return flag.pos.x >= topLeft.x and flag.pos.x <= bottomRight.x and flag.pos.y >= topLeft.y and flag.pos.y <= bottomRight.y and flag.pos.z == topLeft.z
|
||||
end
|