elisa
Topic Author
Posts: 3
Joined: 01 Feb 2015, 05:32

Dialog popups?

01 Feb 2015, 05:37

How do you make a dialog popup -

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

using Neosis inside Unity3d?
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Dialog popups?

02 Feb 2015, 11:52

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);
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: Dialog popups?

02 Feb 2015, 15:08

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.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Dialog popups?

03 Feb 2015, 18:23

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.
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: Dialog popups?

03 Feb 2015, 19:54

Ups, now that I took a closer look at it you're right. Sorry about that. :oops:

Who is online

Users browsing this forum: Google [Bot] and 1 guest