• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient Game Map Anchors

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
57
Hey guys,

I want to position a widget where is that red square, anchored inside the game map view.

I already tested anchor in the gameMapPanel, but it positions it outside the game map view.

Does anyone know how I could do this?

img-anchors.png
 
Solution

Unfortunately, the game screen area is not a separeted widget.
The game screen area is the same widget of the game map panel.
It means, you need to anchor it by another way and then set a calculated margin-left and margin-top.

Something like that:

Lua:
-- This, you need to set only once in yourWidget
-- Attaching to gameRootPanel is to be able to move your widget anywhere
yourWidget:setAnchor(AnchorTop, 'gameRootPanel', AnchorTop) -- Anchors yourWidget top on top of gameRootPanel
yourWidget:setAnchor(AnchorLeft, 'gameRootPanel', AnchorLeft) -- Anchors yourWidget left on left of gameRootPanel

Lua:
-- This, you need to set for view mode that is not full screen
local mapWidget = modules.game_interface.getMapPanel()
local...
Come to think of it, As I already have the gameMapView, I just need to have the maximum height and width game map view.

But how to do that? I have already reviewed all OtClient files and found nothing.

It would basically be that:

Code:
mapPanel = modules.game_interface.getMapPanel()

mapWidth = mapPanel:getWidth()
mapHeight = mapPanel:getHeight()

gameMapViewX = ???
gameMapViewY = ???

X = (mapWidth - gameMapViewX) / 2
Y = mapHeight - gameMapViewY

MyNewModule:setX(X)
MyNewModule:setY(Y)
 
Last edited:

Unfortunately, the game screen area is not a separeted widget.
The game screen area is the same widget of the game map panel.
It means, you need to anchor it by another way and then set a calculated margin-left and margin-top.

Something like that:

Lua:
-- This, you need to set only once in yourWidget
-- Attaching to gameRootPanel is to be able to move your widget anywhere
yourWidget:setAnchor(AnchorTop, 'gameRootPanel', AnchorTop) -- Anchors yourWidget top on top of gameRootPanel
yourWidget:setAnchor(AnchorLeft, 'gameRootPanel', AnchorLeft) -- Anchors yourWidget left on left of gameRootPanel

Lua:
-- This, you need to set for view mode that is not full screen
local mapWidget = modules.game_interface.getMapPanel()
local yourWidgetTopMargin = 4
local yourWidgetLeftMargin = 4
local mapWidgetMarginTop = mapWidget:getY() -- Top margin of mapWidget (which is the top menu height)
local mapWidgetMarginLeft = mapWidget:getX() -- Left margin of mapWidget (which is the left panels width)
local gameScreenAreaMarginTop = math.floor( ( mapWidget:getHeight() - mapWidget:getMapHeight() ) / 2 ) -- Top margin between mapWidget and the game screen area
local gameScreenAreaMarginLeft = math.floor( ( mapWidget:getWidth() - mapWidget:getMapWidth() ) / 2 ) -- Left margin between mapWidget and the game screen area

yourWidget:setMarginTop( yourWidgetTopMargin + mapWidgetMarginTop + gameScreenAreaMarginTop )
yourWidget:setMarginLeft( yourWidgetLeftMargin + mapWidgetMarginLeft + gameScreenAreaMarginLeft )

The problem is that, if you have view modes (since is OTClient, you can change your view mode with shortcut Ctrl+.), it won't work for the full screen view mode.
It means that, in the full screen view mode, your widget would be below the left panel.
To fix that, you need to set a different margin left only for the full screen mode: for the top margin, exactly the top menu height + yourWidgetTopMargin; and, for the left margin, exactly the left panels width + yourWidgetLeftMargin.

Once you change back to non full screen view mode, you should back the previous top and left margins.

Good luck with that.
 
Solution
Unfortunately, the game screen area is not a separeted widget.
The game screen area is the same widget of the game map panel.
It means, you need to anchor it by another way and then set a calculated margin-left and margin-top.

Something like that:

Lua:
-- This, you need to set only once in yourWidget
-- Attaching to gameRootPanel is to be able to move your widget anywhere
yourWidget:setAnchor(AnchorTop, 'gameRootPanel', AnchorTop) -- Anchors yourWidget top on top of gameRootPanel
yourWidget:setAnchor(AnchorLeft, 'gameRootPanel', AnchorLeft) -- Anchors yourWidget left on left of gameRootPanel

Lua:
-- This, you need to set for view mode that is not full screen
local mapWidget = modules.game_interface.getMapPanel()
local yourWidgetTopMargin = 4
local yourWidgetLeftMargin = 4
local mapWidgetMarginTop = mapWidget:getY() -- Top margin of mapWidget (which is the top menu height)
local mapWidgetMarginLeft = mapWidget:getX() -- Left margin of mapWidget (which is the left panels width)
local gameScreenAreaMarginTop = math.floor( ( mapWidget:getHeight() - mapWidget:getMapHeight() ) / 2 ) -- Top margin between mapWidget and the game screen area
local gameScreenAreaMarginLeft = math.floor( ( mapWidget:getWidth() - mapWidget:getMapWidth() ) / 2 ) -- Left margin between mapWidget and the game screen area

yourWidget:setMarginTop( yourWidgetTopMargin + mapWidgetMarginTop + gameScreenAreaMarginTop )
yourWidget:setMarginLeft( yourWidgetLeftMargin + mapWidgetMarginLeft + gameScreenAreaMarginLeft )

The problem is that, if you have view modes (since is OTClient, you can change your view mode with shortcut Ctrl+.), it won't work for the full screen view mode.
It means that, in the full screen view mode, your widget would be below the left panel.
To fix that, you need to set a different margin left only for the full screen mode: for the top margin, exactly the top menu height + yourWidgetTopMargin; and, for the left margin, exactly the left panels width + yourWidgetLeftMargin.

Once you change back to non full screen view mode, you should back the previous top and left margins.

Good luck with that.

Thanks for your time River,

I just have a error in this part "mapWidget:getMapWidth()", its a nil value.
 
Thanks for your time River,

I just have a error in this part "mapWidget:getMapWidth()", its a nil value.

Sorry. Forgot that was a custom code of mine.

1. Add this within src/client/uimap.h in public functions:
C++:
int getMapWidth() { return m_mapRect.width(); }
int getMapHeight() { return m_mapRect.height(); }

2. Add this within src/client/luafunctions.cpp after functions of UIMap (after line g_lua.registerClass<UIMap, UIWidget>();):
C++:
g_lua.bindClassMemberFunction<UIMap>("getMapWidth", &UIMap::getMapWidth);
g_lua.bindClassMemberFunction<UIMap>("getMapHeight", &UIMap::getMapHeight);
Like that:
1608673034284.png

3. Compile and test it again.
 
Back
Top