Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
KYPremco committed Jan 21, 2024
2 parents 456db2f + 260755b commit 4ca2a85
Show file tree
Hide file tree
Showing 27 changed files with 189 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using TimberApi.Core.LoggingSystem;
using TimberApi.Core.ModLoaderSystem;
using TimberApi.HarmonyPatcherSystem;
using TimberApi.SceneSystem;

namespace TimberApi.Core.BootstrapSystem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using Bindito.Unity;
using TimberApi.Common.ConsoleSystem;
using TimberApi.Common.Helpers;
using TimberApi.Common.LoggingSystem;
using TimberApi.ConsoleSystem;
using Timberborn.InputSystem;
using UnityEngine;
using UnityEngine.UIElements;

namespace TimberApi.Core.ConsoleSystem
{
Expand Down
2 changes: 0 additions & 2 deletions Core/TimberApi/AssetSystem/AssetLoader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Diagnostics;
using System.Linq;
using TimberApi.AssetSystem.Exceptions;
using TimberApi.ShaderSystem;
using Timberborn.Persistence;
using Timberborn.SingletonSystem;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;

namespace TimberApi.AssetSystem
Expand Down
1 change: 0 additions & 1 deletion Core/TimberApi/BottomBarSystem/BottomBarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using TimberApi.Common.SingletonSystem;
using TimberApi.ToolGroupSystem;
using TimberApi.ToolSystem;
using Timberborn.SingletonSystem;

namespace TimberApi.BottomBarSystem
{
Expand Down
2 changes: 0 additions & 2 deletions Core/TimberApi/BottomBarSystem/Patchers/ToolButtonPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using HarmonyLib;
using TimberApi.HarmonyPatcherSystem;
using TimberApi.SceneSystem;
using Timberborn.BuilderPrioritySystemUI;
using Timberborn.ToolSystem;
using UnityEngine;

namespace TimberApi.BottomBarSystem.Patchers
{
Expand Down
38 changes: 14 additions & 24 deletions Core/TimberApi/BottomBarSystem/Patchers/ToolGroupButtonPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
using TimberApi.HarmonyPatcherSystem;
using TimberApi.SceneSystem;
using TimberApi.ToolGroupSystem;
using TimberApi.ToolSystem;
using Timberborn.Common;
using Timberborn.CoreUI;
using Timberborn.CursorToolSystem;
using Timberborn.Debugging;
using Timberborn.ToolSystem;
using UnityEngine;
using UnityEngine.UIElements;

namespace TimberApi.BottomBarSystem.Patchers
Expand All @@ -20,26 +24,22 @@ public class ToolGroupButtonPatcher : BaseHarmonyPatcher, ITimberApiLoadableSing

private static BottomBarService _bottomBarService = null!;

private static DevModeManager _devModeManager = null!;

private static readonly string ActiveClassName = "button--active";

public override string UniqueId => "TimberApi.ToolGroupButton";

public void Load()
{
_bottomBarService = DependencyContainer.GetInstance<BottomBarService>();
_devModeManager = DependencyContainer.GetInstance<DevModeManager>();
_toolGroupService = DependencyContainer.GetInstance<ToolGroupService>();
}

public override void Apply(Harmony harmony)
{

harmony.Patch(
GetMethodInfo<ToolButtonService>(nameof(ToolButtonService.Add), new Type[] { typeof(ToolButton) }),
GetHarmonyMethod(nameof(AddPatch)));

harmony.Patch(
AccessTools.PropertyGetter(typeof(ToolGroupButton), nameof(ToolGroupButton.IsVisible)),
GetHarmonyMethod(nameof(ContainsToolPatch))
Expand All @@ -55,31 +55,21 @@ public override void Apply(Harmony harmony)
GetHarmonyMethod(nameof(OnToolGroupExited))
);
}

public static bool AddPatch(ToolButton toolButton, ToolButtonService __instance)
{
if(toolButton.Tool?.Default == true)
__instance._toolButtons.Add(toolButton);

if (toolButton.Tool.ToolGroup != null)
{
__instance._toolButtons.Insert(0, toolButton);
}
else
{
__instance._toolButtons.Insert(__instance._toolButtons.Count > 0 ? 1 : 0, toolButton);
return false;
}
if (toolButton.Tool?.ToolGroup == null)

if (toolButton.Tool is not IUnselectableTool && toolButton.Tool is not CursorTool)
{
if (toolButton.Root.Q<VisualElement>("ToolImage")?.style.backgroundImage.ToString() != "Options (UnityEngine.Sprite)")
{
if (toolButton.Tool?.Default == true)
{
__instance._rootButtons.Insert(0, toolButton);
}
else
{
__instance._rootButtons.Insert(1, toolButton);
}
}
__instance._rootButtons.Add(toolButton);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using TimberApi.HarmonyPatcherSystem;
using Timberborn.ToolSystem;

namespace TimberApi.BottomBarSystem.Patchers
{
public class ToolbarButtonRetrieverPatcher : BaseHarmonyPatcher
{
public override string UniqueId => "TimberApi.ToolButtonRetriever";

public override void Apply(Harmony harmony)
{
harmony.Patch(
GetMethodInfo<ToolbarButtonRetriever>(nameof(ToolbarButtonRetriever.TryGetPreviousVisibleButton)),
GetHarmonyMethod(nameof(TryGetPreviousVisibleButtonPatch))
);
}

public static bool TryGetPreviousVisibleButtonPatch(IEnumerable<IToolbarButton> buttons, out IToolbarButton? previousButton)
{
previousButton = null;
return buttons.Any(button => button.IsVisible);
}
}
}
1 change: 0 additions & 1 deletion Core/TimberApi/LocalizationSystem/LocalizationFetcher.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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using UnityEngine;

namespace TimberApi.SpecificationSystem.SpecificationTypes
{
Expand Down
1 change: 0 additions & 1 deletion Core/TimberApi/ToolGroupSystem/ToolGroupService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using TimberApi.Common.SingletonSystem;
using Timberborn.Persistence;
using UnityEngine;

namespace TimberApi.ToolGroupSystem
{
Expand Down
13 changes: 12 additions & 1 deletion Core/TimberApi/ToolGroupUISystem/ToolGroupButtonFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using TimberApi.ToolGroupSystem;
using Timberborn.AssetSystem;
using Timberborn.CoreUI;
using Timberborn.Localization;
Expand Down Expand Up @@ -56,7 +57,7 @@ public ToolGroupButton Create(ToolGroup toolGroup, Sprite toolGroupImage, Sprite
visualElement.Q<VisualElement>("ToolButtons"),
visualElement.Q<VisualElement>("ToolGroupButtonWrapper"));
_eventBus.Register(toolGroupButton);
_toolButtonService.Add(toolGroupButton);
Add((IToolGroup)toolGroup, toolGroupButton);
return toolGroupButton;
}

Expand Down Expand Up @@ -84,5 +85,15 @@ private void OnButtonClick(VisualElement tooltip, ToolGroup toolGroup)
tooltip.parent.ToggleDisplayStyle(false);
}
}

private void Add(IToolGroup toolGroup, ToolGroupButton toolButton)
{
_toolButtonService._toolGroupButtons.Add(toolButton);

if (toolGroup.GroupId == null)
{
_toolButtonService._rootButtons.Add(toolButton);
}
}
}
}
7 changes: 7 additions & 0 deletions Core/TimberApi/ToolSystem/IUnselectableTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TimberApi.ToolSystem
{
public interface IUnselectableTool
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public BuilderPriorityToolFactory(TimberbornBuilderPriorityToolFactory builderPr

protected override Tool CreateTool(ToolSpecification toolSpecification, BuilderPriorityToolToolInformation toolInformation, ToolGroup? toolGroup)
{
return _builderPriorityToolFactory.Create(toolInformation.Priority);
var priorityTool = _builderPriorityToolFactory.Create(toolInformation.Priority);
priorityTool.ToolGroup = toolGroup;

return priorityTool;
}

protected override BuilderPriorityToolToolInformation DeserializeToolInformation(IObjectLoader objectLoader)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Timberborn.RecoveredGoodSystemUI;
using Timberborn.ToolSystem;

namespace TimberApi.ToolSystem.Tools.Demolishing
{
public class DeleteRubbleToolFactory : IToolFactory
{
public string Id => "DeleteRecoveredGoodStackTool";

private readonly RecoveredGoodStackDeletionTool _recoveredGoodStackDeletionTool;

public DeleteRubbleToolFactory(RecoveredGoodStackDeletionTool recoveredGoodStackDeletionTool)
{
_recoveredGoodStackDeletionTool = recoveredGoodStackDeletionTool;
}

public Tool Create(ToolSpecification toolSpecification, ToolGroup? toolGroup = null)
{
_recoveredGoodStackDeletionTool.Initialize(toolGroup);
return _recoveredGoodStackDeletionTool;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void Configure(IContainerDefinition containerDefinition)
containerDefinition.MultiBind<IToolFactory>().To<DemolishableSelectionToolFactory>().AsSingleton();
containerDefinition.MultiBind<IToolFactory>().To<EntityBlockObjectDeletionToolFactory>().AsSingleton();
containerDefinition.MultiBind<IToolFactory>().To<BuildingDeconstructionToolFactory>().AsSingleton();
containerDefinition.MultiBind<IToolFactory>().To<DeleteRubbleToolFactory>().AsSingleton();
containerDefinition.MultiBind<ISpecificationGenerator>().To<DemolishingToolGenerator>().AsSingleton();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public IEnumerable<ISpecification> Generate()
{
yield return CreateDemolishingToolGroup();
yield return DemolishableSelectionTool();
yield return DeleteRecoveredGoodStackTool();
yield return DemolishableUnselectionTool();
yield return BuildingDeconstructionTool();
yield return EntityBlockObjectDeletionTool();
Expand All @@ -24,7 +25,7 @@ private static GeneratedSpecification EntityBlockObjectDeletionTool()
GroupId = "Demolishing",
Type = "EntityBlockObjectDeletionTool",
Layout = "Default",
Order = 20,
Order = 30,
NameLocKey = "CAN NOT BE MODIFIED",
DescriptionLocKey = "CAN NOT BE MODIFIED",
Icon = "Sprites/BottomBar/DeleteObjectIcon",
Expand All @@ -34,6 +35,25 @@ private static GeneratedSpecification EntityBlockObjectDeletionTool()

return new GeneratedSpecification(json, "EntityBlockObjectDeletion", "ToolSpecification");
}

private static GeneratedSpecification DeleteRecoveredGoodStackTool()
{
var json = JsonConvert.SerializeObject(new
{
Id = "DeleteRecoveredGoodStack",
GroupId = "Demolishing",
Type = "DeleteRecoveredGoodStackTool",
Layout = "Default",
Order = 10,
NameLocKey = "CAN NOT BE MODIFIED",
DescriptionLocKey = "CAN NOT BE MODIFIED",
Icon = "Sprites/BottomBar/DeleteRecoveredGoodStackToolIcon",
DevMode = false,
Hidden = false,
});

return new GeneratedSpecification(json, "EntityBlockObjectDeletion", "ToolSpecification");
}

private static GeneratedSpecification BuildingDeconstructionTool()
{
Expand Down Expand Up @@ -62,7 +82,7 @@ private static GeneratedSpecification DemolishableSelectionTool()
GroupId = "Demolishing",
Type = "DemolishableSelectionTool",
Layout = "Default",
Order = 10,
Order = 20,
NameLocKey = "CAN NOT BE MODIFIED",
DescriptionLocKey = "CAN NOT BE MODIFIED",
Icon = "Sprites/BottomBar/DemolishResourcesTool",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace TimberApi.ToolSystem.Tools.SettingBox
{
public class SettingBoxTool : Tool
public class SettingBoxTool : Tool, IUnselectableTool
{
private readonly ToolGroupManager _toolGroupManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public TreeCuttingAreaSelectionToolFactory(TreeCuttingAreaSelectionTool treeCutt

public Tool Create(ToolSpecification toolSpecification, ToolGroup? toolGroup = null)
{
_treeCuttingAreaSelectionTool.ToolGroup = toolGroup;

return _treeCuttingAreaSelectionTool;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public TreeCuttingAreaUnselectionToolFactory(TreeCuttingAreaUnselectionTool tree

public Tool Create(ToolSpecification toolSpecification, ToolGroup? toolGroup = null)
{
_treeCuttingAreaUnselectionTool.ToolGroup = toolGroup;

return _treeCuttingAreaUnselectionTool;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Bindito.Core;
using TimberApi.ConfiguratorSystem;
using TimberApi.SceneSystem;
using TimberApi.SpecificationSystem;

namespace TimberApi.ToolSystem.Tools.WaterGenerator
{
[Configurator(SceneEntrypoint.InGame)]
public class WaterGeneratorToolConfigurator : IConfigurator
{
public void Configure(IContainerDefinition containerDefinition)
{
containerDefinition.MultiBind<IToolFactory>().To<WaterGeneratorToolFactory>().AsSingleton();
containerDefinition.MultiBind<ISpecificationGenerator>().To<WaterGeneratorToolGenerator>().AsSingleton();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Timberborn.ToolSystem;
using Timberborn.WaterBrushesUI;

namespace TimberApi.ToolSystem.Tools.WaterGenerator
{
public class WaterGeneratorToolFactory : IToolFactory
{
public string Id => "WaterGeneratorTool";

private readonly WaterHeightBrushTool _waterHeightBrushTool;

public WaterGeneratorToolFactory(WaterHeightBrushTool waterHeightBrushTool)
{
_waterHeightBrushTool = waterHeightBrushTool;
}

public Tool Create(ToolSpecification toolSpecification, ToolGroup? toolGroup = null)
{
_waterHeightBrushTool.ToolGroup = toolGroup;
return _waterHeightBrushTool;
}
}
}
Loading

0 comments on commit 4ca2a85

Please sign in to comment.