Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CreativePowersHelper.cs
Go to the documentation of this file.
1using System;
6using Terraria.ID;
8using Terraria.UI;
9
11
13{
15 {
16 public static readonly Point Unassigned = new Point(0, 0);
17
18 public static readonly Point Deprecated = new Point(0, 0);
19
20 public static readonly Point ItemDuplication = new Point(0, 0);
21
22 public static readonly Point ItemResearch = new Point(1, 0);
23
24 public static readonly Point TimeCategory = new Point(2, 0);
25
26 public static readonly Point WeatherCategory = new Point(3, 0);
27
28 public static readonly Point EnemyStrengthSlider = new Point(4, 0);
29
30 public static readonly Point GameEvents = new Point(5, 0);
31
32 public static readonly Point Godmode = new Point(6, 0);
33
34 public static readonly Point BlockPlacementRange = new Point(7, 0);
35
36 public static readonly Point StopBiomeSpread = new Point(8, 0);
37
38 public static readonly Point EnemySpawnRate = new Point(9, 0);
39
40 public static readonly Point FreezeTime = new Point(10, 0);
41
42 public static readonly Point TimeDawn = new Point(11, 0);
43
44 public static readonly Point TimeNoon = new Point(12, 0);
45
46 public static readonly Point TimeDusk = new Point(13, 0);
47
48 public static readonly Point TimeMidnight = new Point(14, 0);
49
50 public static readonly Point WindDirection = new Point(15, 0);
51
52 public static readonly Point WindFreeze = new Point(16, 0);
53
54 public static readonly Point RainStrength = new Point(17, 0);
55
56 public static readonly Point RainFreeze = new Point(18, 0);
57
58 public static readonly Point ModifyTime = new Point(19, 0);
59
60 public static readonly Point PersonalCategory = new Point(20, 0);
61 }
62
63 public const int TextureIconColumns = 21;
64
65 public const int TextureIconRows = 1;
66
67 public static Color CommonSelectedColor = new Color(152, 175, 235);
68
69 private static Asset<Texture2D> GetPowerIconAsset(string path)
70 {
71 return Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
72 }
73
74 public static UIImageFramed GetIconImage(Point iconLocation)
75 {
76 Asset<Texture2D> powerIconAsset = GetPowerIconAsset("Images/UI/Creative/Infinite_Powers");
77 return new UIImageFramed(powerIconAsset, powerIconAsset.Frame(21, 1, iconLocation.X, iconLocation.Y))
78 {
79 MarginLeft = 4f,
80 MarginTop = 4f,
81 VAlign = 0.5f,
82 HAlign = 1f,
83 IgnoresMouseInteraction = true
84 };
85 }
86
88 {
89 GroupOptionButton<bool> groupOptionButton = new GroupOptionButton<bool>(option: true, null, null, Color.White, null, 0.8f);
90 groupOptionButton.Width = new StyleDimension(info.PreferredButtonWidth, 0f);
91 groupOptionButton.Height = new StyleDimension(info.PreferredButtonHeight, 0f);
92 groupOptionButton.ShowHighlightWhenSelected = false;
93 groupOptionButton.SetCurrentOption(option: false);
94 groupOptionButton.SetColorsBasedOnSelectionState(new Color(152, 175, 235), Colors.InventoryDefaultColor, 1f, 0.7f);
96 return groupOptionButton;
97 }
98
100 {
101 GroupOptionButton<bool> groupOptionButton = new GroupOptionButton<bool>(option: true, null, null, Color.White, null, 0.8f);
102 groupOptionButton.Width = new StyleDimension(info.PreferredButtonWidth, 0f);
103 groupOptionButton.Height = new StyleDimension(info.PreferredButtonHeight, 0f);
104 groupOptionButton.ShowHighlightWhenSelected = false;
105 groupOptionButton.SetCurrentOption(option: false);
106 groupOptionButton.SetColorsBasedOnSelectionState(new Color(152, 175, 235), Colors.InventoryDefaultColor, 1f, 0.7f);
107 return groupOptionButton;
108 }
109
111 {
112 GroupOptionButton<T> groupOptionButton = new GroupOptionButton<T>(option, null, null, Color.White, null, 0.8f);
113 groupOptionButton.Width = new StyleDimension(info.PreferredButtonWidth, 0f);
114 groupOptionButton.Height = new StyleDimension(info.PreferredButtonHeight, 0f);
115 groupOptionButton.ShowHighlightWhenSelected = false;
116 groupOptionButton.SetCurrentOption(currentOption);
117 groupOptionButton.SetColorsBasedOnSelectionState(new Color(152, 175, 235), Colors.InventoryDefaultColor, 1f, 0.7f);
118 return groupOptionButton;
119 }
120
121 public static void AddPermissionTextIfNeeded(ICreativePower power, ref string originalText)
122 {
124 {
125 string textValue = Language.GetTextValue("CreativePowers.CantUsePowerBecauseOfNoPermissionFromServer");
126 originalText = originalText + "\n" + textValue;
127 }
128 }
129
130 public static void AddDescriptionIfNeeded(ref string originalText, string descriptionKey)
131 {
133 {
134 string textValue = Language.GetTextValue(descriptionKey);
135 originalText = originalText + "\n" + textValue;
136 }
137 }
138
139 public static void AddUnlockTextIfNeeded(ref string originalText, bool needed, string descriptionKey)
140 {
141 if (!needed)
142 {
143 string textValue = Language.GetTextValue(descriptionKey);
144 originalText = originalText + "\n" + textValue;
145 }
146 }
147
148 public static UIVerticalSlider CreateSlider(Func<float> GetSliderValueMethod, Action<float> SetValueKeyboardMethod, Action SetValueGamepadMethod)
149 {
150 return new UIVerticalSlider(GetSliderValueMethod, SetValueKeyboardMethod, SetValueGamepadMethod, Color.Red)
151 {
152 Width = new StyleDimension(12f, 0f),
153 Height = new StyleDimension(-10f, 1f),
154 Left = new StyleDimension(6f, 0f),
155 HAlign = 0f,
156 VAlign = 0.5f,
157 EmptyColor = Color.OrangeRed,
158 FilledColor = Color.CornflowerBlue
159 };
160 }
161
162 public static void UpdateUseMouseInterface(UIElement affectedElement)
163 {
164 if (affectedElement.IsMouseHovering)
165 {
166 Main.LocalPlayer.mouseInterface = true;
167 }
168 }
169
170 public static void UpdateUnlockStateByPower(ICreativePower power, UIElement button, Color colorWhenSelected)
171 {
172 IGroupOptionButton asButton = button as IGroupOptionButton;
173 if (asButton != null)
174 {
175 button.OnUpdate += delegate
176 {
177 UpdateUnlockStateByPowerInternal(power, colorWhenSelected, asButton);
178 };
179 }
180 }
181
182 public static bool IsAvailableForPlayer(ICreativePower power, int playerIndex)
183 {
184 switch (power.CurrentPermissionLevel)
185 {
186 default:
187 return false;
188 case PowerPermissionLevel.CanBeChangedByHostAlone:
189 if (Main.netMode == 0)
190 {
191 return true;
192 }
193 return Main.countsAsHostForGameplay[playerIndex];
194 case PowerPermissionLevel.CanBeChangedByEveryone:
195 return true;
196 }
197 }
198
199 private static void UpdateUnlockStateByPowerInternal(ICreativePower power, Color colorWhenSelected, IGroupOptionButton asButton)
200 {
201 bool isUnlocked = power.GetIsUnlocked();
202 bool flag = !IsAvailableForPlayer(power, Main.myPlayer);
203 asButton.SetBorderColor(flag ? Color.DimGray : Color.White);
204 if (flag)
205 {
206 asButton.SetColorsBasedOnSelectionState(new Color(60, 60, 60), new Color(60, 60, 60), 0.7f, 0.7f);
207 }
208 else if (isUnlocked)
209 {
210 asButton.SetColorsBasedOnSelectionState(colorWhenSelected, Colors.InventoryDefaultColor, 1f, 0.7f);
211 }
212 else
213 {
215 }
216 }
217}
static GroupOptionButton< bool > CreateToggleButton(CreativePowerUIElementRequestInfo info)
static void AddPermissionTextIfNeeded(ICreativePower power, ref string originalText)
static void AddDescriptionIfNeeded(ref string originalText, string descriptionKey)
static void UpdateUnlockStateByPowerInternal(ICreativePower power, Color colorWhenSelected, IGroupOptionButton asButton)
static void UpdateUnlockStateByPower(ICreativePower power, UIElement button, Color colorWhenSelected)
static GroupOptionButton< bool > CreateSimpleButton(CreativePowerUIElementRequestInfo info)
static void UpdateUseMouseInterface(UIElement affectedElement)
static GroupOptionButton< T > CreateCategoryButton< T >(CreativePowerUIElementRequestInfo info, T option, T currentOption)
static Asset< Texture2D > GetPowerIconAsset(string path)
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 SetColorsBasedOnSelectionState(Color pickedColor, Color unpickedColor, float opacityPicked, float opacityNotPicked)
static readonly Color InventoryDefaultColor
Definition Colors.cs:93
static string GetTextValue(string key)
Definition Language.cs:15
static bool[] countsAsHostForGameplay
Definition Main.cs:1807
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static IAssetRepository Assets
Definition Main.cs:209
void SetColorsBasedOnSelectionState(Color pickedColor, Color unpickedColor, float opacityPicked, float opacityNotPicked)