Page 1 of 1

Dialog popups?

Posted: 01 Feb 2015, 05:37
by elisa
How do you make a dialog popup -

MessageBox - with "Do you want to quit?" (Yes/No)

using Neosis inside Unity3d?

Re: Dialog popups?

Posted: 02 Feb 2015, 11:52
by sfernandez
Hi,

You can design a UserControl to show your message boxes. The UserControl can expose some properties like Title, Message, Icon, etc. and add it on top of your main window.
using System;
using Noesis;

[Extended]
[UserControlSource("Assets/UI/MessageBox.xaml")]
public class MessageBox : UserControl
{
  public static DependencyProperty TitleProperty = DependencyProperty.Register(
    "Title", typeof(string), typeof(MessageBox), new PropertyMetadata(""));

  public string Tittle
  {
    get { return GetValue<string>(TitleProperty); }
    set { SetValue<string>(TitleProperty, value); }
  }

  public static DependencyProperty MessageProperty = DependencyProperty.Register(
    "Message", typeof(string), typeof(MessageBox), new PropertyMetadata(""));

  public string Tittle
  {
    get { return GetValue<string>(MessageProperty); }
    set { SetValue<string>(MessageProperty, value); }
  }

  // ...

  public void OnPostInit()
  {
    var root = FindName("LayoutRoot");
    root.SetDataContext(this);
  }
}
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="MessageBox">
  <Grid x:Name="LayoutRoot" Background="#80000000">
    <Border BorderBrush="Gray" BorderThickness="1" Background="Silver"
      HorizontalAlignment="Center" VerticalAlignment="Center" Margin="200,100">
      <StackPanel>
        <Border Background="LightSkyBlue" Padding="5,2">
          <TextBlock Text="{Binding Title}" FontWeight="Bold"/>
        </Border>
        <Border Padding="5">
          <TextBlock Text="{Binding Message}" TextWrapping="Wrap"/>
        </Border>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
          <Button Content="{Binding OkText}" Command="{Binding OkCommand}"/>
          <Button Content="{Binding CancelText}" Command="{Binding CancelCommand}"/>
        </StackPanel>
      </StackPanel>
    </Border>
  </Grid>
</UserControl>
And somewhere in your game logic:
//...
var gui = GetComponent<NoesisGUIPanel>();
var mainWindowRoot = gui.GetRoot<Grid>();
MessageBox msgBox = new MessageBox { Title = "Quit?", Message = "Do you really want to quit?", ... };
mainWindowRoot.GetChildren().Add(msgBox);

Re: Dialog popups?

Posted: 02 Feb 2015, 15:08
by Scherub
I do it in a very similar way but my UserControl covers the whole screen. The outer part is only a non-clickable half transparent area that darkens the rest of the screen as long as the dialog is open. The inner bit is the actual dialog.

Re: Dialog popups?

Posted: 03 Feb 2015, 18:23
by sfernandez
If you take a deep look at my UserControl, I was trying to do the same you explained :)
The root Grid has a semitransparent background that hides and prevents clicking on the interface while the MessageBox is open. And the real message panel is centered in the screen.

Re: Dialog popups?

Posted: 03 Feb 2015, 19:54
by Scherub
Ups, now that I took a closer look at it you're right. Sorry about that. :oops: