[Enhancement] Unequip C-items (#6043)

This commit is contained in:
OtherBlue
2025-12-30 21:36:33 -03:00
committed by GitHub
parent 7d6a82be4f
commit c688923272
5 changed files with 108 additions and 6 deletions

View File

@@ -0,0 +1,83 @@
#include <libultraship/bridge.h>
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/ShipInit.hpp"
extern "C" {
#include "z64.h"
#include "functions.h"
#include "macros.h"
#include "variables.h"
#include "overlays/misc/ovl_kaleido_scope/z_kaleido_scope.h"
extern SaveContext gSaveContext;
}
#define CVAR_ITEM_UNEQUIP_NAME CVAR_ENHANCEMENT("ItemUnequip")
#define CVAR_ITEM_UNEQUIP_DEFAULT 0
#define CVAR_ITEM_UNEQUIP_VALUE CVarGetInteger(CVAR_ITEM_UNEQUIP_NAME, CVAR_ITEM_UNEQUIP_DEFAULT)
void RegisterItemUnequip() {
COND_VB_SHOULD(VB_EQUIP_ITEM_TO_C_BUTTON, CVAR_ITEM_UNEQUIP_VALUE, {
PlayState* play = va_arg(args, PlayState*);
u16 cursorSlot = va_arg(args, int);
u16 cursorItem = va_arg(args, int);
Input* input = &play->state.input[0];
int targetButton = -1;
if (CHECK_BTN_ALL(input->press.button, BTN_CLEFT)) {
targetButton = 1;
} else if (CHECK_BTN_ALL(input->press.button, BTN_CDOWN)) {
targetButton = 2;
} else if (CHECK_BTN_ALL(input->press.button, BTN_CRIGHT)) {
targetButton = 3;
} else if (CVarGetInteger(CVAR_ENHANCEMENT("DpadEquips"), 0)) {
if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) {
targetButton = 4;
} else if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) {
targetButton = 5;
} else if (CHECK_BTN_ALL(input->press.button, BTN_DLEFT)) {
targetButton = 6;
} else if (CHECK_BTN_ALL(input->press.button, BTN_DRIGHT)) {
targetButton = 7;
}
}
if (targetButton == -1) {
return;
}
u8 equippedItem = gSaveContext.equips.buttonItems[targetButton];
u8 equippedSlot = gSaveContext.equips.cButtonSlots[targetButton - 1];
bool shouldUnequip = false;
if (equippedItem == cursorItem) {
if (cursorItem >= ITEM_BOTTLE && cursorItem <= ITEM_POE) {
if (equippedSlot == cursorSlot) {
shouldUnequip = true;
}
} else {
shouldUnequip = true;
}
} else if (cursorItem == ITEM_ARROW_FIRE && equippedItem == ITEM_BOW_ARROW_FIRE) {
shouldUnequip = true;
} else if (cursorItem == ITEM_ARROW_ICE && equippedItem == ITEM_BOW_ARROW_ICE) {
shouldUnequip = true;
} else if (cursorItem == ITEM_ARROW_LIGHT && equippedItem == ITEM_BOW_ARROW_LIGHT) {
shouldUnequip = true;
}
if (shouldUnequip) {
gSaveContext.equips.buttonItems[targetButton] = ITEM_NONE;
gSaveContext.equips.cButtonSlots[targetButton - 1] = SLOT_NONE;
Interface_LoadItemIcon1(play, targetButton);
Audio_PlaySoundGeneral(NA_SE_SY_DECIDE, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
*should = false;
}
});
}
static RegisterShipInitFunc initFunc(RegisterItemUnequip, { CVAR_ITEM_UNEQUIP_NAME });

View File

@@ -2414,6 +2414,16 @@ typedef enum {
// - `*Color_RGB8`
VB_APPLY_TUNIC_COLOR,
// #### `result`
// ```c
// true
// ```
// #### `args`
// - `*PlayState`
// - `uint16_t` (cursorSlot - promoted from `u16`)
// - `uint16_t` (cursorItem - promoted from `u16`)
VB_EQUIP_ITEM_TO_C_BUTTON,
} GIVanillaBehavior;
#endif

View File

@@ -730,6 +730,10 @@ void SohMenu::AddMenuEnhancements() {
.Options(CheckboxOptions().Tooltip(
"Equip items and equipment on the D-pad. If used with \"D-pad on Pause Screen\", you must "
"hold C-Up to equip instead of navigate."));
AddWidget(path, "Unequip C-Items on Re-press", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_ENHANCEMENT("ItemUnequip"))
.Options(CheckboxOptions().Tooltip("Allows unequipping items from C-Buttons/D-pad by hovering over an equipped "
"item and pressing the button it's equipped to."));
AddWidget(path, "Assignable Shields, Tunics and Boots", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_ENHANCEMENT("AssignableTunicsAndBoots"))
.Options(CheckboxOptions().Tooltip("Allows equipping Shields, Tunics and Boots to C-Buttons/D-pad."));

View File

@@ -3,6 +3,7 @@
#include "textures/parameter_static/parameter_static.h"
#include "soh/Enhancements/cosmetics/cosmeticsTypes.h"
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
static u8 sChildUpgrades[] = { UPG_BULLET_BAG, UPG_BOMB_BAG, UPG_STRENGTH, UPG_SCALE };
static u8 sAdultUpgrades[] = { UPG_QUIVER, UPG_BOMB_BAG, UPG_STRENGTH, UPG_SCALE };
@@ -677,9 +678,11 @@ void KaleidoScope_DrawEquipment(PlayState* play) {
default:
break;
}
KaleidoScope_SetupItemEquip(play, cursorItem, slot,
pauseCtx->equipVtx[cursorSlot * 4].v.ob[0] * 10,
pauseCtx->equipVtx[cursorSlot * 4].v.ob[1] * 10);
if (GameInteractor_Should(VB_EQUIP_ITEM_TO_C_BUTTON, true, play, slot, cursorItem)) {
KaleidoScope_SetupItemEquip(play, cursorItem, slot,
pauseCtx->equipVtx[cursorSlot * 4].v.ob[0] * 10,
pauseCtx->equipVtx[cursorSlot * 4].v.ob[1] * 10);
}
} else {
Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);

View File

@@ -692,9 +692,11 @@ void KaleidoScope_DrawItemSelect(PlayState* play) {
if (CHECK_BTN_ANY(input->press.button, buttonsToCheck)) {
if (CHECK_AGE_REQ_SLOT(cursorSlot) && (cursorItem != ITEM_SOLD_OUT) &&
(cursorItem != ITEM_NONE)) {
KaleidoScope_SetupItemEquip(play, cursorItem, cursorSlot,
pauseCtx->itemVtx[index].v.ob[0] * 10,
pauseCtx->itemVtx[index].v.ob[1] * 10);
if (GameInteractor_Should(VB_EQUIP_ITEM_TO_C_BUTTON, true, play, cursorSlot, cursorItem)) {
KaleidoScope_SetupItemEquip(play, cursorItem, cursorSlot,
pauseCtx->itemVtx[index].v.ob[0] * 10,
pauseCtx->itemVtx[index].v.ob[1] * 10);
}
} else {
Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);