Skip to content

Commit

Permalink
Add compatibility for Afterlife Overhaul
Browse files Browse the repository at this point in the history
Requires to edit ModAgent within Afterlife!
  • Loading branch information
mgreter committed Sep 20, 2024
1 parent 75c6335 commit d17f9c7
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 16 deletions.
1 change: 1 addition & 0 deletions 00-CompileModule.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

call 10-CompileVanilla.bat %*
call 11-CompileSmxCompat.bat %*
call 12-CompileAlCompat.bat %*
1 change: 1 addition & 0 deletions 01-CreateRelease.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

call 20-PackageVanilla.bat %*
call 21-PackageSmxCompat.bat %*
call 22-PackageAlCompat.bat %*
13 changes: 13 additions & 0 deletions 12-CompileAlCompat.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off

call MC7D2D AlCompat\InventoryMouseWheel.dll ^
/reference:"%PATH_7D2D_MANAGED%\NGUI.dll" ^
/reference:"%PATH_7D2D_MANAGED%\Assembly-CSharp.dll" ^
/reference:"%PATH_7D2D_MANAGED%\Afterlife.dll" ^
/reference:"%PATH_7D2D_MANAGED%\Quartz.dll" ^
Harmony\*.cs AlCompat\*.cs && ^
echo Successfully compiled AlCompat\InventoryMouseWheel.dll

SET RV=%ERRORLEVEL%
if "%CI%"=="" pause
exit /B %RV%
40 changes: 40 additions & 0 deletions 22-PackageAlCompat.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@echo off

SET NAME=OcbInventoryMouseWheelAL

if not exist build\ (
mkdir build
)

if exist build\%NAME%\ (
echo remove existing directory
rmdir build\%NAME% /S /Q
)

mkdir build\%NAME%

SET VERSION=snapshot

if not "%1"=="" (
SET VERSION=%1
)

echo create %VERSION%

xcopy *.xml build\%NAME%\
xcopy *.md build\%NAME%\
xcopy AlCompat\*.dll build\%NAME%\
xcopy Config build\%NAME%\Config\ /S
xcopy Resources build\%NAME%\Resources\ /S
xcopy UIAtlases build\%NAME%\UIAtlases\ /S

powershell -Command "(gc -encoding UTF8 build\%NAME%\ModInfo.xml) -replace '\"OcbInventoryMouseWheel\"', '\"OcbInventoryMouseWheelAL\"' | Out-File -encoding UTF8 build\%NAME%\ModInfo.xml"

cd build
echo Packaging %NAME%-%VERSION%.zip
powershell Compress-Archive %NAME% %NAME%-%VERSION%.zip -Force
cd ..

SET RV=%ERRORLEVEL%
if "%CI%"=="" pause
exit /B %RV%
Binary file added AlCompat/InventoryMouseWheel.dll
Binary file not shown.
84 changes: 84 additions & 0 deletions AlCompat/XUiC_AL_ItemStack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Audio;
using System;
using UnityEngine;

public class XUiC_AL_WheelItemStack : AL.UI.XUiC_AL_ItemStack
{

protected bool IsOver = false;

public override void Init()
{
base.Init();
}

private ItemStack DnDStack => xui.dragAndDrop.CurrentStack;

private void SetSlot(ItemStack stack) => ItemStack = stack;

private void SetDnD(ItemStack stack) => xui.dragAndDrop.CurrentStack = stack;

static bool IsShiftPressed => Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

protected virtual int TransferItems(int amount,
ItemStack src, Action<ItemStack> setSrc,
ItemStack dst, Action<ItemStack> setDst)
{
if (IsShiftPressed) amount *= 10;
if (WheelItemStack.TransferItems(amount, src, setSrc, dst, setDst) > 0)
{
// Copied from vanilla
ForceRefreshItemStack();
IsDirty = true;
Selected = false;
HandleClickComplete();
xui.calloutWindow.UpdateCalloutsForItemStack(
ViewComponent.UiTransform.gameObject,
ItemStack, IsOver);
if (placeSound != null) Manager.
PlayXUiSound(placeSound, 0.1f);
}
// Return how much was transfered
return amount;
}

public override void OnHovered(bool _isOver)
{
IsOver = _isOver;
base.OnHovered(_isOver);
}

public override void OnScrolled(float _delta)
{
// Process the item transfer
if (IsLocked || StackLock)
{
base.OnScrolled(_delta);
}
// Do nothing if the cursor is currently locked
// Happens when cursors stay over toolbar when backpack is closed
else if (Cursor.lockState != CursorLockMode.None)
{
base.OnScrolled(_delta);
}
else if (_delta > 0.0)
{
TransferItems(
(int)(_delta * 10),
DnDStack, SetDnD,
itemStack, SetSlot);
}
else if (_delta < 0.0)
{
TransferItems(
(int)(_delta * -10),
itemStack, SetSlot,
DnDStack, SetDnD);
}
else
{
base.OnScrolled(_delta);
}
}

}
78 changes: 78 additions & 0 deletions AlCompat/XUiC_AL_RequiredItemStack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Audio;
using System;
using UnityEngine;

public class XUiC_AL_WheelRequiredItemStack : AL.UI.XUiC_AL_RequiredItemStack
{

protected bool IsOver = false;

private ItemStack DnDStack => xui.dragAndDrop.CurrentStack;

private void SetSlot(ItemStack stack) => ItemStack = stack;

private void SetDnD(ItemStack stack) => xui.dragAndDrop.CurrentStack = stack;

static bool IsShiftPressed => Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

protected virtual int TransferItems(int amount,
ItemStack src, Action<ItemStack> setSrc,
ItemStack dst, Action<ItemStack> setDst)
{
if (IsShiftPressed) amount *= 10;
if (WheelItemStack.TransferItems(amount, src, setSrc, dst, setDst) > 0)
{
// Copied from vanilla
ForceRefreshItemStack();
IsDirty = true;
Selected = false;
HandleClickComplete();
xui.calloutWindow.UpdateCalloutsForItemStack(
ViewComponent.UiTransform.gameObject,
ItemStack, IsOver);
if (placeSound != null) Manager.
PlayXUiSound(placeSound, 0.1f);
}
// Return how much was transfered
return amount;
}

public override void OnHovered(bool _isOver)
{
IsOver = _isOver;
base.OnHovered(_isOver);
}

public override void OnScrolled(float _delta)
{
// Process the item transfer
if (IsLocked || StackLock)
{
base.OnScrolled(_delta);
}
// Do nothing if the cursor is currently locked
// Happens when cursors stay over toolbar when backpack is closed
else if (Cursor.lockState != CursorLockMode.None)
{
base.OnScrolled(_delta);
}
else if (_delta > 0.0 && !TakeOnly && CanSwap(DnDStack))
{
TransferItems(
(int)(_delta * 10),
DnDStack, SetDnD,
itemStack, SetSlot);
}
else if (_delta < 0.0 && (DnDStack.IsEmpty() || CanSwap(DnDStack)))
{
TransferItems(
(int)(_delta * -10),
itemStack, SetSlot,
DnDStack, SetDnD);
}
else
{
base.OnScrolled(_delta);
}
}
}
18 changes: 10 additions & 8 deletions Config/XUi/controls.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<configs patcher-version="7">
<modif condition="xpath:/controls/item_stack">
<echo log="OcbInventoryMouseWheel: Patching Vanilla item stack"/>
<setattribute xpath="/controls/item_stack" name="on_scroll">true</setattribute>
<setattribute xpath="/controls/item_stack" name="controller">WheelItemStack, InventoryMouseWheel</setattribute>
<!-- Afterlife compatibility -->
<modif condition="xpath:/controls//*[@controller='AL.UI.AL_ItemStack\,Afterlife']">
<echo log="OcbInventoryMouseWheel: Patching Afterlife item stack"/>
<setattribute xpath="/controls//*[@controller='AL.UI.AL_ItemStack,Afterlife']" name="on_scroll">true</setattribute>
<setattribute xpath="/controls//*[@controller='AL.UI.AL_ItemStack,Afterlife']" name="controller">AL_WheelItemStack, InventoryMouseWheel</setattribute>
</modif>

<modif condition="xpath:/controls/backpack_item_stack">
<echo log="OcbInventoryMouseWheel: Patching Vanilla backpack stack"/>
<setattribute xpath="/controls/backpack_item_stack" name="on_scroll">true</setattribute>
<setattribute xpath="/controls/backpack_item_stack" name="controller">WheelItemStack, InventoryMouseWheel</setattribute>
<!-- Vanilla compatibility -->
<modif condition="xpath:/controls/*[@controller='ItemStack']">
<echo log="OcbInventoryMouseWheel: Patching Vanilla item stack"/>
<setattribute xpath="/controls/*[@controller='ItemStack']" name="on_scroll">true</setattribute>
<setattribute xpath="/controls/*[@controller='ItemStack']" name="controller">WheelItemStack, InventoryMouseWheel</setattribute>
</modif>

<!-- SMX UI compatibility -->
Expand Down
11 changes: 8 additions & 3 deletions Config/XUi/windows.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<configs patcher-version="7">
<modif condition="xpath:/windows//item_stack[@controller='RequiredItemStack']">
<modif condition="xpath:/windows//*[@controller='AL.UI.AL_RequiredItemStack\,Afterlife']">
<echo log="OcbInventoryMouseWheel: Patching Afterlife required item stack"/>
<setattribute xpath="/windows//*[@controller='AL.UI.AL_RequiredItemStack,Afterlife']" name="on_scroll">true</setattribute>
<setattribute xpath="/windows//*[@controller='AL.UI.AL_RequiredItemStack,Afterlife']" name="controller">AL_WheelRequiredItemStack, InventoryMouseWheel</setattribute>
</modif>
<modif condition="xpath:/windows//*[@controller='RequiredItemStack']">
<echo log="OcbInventoryMouseWheel: Patching Vanilla required item stack"/>
<setattribute xpath="/windows//item_stack[@controller='RequiredItemStack']" name="on_scroll">true</setattribute>
<setattribute xpath="/windows//item_stack[@controller='RequiredItemStack']" name="controller">WheelRequiredItemStack, InventoryMouseWheel</setattribute>
<setattribute xpath="/windows//*[@controller='RequiredItemStack']" name="on_scroll">true</setattribute>
<setattribute xpath="/windows//*[@controller='RequiredItemStack']" name="controller">WheelRequiredItemStack, InventoryMouseWheel</setattribute>
</modif>
</configs>
2 changes: 2 additions & 0 deletions Harmony/InventoryMouseWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ static void Postfix(ref List<Mod> __result)
{
switch (__result[i].Name)
{
case "Afterlife":
case "Khaines60BBM":
case "Khaines96BBM":
case "Z_Ravenhearst_ResizedBackpack":
depPos = Mathf.Max(depPos, i + 1);
break;
case "OcbInventoryMouseWheel":
case "OcbInventoryMouseWheelAL":
case "OcbInventoryMouseWheelSMX":
myPos = i;
break;
Expand Down
5 changes: 1 addition & 4 deletions InventoryMouseWheel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>InventoryMouseWheel</RootNamespace>
<AssemblyName>InventoryMouseWheel</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
Expand Down Expand Up @@ -78,9 +78,6 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(PATH_7D2D_MANAGED)\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="Quartz">
<HintPath>..\SMXcore\Quartz.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Harmony\AssemblyInfo.cs" />
Expand Down
Binary file modified InventoryMouseWheel.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="Use mouse scroll wheel to move inventory items." />
<Website value="https://github.com/OCB7D2D/OcbInventoryMouseWheel" />
<Author value="ocbMaurice" />
<Version value="0.3.1" />
<Version value="0.3.2" />
</xml>
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Only clone or download the repo if you know what you do!

## Changelog

### Version 0.3.2

- Enable pressing shift to take 10 items
- Add compatibility for Afterlife Overhaul

### Version 0.3.1

- Fix XML-Patcher for V1 compatibility
Expand Down
Binary file modified SmxCompat/InventoryMouseWheel.dll
Binary file not shown.

0 comments on commit d17f9c7

Please sign in to comment.