Skip to content

Commit 266a15f

Browse files
committed
0.1.5 release. Hide bosses and hidden boss mp sync.
1 parent 37ea499 commit 266a15f

File tree

5 files changed

+151
-6
lines changed

5 files changed

+151
-6
lines changed

BossChecklist.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Terraria.UI.Chat;
1010
using System.Linq;
1111
using Terraria.GameContent.UI.Chat;
12+
using System.IO;
13+
using Terraria.ID;
1214

1315
// TODO: Kill all npc checklist
1416
// TODO: Currently have all town npc checklist
@@ -212,6 +214,51 @@ public override object Call(params object[] args)
212214
}
213215
return "Failure";
214216
}
217+
218+
public override void HandlePacket(BinaryReader reader, int whoAmI)
219+
{
220+
BossChecklistMessageType msgType = (BossChecklistMessageType)reader.ReadByte();
221+
switch (msgType)
222+
{
223+
// Sent from Client to Server
224+
case BossChecklistMessageType.RequestHideBoss:
225+
//if (Main.netMode == NetmodeID.MultiplayerClient)
226+
//{
227+
// Main.NewText("Huh? RequestHideBoss on client?");
228+
//}
229+
string bossName = reader.ReadString();
230+
bool hide = reader.ReadBoolean();
231+
if (hide)
232+
BossChecklistWorld.HiddenBosses.Add(bossName);
233+
else
234+
BossChecklistWorld.HiddenBosses.Remove(bossName);
235+
if (Main.netMode == NetmodeID.Server)
236+
NetMessage.SendData(MessageID.WorldData);
237+
//else
238+
// ErrorLogger.Log("BossChecklist: Why is RequestHideBoss on Client/SP?");
239+
break;
240+
case BossChecklistMessageType.RequestClearHidden:
241+
//if (Main.netMode == NetmodeID.MultiplayerClient)
242+
//{
243+
// Main.NewText("Huh? RequestClearHidden on client?");
244+
//}
245+
BossChecklistWorld.HiddenBosses.Clear();
246+
if (Main.netMode == NetmodeID.Server)
247+
NetMessage.SendData(MessageID.WorldData);
248+
//else
249+
// ErrorLogger.Log("BossChecklist: Why is RequestHideBoss on Client/SP?");
250+
break;
251+
default:
252+
ErrorLogger.Log("BossChecklist: Unknown Message type: " + msgType);
253+
break;
254+
}
255+
}
256+
}
257+
258+
enum BossChecklistMessageType : byte
259+
{
260+
RequestHideBoss,
261+
RequestClearHidden,
215262
}
216263
}
217264

BossChecklistUI.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Terraria.ID;
99
using Terraria.UI.Chat;
1010
using Terraria.ModLoader;
11+
using Microsoft.Xna.Framework.Input;
1112

1213
namespace BossChecklist.UI
1314
{
@@ -16,6 +17,7 @@ class BossChecklistUI : UIState
1617
public UIHoverImageButton toggleCompletedButton;
1718
public UIHoverImageButton toggleMiniBossButton;
1819
public UIHoverImageButton toggleEventButton;
20+
public UIHoverImageButton toggleHiddenButton;
1921
public UIPanel checklistPanel;
2022
public UIList checklistList;
2123

@@ -24,6 +26,7 @@ class BossChecklistUI : UIState
2426
public static bool showCompleted = true;
2527
public static bool showMiniBoss = true;
2628
public static bool showEvent = true;
29+
public static bool showHidden = false;
2730
public static string hoverText = "";
2831

2932
public override void OnInitialize()
@@ -55,6 +58,12 @@ public override void OnInitialize()
5558
toggleEventButton.Top.Pixels = spacing;
5659
checklistPanel.Append(toggleEventButton);
5760

61+
toggleHiddenButton = new UIHoverImageButton(Main.itemTexture[ItemID.InvisibilityPotion], "Toggle Show Hidden Bosses\n- Alt Click to clear Hidden bosses\n-Alt Click on boss to hide");
62+
toggleHiddenButton.OnClick += ToggleHiddenButtonClicked;
63+
toggleHiddenButton.Left.Pixels = spacing + 96;
64+
toggleHiddenButton.Top.Pixels = spacing;
65+
checklistPanel.Append(toggleHiddenButton);
66+
5867
checklistList = new UIList();
5968
checklistList.Top.Pixels = 32f + spacing;
6069
checklistList.Width.Set(-25f, 1f);
@@ -100,6 +109,27 @@ private void ToggleEventButtonClicked(UIMouseEvent evt, UIElement listeningEleme
100109
UpdateCheckboxes();
101110
}
102111

112+
private void ToggleHiddenButtonClicked(UIMouseEvent evt, UIElement listeningElement)
113+
{
114+
Main.PlaySound(SoundID.MenuOpen);
115+
if (Main.keyState.IsKeyDown(Keys.LeftAlt) || Main.keyState.IsKeyDown(Keys.RightAlt))
116+
{
117+
BossChecklistWorld.HiddenBosses.Clear();
118+
showHidden = false;
119+
UpdateCheckboxes();
120+
121+
if (Main.netMode == NetmodeID.MultiplayerClient)
122+
{
123+
ModPacket packet = BossChecklist.instance.GetPacket();
124+
packet.Write((byte)BossChecklistMessageType.RequestClearHidden);
125+
packet.Send();
126+
}
127+
return;
128+
}
129+
showHidden = !showHidden;
130+
UpdateCheckboxes();
131+
}
132+
103133
/*public bool ThoriumModDownedScout
104134
{
105135
get { return ThoriumMod.ThoriumWorld.downedScout; }
@@ -112,7 +142,8 @@ internal void UpdateCheckboxes()
112142

113143
foreach (BossInfo boss in allBosses)
114144
{
115-
if (boss.available())
145+
boss.hidden = BossChecklistWorld.HiddenBosses.Contains(boss.name);
146+
if (boss.available() && (!boss.hidden || showHidden))
116147
{
117148
if (showCompleted || !boss.downed())
118149
{
@@ -214,9 +245,10 @@ private void InitializeVanillaBosses()
214245
new BossInfo(BossChecklistType.MiniBoss, "Mourning Wood", Plantera + 0.6f, () => true, () => NPC.downedHalloweenTree, $"Spawns during Wave 4 of Pumpkin Moon. Start Pumpkin Moon with [i:{ItemID.PumpkinMoonMedallion}]"),
215246
new BossInfo(BossChecklistType.Event, "Martian Madness", Golem + 0.4f, () => true, () => NPC.downedMartians, $"After defeating Golem, find a Martian Probe above ground and let it escape."),
216247
new BossInfo(BossChecklistType.Event, "Pirate Invasion", WallOfFlesh + 0.7f, () => true, () => NPC.downedPirates, $"Occurs randomly in Hardmode after an Altar has been destroyed. Alternatively, spawn with [i:{ItemID.PirateMap}]"),
217-
new BossInfo(BossChecklistType.Event, "Old One's Army 1", EaterOfWorlds + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT1, $"After finding the Tavernkeep, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
218-
new BossInfo(BossChecklistType.Event, "Old One's Army 2", TheTwins + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT2, $"After defeating a mechanical boss, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
219-
new BossInfo(BossChecklistType.Event, "Old One's Army 3", Golem + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT3, $"After defeating Golem, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
248+
new BossInfo(BossChecklistType.Event, "Old One's Army Any Tier", EaterOfWorlds + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionAnyDifficulty, $"After finding the Tavernkeep, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
249+
//new BossInfo(BossChecklistType.Event, "Old One's Army 1", EaterOfWorlds + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT1, $"After finding the Tavernkeep, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
250+
//new BossInfo(BossChecklistType.Event, "Old One's Army 2", TheTwins + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT2, $"After defeating a mechanical boss, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
251+
//new BossInfo(BossChecklistType.Event, "Old One's Army 3", Golem + 0.5f, () => true, () => Terraria.GameContent.Events.DD2Event.DownedInvasionT3, $"After defeating Golem, activate [i:{ItemID.DD2ElderCrystalStand}] with [i:{ItemID.DD2ElderCrystal}]"),
220252

221253
// ThoriumMod -- Working, missing some minibosses/bosses?
222254
/*
@@ -339,6 +371,7 @@ internal void AddEvent(string bossname, float bossValue, Func<bool> bossDowned,
339371
public class BossInfo
340372
{
341373
internal Func<bool> available;
374+
internal bool hidden;
342375
internal Func<bool> downed;
343376
internal string name;
344377
internal float progression;
@@ -354,6 +387,7 @@ internal BossInfo(BossChecklistType type, string name, float progression, Func<b
354387
this.available = available;
355388
this.downed = downed;
356389
this.info = info;
390+
this.hidden = false;
357391
}
358392
}
359393

BossChecklistWorld.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using Terraria;
34
using Terraria.ModLoader;
5+
using Terraria.ModLoader.IO;
46

57
namespace BossChecklist
68
{
@@ -9,6 +11,29 @@ namespace BossChecklist
911
/// </summary>
1012
class BossChecklistWorld : ModWorld
1113
{
14+
public static HashSet<string> HiddenBosses = new HashSet<string>();
15+
public override void Initialize()
16+
{
17+
HiddenBosses.Clear();
18+
}
19+
20+
public override void Load(TagCompound tag)
21+
{
22+
var HiddenBossesList = tag.GetList<string>("HiddenBossesList");
23+
foreach (var bossName in HiddenBossesList)
24+
{
25+
HiddenBosses.Add(bossName);
26+
}
27+
}
28+
29+
public override TagCompound Save()
30+
{
31+
var HiddenBossesList = new List<string>(HiddenBosses);
32+
return new TagCompound {
33+
{"HiddenBossesList", HiddenBossesList}
34+
};
35+
}
36+
1237
public override void NetSend(BinaryWriter writer)
1338
{
1439
BitsByte flags = new BitsByte();
@@ -17,6 +42,12 @@ public override void NetSend(BinaryWriter writer)
1742
flags[2] = NPC.downedTowerNebula;
1843
flags[3] = NPC.downedTowerStardust;
1944
writer.Write(flags);
45+
46+
writer.Write(HiddenBosses.Count);
47+
foreach (var bossName in HiddenBosses)
48+
{
49+
writer.Write(bossName);
50+
}
2051
}
2152

2253
public override void NetReceive(BinaryReader reader)
@@ -26,6 +57,14 @@ public override void NetReceive(BinaryReader reader)
2657
NPC.downedTowerVortex = flags[1];
2758
NPC.downedTowerNebula = flags[2];
2859
NPC.downedTowerStardust = flags[3];
60+
61+
HiddenBosses.Clear();
62+
int count = reader.ReadInt32();
63+
for (int i = 0; i < count; i++)
64+
{
65+
HiddenBosses.Add(reader.ReadString());
66+
}
67+
BossChecklist.instance.bossChecklistUI.UpdateCheckboxes();
2968
}
3069
}
3170
}

UIBossCheckbox.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
using Terraria.UI;
44
using Terraria;
55
using Terraria.UI.Chat;
6+
using Microsoft.Xna.Framework.Input;
7+
using Terraria.ID;
8+
using Terraria.ModLoader;
69

710
namespace BossChecklist.UI
811
{
12+
// TODO: investigate DD event problem: complete dd1, dd2 and 3 are checked off. -> vanilla bug.
913
class UIBossCheckbox : UIElement
1014
{
1115
internal UICheckbox checkbox;
@@ -24,6 +28,8 @@ public UIBossCheckbox(BossInfo boss)
2428
checkbox.TextColor = Color.MediumPurple;
2529
if (boss.type == BossChecklistType.MiniBoss)
2630
checkbox.TextColor = Color.CornflowerBlue;
31+
if (boss.hidden)
32+
checkbox.TextColor = Color.DarkGreen;
2733
checkbox.Selected = boss.downed();
2834
//checkbox.spawnItemID = boss.spawnItemID;
2935
Append(checkbox);
@@ -33,6 +39,25 @@ public UIBossCheckbox(BossInfo boss)
3339

3440
private void Box_OnClick(UIMouseEvent evt, UIElement listeningElement)
3541
{
42+
if (Main.keyState.IsKeyDown(Keys.LeftAlt) || Main.keyState.IsKeyDown(Keys.RightAlt))
43+
{
44+
boss.hidden = !boss.hidden;
45+
if (boss.hidden)
46+
BossChecklistWorld.HiddenBosses.Add(boss.name);
47+
else
48+
BossChecklistWorld.HiddenBosses.Remove(boss.name);
49+
BossChecklist.instance.bossChecklistUI.UpdateCheckboxes();
50+
if (Main.netMode == NetmodeID.MultiplayerClient)
51+
{
52+
ModPacket packet = BossChecklist.instance.GetPacket();
53+
packet.Write((byte)BossChecklistMessageType.RequestHideBoss);
54+
packet.Write(boss.name);
55+
packet.Write(boss.hidden);
56+
packet.Send();
57+
}
58+
return;
59+
}
60+
3661
UIBossCheckbox clicked = listeningElement as UIBossCheckbox;
3762
foreach (var item in BossChecklist.instance.bossChecklistUI.checklistList._items)
3863
{

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
author = jopojelly
2-
version = 0.1.4.2
2+
version = 0.1.5
33
displayName = Boss Checklist
44
homepage = http://forums.terraria.org/index.php?threads/boss-checklist-in-game-progression-checklist.50668/
55
hideCode = false

0 commit comments

Comments
 (0)