1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 13:17:46 +02:00

Show previous window instead of Home after closing a window

This commit is contained in:
jfreegman 2021-01-25 20:07:07 -05:00
parent 7abf6388f8
commit 35aa6922d6
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 58 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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;
}