Improve game map view modes
This commit is contained in:
parent
5b65088426
commit
a8fbd6cdfc
|
@ -12,6 +12,8 @@ countWindow = nil
|
|||
logoutWindow = nil
|
||||
exitWindow = nil
|
||||
bottomSplitter = nil
|
||||
limitZoom = false
|
||||
currentViewMode = 0
|
||||
|
||||
lastDir = nil
|
||||
walkEvent = nil
|
||||
|
@ -52,6 +54,8 @@ function init()
|
|||
|
||||
logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'), '/images/topbuttons/logout', tryLogout, true)
|
||||
|
||||
setupViewMode(0)
|
||||
|
||||
bindKeys()
|
||||
|
||||
if g_game.isOnline() then
|
||||
|
@ -93,7 +97,7 @@ function bindKeys()
|
|||
g_keyboard.bindKeyDown('Ctrl+L', logout, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+N', function() gameMapPanel:setDrawTexts(not gameMapPanel:isDrawingTexts()) end, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+.', toggleAlternativeView, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel)
|
||||
end
|
||||
|
||||
function terminate()
|
||||
|
@ -270,21 +274,11 @@ function smartWalk(defaultDir)
|
|||
end
|
||||
|
||||
function updateStretchShrink()
|
||||
if modules.client_options.getOption('dontStretchShrink') then
|
||||
gameMapPanel:setKeepAspectRatio(true)
|
||||
if modules.client_options.getOption('dontStretchShrink') and not alternativeView then
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
|
||||
-- Set gameMapPanel size to height = 11 * 32
|
||||
bottomSplitter:setMarginBottom(bottomSplitter:getMarginBottom() + (gameMapPanel:getHeight() - 32 * 11) - 10)
|
||||
end
|
||||
end
|
||||
|
||||
function toggleAspectRatio()
|
||||
if gameMapPanel:isKeepAspectRatioEnabled() then
|
||||
gameMapPanel:setKeepAspectRatio(false)
|
||||
else
|
||||
gameMapPanel:setKeepAspectRatio(true)
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
-- Set gameMapPanel size to height = 11 * 32 + 2
|
||||
bottomSplitter:setMarginBottom(bottomSplitter:getMarginBottom() + (gameMapPanel:getHeight() - 32 * 11) - 10)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -311,7 +305,6 @@ function onUseWith(clickedWidget, mousePosition)
|
|||
if clickedWidget:getClassName() == 'UIMap' then
|
||||
local tile = clickedWidget:getTile(mousePosition)
|
||||
if tile then
|
||||
print('use on' .. tile:getTopMultiUseThing():getClassName())
|
||||
g_game.useWith(selectedThing, tile:getTopMultiUseThing())
|
||||
end
|
||||
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
||||
|
@ -655,25 +648,14 @@ function onLeftPanelVisibilityChange(leftPanel, visible)
|
|||
end
|
||||
end
|
||||
|
||||
function toggleAlternativeView()
|
||||
if gameMapPanel:isKeepAspectRatioEnabled() then
|
||||
gameMapPanel:setKeepAspectRatio(false)
|
||||
gameMapPanel:setZoom(14)
|
||||
gameMapPanel:fill('parent')
|
||||
gameRootPanel:fill('parent')
|
||||
gameLeftPanel:setImageColor('alpha')
|
||||
gameRightPanel:setImageColor('alpha')
|
||||
gameLeftPanel:setMarginTop(36)
|
||||
gameRightPanel:setMarginTop(36)
|
||||
gameLeftPanel:setOn(true)
|
||||
gameLeftPanel:setVisible(true)
|
||||
gameRightPanel:setOn(true)
|
||||
gameBottomPanel:setImageColor('#00000099')
|
||||
modules.client_topmenu.getTopMenu():setImageColor('#ffffff66')
|
||||
g_game.changeMapAwareRange(24, 20)
|
||||
else
|
||||
gameMapPanel:setKeepAspectRatio(true)
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
function nextViewMode()
|
||||
setupViewMode((currentViewMode + 1) % 3)
|
||||
end
|
||||
|
||||
function setupViewMode(mode)
|
||||
if mode == currentViewMode then return end
|
||||
|
||||
if currentViewMode == 2 then
|
||||
gameMapPanel:addAnchor(AnchorLeft, 'gameLeftPanel', AnchorRight)
|
||||
gameMapPanel:addAnchor(AnchorRight, 'gameRightPanel', AnchorLeft)
|
||||
gameMapPanel:addAnchor(AnchorBottom, 'gameBottomPanel', AnchorTop)
|
||||
|
@ -688,4 +670,42 @@ function toggleAlternativeView()
|
|||
modules.client_topmenu.getTopMenu():setImageColor('white')
|
||||
g_game.changeMapAwareRange(18, 14)
|
||||
end
|
||||
|
||||
if mode == 0 then
|
||||
gameMapPanel:setKeepAspectRatio(true)
|
||||
gameMapPanel:setLimitVisibleRange(false)
|
||||
gameMapPanel:setZoom(11)
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
elseif mode == 1 then
|
||||
gameMapPanel:setKeepAspectRatio(false)
|
||||
gameMapPanel:setLimitVisibleRange(true)
|
||||
gameMapPanel:setZoom(11)
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
elseif mode == 2 then
|
||||
gameMapPanel:setLimitVisibleRange(limitZoom)
|
||||
gameMapPanel:setZoom(11)
|
||||
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
|
||||
gameMapPanel:fill('parent')
|
||||
gameRootPanel:fill('parent')
|
||||
gameLeftPanel:setImageColor('alpha')
|
||||
gameRightPanel:setImageColor('alpha')
|
||||
gameLeftPanel:setMarginTop(36)
|
||||
gameRightPanel:setMarginTop(36)
|
||||
gameLeftPanel:setOn(true)
|
||||
gameLeftPanel:setVisible(true)
|
||||
gameRightPanel:setOn(true)
|
||||
gameBottomPanel:setImageColor('#00000099')
|
||||
modules.client_topmenu.getTopMenu():setImageColor('#ffffff66')
|
||||
if not limitZoom then
|
||||
g_game.changeMapAwareRange(24, 20)
|
||||
end
|
||||
end
|
||||
|
||||
currentViewMode = mode
|
||||
end
|
||||
|
||||
function limitZoom()
|
||||
limitZoom = true
|
||||
gameMapPanel:setMaxZoomOut(11)
|
||||
gameMapPanel:setLimitVisibleRange(true)
|
||||
end
|
||||
|
|
|
@ -555,10 +555,12 @@ void Client::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UIMap>("setKeepAspectRatio", &UIMap::setKeepAspectRatio);
|
||||
g_lua.bindClassMemberFunction<UIMap>("setMapShader", &UIMap::setMapShader);
|
||||
g_lua.bindClassMemberFunction<UIMap>("setMinimumAmbientLight", &UIMap::setMinimumAmbientLight);
|
||||
g_lua.bindClassMemberFunction<UIMap>("setLimitVisibleRange", &UIMap::setLimitVisibleRange);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isMultifloor", &UIMap::isMultifloor);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isAutoViewModeEnabled", &UIMap::isAutoViewModeEnabled);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isDrawingTexts", &UIMap::isDrawingTexts);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isDrawingLights", &UIMap::isDrawingLights);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isLimitVisibleRangeEnabled", &UIMap::isLimitVisibleRangeEnabled);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isAnimating", &UIMap::isAnimating);
|
||||
g_lua.bindClassMemberFunction<UIMap>("isKeepAspectRatioEnabled", &UIMap::isKeepAspectRatioEnabled);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getVisibleDimension", &UIMap::getVisibleDimension);
|
||||
|
|
|
@ -33,9 +33,11 @@ UIMap::UIMap()
|
|||
m_draggable = true;
|
||||
m_mapView = MapViewPtr(new MapView);
|
||||
m_zoom = m_mapView->getVisibleDimension().height();
|
||||
m_aspectRatio = 0.0f;
|
||||
m_keepAspectRatio = true;
|
||||
m_limitVisibleRange = false;
|
||||
m_aspectRatio = m_mapView->getVisibleDimension().ratio();
|
||||
m_maxZoomIn = 3;
|
||||
m_maxZoomOut = 512;
|
||||
m_maxZoomOut = 513;
|
||||
m_mapRect.resize(1,1);
|
||||
g_map.addMapView(m_mapView);
|
||||
}
|
||||
|
@ -78,7 +80,10 @@ bool UIMap::setZoom(int zoom)
|
|||
bool UIMap::zoomIn()
|
||||
{
|
||||
int delta = 2;
|
||||
if(m_zoom - delta <= m_maxZoomIn)
|
||||
if(m_zoom - delta < m_maxZoomIn)
|
||||
delta--;
|
||||
|
||||
if(m_zoom - delta < m_maxZoomIn)
|
||||
return false;
|
||||
|
||||
m_zoom -= delta;
|
||||
|
@ -89,7 +94,10 @@ bool UIMap::zoomIn()
|
|||
bool UIMap::zoomOut()
|
||||
{
|
||||
int delta = 2;
|
||||
if(m_zoom + delta >= m_maxZoomOut)
|
||||
if(m_zoom + delta > m_maxZoomOut)
|
||||
delta--;
|
||||
|
||||
if(m_zoom + delta > m_maxZoomOut)
|
||||
return false;
|
||||
|
||||
m_zoom += 2;
|
||||
|
@ -100,19 +108,17 @@ bool UIMap::zoomOut()
|
|||
void UIMap::setVisibleDimension(const Size& visibleDimension)
|
||||
{
|
||||
m_mapView->setVisibleDimension(visibleDimension);
|
||||
m_aspectRatio = visibleDimension.ratio();
|
||||
|
||||
if(m_aspectRatio != 0.0f) {
|
||||
m_aspectRatio = visibleDimension.ratio();
|
||||
if(m_keepAspectRatio)
|
||||
updateMapSize();
|
||||
}
|
||||
}
|
||||
|
||||
void UIMap::setKeepAspectRatio(bool enable)
|
||||
{
|
||||
m_keepAspectRatio = enable;
|
||||
if(enable)
|
||||
m_aspectRatio = getVisibleDimension().ratio();
|
||||
else
|
||||
m_aspectRatio = 0.0f;
|
||||
updateMapSize();
|
||||
}
|
||||
|
||||
|
@ -196,8 +202,8 @@ void UIMap::updateVisibleDimension()
|
|||
{
|
||||
int dimensionHeight = m_zoom;
|
||||
|
||||
float ratio = 1;
|
||||
if(!m_mapRect.isEmpty())
|
||||
float ratio = m_aspectRatio;
|
||||
if(!m_limitVisibleRange && !m_mapRect.isEmpty() && !m_keepAspectRatio)
|
||||
ratio = m_mapRect.size().ratio();
|
||||
|
||||
if(dimensionHeight % 2 == 0)
|
||||
|
@ -208,7 +214,7 @@ void UIMap::updateVisibleDimension()
|
|||
|
||||
m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
|
||||
|
||||
if(m_aspectRatio != 0.0f)
|
||||
if(m_keepAspectRatio)
|
||||
updateMapSize();
|
||||
}
|
||||
|
||||
|
@ -216,7 +222,7 @@ void UIMap::updateMapSize()
|
|||
{
|
||||
Rect clippingRect = getPaddingRect();
|
||||
Size mapSize;
|
||||
if(m_aspectRatio != 0.0f) {
|
||||
if(m_keepAspectRatio) {
|
||||
Rect mapRect = clippingRect.expanded(-1);
|
||||
mapSize = Size(m_aspectRatio*m_zoom, m_zoom);
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
|
@ -228,6 +234,6 @@ void UIMap::updateMapSize()
|
|||
m_mapRect.moveCenter(clippingRect.center());
|
||||
m_mapView->optimizeForSize(mapSize);
|
||||
|
||||
if(m_aspectRatio == 0.0f)
|
||||
if(!m_keepAspectRatio)
|
||||
updateVisibleDimension();
|
||||
}
|
||||
|
|
|
@ -56,13 +56,15 @@ public:
|
|||
void setKeepAspectRatio(bool enable);
|
||||
void setMapShader(const PainterShaderProgramPtr& shader, float fadeout, float fadein) { m_mapView->setShader(shader, fadein, fadeout); }
|
||||
void setMinimumAmbientLight(float intensity) { m_mapView->setMinimumAmbientLight(intensity); }
|
||||
void setLimitVisibleRange(bool limitVisibleRange) { m_limitVisibleRange = limitVisibleRange; updateVisibleDimension(); }
|
||||
|
||||
bool isMultifloor() { return m_mapView->isMultifloor(); }
|
||||
bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); }
|
||||
bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
|
||||
bool isDrawingLights() { return m_mapView->isDrawingLights(); }
|
||||
bool isAnimating() { return m_mapView->isAnimating(); }
|
||||
bool isKeepAspectRatioEnabled() { return m_aspectRatio != 0.0f; }
|
||||
bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }
|
||||
bool isLimitVisibleRangeEnabled() { return m_limitVisibleRange; }
|
||||
|
||||
Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
|
||||
MapView::ViewMode getViewMode() { return m_mapView->getViewMode(); }
|
||||
|
@ -89,6 +91,8 @@ private:
|
|||
MapViewPtr m_mapView;
|
||||
Rect m_mapRect;
|
||||
float m_aspectRatio;
|
||||
bool m_keepAspectRatio;
|
||||
bool m_limitVisibleRange;
|
||||
int m_maxZoomIn;
|
||||
int m_maxZoomOut;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue