Skip to content

Commit

Permalink
v1.2.0 - fixes and better UI
Browse files Browse the repository at this point in the history
- fixed PBs not being loaded
- fixed compatibility with RandomizedPantheons
- added compact mode UI
- now uses Satchel BetterMenus
  • Loading branch information
Dastan21 committed Jan 16, 2022
1 parent cbb9ed4 commit 5b1abf7
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 508 deletions.
4 changes: 4 additions & 0 deletions PantheonsHitCounter/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public class BossData
[Serializable]
public class GlobalData
{
public static int defaultSplitsNumber = 5;

[JsonConverter(typeof(PlayerActionSetConverter))]
public KeyBinds keybinds = new KeyBinds();
[JsonConverter(typeof(PlayerActionSetConverter))]
public ButtonBinds buttonbinds = new ButtonBinds();

public bool anonymize;
public bool compactMode;
public int totalSplits = defaultSplitsNumber;
}

public class KeyBinds : PlayerActionSet
Expand Down
481 changes: 98 additions & 383 deletions PantheonsHitCounter/ModMenu.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PantheonsHitCounter/Pantheon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void ResetPbCounter()
}

public Boss GetBossBySceneName(string sceneName) => bosses.Find(boss => boss.sceneName.Equals(sceneName));
public Boss GetBossByName(string bossName) => bosses.Find(boss => boss.name.Equals(bossName));
public void NextBoss()
{
if (bossNumber < bosses.Count - 1) bossNumber++;
Expand Down
73 changes: 33 additions & 40 deletions PantheonsHitCounter/PantheonsHitCounter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -27,30 +26,36 @@ public class PantheonsHitCounter : Mod, IGlobalSettings<GlobalData>, ILocalSetti
private static readonly string[] TransitionScenes = { "GG_Spa", "GG_Engine", "GG_Engine_Prime", "GG_Engine_Root", "GG_Unn", "GG_Wyrm", "GG_End_Sequence" };
private static readonly string[] GodhomeScenes = { "GG_Atrium", "GG_Atrium_Roof" };
private static readonly string[] CompletedScene = { "GG_End_Sequence", "End_Game_Completion" };
public const int SplitsMin = 3;
public const int DefaultSplitsCountMax = 10;
public const int CompactSplitsCountMax = 30;

public PantheonsHitCounter() : base("Pantheons Hit Counter") {}
public override string GetVersion() => "1.1.0";
public override string GetVersion() => "1.2.0";
public void OnLoadGlobal(GlobalData data) => globalData = data;
public GlobalData OnSaveGlobal() => globalData;
public void OnLoadLocal(LocalData data) => _localData = data;
public LocalData OnSaveLocal() => _localData;
private static bool IsTransitionScene(string sceneName) => TransitionScenes.Contains(sceneName);
private static bool IsFailingScene(string sceneName) => GodhomeScenes.Contains(sceneName);
private static bool IsCompletedScene(string sceneName) => CompletedScene.Contains(sceneName);
private static bool IsMenuTitleScene() => Satchel.SceneUtils.getCurrentScene().name == "Menu_Title";

public override void Initialize()
{
instance = this;

ModHooks.SavegameLoadHook += LoadPBs;
On.QuitToMenu.Start += OnQuitToMenu;
ModHooks.BeforeSceneLoadHook += OnSceneLoad;
ModHooks.TakeHealthHook += OnHitTaken;
ModHooks.HeroUpdateHook += OnHeroUpdate;
On.BossSequenceDoor.Start += OnRandomizedPantheon;
On.UIManager.ShowMenu += ReorderButtons;

if (_loaded) return;
if (_loaded)
{
ToggleCurrentCounter();
return;
}
_loaded = true;

ResourcesLoader.Instance.LoadResources();
Expand All @@ -71,12 +76,14 @@ private void OnRandomizedPantheon(On.BossSequenceDoor.orig_Start orig, BossSeque
var bossScene = bossSequence.GetBossScene(b);
if (TransitionScenes.Contains(bossScene.sceneName)) continue;

var boss = new Boss
var boss = pantheon.GetBossBySceneName(bossScene.sceneName);
var newBoss = new Boss
{
sceneName = bossScene.sceneName,
name = pantheon.GetBossBySceneName(bossScene.sceneName).name
name = boss.name,
hitsPb = boss.hitsPb
};
bosses.Add(boss);
bosses.Add(newBoss);
}

pantheon.bosses = bosses;
Expand All @@ -92,9 +99,13 @@ private void LoadPBs(int _)

var pantheonData = _localData.pantheons[p];
if (pantheonData.bosses.Count == 0) continue;

for (var b = 0; b < pantheon.bosses.Count; b++)
pantheon.bosses[b].hitsPb = pantheonData.bosses[b].hitsPb;
{
var bossData = pantheonData.bosses[b];
var boss = pantheon.GetBossByName(bossData.name);
boss.hitsPb = bossData.hitsPb;
}

Log($"Loaded PBs for {pantheon.name}");
}
Expand Down Expand Up @@ -170,7 +181,7 @@ private void UpdateData()
var pantheon = pantheons[pantheonNumber];
var pantheonData = _localData.pantheons[pantheonNumber];
if (pantheonData.bosses.Count == 0) pantheonData.FillPantheonBosses();

for (var b = 0; b < pantheon.bosses.Count; b++)
{
var boss = pantheon.bosses[b];
Expand Down Expand Up @@ -217,49 +228,31 @@ private void OnHeroUpdate()
CounterUI.Toggle(currentPantheon);
}
}

private static IEnumerator ReorderButtons(On.UIManager.orig_ShowMenu orig, UIManager self, MenuScreen menu)
{
// need to do this, probably something about components not being active in hierarchy and so the logic doesn't work
if (menu == ModMenu.mainMenu)
GameManager.instance.StartCoroutine(ReorderAfterFrame());
yield return orig(self, menu);

}

private static IEnumerator ReorderAfterFrame()
{
yield return null;
ModMenu.Reorder();
ModMenu.needReorder = false;

}

private static IEnumerator OnQuitToMenu(On.QuitToMenu.orig_Start orig, QuitToMenu self)

public void ToggleCurrentCounter()
{
ResourcesLoader.Instance.Destroy();
ModMenu.needReorder = true;
ModMenu.isControllerBindsShown = !ModMenu.isControllerBindsShown;
ModMenu.isKeyboardBindsShown = !ModMenu.isKeyboardBindsShown;
return orig(self);
if (currentPantheon == null) return;

if (IsMenuTitleScene()) return;
if (ResourcesLoader.Instance.canvas) ResourcesLoader.Instance.Destroy();
ResourcesLoader.Instance.BuildMenus(currentPantheon);
}

public MenuScreen GetMenuScreen(MenuScreen modListMenu, ModToggleDelegates? toggle)
{
var menu = ModMenu.CreateMenuScreen(modListMenu, toggle);
ModMenu.RefreshOptions();
var menu = ModMenu.GetMenu(modListMenu, toggle);
return menu;
}

public void Unload()
{
ModHooks.SavegameLoadHook -= LoadPBs;
On.QuitToMenu.Start -= OnQuitToMenu;
ModHooks.BeforeSceneLoadHook -= OnSceneLoad;
ModHooks.TakeHealthHook -= OnHitTaken;
ModHooks.HeroUpdateHook -= OnHeroUpdate;
On.BossSequenceDoor.Start -= OnRandomizedPantheon;
On.UIManager.ShowMenu -= ReorderButtons;

ResourcesLoader.Instance.Destroy();
}
}
}
36 changes: 17 additions & 19 deletions PantheonsHitCounter/PantheonsHitCounter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PantheonsHitCounter</RootNamespace>
<AssemblyName>PantheonsHitCounter</AssemblyName>
<HollowKnightModsDirectory>..\..\HollowKnightData</HollowKnightModsDirectory>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand All @@ -33,47 +34,50 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="MMHOOK_Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\MMHOOK_Assembly-CSharp.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\MMHOOK_Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Newtonsoft.Json.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Satchel, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(HollowKnightModsDirectory)\Managed\Mods\Satchel\Satchel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Plugins\x86_64\System.Windows.Forms.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Plugins\x86_64\System.Windows.Forms.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.UIElementsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIElementsNativeModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.UIElementsNativeModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.UIElementsNativeModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\..\Jeux\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\UnityEngine.UIModule.dll</HintPath>
<HintPath>$(HollowKnightModsDirectory)\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -96,12 +100,6 @@
<ItemGroup>
<EmbeddedResource Include="UI\Images\*.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit 5b1abf7

Please sign in to comment.