forked from OrekiWoof/ChestPreview
Compare commits
1 Commits
main
...
option-tog
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1121e4c67 |
@@ -21,4 +21,8 @@ public sealed class Config
|
|||||||
public string BlacklistedContainers { get; set; } = "";
|
public string BlacklistedContainers { get; set; } = "";
|
||||||
|
|
||||||
public bool GroundStorageOnlyContainers { get; set; } = true;
|
public bool GroundStorageOnlyContainers { get; set; } = true;
|
||||||
|
|
||||||
|
public bool TogglePreview { get; set; } = false;
|
||||||
|
|
||||||
|
public bool TogglePreviewNearby { get; set; } = false;
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,9 @@ public class ChestPreviewModSystem : ModSystem
|
|||||||
private StorageHoverHudRenderer? storageHoverHudRenderer;
|
private StorageHoverHudRenderer? storageHoverHudRenderer;
|
||||||
private WorldBillboardRenderer? worldBillboardRenderer;
|
private WorldBillboardRenderer? worldBillboardRenderer;
|
||||||
|
|
||||||
|
public bool PreviewNearbyToggleState { get; private set; } = false;
|
||||||
|
public bool PreviewToggleState { get; private set; } = false;
|
||||||
|
|
||||||
public override bool ShouldLoad(EnumAppSide forSide) => forSide is EnumAppSide.Client;
|
public override bool ShouldLoad(EnumAppSide forSide) => forSide is EnumAppSide.Client;
|
||||||
|
|
||||||
public override void StartClientSide(ICoreClientAPI api)
|
public override void StartClientSide(ICoreClientAPI api)
|
||||||
@@ -35,6 +38,24 @@ public class ChestPreviewModSystem : ModSystem
|
|||||||
|
|
||||||
worldBillboardRenderer = new WorldBillboardRenderer(api, config, cardRenderer);
|
worldBillboardRenderer = new WorldBillboardRenderer(api, config, cardRenderer);
|
||||||
api.Event.RegisterRenderer(worldBillboardRenderer, EnumRenderStage.AfterOIT, "chestpreview-world-billboard-preview");
|
api.Event.RegisterRenderer(worldBillboardRenderer, EnumRenderStage.AfterOIT, "chestpreview-world-billboard-preview");
|
||||||
|
|
||||||
|
api.Input.SetHotKeyHandler(
|
||||||
|
hotkeyCode: PREVIEW_CONTAINERS_HOTKEY_CODE,
|
||||||
|
keycomb =>
|
||||||
|
{
|
||||||
|
if (!config.TogglePreview) return false;
|
||||||
|
this.PreviewToggleState = !this.PreviewToggleState;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
api.Input.SetHotKeyHandler(
|
||||||
|
hotkeyCode: PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE,
|
||||||
|
keycomb =>
|
||||||
|
{
|
||||||
|
if (!config.TogglePreviewNearby) return false;
|
||||||
|
this.PreviewNearbyToggleState = !this.PreviewNearbyToggleState;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
|
|||||||
private readonly Config config = config;
|
private readonly Config config = config;
|
||||||
private readonly List<BlockEntity> nearbyContainerEntities = [];
|
private readonly List<BlockEntity> nearbyContainerEntities = [];
|
||||||
private float nearbyScanAccumulator;
|
private float nearbyScanAccumulator;
|
||||||
|
private Lazy<ChestPreviewModSystem> coreModSystem = new Lazy<ChestPreviewModSystem>(() => api.ModLoader.GetModSystem<ChestPreviewModSystem>());
|
||||||
|
|
||||||
public void CollectTargets(float deltaTime, List<PreviewTarget> targets)
|
public void CollectTargets(float deltaTime, List<PreviewTarget> targets)
|
||||||
{
|
{
|
||||||
@@ -83,13 +84,39 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
|
|||||||
|
|
||||||
private string GetActiveMode()
|
private string GetActiveMode()
|
||||||
{
|
{
|
||||||
if (IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE))
|
if (IsPreviewContainersNearbyActive())
|
||||||
return PreviewModes.ON_NEARBY_CONTAINERS;
|
return PreviewModes.ON_NEARBY_CONTAINERS;
|
||||||
|
|
||||||
if (config.HoldKey && !IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_HOTKEY_CODE))
|
return IsPreviewContainersActive() ? PreviewModes.Normalize(config.Mode) : PreviewModes.NONE;
|
||||||
return PreviewModes.NONE;
|
}
|
||||||
|
|
||||||
return PreviewModes.Normalize(config.Mode);
|
private bool IsPreviewContainersNearbyActive()
|
||||||
|
{
|
||||||
|
if (config.TogglePreviewNearby)
|
||||||
|
{
|
||||||
|
return coreModSystem.Value.PreviewNearbyToggleState;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsPreviewContainersActive()
|
||||||
|
{
|
||||||
|
if (config.TogglePreview)
|
||||||
|
{
|
||||||
|
return coreModSystem.Value.PreviewToggleState;
|
||||||
|
}
|
||||||
|
else if (config.HoldKey)
|
||||||
|
{
|
||||||
|
return IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_HOTKEY_CODE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Always
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsHotkeyHeld(string hotkeyCode)
|
private bool IsHotkeyHeld(string hotkeyCode)
|
||||||
|
|||||||
@@ -90,11 +90,25 @@
|
|||||||
"clientSide": true
|
"clientSide": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "GroundStorageOnlyContainers",
|
"code": "GroundStorageOnlyContainers",
|
||||||
"comment": "config-desc-GroundStorageOnlyContainers",
|
"comment": "config-desc-GroundStorageOnlyContainers",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"clientSide": true
|
"clientSide": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "TogglePreview",
|
||||||
|
"comment": "config-desc-TogglePreview",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"clientSide": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "TogglePreviewNearby",
|
||||||
|
"comment": "config-desc-TogglePreviewNearby",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"clientSide": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -10,5 +10,7 @@
|
|||||||
"config-desc-WhitelistedContainersOnly": "If true, only container codes in WhitelistedContainers are handled.",
|
"config-desc-WhitelistedContainersOnly": "If true, only container codes in WhitelistedContainers are handled.",
|
||||||
"config-desc-GroundStorageOnlyContainers": "If true, groundstorage previews only appear when the stored item has its own inventory (for example bags/backpacks).",
|
"config-desc-GroundStorageOnlyContainers": "If true, groundstorage previews only appear when the stored item has its own inventory (for example bags/backpacks).",
|
||||||
"config-desc-WhitelistedContainers": "Allowed container codes, separated by comma, semicolon, or spaces. No effectif WhitelistedContainersOnly==false.",
|
"config-desc-WhitelistedContainers": "Allowed container codes, separated by comma, semicolon, or spaces. No effectif WhitelistedContainersOnly==false.",
|
||||||
"config-desc-BlacklistedContainers": "Blocked container codes, separated by comma, semicolon, or spaces."
|
"config-desc-BlacklistedContainers": "Blocked container codes, separated by comma, semicolon, or spaces.",
|
||||||
|
"config-desc-TogglePreview": "If true, \"Preview container\" is toggled on/off with the key instead of being held. HoldKey will be ignored.",
|
||||||
|
"config-desc-TogglePreviewNearby": "If true, \"Preview containers nearby\" is toggled on/off with the key instead of being held. Note: Toggle may not work with modifier-only key combinations (e.g. Ctrl+Shift). You might need to reassign the hotkey."
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user