Skip to content

Commit

Permalink
Fix f1 hotkey conflict (#2646)
Browse files Browse the repository at this point in the history
* fix f1 hotkey conflict

* use f7 as it doesn't conflict

* fix f1 hotkey conflict
  • Loading branch information
Miguel-hrvs authored Aug 4, 2024
1 parent 55ee0b3 commit 048df32
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/studio/editors/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,13 @@ 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_f1))
{
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 048df32

Please sign in to comment.