-
Notifications
You must be signed in to change notification settings - Fork 5
/
PRPlayer.cs
110 lines (92 loc) · 2.54 KB
/
PRPlayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.GameContent;
using Terraria.GameInput;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.UI.Chat;
namespace PetRenamer
{
internal class PRPlayer : ModPlayer
{
internal int petTypeVanity;
internal string petNameVanity;
internal int petTypeLight;
internal string petNameLight;
internal Item renamePetUIItem;
private int prevItemType;
private bool OpenedChatWithMouseItem => !Main.chatRelease && PetRenamer.IsPetItem(Main.mouseItem);
private bool MouseItemChangedToPetItem => prevItemType != Main.mouseItem.type && PetRenamer.IsPetItem(Main.mouseItem);
public override void ProcessTriggers(TriggersSet triggersSet)
{
if (PetRenamer.RenamePetUIHotkey.JustPressed)
{
PRUISystem.ToggleRenamePetUI();
}
}
public override void Initialize()
{
petTypeVanity = 0;
petNameVanity = string.Empty;
petTypeLight = 0;
petNameLight = string.Empty;
renamePetUIItem = new Item();
prevItemType = 0;
}
public override void SaveData(TagCompound tag)
{
if (!renamePetUIItem.IsAir)
{
tag.Add("renamePetUIItem", renamePetUIItem);
}
}
public override void LoadData(TagCompound tag)
{
renamePetUIItem = tag.Get<Item>("renamePetUIItem");
if (renamePetUIItem == null)
{
renamePetUIItem = new Item();
}
}
public override void PostUpdateEquips()
{
UpdatePets();
//Only do the autocomplete in chat on the client
if (Main.netMode != NetmodeID.Server && Main.myPlayer == Player.whoAmI)
{
Autocomplete();
}
}
private void UpdatePets()
{
SetTypeAndNameOfCurrentEquippedPetInSlot(PetRenamer.VANITY_PET, ref petTypeVanity, ref petNameVanity);
SetTypeAndNameOfCurrentEquippedPetInSlot(PetRenamer.LIGHT_PET, ref petTypeLight, ref petNameLight);
}
private void SetTypeAndNameOfCurrentEquippedPetInSlot(int slot, ref int type, ref string name)
{
Item item = Player.miscEquips[slot];
if (!Player.hideMisc[slot] && item.TryGetGlobalItem(out PRItem petItem))
{
type = item.shoot;
name = petItem.petName;
}
}
private void Autocomplete()
{
if (!Config.Instance.EnableChatAutofill)
{
return;
}
if (Main.drawingPlayerChat &&
(OpenedChatWithMouseItem || MouseItemChangedToPetItem))
{
if (!Main.chatText.StartsWith(PRCommand.CommandStart) && Main.chatText.Length == 0)
{
ChatManager.AddChatText(FontAssets.MouseText.Value, PRCommand.CommandStart, Vector2.One);
}
}
prevItemType = Main.mouseItem?.type ?? 0;
}
}
}