Thread Tools Display Modes
02/19/23, 03:26 PM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Question 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

Last edited by sinnereso : 02/19/23 at 03:29 PM.
  Reply With Quote
02/19/23, 03:38 PM   #2
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by sinnereso View Post
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.

Last edited by Masteroshi430 : 02/19/23 at 03:50 PM.
  Reply With Quote
02/19/23, 05:38 PM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
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.
  Reply With Quote
02/19/23, 06:51 PM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by sirinsidiator View Post
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.

Last edited by sinnereso : 02/19/23 at 07:05 PM.
  Reply With Quote
02/20/23, 01:02 AM   #5
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
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

Last edited by sinnereso : 02/20/23 at 01:11 AM.
  Reply With Quote
02/20/23, 02:09 AM   #6
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
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...
  Reply With Quote
02/20/23, 02:22 AM   #7
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Masteroshi430 View Post
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
  Reply With Quote
02/20/23, 06:01 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
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.

Last edited by sirinsidiator : 02/20/23 at 06:04 AM.
  Reply With Quote
02/20/23, 10:53 AM   #9
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
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?
  Reply With Quote
02/20/23, 11:22 AM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
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"?
  Reply With Quote
02/20/23, 11:31 AM   #11
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by sirinsidiator View Post
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.
  Reply With Quote
02/20/23, 12:41 PM   #12
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by sirinsidiator View Post
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
  Reply With Quote
02/20/23, 01:14 PM   #13
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
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

Last edited by sinnereso : 02/20/23 at 01:16 PM.
  Reply With Quote
02/20/23, 01:29 PM   #14
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
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
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » rotate an image while incombat

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off