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