Skip to content

Commit

Permalink
Fixes for 0.5.3.0 (#92)
Browse files Browse the repository at this point in the history
* Fixes for 0.5.3

* Added to changelog

* Almost fixed ctrl scrolling
  • Loading branch information
hytonhan authored Nov 15, 2023
1 parent f88e283 commit e8df737
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Core/TimberApi.Common/TimberApi.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Timberborn.GameLibs" Version="0.5.2-r.0" />
<PackageReference Update="Timberborn.GameLibs" Version="0.5.3-r.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Core/TimberApi.Core/TimberApi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Timberborn.GameLibs" Version="0.5.2-r.0" />
<PackageReference Update="Timberborn.GameLibs" Version="0.5.3-r.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ToolButtonPatcher : BaseHarmonyPatcher
public override void Apply(Harmony harmony)
{
harmony.Patch(
GetMethodInfo<ToolButton>(nameof(ToolButton.OnButtonClicked)),
GetMethodInfo<ToolButton>(nameof(ToolButton.Select)),
prefix: GetHarmonyMethod(nameof(OnButtonClickedPatch))
);
}
Expand Down
38 changes: 36 additions & 2 deletions Core/TimberApi/BottomBarSystem/Patchers/ToolGroupButtonPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using TimberApi.Common.SingletonSystem;
Expand Down Expand Up @@ -33,8 +35,13 @@ public void Load()

public override void Apply(Harmony harmony)
{

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

harmony.Patch(
GetMethodInfo<ToolGroupButton>(nameof(ToolGroupButton.ContainsTool)),
AccessTools.PropertyGetter(typeof(ToolGroupButton), nameof(ToolGroupButton.IsVisible)),
GetHarmonyMethod(nameof(ContainsToolPatch))
);

Expand All @@ -49,6 +56,33 @@ public override void Apply(Harmony harmony)
);
}

public static bool AddPatch(ToolButton toolButton, ToolButtonService __instance)
{
if(toolButton.Tool?.Default == true)
{
__instance._toolButtons.Insert(0, toolButton);
}
else
{
__instance._toolButtons.Insert(__instance._toolButtons.Count > 0 ? 1 : 0, toolButton);
}
if (toolButton.Tool?.ToolGroup == null)
{
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);
}
}
}
return false;
}

public override bool ShouldApply(SceneEntrypoint? sceneEntrypoint)
{
return sceneEntrypoint == SceneEntrypoint.InGame;
Expand All @@ -71,7 +105,7 @@ public static bool ContainsToolPatch(ref bool __result, ToolGroup ____toolGroup,

__result = _toolGroupService
.GetToolGroupButtonByGroupId(apiToolGroup.Id)
.Any(button => button.ContainsTool());
.Any(button => button.IsVisible);

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static void SwitchToolGroupPatch(ToolGroup? toolGroup, ToolGroupManager _
{
return;
}

____eventBus.Post(new ToolGroupExitedEvent(__instance.ActiveToolGroup));

__instance.ActiveToolGroup = ExitingToolGroup;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/TimberApi/TimberApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Timberborn.GameLibs" Version="0.5.2-r.0" />
<PackageReference Update="Timberborn.GameLibs" Version="0.5.3-r.1" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion Core/TimberApi/ToolGroupSystem/ToolGroupService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void LateLoad()

var toolGroupButtons = new Dictionary<string, ToolGroupButton>();

foreach (var toolGroupSpecification in _toolGroupSpecificationService.ToolGroupSpecifications)
foreach (var toolGroupSpecification in _toolGroupSpecificationService.ToolGroupSpecifications.OrderBy(x => x.Layout).ThenBy(x => x.Order))
{
var toolGroup = _toolGroupFactoryService.Get(toolGroupSpecification.Type).Create(toolGroupSpecification);

Expand Down
7 changes: 6 additions & 1 deletion Core/TimberApi/ToolGroupUISystem/ToolGroupButtonFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public ToolGroupButton Create(ToolGroup toolGroup, Sprite toolGroupImage, Sprite
var visualElement = _visualElementLoader.LoadVisualElement("Common/BottomBar/ToolGroupButton");
visualElement.Q<VisualElement>("ToolGroupButtonWrapper").Q<VisualElement>("").style.backgroundImage = new StyleBackground(backgroundImage);
InitializeElement(visualElement, toolGroup, toolGroupImage);
var toolGroupButton = new ToolGroupButton(_loc, toolGroup, visualElement, visualElement.Q<VisualElement>("ToolButtons"), visualElement.Q<VisualElement>("ToolGroupButtonWrapper"));
var toolGroupButton = new ToolGroupButton(_loc,
_toolGroupManager,
toolGroup,
visualElement,
visualElement.Q<VisualElement>("ToolButtons"),
visualElement.Q<VisualElement>("ToolGroupButtonWrapper"));
_eventBus.Register(toolGroupButton);
_toolButtonService.Add(toolGroupButton);
return toolGroupButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class PlaceableObjectToolFactory : BaseToolFactory<PlaceableObjectToolToo

private readonly UISoundController _uiSoundController;

private readonly BlockObjectUnlockerService _blockObjectUnlockerService;

public PlaceableObjectToolFactory(
ObjectCollectionService objectCollectionService,
BlockObjectToolDescriber blockObjectToolDescriber,
Expand All @@ -38,7 +40,8 @@ public PlaceableObjectToolFactory(
PreviewPlacerFactory previewPlacerFactory,
UISoundController uiSoundController,
BlockObjectPlacerService blockObjectPlacerService,
MapEditorMode mapEditorMode)
MapEditorMode mapEditorMode,
BlockObjectUnlockerService blockObjectUnlockerService)
{
_objectCollectionService = objectCollectionService;
_blockObjectToolDescriber = blockObjectToolDescriber;
Expand All @@ -48,6 +51,7 @@ public PlaceableObjectToolFactory(
_uiSoundController = uiSoundController;
_blockObjectPlacerService = blockObjectPlacerService;
_mapEditorMode = mapEditorMode;
_blockObjectUnlockerService = blockObjectUnlockerService;
}

public override string Id => "PlaceableObjectTool";
Expand All @@ -60,7 +64,15 @@ protected override Tool CreateTool(ToolSpecification toolSpecification, Placeabl
placeableBlockObject._devModeTool = toolSpecification.DevMode;
placeableBlockObject._toolOrder = toolSpecification.Order;

var blockObjectTool = new BlockObjectTool(_blockObjectToolDescriber, _inputService, _areaPickerFactory, _previewPlacerFactory, _uiSoundController, _blockObjectPlacerService, _mapEditorMode);
var blockObjectTool = new BlockObjectTool(
_blockObjectToolDescriber,
_inputService,
_areaPickerFactory,
_previewPlacerFactory,
_uiSoundController,
_blockObjectPlacerService,
_blockObjectUnlockerService,
_mapEditorMode);

if(toolGroup == null)
{
Expand Down
17 changes: 15 additions & 2 deletions Core/TimberApi/ToolSystem/Tools/Planting/PlantingToolFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using Timberborn.CoreUI;
using Timberborn.Localization;
using Timberborn.Persistence;
using Timberborn.Planting;
Expand All @@ -24,20 +25,24 @@ public class PlantingToolFactory : BaseToolFactory<PlantingToolToolInformation>

private readonly SelectionToolProcessorFactory _selectionToolProcessorFactory;

private readonly DialogBoxShower _dialogBoxShower;

public PlantingToolFactory(
PlantableDescriber plantableDescriber,
PlantingSelectionService plantingSelectionService,
DevModePlantableSpawner devModePlantableSpawner,
SelectionToolProcessorFactory selectionToolProcessorFactory,
ILoc loc,
ObjectCollectionService objectCollectionService)
ObjectCollectionService objectCollectionService,
DialogBoxShower dialogBoxShower)
{
_plantableDescriber = plantableDescriber;
_plantingSelectionService = plantingSelectionService;
_devModePlantableSpawner = devModePlantableSpawner;
_selectionToolProcessorFactory = selectionToolProcessorFactory;
_loc = loc;
_objectCollectionService = objectCollectionService;
_dialogBoxShower = dialogBoxShower;
}

public override string Id => "PlantingTool";
Expand All @@ -47,7 +52,15 @@ protected override Tool CreateTool(ToolSpecification toolSpecification, Planting
var prefab = _objectCollectionService.GetAllMonoBehaviours<Prefab>().First(o => o.IsNamedExactly(toolInformation.PrefabName));
var plantable = prefab.GetComponentFast<Plantable>();

return new PlantingTool(_plantableDescriber, _plantingSelectionService, _devModePlantableSpawner, _selectionToolProcessorFactory, plantable, GetPlanterBuildingName(plantable), toolGroup);
return new PlantingTool(
_plantableDescriber,
_plantingSelectionService,
_devModePlantableSpawner,
_loc,
_dialogBoxShower,
_selectionToolProcessorFactory,
plantable,
GetPlanterBuildingName(plantable), toolGroup);
}

protected override PlantingToolToolInformation DeserializeToolInformation(IObjectLoader objectLoader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Timberborn.GameLibs" Version="0.5.2-r.0" />
<PackageReference Update="Timberborn.GameLibs" Version="0.5.3-r.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="MonoMod.RuntimeDetour" Version="21.12.13.1" />
<PackageReference Include="UnityEngine" Version="5.6.1" />
<PackageReference Include="UnityEngine.Modules" Version="2022.1.6" />
<PackageReference Include="Timberborn.GameLibs" Version="0.5.2-r.0" Condition="$(UseLocalTimberbornSource) == false" />
<PackageReference Include="Timberborn.GameLibs" Version="0.5.3-r.1" Condition="$(UseLocalTimberbornSource) == false" />
</ItemGroup>

<!-- Import dll's from Timberborn's symlink in solution folder-->
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Unreleased
Updated gamelibs to v0.5.3.0 and fixes to make TimberAPI work with game version 0.5.3.0

### Changes
- Updated gamelibs to v0.5.3.0
- Fixes to make TimberAPI work with game version 0.5.3.0

## TimberAPI v0.6.2.1
Updated gamelibs to v0.5.2.0
Expand Down

0 comments on commit e8df737

Please sign in to comment.