ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   rotate an image while incombat (https://www.esoui.com/forums/showthread.php?t=10460)

sinnereso 02/19/23 03:26 PM

rotate an image while incombat
 
Looking for some help rotating an image like an hourglass while in combat.. Ive tried many WHILE and IF setups but every one freezes the game.

Im looking basically to do this :

Code:

zo_callLater(function() TeleportHourglass:SetTransformRotationZ(math.rad(45)) end, effectDelay)-- test
the entire time before this executes when combat ends:

Code:

EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_PLAYER_COMBAT_STATE, RidinDirty.TeleportQueue)

Basically im looking to be able to repeat the following or something similarly effective, looped until combat ends and then jump to new code:
Code:

zo_callLater(function() TeleportHourglass:SetTransformRotationZ(math.rad(45)) end, effectDelay)-- test

Masteroshi430 02/19/23 03:38 PM

Quote:

Originally Posted by sinnereso (Post 47234)
Looking for some help rotating an image like an hourglass while in combat.. Ive tried many WHILE and IF setups but every one freezes the game.

Im looking basically to do this :

Code:

zo_callLater(function() TeleportHourglass:SetTransformRotationZ(math.rad(45)) end, effectDelay)-- test
the entire time before this executes when combat ends:

Code:

EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_PLAYER_COMBAT_STATE, RidinDirty.TeleportQueue)

Basically im looking to be able to repeat the following or something similarly effective, looped until combat ends and then jump to new code:
Code:

zo_callLater(function() TeleportHourglass:SetTransformRotationZ(math.rad(45)) end, effectDelay)-- test

SetTransformRotationZ(math.rad(45)) does not rotate the texture by 45°, it sets the texture to a 45° position, if you want a rotation effect you'll have to increment or decrement the value by 1 or a bigger number each time that part of code is called.

EDIT:
Inspect the code in the function FyrMM.CheapAnimation(pin, rotate) in my Minimap by Fyrakin version, I use it to make the world event cyclon texture spin when it's active.

sirinsidiator 02/19/23 05:38 PM

Or use the animation framework the game already provides instead of setting properties in your own code manually. ;)
You can find an example of how it is used in the ui source code.
"LoadIconAnimation" rotates a texture by 360° every 1.5 seconds as defined here.

sinnereso 02/19/23 06:51 PM

Quote:

Originally Posted by sirinsidiator (Post 47236)
Or use the animation framework the game already provides instead of setting properties in your own code manually. ;)
You can find an example of how it is used in the ui source code.
"LoadIconAnimation" rotates a texture by 360° every 1.5 seconds as defined here.

Thats looks very much like what im looking for but looks like XML which I haven't touched on yet. Im trying to keep it basic and no dependencies while also learning how it all works. Is there anyway to rotate "/esoui/art/screens_app/load_ourosboros.dds" with something like that in LUA during a short function?

Or maybe what I should be asking is.. How do I call that function to load and rotate "/esoui/art/screens_app/load_ourosboros.dds" while i want it to and then shut it down after? I havent the slightest how to make sense or use of that XML yet.

sinnereso 02/20/23 01:02 AM

this seems mind blowing but i assume i need to create the window and the control 1st with the image and then animate it? Heres kinda what im working with so far.. no errors but no animation either just image. I feel im close but missing something.

Code:

function Initialize()
        hourglass = WINDOW_MANAGER:CreateTopLevelWindow("TeleportHourglass")
        hourglass:SetDimensions(128,128)
        hourglass:SetAnchor(CENTER, GuiRoot, TOP, 0, 260)
        hourglass:SetHidden(true)
        image = WINDOW_MANAGER:CreateControl("TeleportHourglassImage", hourglass, CT_TEXTURE)
        image:SetAnchorFill(hourglass)
        TeleportHourglassImage:SetTexture("/esoui/art/screens_app/load_ourosboros.dds")
        hourglass.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("LoadIconAnimation", GetControl(image, "/esoui/art/screens_app/load_ourosboros.dds"))
end

function to turn it on()
        hourglass:SetHidden(false)
        hourglass.animation:PlayForward()
end

function to turn it off()
        hourglass:SetHidden(true)
        hourglass.animation:Stop()
end


Masteroshi430 02/20/23 02:09 AM

wiki:
https://wiki.esoui.com/How_to_animate_textures
which just sends to this thread:
https://www.esoui.com/forums/showthread.php?t=1191

The animation manager is till very obscure to me though...

sinnereso 02/20/23 02:22 AM

Quote:

Originally Posted by Masteroshi430 (Post 47240)
wiki:
https://wiki.esoui.com/How_to_animate_textures
which just sends to this thread:
https://www.esoui.com/forums/showthread.php?t=1191

The animation manager is till very obscure to me though...

Ya it is for me as well... I think the truth is somewhere between what ive got so far and your links :)

sirinsidiator 02/20/23 06:01 AM

You almost got it right. Instead of GetControl(image, "/esoui/art/screens_app/load_ourosboros.dds") you need to pass the image to it directly though.
GetControl is used to get a control by name, so passing a texture path to it doesn't make any sense.
Lua Code:
  1. local image = WINDOW_MANAGER:CreateControl("TeleportHourglassImage", hourglass, CT_TEXTURE) -- do not forget to make it local, otherwise it may overwrite a global variable and mess things up for the ingame ui or other addons!
  2. image:SetAnchorFill(hourglass)
  3. image:SetTexture("/esoui/art/screens_app/load_ourosboros.dds") -- no point in doing that via the global variable when you already have it locally
  4. hourglass.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("LoadIconAnimation", image)

You don't have to mess with xml if you do not want to do that yet. You can just use the existing animation templates.
It's also possible to modify them in Lua once you created it, but I don't really recommend it, as it's bad for long-term maintainability of your addon.
Lua Code:
  1. hourglass.animation:GetFirstAnimation():SetDuration(3000) -- set it to 3s
Simply defining the whole animation template in XML is much better in that regard.


EDIT: you should also take care to make your variables local or store them on a table your addon "owns". Otherwise you may accidentally overwrite something somewhere that is out of your scope and break stuff.

sinnereso 02/20/23 10:53 AM

MOst of that makes sense thank you! with the exception of point 2 and 3:

2. image:SetAnchorFill(hourglass)
3. image:SetTexture("/esoui/art/screens_app/load_ourosboros.dds") -- no point in doing that via the global variable when you already have it locally

its unclear what u were suggesting for #2 and for #3 if i dont load the "/esoui/art/screens_app/load_ourosboros.dds" there then how will it load that image as thats the only place its even mentioned?

sirinsidiator 02/20/23 11:22 AM

the comment was regarding how you accessed the image in your original code:
Lua Code:
  1. TeleportHourglassImage:SetTexture("/esoui/art/screens_app/load_ourosboros.dds")
You already have "image" locally. Why access it via the global variable "TeleportHourglassImage"?

sinnereso 02/20/23 11:31 AM

Quote:

Originally Posted by sirinsidiator (Post 47251)
the comment was regarding how you accessed the image in your original code:
Lua Code:
  1. TeleportHourglassImage:SetTexture("/esoui/art/screens_app/load_ourosboros.dds")
You already have "image" locally. Why access it via the global variable "TeleportHourglassImage"?

i assumed that was linking back to that line.. or is "image" somehow the image im looking for by default? Becausr that is the only place in my code where ive specified which image to use as in "/esoui/art/screens_app/load_ourosboros.dds" is nowhere else in my addon.

also got it animating!!! with that line so far... now just trying to put a text label on it thats visible.. its just a waiting for combat to end message and hourglass for a teleport function i have.. I wanted something visible so you knew its still running or waiting.

sinnereso 02/20/23 12:41 PM

Quote:

Originally Posted by sirinsidiator (Post 47251)
the comment was regarding how you accessed the image in your original code:
Lua Code:
  1. TeleportHourglassImage:SetTexture("/esoui/art/screens_app/load_ourosboros.dds")
You already have "image" locally. Why access it via the global variable "TeleportHourglassImage"?

got it all working and label too!! ty guys soo much.. now maybe a sound? like playsound()? im gonna look that up now :)

sinnereso 02/20/23 01:14 PM

ok got the sound working too yay!! now one last thing.. Id like it to toggle on and off during combat if you press it again. im working with this section now only and like only the if statement line. What im wanting is repeated presses check if the animation is visible and if it is turn it off and the combat state monitoring etc like you see below:

Code:

if IsHidden(hourglass) == (false) then
        EVENT_MANAGER:UnregisterForEvent("RidinDirty", EVENT_PLAYER_COMBAT_STATE)
        PlaySound("GuildRoster_Added")
        hourglass:SetHidden(true)
        hourglass.animation:Stop()
        return
else
        EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_PLAYER_COMBAT_STATE, RidinDirty.TeleportQueue)
        PlaySound("GuildRoster_Added")
        hourglass:SetHidden(false)
        hourglass.animation:PlayForward()
        eturn
end


sinnereso 02/20/23 01:29 PM

nevermind i got it!! thank you all so much for all the help.. i love this little tool :)

Code:

if not hourglass:IsHidden() then
this beauty did the trick :)


All times are GMT -6. The time now is 09:19 AM.

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