Trying to mod the aircraft pulldown

Kuupora

Chieftain
Joined
Jul 8, 2013
Messages
11
I'm trying to add a stack which contains two buttons instead of one button in the aircraft pulldown.

In UnitFlagManager.xml under the

<Instance Name="AirButton" > -line is this:


...

<InstanceData Name="UnitInstance" >
<Button Size="175,26" Anchor="C,C" ID="Button" >
<ShowOnMouseOver>
<AlphaAnim ID="SelectAnim" Anchor="C,C" Offset="0,0" Size="150,24" Pause="0" Cycle="Bounce" Speed="1" AlphaStart="2" AlphaEnd="1">
<Grid ID="SelectHL" Size="150,24" Offset="0,0" Padding="0,0" Style="Grid9FrameTurnsHL" />
</AlphaAnim>
</ShowOnMouseOver>
</Button>
</InstanceData>

...



I assume this is the place where the Button instance (for the aircraft) is defined. Is that correct? I tried to replace the aboce mentioned code with this one:



<InstanceData Name="UnitInstance" >
<Stack Anchor="L,C" StackGrowth="Right" Offset="0,0" Padding="0" >

<Button Offset="0,0" Anchor="R,C" Size="200,24" ID="Button" >
<AlphaAnim ID="SelectAnim" Anchor="C,C" Offset="0,0" Size="150,24" Pause="0" Cycle="Bounce" Speed="1" AlphaStart="2" AlphaEnd="1">
<Grid ID="SelectHL" Size="150,24" Offset="0,0" Padding="0,0" Style="Grid9FrameTurnsHL" />
</AlphaAnim>
</Button>
<Button Offset="0,0" Anchor="C,C" Size="180,24" ID="Button2" >
<AlphaAnim ID="SelectAnim" Anchor="C,C" Offset="0,0" Size="150,24" Pause="0" Cycle="Bounce" Speed="1" AlphaStart="2" AlphaEnd="1">
<Grid ID="SelectHL" Size="150,24" Offset="0,0" Padding="0,0" Style="Grid9FrameTurnsHL" />
</AlphaAnim>
</Button>

</Stack>
</InstanceData>



The whole AirButton disappeared. What am I doing something wrong? Is it even possible to modify this pulldown?



In UnitFlagManager.lua there is this line: (on line 1091)

cityFlagInstance.PullDown:BuildEntry( "UnitInstance", controlTable );


What is this controlTable parameter? I guess this is the place where the lua file refers to the UnitInstance in the Xml file.


:confused::confused::confused:
 
This, for example, is strange:

In the UnitFlagManager.xml file within the <Instance Name="AirButton" > and <InstanceData Name="UnitInstance" > tags is this line:
<Button Size="175,26" Anchor="C,C" ID="Button" >


I tried to mod the Button Size (x,y I presume) but it didn't seem to affect anything. Why?

Then I tried to modify the following code ( UnitFlagManager.lua, function UpdateCityCargo( pPlot ) ) and replace the parameters in the line: local newWidth = math.max(150, tw+50);.

...

controlTable = {};
cityFlagInstance.PullDown:BuildEntry( "UnitInstance", controlTable );

--
local unitName = pPlotUnit:GetName();

local bw, bh = controlTable.Button:GetSizeVal();
controlTable.Button:SetText(unitName);
local tw, th = controlTable.Button:GetTextControl():GetSizeVal();

local newWidth = math.max(150, tw+50);

controlTable.Button:SetSizeVal(newWidth,bh);

...


and yes, the pulldown size changed immediately.

I would like know where the functions SetText(string), SetSizeVal(int1, int2) are defined? Any ideas?
 
I would like know where the functions SetText(string), SetSizeVal(int1, int2) are defined? Any ideas?

They are Lua API interfaces to the C++ code within the graphical user interface - a DLL for which we do NOT have the source code
 
whoward69, thanks for your answer.

I intend to mod the aircraft pulldown to look more like this:




I want each row to contain the name of the unit, health, and promotions respectively. So each row has to be a stack that grows to right.


A further question: Is it possible to add a stack into the pulldown element instead of a button?
 
That is possible.

But you are into advanced UI techniques to achieve it. Stacks within stacks fall into the "non-trivial" category, as you will have to have multiple instance managers for the stacks of promotions, all being created dynamically for each aircraft row (which will have their own instance manager), and stored/accessed/reset within the aircraft row instances.

Lots of reading of the UI Tutorials and similar mods (eg "UI - City Religions", specifically the usage of PurchaseInstance and ItemInstance) ahead of you
 
Yes, I'd like to read some UI tutorials. Just found your tutorial in 2k forum :)
So what do you think about the idea of this mod? I also thought about adding a "Rebase all" -button.
 
Okay, I read the UI tutorials 1, 2 and 3.

First I'm trying to make a horizontal stack, and put stuff there. I added this line in UnitFlagManager.xml (after the <InstanceData Name="UnitInstance" > ...)

<Stack ID="UnitStack" Anchor="L,C" StackGrowth="Right" Offset="0,0" Padding="10" />





and then added this to the UnitFlagManager.lua

unitStackInstance = {};

cityFlagInstance.PullDown:BuildEntry( "UnitStack", unitStackInstance );

** correct so far I assume? **

Then I'm trying to add the UnitInstance (the existing code) to be controlled by the new UnitStackInstance. Not working.

ContextPtr:BuildInstanceForControl( "UnitInstance", controlTable, Controls.UnitStack );




error:

UnitFlagManager.lua:1102: attempt to index field 'Button' (a nil value)

this is the line where the error takes place:

local bw, bh = controlTable.Button:GetSizeVal();



So, should I read the rest of the tutorials or continue to knock my head against the wall? I think there was nothing about creating the instance manager in first three tutorials... What's the role of the instance manager in this?
 
Top Bottom