Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
NewWorldScreen.cs
浏览该文件的文档.
1using System.Xml.Linq;
2
3namespace Game {
4 public class NewWorldScreen : Screen {
6
8
10
12
14
16
18
20
22
24
25 public Random m_random = new();
26
28
29 public const string fName = "NewWorldScreen";
30
31 public NewWorldScreen() {
32 XElement node = ContentManager.Get<XElement>("Screens/NewWorldScreen");
33 LoadContents(this, node);
34 m_nameTextBox = Children.Find<TextBoxWidget>("Name");
35 m_seedTextBox = Children.Find<TextBoxWidget>("Seed");
36 m_gameModeButton = Children.Find<ButtonWidget>("GameMode");
37 m_startingPositionButton = Children.Find<ButtonWidget>("StartingPosition");
38 m_worldOptionsButton = Children.Find<ButtonWidget>("WorldOptions");
39 m_blankSeedLabel = Children.Find<LabelWidget>("BlankSeed");
40 m_seedButton = Children.Find<ButtonWidget>("SeedButton");
41 m_descriptionLabel = Children.Find<LabelWidget>("Description");
42 m_errorLabel = Children.Find<LabelWidget>("Error");
43 m_playButton = Children.Find<ButtonWidget>("Play");
44 m_nameTextBox.TextChanged += delegate { m_worldSettings.Name = m_nameTextBox.Text; };
45 m_nameTextBox.MaximumLength = 128;
46 m_seedTextBox.TextChanged += delegate { m_worldSettings.Seed = m_seedTextBox.Text; };
47 }
48
49 public override void Enter(object[] parameters) {
53 OriginalSerializationVersion = VersionsManager.SerializationVersion
54 };
55 }
56 }
57
58 public override void Update() {
59 if (m_seedButton.IsClicked) {
61 null,
63 m_worldSettings.CustomWorldSeed ? null : m_seedTextBox.Text,
64 m_worldSettings.WorldSeed,
65 (seed, trueSeed) => {
66 if (seed == null) {
67 m_worldSettings.CustomWorldSeed = true;
68 m_worldSettings.WorldSeed = trueSeed;
69 m_seedTextBox.IsEnabled = false;
70 m_worldSettings.Seed = String.Empty;
71 }
72 else {
73 m_worldSettings.CustomWorldSeed = false;
74 m_worldSettings.WorldSeed = 0;
75 m_seedTextBox.IsEnabled = true;
76 m_seedTextBox.Text = seed;
77 }
78 }
79 )
80 );
81 }
84 null,
85 new SelectGameModeDialog(string.Empty, false, true, delegate(GameMode gameMode) { m_worldSettings.GameMode = gameMode; })
86 );
87 }
88 if (m_startingPositionButton.IsClicked) {
89 IList<int> enumValues2 = EnumUtils.GetEnumValues<StartingPositionMode>();
90 m_worldSettings.StartingPositionMode = (StartingPositionMode)((enumValues2.IndexOf((int)m_worldSettings.StartingPositionMode) + 1)
91 % enumValues2.Count);
92 }
93 bool flag = WorldsManager.ValidateWorldName(m_worldSettings.Name);
94 m_nameTextBox.Text = m_worldSettings.Name;
95 m_seedTextBox.Text = m_worldSettings.Seed;
96 m_gameModeButton.Text = LanguageControl.Get("GameMode", m_worldSettings.GameMode.ToString());
97 m_startingPositionButton.Text = LanguageControl.Get("StartingPositionMode", m_worldSettings.StartingPositionMode.ToString());
98 m_playButton.IsVisible = flag;
99 m_errorLabel.IsVisible = !flag;
100 m_blankSeedLabel.IsVisible = string.IsNullOrEmpty(m_worldSettings.Seed) && !m_seedTextBox.HasFocus;
101 m_blankSeedLabel.Text = m_worldSettings.CustomWorldSeed
102 ? string.Format(LanguageControl.Get(fName, "2"), m_worldSettings.WorldSeed)
103 : LanguageControl.Get(fName, "1");
104 m_descriptionLabel.Text = StringsManager.GetString($"GameMode.{m_worldSettings.GameMode}.Description");
105 if (m_worldOptionsButton.IsClicked) {
106 ScreensManager.SwitchScreen("WorldOptions", m_worldSettings, false);
107 }
108 if (m_playButton.IsClicked
109 && WorldsManager.ValidateWorldName(m_nameTextBox.Text)) {
110 if (m_worldSettings.GameMode != 0) {
111 m_worldSettings.ResetOptionsForNonCreativeMode(null);
112 }
113 WorldInfo worldInfo = WorldsManager.CreateWorld(m_worldSettings);
114 ScreensManager.SwitchScreen("GameLoading", worldInfo, null);
115 }
116 if (Input.Back
117 || Input.Cancel
118 || Children.Find<ButtonWidget>("TopBar.Back").IsClicked) {
119 ScreensManager.SwitchScreen("Play");
120 }
121 }
122 }
123}
readonly WidgetsList Children
static object Get(Type type, string name)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
ButtonWidget m_worldOptionsButton
override void Enter(object[] parameters)
ButtonWidget m_startingPositionButton
static Screen PreviousScreen
上一个Screen
virtual string Name
virtual void LoadContents(object eventsTarget, XElement node)
static ReadOnlyList< string > NewWorldNames
模组调整世界设置的界面需要继承该接口