Dynamic frame resize, whilst in combat?
Hi there, first post here and a newbie member so thank you for taking the time to read this..
I am an experienced asm/c/c++ programmer that loves wow and am having a go at writing my first addon. I have no problems with events, frames, textures and understanding coding in general. The problem I have is this.. I am creating a target unit frame ( a simple one ) and all I want it to do right now is dynamically change its width based on the width of the targets name. I have the frame with some text for the name of the target all doing what it should except for combat... now you see my problem, I can't change the width of the frame whilst in combat to match the width of the new targets name, not allowed and I get why. Thing is I have seen frames dynamically resize whilst in combat.. i.e raid frames, so it must be possible... Now I think I need to be involved with RegisterStateDriver and secure frame wrapscript etc.. I mean I have a secure frame, that's easy, and I understand setting attributes, however I don't know how to respond to a change of target in the frames secure environment. I do hope this makes sense.. or you get the idea of what i'm trying to do.... should be simple to do I think, but I just can't see it. Thank you all for reading Kind regards v p.s I have posted this in the wrong forum, I'm very sorry, could a mod please move it for me? Thank you. |
Anything clickable for combat, such as buttons or in this case the target frame, cannot be altered while in combat. The raid frames adding people in combat is Blizzard's secure code, which is why they can change. There is very limited options for custom secure code, and moving/resizing is not included.
If you're okay with making a custom target frame that can't be clicked, then you can do whatever you want to it in combat. It could also be possible for a custom static frame with 0 alpha overlaying a frame that can't be clicked, so you can make it look like the target frame is clickable but can still resize visually, but that's beyond me. |
Oh, so it's not possible. That's a pain! The problem with an overlay frame is that it would have to be anchored to the secure frame, which as I understand it would make the overlay frame implicitly secure too, if I have understood correctly.
It'a a shame it can't be done. I've seen examples of wrapping arbitrary insecure snippets using 'secureFrame:WrapScript' which essentially executes addon insecure code in a secure environment, actually SUF does exactly that, but it would take a long time to pick out how it works. I just can't find enough information on it to know if it's something I can use. Thank you for your reply. |
You wouldn't need to anchor the overlay. Just make two separate frames with manually set coordinates relative to something like UIParent at the same location. The secure frame on top doesn't resize, has 0 alpha, and accepts the clicks while the unsecure frame underneath acts like a background displaying the target name and resizes width accordingly. I'm just tossing the idea out.
|
Yea, it's a good idea, and it's very likely that it would work fine. I haven't tested it yet but I can't think of a reason why it wouldn't work. You know when you start down a path have to have to solve the problem? That's where I got to with this.... as much as I wanted to understand secure frame handling better. It's going to be a bigger and bigger part of wow I would imagine and it seems important to understand it.
I will try your idea, thank you. In the mean time could you help me with understanding secure frames a bit better... with a snippet I can try? Preferably using the WrapScript method so I can start to understand what it would be used for. Thanks |
Quote:
For context, my purpose was: when in an actionbar page other than 1, after clicking a button on said page, automatically switch back to page 1 (something you can do with a macro, for each button, like /cast <spell> /changeactionbar 1). This is what I got from MunkDev: Quote:
You can see a list of attributes to use in: https://wow.gamepedia.com/SecureActionButtonTemplate MunkDev also linked a very helpful (albeit not enough for my lack of coding-skills :D ) free ebook about the restricted environment: Iriel's Field Guide to Secure Handlers Hope that helps! |
Thanks, and interesting that you posted that link, as it was the very one I was just reading! and it gives me hope... according to the article it is possible to SetWidth and SetHeight of frames during combat. It says so clearly in the article... the restriction is.. as far as I can tell without testing that..
a) It must be a precompiled "snippet" string of lua code. b) the frame must be first made available to the secure environment ( which now I know is nothing but a sandbox ) by using Header.SetFrameRef(..) and then inside the snippet the frame can be referenced with Header.GetFrameRef(..) From there the handle returned can ( if i'm correct ) be used to manipulate many of the frames properties.. i.e Width/Height/Show/Hide/Alpha to name just a few... No moving though.. but that makes sense. I will try to make a test addon tonight and have it changed the width of a frame during combat, and see if it works.. If so I'll post the code here for anyone to use. Hopefully it'll work! |
Incidentally, I was way off with thinking WrapScript was the answer..... all it does it "wrap" an existing script handler allowing you to place pre and post snippets of code around it. Kinda makes sense I suppose.
|
You can change secure attributes in combat, however only in under certain conditions (everything that a macro can do), and you can only access certain functions in the restricted environment, and you can only access your own secure references that you can only set out of combat and while logging into the game, or if your secure reference is a frame you can only access it's sub-methods limited too. UnitName() which would be the handler here for the changes you want to make, is not accessible. So it's not possible.
|
Interestingly enough, SetWidth/SetHeight, as well as GetWidth/GetHeight do work in the sandboxed (as you very well put it) restricted environment; SetSize/GetSize however do not.
There's a nice listing of what's available in a restricted environment here: https://wow.gamepedia.com/RestrictedEnvironment Secure handler templates will give you a few more methods: https://wow.gamepedia.com/SecureHandlers (see bottom of page for more info on specific templates). And... you have the "source" (if I'm not mistaken: the source is actualy in C, I believe, and unavailable; these are the Lua equivalents of the proper source). There is a Blizzard-provided tool for the purpose of extracting the data but I forgot what it is. I do remember it is a lengthy process (lots of data) and some people have kindly posted it on the Internet anyway. For example: https://www.townlong-yak.com/framexml/ptr - RestrictedEnvironment.lua and other Restricted*.lua files should be of interest. |
Oh, so you're saying it's possible to change the frame just fine, but there would be no way for me to get the with of the string in to the secure snippet?
You are absolutely right... there isn't. Well, glad I didn't sit here all night trying to get that to work.. :) Thanks for the reply and saving me the time. |
Wait a sec... you're saying that the Blizzard function UnitName is not callable from a secure snippet? But why not, that actually doesn't make sense at all.
|
Rightio, for anyone that might be interested in how to accomplish this, here is the quicker and much dirtier answer.....
No need to worry about changing the size of the frame itself. Since texture are not clipped to the frame and they can "live" outside of it, one solution is to have the frame the size of your portrait and then set textures for the fill and border. Simply then anchor the textures to the right side of the fontstring and hey presto. The frame then appears to change size in response to the width of the string ( the targets name in this case ) The only caveat is that the only part of the frame that is clickable is the portrait itself, which in and of itself is desirable is this case... less chance of a random, mid-battle misclick. There we go, if you can't to do it properly... hack! :) V |
Quote:
Code:
local width, height = frame:GetSize() Code:
local width, height = frame:GetWidth(), frame:GetHeight() |
Quote:
The FrameXML source is The Book for that. Only, it can be a pain to get... ;) |
Quote:
Or rather, KISS. ;) |
Quote:
Townlong-Yak is useful though for the diffs, and you can probably just work straight off of it without dumping the files yourself. But dumping it yourself you get more than just the FrameXML too, so there's that. |
Quote:
|
Quote:
|
Quote:
Here's a list of what's available: https://www.townlong-yak.com/framexm...ronment.lua#74 |
All times are GMT -6. The time now is 11:31 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI