Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Numpad Enter key as regular Enter key #2305

Merged
merged 12 commits into from
Sep 25, 2023
1 change: 1 addition & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ void tic_core_synth_sound(tic_mem* tic);
void tic_core_blit(tic_mem* tic);
void tic_core_blit_ex(tic_mem* tic, tic_blit_callback clb);
const tic_script_config* tic_core_script_config(tic_mem* memory);
bool tic_core_enterp(tic_mem* tic, s32 hold, s32 period);
neolight1010 marked this conversation as resolved.
Show resolved Hide resolved

#define VBANK(tic, bank) \
bool MACROVAR(_bank_) = tic_api_vbank(tic, bank); \
Expand Down
6 changes: 6 additions & 0 deletions src/core/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ tic_point tic_api_mouse(tic_mem* memory)
: (tic_point){memory->ram->input.mouse.x - TIC80_OFFSET_LEFT, memory->ram->input.mouse.y - TIC80_OFFSET_TOP};
}

bool tic_core_enterp(tic_mem* tic, s32 hold, s32 period)
neolight1010 marked this conversation as resolved.
Show resolved Hide resolved
{
return tic_api_keyp(tic, tic_key_return, hold, period) ||
tic_api_keyp(tic, tic_key_numpadenter, hold, period);
}

void tic_core_tick_io(tic_mem* tic)
{
tic_core* core = (tic_core*)tic;
Expand Down
14 changes: 7 additions & 7 deletions src/studio/editors/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ static void processViKeyboard(Code* code)
else if (keyWasPressed(code->studio, tic_key_tab))
doTab(code, shift, ctrl);

else if (keyWasPressed(code->studio, tic_key_return))
else if (enterWasPressed(code->studio))
newLine(code);

else if (clear || shift)
Expand Down Expand Up @@ -2995,14 +2995,14 @@ static void processKeyboard(Code* code)
else if(keyWasPressed(code->studio, tic_key_pagedown)) pageDown(code);
else if(keyWasPressed(code->studio, tic_key_delete)) deleteChar(code);
else if(keyWasPressed(code->studio, tic_key_backspace)) backspaceChar(code);
else if(keyWasPressed(code->studio, tic_key_return)) newLine(code);
else if(enterWasPressed(code->studio)) newLine(code);
else if(keyWasPressed(code->studio, tic_key_tab)) doTab(code, shift, ctrl);
else usedKeybinding = false;
}

if(!usedKeybinding)
{
if(shift && keyWasPressed(code->studio, tic_key_return))
if(shift && enterWasPressed(code->studio))
{
newLineAutoClose(code);
usedKeybinding = true;
Expand Down Expand Up @@ -3181,7 +3181,7 @@ static void textFindTick(Code* code)
{


if(keyWasPressed(code->studio, tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE);
if(enterWasPressed(code->studio)) setCodeMode(code, TEXT_EDIT_MODE);
else if(keyWasPressed(code->studio, tic_key_up)
|| keyWasPressed(code->studio, tic_key_down)
|| keyWasPressed(code->studio, tic_key_left)
Expand Down Expand Up @@ -3226,7 +3226,7 @@ static void textFindTick(Code* code)
static void textReplaceTick(Code* code)
{

if(keyWasPressed(code->studio, tic_key_return)) {
if (enterWasPressed(code->studio)) {
if (*code->popup.text && code->popup.offset == NULL) //still in "find" mode
{
code->popup.offset = code->popup.text + strlen(code->popup.text);
Expand Down Expand Up @@ -3317,7 +3317,7 @@ static void textGoToTick(Code* code)
{
tic_mem* tic = code->tic;

if(keyWasPressed(code->studio, tic_key_return))
if(enterWasPressed(code->studio))
{
if(*code->popup.text)
updateGotoCode(code);
Expand Down Expand Up @@ -3462,7 +3462,7 @@ static void processSidebar(Code* code)
else if(keyWasPressed(code->studio, tic_key_end))
updateSidebarIndex(code, code->sidebar.size - 1);

else if(keyWasPressed(code->studio, tic_key_return))
else if(enterWasPressed(code->studio))
{
updateSidebarCode(code);
setCodeMode(code, TEXT_EDIT_MODE);
Expand Down
4 changes: 2 additions & 2 deletions src/studio/editors/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ static void processPatternKeyboard(Music* music)
else if(keyWasPressed(music->studio, tic_key_left)) colLeft(music);
else if(keyWasPressed(music->studio, tic_key_right)) colRight(music);
else if(keyWasPressed(music->studio, tic_key_down)
|| keyWasPressed(music->studio, tic_key_return))
|| enterWasPressed(music->studio))
music->tracker.edit.y = music->scroll.pos;
else
{
Expand Down Expand Up @@ -1542,7 +1542,7 @@ static void processKeyboard(Music* music)
? playTrack(music)
: stopTrack(music);
}
else if(keyWasPressed(music->studio, tic_key_return))
else if(enterWasPressed(music->studio))
{
stopped
? (shift
Expand Down
2 changes: 1 addition & 1 deletion src/studio/screens/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,7 @@ static void processKeyboard(Console* console)
if(console->input.pos > len)
console->input.pos = len;
}
else if(keyWasPressed(console->studio, tic_key_return)) processConsoleCommand(console);
else if(enterWasPressed(console->studio)) processConsoleCommand(console);
else if(keyWasPressed(console->studio, tic_key_backspace)) processConsoleBackspace(console);
else if(keyWasPressed(console->studio, tic_key_delete)) processConsoleDel(console);
else if(keyWasPressed(console->studio, tic_key_home)) processConsoleHome(console);
Expand Down
3 changes: 1 addition & 2 deletions src/studio/screens/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ static void drawMenu(Menu* menu, s32 x, s32 y)
}
}

if(tic_api_btnp(menu->tic, A, -1, -1)
|| tic_api_keyp(tic, tic_key_return, Hold, Period))
if(tic_api_btnp(menu->tic, A, -1, -1) || tic_core_enterp(tic, -1, -1))
{
if(option)
{
Expand Down
6 changes: 3 additions & 3 deletions src/studio/screens/surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ static void processGamepad(Surf* surf)
move(surf, dir);
}

if(tic_api_btnp(tic, A, -1, -1)
|| tic_api_keyp(tic, tic_key_return, -1, -1))
if(tic_api_btnp(tic, A, -1, -1)
|| tic_core_enterp(tic, -1, -1))
{
SurfItem* item = getMenuItem(surf);
item->dir
Expand Down Expand Up @@ -906,4 +906,4 @@ void freeSurf(Surf* surf)
freeAnim(surf);
resetMenu(surf);
free(surf);
}
}
16 changes: 14 additions & 2 deletions src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ bool keyWasPressed(Studio* studio, tic_key key)
return tic_api_keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD);
}

bool enterWasPressed(Studio* studio)
{
tic_mem* tic = studio->tic;
return tic_core_enterp(tic, KEYBOARD_HOLD, KEYBOARD_PERIOD);
}

bool anyKeyWasPressed(Studio* studio)
{
tic_mem* tic = studio->tic;
Expand Down Expand Up @@ -1695,6 +1701,12 @@ void gotoMenu(Studio* studio)
studio->mainmenu = studio_mainmenu_init(studio->menu, studio->config);
}

static bool enterWasPressedOnce(Studio* studio)
{
return keyWasPressedOnce(studio, tic_key_return) ||
keyWasPressedOnce(studio, tic_key_numpadenter);
}

static void processShortcuts(Studio* studio)
{
tic_mem* tic = studio->tic;
Expand All @@ -1716,7 +1728,7 @@ static void processShortcuts(Studio* studio)

if(alt)
{
if (keyWasPressedOnce(studio, tic_key_return)) gotoFullscreen(studio);
if (enterWasPressedOnce(studio)) gotoFullscreen(studio);
#if defined(BUILD_EDITORS)
else if(studio->mode != TIC_RUN_MODE)
{
Expand All @@ -1735,7 +1747,7 @@ static void processShortcuts(Studio* studio)
#if defined(BUILD_EDITORS)
else if(keyWasPressedOnce(studio, tic_key_pageup)) changeStudioMode(studio, -1);
else if(keyWasPressedOnce(studio, tic_key_pagedown)) changeStudioMode(studio, +1);
else if(keyWasPressedOnce(studio, tic_key_return)) runGame(studio);
else if(enterWasPressedOnce(studio)) runGame(studio);
else if(keyWasPressedOnce(studio, tic_key_r)) runGame(studio);
else if(keyWasPressedOnce(studio, tic_key_s)) saveProject(studio);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/studio/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ tic_map* getBankMap(Studio* studio);

char getKeyboardText(Studio* studio);
bool keyWasPressed(Studio* studio, tic_key key);
bool enterWasPressed(Studio* studio);
bool anyKeyWasPressed(Studio* studio);

const StudioConfig* getConfig(Studio* studio);
Expand Down
Loading