[SOLVED] UI Buttons don't match Sorting of Items

Zegangani

King
Joined
Oct 9, 2020
Messages
898
Hi, @Infixo !
Sorry for pinging you, I have an Issue with a civ6 UI file and I want to ask you if you could help me solve that Issue.
I want to make the City-State Overview Panel sort CSs based on Name, Tokens given by player, Suzerain...etc. I got that working and everything sorts accordingly but the buttons of sending envoys didn't match that (got really weird), so I tried to fix that. And I got that working (showing properly on each CS row), but when pressing the buttons only few match the CS where the Buttons are (the CS row - but when clicked, they change the envoy number of the right CS) and some buttons don't even work. And the Log file doesn't show any Errors (aside from some errors that are most likely caused by this Issue).

I just started to tinker with the UI of Civ6, so I'm not experienced enough to know what exactly is causing that. So I would really appreciate your help!

I've commented with my Initials"Zegangani" everywhere where I've changed something in the code (not much changing tho), and made some code comments on that.
I think the Issue lies in "m_uiCityStateRows" (perhaps a sorting Issue) , but I don't know how to solve it. I'm not even sure if that's what's causing all of this.

EDIT: since when this Forum doesn't allow uploading lua files? Anyway I just uploaded the lua file as a text file.
 

Attachments

You can try double-indexing to sort the m_kCityStates without actually sorting it. Here is an example script for it.

Code:
-- m_kCityStates built earlier
m_aSortedPlayerIDs = {}

-- You could merge this while building m_kCityStates also
for iPlayer, _ in pairs(m_kCityStates) do
    table.insert(m_aSortedPlayerIDs, iPlayer)
end

-- Sort something like this
-- Each entry in m_aSortedPlayerIDs is the index for m_kCityStates
table.sort(m_aSortedPlayerIDs,
    function(a, b)
        return Locale.Compare(m_kCityStates[a].Tokens, m_kCityStates[b].Tokens) == -1
    )

-- For iterating make sure to use ipairs
for _, iPlayer in ipairs(m_aSortedPlayerIDs) do
    -- This will get you the tables in the correct order without actually sorting the m_kCityStates table
    local kCityState:table = m_kCityStates[iPlayer]
end
 
Back
Top Bottom