-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inventory source option to the Inventory Space Indicator widget (F…
- Loading branch information
1 parent
e1da916
commit bdea1e1
Showing
12 changed files
with
181 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Umbra.Game.Inventory; | ||
|
||
public interface IPlayerInventory | ||
{ | ||
/// <summary> | ||
/// Returns the amount of occupied inventory space for the given inventory type. | ||
/// </summary> | ||
public uint GetOccupiedInventorySpace(PlayerInventoryType type); | ||
|
||
/// <summary> | ||
/// Returns the total amount of inventory space for the given inventory type. | ||
/// </summary> | ||
public uint GetTotalInventorySpace(PlayerInventoryType type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using FFXIVClientStructs.FFXIV.Client.Game; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Umbra.Common; | ||
|
||
namespace Umbra.Game.Inventory; | ||
|
||
[Service] | ||
internal class PlayerInventory : IPlayerInventory | ||
{ | ||
public uint GetOccupiedInventorySpace(PlayerInventoryType type) | ||
{ | ||
return GetInventoryTypes(type).Aggregate<InventoryType, uint>(0, (current, iType) => current + GetUsedSizeOf(iType)); | ||
} | ||
|
||
public uint GetTotalInventorySpace(PlayerInventoryType type) | ||
{ | ||
return GetInventoryTypes(type).Aggregate<InventoryType, uint>(0, (current, iType) => current + GetTotalSizeOf(iType)); | ||
} | ||
|
||
private static unsafe uint GetUsedSizeOf(InventoryType type) | ||
{ | ||
InventoryManager* im = InventoryManager.Instance(); | ||
InventoryContainer* inv = im->GetInventoryContainer(type); | ||
|
||
if (inv->Loaded == 0 || inv->Size == 0) return 0; | ||
|
||
uint usedSpace = 0; | ||
|
||
for (var i = 0; i <= inv->Size; i++) { | ||
var slot = inv->GetInventorySlot(i); | ||
if (slot == null) continue; | ||
if (slot->ItemId > 0) usedSpace++; | ||
} | ||
|
||
return usedSpace; | ||
} | ||
|
||
private static unsafe uint GetTotalSizeOf(InventoryType type) | ||
{ | ||
InventoryManager* im = InventoryManager.Instance(); | ||
InventoryContainer* inv = im->GetInventoryContainer(type); | ||
|
||
return inv->Loaded == 0 ? 0 : inv->Size; | ||
} | ||
|
||
private static IEnumerable<InventoryType> GetInventoryTypes(PlayerInventoryType type) | ||
{ | ||
return type switch | ||
{ | ||
PlayerInventoryType.Inventory => | ||
[ | ||
InventoryType.Inventory1, | ||
InventoryType.Inventory2, | ||
InventoryType.Inventory3, | ||
InventoryType.Inventory4 | ||
], | ||
PlayerInventoryType.Saddlebag => | ||
[ | ||
InventoryType.SaddleBag1, | ||
InventoryType.SaddleBag2, | ||
], | ||
PlayerInventoryType.SaddlebagPremium => | ||
[ | ||
InventoryType.SaddleBag1, | ||
InventoryType.SaddleBag2, | ||
InventoryType.PremiumSaddleBag1, | ||
InventoryType.PremiumSaddleBag2 | ||
], | ||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Umbra.Game.Inventory; | ||
|
||
public enum PlayerInventoryType | ||
{ | ||
Inventory, | ||
Saddlebag, | ||
SaddlebagPremium, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters