Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
VitalStatsWidget.cs
浏览该文件的文档.
1using System.Globalization;
2using System.Xml.Linq;
3using Engine;
4
5namespace Game {
33
35 public const string fName = "VitalStatsWidget";
36
37 public VitalStatsWidget(ComponentPlayer componentPlayer) {
38 m_componentPlayer = componentPlayer;
39 XElement node = ContentManager.Get<XElement>("Widgets/VitalStatsWidget");
40 LoadContents(this, node);
41 m_titleLabel = Children.Find<LabelWidget>("TitleLabel");
42 m_healthLink = Children.Find<LinkWidget>("HealthLink");
43 m_healthValueBar = Children.Find<ValueBarWidget>("HealthValueBar");
44 m_staminaLink = Children.Find<LinkWidget>("StaminaLink");
45 m_staminaValueBar = Children.Find<ValueBarWidget>("StaminaValueBar");
46 m_foodLink = Children.Find<LinkWidget>("FoodLink");
47 m_foodValueBar = Children.Find<ValueBarWidget>("FoodValueBar");
48 m_sleepLink = Children.Find<LinkWidget>("SleepLink");
49 m_sleepValueBar = Children.Find<ValueBarWidget>("SleepValueBar");
50 m_temperatureLink = Children.Find<LinkWidget>("TemperatureLink");
51 m_temperatureValueBar = Children.Find<ValueBarWidget>("TemperatureValueBar");
52 m_wetnessLink = Children.Find<LinkWidget>("WetnessLink");
53 m_wetnessValueBar = Children.Find<ValueBarWidget>("WetnessValueBar");
54 m_chokeButton = Children.Find<ButtonWidget>("ChokeButton");
55 m_strengthLink = Children.Find<LinkWidget>("StrengthLink");
56 m_strengthLabel = Children.Find<LabelWidget>("StrengthLabel");
57 m_resilienceLink = Children.Find<LinkWidget>("ResilienceLink");
58 m_resilienceLabel = Children.Find<LabelWidget>("ResilienceLabel");
59 m_speedLink = Children.Find<LinkWidget>("SpeedLink");
60 m_speedLabel = Children.Find<LabelWidget>("SpeedLabel");
61 m_hungerLink = Children.Find<LinkWidget>("HungerLink");
62 m_hungerLabel = Children.Find<LabelWidget>("HungerLabel");
63 m_experienceLink = Children.Find<LinkWidget>("ExperienceLink");
64 m_experienceValueBar = Children.Find<ValueBarWidget>("ExperienceValueBar");
65 m_insulationLink = Children.Find<LinkWidget>("InsulationLink");
66 m_insulationLabel = Children.Find<LabelWidget>("InsulationLabel");
67 }
68
69 public override void Update() {
70 m_titleLabel.Text = string.Format(
72 m_componentPlayer.PlayerData.Name,
73 MathF.Floor(m_componentPlayer.PlayerData.Level),
74 LanguageControl.GetContentWidgets(fName, m_componentPlayer.PlayerData.PlayerClass.ToString())
75 );
76 m_healthValueBar.Value = m_componentPlayer.ComponentHealth.Health;
77 m_staminaValueBar.Value = m_componentPlayer.ComponentVitalStats.Stamina;
78 m_foodValueBar.Value = m_componentPlayer.ComponentVitalStats.Food;
79 m_sleepValueBar.Value = m_componentPlayer.ComponentVitalStats.Sleep;
80 m_temperatureValueBar.Value = m_componentPlayer.ComponentVitalStats.Temperature / 24f;
81 m_wetnessValueBar.Value = m_componentPlayer.ComponentVitalStats.Wetness;
82 m_experienceValueBar.Value = m_componentPlayer.PlayerData.Level - MathF.Floor(m_componentPlayer.PlayerData.Level);
83 m_strengthLabel.Text = string.Format(CultureInfo.InvariantCulture, "x {0:0.00}", m_componentPlayer.ComponentLevel.StrengthFactor);
84 m_resilienceLabel.Text = string.Format(CultureInfo.InvariantCulture, "x {0:0.00}", m_componentPlayer.ComponentLevel.ResilienceFactor);
85 m_speedLabel.Text = string.Format(CultureInfo.InvariantCulture, "x {0:0.00}", m_componentPlayer.ComponentLevel.SpeedFactor);
86 m_hungerLabel.Text = string.Format(CultureInfo.InvariantCulture, "x {0:0.00}", m_componentPlayer.ComponentLevel.HungerFactor);
87 m_insulationLabel.Text = string.Format(CultureInfo.InvariantCulture, "{0:0.00} clo", m_componentPlayer.ComponentClothing.Insulation);
88 if (m_healthLink.IsClicked) {
89 HelpTopic topic = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Health");
91 m_componentPlayer.GuiWidget,
92 new MessageDialog(topic.Title, topic.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
93 );
94 }
95 if (m_staminaLink.IsClicked) {
96 HelpTopic topic2 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Stamina");
98 m_componentPlayer.GuiWidget,
99 new MessageDialog(topic2.Title, topic2.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
100 );
101 }
102 if (m_foodLink.IsClicked) {
103 HelpTopic topic3 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Hunger");
105 m_componentPlayer.GuiWidget,
106 new MessageDialog(topic3.Title, topic3.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
107 );
108 }
109 if (m_sleepLink.IsClicked) {
110 HelpTopic topic4 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Sleep");
112 m_componentPlayer.GuiWidget,
113 new MessageDialog(topic4.Title, topic4.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
114 );
115 }
116 if (m_temperatureLink.IsClicked) {
117 HelpTopic topic5 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Temperature");
119 m_componentPlayer.GuiWidget,
120 new MessageDialog(topic5.Title, topic5.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
121 );
122 }
123 if (m_wetnessLink.IsClicked) {
124 HelpTopic topic6 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Wetness");
126 m_componentPlayer.GuiWidget,
127 new MessageDialog(topic6.Title, topic6.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
128 );
129 }
130 if (m_strengthLink.IsClicked) {
131 List<ComponentLevel.Factor> factors = m_componentPlayer.ComponentLevel.m_strengthFactors;
132 float total = m_componentPlayer.ComponentLevel.StrengthFactor;
134 m_componentPlayer.GuiWidget,
138 factors,
139 total
140 )
141 );
142 }
143 if (m_resilienceLink.IsClicked) {
144 List<ComponentLevel.Factor> factors2 = m_componentPlayer.ComponentLevel.m_resilienceFactors;
145 float total2 = m_componentPlayer.ComponentLevel.ResilienceFactor;
147 m_componentPlayer.GuiWidget,
151 factors2,
152 total2
153 )
154 );
155 }
156 if (m_speedLink.IsClicked) {
157 List<ComponentLevel.Factor> factors3 = m_componentPlayer.ComponentLevel.m_speedFactors;
158 float total3 = m_componentPlayer.ComponentLevel.SpeedFactor;
160 m_componentPlayer.GuiWidget,
164 factors3,
165 total3
166 )
167 );
168 }
169 if (m_hungerLink.IsClicked) {
170 List<ComponentLevel.Factor> factors4 = m_componentPlayer.ComponentLevel.m_hungerFactors;
171 float total4 = m_componentPlayer.ComponentLevel.HungerFactor;
173 m_componentPlayer.GuiWidget,
177 factors4,
178 total4
179 )
180 );
181 }
182 if (m_experienceLink.IsClicked) {
183 HelpTopic topic7 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Levels");
185 m_componentPlayer.GuiWidget,
186 new MessageDialog(topic7.Title, topic7.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
187 );
188 }
189 if (m_insulationLink.IsClicked) {
190 HelpTopic topic8 = ScreensManager.FindScreen<HelpScreen>("Help").GetTopic("Clothing");
192 m_componentPlayer.GuiWidget,
193 new MessageDialog(topic8.Title, topic8.Text, LanguageControl.Ok, null, new Vector2(700f, 360f), null)
194 );
195 }
196 if (m_chokeButton.IsClicked) {
197 m_componentPlayer.ComponentHealth.Injure(new SuicideInjury(0.1f));
198 }
199 }
200 }
201}
这里的Factor类型从struct改为class,是由于模组在修改Factor的时候,通常是需要修改引用的值。 如果是struct则只能复制并修改值,不能修改引用。
readonly WidgetsList Children
static object Get(Type type, string name)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static string GetContentWidgets(string name, string prop)
VitalStatsWidget(ComponentPlayer componentPlayer)
virtual void LoadContents(object eventsTarget, XElement node)