Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CreativePowers.cs
Go to the documentation of this file.
1using System;
3using System.IO;
13using Terraria.Net;
14using Terraria.UI;
15
17
18public class CreativePowers
19{
21 {
22 private enum SubMessageType : byte
23 {
26 }
27
28 internal string _powerNameKey;
29
31
32 internal bool _defaultToggleState;
33
34 private bool[] _perPlayerIsEnabled = new bool[255];
35
36 public ushort PowerId { get; set; }
37
38 public string ServerConfigName { get; set; }
39
41
43
45 {
46 if (!_perPlayerIsEnabled.IndexInRange(playerIndex))
47 {
48 return false;
49 }
51 }
52
53 public void DeserializeNetMessage(BinaryReader reader, int userId)
54 {
55 switch ((SubMessageType)reader.ReadByte())
56 {
57 case SubMessageType.SyncEveryone:
59 break;
60 case SubMessageType.SyncOnePlayer:
61 {
62 int playerIndex = reader.ReadByte();
63 bool state = reader.ReadBoolean();
64 if (Main.netMode == 2)
65 {
68 {
69 break;
70 }
71 }
73 break;
74 }
75 }
76 }
77
79 {
80 int num = (int)Math.Ceiling((float)_perPlayerIsEnabled.Length / 8f);
82 {
83 reader.ReadBytes(num);
84 return;
85 }
86 for (int i = 0; i < num; i++)
87 {
88 BitsByte bitsByte = reader.ReadByte();
89 for (int j = 0; j < 8; j++)
90 {
91 int num2 = i * 8 + j;
92 if (num2 != Main.myPlayer)
93 {
94 if (num2 >= _perPlayerIsEnabled.Length)
95 {
96 break;
97 }
99 }
100 }
101 }
102 }
103
104 public void SetEnabledState(int playerIndex, bool state)
105 {
107 if (Main.netMode == 2)
108 {
110 packet.Writer.Write((byte)1);
111 packet.Writer.Write((byte)playerIndex);
112 packet.Writer.Write(state);
113 NetManager.Instance.Broadcast(packet);
114 }
115 }
116
117 public void DebugCall()
118 {
119 RequestUse();
120 }
121
122 internal void RequestUse()
123 {
125 packet.Writer.Write((byte)1);
126 packet.Writer.Write((byte)Main.myPlayer);
127 packet.Writer.Write(!_perPlayerIsEnabled[Main.myPlayer]);
128 NetManager.Instance.SendToServerOrLoopback(packet);
129 }
130
131 public void Reset()
132 {
133 for (int i = 0; i < _perPlayerIsEnabled.Length; i++)
134 {
136 }
137 }
138
140 {
141 int num = (int)Math.Ceiling((float)_perPlayerIsEnabled.Length / 8f);
143 packet.Writer.Write((byte)0);
144 for (int i = 0; i < num; i++)
145 {
146 BitsByte bitsByte = (byte)0;
147 for (int j = 0; j < 8; j++)
148 {
149 int num2 = i * 8 + j;
150 if (num2 >= _perPlayerIsEnabled.Length)
151 {
152 break;
153 }
155 }
156 packet.Writer.Write(bitsByte);
157 }
158 NetManager.Instance.SendToClient(packet, playerIndex);
159 }
160
170
172 {
175 groupOptionButton.SetCurrentOption(currentOption);
176 if (affectedElement.IsMouseHovering)
177 {
178 string originalText = Language.GetTextValue(groupOptionButton.IsSelected ? (_powerNameKey + "_Enabled") : (_powerNameKey + "_Disabled"));
179 CreativePowersHelper.AddDescriptionIfNeeded(ref originalText, _powerNameKey + "_Description");
182 Main.instance.MouseTextNoOverride(originalText, 0, 0);
183 }
184 }
185
193
194 public abstract bool GetIsUnlocked();
195 }
196
198 {
200
202
203 internal string _powerNameKey;
204
205 internal float[] _cachePerPlayer = new float[256];
206
207 internal float _sliderDefaultValue;
208
209 private float _currentTargetValue;
210
212
214
215 public ushort PowerId { get; set; }
216
217 public string ServerConfigName { get; set; }
218
220
222
224 {
225 value = 0f;
226 if (!_cachePerPlayer.IndexInRange(playerIndex))
227 {
228 return false;
229 }
231 return true;
232 }
233
234 public abstract float RemapSliderValueToPowerValue(float sliderValue);
235
237 {
238 int num = reader.ReadByte();
239 float num2 = reader.ReadSingle();
240 if (Main.netMode == 2)
241 {
242 num = userId;
244 {
245 return;
246 }
247 }
248 _cachePerPlayer[num] = num2;
249 if (num == Main.myPlayer)
250 {
253 }
254 }
255
256 internal abstract void UpdateInfoFromSliderValueCache();
257
262
263 public void DebugCall()
264 {
266 packet.Writer.Write((byte)Main.myPlayer);
267 packet.Writer.Write(0f);
268 NetManager.Instance.SendToServerOrLoopback(packet);
269 }
270
271 public abstract UIElement ProvideSlider();
272
273 internal float GetSliderValue()
274 {
276 {
277 return _currentTargetValue;
278 }
280 }
281
282 internal void SetValueKeyboard(float value)
283 {
285 {
288 }
289 }
290
291 internal void SetValueGamepad()
292 {
293 float sliderValue = GetSliderValue();
294 float num = UILinksInitializer.HandleSliderVerticalInput(sliderValue, 0f, 1f, PlayerInput.CurrentProfile.InterfaceDeadzoneX, 0.35f);
295 if (num != sliderValue)
296 {
297 SetValueKeyboard(num);
298 }
299 }
300
311
320
322 {
323 if (affectedElement.IsMouseHovering)
324 {
326 string originalText = Language.GetTextValue(_powerNameKey + (groupOptionButton.IsSelected ? "_Opened" : "_Closed"));
327 CreativePowersHelper.AddDescriptionIfNeeded(ref originalText, _powerNameKey + "_Description");
330 Main.instance.MouseTextNoOverride(originalText, 0, 0);
331 }
333 }
334
335 private void AttemptPushingChange()
336 {
338 {
340 }
341 }
342
343 internal void PushChange(float newSliderValue)
344 {
345 _needsToCommitChange = false;
349 packet.Writer.Write((byte)Main.myPlayer);
350 packet.Writer.Write(newSliderValue);
351 NetManager.Instance.SendToServerOrLoopback(packet);
352 }
353
354 public virtual void Reset()
355 {
356 for (int i = 0; i < _cachePerPlayer.Length; i++)
357 {
359 }
360 }
361
371
373 {
375 }
376
377 public abstract bool GetIsUnlocked();
378 }
379
380 public abstract class ASharedButtonPower : ICreativePower
381 {
383
384 internal string _powerNameKey;
385
386 internal string _descriptionKey;
387
388 public ushort PowerId { get; set; }
389
390 public string ServerConfigName { get; set; }
391
393
395
397 {
398 OnCreation();
399 }
400
401 public void RequestUse()
402 {
404 NetManager.Instance.SendToServerOrLoopback(packet);
405 }
406
408 {
410 {
411 UsePower();
412 }
413 }
414
415 internal abstract void UsePower();
416
417 internal abstract void OnCreation();
418
428
430 {
431 if (affectedElement.IsMouseHovering)
432 {
433 string originalText = Language.GetTextValue(_powerNameKey);
437 Main.instance.MouseTextNoOverride(originalText, 0, 0);
438 }
439 }
440
448
449 public abstract bool GetIsUnlocked();
450 }
451
453 {
454 public ushort PowerId { get; set; }
455
456 public string ServerConfigName { get; set; }
457
459
461
462 public bool Enabled { get; private set; }
463
464 public void SetPowerInfo(bool enabled)
465 {
466 Enabled = enabled;
467 }
468
469 public void Reset()
470 {
471 Enabled = false;
472 }
473
475 {
477 packet.Writer.Write(Enabled);
478 NetManager.Instance.SendToClient(packet, playerIndex);
479 }
480
482 {
483 bool powerInfo = reader.ReadBoolean();
485 {
487 if (Main.netMode == 2)
488 {
490 packet.Writer.Write(Enabled);
491 NetManager.Instance.Broadcast(packet);
492 }
493 }
494 }
495
496 private void RequestUse()
497 {
499 packet.Writer.Write(!Enabled);
500 NetManager.Instance.SendToServerOrLoopback(packet);
501 }
502
512
514 {
515 bool enabled = Enabled;
517 groupOptionButton.SetCurrentOption(enabled);
518 if (affectedElement.IsMouseHovering)
519 {
521 string originalText = Language.GetTextValue(buttonTextKey + (groupOptionButton.IsSelected ? "_Enabled" : "_Disabled"));
522 CreativePowersHelper.AddDescriptionIfNeeded(ref originalText, buttonTextKey + "_Description");
525 Main.instance.MouseTextNoOverride(originalText, 0, 0);
526 }
527 }
528
536
537 internal abstract void CustomizeButton(UIElement button);
538
539 internal abstract string GetButtonTextKey();
540
541 public abstract bool GetIsUnlocked();
542 }
543
545 {
547
549
550 internal string _powerNameKey;
551
552 internal bool _syncToJoiningPlayers = true;
553
554 internal float _currentTargetValue;
555
557
559
560 public ushort PowerId { get; set; }
561
562 public string ServerConfigName { get; set; }
563
565
567
569 {
570 float num = reader.ReadSingle();
572 {
575 if (Main.netMode == 2)
576 {
578 packet.Writer.Write(num);
579 NetManager.Instance.Broadcast(packet);
580 }
581 }
582 }
583
584 internal abstract void UpdateInfoFromSliderValueCache();
585
590
591 public void DebugCall()
592 {
594 packet.Writer.Write(0f);
595 NetManager.Instance.SendToServerOrLoopback(packet);
596 }
597
598 public abstract UIElement ProvideSlider();
599
600 internal float GetSliderValue()
601 {
603 {
604 return _currentTargetValue;
605 }
606 return GetSliderValueInner();
607 }
608
609 internal virtual float GetSliderValueInner()
610 {
612 }
613
614 internal void SetValueKeyboard(float value)
615 {
617 {
619 }
620 }
621
622 internal void SetValueKeyboardForced(float value)
623 {
625 {
628 }
629 }
630
631 internal void SetValueGamepad()
632 {
633 float sliderValue = GetSliderValue();
634 float num = UILinksInitializer.HandleSliderVerticalInput(sliderValue, 0f, 1f, PlayerInput.CurrentProfile.InterfaceDeadzoneX, 0.35f);
635 if (num != sliderValue)
636 {
637 SetValueKeyboard(num);
638 }
639 }
640
649
651 {
652 if (affectedElement.IsMouseHovering)
653 {
655 string originalText = Language.GetTextValue(_powerNameKey + (groupOptionButton.IsSelected ? "_Opened" : "_Closed"));
656 CreativePowersHelper.AddDescriptionIfNeeded(ref originalText, _powerNameKey + "_Description");
659 Main.instance.MouseTextNoOverride(originalText, 0, 0);
660 }
662 }
663
676
677 public virtual void Reset()
678 {
680 }
681
691
692 public abstract bool GetIsUnlocked();
693 }
694
696 {
698 {
699 _powerNameKey = "CreativePowers.Godmode";
701 }
702
703 public override bool GetIsUnlocked()
704 {
705 return true;
706 }
707
708 public void Save(Player player, BinaryWriter writer)
709 {
711 writer.Write(value);
712 }
713
714 public void ResetDataForNewPlayer(Player player)
715 {
716 player.savedPerPlayerFieldsThatArentInThePlayerClass.godmodePowerEnabled = _defaultToggleState;
717 }
718
719 public void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
720 {
721 bool godmodePowerEnabled = reader.ReadBoolean();
722 player.savedPerPlayerFieldsThatArentInThePlayerClass.godmodePowerEnabled = godmodePowerEnabled;
723 }
724
732 }
733
735 {
737 {
738 _powerNameKey = "CreativePowers.InfinitePlacementRange";
740 _defaultToggleState = true;
741 }
742
743 public override bool GetIsUnlocked()
744 {
745 return true;
746 }
747
748 public void Save(Player player, BinaryWriter writer)
749 {
751 writer.Write(value);
752 }
753
754 public void ResetDataForNewPlayer(Player player)
755 {
756 player.savedPerPlayerFieldsThatArentInThePlayerClass.farPlacementRangePowerEnabled = _defaultToggleState;
757 }
758
759 public void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
760 {
761 bool farPlacementRangePowerEnabled = reader.ReadBoolean();
762 player.savedPerPlayerFieldsThatArentInThePlayerClass.farPlacementRangePowerEnabled = farPlacementRangePowerEnabled;
763 }
764
772 }
773
775 {
776 internal override void UsePower()
777 {
778 if (Main.netMode != 1)
779 {
780 Main.SkipToTime(0, setIsDayTime: true);
781 }
782 }
783
784 internal override void OnCreation()
785 {
786 _powerNameKey = "CreativePowers.StartDayImmediately";
787 _descriptionKey = _powerNameKey + "_Description";
789 }
790
791 public override bool GetIsUnlocked()
792 {
793 return true;
794 }
795 }
796
798 {
799 internal override void UsePower()
800 {
801 if (Main.netMode != 1)
802 {
803 Main.SkipToTime(0, setIsDayTime: false);
804 }
805 }
806
807 internal override void OnCreation()
808 {
809 _powerNameKey = "CreativePowers.StartNightImmediately";
810 _descriptionKey = _powerNameKey + "_Description";
812 }
813
814 public override bool GetIsUnlocked()
815 {
816 return true;
817 }
818 }
819
821 {
822 internal override void UsePower()
823 {
824 if (Main.netMode != 1)
825 {
826 Main.SkipToTime(27000, setIsDayTime: true);
827 }
828 }
829
830 internal override void OnCreation()
831 {
832 _powerNameKey = "CreativePowers.StartNoonImmediately";
833 _descriptionKey = _powerNameKey + "_Description";
835 }
836
837 public override bool GetIsUnlocked()
838 {
839 return true;
840 }
841 }
842
844 {
845 internal override void UsePower()
846 {
847 if (Main.netMode != 1)
848 {
849 Main.SkipToTime(16200, setIsDayTime: false);
850 }
851 }
852
853 internal override void OnCreation()
854 {
855 _powerNameKey = "CreativePowers.StartMidnightImmediately";
856 _descriptionKey = _powerNameKey + "_Description";
858 }
859
860 public override bool GetIsUnlocked()
861 {
862 return true;
863 }
864 }
865
867 {
868 public int TargetTimeRate { get; private set; }
869
871 {
872 _powerNameKey = "CreativePowers.ModifyTimeRate";
874 }
875
876 public override void Reset()
877 {
879 TargetTimeRate = 1;
880 }
881
882 internal override void UpdateInfoFromSliderValueCache()
883 {
885 }
886
887 public override UIElement ProvideSlider()
888 {
889 UIVerticalSlider uIVerticalSlider = CreativePowersHelper.CreateSlider(base.GetSliderValue, base.SetValueKeyboard, base.SetValueGamepad);
890 uIVerticalSlider.OnUpdate += UpdateSliderAndShowMultiplierMouseOver;
891 UIPanel uIPanel = new UIPanel();
892 uIPanel.Width = new StyleDimension(87f, 0f);
893 uIPanel.Height = new StyleDimension(180f, 0f);
894 uIPanel.HAlign = 0f;
895 uIPanel.VAlign = 0.5f;
898 UIText uIText = new UIText("x24")
899 {
900 HAlign = 1f,
901 VAlign = 0f
902 };
903 uIText.OnMouseOver += Button_OnMouseOver;
904 uIText.OnMouseOut += Button_OnMouseOut;
905 uIText.OnLeftClick += topText_OnClick;
906 uIPanel.Append(uIText);
907 UIText uIText2 = new UIText("x12")
908 {
909 HAlign = 1f,
910 VAlign = 0.5f
911 };
912 uIText2.OnMouseOver += Button_OnMouseOver;
913 uIText2.OnMouseOut += Button_OnMouseOut;
914 uIText2.OnLeftClick += middleText_OnClick;
915 uIPanel.Append(uIText2);
916 UIText uIText3 = new UIText("x1")
917 {
918 HAlign = 1f,
919 VAlign = 1f
920 };
921 uIText3.OnMouseOver += Button_OnMouseOver;
922 uIText3.OnMouseOut += Button_OnMouseOut;
923 uIText3.OnLeftClick += bottomText_OnClick;
924 uIPanel.Append(uIText3);
925 return uIPanel;
926 }
927
933
939
945
947 {
949 {
950 uIText.ShadowColor = Color.Black;
951 }
953 }
954
956 {
958 {
959 uIText.ShadowColor = Main.OurFavoriteColor;
960 }
962 }
963
964 public override bool GetIsUnlocked()
965 {
966 return true;
967 }
968
970 {
972 }
973
979
981 {
982 reader.ReadSingle();
983 }
984
986 {
987 if (affectedElement.IsMouseHovering)
988 {
989 string originalText = "x" + TargetTimeRate;
991 Main.instance.MouseTextNoOverride(originalText, 0, 0);
992 }
993 }
994 }
995
997 {
998 public float StrengthMultiplierToGiveNPCs { get; private set; }
999
1001 {
1002 _powerNameKey = "CreativePowers.DifficultySlider";
1004 }
1005
1006 public override void Reset()
1007 {
1010 }
1011
1012 internal override void UpdateInfoFromSliderValueCache()
1013 {
1014 if (_sliderCurrentValueCache <= 0.33f)
1015 {
1017 }
1018 else
1019 {
1021 }
1024 }
1025
1026 public override UIElement ProvideSlider()
1027 {
1028 UIVerticalSlider uIVerticalSlider = CreativePowersHelper.CreateSlider(base.GetSliderValue, base.SetValueKeyboard, base.SetValueGamepad);
1029 UIPanel uIPanel = new UIPanel();
1030 uIPanel.Width = new StyleDimension(82f, 0f);
1031 uIPanel.Height = new StyleDimension(180f, 0f);
1032 uIPanel.HAlign = 0f;
1033 uIPanel.VAlign = 0.5f;
1034 uIPanel.Append(uIVerticalSlider);
1036 uIVerticalSlider.OnUpdate += UpdateSliderColorAndShowMultiplierMouseOver;
1037 AddIndication(uIPanel, 0f, "x3", "Images/UI/WorldCreation/IconDifficultyMaster", MouseOver_Master, Click_Master);
1038 AddIndication(uIPanel, 1f / 3f, "x2", "Images/UI/WorldCreation/IconDifficultyExpert", MouseOver_Expert, Click_Expert);
1039 AddIndication(uIPanel, 2f / 3f, "x1", "Images/UI/WorldCreation/IconDifficultyNormal", MouseOver_Normal, Click_Normal);
1040 AddIndication(uIPanel, 1f, "x0.5", "Images/UI/WorldCreation/IconDifficultyCreative", MouseOver_Journey, Click_Journey);
1041 return uIPanel;
1042 }
1043
1049
1055
1061
1067
1069 {
1071 {
1072 HAlign = 1f,
1073 VAlign = yAnchor,
1074 Left = new StyleDimension(4f, 0f),
1075 Top = new StyleDimension(2f, 0f),
1076 RemoveFloatingPointsFromDrawPosition = true
1077 };
1078 uIImage.OnMouseOut += Button_OnMouseOut;
1079 uIImage.OnMouseOver += Button_OnMouseOver;
1080 if (updateEvent != null)
1081 {
1082 uIImage.OnUpdate += updateEvent;
1083 }
1084 if (clickEvent != null)
1085 {
1086 uIImage.OnLeftClick += clickEvent;
1087 }
1088 panel.Append(uIImage);
1089 }
1090
1095
1100
1102 {
1103 if (affectedElement.IsMouseHovering)
1104 {
1105 string textValue = Language.GetTextValue("UI.Creative");
1106 Main.instance.MouseTextNoOverride(textValue, 0, 0);
1107 }
1108 }
1109
1111 {
1112 if (affectedElement.IsMouseHovering)
1113 {
1114 string textValue = Language.GetTextValue("UI.Normal");
1115 Main.instance.MouseTextNoOverride(textValue, 0, 0);
1116 }
1117 }
1118
1120 {
1121 if (affectedElement.IsMouseHovering)
1122 {
1123 string textValue = Language.GetTextValue("UI.Expert");
1124 Main.instance.MouseTextNoOverride(textValue, 0, 0);
1125 }
1126 }
1127
1129 {
1130 if (affectedElement.IsMouseHovering)
1131 {
1132 string textValue = Language.GetTextValue("UI.Master");
1133 Main.instance.MouseTextNoOverride(textValue, 0, 0);
1134 }
1135 }
1136
1138 {
1139 if (affectedElement.IsMouseHovering)
1140 {
1141 string originalText = "x" + StrengthMultiplierToGiveNPCs.ToString("F2");
1143 Main.instance.MouseTextNoOverride(originalText, 0, 0);
1144 }
1146 {
1147 uIVerticalSlider.EmptyColor = Color.Black;
1148 Color filledColor = (Main.masterMode ? Main.hcColor : (Main.expertMode ? Main.mcColor : ((!(StrengthMultiplierToGiveNPCs < 1f)) ? Color.White : Main.creativeModeColor)));
1149 uIVerticalSlider.FilledColor = filledColor;
1150 }
1151 }
1152
1153 public override bool GetIsUnlocked()
1154 {
1155 return true;
1156 }
1157
1159 {
1161 }
1162
1168
1170 {
1171 reader.ReadSingle();
1172 }
1173 }
1174
1176 {
1178 {
1179 _powerNameKey = "CreativePowers.ModifyWindDirectionAndStrength";
1181 _syncToJoiningPlayers = false;
1182 }
1183
1184 internal override void UpdateInfoFromSliderValueCache()
1185 {
1186 Main.windSpeedCurrent = (Main.windSpeedTarget = MathHelper.Lerp(-0.8f, 0.8f, _sliderCurrentValueCache));
1187 }
1188
1189 internal override float GetSliderValueInner()
1190 {
1191 return Utils.GetLerpValue(-0.8f, 0.8f, Main.windSpeedTarget);
1192 }
1193
1194 public override bool GetIsUnlocked()
1195 {
1196 return true;
1197 }
1198
1199 public override UIElement ProvideSlider()
1200 {
1201 UIVerticalSlider uIVerticalSlider = CreativePowersHelper.CreateSlider(base.GetSliderValue, base.SetValueKeyboard, base.SetValueGamepad);
1202 uIVerticalSlider.OnUpdate += UpdateSliderAndShowMultiplierMouseOver;
1203 UIPanel uIPanel = new UIPanel();
1204 uIPanel.Width = new StyleDimension(132f, 0f);
1205 uIPanel.Height = new StyleDimension(180f, 0f);
1206 uIPanel.HAlign = 0f;
1207 uIPanel.VAlign = 0.5f;
1208 uIPanel.Append(uIVerticalSlider);
1210 UIText uIText = new UIText(Language.GetText("CreativePowers.WindWest"))
1211 {
1212 HAlign = 1f,
1213 VAlign = 0f
1214 };
1215 uIText.OnMouseOut += Button_OnMouseOut;
1216 uIText.OnMouseOver += Button_OnMouseOver;
1217 uIText.OnLeftClick += topText_OnClick;
1218 uIPanel.Append(uIText);
1219 UIText uIText2 = new UIText(Language.GetText("CreativePowers.WindEast"))
1220 {
1221 HAlign = 1f,
1222 VAlign = 1f
1223 };
1224 uIText2.OnMouseOut += Button_OnMouseOut;
1225 uIText2.OnMouseOver += Button_OnMouseOver;
1226 uIText2.OnLeftClick += bottomText_OnClick;
1227 uIPanel.Append(uIText2);
1228 UIText uIText3 = new UIText(Language.GetText("CreativePowers.WindNone"))
1229 {
1230 HAlign = 1f,
1231 VAlign = 0.5f
1232 };
1233 uIText3.OnMouseOut += Button_OnMouseOut;
1234 uIText3.OnMouseOver += Button_OnMouseOver;
1235 uIText3.OnLeftClick += middleText_OnClick;
1236 uIPanel.Append(uIText3);
1237 return uIPanel;
1238 }
1239
1245
1251
1257
1259 {
1261 {
1262 uIText.ShadowColor = Color.Black;
1263 }
1265 }
1266
1268 {
1270 {
1271 uIText.ShadowColor = Main.OurFavoriteColor;
1272 }
1274 }
1275
1277 {
1278 if (affectedElement.IsMouseHovering)
1279 {
1280 int num = (int)(Main.windSpeedCurrent * 50f);
1281 string originalText = "";
1282 if (num < 0)
1283 {
1284 originalText += Language.GetTextValue("GameUI.EastWind", Math.Abs(num));
1285 }
1286 else if (num > 0)
1287 {
1288 originalText += Language.GetTextValue("GameUI.WestWind", num);
1289 }
1291 Main.instance.MouseTextNoOverride(originalText, 0, 0);
1292 }
1293 }
1294 }
1295
1297 {
1299 {
1300 _powerNameKey = "CreativePowers.ModifyRainPower";
1302 _syncToJoiningPlayers = false;
1303 }
1304
1305 internal override void UpdateInfoFromSliderValueCache()
1306 {
1307 if (_sliderCurrentValueCache == 0f)
1308 {
1309 Main.StopRain();
1310 }
1311 else
1312 {
1313 Main.StartRain();
1314 }
1315 Main.cloudAlpha = _sliderCurrentValueCache;
1316 Main.maxRaining = _sliderCurrentValueCache;
1317 }
1318
1319 internal override float GetSliderValueInner()
1320 {
1321 return Main.cloudAlpha;
1322 }
1323
1324 public override bool GetIsUnlocked()
1325 {
1326 return true;
1327 }
1328
1329 public override UIElement ProvideSlider()
1330 {
1331 UIVerticalSlider uIVerticalSlider = CreativePowersHelper.CreateSlider(base.GetSliderValue, base.SetValueKeyboard, base.SetValueGamepad);
1332 uIVerticalSlider.OnUpdate += UpdateSliderAndShowMultiplierMouseOver;
1333 UIPanel uIPanel = new UIPanel();
1334 uIPanel.Width = new StyleDimension(132f, 0f);
1335 uIPanel.Height = new StyleDimension(180f, 0f);
1336 uIPanel.HAlign = 0f;
1337 uIPanel.VAlign = 0.5f;
1338 uIPanel.Append(uIVerticalSlider);
1340 UIText uIText = new UIText(Language.GetText("CreativePowers.WeatherMonsoon"))
1341 {
1342 HAlign = 1f,
1343 VAlign = 0f
1344 };
1345 uIText.OnMouseOut += Button_OnMouseOut;
1346 uIText.OnMouseOver += Button_OnMouseOver;
1347 uIText.OnLeftClick += topText_OnClick;
1348 uIPanel.Append(uIText);
1349 UIText uIText2 = new UIText(Language.GetText("CreativePowers.WeatherClearSky"))
1350 {
1351 HAlign = 1f,
1352 VAlign = 1f
1353 };
1354 uIText2.OnMouseOut += Button_OnMouseOut;
1355 uIText2.OnMouseOver += Button_OnMouseOver;
1356 uIText2.OnLeftClick += bottomText_OnClick;
1357 uIPanel.Append(uIText2);
1358 UIText uIText3 = new UIText(Language.GetText("CreativePowers.WeatherDrizzle"))
1359 {
1360 HAlign = 1f,
1361 VAlign = 0.5f
1362 };
1363 uIText3.OnMouseOut += Button_OnMouseOut;
1364 uIText3.OnMouseOver += Button_OnMouseOver;
1365 uIText3.OnLeftClick += middleText_OnClick;
1366 uIPanel.Append(uIText3);
1367 return uIPanel;
1368 }
1369
1375
1381
1387
1389 {
1391 {
1392 uIText.ShadowColor = Color.Black;
1393 }
1395 }
1396
1398 {
1400 {
1401 uIText.ShadowColor = Main.OurFavoriteColor;
1402 }
1404 }
1405
1407 {
1408 if (affectedElement.IsMouseHovering)
1409 {
1410 string originalText = Main.maxRaining.ToString("P0");
1412 Main.instance.MouseTextNoOverride(originalText, 0, 0);
1413 }
1414 }
1415 }
1416
1418 {
1423
1424 internal override string GetButtonTextKey()
1425 {
1426 return "CreativePowers.FreezeTime";
1427 }
1428
1429 public override bool GetIsUnlocked()
1430 {
1431 return true;
1432 }
1433
1435 {
1436 writer.Write(base.Enabled);
1437 }
1438
1440 {
1441 bool powerInfo = reader.ReadBoolean();
1443 }
1444
1446 {
1447 reader.ReadBoolean();
1448 }
1449 }
1450
1452 {
1457
1458 internal override string GetButtonTextKey()
1459 {
1460 return "CreativePowers.FreezeWindDirectionAndStrength";
1461 }
1462
1463 public override bool GetIsUnlocked()
1464 {
1465 return true;
1466 }
1467
1469 {
1470 writer.Write(base.Enabled);
1471 }
1472
1474 {
1475 bool powerInfo = reader.ReadBoolean();
1477 }
1478
1480 {
1481 reader.ReadBoolean();
1482 }
1483 }
1484
1486 {
1491
1492 internal override string GetButtonTextKey()
1493 {
1494 return "CreativePowers.FreezeRainPower";
1495 }
1496
1497 public override bool GetIsUnlocked()
1498 {
1499 return true;
1500 }
1501
1503 {
1504 writer.Write(base.Enabled);
1505 }
1506
1508 {
1509 bool powerInfo = reader.ReadBoolean();
1511 }
1512
1514 {
1515 reader.ReadBoolean();
1516 }
1517 }
1518
1520 {
1525
1526 internal override string GetButtonTextKey()
1527 {
1528 return "CreativePowers.StopBiomeSpread";
1529 }
1530
1531 public override bool GetIsUnlocked()
1532 {
1533 return true;
1534 }
1535
1537 {
1538 writer.Write(base.Enabled);
1539 }
1540
1542 {
1543 bool powerInfo = reader.ReadBoolean();
1545 }
1546
1548 {
1549 reader.ReadBoolean();
1550 }
1551 }
1552
1554 {
1555 public float StrengthMultiplierToGiveNPCs { get; private set; }
1556
1558 {
1559 _powerNameKey = "CreativePowers.NPCSpawnRateSlider";
1560 _sliderDefaultValue = 0.5f;
1562 }
1563
1565 {
1566 if (!_cachePerPlayer.IndexInRange(playerIndex))
1567 {
1568 return false;
1569 }
1570 if (playerIndex == Main.myPlayer)
1571 {
1572 return _sliderCurrentValueCache == 0f;
1573 }
1574 return _cachePerPlayer[playerIndex] == 0f;
1575 }
1576
1577 internal override void UpdateInfoFromSliderValueCache()
1578 {
1579 }
1580
1581 public override float RemapSliderValueToPowerValue(float sliderValue)
1582 {
1583 if (sliderValue < 0.5f)
1584 {
1585 return Utils.Remap(sliderValue, 0f, 0.5f, 0.1f, 1f);
1586 }
1587 return Utils.Remap(sliderValue, 0.5f, 1f, 1f, 10f);
1588 }
1589
1590 public override UIElement ProvideSlider()
1591 {
1592 UIVerticalSlider uIVerticalSlider = CreativePowersHelper.CreateSlider(base.GetSliderValue, base.SetValueKeyboard, base.SetValueGamepad);
1593 uIVerticalSlider.OnUpdate += UpdateSliderAndShowMultiplierMouseOver;
1594 UIPanel uIPanel = new UIPanel();
1595 uIPanel.Width = new StyleDimension(77f, 0f);
1596 uIPanel.Height = new StyleDimension(180f, 0f);
1597 uIPanel.HAlign = 0f;
1598 uIPanel.VAlign = 0.5f;
1599 uIPanel.Append(uIVerticalSlider);
1601 UIText uIText = new UIText("x10")
1602 {
1603 HAlign = 1f,
1604 VAlign = 0f
1605 };
1606 uIText.OnMouseOut += Button_OnMouseOut;
1607 uIText.OnMouseOver += Button_OnMouseOver;
1608 uIText.OnLeftClick += topText_OnClick;
1609 uIPanel.Append(uIText);
1610 UIText uIText2 = new UIText("x1")
1611 {
1612 HAlign = 1f,
1613 VAlign = 0.5f
1614 };
1615 uIText2.OnMouseOut += Button_OnMouseOut;
1616 uIText2.OnMouseOver += Button_OnMouseOver;
1617 uIText2.OnLeftClick += middleText_OnClick;
1618 uIPanel.Append(uIText2);
1619 UIText uIText3 = new UIText("x0")
1620 {
1621 HAlign = 1f,
1622 VAlign = 1f
1623 };
1624 uIText3.OnMouseOut += Button_OnMouseOut;
1625 uIText3.OnMouseOver += Button_OnMouseOver;
1626 uIText3.OnLeftClick += bottomText_OnClick;
1627 uIPanel.Append(uIText3);
1628 return uIPanel;
1629 }
1630
1632 {
1634 {
1635 uIText.ShadowColor = Color.Black;
1636 }
1638 }
1639
1641 {
1643 {
1644 uIText.ShadowColor = Main.OurFavoriteColor;
1645 }
1647 }
1648
1654
1660
1666
1668 {
1669 if (affectedElement.IsMouseHovering)
1670 {
1671 string originalText = "x" + RemapSliderValueToPowerValue(GetSliderValue()).ToString("F2");
1673 {
1674 originalText = Language.GetTextValue(_powerNameKey + "EnemySpawnsDisabled");
1675 }
1677 Main.instance.MouseTextNoOverride(originalText, 0, 0);
1678 }
1679 }
1680
1681 public override bool GetIsUnlocked()
1682 {
1683 return true;
1684 }
1685
1691
1692 public void ResetDataForNewPlayer(Player player)
1693 {
1694 player.savedPerPlayerFieldsThatArentInThePlayerClass.spawnRatePowerSliderValue = _sliderDefaultValue;
1695 }
1696
1697 public void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
1698 {
1699 float spawnRatePowerSliderValue = reader.ReadSingle();
1700 player.savedPerPlayerFieldsThatArentInThePlayerClass.spawnRatePowerSliderValue = spawnRatePowerSliderValue;
1701 }
1702
1707 }
1708}
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
void Add(TKey key, TValue value)
virtual bool ReadBoolean()
virtual byte ReadByte()
virtual float ReadSingle()
virtual byte[] ReadBytes(int count)
static decimal Round(decimal d)
Definition Math.cs:1096
static double Ceiling(double a)
static double Abs(double value)
static void PlaySound(int type, Vector2 position, int style=1)
static GroupOptionButton< bool > CreateToggleButton(CreativePowerUIElementRequestInfo info)
static void AddPermissionTextIfNeeded(ICreativePower power, ref string originalText)
static void AddDescriptionIfNeeded(ref string originalText, string descriptionKey)
static void UpdateUnlockStateByPower(ICreativePower power, UIElement button, Color colorWhenSelected)
static GroupOptionButton< bool > CreateSimpleButton(CreativePowerUIElementRequestInfo info)
static void UpdateUseMouseInterface(UIElement affectedElement)
static bool IsAvailableForPlayer(ICreativePower power, int playerIndex)
static UIVerticalSlider CreateSlider(Func< float > GetSliderValueMethod, Action< float > SetValueKeyboardMethod, Action SetValueGamepadMethod)
static UIImageFramed GetIconImage(Point iconLocation)
static void AddUnlockTextIfNeeded(ref string originalText, bool needed, string descriptionKey)
void ProvidePowerButtons(CreativePowerUIElementRequestInfo info, List< UIElement > elements)
GroupOptionButton< int > GetOptionButton(CreativePowerUIElementRequestInfo info, int optionIndex, int currentOptionIndex)
void ProvidePowerButtons(CreativePowerUIElementRequestInfo info, List< UIElement > elements)
void button_OnClick(UIMouseEvent evt, UIElement listeningElement)
void button_OnClick(UIMouseEvent evt, UIElement listeningElement)
void ProvidePowerButtons(CreativePowerUIElementRequestInfo info, List< UIElement > elements)
GroupOptionButton< int > GetOptionButton(CreativePowerUIElementRequestInfo info, int optionIndex, int currentOptionIndex)
void ProvidePowerButtons(CreativePowerUIElementRequestInfo info, List< UIElement > elements)
void ProvidePowerButtons(CreativePowerUIElementRequestInfo info, List< UIElement > elements)
void button_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Click_Expert(UIMouseEvent evt, UIElement listeningElement)
void Click_Normal(UIMouseEvent evt, UIElement listeningElement)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Click_Journey(UIMouseEvent evt, UIElement listeningElement)
void Click_Master(UIMouseEvent evt, UIElement listeningElement)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
static void Button_OnMouseOut(UIMouseEvent evt, UIElement listeningElement)
static void Button_OnMouseOver(UIMouseEvent evt, UIElement listeningElement)
static void AddIndication(UIPanel panel, float yAnchor, string indicationText, string iconImagePath, UIElement.ElementEvent updateEvent, UIElement.MouseEvent clickEvent)
void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
void Save(Player player, BinaryWriter writer)
void UpdateSliderAndShowMultiplierMouseOver(UIElement affectedElement)
void middleText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void topText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void bottomText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOver(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOut(UIMouseEvent evt, UIElement listeningElement)
void UpdateSliderAndShowMultiplierMouseOver(UIElement affectedElement)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Button_OnMouseOver(UIMouseEvent evt, UIElement listeningElement)
void bottomText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOut(UIMouseEvent evt, UIElement listeningElement)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void topText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void middleText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void bottomText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOver(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOut(UIMouseEvent evt, UIElement listeningElement)
void topText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void middleText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void topText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void bottomText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOut(UIMouseEvent evt, UIElement listeningElement)
void middleText_OnClick(UIMouseEvent evt, UIElement listeningElement)
void Button_OnMouseOver(UIMouseEvent evt, UIElement listeningElement)
void Load(Player player, BinaryReader reader, int gameVersionSaveWasMadeOn)
void ValidateWorld(BinaryReader reader, int gameVersionSaveWasMadeOn)
void Load(BinaryReader reader, int gameVersionSaveWasMadeOn)
static NetPacket PreparePacket(ushort powerId, int specificInfoBytesInPacketCount)
static PlayerInputProfile CurrentProfile
static float HandleSliderVerticalInput(float currentValue, float min, float max, float deadZone=0.2f, float sensitivity=0.5f)
static LocalizedText GetText(string key)
Definition Language.cs:10
static string GetTextValue(string key)
Definition Language.cs:15
static float windSpeedCurrent
Definition Main.cs:1360
static float cloudAlpha
Definition Main.cs:1302
static float windSpeedTarget
Definition Main.cs:1362
static void SkipToTime(int timeToSet, bool setIsDayTime)
Definition Main.cs:61890
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static Microsoft.Xna.Framework.Color creativeModeColor
Definition Main.cs:996
static Main instance
Definition Main.cs:283
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static void StartRain()
Definition Main.cs:61448
static float maxRaining
Definition Main.cs:1304
static IAssetRepository Assets
Definition Main.cs:209
static void StopRain()
Definition Main.cs:61441
static readonly NetManager Instance
Definition NetManager.cs:18
SavedPlayerDataWithAnnoyingRules savedPerPlayerFieldsThatArentInThePlayerClass
Definition Player.cs:2730
delegate void ElementEvent(UIElement affectedElement)
delegate void MouseEvent(UIMouseEvent evt, UIElement listeningElement)
static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
Definition Utils.cs:233
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static unsafe DateTime UtcNow
Definition DateTime.cs:142