[UI] Unit Panel Modding

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
I need to mod the Unit Panel, but I am stuck on how to do it.
My idea is to either create a row with the information I want, like this:
soulgem.gif
(from ViceVirtuoso's Civilization mods)

...which would need me to make a biparted row in case of ranged units

or

A single circle like the Civ one above the Unit's icon.


This information is fluid, it'll be like a 'charge', so an action might change what that charge is, which would change the information on that icon/row.


Any ideas on how to make them?
Cheers.
 
Why not poke VV about it?
As far as floating icons above the unitflag, I think someone made a mod (or modmod?) at some point to show smaller promotion flags in that area.. perhaps that could be repurposed for your intended usage.
 
Oh, I see that we misunderstood each other. :lol:
I mean above the unit's icon, not below it's flag; there is already one circle above it indicating the owner's Civilization, I was thinking of replicating that on the opposite side/above/whatever IF I can't solve the issue of biparting the row.
 
...oh!

I don't think I've seen such functionality, and I suspect that it would be, like most other UI elements, defined in some XML files and then filled in with Lua. Adding another bubble like the one on the bottom left corner would likely involve editing the XML file to create such a secondary space for you to use.

Of course, I likely have no idea what I'm talking about either, since I haven't yet delved into UI elements in my Civ. I'm holding off on that until I begin development of E&D support.
 
Do you have a screen mock up of what you're trying to achieve - even if it's just coloured blobs on a screen shot - as I'm not getting the description in post #1
 
Absolutely.

It's either:


Making both Strength AND RangedStrength in the same row, leaving the original RangedStrength (and Spread Uses? If I'm not mistaken) for Void only. (preferable, because it seems more elegant to me)



Or creating a new circle with the void uses, leaving the RangedStrength intact.
 
The bottom one is significantly easier as you'll be able to do it without changing UnitPanel at all.

Detect when the UnitPanel is shown/hidden and show/hide your own UI context which will have only the new framed circle in it. Due to the way the contexts stack (z-order) your's will always appear over the unit icon.

Then you just need to add the appropriate text into the circle.

The unit panel hooks the InfoPaneDirty event to show/hide itself, so you should be able to use the same trick

Code:
function OnInfoPaneDirty()
  local unit = UI.GetHeadSelectedUnit();
  ContextPtr:SetHide(unit == nil)
end
Events.SerialEventUnitInfoDirty.Add(OnInfoPaneDirty);
You will need to change this if not all units should have the new circle
 
I did send him a PM, I believe he isn't very active nowadays.

Real life's been quite busy lately, what with cramming for finals and my CCNA, a job which I don't have the luxury of doing at a computer, and doing holiday shopping. Pair that with buying Endless Legend and yeah...but at least I can drop EL for now since it won't stop crashing. Not to mention I'm not too terribly active on Civfanatics anyway, since the reception to my mods here tends to be lukewarm at best.

But back to the topic at hand.

What whoward said is true: the second option will be easier to implement, and would be highly recommended if that's all you're adding to the unit panel. If you want to do the first option, though, it's still not too terribly difficult. In UnitPanel.lua, find the UpdateUnitStats function and find the "Ranged Strength" comment. Then you need to add another elseif to the if clause below it. Something like:
Spoiler :
Code:
    -- Ranged Strength
    local iRangedStrength = 0;
    if(unit:GetDomainType() ~= DomainTypes.DOMAIN_AIR) then
        iRangedStrength = unit:GetBaseRangedCombatStrength();
    else
        iRangedStrength = 0;
    end
    if(iRangedStrength > 0) then
        local szRangedStrength = iRangedStrength .. " [ICON_RANGE_STRENGTH]";
        Controls.UnitRangedAttackBox:SetHide(false);
        local rangeStrengthStr = Locale.ConvertTextKey( "TXT_KEY_UPANEL_RANGED_ATTACK" );
        Controls.UnitStatNameRangedAttack:SetText(rangeStrengthStr);
        Controls.UnitStatRangedAttack:SetText(szRangedStrength);
        local rangeStrengthTT = Locale.ConvertTextKey( "TXT_KEY_UPANEL_RANGED_ATTACK_TT" );
        Controls.UnitStatRangedAttack:SetToolTipString(rangeStrengthTT);
        Controls.UnitStatNameRangedAttack:SetToolTipString(rangeStrengthTT);

	elseif (whatever) then
	    Controls.UnitRangedAttackBox:SetHide(false);
                local text, otherText, rangeStrengthTT = --insert your code
		Controls.UnitStatNameRangedAttack:SetText(text);
		Controls.UnitStatRangedAttack:SetText(otherText);
		Controls.UnitStatRangedAttack:SetToolTipString(rangeStrengthTT);
		Controls.UnitStatNameRangedAttack:SetToolTipString(rangeStrengthTT);
        --the rest of the elseifs for religious spreads, etc., are below this


If you want to add ranged strength to the melee strength bar, you can move the first part of the Ranged Strength portion of the function to the Strength portion, then concatenate the two values along with their icons into one string.

Spoiler :
Code:
    -- Strength
    local strength = 0;
    local iRangedStrength = 0;
    if(unit:GetDomainType() == DomainTypes.DOMAIN_AIR) then
        strength, iRangedStrength = unit:GetBaseRangedCombatStrength();
    elseif (not unit:IsEmbarked()) then
        strength = unit:GetBaseCombatStrength();
        iRangedStrength = unit:GetBaseRangedCombatStrength();
    end
    if(strength > 0) then
        strength = strength .. " [ICON_STRENGTH]";
        if iRangedStrength > 0 then
            strength = strength .. " " ..iRangedStrength.. " [ICON_RANGE_STRENGTH]";
         --rest of code
 
Top Bottom