Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MessageDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3
4namespace Game {
5 public class MessageDialog : Dialog {
6 public Action<MessageDialogButton> m_handler;
7
9
11
13
15
16 public bool AutoHide { get; set; }
17
18 public MessageDialog(string largeMessage,
19 string smallMessage,
20 string button1Text,
21 string button2Text,
22 Vector2 size,
23 Action<MessageDialogButton> handler) {
24 m_handler = handler;
25 XElement node = ContentManager.Get<XElement>("Dialogs/MessageDialog");
26 LoadContents(this, node);
27 Size = new Vector2(size.X >= 0f ? size.X : Size.X, size.Y >= 0f ? size.Y : Size.Y);
28 m_largeLabelWidget = Children.Find<LabelWidget>("MessageDialog.LargeLabel");
29 m_smallLabelWidget = Children.Find<LabelWidget>("MessageDialog.SmallLabel");
30 m_button1Widget = Children.Find<ButtonWidget>("MessageDialog.Button1");
31 m_button2Widget = Children.Find<ButtonWidget>("MessageDialog.Button2");
32 m_largeLabelWidget.IsVisible = !string.IsNullOrEmpty(largeMessage);
33 m_largeLabelWidget.Text = largeMessage ?? string.Empty;
34 m_smallLabelWidget.IsVisible = !string.IsNullOrEmpty(smallMessage);
35 m_smallLabelWidget.Text = smallMessage ?? string.Empty;
36 //if (largeMessage == LanguageControl.Get("ModifyWorldScreen",1))
37 //m_smallLabelWidget.Color = Color.Red;
38 m_button1Widget.IsVisible = !string.IsNullOrEmpty(button1Text);
39 m_button1Widget.Text = button1Text ?? string.Empty;
40 m_button2Widget.IsVisible = !string.IsNullOrEmpty(button2Text);
41 m_button2Widget.Text = button2Text ?? string.Empty;
42 if (!m_button1Widget.IsVisible
43 && !m_button2Widget.IsVisible) {
44 throw new InvalidOperationException("MessageDialog must have at least one button.");
45 }
46 AutoHide = true;
47 }
48
49 public MessageDialog(string largeMessage, string smallMessage, string button1Text, string button2Text, Action<MessageDialogButton> handler) :
50 this(largeMessage, smallMessage, button1Text, button2Text, new Vector2(-1f), handler) { }
51
52 public override void Update() {
53 if (Input.Cancel) {
54 if (m_button2Widget.IsVisible) {
56 }
57 else {
59 }
60 }
61 else if (Input.Ok
62 || m_button1Widget.IsClicked) {
64 }
65 else if (m_button2Widget.IsClicked) {
67 }
68 }
69
70 public void Dismiss(MessageDialogButton button) {
71 if (AutoHide) {
73 }
74 m_handler?.Invoke(button);
75 }
76 }
77}
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
MessageDialog(string largeMessage, string smallMessage, string button1Text, string button2Text, Vector2 size, Action< MessageDialogButton > handler)
Action< MessageDialogButton > m_handler
MessageDialog(string largeMessage, string smallMessage, string button1Text, string button2Text, Action< MessageDialogButton > handler)
void Dismiss(MessageDialogButton button)
LabelWidget m_largeLabelWidget
virtual void LoadContents(object eventsTarget, XElement node)