WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   HybridScrollFrame row background colour (https://www.wowinterface.com/forums/showthread.php?t=58716)

Ylaana 05-03-21 09:31 AM

HybridScrollFrame row background colour
 
3 Attachment(s)
This is my first addon. I have a list which is basically Meorawr's HybridScrollFrame demo, just with a different dataset.

https://gist.github.com/Meorawr/7d67...7a875db3fd1d7a

If an item's itemName exists within a given itemArray, I want to colour the row background, which I've done like this:

Code:

button.Text:SetText(item.text or "");

local tex = button:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
tex:SetGradientAlpha("HORIZONTAL", unpack({0.15,0.6,0.15,1, 0.15,0.6,0.15,0}))
button.Texture = tex
button.Texture:Hide()

if ItemExists(itemArray, item.itemName) then
    button.Texture:Show()
end

This puts the background in as expected for the right items on load, but when I scroll down, the coloured background 'sticks' to the top of the list, and ends up colouring the background of the items I scrolled past. I also noticed that some rows appear to get the background applied more than once(?) as the opacity/gradient varies between them. I've attached images of the initial view (1), and what happens when you scroll down (2) and back up (3).

I'd be very grateful if someone could point me in the right direction.

Xrystal 05-03-21 10:38 AM

Off the top of my head it sounds like the problem is happening because you are coloring the display rather than marking the value as being colorable. As in there may be 1000 items but only 20 bars. You only want to color the bar that contains the item you want to have colored and uncolor the other bars.

If you set the default bar color it should ensure that each bar is uncolored until you ask it to color it based on the item.

Fizzlemizz 05-03-21 11:20 AM

Code:

button.Text:SetText(item.text or "");

local tex = button:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
tex:SetGradientAlpha("HORIZONTAL", unpack({0.15,0.6,0.15,1, 0.15,0.6,0.15,0}))
button.Texture = tex
button.Texture:Hide()

This indicates that you are creating a new background texture every time you scroll and update a row of the scrollframe. Each row will end up with multiple textures on top of each other with the previous ones permanent display state being what it was before you create and assign the new one with button.Texture = tex

You could apply the texture to the Background element of the HybridScrollDemoListItemTemplate section of the XML (this defines what each row will look like). You can then just set the colour etc. (highligh or default) of the background texture when you set the text.

Ylaana 05-12-21 02:15 PM

Thanks, that's exactly what I needed! :)

I've made some further changes, and it's all working - but not on player login. The rows don't get coloured until you do an interface reload, but printing the values inside the functions to the console returns the right data. I've tried registering PLAYER_LOGIN and adding it to the events with a self:RefreshLayout() but that doesn't change anything.

Is the code taking too long to run? Have I missed something obvious? I don't really know how to fix this and further improve/optimise the code. I've put my addon files in here: https://pastebin.com/u/Ylaana/1/tPZRxwDK

Any advice is greatly appreciated (and I hope someone will find the addon useful :p).

Fizzlemizz 05-12-21 02:56 PM

I can't see anything usable in the Pastebin page but then again, I'm not a Pastebin expert.

Ylaana 05-12-21 03:19 PM

Sorry, I've set them all to public now so you should be able to see them. Here are the direct links:

https://pastebin.com/aK9HQctf
https://pastebin.com/ajc1CuYC
https://pastebin.com/nEf8Cy12
https://pastebin.com/KaXaKLH8

Fizzlemizz 05-12-21 08:50 PM

I don't have many Glyphs except a couple on a Druid (Cheetah etc.) so I'm not sure how to get one to display as active or in confict.

You do your RefreshLayout OnShow and and on receiving a GET_ITEM_INFO_RECEIVED event.

Frames by default are shown (your xml frame does not have the hidden attribute) so you won't get an initial refresh unless you receive an event or manually hide/show the frame (the OnShow script is set after the frame is created ie. already shown).

Ylaana 05-13-21 03:03 AM

2 Attachment(s)
To determine which glyphs are active, the addon looks in your spellbook for any spells that have glyphs attached to them and puts those in a table. It then compares that table to the names of the glyphs in GlyphData.lua for your classID, and if a match is found the row background should be green. It also checks the conflicts to see if the active glyphs are in an exclusive set, so the other glyphs in that set are coloured red. I've attached an image of what it looks like on a paladin with the Valorous Charger's Bridle glyph on Divine Steed, which is exclusive with the Vengeful/Vigilant/Golden Charger's Bridles and Glyph of the Trusted Steed, and on a priest with the Shackle Undead and Voidling glyphs, with the latter being exclusive with the Glyphs of the Lightspawn and Sha.

Because Marks (of the Cheetah/Dolphin/etc.) are made by scribes but aren't technically glyphs (i.e. not trackable through the spellbook), I included them in the list but they won't get coloured in the same way as 'regular' glyphs, as Blizzard don't currently have an API call in place that would allow me to obtain that information from the barber shop interface. I don't know if I should just hide them altogether because a lot of people I spoke to about these Marks weren't even aware they existed, so I suppose just making them visible in this way could be helpful.

Manually hiding/showing the frame by clicking the close button and then using /gl to show it again doesn't update the row colours, nor does triggering RefreshLayout on the PLAYER_LOGIN or PLAYER_ENTERING_WORLD events. I even tried on SPELLS_CHANGED and learning a new glyph to see if that would do anything, but again with no luck. I do want to make it so that learning a new glyph automatically refreshes the row colours, but that probably means re-scanning the spellbook to see what's changed and running through the active/exclusions lists again.

Fizzlemizz 05-13-21 11:40 AM

Code:

local glyphedSpells = GetGlyphedSpells()
You're setting up your lookup table of glyphs when your addon loads before much of the character data has been gathered especially when first loggin in. Doing this also means the information in the table doesn't change even if spells are updated during play.

This table needs to be refreshed when new data is available (the chached spell information won't have been flushed during a /reload which is why it is already available so early "second time in").

Something like adding glyphedSpells = GetGlyphedSpells() to your cache_writer OnEvent script (might refresh too often but gives you an idea of what's going on).

Code:

button.GlyphActive:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
button.GlyphActive:SetGradientAlpha("HORIZONTAL", unpack({0.15,0.6,0.15,1, 0.15,0.6,0.15,0}))
 
button.GlyphConflict:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
button.GlyphConflict:SetGradientAlpha("HORIZONTAL", unpack({0.6,0.15,0.15,1, 0.6,0.15,0.15,0}))

As with the texture originally, your resetting the highlight file and gradient every time you scroll. While this doesn't create the problem seen previously, it's doing things over and over again that only need to be done once. You could move this to your XML with

Code:


<Texture parentKey="GlyphActive" setAllPoints="true" file="Interface\Tooltips\UI-Tooltip-Background">
        <Gradient orientation="HORIZONTAL">
                <MinColor r="0.15" g="0.6" b="0.15" a="1"/>
                <MaxColor r="0.15" g="0.6" b="0.15" a="0"/>
        </Gradient>
</Texture>
<Texture parentKey="GlyphConflict" setAllPoints="true" file="Interface\Tooltips\UI-Tooltip-Background">
        <Gradient orientation="HORIZONTAL">
                <MinColor r="0.6" g="0.15" b="0.15" a="1"/>
                <MaxColor r="0.6" g="0.15" b="0.15" a="0"/>
        </Gradient>
</Texture>

As an aside, unpack({0.15,0.6,0.15,1, 0.15,0.6,0.15,0}) is creating a table just to unpack it straight away and then discard it.
Code:

button.GlyphActive:SetGradientAlpha("HORIZONTAL", 0.15, 0.6, 0.15, 1, 0.15, 0.6, 0.15, 0)
Is the same without adding the middle step.

Ylaana 11-13-23 01:00 PM

Hi, I remembered I had posted here asking for advice and just wanted to thank you for your help getting me started. I've been working on this addon for the past two years and gradually improving it, and I have a lot more planned! It's called GlyphList and it's available on CurseForge, I've just updated it for 10.2 :)


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

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