Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentGui.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
9
11
12 public float Factor;
13 }
14
15 public class Message {
16 public string LargeText;
17
18 public string SmallText;
19
20 public double StartTime;
21
22 public float Duration;
23 }
24
25 public static string fName = "ComponentGui";
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
103 public float m_sidePanelsFactor;
104
106
108
110
112
114
116
118
119 public static Func<Widget> OpenClothingWidget;
120
122
123 public GameWidget GameWidget { get; set; }
124
126
127 public TouchInputWidget ViewWidget { get; set; }
128
129 public TouchInputWidget MoveWidget { get; set; }
130
131 public MoveRoseWidget MoveRoseWidget { get; set; }
132
133 public TouchInputWidget LookWidget { get; set; }
134
136
137 public ValueBarWidget HealthBarWidget { get; set; }
138
139 public ValueBarWidget FoodBarWidget { get; set; }
140
142
143 public LabelWidget LevelLabelWidget { get; set; }
144
145 public virtual bool ShowTouchWidget => m_componentPlayer.ComponentInput.IsControlledByTouch;
146
148 get {
150 || m_modalPanelContainerWidget.Children.Count <= 0) {
151 return null;
152 }
153 return m_modalPanelContainerWidget.Children[0];
154 }
155 set {
156 if (value != ModalPanelWidget) {
157 if (m_modalPanelAnimationData != null) {
159 }
160 m_modalPanelAnimationData = new ModalPanelAnimationData { OldWidget = ModalPanelWidget, NewWidget = value };
161 if (value != null) {
162 value.HorizontalAlignment = WidgetAlignment.Center;
163 m_modalPanelContainerWidget.Children.Insert(0, value);
164 }
166 m_componentPlayer.GameWidget.Input.Clear();
167 m_componentPlayer.ComponentInput.SetSplitSourceInventoryAndSlot(null, -1);
169 "OnModalPanelWidgetSet",
170 loader => {
171 loader.OnModalPanelWidgetSet(this, ModalPanelWidget, value);
172 return false;
173 }
174 );
175 }
176 }
177 }
178
180
181 public int[] DrawOrders => [9];
182
183 public virtual void DisplayLargeMessage(string largeText, string smallText, float duration, float delay) {
184 m_message = new Message { LargeText = largeText, SmallText = smallText, Duration = duration, StartTime = Time.RealTime + delay };
185 }
186
187 public virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound) {
188 MessageWidget.Message message = new(text, color, blinking);
189 DisplaySmallMessage(message, playNotificationSound);
190 }
191
192 // ReSharper disable MethodOverloadWithOptionalParameter
193 public virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound, float fontScale = 1f)
194 // ReSharper restore MethodOverloadWithOptionalParameter
195 {
196 MessageWidget.Message message = new(text, color, blinking, fontScale);
197 DisplaySmallMessage(message, playNotificationSound);
198 }
199
205 public virtual void DisplaySmallMessage(MessageWidget.Message message, bool playNotificationSound) {
206 m_messageWidget.DisplayMessage(message);
207 if (playNotificationSound) {
208 m_subsystemAudio.PlaySound("Audio/UI/Message", 1f, 0f, 0f, 0f);
209 }
210 }
211
212 public virtual bool IsGameMenuDialogVisible() {
213 foreach (Dialog dialog in DialogsManager.Dialogs) {
214 if (dialog.ParentWidget == m_componentPlayer.GuiWidget
215 && dialog is GameMenuDialog) {
216 return true;
217 }
218 }
219 return false;
220 }
221
222 public virtual void Update(float dt) {
223 HandleInput();
226 "GuiUpdate",
227 modLoader => {
228 modLoader.GuiUpdate(this);
229 return false;
230 }
231 );
232 }
233
234 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
235 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
236 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
237 m_subsystemTimeOfDay = Project.FindSubsystem<SubsystemTimeOfDay>(true);
238 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
239 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
240 m_subsystemWeather = Project.FindSubsystem<SubsystemWeather>(true);
242 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
243 m_componentInput = Entity.FindComponent<ComponentInput>();
244 GameWidget = m_componentPlayer.GameWidget;
245 ContainerWidget guiWidget = m_componentPlayer.GuiWidget;
246 m_backButtonWidget = guiWidget.Children.Find<ButtonWidget>("BackButton");
247 m_inventoryButtonWidget = guiWidget.Children.Find<ButtonWidget>("InventoryButton");
248 m_clothingButtonWidget = guiWidget.Children.Find<ButtonWidget>("ClothingButton");
249 m_moreButtonWidget = guiWidget.Children.Find<ButtonWidget>("MoreButton");
250 m_moreContentsWidget = guiWidget.Children.Find<Widget>("MoreContents");
251 m_helpButtonWidget = guiWidget.Children.Find<ButtonWidget>("HelpButton");
252 m_photoButtonWidget = guiWidget.Children.Find<ButtonWidget>("PhotoButton");
253 m_lightningButtonWidget = guiWidget.Children.Find<ButtonWidget>("LightningButton");
254 m_precipitationButtonWidget = guiWidget.Children.Find<ButtonWidget>("PrecipitationButton");
255 m_fogButtonWidget = guiWidget.Children.Find<ButtonWidget>("FogButton");
256 m_timeOfDayButtonWidget = guiWidget.Children.Find<ButtonWidget>("TimeOfDayButton");
257 m_cameraButtonWidget = guiWidget.Children.Find<ButtonWidget>("CameraButton");
258 m_creativeFlyButtonWidget = guiWidget.Children.Find<ButtonWidget>("CreativeFlyButton");
259 m_crouchButtonWidget = guiWidget.Children.Find<ButtonWidget>("CrouchButton");
260 m_mountButtonWidget = guiWidget.Children.Find<ButtonWidget>("MountButton");
261 m_editItemButton = guiWidget.Children.Find<ButtonWidget>("EditItemButton");
262 MoveWidget = guiWidget.Children.Find<TouchInputWidget>("Move");
263 MoveRoseWidget = guiWidget.Children.Find<MoveRoseWidget>("MoveRose");
264 LookWidget = guiWidget.Children.Find<TouchInputWidget>("Look");
265 ViewWidget = m_componentPlayer.ViewWidget;
266 HealthBarWidget = guiWidget.Children.Find<ValueBarWidget>("HealthBar");
267 FoodBarWidget = guiWidget.Children.Find<ValueBarWidget>("FoodBar");
268 TemperatureBarWidget = guiWidget.Children.Find<ValueBarWidget>("TemperatureBar");
269 LevelLabelWidget = guiWidget.Children.Find<LabelWidget>("LevelLabel");
270 m_modalPanelContainerWidget = guiWidget.Children.Find<ContainerWidget>("ModalPanelContainer");
271 ControlsContainerWidget = guiWidget.Children.Find<ContainerWidget>("ControlsContainer");
272 m_leftControlsContainerWidget = guiWidget.Children.Find<ContainerWidget>("LeftControlsContainer");
273 m_rightControlsContainerWidget = guiWidget.Children.Find<ContainerWidget>("RightControlsContainer");
274 m_moveContainerWidget = guiWidget.Children.Find<ContainerWidget>("MoveContainer");
275 m_lookContainerWidget = guiWidget.Children.Find<ContainerWidget>("LookContainer");
276 m_moveRectangleWidget = guiWidget.Children.Find<RectangleWidget>("MoveRectangle");
277 m_lookRectangleWidget = guiWidget.Children.Find<RectangleWidget>("LookRectangle");
278 m_moveRectangleContainerWidget = guiWidget.Children.Find<ContainerWidget>("MoveRectangleContainer");
279 m_lookRectangleContainerWidget = guiWidget.Children.Find<ContainerWidget>("LookRectangleContainer");
280 m_moveRectangleWidget = guiWidget.Children.Find<RectangleWidget>("MoveRectangle");
281 m_lookRectangleWidget = guiWidget.Children.Find<RectangleWidget>("LookRectangle");
282 m_movePadContainerWidget = guiWidget.Children.Find<ContainerWidget>("MovePadContainer");
283 m_lookPadContainerWidget = guiWidget.Children.Find<ContainerWidget>("LookPadContainer");
284 m_moveButtonsContainerWidget = guiWidget.Children.Find<ContainerWidget>("MoveButtonsContainer");
285 ShortInventoryWidget = guiWidget.Children.Find<ShortInventoryWidget>("ShortInventory");
286 m_largeMessageWidget = guiWidget.Children.Find<ContainerWidget>("LargeMessage");
287 m_messageWidget = guiWidget.Children.Find<MessageWidget>("Message");
288 m_keyboardHelpMessageShown = valuesDictionary.GetValue<bool>("KeyboardHelpMessageShown");
289 m_gamepadHelpMessageShown = valuesDictionary.GetValue<bool>("GamepadHelpMessageShown");
290 WorldSettings worldSettings = m_subsystemGameInfo.WorldSettings;
291 GameMode gameMode = worldSettings.GameMode;
292 bool isCreative = gameMode == GameMode.Creative;
293 m_creativeFlyButtonWidget.IsVisible = isCreative;
294 m_timeOfDayButtonWidget.IsVisible = isCreative;
295 m_lightningButtonWidget.IsVisible = isCreative;
296 m_precipitationButtonWidget.IsVisible = isCreative && worldSettings.AreWeatherEffectsEnabled;
297 m_fogButtonWidget.IsVisible = isCreative && worldSettings.AreWeatherEffectsEnabled;
298 //启动冒险模式
299 bool adventureEnabled = worldSettings.AreAdventureSurvivalMechanicsEnabled;
300 HealthBarWidget.IsVisible = !isCreative;
301 FoodBarWidget.IsVisible = !isCreative && adventureEnabled;
302 TemperatureBarWidget.IsVisible = !isCreative && adventureEnabled;
303 LevelLabelWidget.IsVisible = !isCreative && adventureEnabled;
304 }
305
306 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
307 valuesDictionary.SetValue("KeyboardHelpMessageShown", m_keyboardHelpMessageShown);
308 valuesDictionary.SetValue("GamepadHelpMessageShown", m_gamepadHelpMessageShown);
309 }
310
311 public override void OnEntityAdded() {
312 ShortInventoryWidget.AssignComponents(m_componentPlayer.ComponentMiner.Inventory);
313 }
314
315 public override void OnEntityRemoved() {
316 ShortInventoryWidget.AssignComponents(null);
317 m_message = null;
318 }
319
320 public override void Dispose() {
321 ModalPanelWidget = null;
323 if (ShortInventoryWidget != null) {
324 ShortInventoryWidget.AssignComponents(null);
325 }
326 }
327
328 public virtual void UpdateSidePanelsAnimation() {
329 float num = MathUtils.Min(Time.FrameDuration, 0.1f);
330 bool showModelWidget = ModalPanelWidget != null && (m_modalPanelAnimationData == null || m_modalPanelAnimationData.NewWidget != null);
331 float targetSidePanelsFactor = (ShowTouchWidget | showModelWidget) ? 0 : 1;
332 float x = targetSidePanelsFactor - m_sidePanelsFactor;
333 if (MathF.Abs(x) > 0.01f) {
334 m_sidePanelsFactor += Math.Clamp(12f * MathUtils.PowSign(x, 0.75f) * num, 0f - MathF.Abs(x), MathF.Abs(x));
335 }
336 else {
337 m_sidePanelsFactor = targetSidePanelsFactor;
338 }
339 m_leftControlsContainerWidget.RenderTransform = Matrix.CreateTranslation(
341 0f,
342 0f
343 );
344 m_rightControlsContainerWidget.RenderTransform = Matrix.CreateTranslation(
346 0f,
347 0f
348 );
349 }
350
351 public virtual void UpdateModalPanelAnimation() {
352 m_modalPanelAnimationData.Factor += 6f * MathUtils.Min(Time.FrameDuration, 0.1f);
353 if (m_modalPanelAnimationData.Factor < 1f) {
354 float factor = m_modalPanelAnimationData.Factor;
355 float num = 0.5f + 0.5f * MathF.Pow(1f - factor, 0.1f);
356 float num2 = 0.5f + 0.5f * MathF.Pow(factor, 0.1f);
357 float s = 1f - factor;
358 float s2 = factor;
359 if (m_modalPanelAnimationData.OldWidget != null) {
360 Vector2 actualSize = m_modalPanelAnimationData.OldWidget.ActualSize;
361 m_modalPanelAnimationData.OldWidget.ColorTransform = Color.White * s;
362 m_modalPanelAnimationData.OldWidget.RenderTransform =
363 Matrix.CreateTranslation((0f - actualSize.X) / 2f, (0f - actualSize.Y) / 2f, 0f)
364 * Matrix.CreateScale(num, num, 1f)
365 * Matrix.CreateTranslation(actualSize.X / 2f, actualSize.Y / 2f, 0f);
366 }
367 if (m_modalPanelAnimationData.NewWidget != null) {
368 Vector2 actualSize2 = m_modalPanelAnimationData.NewWidget.ActualSize;
369 m_modalPanelAnimationData.NewWidget.ColorTransform = Color.White * s2;
370 m_modalPanelAnimationData.NewWidget.RenderTransform =
371 Matrix.CreateTranslation((0f - actualSize2.X) / 2f, (0f - actualSize2.Y) / 2f, 0f)
372 * Matrix.CreateScale(num2, num2, 1f)
373 * Matrix.CreateTranslation(actualSize2.X / 2f, actualSize2.Y / 2f, 0f);
374 }
375 }
376 else {
378 }
379 }
380
381 public virtual void EndModalPanelAnimation() {
382 if (m_modalPanelAnimationData.OldWidget != null) {
384 }
385 if (m_modalPanelAnimationData.NewWidget != null) {
386 m_modalPanelAnimationData.NewWidget.ColorTransform = Color.White;
387 m_modalPanelAnimationData.NewWidget.RenderTransform = Matrix.Identity;
388 }
390 }
391
392 public virtual void UpdateWidgets() {
393 ComponentRider componentRider = m_componentPlayer.ComponentRider;
394 ComponentSleep componentSleep = m_componentPlayer.ComponentSleep;
395 //ComponentInput componentInput = m_componentPlayer.ComponentInput;
396 //WorldSettings worldSettings = m_subsystemGameInfo.WorldSettings;
397 //GameMode gameMode = worldSettings.GameMode;
399 if (m_modalPanelAnimationData != null) {
401 }
402 if (m_message != null) {
403 double realTime = Time.RealTime;
404 m_largeMessageWidget.IsVisible = true;
405 LabelWidget labelWidget = m_largeMessageWidget.Children.Find<LabelWidget>("LargeLabel");
406 LabelWidget labelWidget2 = m_largeMessageWidget.Children.Find<LabelWidget>("SmallLabel");
407 labelWidget.Text = m_message.LargeText;
408 labelWidget2.Text = m_message.SmallText;
409 labelWidget.IsVisible = !string.IsNullOrEmpty(m_message.LargeText);
410 labelWidget2.IsVisible = !string.IsNullOrEmpty(m_message.SmallText);
411 float num = (float)Math.Min(
412 MathUtils.Saturate(2.0 * (realTime - m_message.StartTime)),
413 MathUtils.Saturate(2.0 * (m_message.StartTime + m_message.Duration - realTime))
414 );
415 labelWidget.Color = new Color(num, num, num, num);
416 labelWidget2.Color = new Color(num, num, num, num);
417 if (Time.RealTime > m_message.StartTime + m_message.Duration) {
418 m_message = null;
419 }
420 }
421 else {
422 m_largeMessageWidget.IsVisible = false;
423 }
424 ControlsContainerWidget.IsVisible = m_componentPlayer.PlayerData.IsReadyForPlaying
425 && m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled
426 && componentSleep.SleepFactor <= 0f;
427 m_moveRectangleContainerWidget.IsVisible = !SettingsManager.HideMoveLookPads && ShowTouchWidget;
428 bool flag = false;
432 flag = true;
433 }
435 flag = true;
436 }
437 }
438 m_lookRectangleContainerWidget.IsVisible = flag;
439 m_lookPadContainerWidget.IsVisible = !SettingsManager.HideMoveLookPads && ShowTouchWidget;
441 m_moreContentsWidget.IsVisible = m_moreButtonWidget.IsChecked;
442 m_moveButtonsContainerWidget.IsVisible = SettingsManager.MoveControlMode == MoveControlMode.Buttons;
443 m_movePadContainerWidget.IsVisible = SettingsManager.MoveControlMode == MoveControlMode.Pad;
445 m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
446 m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
447 m_moveRectangleWidget.FlipHorizontal = true;
448 m_lookRectangleWidget.FlipHorizontal = false;
449 }
450 else {
451 m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
452 m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
453 m_moveRectangleWidget.FlipHorizontal = false;
454 m_lookRectangleWidget.FlipHorizontal = true;
455 }
457 * ControlsContainerWidget.ActualSize;
458 m_precipitationButtonWidget.IsChecked = m_subsystemWeather.IsPrecipitationStarted;
459 m_fogButtonWidget.IsChecked = m_subsystemWeather.IsFogStarted;
460 m_crouchButtonWidget.IsChecked = m_componentPlayer.ComponentBody.TargetCrouchFactor > 0f;
461 m_creativeFlyButtonWidget.IsChecked = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
462 m_inventoryButtonWidget.IsChecked = IsInventoryVisible();
463 m_clothingButtonWidget.IsChecked = IsClothingVisible();
465 || m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue) {
466 m_crouchButtonWidget.IsVisible = false;
467 m_mountButtonWidget.IsVisible = false;
468 m_editItemButton.IsVisible = true;
469 }
470 else if (componentRider != null
471 && componentRider.Mount != null) {
472 m_crouchButtonWidget.IsVisible = false;
473 m_mountButtonWidget.IsChecked = true;
474 m_mountButtonWidget.IsVisible = true;
475 m_editItemButton.IsVisible = false;
476 }
477 else {
478 m_mountButtonWidget.IsChecked = false;
479 if (componentRider != null
482 if (componentRider.FindNearestMount() != null) {
483 m_crouchButtonWidget.IsVisible = false;
484 m_mountButtonWidget.IsVisible = true;
485 m_editItemButton.IsVisible = false;
486 }
487 else {
488 m_crouchButtonWidget.IsVisible = true;
489 m_mountButtonWidget.IsVisible = false;
490 m_editItemButton.IsVisible = false;
491 }
492 }
493 }
494 if (!m_componentPlayer.IsAddedToProject
495 || m_componentPlayer.ComponentHealth.Health == 0f
496 || componentSleep.IsSleeping
497 || m_componentPlayer.ComponentSickness.IsPuking) {
498 ModalPanelWidget = null;
499 }
500 if (m_componentPlayer.ComponentSickness.IsSick) {
501 m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(166, 175, 103);
502 }
503 else {
504 m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = m_componentPlayer.ComponentFlu.HasFlu
505 ? new Color(0, 48, 255)
506 : new Color(224, 24, 0);
507 }
508 }
509
510 public virtual void HandleInput() {
511 WidgetInput input = m_componentPlayer.GameWidget.Input;
512 PlayerInput playerInput = m_componentPlayer.ComponentInput.PlayerInput;
513 ComponentRider componentRider = m_componentPlayer.ComponentRider;
514 if (m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled) {
516 && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0
517 && Time.PeriodicEvent(7.0, 0.0)) {
520 }
522 && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0
523 && Time.PeriodicEvent(7.0, 0.0)) {
526 }
527 }
528 if (playerInput.KeyboardHelp) {
529 ScreensManager.SwitchScreen("KeyboardMapping");
530 }
531 if (playerInput.GamepadHelp) {
532 ScreensManager.SwitchScreen("GamepadMapping");
533 }
534 if (m_helpButtonWidget.IsClicked) {
536 }
537 if (playerInput.ToggleInventory
538 || m_inventoryButtonWidget.IsClicked) {
539 if (IsInventoryVisible()) {
540 ModalPanelWidget = null;
541 }
542 else {
543 ModalPanelWidget = m_componentPlayer.ComponentMiner.Inventory is ComponentCreativeInventory
546 m_componentPlayer.ComponentMiner.Inventory,
547 m_componentPlayer.Entity.FindComponent<ComponentCraftingTable>(true)
548 );
549 }
550 }
551 if (playerInput.ToggleClothing
552 || m_clothingButtonWidget.IsClicked) {
553 if (IsClothingVisible()) {
554 ModalPanelWidget = null;
555 }
556 else {
557 ClothingWidget clothingWidget = new(m_componentPlayer);
559 "ClothingWidgetOpen",
560 modLoader => {
561 modLoader.ClothingWidgetOpen(this, clothingWidget);
562 return false;
563 }
564 );
565 ModalPanelWidget = clothingWidget;
566 }
567 }
568 if (m_crouchButtonWidget.IsClicked
569 || playerInput.ToggleCrouch) {
570 if (m_componentPlayer.ComponentBody.TargetCrouchFactor == 0f) {
571 if (m_componentPlayer.ComponentBody.StandingOnValue.HasValue) {
572 m_componentPlayer.ComponentBody.TargetCrouchFactor = 1f;
574 }
575 }
576 else {
577 m_componentPlayer.ComponentBody.TargetCrouchFactor = 0f;
579 }
580 }
581 if (componentRider != null
582 && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount)) {
583 bool flag = componentRider.Mount != null;
584 if (flag) {
585 componentRider.StartDismounting();
586 }
587 else {
588 ComponentMount componentMount = componentRider.FindNearestMount();
589 if (componentMount != null) {
590 componentRider.StartMounting(componentMount);
591 }
592 }
593 if (componentRider.Mount != null != flag) {
595 componentRider.Mount != null ? LanguageControl.Get(fName, 5) : LanguageControl.Get(fName, 6),
596 Color.White,
597 false,
598 false
599 );
600 }
601 }
602 if ((m_editItemButton.IsClicked || playerInput.EditItem)
603 && m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue) {
604 Point3 value = m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.Value;
605 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(value.X, value.Y, value.Z);
606 SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(cellValue));
607 for (int i = 0;
608 i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(value.X, value.Y, value.Z, cellValue, m_componentPlayer);
609 i++) { }
610 }
611 else if ((m_editItemButton.IsClicked || playerInput.EditItem)
613 IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
614 if (inventory != null) {
615 int activeSlotIndex = inventory.ActiveSlotIndex;
616 int value = inventory.GetSlotValue(activeSlotIndex);
617 int num = Terrain.ExtractContents(value);
618 if (BlocksManager.Blocks[num].IsEditable_(value)) {
619 SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(num));
620 for (int i = 0;
621 i < blockBehaviors.Length && !blockBehaviors[i].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer);
622 i++) { }
623 }
624 }
625 }
626 if (m_creativeFlyButtonWidget.IsVisible
627 && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly)
628 && componentRider.Mount == null) {
629 bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
630 m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
631 if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled) {
632 if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled) {
633 m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
635 }
636 else {
638 }
639 }
640 }
641 if (m_cameraButtonWidget.IsClicked
642 || playerInput.SwitchCameraMode) {
644 "OnCameraChange",
645 modLoader => {
646 modLoader.OnCameraChange(m_componentPlayer, this);
647 return false;
648 }
649 );
650 }
651 if (m_photoButtonWidget.IsClicked
652 || playerInput.TakeScreenshot) {
654 delegate { DisplaySmallMessage(LanguageControl.Get(fName, 13), Color.White, false, false); },
655 delegate { DisplaySmallMessage(LanguageControl.Get(fName, 14), Color.White, false, false); }
656 );
657 }
658 if (m_lightningButtonWidget.IsVisible
659 && (m_lightningButtonWidget.IsClicked || playerInput.Lighting)) {
660 Matrix matrix = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
661 m_subsystemWeather.ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, matrix.Forward);
662 }
663 if (m_precipitationButtonWidget.IsVisible
664 && (m_precipitationButtonWidget.IsClicked || playerInput.Precipitation)) {
665 if (m_subsystemWeather.IsPrecipitationStarted) {
666 m_subsystemWeather.ManualPrecipitationEnd();
668 }
669 else {
670 m_subsystemWeather.ManualPrecipitationStart();
672 }
673 }
674 if (m_fogButtonWidget.IsVisible
675 && (m_fogButtonWidget.IsClicked || playerInput.Fog)) {
676 if (m_subsystemWeather.IsFogStarted) {
677 m_subsystemWeather.ManualFogEnd();
679 }
680 else {
681 m_subsystemWeather.ManualFogStart();
683 }
684 }
685 if (m_timeOfDayButtonWidget.IsVisible
686 && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay)) {
687 float num2 = IntervalUtils.Interval(m_subsystemTimeOfDay.TimeOfDay, m_subsystemTimeOfDay.Middawn);
688 float num3 = IntervalUtils.Interval(m_subsystemTimeOfDay.TimeOfDay, m_subsystemTimeOfDay.Midday);
689 float num4 = IntervalUtils.Interval(m_subsystemTimeOfDay.TimeOfDay, m_subsystemTimeOfDay.Middusk);
690 float num5 = IntervalUtils.Interval(m_subsystemTimeOfDay.TimeOfDay, m_subsystemTimeOfDay.Midnight);
691 float num6 = MathUtils.Min(num2, num3, num4, num5);
692 if (num2 == num6) {
693 m_subsystemTimeOfDay.TimeOfDayOffset += num2;
695 }
696 else if (num3 == num6) {
697 m_subsystemTimeOfDay.TimeOfDayOffset += num3;
699 }
700 else if (num4 == num6) {
701 m_subsystemTimeOfDay.TimeOfDayOffset += num4;
703 }
704 else if (num5 == num6) {
705 m_subsystemTimeOfDay.TimeOfDayOffset += num5;
707 }
708 }
709 if (ModalPanelWidget != null) {
710 if (input.Cancel
711 || input.Back
712 || m_backButtonWidget.IsClicked) {
713 ModalPanelWidget = null;
714 }
715 }
716 else if (input.Back
717 || m_backButtonWidget.IsClicked) {
719 }
720 }
721
723
724 public virtual bool IsInventoryVisible() {
725 if (ModalPanelWidget != null) {
726 return !IsClothingVisible();
727 }
728 return false;
729 }
730
731 public virtual bool IsActiveSlotEditable() {
732 IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
733 if (inventory != null) {
734 int activeSlotIndex = inventory.ActiveSlotIndex;
735 int value = inventory.GetSlotValue(activeSlotIndex);
736 int num = Terrain.ExtractContents(value);
737 if (BlocksManager.Blocks[num].IsEditable_(value)) {
738 return true;
739 }
740 }
741 return false;
742 }
743
744 public virtual void Draw(Camera camera, int drawOrder) {
746 "GuiDraw",
747 modloader => {
748 modloader.GuiDraw(this, camera, drawOrder);
749 return false;
750 }
751 );
752 }
753 }
754}
Engine.Color Color
static int Min(int x1, int x2)
static float Saturate(float x)
static float PowSign(float x, float n)
static double RealTime
定义 Time.cs:38
static float FrameDuration
定义 Time.cs:46
static bool PeriodicEvent(double period, double offset)
定义 Time.cs:63
static double FrameStartTime
定义 Time.cs:42
virtual bool IsEditable_(int value)
ContainerWidget m_moveRectangleContainerWidget
GamepadHelpDialog m_gamepadHelpDialog
virtual bool IsClothingVisible()
RectangleWidget m_lookRectangleWidget
override void Dispose()
ButtonWidget m_editItemButton
virtual void UpdateWidgets()
SubsystemAudio m_subsystemAudio
ButtonWidget m_inventoryButtonWidget
ButtonWidget m_fogButtonWidget
SubsystemBlockBehaviors m_subsystemBlockBehaviors
ContainerWidget m_moveButtonsContainerWidget
ContainerWidget m_lookContainerWidget
ValueBarWidget TemperatureBarWidget
RectangleWidget m_moveRectangleWidget
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
ButtonWidget m_photoButtonWidget
ContainerWidget ControlsContainerWidget
ComponentInput m_componentInput
virtual void Update(float dt)
virtual bool IsInventoryVisible()
ButtonWidget m_cameraButtonWidget
SubsystemWeather m_subsystemWeather
ButtonWidget m_clothingButtonWidget
ButtonWidget m_mountButtonWidget
ShortInventoryWidget ShortInventoryWidget
ButtonWidget m_crouchButtonWidget
ContainerWidget m_movePadContainerWidget
ButtonWidget m_precipitationButtonWidget
virtual bool ShowTouchWidget
ContainerWidget m_lookRectangleContainerWidget
ButtonWidget m_helpButtonWidget
SubsystemTerrain m_subsystemTerrain
override void OnEntityRemoved()
ContainerWidget m_lookPadContainerWidget
virtual void DisplaySmallMessage(MessageWidget.Message message, bool playNotificationSound)
模组如果需要自定义类型的DisplaySmallMessage,比如彩虹渐变色的Message,可以自己建立对应的Message类型,并调用这个方法
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
ContainerWidget m_largeMessageWidget
ModalPanelAnimationData m_modalPanelAnimationData
TouchInputWidget LookWidget
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound, float fontScale=1f)
SubsystemSky m_subsystemSky
ButtonWidget m_creativeFlyButtonWidget
ButtonWidget m_moreButtonWidget
virtual void UpdateSidePanelsAnimation()
SubsystemGameInfo m_subsystemGameInfo
KeyboardHelpDialog m_keyboardHelpDialog
ButtonWidget m_backButtonWidget
ContainerWidget m_leftControlsContainerWidget
ValueBarWidget FoodBarWidget
ContainerWidget m_rightControlsContainerWidget
MoveRoseWidget MoveRoseWidget
override void OnEntityAdded()
ContainerWidget m_moveContainerWidget
ComponentPlayer m_componentPlayer
ValueBarWidget HealthBarWidget
virtual bool IsGameMenuDialogVisible()
virtual void Draw(Camera camera, int drawOrder)
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
virtual void HandleInput()
MessageWidget m_messageWidget
virtual void EndModalPanelAnimation()
virtual void UpdateModalPanelAnimation()
virtual void DisplayLargeMessage(string largeText, string smallText, float duration, float delay)
ContainerWidget m_modalPanelContainerWidget
static Func< Widget > OpenClothingWidget
double m_lastMountableCreatureSearchTime
TouchInputWidget ViewWidget
virtual bool IsActiveSlotEditable()
SubsystemTimeOfDay m_subsystemTimeOfDay
ButtonWidget m_lightningButtonWidget
TouchInputWidget MoveWidget
ButtonWidget m_timeOfDayButtonWidget
virtual ComponentMount FindNearestMount()
virtual void StartMounting(ComponentMount componentMount)
virtual void StartDismounting()
readonly WidgetsList Children
static ReadOnlyList< Dialog > Dialogs
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static float Interval(float t1, float t2)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static void CapturePhoto(Action success, Action< Exception > failure)
static void SwitchScreen(string name, params object[] parameters)
static MoveControlMode MoveControlMode
static LookControlMode LookControlMode
virtual bool OnEditBlock(int x, int y, int z, int value, ComponentPlayer componentPlayer)
virtual bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
static int ExtractContents(int value)
virtual bool IsVisible
ContainerWidget ParentWidget
Widget Find(string name, Type type, bool throwIfNotFound=true)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
int GetSlotValue(int slotIndex)
static Color White
static Matrix CreateFromQuaternion(Quaternion quaternion)
static Matrix CreateTranslation(float x, float y, float z)
static readonly Matrix Identity
Vector3 Forward
static Matrix CreateScale(float scale)