Struggling to order GUIs

Started by bauldur_rises, Tue 21/06/2022 06:59:54

Previous topic - Next topic

bauldur_rises

So, I have multiple GUIs going on for menus.  I also have a black full-screen GUI that I wish to be placed underneath the foremost GUI, and so whenever the foremost GUI is closed I want to have the black GUI (which I call gBlackSlug) to be moved behind the next foremost GUI (or disappear if there is no other used GUI).  My intent is that everything behind the menu is visually darkened, things beneath the menu cannot be interacted with, and so that when the player clicks outside the menu that it will close the menu (the gBlackSlug having a button covering the whole thing that will refer to the relevant functions).

What I've got to do that is first these functions:  (I use edmundito's Tween Module)

Code: ags

function HighestGUI()
{
  int Previous_ZOrder = 0;
  for (int x=0; x<Screen.Width; x+=5)
  {
    for (int y=0; y<Screen.Height; y+=5)
    {
      GUI *theGui = GUI.GetAtScreenXY(x,y);
      if ((theGui!=null)&&(theGui.ZOrder>Previous_ZOrder)&&(theGui!=gBlackSlug))
       {
         Previous_ZOrder = theGui.ZOrder;
       }
    }
  }
  return(Previous_ZOrder);
}

function ReorderBlackSlug(BlackSlugFade Fadetype, float t)
{
  int Target_ZOrder = HighestGUI();
  if (Target_ZOrder<=2)
  {
    gBlackSlug.Visible = false;
    gBlackSlug.Clickable =false;
    gBlackSlug.Transparency=100;
    gBlackSlug.ZOrder = 0;
  }
  else
  {
    if (gBlackSlug.Visible==false){gBlackSlug.Visible = true;}
    if (gBlackSlug.Clickable==false){gBlackSlug.Clickable = true;}
    if (Fadetype == eSlugFade)
      {
        if (gBlackSlug.Transparency!=100){gBlackSlug.Transparency = 100;}
        gBlackSlug.TweenTransparency (t, 40, eEaseLinearTween, eNoBlockTween, 0.0, eTweenSeconds);  // This fades in the gBlackSlug to Transparency 40 over t seconds
      }
    else if (Fadetype== eSlugNoFade)
      {
        if (gBlackSlug.Transparency!=40){gBlackSlug.Transparency = 40;}
      }
    gBlackSlug.ZOrder = Target_ZOrder-3;
  }
}
 

And then the button to bring up a menu is:

Code: ags
  if (gMenu.Visible==false)
    {
      gMenu.Visible = true;
      if (!IsGamePaused()){PauseGame();}
      gMenu.Clickable= false;
      gMenu.TweenPosition(0.5,Menu_Onscreen_X,  Menu_Onscreen_Y, eEaseOutExpoTween, eBlockTween, 0.0, eTweenSeconds);
      gMenu.Clickable= true;
      ReorderBlackSlug(eSlugNoFade, 0.0);

    }
  else if (gMenu.Visible==true)
    {
      if (IsGamePaused()==1){UnPauseGame();}
      gMenu.TweenPosition(0.5, Menu_Offscreen_X, Screen.Height, eEaseLinearTween, eBlockTween, 0.0, eTweenSeconds);
      gMenu.Visible=false;
      gMenu.Clickable= false;
      ReorderBlackSlug(eSlugNoFade, 0.0);
    }
}


However, what happens when I press the button opening the Menu is that after the Menu GUI moves onscreen, the gBlackSlug appears on top of gMenu. 

I'm new to scripting and can't puzzle out why, so I would love some insight and help.  Thanks!

bauldur_rises

I've discovered my error - I had a GUI that was intended to sit on top of everything that was, of course, being detected by my function finding the next highest GUI, and thus the bBlackSlug was always above everything else.

Now to work out the other issues with my script.

SMF spam blocked by CleanTalk