Exemplo n.º 1
0
 private static bool isPanelShowingLobby(OuiChapterPanel panel = null)
 {
     if (overworldWrapper != null)
     {
         panel = overworldWrapper.WrappedScene?.GetUI <OuiChapterPanel>();
     }
     if (panel == null)
     {
         panel = (Engine.Scene as Overworld)?.GetUI <OuiChapterPanel>();
     }
     return(LobbyHelper.GetLobbyLevelSet(panel?.Area.GetSID() ?? "") != null);
 }
Exemplo n.º 2
0
        private static void OnChapterPanelUpdateStats(On.Celeste.OuiChapterPanel.orig_UpdateStats orig, OuiChapterPanel self, bool wiggle,
                                                      bool?overrideStrawberryWiggle, bool?overrideDeathWiggle, bool?overrideHeartWiggle)
        {
            orig(self, wiggle, overrideStrawberryWiggle, overrideDeathWiggle, overrideHeartWiggle);

            DeathsCounter deathsCounter = new DynData <OuiChapterPanel>(self).Get <DeathsCounter>("deaths");

            if (Engine.Scene == overworldWrapper?.Scene)
            {
                // within lobbies, death counts always show up, even if you didn't beat the map yet.
                AreaModeStats areaModeStats = self.DisplayedStats.Modes[(int)self.Area.Mode];
                deathsCounter.Visible = areaModeStats.Deaths > 0 && !AreaData.Get(self.Area).Interlude_Safe;
            }

            // mod the death icon: for the path, use the current level set, or for lobbies, the lobby's matching level set.
            string pathToSkull = "CollabUtils2/skulls/" + self.Area.GetLevelSet();

            if (LobbyHelper.GetLobbyLevelSet(self.Area.GetSID()) != null)
            {
                pathToSkull = "CollabUtils2/skulls/" + LobbyHelper.GetLobbyLevelSet(self.Area.GetSID());
            }
            if (GFX.Gui.Has(pathToSkull))
            {
                new DynData <DeathsCounter>(deathsCounter)["icon"] = GFX.Gui[pathToSkull];
            }
            new DynData <DeathsCounter>(deathsCounter)["modifiedByCollabUtils"] = GFX.Gui.Has(pathToSkull);


            if (isPanelShowingLobby(self) || Engine.Scene == overworldWrapper?.Scene)
            {
                // turn strawberry counter into golden if there only are golden berries in the map
                MapData mapData = AreaData.Get(self.Area).Mode[0].MapData;
                if (mapData.GetDetectedStrawberriesIncludingUntracked() == mapData.Goldenberries.Count)
                {
                    StrawberriesCounter strawberriesCounter = new DynData <OuiChapterPanel>(self).Get <StrawberriesCounter>("strawberries");
                    strawberriesCounter.Golden    = true;
                    strawberriesCounter.ShowOutOf = false;
                }
            }
        }
Exemplo n.º 3
0
        public OuiJournalCollabProgressInOverworld(OuiJournal journal)
            : base(journal)
        {
            bool displaySpeedBerryColumn = shouldDisplaySpeedBerryColumn();

            PageTexture = "page";
            table       = new Table()
                          .AddColumn(new TextCell(Dialog.Clean("journal_progress"), new Vector2(0f, 0.5f), 1f, Color.Black * 0.7f, 420f))
                          .AddColumn(new EmptyCell(20f))
                          .AddColumn(new EmptyCell(64f))
                          .AddColumn(new IconCell("strawberry", 150f))
                          .AddColumn(new IconCell("skullblue", 100f))
                          .AddColumn(new IconCell("CollabUtils2MinDeaths/SpringCollab2020/1-Beginner", 100f));

            if (OuiJournalCollabProgressDashCountMod.IsDashCountEnabled())
            {
                table.AddColumn(new IconCell("max480/DashCountMod/dashes", 80f));
            }

            table
            .AddColumn(new IconCell("time", 220f))
            .AddColumn(new IconCell("CollabUtils2/speed_berry_pbs_heading", 220f))
            .AddColumn(new EmptyCell(30f));

            int  totalStrawberries = 0;
            int  totalDeaths       = 0;
            int  sumOfBestDeaths   = 0;
            int  sumOfBestDashes   = 0;
            long totalTime         = 0;
            long sumOfBestTimes    = 0;

            bool allLevelsDone               = true;
            bool allSpeedBerriesDone         = true;
            bool allMapsCompletedInSingleRun = true;

            foreach (AreaStats item in SaveData.Instance.Areas_Safe)
            {
                AreaData areaData = AreaData.Get(item.ID_Safe);
                if (areaData.GetLevelSet() == SaveData.Instance.LevelSet)
                {
                    string        lobbyMapLevelSetName = LobbyHelper.GetLobbyLevelSet(areaData.GetSID());
                    LevelSetStats lobbyMapLevelSet     = null;
                    if (lobbyMapLevelSetName != null)
                    {
                        lobbyMapLevelSet = SaveData.Instance.GetLevelSetStatsFor(lobbyMapLevelSetName);
                    }

                    int  lobbyStrawberries                = item.TotalStrawberries;
                    int  lobbyTotalStrawberries           = areaData.Mode[0].TotalStrawberries;
                    int  lobbyDeaths                      = item.Modes[0].Deaths;
                    int  lobbySumOfBestDeaths             = 0;
                    int  lobbySumOfBestDashes             = OuiJournalCollabProgressDashCountMod.DisplaysTotalDashes() ? OuiJournalCollabProgressDashCountMod.GetLevelDashesForJournalProgress(item) : 0;
                    long lobbyTotalTime                   = item.TotalTimePlayed;
                    long lobbySumOfBestTimes              = 0;
                    bool lobbyLevelsDone                  = true;
                    int  lobbySpeedBerryLevel             = 1;
                    bool lobbySilverBerriesObtained       = true;
                    bool lobbyAllMapsCompletedInSingleRun = true;

                    foreach (AreaStats lobbyMap in lobbyMapLevelSet?.Areas ?? new List <AreaStats>())
                    {
                        AreaData lobbyAreaData = AreaData.Get(lobbyMap.ID_Safe);
                        lobbyStrawberries                += lobbyMap.TotalStrawberries;
                        lobbyTotalStrawberries           += lobbyAreaData.Mode[0].TotalStrawberries;
                        lobbyDeaths                      += lobbyMap.Modes[0].Deaths;
                        lobbyTotalTime                   += lobbyMap.TotalTimePlayed;
                        lobbyAllMapsCompletedInSingleRun &= lobbyMap.Modes[0].SingleRunCompleted;

                        if (displaySpeedBerryColumn)
                        {
                            if (CollabMapDataProcessor.SpeedBerries.TryGetValue(lobbyMap.GetSID(), out CollabMapDataProcessor.SpeedBerryInfo mapSpeedBerryInfo) &&
                                CollabModule.Instance.SaveData.SpeedBerryPBs.TryGetValue(lobbyMap.GetSID(), out long mapSpeedBerryPB))
                            {
                                lobbySpeedBerryLevel = Math.Max(getRankLevel(mapSpeedBerryInfo, mapSpeedBerryPB), lobbySpeedBerryLevel);
                                lobbySumOfBestTimes += mapSpeedBerryPB;
                            }
                            else
                            {
                                lobbySpeedBerryLevel = 4;
                            }
                        }
                        else
                        {
                            if (lobbyMap.Modes[0].BestTime > 0f)
                            {
                                lobbySumOfBestTimes += lobbyMap.Modes[0].BestTime;
                            }
                            else
                            {
                                lobbySpeedBerryLevel = 4;
                            }
                        }

                        bool goldenBerryNotObtained = !lobbyMap.Modes[0].Strawberries.Any(berry => lobbyAreaData.Mode[0].MapData.Goldenberries.Any(golden => golden.ID == berry.ID && golden.Level.Name == berry.Level));
                        bool silverBerryNotObtained = !CollabMapDataProcessor.SilverBerries.TryGetValue(lobbyMap.GetLevelSet(), out Dictionary <string, EntityID> levelSetBerries) ||
                                                      !levelSetBerries.TryGetValue(lobbyMap.GetSID(), out EntityID berryID) ||
                                                      !lobbyMap.Modes[0].Strawberries.Contains(berryID);

                        if (goldenBerryNotObtained && silverBerryNotObtained)
                        {
                            lobbySilverBerriesObtained = false;
                            lobbySumOfBestDeaths      += lobbyMap.Modes[0].BestDeaths;
                        }

                        lobbySumOfBestDashes += OuiJournalCollabProgressDashCountMod.GetLevelDashesForJournalProgress(lobbyMap);

                        if (!lobbyMap.Modes[0].HeartGem)
                        {
                            lobbyLevelsDone = false;
                        }
                    }

                    string strawberryText = null;
                    if (lobbyStrawberries > 0 || lobbyTotalStrawberries > 0)
                    {
                        strawberryText = lobbyStrawberries.ToString();
                        if (lobbyLevelsDone)
                        {
                            strawberryText = strawberryText + "/" + lobbyTotalStrawberries;
                        }
                    }
                    else
                    {
                        strawberryText = "-";
                    }

                    string heartTexturePath = lobbyMapLevelSetName ?? areaData.GetSID();
                    string heartTexture     = MTN.Journal.Has("CollabUtils2Hearts/" + heartTexturePath) ? "CollabUtils2Hearts/" + heartTexturePath : "heartgem0";

                    string areaName = Dialog.Clean(areaData.Name);
                    if (Dialog.Has(areaData.Name + "_journal"))
                    {
                        areaName = Dialog.Clean(areaData.Name + "_journal");
                    }

                    Row row = table.AddRow()
                              .Add(new TextCell(areaName, new Vector2(1f, 0.5f), 0.6f, TextColor))
                              .Add(null)
                              .Add(new IconCell(item.Modes[0].HeartGem ? heartTexture : "dot"))
                              .Add(new TextCell(strawberryText, TextJustify, 0.5f, TextColor));

                    if (lobbyTotalTime > 0)
                    {
                        row.Add(new TextCell(Dialog.Deaths(lobbyDeaths), TextJustify, 0.5f, TextColor));
                    }
                    else
                    {
                        row.Add(new IconCell("dot"));
                    }

                    if (lobbyLevelsDone)
                    {
                        AreaStats stats = SaveData.Instance.GetAreaStatsFor(areaData.ToKey());
                        if (lobbyMapLevelSet == null)
                        {
                            row.Add(new TextCell(Dialog.Deaths(item.Modes[0].BestDeaths), TextJustify, 0.5f, TextColor));
                            sumOfBestDeaths += item.Modes[0].BestDeaths;
                        }
                        else if (lobbySilverBerriesObtained)
                        {
                            row.Add(new IconCell("CollabUtils2/golden_strawberry"));
                        }
                        else if (lobbyAllMapsCompletedInSingleRun)
                        {
                            row.Add(new TextCell(Dialog.Deaths(lobbySumOfBestDeaths), TextJustify, 0.5f, TextColor));
                        }
                        else
                        {
                            row.Add(new IconCell("dot"));
                        }
                    }
                    else
                    {
                        row.Add(new IconCell("dot"));
                        allLevelsDone = false;
                    }


                    if (OuiJournalCollabProgressDashCountMod.IsDashCountEnabled())
                    {
                        if (lobbyMapLevelSet == null)
                        {
                            if ((OuiJournalCollabProgressDashCountMod.DisplaysTotalDashes() && item.TotalTimePlayed > 0) || item.Modes[0].SingleRunCompleted)
                            {
                                row.Add(new TextCell(Dialog.Deaths(OuiJournalCollabProgressDashCountMod.GetLevelDashesForJournalProgress(item)),
                                                     TextJustify, 0.5f, TextColor));
                                sumOfBestDashes += OuiJournalCollabProgressDashCountMod.GetLevelDashesForJournalProgress(item);
                            }
                            else
                            {
                                row.Add(new IconCell("dot"));
                            }
                        }
                        else if ((OuiJournalCollabProgressDashCountMod.DisplaysTotalDashes() && item.TotalTimePlayed > 0) || lobbyAllMapsCompletedInSingleRun)
                        {
                            row.Add(new TextCell(Dialog.Deaths(lobbySumOfBestDashes), TextJustify, 0.5f, TextColor));
                        }
                        else
                        {
                            row.Add(new IconCell("dot"));
                        }
                    }

                    if (lobbyTotalTime > 0)
                    {
                        row.Add(new TextCell(Dialog.Time(lobbyTotalTime), TextJustify, 0.5f, TextColor));
                    }
                    else
                    {
                        row.Add(new IconCell("dot"));
                    }

                    if (lobbyMapLevelSet == null)
                    {
                        row.Add(new TextCell("-", TextJustify, 0.5f, TextColor)).Add(null);
                    }
                    else if (lobbySpeedBerryLevel < 4)
                    {
                        if (displaySpeedBerryColumn)
                        {
                            row.Add(new TextCell(Dialog.Time(lobbySumOfBestTimes), TextJustify, 0.5f, getRankColor(lobbySpeedBerryLevel)));
                            row.Add(new IconCell(getRankIcon(lobbySpeedBerryLevel)));
                            sumOfBestTimes += lobbySumOfBestTimes;
                        }
                        else
                        {
                            row.Add(new TextCell(Dialog.Time(lobbySumOfBestTimes), TextJustify, 0.5f, TextColor)).Add(null);
                            sumOfBestTimes += lobbySumOfBestTimes;
                        }
                    }
                    else
                    {
                        row.Add(new IconCell("dot")).Add(null);
                        allSpeedBerriesDone = false;
                    }

                    totalStrawberries           += lobbyStrawberries;
                    totalDeaths                 += lobbyDeaths;
                    sumOfBestDeaths             += lobbySumOfBestDeaths;
                    sumOfBestDashes             += lobbySumOfBestDashes;
                    totalTime                   += lobbyTotalTime;
                    allMapsCompletedInSingleRun &= lobbyAllMapsCompletedInSingleRun;

                    if (!lobbyLevelsDone)
                    {
                        allLevelsDone = false;
                    }
                }
            }

            table.AddRow();
            Row totalsRow = table.AddRow()
                            .Add(new TextCell(Dialog.Clean("journal_totals"), new Vector2(1f, 0.5f), 0.7f, TextColor)).Add(null)
                            .Add(null)
                            .Add(new TextCell(totalStrawberries.ToString(), TextJustify, 0.6f, TextColor))
                            .Add(new TextCell(Dialog.Deaths(totalDeaths), TextJustify, 0.6f, TextColor))
                            .Add(new TextCell(allLevelsDone && allMapsCompletedInSingleRun ? Dialog.Deaths(sumOfBestDeaths) : "-", TextJustify, 0.6f, TextColor));

            if (OuiJournalCollabProgressDashCountMod.IsDashCountEnabled())
            {
                totalsRow.Add(new TextCell(OuiJournalCollabProgressDashCountMod.DisplaysTotalDashes() || (allLevelsDone && allMapsCompletedInSingleRun) ?
                                           Dialog.Deaths(sumOfBestDashes) : "-", TextJustify, 0.6f, TextColor));
            }

            totalsRow
            .Add(new TextCell(Dialog.Time(totalTime), TextJustify, 0.6f, TextColor))
            .Add(new TextCell(allSpeedBerriesDone ? Dialog.Time(sumOfBestTimes) : "-", TextJustify, 0.6f, TextColor)).Add(null);

            for (int l = 1; l < SaveData.Instance.UnlockedModes; l++)
            {
                totalsRow.Add(null);
            }
            totalsRow.Add(new TextCell(Dialog.Time(SaveData.Instance.Time), TextJustify, 0.6f, TextColor));
            table.AddRow();
        }