Add key bindings for advancing hotbar selected slot by one slot left or right, which is also bound to ZL and ZR on gamepad by default

This commit is contained in:
UnknownShadow200 2023-08-18 21:21:14 +10:00
parent f887954b5f
commit a9535fbd3f
6 changed files with 65 additions and 33 deletions

View File

@ -191,7 +191,7 @@ static void ClearTouches(void) { }
#define Pad_Names \
"PAD_A", "PAD_B", "PAD_X", "PAD_Y", "PAD_L", "PAD_R", \
"PAD_LEFT", "PAD_RIGHT", "PAD_UP", "PAD_DOWN", \
"PAD_START", "PAD_SELECT"
"PAD_START", "PAD_SELECT", "PAD_ZL", "PAD_ZR"
/* Names for each input button when stored to disc */
static const char* const storageNames[INPUT_COUNT] = {
@ -327,10 +327,14 @@ const cc_uint8 KeyBind_GamepadDefaults[KEYBIND_COUNT] = {
CCPAD_UP, CCPAD_DOWN, CCPAD_LEFT, CCPAD_RIGHT, /* Movement */
CCPAD_A, 0, CCPAD_START, CCPAD_Y, /* Jump, SetSpawn, OpenChat */
CCPAD_X, 0, CCPAD_START, 0, /* Inventory, EnterChat */
CCKEY_LSHIFT, 'X', 'Z', 'Q', 'E',
CCKEY_LSHIFT, 'X', 'Z', 'Q', 'E', /* Hacks */
0, 0, 0, 0,
CCKEY_F5, 0, 0, 0,
0, CCPAD_L, 0, CCPAD_R,
0, 0, 0,
0,0,0, 0,0,0,0,
0,0,0, 0,0,0, 0,0,0, /* Hotbar slots */
CCPAD_ZL, CCPAD_ZR
};
const cc_uint8 KeyBind_NormalDefaults[KEYBIND_COUNT] = {
'W', 'S', 'A', 'D',
@ -343,7 +347,8 @@ const cc_uint8 KeyBind_NormalDefaults[KEYBIND_COUNT] = {
CCKEY_F6, CCKEY_LALT, CCKEY_F8,
'G', CCKEY_F10, 0,
0, 0, 0, 0,
'1','2','3', '4','5','6', '7','8','9'
'1','2','3', '4','5','6', '7','8','9',
0, 0
};
static const char* const keybindNames[KEYBIND_COUNT] = {
@ -359,7 +364,8 @@ static const char* const keybindNames[KEYBIND_COUNT] = {
"LookUp", "LookDown", "LookRight", "LookLeft",
"Hotbar1", "Hotbar2", "Hotbar3",
"Hotbar4", "Hotbar5", "Horbar6",
"Hotbar7", "Hotbar8", "Hotbar9"
"Hotbar7", "Hotbar8", "Hotbar9",
"HotbarLeft", "HotbarRight"
};
cc_bool KeyBind_IsPressed(KeyBind binding) { return Input.Pressed[KeyBinds[binding]]; }

View File

@ -47,7 +47,7 @@ enum InputButtons {
CCPAD_A, CCPAD_B, CCPAD_X, CCPAD_Y, CCPAD_L, CCPAD_R,
CCPAD_LEFT, CCPAD_RIGHT, CCPAD_UP, CCPAD_DOWN,
CCPAD_START, CCPAD_SELECT,
CCPAD_START, CCPAD_SELECT, CCPAD_ZL, CCPAD_ZR,
INPUT_COUNT,
@ -154,6 +154,7 @@ enum KeyBind_ {
KEYBIND_HOTBAR_1, KEYBIND_HOTBAR_2, KEYBIND_HOTBAR_3,
KEYBIND_HOTBAR_4, KEYBIND_HOTBAR_5, KEYBIND_HOTBAR_6,
KEYBIND_HOTBAR_7, KEYBIND_HOTBAR_8, KEYBIND_HOTBAR_9,
KEYBIND_HOTBAR_LEFT, KEYBIND_HOTBAR_RIGHT,
KEYBIND_COUNT
};
typedef int KeyBind;

View File

@ -2082,11 +2082,12 @@ void MouseBindingsScreen_Show(void) {
*-------------------------------------------------HotbarBindingsScreen----------------------------------------------------*
*#########################################################################################################################*/
void HotbarBindingsScreen_Show(void) {
static const cc_uint8 binds[] = { KEYBIND_HOTBAR_1,KEYBIND_HOTBAR_2,KEYBIND_HOTBAR_3, KEYBIND_HOTBAR_4,KEYBIND_HOTBAR_5,KEYBIND_HOTBAR_6, KEYBIND_HOTBAR_7,KEYBIND_HOTBAR_8,KEYBIND_HOTBAR_9 };
static const char* const descs[] = { "Slot #1","Slot #2","Slot #3", "Slot #4","Slot #5","Slot #6", "Slot #7","Slot #8","Slot #9" };
static const cc_uint8 binds[] = { KEYBIND_HOTBAR_1,KEYBIND_HOTBAR_2,KEYBIND_HOTBAR_3, KEYBIND_HOTBAR_4,KEYBIND_HOTBAR_5,KEYBIND_HOTBAR_6, KEYBIND_HOTBAR_7,KEYBIND_HOTBAR_8,KEYBIND_HOTBAR_9,
KEYBIND_HOTBAR_LEFT, KEYBIND_HOTBAR_RIGHT };
static const char* const descs[] = { "Slot #1","Slot #2","Slot #3", "Slot #4","Slot #5","Slot #6", "Slot #7","Slot #8","Slot #9", "Slot left","Slot right" };
KeyBindsScreen_Reset(Menu_SwitchBindsMouse, NULL, 260);
KeyBindsScreen_SetLayout(-140, 10, 5);
KeyBindsScreen_SetLayout(-140, 10, 6);
KeyBindsScreen_Show(Array_Elems(binds), binds, descs, "Hotbar controls");
}

View File

@ -517,10 +517,27 @@ static int HotbarWidget_MapKey(int key) {
return -1;
}
static int HotbarWidget_CycleIndex(int dir) {
Inventory.SelectedIndex += dir;
if (Inventory.SelectedIndex < 0)
Inventory.SelectedIndex += INVENTORY_BLOCKS_PER_HOTBAR;
if (Inventory.SelectedIndex >= INVENTORY_BLOCKS_PER_HOTBAR)
Inventory.SelectedIndex -= INVENTORY_BLOCKS_PER_HOTBAR;
return true;
}
static int HotbarWidget_KeyDown(void* widget, int key) {
struct HotbarWidget* w = (struct HotbarWidget*)widget;
int index = HotbarWidget_MapKey(key);
if (index == -1) return false;
if (index == -1) {
if (key == KeyBinds[KEYBIND_HOTBAR_LEFT])
return HotbarWidget_CycleIndex(-1);
if (key == KeyBinds[KEYBIND_HOTBAR_RIGHT])
return HotbarWidget_CycleIndex(+1);
return false;
}
if (KeyBind_IsPressed(KEYBIND_HOTBAR_SWITCH)) {
/* Pick from first to ninth row */

View File

@ -92,6 +92,9 @@ static void HandleButtons_Game(u32 mods) {
Input_SetNonRepeatable(CCPAD_RIGHT, mods & KEY_DRIGHT);
Input_SetNonRepeatable(CCPAD_UP, mods & KEY_DUP);
Input_SetNonRepeatable(CCPAD_DOWN, mods & KEY_DDOWN);
Input_SetNonRepeatable(CCPAD_ZL, mods & KEY_ZL);
Input_SetNonRepeatable(CCPAD_ZR, mods & KEY_ZR);
}
static void HandleButtons_Launcher(u32 mods) {
@ -115,30 +118,7 @@ static void ProcessJoystickInput(circlePosition* pos, double delta) {
Event_RaiseRawMove(&PointerEvents.RawMoved, pos->dx * scale, -pos->dy * scale);
}
void Window_ProcessEvents(double delta) {
hidScanInput();
/* TODO implement */
if (!aptMainLoop()) {
Event_RaiseVoid(&WindowEvents.Closing);
WindowInfo.Exists = false;
return;
}
//u32 m1 = hidKeysDown(), m2 = hidKeysHeld();
//Platform_Log2("MODS: %h | %h", &m1, &m2);
// hidKeysDown hidKeysUp
//u32 mods = hidKeysDownRepeat();
u32 mods = hidKeysDown() | hidKeysHeld();
if (launcherMode) {
HandleButtons_Launcher(mods);
} else {
HandleButtons_Game(mods);
}
Input_SetNonRepeatable(CCMOUSE_L, mods & KEY_TOUCH);
static void ProcessTouchInput(int mods) {
touchPosition touch;
hidTouchRead(&touch);
touchActive = mods & KEY_TOUCH;
@ -154,6 +134,27 @@ void Window_ProcessEvents(double delta) {
touchBegX = touch.px;
touchBegY = touch.py;
}
}
void Window_ProcessEvents(double delta) {
hidScanInput();
/* TODO implement */
if (!aptMainLoop()) {
Event_RaiseVoid(&WindowEvents.Closing);
WindowInfo.Exists = false;
return;
}
u32 mods = hidKeysDown() | hidKeysHeld();
if (launcherMode) {
HandleButtons_Launcher(mods);
} else {
HandleButtons_Game(mods);
}
Input_SetNonRepeatable(CCMOUSE_L, mods & KEY_TOUCH);
ProcessTouchInput(mods);
if (Input.RawMode) {
circlePosition pos;

View File

@ -162,6 +162,7 @@ static void ProcessPADInput(double delta) {
PADStatus pads[4];
PAD_Read(pads);
int error = pads[0].err;
if (error == 0) {
gc_pad = pads[0]; // new state arrived
} else if (error == PAD_ERR_TRANSFER) {
@ -334,6 +335,7 @@ static void ProcessClassic_RightJoystick(struct joystick_t* js, double delta) {
Event_RaiseRawMove(&PointerEvents.RawMoved, dx * scale, -dy * scale);
}
static void ProcessClassic_Launcher(int mods) {
Input_SetNonRepeatable(CCPAD_START, mods & CLASSIC_CTRL_BUTTON_A);
Input_SetNonRepeatable(CCPAD_SELECT, mods & CLASSIC_CTRL_BUTTON_B);
@ -361,11 +363,15 @@ static void ProcessClassic_Game(int mods, double delta, classic_ctrl_t* ctrls) {
Input_SetNonRepeatable(CCPAD_UP, mods & CLASSIC_CTRL_BUTTON_UP);
Input_SetNonRepeatable(CCPAD_DOWN, mods & CLASSIC_CTRL_BUTTON_DOWN);
Input_SetNonRepeatable(CCPAD_ZL, mods & CLASSIC_CTRL_BUTTON_ZL);
Input_SetNonRepeatable(CCPAD_ZR, mods & CLASSIC_CTRL_BUTTON_ZR);
if (Input.RawMode) {
ProcessClassic_LeftJoystick( &ctrls->ljs);
ProcessClassic_RightJoystick(&ctrls->rjs, delta);
}
}
static void ProcessClassicInput(double delta) {
WPADData* wd = WPAD_Data(0);
classic_ctrl_t ctrls = wd->exp.classic;