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
|
||||
|
||||
MinimapFullPanel < UIWidget
|
||||
image-smooth: true
|
||||
border-width: 2
|
||||
border-color: #000000
|
||||
MinimapFullPanel < FlatPanel
|
||||
phantom: false
|
||||
anchors.fill: parent
|
||||
anchors.top: topMenu.bottom
|
||||
|
||||
ImageView
|
||||
id: image
|
||||
anchors.fill: parent
|
||||
|
||||
Button
|
||||
!text: tr('Close')
|
||||
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
|
||||
loadMap()
|
||||
online()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,6 @@ end
|
|||
|
||||
function loadMap()
|
||||
local protocolVersion = g_game.getProtocolVersion()
|
||||
g_map.clean()
|
||||
g_minimap.clean()
|
||||
|
||||
if otmm then
|
||||
|
|
|
@ -146,18 +146,24 @@ function UIMinimap:updateFlags()
|
|||
end
|
||||
end
|
||||
|
||||
UIMinimap.realZoomIn = UIMinimap.zoomIn
|
||||
UIMinimap.realZoomIn = UIMinimap.realZoomIn or UIMinimap.zoomIn
|
||||
function UIMinimap:zoomIn()
|
||||
self:realZoomIn()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realZoomOut = UIMinimap.zoomOut
|
||||
UIMinimap.realZoomOut = UIMinimap.realZoomOut or UIMinimap.zoomOut
|
||||
function UIMinimap:zoomOut()
|
||||
self:realZoomOut()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realSetZoom = UIMinimap.realSetZoom or UIMinimap.setZoom
|
||||
function UIMinimap:setZoom(zoom)
|
||||
self:realSetZoom(zoom)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:floorUp(floors)
|
||||
local pos = self:getCameraPosition()
|
||||
pos.z = pos.z - floors
|
||||
|
@ -177,9 +183,11 @@ function UIMinimap:floorDown(floors)
|
|||
end
|
||||
|
||||
function UIMinimap:followLocalPlayer()
|
||||
if not self:isDragging() then
|
||||
local player = g_game.getLocalPlayer()
|
||||
self:followCreature(player)
|
||||
self:updateFlags()
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:reset()
|
||||
|
@ -231,8 +239,9 @@ function UIMinimap:onMouseRelease(pos, button)
|
|||
|
||||
if button == MouseLeftButton then
|
||||
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:autoWalk(mapPos)
|
||||
end
|
||||
return true
|
||||
elseif button == MouseRightButton then
|
||||
|
@ -260,8 +269,9 @@ end
|
|||
|
||||
function UIMinimap:createFullPanel()
|
||||
self.fullPanel = g_ui.createWidget('MinimapFullPanel', rootWidget)
|
||||
self.fullPanel:setImageSource(self.fullImage)
|
||||
self.fullPanel.onDestroy = function() self.fullPanel = nil end
|
||||
local image = self.fullPanel:getChildById('image')
|
||||
image:setImage(self.fullImage)
|
||||
end
|
||||
|
||||
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 })
|
||||
return topLeft, bottomRight
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -581,6 +581,8 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderRight", &UIWidget::getImageBorderRight);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderBottom", &UIWidget::getImageBorderBottom);
|
||||
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>("clearText", &UIWidget::clearText);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
|
||||
|
|
|
@ -455,6 +455,8 @@ public:
|
|||
int getImageBorderRight() { return m_imageBorder.right; }
|
||||
int getImageBorderBottom() { return m_imageBorder.bottom; }
|
||||
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
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue