project-navigation
Personal tools

Author Topic: UI problems with alien containment init  (Read 2868 times)

Offline H-Hour

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1923
    • View Profile
UI problems with alien containment init
« on: January 26, 2012, 03:31:26 pm »
I am trying to build the alien containment functions in my custom UI and having a problem. I have not put alien containment into its own window node. Instead, it is a panel that I show/hide in the overall bases window (/ui/bases.ufo).

When the panel is opened, I call a confunc which calls aliencont_init, which points to cp_aliencont_callbacks.c, AC_Init_f(), which then calls AC_UpdateMenu(). This function then sets a number of cvars like mn_ac_name0, mn_ac_name1, etc.

In my confunc, after I have called this aliencont_init to get these cvars, I then use them to add children panels for each alien through a while loop. I have found, however, that the while loop is executed before the cvars are populated. It is tricky to spot because each the data is set to the cvars, so when the cvars are populated it appears fine. But I'm trying to limit the number of panels based on a cvar, so I will end up with the correct number of panels for the last time I opened alien containment. That means, if I open alien containment in a base with 3 alien types, then switch to a base with 1, I will get two extra panels with no information. If I open alien containment in a base with 0 alien types, then switch to a base with three, there will be no panels.

Here is my confunc, and I've attached the whole mod to look at. This confunc is in bases.ufo.

Code: [Select]
/*
* Show and hide the alien containment panel
* param1 = true (show alien containment), false (hide alien containment)
*/
confunc alien_containment
{

if (param1 eq "true") {

// Call to cp_aliencont_callbacks.c to get data
cmd "aliencont_init;"

cmd "echo 1-al0 name <cvar:mn_ac_name0>;"

// Show the alien containment area
*node:parent.base_container.alien_containment@invis = false

// Show the aliens
*cvar:i = 0;
while ( *cvar:i < 8 ) {
if (*cvar:mn_ac_name<cvar:i> ne "None") {
call *node:parent.base_container.alien_containment.aliens@createChild("<cvar:i>", "AlienPanel")
*node:parent.base_container.alien_containment.aliens.<cvar:i>.label@string = *cvar:mn_ac_name<cvar:i>
*node:parent.base_container.alien_containment.aliens.<cvar:i>.status@string = *cvar:mn_ac_statusstr<cvar:i>
*node:parent.base_container.alien_containment.aliens.<cvar:i>.data_bar@current = *cvar:mn_ac_progress<cvar:i>
*node:parent.base_container.alien_containment.aliens.<cvar:i>.alien_num@string = <cvar:i>
}
*cvar:i = ( *cvar:i + 1 )
}

// Set the state for subsequent clicks
*node:parent.sections.containment.state@string = false

cmd "echo 2-al0 name <cvar:mn_ac_name0>;"
} else {

// Remove alien panels and hide the image/info when loaded
call *node:parent.base_container.alien_containment.aliens@removeAllChild
*node:parent.base_container.alien_containment.info@invis = true

// Hide the alien containment area
*node:parent.base_container.alien_containment@invis = true

// Set the state for subsequent clicks
*node:parent.sections.containment.state@string = true
}

// Show or hide the base map, employees and buttons under the map
*node:parent.base_container.base_map_container@invis = <1>
*node:parent.base_container.cur_employees@invis = <1>
*node:parent.base_container.buttons@invis = <1>
}


Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: UI problems with alien containment init
« Reply #1 on: January 26, 2012, 10:50:29 pm »
A cmd call is executed in the next rendering frame, while your loop runs in this one.
The easiest solution is moving out the aliencont_init call from alien_containment confunc, like

Code: [Select]
                BaseSection containment
                {
                        {
                                onClick         { cmd "build_facility false; aliencont_init; alien_containment <node:this.state@string>;" }
                        }
                        string label { string "_Alien Containment" }
                        custombutton icon { icon "icons/aliens" }
                        data state { string "true" }
                }

-geever

Offline H-Hour

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1923
    • View Profile
Re: UI problems with alien containment init
« Reply #2 on: January 27, 2012, 04:45:58 am »
That did it! Thanks.