diff options
Diffstat (limited to 'apps/plugins/chessbox/chessbox_pgn.c')
-rw-r--r-- | apps/plugins/chessbox/chessbox_pgn.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index 4e16834f5c..39a24d6fa1 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c | |||
@@ -539,14 +539,21 @@ static void coords_to_pgn(struct pgn_ply_node* ply){ | |||
539 | } | 539 | } |
540 | } | 540 | } |
541 | 541 | ||
542 | static const char* get_game_text(int selected_item, void *data, | 542 | static struct pgn_game_node *get_game_info(int selected_item, void *data){ |
543 | char *buffer, size_t buffer_len){ | ||
544 | int i; | 543 | int i; |
545 | struct pgn_game_node *temp_node = (struct pgn_game_node *)data; | 544 | struct pgn_game_node *temp_node = (struct pgn_game_node *)data; |
546 | 545 | ||
547 | for (i=0;i<selected_item && temp_node != NULL;i++){ | 546 | for (i=0;i<selected_item && temp_node != NULL;i++){ |
548 | temp_node = temp_node->next_node; | 547 | temp_node = temp_node->next_node; |
549 | } | 548 | } |
549 | |||
550 | return temp_node; | ||
551 | } | ||
552 | |||
553 | static const char* get_game_text(int selected_item, void *data, | ||
554 | char *buffer, size_t buffer_len){ | ||
555 | struct pgn_game_node *temp_node = get_game_info(selected_item, data); | ||
556 | |||
550 | if (temp_node == NULL){ | 557 | if (temp_node == NULL){ |
551 | return NULL; | 558 | return NULL; |
552 | } | 559 | } |
@@ -556,6 +563,35 @@ static const char* get_game_text(int selected_item, void *data, | |||
556 | return buffer; | 563 | return buffer; |
557 | } | 564 | } |
558 | 565 | ||
566 | static void say_player(const char *name, bool enqueue) { | ||
567 | if (!rb->strcasecmp(name, "player")) | ||
568 | rb->talk_id(VOICE_PLAYER, enqueue); | ||
569 | else if (!rb->strcasecmp(name, "gnuchess")) | ||
570 | rb->talk_id(VOICE_GNUCHESS, enqueue); | ||
571 | else | ||
572 | rb->talk_spell(name, enqueue); | ||
573 | } | ||
574 | |||
575 | static int speak_game_selection(int selected_item, void *data){ | ||
576 | struct pgn_game_node *temp_node = get_game_info(selected_item, data); | ||
577 | |||
578 | if (temp_node != NULL){ | ||
579 | say_player(temp_node->white_player, false); | ||
580 | say_player(temp_node->black_player, true); | ||
581 | if (temp_node->game_date[0] != '?') { | ||
582 | char buf[12]; | ||
583 | rb->strcpy(buf, temp_node->game_date); | ||
584 | buf[4] = 0; | ||
585 | buf[7] = 0; | ||
586 | rb->talk_id(LANG_MONTH_JANUARY + rb->atoi(&(buf[5])) - 1, true); | ||
587 | rb->talk_number(rb->atoi(&(buf[8])), true); | ||
588 | rb->talk_number(rb->atoi(buf), true); | ||
589 | } | ||
590 | } | ||
591 | |||
592 | return 0; | ||
593 | } | ||
594 | |||
559 | static void write_pgn_token(int fhandler, char *buffer, size_t *line_length){ | 595 | static void write_pgn_token(int fhandler, char *buffer, size_t *line_length){ |
560 | if (*line_length + rb->strlen(buffer) + 1 > 80){ | 596 | if (*line_length + rb->strlen(buffer) + 1 > 80){ |
561 | rb->fdprintf(fhandler,"\n"); | 597 | rb->fdprintf(fhandler,"\n"); |
@@ -636,14 +672,18 @@ struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game){ | |||
636 | 672 | ||
637 | 673 | ||
638 | rb->gui_synclist_init(&games_list, &get_game_text, first_game, false, 1, NULL); | 674 | rb->gui_synclist_init(&games_list, &get_game_text, first_game, false, 1, NULL); |
639 | rb->gui_synclist_set_title(&games_list, "Games", NOICON); | 675 | rb->gui_synclist_set_title(&games_list, rb->str(LANG_CHESSBOX_GAMES), NOICON); |
640 | rb->gui_synclist_set_icon_callback(&games_list, NULL); | 676 | rb->gui_synclist_set_icon_callback(&games_list, NULL); |
677 | if (rb->global_settings->talk_menu) | ||
678 | rb->gui_synclist_set_voice_callback(&games_list, speak_game_selection); | ||
641 | rb->gui_synclist_set_nb_items(&games_list, i); | 679 | rb->gui_synclist_set_nb_items(&games_list, i); |
642 | rb->gui_synclist_limit_scroll(&games_list, true); | 680 | rb->gui_synclist_limit_scroll(&games_list, true); |
643 | rb->gui_synclist_select_item(&games_list, 0); | 681 | rb->gui_synclist_select_item(&games_list, 0); |
644 | 682 | ||
683 | rb->gui_synclist_draw(&games_list); | ||
684 | rb->gui_synclist_speak_item(&games_list); | ||
685 | |||
645 | while (true) { | 686 | while (true) { |
646 | rb->gui_synclist_draw(&games_list); | ||
647 | curr_selection = rb->gui_synclist_get_sel_pos(&games_list); | 687 | curr_selection = rb->gui_synclist_get_sel_pos(&games_list); |
648 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | 688 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); |
649 | if (rb->gui_synclist_do_button(&games_list,&button,LIST_WRAP_OFF)){ | 689 | if (rb->gui_synclist_do_button(&games_list,&button,LIST_WRAP_OFF)){ |
@@ -651,11 +691,7 @@ struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game){ | |||
651 | } | 691 | } |
652 | switch (button) { | 692 | switch (button) { |
653 | case ACTION_STD_OK: | 693 | case ACTION_STD_OK: |
654 | temp_node = first_game; | 694 | return get_game_info(curr_selection, first_game); |
655 | for (i=0;i<curr_selection && temp_node != NULL;i++){ | ||
656 | temp_node = temp_node->next_node; | ||
657 | } | ||
658 | return temp_node; | ||
659 | break; | 695 | break; |
660 | case ACTION_STD_CANCEL: | 696 | case ACTION_STD_CANCEL: |
661 | return NULL; | 697 | return NULL; |