UIImageView, fixes to minimap
This commit is contained in:
parent
cb7f855fd8
commit
546007f1df
|
@ -0,0 +1,6 @@
|
||||||
|
ImageView < UIImageView
|
||||||
|
image-smooth: false
|
||||||
|
image-fixed-ratio: true
|
||||||
|
draggable: true
|
||||||
|
border-width: 2
|
||||||
|
border-color: #000000
|
|
@ -248,13 +248,15 @@ MinimapFlagWindow < MainWindow
|
||||||
|
|
||||||
// Minimap Full Panel
|
// Minimap Full Panel
|
||||||
|
|
||||||
MinimapFullPanel < UIWidget
|
MinimapFullPanel < FlatPanel
|
||||||
image-smooth: true
|
phantom: false
|
||||||
border-width: 2
|
|
||||||
border-color: #000000
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.top: topMenu.bottom
|
anchors.top: topMenu.bottom
|
||||||
|
|
||||||
|
ImageView
|
||||||
|
id: image
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
Button
|
Button
|
||||||
!text: tr('Close')
|
!text: tr('Close')
|
||||||
margin-right: 4
|
margin-right: 4
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
-- @docclass
|
||||||
|
UIImageView = extends(UIWidget)
|
||||||
|
|
||||||
|
function UIImageView.create()
|
||||||
|
local imageView = UIImageView.internalCreate()
|
||||||
|
imageView.zoom = 1
|
||||||
|
imageView:setClipping(true)
|
||||||
|
return imageView
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:getDefaultZoom()
|
||||||
|
local width = self:getWidth()
|
||||||
|
local height = self:getHeight()
|
||||||
|
local textureWidth = self:getImageTextureWidth()
|
||||||
|
local textureHeight = self:getImageTextureHeight()
|
||||||
|
local zoomX = width / textureWidth
|
||||||
|
local zoomY = height / textureHeight
|
||||||
|
return math.min(zoomX, zoomY)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:getImagePosition(x, y)
|
||||||
|
x = x or self:getWidth() / 2
|
||||||
|
y = y or self:getHeight() / 2
|
||||||
|
local offsetX = self:getImageOffsetX()
|
||||||
|
local offsetY = self:getImageOffsetY()
|
||||||
|
local posX = (x - offsetX) / self.zoom
|
||||||
|
local posY = (y - offsetY) / self.zoom
|
||||||
|
return posX, posY
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:setImage(image)
|
||||||
|
self:setImageSource(image)
|
||||||
|
local zoom = self:getDefaultZoom()
|
||||||
|
self:setZoom(zoom)
|
||||||
|
self:center()
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:setZoom(zoom, x, y)
|
||||||
|
local posX, posY = self:getImagePosition(x, y)
|
||||||
|
local textureWidth = self:getImageTextureWidth()
|
||||||
|
local textureHeight = self:getImageTextureHeight()
|
||||||
|
local imageWidth = textureWidth * zoom
|
||||||
|
local imageHeight = textureHeight * zoom
|
||||||
|
self:setImageWidth(imageWidth)
|
||||||
|
self:setImageHeight(imageHeight)
|
||||||
|
self.zoom = zoom
|
||||||
|
self:move(posX, posY, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:zoomIn(x, y)
|
||||||
|
local zoom = self.zoom * 1.1
|
||||||
|
self:setZoom(zoom, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:zoomOut(x, y)
|
||||||
|
local zoom = self.zoom / 1.1
|
||||||
|
self:setZoom(zoom, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:center()
|
||||||
|
self:move(self:getImageTextureWidth() / 2, self:getImageTextureHeight() / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:move(x, y, centerX, centerY)
|
||||||
|
x = math.max(math.min(x, self:getImageTextureWidth()), 0)
|
||||||
|
y = math.max(math.min(y, self:getImageTextureHeight()), 0)
|
||||||
|
local centerX = centerX or self:getWidth() / 2
|
||||||
|
local centerY = centerY or self:getHeight() / 2
|
||||||
|
local offsetX = centerX - x * self.zoom
|
||||||
|
local offsetY = centerY - y * self.zoom
|
||||||
|
self:setImageOffset({x=offsetX, y=offsetY})
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:onDragEnter(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:onDragMove(pos, moved)
|
||||||
|
local posX, posY = self:getImagePosition()
|
||||||
|
self:move(posX - moved.x / self.zoom, posY - moved.y / self.zoom)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:onDragLeave(widget, pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function UIImageView:onMouseWheel(mousePos, direction)
|
||||||
|
local x = mousePos.x - self:getX()
|
||||||
|
local y = mousePos.y - self:getY()
|
||||||
|
if direction == MouseWheelUp then
|
||||||
|
self:zoomIn(x, y)
|
||||||
|
elseif direction == MouseWheelDown then
|
||||||
|
self:zoomOut(x, y)
|
||||||
|
end
|
||||||
|
end
|
|
@ -27,7 +27,7 @@ function init()
|
||||||
})
|
})
|
||||||
|
|
||||||
if g_game.isOnline() then
|
if g_game.isOnline() then
|
||||||
loadMap()
|
online()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ end
|
||||||
|
|
||||||
function loadMap()
|
function loadMap()
|
||||||
local protocolVersion = g_game.getProtocolVersion()
|
local protocolVersion = g_game.getProtocolVersion()
|
||||||
g_map.clean()
|
|
||||||
g_minimap.clean()
|
g_minimap.clean()
|
||||||
|
|
||||||
if otmm then
|
if otmm then
|
||||||
|
|
|
@ -146,18 +146,24 @@ function UIMinimap:updateFlags()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
UIMinimap.realZoomIn = UIMinimap.zoomIn
|
UIMinimap.realZoomIn = UIMinimap.realZoomIn or UIMinimap.zoomIn
|
||||||
function UIMinimap:zoomIn()
|
function UIMinimap:zoomIn()
|
||||||
self:realZoomIn()
|
self:realZoomIn()
|
||||||
self:updateFlags()
|
self:updateFlags()
|
||||||
end
|
end
|
||||||
|
|
||||||
UIMinimap.realZoomOut = UIMinimap.zoomOut
|
UIMinimap.realZoomOut = UIMinimap.realZoomOut or UIMinimap.zoomOut
|
||||||
function UIMinimap:zoomOut()
|
function UIMinimap:zoomOut()
|
||||||
self:realZoomOut()
|
self:realZoomOut()
|
||||||
self:updateFlags()
|
self:updateFlags()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
UIMinimap.realSetZoom = UIMinimap.realSetZoom or UIMinimap.setZoom
|
||||||
|
function UIMinimap:setZoom(zoom)
|
||||||
|
self:realSetZoom(zoom)
|
||||||
|
self:updateFlags()
|
||||||
|
end
|
||||||
|
|
||||||
function UIMinimap:floorUp(floors)
|
function UIMinimap:floorUp(floors)
|
||||||
local pos = self:getCameraPosition()
|
local pos = self:getCameraPosition()
|
||||||
pos.z = pos.z - floors
|
pos.z = pos.z - floors
|
||||||
|
@ -177,10 +183,12 @@ function UIMinimap:floorDown(floors)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMinimap:followLocalPlayer()
|
function UIMinimap:followLocalPlayer()
|
||||||
|
if not self:isDragging() then
|
||||||
local player = g_game.getLocalPlayer()
|
local player = g_game.getLocalPlayer()
|
||||||
self:followCreature(player)
|
self:followCreature(player)
|
||||||
self:updateFlags()
|
self:updateFlags()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UIMinimap:reset()
|
function UIMinimap:reset()
|
||||||
self:followLocalPlayer()
|
self:followLocalPlayer()
|
||||||
|
@ -231,8 +239,9 @@ function UIMinimap:onMouseRelease(pos, button)
|
||||||
|
|
||||||
if button == MouseLeftButton then
|
if button == MouseLeftButton then
|
||||||
local player = g_game.getLocalPlayer()
|
local player = g_game.getLocalPlayer()
|
||||||
if self.autowalk and not player:autoWalk(mapPos) then
|
if self.autowalk then
|
||||||
player.onAutoWalkFail = function() modules.game_textmessage.displayFailureMessage(tr('There is no way.')) end
|
player.onAutoWalkFail = function() modules.game_textmessage.displayFailureMessage(tr('There is no way.')) end
|
||||||
|
player:autoWalk(mapPos)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif button == MouseRightButton then
|
elseif button == MouseRightButton then
|
||||||
|
@ -260,8 +269,9 @@ end
|
||||||
|
|
||||||
function UIMinimap:createFullPanel()
|
function UIMinimap:createFullPanel()
|
||||||
self.fullPanel = g_ui.createWidget('MinimapFullPanel', rootWidget)
|
self.fullPanel = g_ui.createWidget('MinimapFullPanel', rootWidget)
|
||||||
self.fullPanel:setImageSource(self.fullImage)
|
|
||||||
self.fullPanel.onDestroy = function() self.fullPanel = nil end
|
self.fullPanel.onDestroy = function() self.fullPanel = nil end
|
||||||
|
local image = self.fullPanel:getChildById('image')
|
||||||
|
image:setImage(self.fullImage)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMinimap:destroyFullPanel()
|
function UIMinimap:destroyFullPanel()
|
||||||
|
@ -316,5 +326,3 @@ function UIMinimap:getArea()
|
||||||
local bottomRight = self:getPosition({ x = self:getX() + self:getWidth() - 2, y = self:getY() + self:getHeight() - 2 })
|
local bottomRight = self:getPosition({ x = self:getX() + self:getWidth() - 2, y = self:getY() + self:getHeight() - 2 })
|
||||||
return topLeft, bottomRight
|
return topLeft, bottomRight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -581,6 +581,8 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderRight", &UIWidget::getImageBorderRight);
|
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderRight", &UIWidget::getImageBorderRight);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderBottom", &UIWidget::getImageBorderBottom);
|
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderBottom", &UIWidget::getImageBorderBottom);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderLeft", &UIWidget::getImageBorderLeft);
|
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderLeft", &UIWidget::getImageBorderLeft);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("getImageTextureWidth", &UIWidget::getImageTextureWidth);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("getImageTextureHeight", &UIWidget::getImageTextureHeight);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("resizeToText", &UIWidget::resizeToText);
|
g_lua.bindClassMemberFunction<UIWidget>("resizeToText", &UIWidget::resizeToText);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("clearText", &UIWidget::clearText);
|
g_lua.bindClassMemberFunction<UIWidget>("clearText", &UIWidget::clearText);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
|
g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
|
||||||
|
|
|
@ -455,6 +455,8 @@ public:
|
||||||
int getImageBorderRight() { return m_imageBorder.right; }
|
int getImageBorderRight() { return m_imageBorder.right; }
|
||||||
int getImageBorderBottom() { return m_imageBorder.bottom; }
|
int getImageBorderBottom() { return m_imageBorder.bottom; }
|
||||||
int getImageBorderLeft() { return m_imageBorder.left; }
|
int getImageBorderLeft() { return m_imageBorder.left; }
|
||||||
|
int getImageTextureWidth() { return m_imageTexture ? m_imageTexture->getWidth() : 0; }
|
||||||
|
int getImageTextureHeight() { return m_imageTexture ? m_imageTexture->getHeight() : 0; }
|
||||||
|
|
||||||
// text related
|
// text related
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue