diff options
Diffstat (limited to 'apps/plugins/solitaire.c')
-rw-r--r-- | apps/plugins/solitaire.c | 172 |
1 files changed, 35 insertions, 137 deletions
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index 47b1b25fa0..668f0d5f96 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | #include "lib/playback_control.h" | 23 | #include "lib/playback_control.h" |
24 | #include "lib/configfile.h" | 24 | #include "lib/configfile.h" |
25 | #include "lib/display_text.h" | ||
25 | #include "button.h" | 26 | #include "button.h" |
26 | #include "lcd.h" | 27 | #include "lcd.h" |
27 | 28 | ||
@@ -448,26 +449,6 @@ PLUGIN_HEADER | |||
448 | #endif | 449 | #endif |
449 | 450 | ||
450 | /** | 451 | /** |
451 | * Help strings | ||
452 | */ | ||
453 | |||
454 | static int helplines; | ||
455 | static int displaylines; | ||
456 | |||
457 | static char helptext[] = | ||
458 | /* Use single spaces only! Close each line with one \0. */ | ||
459 | "-- Navigation --\0" | ||
460 | HK_LR ": Move the cursor to the previous/ next column.\0" | ||
461 | HK_UD ": Move the cursor up/ down in the column.\0" | ||
462 | HK_MOVE ": Select cards, move cards, reveal hidden cards...\0" | ||
463 | HK_DRAW ": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0" | ||
464 | "-- Shortcuts --\0" | ||
465 | HK_REM2CUR ": Put the card on top of the remains stack on top of the cursor.\0" | ||
466 | HK_CUR2STACK ": Put the card under the cursor on one of the 4 final stacks.\0" | ||
467 | HK_REM2STACK ": Put the card on top of the remains stack on one of the 4 final stacks.\0" | ||
468 | ; | ||
469 | |||
470 | /** | ||
471 | * Misc constants, graphics and other defines | 452 | * Misc constants, graphics and other defines |
472 | */ | 453 | */ |
473 | 454 | ||
@@ -634,122 +615,41 @@ static void draw_empty_stack( int s, int x, int y, bool cursor ) | |||
634 | draw_card_ext( x, y, false, cursor ); | 615 | draw_card_ext( x, y, false, cursor ); |
635 | } | 616 | } |
636 | 617 | ||
637 | /** | 618 | /* Help */ |
638 | * Help | 619 | static bool solitaire_help( void ) |
639 | */ | ||
640 | |||
641 | static void init_help(void) | ||
642 | { | ||
643 | int lines = 0; | ||
644 | int w_space, w, h; | ||
645 | int para_len; | ||
646 | char *para = helptext; | ||
647 | |||
648 | rb->lcd_getstringsize(" ", &w_space, &h); | ||
649 | displaylines = LCD_HEIGHT / h; | ||
650 | para_len = rb->strlen(para); | ||
651 | |||
652 | while (para_len) | ||
653 | { | ||
654 | bool first = true; | ||
655 | int x = 0; | ||
656 | char *next, *store; | ||
657 | |||
658 | next = rb->strtok_r(para, " ", &store); | ||
659 | while (next) | ||
660 | { | ||
661 | rb->lcd_getstringsize(next, &w, NULL); | ||
662 | if (!first) | ||
663 | { | ||
664 | if (x + w > LCD_WIDTH) | ||
665 | { | ||
666 | lines++; | ||
667 | x = 0; | ||
668 | } | ||
669 | else | ||
670 | next[-1] = ' '; /* re-concatenate string */ | ||
671 | } | ||
672 | else | ||
673 | first = false; | ||
674 | |||
675 | x += w + w_space; | ||
676 | next = rb->strtok_r(NULL, " ", &store); | ||
677 | } | ||
678 | |||
679 | lines++; | ||
680 | para += para_len + 1; | ||
681 | para_len = rb->strlen(para); | ||
682 | } | ||
683 | helplines = lines; | ||
684 | } | ||
685 | |||
686 | enum help { HELP_QUIT, HELP_USB }; | ||
687 | |||
688 | /* help for the not so intuitive interface */ | ||
689 | enum help solitaire_help( void ) | ||
690 | { | 620 | { |
691 | int start = 0; | ||
692 | int button; | 621 | int button; |
693 | int lastbutton = BUTTON_NONE; | 622 | #define WORDS (sizeof help_text / sizeof (char*)) |
694 | bool fixed = (displaylines >= helplines); | 623 | static char* help_text[] = { |
695 | 624 | "Solitaire", "", "Controlls", "", | |
696 | while( true ) | 625 | HK_LR ":", "Move", "the", "cursor", "to", "the", |
697 | { | 626 | "previous/", "next", "column.", "", |
698 | char *text = helptext; | 627 | HK_UD ":", "Move", "the", "cursor", "up/", "down", "in", "the", |
699 | int line = fixed ? (displaylines - helplines) / 2 : 0; | 628 | "column.", "", |
700 | int i; | 629 | HK_MOVE ":", "Select", "cards,", "move", "cards...", "", |
701 | 630 | HK_DRAW ":", "Deselect", "a", "card", "if", "it", "was", "selected.", | |
702 | rb->lcd_clear_display(); | 631 | "Else", "draw", "new", "card(s)", "from", "the", "remains", |
703 | 632 | "stack.", "", "", | |
704 | for (i = 0; i < start + displaylines; i++) | 633 | "Shortcuts", "", |
705 | { | 634 | HK_REM2CUR ":", "Put", "the", "card", "on", "top", "of", "the", |
706 | if (i >= start) | 635 | "remains", "stack", "on", "top", "of", "the", "cursor.", "", |
707 | rb->lcd_puts(0, line++, text); | 636 | HK_CUR2STACK ":", "Put", "the", "card", "under", "the", "cursor", |
708 | text += rb->strlen(text) + 1; | 637 | "on", "one", "of", "the", "4", "final", "stacks.", "", |
709 | } | 638 | HK_REM2STACK ":", "Put", "the", "card", "on", "top", "of", "the", |
710 | rb->lcd_update(); | 639 | "remains", "stack", "on", "one", "of", "the", "4", "final", |
711 | 640 | "stacks." | |
712 | button = rb->button_get( true ); | 641 | }; |
713 | switch( button ) | 642 | |
714 | { | 643 | if (display_text(WORDS, help_text, NULL, NULL)) |
715 | case SOL_UP: | 644 | return true; |
716 | #ifdef SOL_UP_PRE | 645 | do { |
717 | if( lastbutton != SOL_UP_PRE ) | 646 | button = rb->button_get(true); |
718 | break; | 647 | if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) |
719 | #else | 648 | return true; |
720 | case SOL_UP|BUTTON_REPEAT: | 649 | } while( ( button == BUTTON_NONE ) |
721 | #endif | 650 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); |
722 | if (!fixed && start > 0) | 651 | |
723 | start--; | 652 | return false; |
724 | break; | ||
725 | |||
726 | case SOL_DOWN: | ||
727 | #ifdef SOL_DOWN_PRE | ||
728 | if( lastbutton != SOL_DOWN_PRE ) | ||
729 | break; | ||
730 | #else | ||
731 | case SOL_DOWN|BUTTON_REPEAT: | ||
732 | #endif | ||
733 | if (!fixed && start < helplines - displaylines) | ||
734 | start++; | ||
735 | break; | ||
736 | |||
737 | #ifdef SOL_RC_QUIT | ||
738 | case SOL_RC_QUIT: | ||
739 | #endif | ||
740 | case SOL_QUIT: | ||
741 | return HELP_QUIT; | ||
742 | |||
743 | default: | ||
744 | if( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) | ||
745 | return HELP_USB; | ||
746 | break; | ||
747 | } | ||
748 | if( button != BUTTON_NONE ) | ||
749 | lastbutton = button; | ||
750 | |||
751 | rb->yield(); | ||
752 | } | ||
753 | } | 653 | } |
754 | 654 | ||
755 | /** | 655 | /** |
@@ -831,7 +731,7 @@ int solitaire_menu(bool in_game) | |||
831 | break; | 731 | break; |
832 | 732 | ||
833 | case 3: | 733 | case 3: |
834 | if (solitaire_help() == HELP_USB) | 734 | if (solitaire_help()) |
835 | result = MENU_USB; | 735 | result = MENU_USB; |
836 | break; | 736 | break; |
837 | 737 | ||
@@ -1929,8 +1829,6 @@ enum plugin_status plugin_start(const void* parameter ) | |||
1929 | else | 1829 | else |
1930 | result = SOLITAIRE_WIN; | 1830 | result = SOLITAIRE_WIN; |
1931 | 1831 | ||
1932 | init_help(); | ||
1933 | |||
1934 | /* play the game :) | 1832 | /* play the game :) |
1935 | * Keep playing if a game was won (that means display the menu after | 1833 | * Keep playing if a game was won (that means display the menu after |
1936 | * winning instead of quiting) */ | 1834 | * winning instead of quiting) */ |