Forum rules - please read before posting.

[SOLVED] Black border around dialog menu

edited April 2014 in Technical Q&A
I'm going for a comic book style for my dialog lines.  For this I'd like to create a black border around my white dialog background textures. But how can I do it? 

A uniform black border will be fine, as long as I can have the same border thickness even if the dialog gets resized.

P.S. Sorry that I confused you with the hand drawn look in my previous screenshots. Ideally I'd like that look but I understand that it gets complicated with automatic sizing. So I will just start with a uniform border for now.

Comments

  • The thing about menus is that no matter how complex the style/functionality interfaces are, it'll never be enough to suit everyone's needs all the time.  For that reason, the MenuSystem script is designed to let you add your own code when AC vanilla isn't quite enough.  I think you could use it to get what you need - hand-drawn borders and all.

    Whenever a Menu is turned on, the MenuSystem's OnMenuEnable function is called, with a parameter to get the name of the Menu in question.  This is a one-time call only (not every frame the menu is active), so it's used to reposition / resize / hide elements.  You'll have to make sure your subtitle text doesn't scroll (so that the size of the label is determined beforehand), but try this:

    Split your "speech bubble" background into two: the first containing the top, left and right edges; the second just the bottom.  Make the first graphic extend deep enough to cover any possible text lengths.

    Put these into two Label elements, in the order TopBubble, SubtitleText, BottomBubble.  Set the position of the TopBubble and Subtitle Text to absolute 0,0.  The ordering should make sure you can still see the SubtitleText above the TopBubble graphic.  Set the position of the BottomBubble to Relative to Menu Size, and place it at the bottom edge.

    Then resize the TopBubble so that it extends beyond the size of the menu, so that you can only see the top bit of it.  The idea in the script is then to resize the menu's height dynamically.  As it gets deeper, more of the TopBubble graphic will be revealed, while the BottomGraphic will remain at the bottom.

    In your MenuSystem script, do a check for your menu, and then adjust it's manualSize.y property based on the size of the label.  (You can get an element with the PlayerMenus.GetElementWithName function).  You'll have to call the Menu's "Recalculate" function afterwards.

    Hope that makes more sense when you play around with it!
  • edited April 2014
    Hi again,

    It's been a while, but I've tried to implement my custom menu according to your instructions. My main problem is that I can't retrieve the correct dialog label size in OnMenuEnable. The label size I get is for the PREVIOUS dialog line, since the current dialog line hasn't been rendered yet. How can I resize the menu after the current dialog line has been set and auto adjusted?

  • This may have been sorted by the latest update, but if not, here's how the label itself calculates the height, assuming a fixed width:

    Dialog dialog = GameObject.FindWithTag (Tags.gameEngine).GetComponent <Dialog>();
    if (dialog.GetLine () != "")
    {
      GUIContent content = new GUIContent (dialog.GetLine ());
      relativeRect.height = _style.CalcHeight (content, relativeRect.width);
    }


  • edited April 2014
    Just wanted to update that I've found a solution which works for me. It was a struggle, but you pointed me in the right direction. Thank you! I had to put the bottom bubble in its own menu (due to transparency problems) and I needed to put some custom spacing in. For posterity, here is my code in MenuSystem.OnMenuEnable:

    if (_menu.title == "Subtitles") {
    Dialog dialog = GameObject.FindWithTag (Tags.gameEngine).GetComponent <Dialog>();
    string newLabel = dialog.GetLine ();
    if (newLabel != "")
    {
    MenuLabel subsLineLabel = (MenuLabel) _menu.GetElementWithName("SubsLineLabel");
    //Creating a normalStyle the get the correct subtitleHeight
    GUIStyle normalStyle = new GUIStyle();
    normalStyle.font = subsLineLabel.font;
    normalStyle.fontSize = (int) (AdvGame.GetMainGameViewSize ().x * subsLineLabel.fontScaleFactor / 100);
    normalStyle.alignment = subsLineLabel.anchor;
    normalStyle.wordWrap = true;
    GUIContent content = new GUIContent (newLabel);
    float subtitleHeight = normalStyle.CalcHeight (content, subsLineLabel.slotSize.x/ 100f * AdvGame.GetMainGameViewSize ().x) + 
    _menu.spacing / 100 * AdvGame.GetMainGameViewSize ().x*2;
    _menu.manualSize.y = (subtitleHeight / AdvGame.GetMainGameViewSize ().y) * 100;
    //Add spacing
    subsLineLabel.SetPosition(new Vector2 ((_menu.spacing / 100 * AdvGame.GetMainGameViewSize ().x), (_menu.spacing / 100 * AdvGame.GetMainGameViewSize ().x)));
    Menu bottomSubtitleMenu = PlayerMenus.GetMenuWithName("Bottom Subtitle");
    //NOTE: manualPosition is in the center of the menu rectangle, not top left
    bottomSubtitleMenu.manualPosition.x = _menu.manualPosition.x;
    bottomSubtitleMenu.manualPosition.y = _menu.manualPosition.y + _menu.manualSize.y/2 + bottomSubtitleMenu.manualSize.y/2;
    bottomSubtitleMenu.Recalculate();
    _menu.Recalculate();
    }
    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.