Skip to content

Commit

Permalink
fix f1 hotkey conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel-hrvs authored Aug 3, 2024
1 parent c8684f0 commit dda61e9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/studio/editors/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -2957,9 +2957,15 @@ static void processKeyboard(Code* code)
}

bool usedKeybinding = true;


if(hasJustSwitchedToCodeMode(code->studio))
{
setJustSwitchedToCodeMode(code->studio, false);
return; // Skip processing other inputs for this frame
}

// handle bookmarks
if(keyWasPressed(code->studio, tic_key_f7))
if(keyWasPressed(code->studio, tic_key_f1))
{
if(ctrl && shift)
{
Expand Down
26 changes: 25 additions & 1 deletion src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,23 @@ static bool enterWasPressedOnce(Studio* studio)
keyWasPressedOnce(studio, tic_key_numpadenter);
}

#if defined(BUILD_EDITORS)
// These three are to fix the f1 hotkey conflict

// Add a static variable in studio.c to track the mode switch
static bool justSwitchedToCodeMode = false;

void setJustSwitchedToCodeMode(Studio* studio, bool value)
{
justSwitchedToCodeMode = value;
}

bool hasJustSwitchedToCodeMode(Studio* studio)
{
return justSwitchedToCodeMode;
}
#endif

#if defined(BUILD_EDITORS)

static bool showGameMenu(Studio* studio)
Expand Down Expand Up @@ -1890,7 +1907,14 @@ static void processShortcuts(Studio* studio)

if(!showGameMenu(studio) || studio->mode != TIC_RUN_MODE)
{
if(keyWasPressedOnce(studio, tic_key_f1)) setStudioMode(studio, TIC_CODE_MODE);
if(keyWasPressedOnce(studio, tic_key_f1))
{
if(studio->mode != TIC_CODE_MODE)
{
setStudioMode(studio, TIC_CODE_MODE);
setJustSwitchedToCodeMode(studio, true);
}
}
else if(keyWasPressedOnce(studio, tic_key_f2)) setStudioMode(studio, TIC_SPRITE_MODE);
else if(keyWasPressedOnce(studio, tic_key_f3)) setStudioMode(studio, TIC_MAP_MODE);
else if(keyWasPressedOnce(studio, tic_key_f4)) setStudioMode(studio, TIC_SFX_MODE);
Expand Down
2 changes: 2 additions & 0 deletions src/studio/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ typedef struct

typedef struct Studio Studio;

void setJustSwitchedToCodeMode(Studio* studio, bool value);
bool hasJustSwitchedToCodeMode(Studio* studio);
const tic_mem* studio_mem(Studio* studio);
void studio_tick(Studio* studio, tic80_input input);
void studio_sound(Studio* studio);
Expand Down

0 comments on commit dda61e9

Please sign in to comment.