Is there a way to make an "invisible promotion"?

Neirai

the Forgiven
Joined
Aug 5, 2013
Messages
1,046
Location
Canada
I'd like to make a unit with an additive promotion. But I'd rather not have a ton of different promotions showing up on the unit. Is there a way to make promotions invisible?
 
You'd probably have to replace UnitPanel.lua with the functionality to make certain promotions invisible. At least, that's what I plan on doing for my large-scale mod I'm working on.
 
You'd probably have to replace UnitPanel.lua with the functionality to make certain promotions invisible. At least, that's what I plan on doing for my large-scale mod I'm working on.

Add a ShowInUnitPanel column to the promotions table - see http://forums.civfanatics.com/showthread.php?t=520670 for a similar approach for the tech tree - and then in the UnitPanel.lua file

Code:
--------------------------------------------------------------------------------
-- Refresh unit promotions
--------------------------------------------------------------------------------
function UpdateUnitPromotions(unit)
    g_EarnedPromotionIM:ResetInstances();
    local controlTable;
    
    --For each avail promotion, display the icon
    for unitPromotion in GameInfo.UnitPromotions() do
        local unitPromotionID = unitPromotion.ID;
        
        if ([B][COLOR="Red"]unitPromotion.ShowInUnitPanel == 1 and [/COLOR][/B]unit:IsHasPromotion(unitPromotionID) and not unit:IsTrade()) then
            controlTable = g_EarnedPromotionIM:GetInstance();
            IconHookup( unitPromotion.PortraitIndex, 32, unitPromotion.IconAtlas, controlTable.UnitPromotionImage );

            -- Tooltip
            local strToolTip = Locale.ConvertTextKey(unitPromotion.Description);
            strToolTip = strToolTip .. "[NEWLINE][NEWLINE]" .. Locale.ConvertTextKey(unitPromotion.Help)
            controlTable.UnitPromotionImage:SetToolTipString(strToolTip);
        end
    end
end

You'll also need to update EnemyUnitPanel.lua

Code:
--------------------------------------------------------------------------------
-- Refresh Unit promotions
--------------------------------------------------------------------------------
function UpdateUnitPromotions(pUnit)
    local UnitPromotionKey = "UnitPromotion";
    
    --Clear Unit Promotions
    local i = 1;
    while(Controls[UnitPromotionKey..i] ~= nil) do
        local promotionIcon = Controls[UnitPromotionKey..i];
        promotionIcon:SetHide(true);
        i = i + 1;
    end
    
    if pUnit then
        --For each avail promotion, display the icon
        for unitPromotion in GameInfo.UnitPromotions() do
            local unitPromotionID = unitPromotion.ID;
            if ([B][COLOR="Red"]unitPromotion.ShowInUnitPanel == 1 and[/COLOR][/B] pUnit:IsHasPromotion(unitPromotionID)) then
                
                -- Get next available promotion button
                local idx = 1;
                local promotionIcon;
                repeat
                    promotionIcon = Controls[UnitPromotionKey..idx];
                    idx = idx + 1;
                until(promotionIcon == nil or promotionIcon:IsHidden() == true);
                
                if promotionIcon ~= nil then
                    IconHookup( unitPromotion.PortraitIndex, 32, unitPromotion.IconAtlas, promotionIcon );                
                    promotionIcon:SetHide(false);
                end
            end
        end
    end
end

Then for any promotion that you don't want to show up, just add a
Code:
<ShowInUnitPanel>0<ShowInUnitPanel>
line in the promotions XML (or SQL equivalent if using SQL)


Note: as the table has been altered you cannot treat this column as a boolean, so do not try (unitPromotion.ShowInUnitPanel == true) and <ShowInUnitPanel>false<ShowInUnitPanel> as they don't work as expected
 
@whoward: Thanks a lot for the code above. Now for a more noobish question: I seem to recall that to modify the UnitPanel.lua and EnemyUnitPanel.lua files you have to copy their entire contents into a new lua file that also contains your new bits of lua - is this true, or can I just add your code as a new lua file through InGameUIAddin?
 
You have to copy the core file into your mod, make the changes and then set VFS=true - do NOT add an InGameUIAddin entry
 
Top Bottom