#region Copyright
/*
--------------------------------------------------------------------------------
This source file is part of Xenocide
by Project Xenocide Team
For the latest info on Xenocide, see http://www.projectxenocide.com/
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 2.5 License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.
--------------------------------------------------------------------------------
*/
/*
* @file YesNoDialog.cs
* @date Created: 2007/05/07
* @author File creator: dteviot
* @author Credits: none
*/
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using CeGui;
using ProjectXenocide.UI.Screens;
using Xenocide.Resources;
#endregion
namespace ProjectXenocide.UI.Dialogs
{
///
/// Dialog that asks user a question with "yes" and "no" buttons for getting the answer
///
public class YesNoDialog : Dialog
{
///
/// Constructor
///
/// Text to show on dialog
/// Text to show on yes button
/// Text to show on no button
public YesNoDialog(string messageText, String yesButtonText, String noButtonText)
: this(messageText, Strings.DLG_YESNO_TITLE, yesButtonText, noButtonText)
{
}
///
/// Constructor
///
/// Text to show on dialog
/// Text to show on the dialog title bar
/// Text to show on yes button
/// Text to show on no button
public YesNoDialog(string messageText, String title, String yesButtonText, String noButtonText)
: base(new System.Drawing.SizeF(0.5f, 0.3f), title)
{
this.messageText = messageText;
this.yesButtonText = yesButtonText;
this.noButtonText = noButtonText;
}
///
/// Constructor
///
/// Text to show on dialog
public YesNoDialog(string messageText)
: this(messageText, null, null)
{
}
///
/// Constructor
///
/// Text to show on dialog
/// Text to show on the dialog title bar
public YesNoDialog(string messageText, string title)
: this(messageText, title, null, null)
{
}
///
/// Create a YesNoDialog with 'OK' and 'Cancel' buttons
///
/// the YesNoDialog
public static YesNoDialog OkCancelDialog(string messageText)
{
return new YesNoDialog(messageText, Strings.BUTTON_OK, Strings.BUTTON_CANCEL);
}
///
/// Create a YesNoDialog with 'OK' and 'Cancel' buttons
///
/// Text to show on dialog
/// Text to show on the dialog title bar
/// the YesNoDialog
public static YesNoDialog OkCancelDialog(string messageText, string title)
{
return new YesNoDialog(messageText, title, Strings.BUTTON_OK, Strings.BUTTON_CANCEL);
}
#region Create the CeGui widgets
///
/// add the buttons to the screen
///
protected override void CreateCeguiWidgets()
{
// static text to show the message
textWindow = GuiBuilder.CreateText(CeguiId + "_text");
AddWidget(textWindow, 0.02f, 0.073f, 0.96f, 0.52f);
textWindow.Text = messageText;
textWindow.HorizontalFormat = HorizontalTextFormat.WordWrapLeft;
// other buttons
yesButton = AddButton("BUTTON_YES", 0.2500f, 0.80f, 0.2275f, 0.10f);
noButton = AddButton("BUTTON_NO", 0.7475f, 0.80f, 0.2275f, 0.10f);
yesButton.Clicked += new CeGui.GuiEventHandler(OnYesClicked);
noButton.Clicked += new CeGui.GuiEventHandler(OnNoClicked);
// Set text on yes and no buttons (if necessary)
SetButtonText();
}
private CeGui.Widgets.StaticText textWindow;
private CeGui.Widgets.PushButton yesButton;
private CeGui.Widgets.PushButton noButton;
#endregion Create the CeGui widgets
///
/// Set the text on the yes and no butons
///
private void SetButtonText()
{
if (!String.IsNullOrEmpty(yesButtonText))
{
yesButton.Text = yesButtonText;
}
if (!String.IsNullOrEmpty(noButtonText))
{
noButton.Text = noButtonText;
}
}
#region event handlers
/// React to user pressing the "yes" button
/// Not used
/// Not used
private void OnYesClicked(object sender, CeGui.GuiEventArgs e)
{
if (null != yesAction)
{
yesAction();
}
ScreenManager.CloseDialog(this);
}
/// React to user pressing the "no" button
/// Not used
/// Not used
private void OnNoClicked(object sender, CeGui.GuiEventArgs e)
{
if (null != noAction)
{
noAction();
}
ScreenManager.CloseDialog(this);
}
#endregion event handlers
#region Fields
///
/// What to do when Yes button is pressed
///
public ButtonAction YesAction { get { return yesAction; } set { yesAction = value; } }
///
/// What to do when No button is pressed
///
public ButtonAction NoAction { get { return noAction; } set { noAction = value; } }
///
/// What to do when Yes button is pressed
///
private ButtonAction yesAction;
///
/// What to do when No button is pressed
///
private ButtonAction noAction;
///
/// Text shown on dialog
///
private string messageText;
///
/// Text to show on Yes button
///
private string yesButtonText;
///
/// Text to show on no button
///
private string noButtonText;
#endregion
}
}