Skip to content

Commit

Permalink
A few things I missed
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreML committed Nov 9, 2023
1 parent 2c0942f commit 1b64786
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
28 changes: 15 additions & 13 deletions src/ChatlogRegionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ChatlogRegionList : RoundedRect
{
// The number of entries in each column of the region list.
private const int labelColumnLength = 5;
// The default text for the 'available' state of the button.
private const string defaultText = "[SHOW REMAINING BROADCAST LOCATIONS]";

// A button which is used to hide the actual region list until it's held down.
// Also used for unavailable chatlogs, greyed out and with its text set to '[UNAVAILABLE]'.
Expand All @@ -30,7 +32,7 @@ public ChatlogRegionList(Menu.Menu menu, MenuObject owner, Vector2 pos, Vector2
this.borderColor = Menu.Menu.MenuColor(Menu.Menu.MenuColors.MediumGrey);

// Create the hold button inside the region list of the same size and with no position offset, so that it acts as a sort of overlay.
showListButton = new(Vector2.zero, size, "[SHOW REMAINING BROADCAST LOCATIONS]", 50f)
showListButton = new(Vector2.zero, size, defaultText, 50f)
{
description = "Hold to display all regions with uncollected broadcast tokens", // Hover text.
colorEdge = Color.white
Expand Down Expand Up @@ -59,24 +61,24 @@ public ChatlogRegionList(Menu.Menu menu, MenuObject owner, Vector2 pos, Vector2
allRegionlabels = leftRegionLabels.Concat(rightRegionLabels).ToArray();
}

// Enable or disable the 'unavailable' state of the region list. Used for linear chatlogs that can't be collected by the player.
public void SetUnavailable(bool on)
// Enable or disable the 'available' state of the region list. Used for linear chatlogs that can't be collected by the player.
public void SetAvailable(bool available)
{
// Set `greyedOut` to the value of `on`, making it so that it can or can't be clicked.
showListButton.greyedOut = on;
if (on)
if (available)
{
// Hide the region labels, reset the button, and set its text.
// Set the button back to normal.
showListButton.greyedOut = false;
showListButton.text = defaultText;
}
else
{
// Hide the region labels, grey-out, reset, and set the text of the button, and make it visible again.
HideRegionNames();
showListButton.greyedOut = true;
showListButton.text = "[UNAVAILABLE]";
showListButton._glow.Hide();
showListButton.Show();
}
else
{
// Set the button back to normal.
showListButton.text = "[SHOW REMAINING BROADCAST LOCATIONS]";
}
}

// Fills the region labels with the names of every region that contains linear chatlog collectibles.
Expand Down Expand Up @@ -112,7 +114,7 @@ private void ShowRegionNames()
}

// Sets the `text` of all region labels to an empty string.
// Called by `SetUnavailable()`, when the selected linear chatlog isn't collectable by the player.
// Called by `SetAvailable()`, when the selected linear chatlog isn't collectable by the player.
private void HideRegionNames()
{
foreach (MenuLabel label in allRegionlabels)
Expand Down
44 changes: 29 additions & 15 deletions src/CollectionLabelsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void CollectionsMenuHK(On.MoreSlugcats.CollectionsMenu.orig_ctor orig, C
orig(self, manager);

// Add `nameLabel` to the menu.
float labelX = self.textBoxBorder.pos.x + (self.textBoxBorder.size.x / 2f); // Centered horizontally.
float labelX = self.textBoxBorder.pos.x + (self.textBoxBorder.size.x / 2f); // Centred horizontally.
float labelY = self.textBoxBorder.pos.y + (self.textBoxBorder.size.y - 30f); // Near the top vertically.
nameLabel = new(self, self.pages[0], "", new Vector2(labelX, labelY), Vector2.zero, true);
self.pages[0].subObjects.Add(nameLabel);
Expand Down Expand Up @@ -72,7 +72,7 @@ private void ShutDownProcessHK(On.MoreSlugcats.CollectionsMenu.orig_ShutDownProc
orig(self);
// Clean up the UI elements when the menu closes.
nameLabel = null;
HideChatlogRegionList(self);
RemoveChatlogRegionList(self);
}

private void LoadPearlNames(CollectionsMenu self)
Expand Down Expand Up @@ -178,7 +178,7 @@ private void SingalHK(On.MoreSlugcats.CollectionsMenu.orig_Singal orig, Collecti
private void HandlePearlSingal(CollectionsMenu self)
{
// Remove the region list if it's there.
HideChatlogRegionList(self);
RemoveChatlogRegionList(self);

DataPearl.AbstractDataPearl.DataPearlType selectedPearl = self.usedPearlTypes[self.selectedPearlInd];

Expand Down Expand Up @@ -208,28 +208,39 @@ private void HandleChatlogSingal(CollectionsMenu self, MenuObject sender)
nameLabel.label.color = sender.inactive ? Color.grey : self.chatlogSprites[chatlogIndex].color;
nameLabel.text = chatlogNames[chatlogIndex];

// todo: comment here
// If `LinearChatlogHelper` couldn't load any Spearmaster save data, nothing past this point would work properly.
if (!LinearChatlogHelper.Loaded)
{
// So just return instead.
return;
}
// If it's a regular chatlog with a set location, or it's already been collected by the player, hide/don't show the region list.

// If it's a regular chatlog with a set location, or it's already been collected by the player, hide the region list.
if (!isLinearChatlog || !sender.inactive)
{
// Hide the region list.
HideChatlogRegionList(self);
// Don't show the region list.
RemoveChatlogRegionList(self);
return;
}

// Create the region list
MakeChatlogRegionList(self);

bool selectedLogIsPrePebs = chatlogIndex < self.prePebsBroadcastChatlogs.Count;
bool selectedLogIsPostPebs = chatlogIndex >= self.prePebsBroadcastChatlogs.Count;

// If it's a pre/post-pebbles exclusive chatlog and the player is in the other part of the story, then they can't collect it even if they want to.
bool unableToCollect = (LinearChatlogHelper.PlayerIsPostPebbles && selectedLogIsPrePebs) || (!LinearChatlogHelper.PlayerIsPostPebbles && selectedLogIsPostPebs);

MakeChatlogRegionList(self);
// If it's unavailable, disable the region list button.
chatlogRegionList.SetUnavailable(unableToCollect);
if ((LinearChatlogHelper.PlayerIsPostPebbles && selectedLogIsPrePebs) || (!LinearChatlogHelper.PlayerIsPostPebbles && selectedLogIsPostPebs))
{
// Disable the region list, and log the reason just in case anyone gets confused.
chatlogRegionList.SetAvailable(false);
Debug.Log($"(CollectionLables) Chatlog {chatlogNames[chatlogIndex]} is not able to be collected by the player due to story progression.");
}
else
{
// Otherwise, set the list back to its original state.
chatlogRegionList.SetAvailable(true);
}
}

private void MakeChatlogRegionList(CollectionsMenu menu)
Expand All @@ -240,21 +251,24 @@ private void MakeChatlogRegionList(CollectionsMenu menu)
return;
}

// Set the region list's initial position to halfway across the collections menu text box, and 60 down from the top of it.
Vector2 regionListPos = new(
menu.textBoxBorder.pos.x + (menu.textBoxBorder.size.x / 2f),
menu.textBoxBorder.pos.y + menu.textBoxBorder.size.y - 60f
);

// Create the list.
chatlogRegionList = new(menu, menu.pages[0], regionListPos, new Vector2(380f, 125f), false);
// Adjust its position so that the centre of the list is at `regionListPos` rather than the corner.
chatlogRegionList.pos.x -= chatlogRegionList.size.x / 2f;
chatlogRegionList.pos.y -= chatlogRegionList.size.y;

// Add it to the collections menu's `subObjects` list.
menu.pages[0].subObjects.Add(chatlogRegionList);
}

private void HideChatlogRegionList(CollectionsMenu menu)
private void RemoveChatlogRegionList(CollectionsMenu menu)
{
// If it doesn't actually exist, return.
// If it isn't actually there to remove, return.
if (chatlogRegionList == null)
{
return;
Expand Down

0 comments on commit 1b64786

Please sign in to comment.