ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Calling a function when zoom level has changed? (https://www.esoui.com/forums/showthread.php?t=10172)

Masteroshi430 05/10/22 12:15 PM

Calling a function when zoom level has changed?
 
Hi guys,
Is it possible to call a function when the zoom level has changed?
I try to avoid using "OnUpdate" aiming at performance optimization.

Baertram 05/10/22 12:23 PM

I'd check what keybind is used for the zoom in and zoom out at the controls, chck that at the lua file where the settings menu for those controls are created (keybindings) and check what function is used there.
Maybe you can use ZO_PreHook or SecurePostHook on it to react on the zoom change then.

esoui/ingame/globals/bindings.xml
<Category name="SI_KEYBINDINGS_CATEGORY_CAMERA">
<Action name="CAMERA_ZOOM_OUT">
<Down>CameraZoomOut()</Down>
</Action>

<Action name="CAMERA_ZOOM_IN">
<Down>CameraZoomIn()</Down>
</Action>

Func names are CameraZoomIn and CameraZoomOut

Test if they are protected via IsProtectedFunction("CameraZoomIn") or not.
Looks like it isn't so a SecurePostHook should/could work.

Lua Code:
  1. SecurePostHook("CameraZoomIn", function()
  2.     d("Zooming in")
  3. end)
  4. SecurePostHook("CameraZoomOut", function()
  5.     d("Zooming out")
  6. end)

Yep, tested, works

Masteroshi430 05/10/22 02:25 PM

Thanks Beatram,
I forgot to mention that was for the map zoom, I tried "WorldMapZoom" and many other things without success.

"ZO_WorldMapZoomMinus_OnClicked" and "ZO_WorldMapZoomPlus_OnClicked" work but only when you click the + and - button of the zoom.

"ZO_WorldMapZoom_OnMouseWheel" doesn't work

edit: ah : "ZO_WorldMap_MouseWheel" works! :banana:

Baertram 05/10/22 02:36 PM

Try function ZO_MapPanAndZoom:SetCurrentNormalizedZoomInternal(normalizedZoom)
It seems to be called from internal local functions as you click the zoom slider and maybe also if you use the mousewheel as it is called from different zoom functions there (normalized, curved etc.)

The object is stored in the local g_mapPanAndZoom which is returned by function ZO_WorldMap_GetPanAndZoom()

Lua Code:
  1. local mapPanAndZoom = ZO_WorldMap_GetPanAndZoom()
  2. SecurePostHook(mapPanAndZoom , "SetCurrentNormalizedZoomInternal", function(selfMapPanAndZoom, normalizedZoom)
  3. d("normalizedZoom: " ..tostring(normalizedZoom))
  4. end)

If this is not the correct one that will fire as you use the mouse wheel check any other of the update/set functions there, e.g.
:OnMouseWheel(delta)
which will call AddZoomDelta
which calls SetLockedNormalizedZoom
which calls SetTargetNormalizedZoom

Masteroshi430 05/10/22 03:13 PM

Thanks again, it works wonderfully :)


All times are GMT -6. The time now is 05:52 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI