Added chat button bind, prevented chat from disabling other binds

This commit is contained in:
MysterD 2020-09-15 22:22:39 -07:00
parent a0d5deceff
commit 275d6444b1
4 changed files with 31 additions and 19 deletions

View file

@ -121,6 +121,7 @@ static const u8 bindStr[][32] = {
{ TEXT_BIND_DOWN },
{ TEXT_BIND_LEFT },
{ TEXT_BIND_RIGHT },
{ TEXT_BIND_CHAT },
{ TEXT_OPT_DEADZONE },
{ TEXT_OPT_RUMBLE }
};
@ -247,10 +248,11 @@ static struct Option optsControls[] = {
DEF_OPT_BIND( bindStr[13], configKeyStickDown ),
DEF_OPT_BIND( bindStr[14], configKeyStickLeft ),
DEF_OPT_BIND( bindStr[15], configKeyStickRight ),
DEF_OPT_BIND( bindStr[16], configKeyChat ),
// max deadzone is 31000; this is less than the max range of ~32768, but this
// way, the player can't accidentally lock themselves out of using the stick
DEF_OPT_SCROLL( bindStr[16], &configStickDeadzone, 0, 100, 1 ),
DEF_OPT_SCROLL( bindStr[17], &configRumbleStrength, 0, 100, 1)
DEF_OPT_SCROLL( bindStr[17], &configStickDeadzone, 0, 100, 1 ),
DEF_OPT_SCROLL( bindStr[18], &configRumbleStrength, 0, 100, 1)
};
static struct Option optsVideo[] = {

View file

@ -72,6 +72,7 @@ unsigned int configKeyStickUp[MAX_BINDS] = { 0x0011, VK_INVALID, VK_INVALID
unsigned int configKeyStickDown[MAX_BINDS] = { 0x001F, VK_INVALID, VK_INVALID };
unsigned int configKeyStickLeft[MAX_BINDS] = { 0x001E, VK_INVALID, VK_INVALID };
unsigned int configKeyStickRight[MAX_BINDS] = { 0x0020, VK_INVALID, VK_INVALID };
unsigned int configKeyChat[MAX_BINDS] = { 0x001C, VK_INVALID, VK_INVALID };
unsigned int configStickDeadzone = 16; // 16*DEADZONE_STEP=4960 (the original default deadzone)
unsigned int configRumbleStrength = 50;
#ifdef EXTERNAL_DATA
@ -131,6 +132,7 @@ static const struct ConfigOption options[] = {
{.name = "key_stickdown", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickDown},
{.name = "key_stickleft", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickLeft},
{.name = "key_stickright", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickRight},
{.name = "key_chat", .type = CONFIG_TYPE_BIND, .uintValue = configKeyChat},
{.name = "stick_deadzone", .type = CONFIG_TYPE_UINT, .uintValue = &configStickDeadzone},
{.name = "rumble_strength", .type = CONFIG_TYPE_UINT, .uintValue = &configRumbleStrength},
#ifdef EXTERNAL_DATA

View file

@ -40,6 +40,7 @@ extern unsigned int configKeyStickUp[];
extern unsigned int configKeyStickDown[];
extern unsigned int configKeyStickLeft[];
extern unsigned int configKeyStickRight[];
extern unsigned int configKeyChat[];
extern unsigned int configStickDeadzone;
extern unsigned int configRumbleStrength;
#ifdef EXTERNAL_DATA

View file

@ -1,7 +1,8 @@
#include <stdbool.h>
#include <ultra64.h>
#include <time.h>
#include <string.h>
#include "pc/configfile.h"
#include "controller_api.h"
#ifdef TARGET_WEB
@ -40,11 +41,12 @@ static int num_keybinds = 0;
static u32 keyboard_lastkey = VK_INVALID;
char gTextInput[MAX_TEXT_INPUT];
static bool inTextInput = false;
static u8 maxTextInput = 0;
static u8 sInTextInput = false;
static u8 sMaxTextInput = 0;
static clock_t sIgnoreTextInput = 0;
u8 held_ctrl, held_shift, held_alt;
static enum TextInputMode textInputMode;
static enum TextInputMode sTextInputMode;
void (*textInputOnEscape)(void) = NULL;
void (*textInputOnEnter)(void) = NULL;
@ -85,11 +87,11 @@ bool keyboard_on_key_down(int scancode) {
keyboard_alter_modifier(scancode, true);
#ifdef DEBUG
if (!inTextInput) {
if (!sInTextInput) {
debug_keyboard_on_key_down(scancode);
}
#endif
if (inTextInput) {
if (sInTextInput) {
// perform text-input-specific actions
switch (scancode) {
case SCANCODE_BACKSPACE:
@ -113,10 +115,10 @@ bool keyboard_on_key_down(int scancode) {
return FALSE;
}
if (!held_alt && (scancode == SCANCODE_ENTER)) {
if (!held_alt && (scancode == (int)configKeyChat[0])) {
if (sSelectedFileNum != 0) {
sIgnoreTextInput = clock() + CLOCKS_PER_SEC * 0.01f;
chat_start_input();
return FALSE;
}
}
@ -130,7 +132,7 @@ bool keyboard_on_key_up(int scancode) {
// alter the held value of modifier keys
keyboard_alter_modifier(scancode, false);
if (inTextInput) {
if (sInTextInput) {
// ignore any key up event if we're in text-input mode
return FALSE;
}
@ -150,7 +152,7 @@ char* keyboard_start_text_input(enum TextInputMode inInputMode, u8 inMaxTextInpu
// set text-input events
textInputOnEscape = onEscape;
textInputOnEnter = onEnter;
maxTextInput = inMaxTextInput;
sMaxTextInput = inMaxTextInput;
// clear buffer
for (int i = 0; i < MAX_TEXT_INPUT; i++) { gTextInput[i] = '\0'; }
@ -162,20 +164,20 @@ char* keyboard_start_text_input(enum TextInputMode inInputMode, u8 inMaxTextInpu
// start allowing text input
wm_api->start_text_input();
textInputMode = inInputMode;
inTextInput = true;
sTextInputMode = inInputMode;
sInTextInput = true;
}
void keyboard_stop_text_input(void) {
// stop allowing text input
inTextInput = false;
sInTextInput = false;
wm_api->stop_text_input();
}
bool keyboard_in_text_input(void) { return inTextInput; }
bool keyboard_in_text_input(void) { return sInTextInput; }
static bool keyboard_allow_character_input(char c) {
switch (textInputMode) {
switch (sTextInputMode) {
case TIM_IP:
// IP only allows numbers, periods, and spaces
return (c >= '0' && c <= '9')
@ -205,7 +207,12 @@ static bool keyboard_allow_character_input(char c) {
}
void keyboard_on_text_input(char* text) {
if (!inTextInput) { return; }
if (sIgnoreTextInput != 0 && clock() <= sIgnoreTextInput) {
sIgnoreTextInput = 0;
return;
}
if (!sInTextInput) { return; }
// sanity check input
if (text == NULL) { return; }
@ -213,7 +220,7 @@ void keyboard_on_text_input(char* text) {
while (*text != '\0') {
// make sure we don't overrun the buffer
if (i >= MAX_TEXT_INPUT) { break; }
if (i >= maxTextInput) { break; }
if (i >= sMaxTextInput) { break; }
// copy over character if we're allowed to input it
if (keyboard_allow_character_input(*text)) {