From 35aa6922d64606e1906c9c8b96a0a624728ec022 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Mon, 25 Jan 2021 20:07:07 -0500 Subject: [PATCH] Show previous window instead of Home after closing a window --- src/game_base.c | 15 +++++++++++---- src/game_chess.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/game_base.c b/src/game_base.c index 9637df7..65a63b8 100644 --- a/src/game_base.c +++ b/src/game_base.c @@ -32,6 +32,7 @@ #include "game_snake.h" #include "line_info.h" #include "misc_tools.h" +#include "windows.h" extern struct Winthread Winthread; @@ -144,6 +145,12 @@ void game_kill(ToxWindow *self) del_window(self); } +static void game_init_abort(const ToxWindow *parent, ToxWindow *self) +{ + game_kill(self); + set_active_window_index(parent->index); +} + static void game_toggle_pause(GameData *game) { GameStatus status = game->status; @@ -234,11 +241,12 @@ int game_initialize(const ToxWindow *parent, Tox *m, GameType type, uint32_t id, if (game->is_multiplayer) { if (parent->type != WINDOW_TYPE_CHAT) { - game_kill(self); + game_init_abort(parent, self); return -3; } if (get_friend_connection_status(parent->num) == TOX_CONNECTION_NONE) { + game_init_abort(parent, self); return -2; } @@ -259,14 +267,14 @@ int game_initialize(const ToxWindow *parent, Tox *m, GameType type, uint32_t id, game->friend_number = parent->num; if (game->window == NULL) { - game_kill(self); + game_init_abort(parent, self); return -4; } int init_ret = game_initialize_type(game, multiplayer_data, length); if (init_ret < 0) { - game_kill(self); + game_init_abort(parent, self); return init_ret; } @@ -680,7 +688,6 @@ void game_onDraw(ToxWindow *self, Tox *m) } default: { - fprintf(stderr, "Unknown game status: %d\n", game->status); break; } } diff --git a/src/game_chess.c b/src/game_chess.c index a3d757c..942c0cf 100644 --- a/src/game_chess.c +++ b/src/game_chess.c @@ -1476,6 +1476,30 @@ static int chess_get_display_colour(ChessColour p_colour, int tile_colour) } } +void chess_move_curs_up_left(ChessState *state) +{ + chess_move_curs_left(state); + chess_move_curs_up(state); +} + +void chess_move_curs_up_right(ChessState *state) +{ + chess_move_curs_right(state); + chess_move_curs_up(state); +} + +void chess_move_curs_down_left(ChessState *state) +{ + chess_move_curs_left(state); + chess_move_curs_down(state); +} + +void chess_move_curs_down_right(ChessState *state) +{ + chess_move_curs_right(state); + chess_move_curs_down(state); +} + static void chess_draw_board_coords_white(WINDOW *win, const Board *board) { for (size_t i = 0; i < CHESS_BOARD_COLUMNS; ++i) { @@ -1728,7 +1752,29 @@ void chess_cb_on_keypress(GameData *game, int key, void *cb_data) break; } - case '\r': { + case KEY_HOME: { + chess_move_curs_up_left(state); + break; + } + + case KEY_END: { + chess_move_curs_down_left(state); + break; + } + + case KEY_PPAGE: { + chess_move_curs_up_right(state); + break; + } + + case KEY_NPAGE: { + chess_move_curs_down_right(state); + break; + } + + case '\r': + /* Intentional fallthrough */ + case ' ': { chess_do_input(game, state); break; }