77using TimberApi . HarmonyPatcherSystem ;
88using TimberApi . SceneSystem ;
99using TimberApi . ToolGroupSystem ;
10+ using TimberApi . ToolSystem ;
11+ using Timberborn . Common ;
1012using Timberborn . CoreUI ;
13+ using Timberborn . CursorToolSystem ;
1114using Timberborn . Debugging ;
1215using Timberborn . ToolSystem ;
16+ using UnityEngine ;
1317using UnityEngine . UIElements ;
1418
1519namespace TimberApi . BottomBarSystem . Patchers
@@ -20,26 +24,22 @@ public class ToolGroupButtonPatcher : BaseHarmonyPatcher, ITimberApiLoadableSing
2024
2125 private static BottomBarService _bottomBarService = null ! ;
2226
23- private static DevModeManager _devModeManager = null ! ;
24-
2527 private static readonly string ActiveClassName = "button--active" ;
2628
2729 public override string UniqueId => "TimberApi.ToolGroupButton" ;
2830
2931 public void Load ( )
3032 {
3133 _bottomBarService = DependencyContainer . GetInstance < BottomBarService > ( ) ;
32- _devModeManager = DependencyContainer . GetInstance < DevModeManager > ( ) ;
3334 _toolGroupService = DependencyContainer . GetInstance < ToolGroupService > ( ) ;
3435 }
3536
3637 public override void Apply ( Harmony harmony )
3738 {
38-
3939 harmony . Patch (
4040 GetMethodInfo < ToolButtonService > ( nameof ( ToolButtonService . Add ) , new Type [ ] { typeof ( ToolButton ) } ) ,
4141 GetHarmonyMethod ( nameof ( AddPatch ) ) ) ;
42-
42+
4343 harmony . Patch (
4444 AccessTools . PropertyGetter ( typeof ( ToolGroupButton ) , nameof ( ToolGroupButton . IsVisible ) ) ,
4545 GetHarmonyMethod ( nameof ( ContainsToolPatch ) )
@@ -55,31 +55,21 @@ public override void Apply(Harmony harmony)
5555 GetHarmonyMethod ( nameof ( OnToolGroupExited ) )
5656 ) ;
5757 }
58-
58+
5959 public static bool AddPatch ( ToolButton toolButton , ToolButtonService __instance )
6060 {
61- if ( toolButton . Tool ? . Default == true )
61+ __instance . _toolButtons . Add ( toolButton ) ;
62+
63+ if ( toolButton . Tool . ToolGroup != null )
6264 {
63- __instance . _toolButtons . Insert ( 0 , toolButton ) ;
64- }
65- else
66- {
67- __instance . _toolButtons . Insert ( __instance . _toolButtons . Count > 0 ? 1 : 0 , toolButton ) ;
65+ return false ;
6866 }
69- if ( toolButton . Tool ? . ToolGroup == null )
67+
68+ if ( toolButton . Tool is not IUnselectableTool && toolButton . Tool is not CursorTool )
7069 {
71- if ( toolButton . Root . Q < VisualElement > ( "ToolImage" ) ? . style . backgroundImage . ToString ( ) != "Options (UnityEngine.Sprite)" )
72- {
73- if ( toolButton . Tool ? . Default == true )
74- {
75- __instance . _rootButtons . Insert ( 0 , toolButton ) ;
76- }
77- else
78- {
79- __instance . _rootButtons . Insert ( 1 , toolButton ) ;
80- }
81- }
70+ __instance . _rootButtons . Add ( toolButton ) ;
8271 }
72+
8373 return false ;
8474 }
8575
0 commit comments