Improve minimap

This commit is contained in:
Eduardo Bart 2012-07-12 16:16:23 -03:00
parent 1f6cd33109
commit c0c2411854
5 changed files with 78 additions and 77 deletions

View File

@ -4,7 +4,7 @@ Minimap = {}
local minimapWidget local minimapWidget
local minimapButton local minimapButton
local minimapWindow local minimapWindow
local DEFAULT_ZOOM = 45 local DEFAULT_ZOOM = 60
minimapFirstLoad = true minimapFirstLoad = true
-- private functions -- private functions
@ -105,30 +105,28 @@ function Minimap.onMiniWindowClose()
end end
function Minimap.isClickInRange(position, fromPosition, toPosition) 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) return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y)
end end
-- hooked functions -- 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}
function Minimap.compassClick(self, mousePos) function Minimap.compassClick(self, mousePos)
local compassPos = self:getRect() local px = mousePos.x - self:getX()
local pos = {x = mousePos.x-compassPos.x, y = mousePos.y-compassPos.y} local py = mousePos.y - self:getY()
local move = {x = 0, y = 0} local dx = px - self:getWidth()/2
for i,v in pairs(compassZones) do local dy = -(py - self:getHeight()/2)
local lowPos = {x = v.x-15, y = v.y-15} local radius = math.sqrt(dx*dx+dy*dy)
local highPos = {x = v.x+15, y = v.y+15} local movex=0
if Minimap.isClickInRange(pos, lowPos, highPos) then local movey=0
move.x = move.x + v.posx * minimapWidget:getZoom()/10 dx = dx/radius
move.y = move.y + v.posy * minimapWidget:getZoom()/10 dy = dy/radius
break
end if dx > 0.5 then movex = 1 end
end if dx < -0.5 then movex = -1 end
if dy > 0.5 then movey = -1 end
if dy < -0.5 then movey = 1 end
local cameraPos = minimapWidget:getCameraPosition() local cameraPos = minimapWidget:getCameraPosition()
local pos = {x = cameraPos.x + move.x, y = cameraPos.y + move.y, z = cameraPos.z} local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z}
minimapWidget:setCameraPosition(pos) minimapWidget:setCameraPosition(pos)
end end

View File

@ -1,23 +1,20 @@
MapControl < Button MapControl < Button
size: 16 16 size: 20 20
$pressed: $pressed:
image-clip: 0 0 16 16 icon-clip: 0 0 16 16
$hover !pressed: $hover !pressed:
image-clip: 0 16 16 16 icon-clip: 0 16 16 16
$!pressed !hover: $!pressed !hover:
image-clip: 0 32 16 16 icon-clip: 0 32 16 16
$disabled:
image-color: #ffffff88
FloorUpControl < MapControl FloorUpControl < MapControl
image-source: /game_minimap/floor_up.png icon-source: /game_minimap/floor_up.png
FloorDownControl < MapControl FloorDownControl < MapControl
image-source: /game_minimap/floor_down.png icon-source: /game_minimap/floor_down.png
//ZoomOutControl < MapControl //ZoomOutControl < MapControl
//image-source: /game_minimap/zoom_out.png //image-source: /game_minimap/zoom_out.png
@ -37,70 +34,66 @@ MiniWindow
padding: 3 padding: 3
UIMap UIMap
id: minimap id: minimap
anchors.left: parent.left anchors.fill: parent
anchors.top: parent.top
size: 110 110
UIButton UIButton
id: compass id: compass
image-source: /game_minimap/compass.png image-source: /game_minimap/compass.png
image-smooth: true
color: #ffffff color: #ffffff
anchors.left: minimap.right anchors.left: parent.left
anchors.top: minimap.top anchors.top: parent.top
size: 60 60 size: 48 48
margin-top: 3 margin-top: 4
margin-left: 5 margin-left: 4
@onClick: function(...) Minimap.compassClick(...) end @onClick: function(...) Minimap.compassClick(...) end
UIButton UIButton
id: compassReset id: compassReset
text: Reset text: R
font: verdana-11px-rounded font: verdana-11px-rounded
anchors.left: compass.left anchors.centerIn: compass
anchors.top: compass.top margin-top: 2
margin-top: 25 margin-right: 1
margin-left: 14
@onClick: function(...) Minimap.center(...) end @onClick: function(...) Minimap.center(...) end
$pressed: $pressed:
color: #eb9f4f88 color: #eb9f4f88
margin-top: 26
margin-left: 15
$hover !pressed: $hover !pressed:
color: #eb9f4f color: #eb9f4f
$!pressed !hover: $!pressed !hover:
color: #ffffff color: #ffffff
margin-top: 25
margin-left: 14
$disabled: $disabled:
image-color: #ffffff88 image-color: #ffffff88
FloorUpControl FloorUpControl
id: floorUp id: floorUp
anchors.left: minimap.right anchors.right: parent.right
anchors.top: compass.bottom anchors.bottom: parent.bottom
margin-top: 10 margin-right: 28
margin-left: 15 margin-bottom: 28
enabled: true enabled: true
@onClick: Minimap.onButtonClick(self:getId()) @onClick: Minimap.onButtonClick(self:getId())
FloorDownControl FloorDownControl
id: floorDown id: floorDown
anchors.left: floorUp.left anchors.right: parent.right
anchors.top: floorUp.bottom anchors.bottom: parent.bottom
margin-top: 4 margin-right: 28
margin-bottom: 4
enabled: true enabled: true
@onClick: Minimap.onButtonClick(self:getId()) @onClick: Minimap.onButtonClick(self:getId())
Button Button
id: zoomIn id: zoomIn
text: + text: +
size: 16 16 size: 20 20
anchors.left: floorUp.right anchors.right: parent.right
anchors.top: floorUp.top anchors.bottom: parent.bottom
margin-left: 10 margin-right: 4
margin-bottom: 28
enabled: true enabled: true
@onClick: Minimap.onButtonClick(self:getId()) @onClick: Minimap.onButtonClick(self:getId())
@ -108,10 +101,11 @@ MiniWindow
id: zoomOut id: zoomOut
text: - text: -
font: terminus-14px-bold font: terminus-14px-bold
size: 16 16 size: 20 20
anchors.left: floorDown.right anchors.right: parent.right
anchors.top: floorDown.top anchors.bottom: parent.bottom
margin-left: 10 margin-right: 4
margin-bottom: 4
enabled: true enabled: true
@onClick: Minimap.onButtonClick(self:getId()) @onClick: Minimap.onButtonClick(self:getId())

View File

@ -218,6 +218,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setIconHeight", &UIWidget::setIconHeight); g_lua.bindClassMemberFunction<UIWidget>("setIconHeight", &UIWidget::setIconHeight);
g_lua.bindClassMemberFunction<UIWidget>("setIconSize", &UIWidget::setIconSize); g_lua.bindClassMemberFunction<UIWidget>("setIconSize", &UIWidget::setIconSize);
g_lua.bindClassMemberFunction<UIWidget>("setIconRect", &UIWidget::setIconRect); g_lua.bindClassMemberFunction<UIWidget>("setIconRect", &UIWidget::setIconRect);
g_lua.bindClassMemberFunction<UIWidget>("setIconClip", &UIWidget::setIconClip);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidth", &UIWidget::setBorderWidth); g_lua.bindClassMemberFunction<UIWidget>("setBorderWidth", &UIWidget::setBorderWidth);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthTop", &UIWidget::setBorderWidthTop); g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthTop", &UIWidget::setBorderWidthTop);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthRight", &UIWidget::setBorderWidthRight); g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthRight", &UIWidget::setBorderWidthRight);
@ -267,6 +268,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getIconHeight", &UIWidget::getIconHeight); g_lua.bindClassMemberFunction<UIWidget>("getIconHeight", &UIWidget::getIconHeight);
g_lua.bindClassMemberFunction<UIWidget>("getIconSize", &UIWidget::getIconSize); g_lua.bindClassMemberFunction<UIWidget>("getIconSize", &UIWidget::getIconSize);
g_lua.bindClassMemberFunction<UIWidget>("getIconRect", &UIWidget::getIconRect); g_lua.bindClassMemberFunction<UIWidget>("getIconRect", &UIWidget::getIconRect);
g_lua.bindClassMemberFunction<UIWidget>("getIconClip", &UIWidget::getIconClip);
g_lua.bindClassMemberFunction<UIWidget>("getBorderTopColor", &UIWidget::getBorderTopColor); g_lua.bindClassMemberFunction<UIWidget>("getBorderTopColor", &UIWidget::getBorderTopColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderRightColor", &UIWidget::getBorderRightColor); g_lua.bindClassMemberFunction<UIWidget>("getBorderRightColor", &UIWidget::getBorderRightColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderBottomColor", &UIWidget::getBorderBottomColor); g_lua.bindClassMemberFunction<UIWidget>("getBorderBottomColor", &UIWidget::getBorderBottomColor);

View File

@ -278,6 +278,7 @@ protected:
TexturePtr m_icon; TexturePtr m_icon;
Color m_iconColor; Color m_iconColor;
Rect m_iconRect; Rect m_iconRect;
Rect m_iconClipRect;
EdgeGroup<Color> m_borderColor; EdgeGroup<Color> m_borderColor;
EdgeGroup<int> m_borderWidth; EdgeGroup<int> m_borderWidth;
EdgeGroup<int> m_margin; EdgeGroup<int> m_margin;
@ -311,6 +312,7 @@ public:
void setIconHeight(int height) { m_iconRect.setHeight(height); } void setIconHeight(int height) { m_iconRect.setHeight(height); }
void setIconSize(const Size& size) { m_iconRect.resize(size); } void setIconSize(const Size& size) { m_iconRect.resize(size); }
void setIconRect(const Rect& rect) { m_iconRect = rect; } void setIconRect(const Rect& rect) { m_iconRect = rect; }
void setIconClip(const Rect& rect) { m_iconClipRect = rect; }
void setBorderWidth(int width) { m_borderWidth.set(width); updateLayout(); } void setBorderWidth(int width) { m_borderWidth.set(width); updateLayout(); }
void setBorderWidthTop(int width) { m_borderWidth.top = width; } void setBorderWidthTop(int width) { m_borderWidth.top = width; }
void setBorderWidthRight(int width) { m_borderWidth.right = width; } void setBorderWidthRight(int width) { m_borderWidth.right = width; }
@ -361,6 +363,7 @@ public:
int getIconHeight() { return m_iconRect.height(); } int getIconHeight() { return m_iconRect.height(); }
Size getIconSize() { return m_iconRect.size(); } Size getIconSize() { return m_iconRect.size(); }
Rect getIconRect() { return m_iconRect; } Rect getIconRect() { return m_iconRect; }
Rect getIconClip() { return m_iconClipRect; }
Color getBorderTopColor() { return m_borderColor.top; } Color getBorderTopColor() { return m_borderColor.top; }
Color getBorderRightColor() { return m_borderColor.right; } Color getBorderRightColor() { return m_borderColor.right; }
Color getBorderBottomColor() { return m_borderColor.bottom; } Color getBorderBottomColor() { return m_borderColor.bottom; }

View File

@ -100,6 +100,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
setIconSize(node->value<Size>()); setIconSize(node->value<Size>());
else if(node->tag() == "icon-rect") else if(node->tag() == "icon-rect")
setIconRect(node->value<Rect>()); setIconRect(node->value<Rect>());
else if(node->tag() == "icon-clip")
setIconClip(node->value<Rect>());
else if(node->tag() == "opacity") else if(node->tag() == "opacity")
setOpacity(node->value<float>()); setOpacity(node->value<float>());
else if(node->tag() == "enabled") else if(node->tag() == "enabled")
@ -369,15 +371,17 @@ void UIWidget::drawIcon(const Rect& screenCoords)
drawRect.translate(m_iconRect.topLeft()); drawRect.translate(m_iconRect.topLeft());
drawRect.resize(m_iconRect.size()); drawRect.resize(m_iconRect.size());
} else { } else {
drawRect.resize(m_icon->getSize()); drawRect.resize(m_iconClipRect.size());
drawRect.moveCenter(screenCoords.center()); drawRect.moveCenter(screenCoords.center());
} }
g_painter->setColor(m_iconColor); g_painter->setColor(m_iconColor);
g_painter->drawTexturedRect(drawRect, m_icon); g_painter->drawTexturedRect(drawRect, m_icon, m_iconClipRect);
} }
} }
void UIWidget::setIcon(const std::string& iconFile) void UIWidget::setIcon(const std::string& iconFile)
{ {
m_icon = g_textures.getTexture(iconFile); m_icon = g_textures.getTexture(iconFile);
if(!m_iconClipRect.isValid())
m_iconClipRect = Rect(0, 0, m_icon->getSize());
} }