Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
EditWorldSeedDialog.cs
浏览该文件的文档.
1using System.Xml.Linq;
2
3namespace Game {
4 public class EditWorldSeedDialog : Dialog {
5 public Action<string, int> m_handler;
6
13
14 public bool m_trueWorldSeedEdited = false;
15
16 public const string fName = "EditWorldSeedDialog";
17
18 public EditWorldSeedDialog(string seed, int trueSeed, Action<string, int> handler) {
19 m_handler = handler;
20 XElement node = ContentManager.Get<XElement>("Dialogs/EditWorldSeedDialog");
21 LoadContents(this, node);
22 m_worldSeedTextBox = Children.Find<TextBoxWidget>("EditWorldSeedDialog.WorldSeedTextBox");
23 m_worldSeedLabel = Children.Find<LabelWidget>("EditWorldSeedDialog.WorldSeedLabel");
24 m_trueWorldSeedTextBox = Children.Find<TextBoxWidget>("EditWorldSeedDialog.TrueWorldSeedTextBox");
25 m_resetButton = Children.Find<ButtonWidget>("EditWorldSeedDialog.ResetButton");
26 m_okButton = Children.Find<ButtonWidget>("EditWorldSeedDialog.OkButton");
27 m_cancelButton = Children.Find<ButtonWidget>("EditWorldSeedDialog.CancelButton");
28 if (seed == null) {
30 m_worldSeedTextBox.Text = string.Empty;
31 m_worldSeedLabel.Text = LanguageControl.Get(fName, "2");
32 m_worldSeedLabel.IsVisible = true;
33 m_trueWorldSeedTextBox.Text = trueSeed.ToString();
34 m_trueWorldSeedTextBox.HasFocus = true;
35 }
36 else {
37 m_worldSeedTextBox.Text = seed;
38 m_worldSeedTextBox.HasFocus = true;
39 m_trueWorldSeedTextBox.Text = SeedToTrueSeed(seed).ToString();
40 }
41 m_worldSeedTextBox.TextChanged += widget => {
43 return;
44 }
45 m_trueWorldSeedTextBox.ChangeTextNoEvent(SeedToTrueSeed(widget.Text).ToString());
46 if (string.IsNullOrEmpty(widget.Text)) {
47 m_worldSeedLabel.Text = LanguageControl.Get(fName, "1");
48 }
49 };
50 m_trueWorldSeedTextBox.TextChanged += widget => {
52 return;
53 }
55 m_worldSeedTextBox.Text = string.Empty;
56 m_worldSeedLabel.Text = LanguageControl.Get(fName, "2");
57 m_worldSeedLabel.IsVisible = true;
58 };
59 }
60
61 public override void Update() {
62 if (m_resetButton.IsClicked) {
64 m_worldSeedTextBox.Text = string.Empty;
65 m_worldSeedLabel.Text = LanguageControl.Get(fName, "1");
66 m_trueWorldSeedTextBox.ChangeTextNoEvent(string.Empty);
67 }
68 else if (Input.Cancel
69 || m_cancelButton.IsClicked) {
71 }
72 else if (Input.Ok
73 || m_okButton.IsClicked) {
75 if (int.TryParse(m_trueWorldSeedTextBox.Text, out int trueSeed)) {
77 m_handler?.Invoke(null, trueSeed);
78 }
79 else {
81 null,
83 );
84 }
85 }
86 else {
88 m_handler?.Invoke(m_worldSeedTextBox.Text, 0);
89 }
90 }
91 m_worldSeedLabel.IsVisible = m_trueWorldSeedEdited || (string.IsNullOrEmpty(m_worldSeedTextBox.Text) && !m_worldSeedTextBox.HasFocus);
92 }
93
94 public static int SeedToTrueSeed(string seed) {
95 int trueSeed = 0;
96 int num = 1;
97 foreach (char c in seed) {
98 trueSeed += c * num;
99 num += 29;
100 }
101 return trueSeed;
102 }
103 }
104}
readonly WidgetsList Children
static object Get(Type type, string name)
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static int SeedToTrueSeed(string seed)
EditWorldSeedDialog(string seed, int trueSeed, Action< string, int > handler)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual void LoadContents(object eventsTarget, XElement node)