forked from Tyfyter/BeastFormCustomization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFishColorPlayer.cs
More file actions
462 lines (437 loc) · 16.3 KB
/
FishColorPlayer.cs
File metadata and controls
462 lines (437 loc) · 16.3 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
using BeastCustomization.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.Chat;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.GameContent.UI.States;
using Terraria.GameInput;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
using Terraria.ModLoader.IO;
using Terraria.UI;
namespace BeastCustomization {
public class FishColorPlayer : BeastPlayerBase {
#region fields
[Label("Head Scale Style")]
[ListRange("HeadScaleTextures"), Slider]
public int headScaleStyle = 1;
[Label("Head Secondary Scale Style")]
[ListRange("HeadSecondaryScaleTextures"), Slider]
public int headScaleStyle2 = 0;
[Label("Eye Style")]
[ListRange("EyesTextures"), Slider]
public int headEyeStyle = 0;
[Label("Body Scale Style")]
[ListRange("BodyScaleTextures"), Slider]
public int bodyScaleStyle = 1;
[Label("Body Secondary Scale Style")]
[ListRange("BodySecondaryScaleTextures"), Slider]
public int bodySecondaryScaleStyle = 0;
[Label("Legs Scale Style")]
[ListRange("LegsScaleTextures"), Slider]
public int legsScaleStyle = 1;
[Label("Legs Secondary Scale Style")]
[ListRange("LegsSecondaryScaleTextures"), Slider]
public int legsScaleStyle2 = 0;
[Label("Glowing Eyes")]
public bool eyesGlow = false;
[Label("Apply Dye to Eyes")]
public bool eyesDye = false;
//[JsonIgnore]
[Label("Apply Head Armor")]
public bool applyHead = false;
//[JsonIgnore]
[Label("Apply Body Armor")]
public bool applyBody = false;
//[JsonIgnore]
[Label("Apply Leg Armor")]
public bool applyLegs = false;
//[JsonIgnore]
[Label("Apply Head Armor Over Scales")]
[Tooltip("Looks absolutely ridiculous with almost everything")]
public bool applyHeadOver = false;
//[JsonIgnore]
[Label("Apply Body Armor Over Scales")]
[Tooltip("Looks absolutely ridiculous with almost everything")]
public bool applyBodyOver = false;
//[JsonIgnore]
[Label("Apply Leg Armor Over Scales")]
[Tooltip("Looks absolutely ridiculous with almost everything")]
public bool applyLegsOver = false;
[Label("Eye Color")]
public Color eyesColor = new Color(242, 8, 46);
[Label("Scale Color")]
public Color scaleColor = new Color(41, 185, 127);
[Label("Secondary Scale Color")]
public Color scaleColor2 = new Color(168, 255, 106);
int oldHeadScaleStyle;
int oldHeadTeethStyle;
int oldBodyScaleStyle;
int oldBodySecondaryScaleStyle;
int oldLegsScaleStyle;
int oldLegsClawsStyle;
bool oldEyesGlow;
bool oldEyesDye;
Color oldEyesIrisColor;
Color oldScaleColor;
Color oldScaleColor2;
bool oldApplyHead;
bool oldApplyBody;
bool oldApplyLegs;
bool oldApplyHeadOver;
bool oldApplyBodyOver;
bool oldApplyLegsOver;
#endregion fields
public override string DisplayName => "Merfolk";
public override FishColorPlayer CreateNew() => new FishColorPlayer();
public override Type ResourceCacheType => typeof(Merfolk);
public override ref List<TagCompound> ConfigPresets => ref BeastCustomizationSavedPresets.Instance.fishPresets;
public override bool IsActive => Player.merman || Player.forceMerman;
public override int Specificity => 1;
public override void StartCustomization() {
oldHeadScaleStyle = headScaleStyle;
oldHeadTeethStyle = headScaleStyle2;
oldBodyScaleStyle = bodyScaleStyle;
oldBodySecondaryScaleStyle = bodySecondaryScaleStyle;
oldLegsScaleStyle = legsScaleStyle;
oldLegsClawsStyle = legsScaleStyle2;
oldEyesGlow = eyesGlow;
oldEyesDye = eyesDye;
oldEyesIrisColor = eyesColor;
oldScaleColor = scaleColor;
oldScaleColor2 = scaleColor2;
oldApplyHead = applyHead;
oldApplyBody = applyBody;
oldApplyLegs = applyLegs;
oldApplyHeadOver = applyHeadOver;
oldApplyBodyOver = applyBodyOver;
oldApplyLegsOver = applyLegsOver;
}
public override void FinishCustomization(bool overwrite) {
if (!overwrite) {
headScaleStyle = oldHeadScaleStyle;
headScaleStyle2 = oldHeadTeethStyle;
bodyScaleStyle = oldBodyScaleStyle;
bodySecondaryScaleStyle = oldBodySecondaryScaleStyle;
legsScaleStyle = oldLegsScaleStyle;
legsScaleStyle2 = oldLegsClawsStyle;
eyesGlow = oldEyesGlow;
eyesDye = oldEyesDye;
eyesColor = oldEyesIrisColor;
scaleColor = oldScaleColor;
scaleColor2 = oldScaleColor2;
applyHead = oldApplyHead;
applyBody = oldApplyBody;
applyLegs = oldApplyLegs;
applyHeadOver = oldApplyHeadOver;
applyBodyOver = oldApplyBodyOver;
applyLegsOver = oldApplyLegsOver;
SendData();
}
}
public override void ExportData(TagCompound tag) {
tag["headScaleStyle"] = headScaleStyle;
tag["headScaleStyle2"] = headScaleStyle2;
tag["bodyScaleStyle"] = bodyScaleStyle;
tag["bodySecondaryScaleStyle"] = bodySecondaryScaleStyle;
tag["legsScaleStyle"] = legsScaleStyle;
tag["legsScaleStyle2"] = legsScaleStyle2;
tag["eyesGlow"] = eyesGlow;
tag["eyesDye"] = eyesDye;
tag["eyesColor"] = eyesColor;
tag["scaleColor"] = scaleColor;
tag["scaleColor2"] = scaleColor2;
tag["applyHead"] = applyHead;
tag["applyBody"] = applyBody;
tag["applyLegs"] = applyLegs;
tag["applyHeadOver"] = applyHeadOver;
tag["applyBodyOver"] = applyBodyOver;
tag["applyLegsOver"] = applyLegsOver;
}
public override void ImportData(TagCompound tag) {
if (tag.TryGet("headScaleStyle", out int tempHeadScaleStyle)) headScaleStyle = tempHeadScaleStyle;
if (tag.TryGet("headScaleStyle2", out int tempHeadTeethStyle)) headScaleStyle2 = tempHeadTeethStyle;
if (tag.TryGet("bodyScaleStyle", out int tempBodyScaleStyle)) bodyScaleStyle = tempBodyScaleStyle;
if (tag.TryGet("bodySecondaryScaleStyle", out int tempBodySecondaryScaleStyle)) bodySecondaryScaleStyle = tempBodySecondaryScaleStyle;
if (tag.TryGet("legsScaleStyle", out int tempLegsScaleStyle)) legsScaleStyle = tempLegsScaleStyle;
if (tag.TryGet("legsScaleStyle2", out int tempLegsClawsStyle)) legsScaleStyle2 = tempLegsClawsStyle;
if (tag.TryGet("eyesGlow", out bool tempEyesGlow)) eyesGlow = tempEyesGlow;
if (tag.TryGet("eyesDye", out bool tempEyesDye)) eyesDye = tempEyesDye;
if (tag.TryGet("eyesColor", out Color tempEyesIrisColor)) eyesColor = tempEyesIrisColor;
if (tag.TryGet("scaleColor", out Color tempScaleColor)) scaleColor = tempScaleColor;
if (tag.TryGet("scaleColor2", out Color tempScaleColor2)) scaleColor2 = tempScaleColor2;
if (tag.TryGet("applyHead", out bool tempApplyHead)) applyHead = tempApplyHead;
if (tag.TryGet("applyBody", out bool tempApplyBody)) applyBody = tempApplyBody;
if (tag.TryGet("applyLegs", out bool tempApplyLegs)) applyLegs = tempApplyLegs;
if (tag.TryGet("applyHeadOver", out bool tempApplyHeadOver)) applyHeadOver = tempApplyHeadOver;
if (tag.TryGet("applyBodyOver", out bool tempApplyBodyOver)) applyBodyOver = tempApplyBodyOver;
if (tag.TryGet("applyLegsOver", out bool tempApplyLegsOver)) applyLegsOver = tempApplyLegsOver;
//Mod.Logger.Info($"loading {Player.name}, scale color: {scaleColor}");
}
public override void NetSend(BinaryWriter writer) {
BeastCustomization.DebugLogger.Info("NetSend");
BeastCustomization.DebugLogger.Info(writer.BaseStream.Position);
writer.Write(headScaleStyle);
writer.Write(headScaleStyle2);
writer.Write(bodyScaleStyle);
writer.Write(bodySecondaryScaleStyle);
writer.Write(legsScaleStyle);
writer.Write(legsScaleStyle2);
writer.Write(eyesGlow);
writer.Write(eyesDye);
writer.Write(eyesColor.PackedValue);
writer.Write(scaleColor.PackedValue);
writer.Write(scaleColor2.PackedValue);
writer.Write(applyHead);
writer.Write(applyBody);
writer.Write(applyLegs);
writer.Write(applyHeadOver);
writer.Write(applyBodyOver);
writer.Write(applyLegsOver);
BeastCustomization.DebugLogger.Info(writer.BaseStream.Position);
}
public override void NetRecieve(BinaryReader reader) {
BeastCustomization.DebugLogger.Info("NetRecieve");
BeastCustomization.DebugLogger.Info(reader.BaseStream.Position);
headScaleStyle = reader.ReadInt32();
headScaleStyle2 = reader.ReadInt32();
bodyScaleStyle = reader.ReadInt32();
bodySecondaryScaleStyle = reader.ReadInt32();
legsScaleStyle = reader.ReadInt32();
legsScaleStyle2 = reader.ReadInt32();
eyesGlow = reader.ReadBoolean();
eyesDye = reader.ReadBoolean();
eyesColor.PackedValue = reader.ReadUInt32();
scaleColor.PackedValue = reader.ReadUInt32();
scaleColor2.PackedValue = reader.ReadUInt32();
applyHead = reader.ReadBoolean();
applyBody = reader.ReadBoolean();
applyLegs = reader.ReadBoolean();
applyHeadOver = reader.ReadBoolean();
applyBodyOver = reader.ReadBoolean();
applyLegsOver = reader.ReadBoolean();
BeastCustomization.DebugLogger.Info(reader.BaseStream.Position);
}
public override void HideDrawLayers(PlayerDrawSet drawInfo) {
if (drawInfo.drawPlayer.head == ArmorIDs.Head.Merman) {
if (!applyHead || GetSlot(0) == -1) {
PlayerDrawLayers.Head.Hide();
}
}
if (drawInfo.drawPlayer.body == ArmorIDs.Body.Merfolk) {
if (!applyBody || GetSlot(1) == -1) {
PlayerDrawLayers.Skin.Hide();
PlayerDrawLayers.Torso.Hide();
PlayerDrawLayers.ArmOverItem.Hide();
}
}
if (drawInfo.drawPlayer.legs == 21) {
if (!applyLegs || GetSlot(2) == -1) {
PlayerDrawLayers.Leggings.Hide();
}
}
}
public override void ModifyDrawInfo(ref PlayerDrawSet drawInfo) {
if (drawInfo.drawPlayer.head == ArmorIDs.Head.Merman && applyHead) {
int slot = GetSlot(0);
if (slot >= 0) {
drawInfo.drawPlayer.head = slot;
if (slot > 0 && slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorHead(slot);
int backID = ArmorIDs.Head.Sets.FrontToBackID[slot];
if (backID >= 0) {
Main.instance.LoadArmorHead(backID);
}
}
drawInfo.drawsBackHairWithoutHeadgear = ArmorIDs.Head.Sets.DrawsBackHairWithoutHeadgear[drawInfo.drawPlayer.head];
drawInfo.fullHair = ArmorIDs.Head.Sets.DrawFullHair[drawInfo.drawPlayer.head];
drawInfo.hatHair = ArmorIDs.Head.Sets.DrawHatHair[drawInfo.drawPlayer.head];
}
}
if (drawInfo.drawPlayer.body == ArmorIDs.Body.Merfolk && applyBody) {
int slot = GetSlot(1);
if (slot >= 0) {
drawInfo.drawPlayer.body = slot;
if (slot > 0 && slot < ArmorIDs.Body.Count) {
Main.instance.LoadArmorBody(slot);
}
drawInfo.armorHidesHands = ArmorIDs.Body.Sets.HidesHands[slot];
drawInfo.armorHidesArms = ArmorIDs.Body.Sets.HidesArms[slot];
}
}
if (drawInfo.drawPlayer.legs == 21 && applyLegs) {
int slot = GetSlot(2);
if (slot >= 0) {
drawInfo.drawPlayer.legs = slot;
if (slot > 0 && slot < ArmorIDs.Legs.Count) {
Main.instance.LoadArmorLegs(slot);
}
}
}
}
}
public class Merfolk_Head_Layer : GenericHeadLayer {
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo) {
return drawInfo.drawPlayer.head == ArmorIDs.Head.Merman;
}
public override IEnumerable<(Texture2D texture, Color color, bool applyDye)> GetData(PlayerDrawSet drawInfo) {
FishColorPlayer beastColorPlayer = drawInfo.drawPlayer.GetModPlayer<FishColorPlayer>();
yield return (
Merfolk.HeadScaleTextures[beastColorPlayer.headScaleStyle],
drawInfo.colorArmorHead.MultiplyRGBA(beastColorPlayer.scaleColor),
true
);
yield return (
Merfolk.HeadSecondaryScaleTextures[beastColorPlayer.headScaleStyle2],
drawInfo.colorArmorHead.MultiplyRGBA(beastColorPlayer.scaleColor2),
true
);
yield return (
Merfolk.EyesTextures[beastColorPlayer.headScaleStyle2],
beastColorPlayer.eyesGlow ? beastColorPlayer.eyesColor : drawInfo.colorArmorHead.MultiplyRGBA(beastColorPlayer.eyesColor),
beastColorPlayer.eyesDye
);
if (beastColorPlayer.applyHeadOver) {
int slot = beastColorPlayer.GetSlot(0);
if (slot > 0) {
if (slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorHead(slot);
int backID = ArmorIDs.Head.Sets.FrontToBackID[slot];
if (backID >= 0) {
Main.instance.LoadArmorHead(backID);
}
}
yield return (
TextureAssets.ArmorHead[slot].Value,
drawInfo.colorArmorHead,
true
);
}
}
}
}
public class Merfolk_Body_Layer : GenericBodyLayer {
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo) {
return drawInfo.drawPlayer.body == ArmorIDs.Body.Merfolk;
}
public override IEnumerable<(Texture2D texture, Color color)> GetData(PlayerDrawSet drawInfo) {
FishColorPlayer beastColorPlayer = drawInfo.drawPlayer.GetModPlayer<FishColorPlayer>();
yield return (
Merfolk.BodyScaleTextures[beastColorPlayer.bodyScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor)
);
yield return (
Merfolk.BodySecondaryScaleTextures[beastColorPlayer.bodySecondaryScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor2)
);
if (beastColorPlayer.applyBodyOver) {
int slot = beastColorPlayer.GetSlot(1);
if (slot > 0) {
if (slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorBody(slot);
}
yield return (
drawInfo.drawPlayer.Male ? TextureAssets.ArmorBodyComposite[slot].Value : TextureAssets.FemaleBody[slot].Value,
drawInfo.colorArmorBody
);
}
}
}
}
public class Merfolk_Arm_Layer_Back : GenericArmLayer_Back {
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo) {
return drawInfo.drawPlayer.body == ArmorIDs.Body.Merfolk;
}
public override IEnumerable<(Texture2D texture, Color color)> GetData(PlayerDrawSet drawInfo) {
FishColorPlayer beastColorPlayer = drawInfo.drawPlayer.GetModPlayer<FishColorPlayer>();
yield return (
Merfolk.BodyScaleTextures[beastColorPlayer.bodyScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor)
);
yield return (
Merfolk.BodySecondaryScaleTextures[beastColorPlayer.bodySecondaryScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor2)
);
if (beastColorPlayer.applyBodyOver) {
int slot = beastColorPlayer.GetSlot(1);
if (slot > 0) {
if (slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorBody(slot);
}
yield return (
TextureAssets.ArmorBodyComposite[slot].Value,
drawInfo.colorArmorBody
);
}
}
}
}
public class Merfolk_Arm_Layer_Front : GenericArmLayer_Front {
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo) {
return drawInfo.drawPlayer.body == ArmorIDs.Body.Merfolk;
}
public override IEnumerable<(Texture2D texture, Color color)> GetData(PlayerDrawSet drawInfo) {
FishColorPlayer beastColorPlayer = drawInfo.drawPlayer.GetModPlayer<FishColorPlayer>();
yield return (
Merfolk.BodyScaleTextures[beastColorPlayer.bodyScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor)
);
yield return (
Merfolk.BodySecondaryScaleTextures[beastColorPlayer.bodySecondaryScaleStyle],
drawInfo.colorArmorBody.MultiplyRGBA(beastColorPlayer.scaleColor2)
);
if (beastColorPlayer.applyBodyOver) {
int slot = beastColorPlayer.GetSlot(1);
if (slot > 0) {
if (slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorBody(slot);
}
yield return (
TextureAssets.ArmorBodyComposite[slot].Value,
drawInfo.colorArmorBody
);
}
}
}
}
public class Merfolk_Legs_Layer : GenericLegsLayer {
public override bool GetDefaultVisibility(PlayerDrawSet drawInfo) {
return drawInfo.drawPlayer.legs == 21;
}
public override IEnumerable<(Texture2D texture, Color color)> GetData(PlayerDrawSet drawInfo) {
FishColorPlayer beastColorPlayer = drawInfo.drawPlayer.GetModPlayer<FishColorPlayer>();
yield return (
Merfolk.LegsScaleTextures[beastColorPlayer.legsScaleStyle],
drawInfo.colorArmorLegs.MultiplyRGBA(beastColorPlayer.scaleColor)
);
yield return (
Merfolk.LegsSecondaryScaleTextures[beastColorPlayer.legsScaleStyle2],
drawInfo.colorArmorLegs.MultiplyRGBA(beastColorPlayer.scaleColor2)
);
if (beastColorPlayer.applyLegsOver) {
int slot = beastColorPlayer.GetSlot(2);
if (slot > 0) {
if (slot < ArmorIDs.Head.Count) {
Main.instance.LoadArmorLegs(slot);
}
yield return (
TextureAssets.ArmorLeg[slot].Value,
drawInfo.colorArmorLegs
);
}
}
}
}
}