Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CreativeUI.cs
Go to the documentation of this file.
1using System;
11using Terraria.Net;
12using Terraria.UI;
14
16
17public class CreativeUI
18{
25
26 public const int ItemSlotIndexes_SacrificeItem = 0;
27
28 public const int ItemSlotIndexes_Count = 1;
29
30 private bool _initialized;
31
33
35
36 private Item[] _itemSlotsForUI = new Item[1];
37
39
41
43
45
47
48 public bool Enabled { get; private set; }
49
50 public bool Blocked
51 {
52 get
53 {
54 if (Main.LocalPlayer.talkNPC == -1)
55 {
56 return Main.LocalPlayer.chest != -1;
57 }
58 return true;
59 }
60 }
61
62 public CreativeUI()
63 {
64 for (int i = 0; i < _itemSlotsForUI.Length; i++)
65 {
66 _itemSlotsForUI[i] = new Item();
67 }
68 }
69
70 public void Initialize()
71 {
72 _buttonTexture = Main.Assets.Request<Texture2D>("Images/UI/Creative/Journey_Toggle", (AssetRequestMode)1);
73 _buttonBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/Creative/Journey_Toggle_MouseOver", (AssetRequestMode)1);
77 _initialized = true;
78 }
79
81 {
83 {
85 }
86 }
87
88 public void Draw(SpriteBatch spriteBatch)
89 {
90 if (!_initialized)
91 {
92 Initialize();
93 }
94 if (Main.LocalPlayer.difficulty != 3)
95 {
96 Enabled = false;
97 }
98 else if (!Blocked)
99 {
100 Vector2 location = new Vector2(28f, 267f);
101 Vector2 vector = new Vector2(353f, 258f);
102 new Vector2(40f, 267f);
103 _ = vector + new Vector2(50f, 50f);
104 if (Main.screenHeight < 650 && Enabled)
105 {
106 location.X += 52f * Main.inventoryScale;
107 }
108 DrawToggleButton(spriteBatch, location);
109 if (Enabled)
110 {
111 _powersUI.Draw(spriteBatch, Main.gameTimeCache);
112 }
113 }
114 }
115
117 {
118 if (itemSlotContext != 0)
119 {
120 return null;
121 }
123 }
124
126 {
127 if (itemSlotContext != 0)
128 {
129 return null;
130 }
132 }
133
135 {
136 if (itemSlotContext == 0)
137 {
139 }
140 }
141
143 {
146 UILinkPointNavigator.SetPosition(311, rectangle.Center.ToVector2());
148 Main.LocalPlayer.creativeInterface = false;
149 if (rectangle.Contains(Main.MouseScreen.ToPoint()))
150 {
151 Main.LocalPlayer.creativeInterface = true;
152 Main.LocalPlayer.mouseInterface = true;
153 if (Enabled)
154 {
155 Main.instance.MouseText(Language.GetTextValue("CreativePowers.PowersMenuOpen"), 0, 0);
156 }
157 else
158 {
159 Main.instance.MouseText(Language.GetTextValue("CreativePowers.PowersMenuClosed"), 0, 0);
160 }
163 {
164 ToggleMenu();
165 }
166 }
167 }
168
169 public void SwapItem(ref Item item)
170 {
171 Utils.Swap(ref item, ref _itemSlotsForUI[0]);
172 }
173
174 public void CloseMenu()
175 {
176 Enabled = false;
177 if (_itemSlotsForUI[0].stack > 0)
178 {
180 }
182 }
183
184 public void ToggleMenu()
185 {
186 Enabled = !Enabled;
190 if (Enabled)
191 {
193 Main.LocalPlayer.tileEntityAnchor.Clear();
195 }
196 else if (_itemSlotsForUI[0].stack > 0)
197 {
200 }
201 }
202
204 {
205 if (Enabled && _uiState != null)
206 {
208 }
209 return false;
210 }
211
213 {
214 if (_uiState != null)
215 {
217 }
218 }
219
221 {
222 if (_uiState != null)
223 {
225 }
226 }
227
229 {
230 if (!_itemSlotsForUI[0].IsAir)
231 {
232 return true;
233 }
234 Item mouseItem = Main.mouseItem;
235 if (mouseItem.IsAir)
236 {
237 return false;
238 }
239 if (!CreativeItemSacrificesCatalog.Instance.TryGetSacrificeCountCapToUnlockInfiniteItems(mouseItem.type, out var amountNeeded))
240 {
241 return false;
242 }
243 if (Main.LocalPlayerCreativeTracker.ItemSacrifices.GetSacrificeCount(mouseItem.type) < amountNeeded)
244 {
245 return true;
246 }
247 return false;
248 }
249
251 {
252 amountWeHave = 0;
254 itemIdChecked = 0;
256 if (!item.IsAir)
257 {
258 itemIdChecked = item.type;
259 }
260 if (!Main.LocalPlayerCreativeTracker.ItemSacrifices.TryGetSacrificeNumbers(item.type, out amountWeHave, out amountNeededTotal))
261 {
262 return false;
263 }
264 return true;
265 }
266
268 {
269 int amountNeededTotal = 0;
270 int amountWeHave = 0;
273 if (!Main.LocalPlayerCreativeTracker.ItemSacrifices.TryGetSacrificeNumbers(item.type, out amountWeHave, out amountNeededTotal))
274 {
275 return ItemSacrificeResult.CannotSacrifice;
276 }
278 if (num == 0)
279 {
280 return ItemSacrificeResult.CannotSacrifice;
281 }
282 int num2 = Math.Min(num, item.stack);
284 {
285 Main.LocalPlayerCreativeTracker.ItemSacrifices.RegisterItemSacrifice(item.type, num2);
286 }
287 else
288 {
290 NetManager.Instance.SendToServerOrLoopback(packet);
291 }
292 bool num3 = num2 == num;
293 item.stack -= num2;
294 if (item.stack <= 0)
295 {
296 item.TurnToAir();
297 }
300 if (item.stack > 0)
301 {
302 item.position.X = Main.player[Main.myPlayer].Center.X - (float)(item.width / 2);
303 item.position.Y = Main.player[Main.myPlayer].Center.Y - (float)(item.height / 2);
305 }
306 if (!num3)
307 {
308 return ItemSacrificeResult.SacrificedButNotDone;
309 }
310 return ItemSacrificeResult.SacrificedAndDone;
311 }
312
314 {
316 Main.LocalPlayerCreativeTracker.ItemSacrifices.FillListOfItemsThatCanBeObtainedInfinitely(_itemIdsAvailableInfinitely);
317 }
318
319 public void Reset()
320 {
321 for (int i = 0; i < _itemSlotsForUI.Length; i++)
322 {
324 }
325 _initialized = false;
326 Enabled = false;
327 }
328}
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static void PlaySound(int type, Vector2 position, int style=1)
void Draw(SpriteBatch spriteBatch)
Definition CreativeUI.cs:88
void DrawToggleButton(SpriteBatch spritebatch, Vector2 location)
ItemSacrificeResult SacrificeItem(out int amountWeSacrificed)
bool GetSacrificeNumbers(out int itemIdChecked, out int amountWeHave, out int amountNeededTotal)
Item GetItemByIndex(int itemSlotContext)
UIElement ProvideItemSlotElement(int itemSlotContext)
void SetItembyIndex(Item item, int itemSlotContext)
bool IsAir
Definition Item.cs:377
void TurnToAir(bool fullReset=false)
Definition Item.cs:49954
static string GetTextValue(string key)
Definition Language.cs:15
static CreativeUnlocksTracker LocalPlayerCreativeTracker
Definition Main.cs:2831
static GameTime gameTimeCache
Definition Main.cs:409
static int myPlayer
Definition Main.cs:1801
static bool mouseLeftRelease
Definition Main.cs:1755
static Main instance
Definition Main.cs:283
static int screenHeight
Definition Main.cs:1721
static Vector2 MouseScreen
Definition Main.cs:2773
static Item mouseItem
Definition Main.cs:1773
static float inventoryScale
Definition Main.cs:1779
static bool playerInventory
Definition Main.cs:1759
static IAssetRepository Assets
Definition Main.cs:209
static Player LocalPlayer
Definition Main.cs:2829
static bool ServerSideCharacter
Definition Main.cs:397
static Player[] player
Definition Main.cs:1803
static bool mouseLeft
Definition Main.cs:614
static readonly NetManager Instance
Definition NetManager.cs:18
static void FindRecipes(bool canDelayCheck=false)
Definition Recipe.cs:453
static void SetPosition(int ID, Vector2 Position)
void Update(GameTime time)
void SetState(UIState state)
void Draw(SpriteBatch spriteBatch, GameTime time)
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604
static GetItemSettings InventoryUIToInventorySettings