Untitled

                Never    
Lua
       
local function UIOnSettlementSelected()
    -- declaring ButtonParent as a local variable to be used within UIOnSettlementSelected()
    local ButtonParent
    -- defining existingElement as a CA_UI element with the string defined in UIBUTTONNAME
    local existingElement = Util.getComponentWithName(UIBUTTONNAME)
    -- if not not existingElement returns true - ie., already exists, then...
    if not not existingElement then
        --# assume existingElement: BUTTON
       -- make the CA_UI visible
        existingElement:SetVisible(true)
       -- make the CA_UI 56x56 pixels
        existingElement:Resize(56, 56)
       -- move the CA_UI to (8, 1016), where (0, 0) is the top left corner
        existingElement:MoveTo(8, 1016)
    -- if the CA_UI doesn't already exist, then...
    else
        -- find the ButtonParent, the CA_UI upon which we'll place our new button
        local ButtonParent = find_uicomponent(core:get_ui_root(), "layout") --, "info_panel_holder", "primary_info_panel_holder", "info_panel_background", "ProvinceInfoPopup", "parchment_banner"
       -- define DetailsButton as a new button using a UIMF method
        local DetailsButton = Button.new(UIBUTTONNAME, ButtonParent, "CIRCULAR", "ui/skins/default/icon_province_details.png")
       -- resize the DetailsButton to 56x56 px
        DetailsButton:Resize(56, 56)
       -- move DetailsButton to(8, 1016)
        DetailsButton:MoveTo(8, 1016)
       -- when DetailsButton is clicked, trigger the function "CreatePanel()"
        DetailsButton:RegisterForClick(function() CreatePanel() end)
    end
end

local UIBUTTONNAME = "some_string"
function vandy()
    core:add_listener(
        "SettlementSelectedUI",
        "SettlementSelected",
        function(context)
          return context:garrison_residence():faction():name() == cm:get_local_faction(true)
       end,
     function(context)
          cm:callback(function() 
            --[[ local existingFrame = Util.getComponentWithName(UIPANELNAME)
                if not not existingFrame then
                   --# assume existingFrame: FRAME
                   existingFrame:Delete()
               end]]
                UIOnSettlementSelected() 
            end, 0.1)
        end,
        true
    )
end

Raw Text