Dialog popups?
How do you make a dialog popup -
MessageBox - with "Do you want to quit?" (Yes/No)
using Neosis inside Unity3d?
MessageBox - with "Do you want to quit?" (Yes/No)
using Neosis inside Unity3d?
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Dialog popups?
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.
And somewhere in your game logic:
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.
Code: Select all
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);
}
}
Code: Select all
<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>
Code: Select all
//...
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?
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.
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Dialog popups?
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.
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?
Ups, now that I took a closer look at it you're right. Sorry about that.
Who is online
Users browsing this forum: No registered users and 7 guests