Skip to content

Commit

Permalink
don't allow mouse clicks when not playing
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Feb 9, 2025
1 parent fe636fe commit c82d829
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 99 deletions.
Binary file modified data/fonts/6x8.tga
Binary file not shown.
Binary file modified data/fonts/6x8.xcf
Binary file not shown.
29 changes: 18 additions & 11 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ void Config::reset(void)

key_attack.sym = SDLK_SPACE;
key_help.sym = SDLK_h;
key_load.sym = SDLK_F11;
key_load.sym = SDLK_F12;
key_move_down.sym = SDLK_s;
key_move_left.sym = SDLK_a;
key_move_right.sym = SDLK_d;
key_move_up.sym = SDLK_w;
key_quit.sym = SDLK_q;
key_quit.mod = KMOD_SHIFT;
key_save.sym = SDLK_F12;
key_save.sym = SDLK_F1;
key_screenshot.sym = SDLK_F10;
key_console.sym = SDLK_TAB;
key_console.sym = SDLK_BACKQUOTE;
key_console.mod = KMOD_SHIFT;
music_volume = {MIX_MAX_VOLUME / 3};
sdl_delay = 10;
Expand Down Expand Up @@ -373,6 +373,8 @@ void Game::start_playing(void)
TRACE_AND_INDENT();

auto g = this;

wid_topcon_init(g);
TOPCON("Welcome to the dungeons of dread, home of the black dragon, %%fg=red$Gorget%%fg=reset$.");
TOPCON("Complete all %%fg=yellow$16%%fg=reset$ levels and collect the Darkenstone to win.");

Expand Down Expand Up @@ -420,6 +422,10 @@ void Game::display(void)
return;
}

if (game->state != STATE_PLAYING) {
return;
}

auto l = game_level_get(g, v);
if (l) {
level_tick(g, v, l);
Expand Down Expand Up @@ -468,6 +474,8 @@ void Game::state_reset(const std::string &why)
}
void game_state_reset(Gamep g, const char *why) { g->state_reset(why); }

uint8_t game_state(Gamep g) { return g->state; }

void Game::state_change(uint8_t new_state, const std::string &why)
{
TRACE_NO_INDENT();
Expand Down Expand Up @@ -497,25 +505,24 @@ void Game::state_change(uint8_t new_state, const std::string &why)
switch (new_state) {
case STATE_MAIN_MENU :
case STATE_QUITTING :
wid_leftbar_fini(g);
wid_load_destroy(g);
wid_main_menu_destroy(g);
wid_quit_destroy(g);
wid_rightbar_fini(g);
wid_save_destroy(g);

wid_leftbar_fini(g);
wid_rightbar_fini(g);
wid_topcon_fini(g);
break;
case STATE_PLAYING :
wid_leftbar_fini(g);
wid_load_destroy(g);
wid_main_menu_destroy(g);
wid_quit_destroy(g);
wid_rightbar_fini(g);
wid_save_destroy(g);
wid_topcon_fini(g);
wid_leftbar_init(g);
wid_rightbar_init(g);
wid_topcon_init(g);
if (old_state == STATE_MAIN_MENU) {
wid_leftbar_init(g);
wid_rightbar_init(g);
}
break;
case STATE_KEYBOARD_MENU :
case STATE_LOAD_MENU :
Expand Down
28 changes: 16 additions & 12 deletions src/game_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
uint8_t game_mouse_down(Gamep g, int x, int y, uint32_t button)
{
DBG("Game mouse down");
LOG("Game mouse down");
TRACE_AND_INDENT();

if (wid_some_recent_event_occurred()) {
Expand All @@ -25,6 +25,10 @@ uint8_t game_mouse_down(Gamep g, int x, int y, uint32_t button)
return false;
}

if (game_state(g) != STATE_PLAYING) {
return false;
}

//
// Follow the mouse path?
//
Expand All @@ -42,7 +46,7 @@ uint8_t game_mouse_up(Gamep g, int x, int y, uint32_t button) { return false; }
uint8_t game_mouse_motion(Gamep g, int x, int y, int relx, int rely, int wheelx, int wheely)
{
DBG2("Game mouse motion");
TRACE_AND_INDENT();
TRACE_NO_INDENT();

if (wid_some_recent_event_occurred()) {
return false;
Expand All @@ -58,22 +62,22 @@ uint8_t game_mouse_motion(Gamep g, int x, int y, int relx, int rely, int wheelx,

uint8_t game_input(Gamep g, const SDL_Keysym *key)
{
LOG("Pressed a key");
TRACE_NO_INDENT();
DBG("INF: Pressed a key");

if (! g) {
DBG("INF: Pressed a key; no game");
DBG("Pressed a key; no game");
return false;
}

auto v = game_levels_get(g);
if (! v) {
DBG("INF: Pressed a key; no levels");
DBG("Pressed a key; no levels");
return false;
}

if (sdlk_eq(*key, game_key_console_get(g))) {
DBG("INF: Pressed a key; over console, ignore");
DBG("Pressed a key; over console, ignore");
return false;
}

Expand All @@ -92,7 +96,7 @@ uint8_t game_input(Gamep g, const SDL_Keysym *key)
}

if (sdlk_eq(*key, game_key_quit_get(g))) {
LOG("INF: Pressed quit key");
LOG("Pressed quit key");
TRACE_AND_INDENT();
if (g_opt_quick_start) {
DIE_CLEAN("Quick quit");
Expand All @@ -102,22 +106,22 @@ uint8_t game_input(Gamep g, const SDL_Keysym *key)
}

if (sdlk_eq(*key, game_key_help_get(g))) {
LOG("INF: Pressed help key");
LOG("Pressed help key");
TRACE_AND_INDENT();
wid_cfg_keyboard_select(g);
return true;
}
if (sdlk_eq(*key, game_key_load_get(g))) {
LOG("INF: Pressed load key");
LOG("Pressed load key");
TRACE_AND_INDENT();
LOG("INF: Loading game");
LOG("Loading game");
wid_load_select(g);
return true;
}
if (sdlk_eq(*key, game_key_save_get(g))) {
LOG("INF: Pressed save key");
LOG("Pressed save key");
TRACE_AND_INDENT();
LOG("INF: Saving the game");
LOG("Saving the game");
wid_save_select(g);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/game_load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void Game::load_select(void)
if (! load(tmp_file, tmp)) {
if (! game_load_error.empty()) {
s += game_load_error;
wid_set_style(w, UI_WID_STYLE_RED);
wid_set_style(w, UI_WID_STYLE_HORIZ_DARK);
CON("GAME LOADING ERROR: %s", game_load_error.c_str());
} else {
if (slot == UI_WID_SAVE_SLOTS - 1) {
Expand All @@ -643,7 +643,7 @@ void Game::load_select(void)
} else {
wid_set_on_mouse_up(game, w, wid_load_mouse_up);
}
wid_set_style(w, UI_WID_STYLE_GREEN);
wid_set_style(w, UI_WID_STYLE_HORIZ_LIGHT);
slot_valid[ slot ] = true;
}
wid_set_int_context(w, slot);
Expand Down
3 changes: 1 addition & 2 deletions src/game_save.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void Game::save_select(void)
point tl(0, y_at);
point br(menu_width - 2, y_at);

std::string s = std::to_string(slot) + " ";
std::string s = std::to_string(slot) + ": ";
if (! load(tmp_file, tmp)) {
if (slot == UI_WID_SAVE_SLOTS - 1) {
s += "<no snapshot>";
Expand All @@ -446,7 +446,6 @@ void Game::save_select(void)
s += tmp.save_meta;
}
wid_set_style(w, UI_WID_STYLE_HORIZ_LIGHT);
wid_set_style(w, UI_WID_STYLE_GREEN);
}

if (slot == UI_WID_SAVE_SLOTS - 1) {
Expand Down
51 changes: 26 additions & 25 deletions src/my_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,31 @@ uint8_t game_mouse_down(Gamep, int x, int y, uint32_t button);
uint8_t game_mouse_motion(Gamep, int x, int y, int relx, int rely, int wheelx, int wheely);
uint8_t game_mouse_up(Gamep, int x, int y, uint32_t button);

void game_config_reset(Gamep);
void game_create_levels(Gamep);
void game_start_playing(Gamep);
void game_destroy_levels(Gamep);
void game_display(Gamep);
void game_fini(Gamep);
void game_init(Gamep);
void game_load(Gamep);
void game_load(Gamep, int slot);
void game_load_config(Gamep game);
void game_load_last_config(const char *appdata);
void game_load_snapshot(Gamep);
void game_save(Gamep);
void game_save(Gamep, int slot);
void game_save_config(Gamep);
void game_save_snapshot_check(Gamep);
void game_save_snapshot(Gamep);
void game_set_currently_saving_snapshot(Gamep);
void game_set_seed(Gamep);
void game_state_change(Gamep, uint8_t state, const char *);
void game_state_reset(Gamep, const char *);
void game_unset_currently_saving_snapshot(Gamep);
void game_unset_request_reset_state_change(Gamep);
void game_unset_request_to_save_snapshot(Gamep);
void game_unset_request_to_update_same_level(Gamep);
void game_config_reset(Gamep);
void game_create_levels(Gamep);
void game_start_playing(Gamep);
void game_destroy_levels(Gamep);
void game_display(Gamep);
void game_fini(Gamep);
void game_init(Gamep);
void game_load(Gamep);
void game_load(Gamep, int slot);
void game_load_config(Gamep game);
void game_load_last_config(const char *appdata);
void game_load_snapshot(Gamep);
void game_save(Gamep);
void game_save(Gamep, int slot);
void game_save_config(Gamep);
void game_save_snapshot_check(Gamep);
void game_save_snapshot(Gamep);
void game_set_currently_saving_snapshot(Gamep);
void game_set_seed(Gamep);
uint8_t game_state(Gamep);
void game_state_change(Gamep, uint8_t state, const char *);
void game_state_reset(Gamep, const char *);
void game_unset_currently_saving_snapshot(Gamep);
void game_unset_request_reset_state_change(Gamep);
void game_unset_request_to_save_snapshot(Gamep);
void game_unset_request_to_update_same_level(Gamep);

#endif
2 changes: 1 addition & 1 deletion src/my_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define UI_TYPE_PIXELART 0
#define UI_TYPES_MAX 1
#define UI_WID_POPUP_WIDTH_NORMAL 18
#define UI_WID_POPUP_WIDTH_WIDE 24
#define UI_WID_POPUP_WIDTH_WIDE 60
#define UI_WID_SAVE_SLOTS 10 // How many save game slots

//
Expand Down
Loading

0 comments on commit c82d829

Please sign in to comment.