Subversion Repositories Kolibri OS

Rev

Rev 5243 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "rsgamemenu.h"
  2.  
  3. #include "rsgame.h"
  4.  
  5. #include "rskos.h"
  6.  
  7. PRSFUNC0 menu_actions[] = {
  8.     /* a */ &menu_action_start,    
  9.     /* b */ &menu_action_exit,
  10.     /* c */ &menu_action_change_window_scale
  11. };
  12.  
  13. char window_scale_str[] = "c< 2X >";
  14.  
  15. char* menu_main_titles[] = {
  16.     "a5TART",
  17.     "15ETTING5",
  18.     "2ABOUT",
  19.     "bQUIT",
  20.     0
  21. };
  22.  
  23. char* menu_settings_titles[] = {
  24.     " WINDOW SCALE:",
  25.     window_scale_str,
  26.     " ",
  27.     "0DONE",
  28.     0
  29. };
  30.  
  31. char* menu_about_titles[] = {
  32.     " DEVELOPED BY",
  33.     " ROMAN SHUVALOV",
  34.     " ",
  35.     "0DONE",
  36.     0
  37. };
  38.  
  39. char **menu_titles[] = {
  40.     /* 0 */ menu_main_titles,
  41.     /* 1 */ menu_settings_titles,
  42.     /* 2 */ menu_about_titles,
  43.     0
  44. };
  45.  
  46.  
  47. void menu_cursor_down() {
  48.     int new_index = game.menu_item_index+1;
  49.     while ( (menu_titles[game.menu_index][new_index]) ) {
  50.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  51.             game.menu_item_index = new_index;
  52.             game_ding(1);
  53.             return;
  54.         };
  55.         new_index++;
  56.     };
  57. };
  58.  
  59. void menu_cursor_up() {
  60.     int new_index = game.menu_item_index-1;
  61.     while ( new_index+1 ) {
  62.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  63.             game.menu_item_index = new_index;
  64.             game_ding(1);
  65.             return;
  66.         };
  67.         new_index--;
  68.     };
  69. };
  70.  
  71. void menu_open(int i) {
  72.    
  73.     game.menu_index = i;
  74.    
  75.     game.menu_item_index = -1;
  76.     // (menu_cursor_down without sound)
  77.     int new_index = game.menu_item_index+1;
  78.     while ( (menu_titles[game.menu_index][new_index]) ) {
  79.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  80.             game.menu_item_index = new_index;
  81.             return;
  82.         };
  83.         new_index++;
  84.     };
  85.    
  86. };
  87.  
  88. void menu_cursor_click() {
  89.    
  90.     char c = menu_titles[game.menu_index][game.menu_item_index][0];
  91.    
  92.     game_ding(0);
  93.    
  94.     if (c > '9') {
  95.         // action: call function
  96.         menu_actions[c - 'a']();
  97.     }
  98.     else {
  99.         // action: navigate to menu
  100.         menu_open(c - '0');
  101.     };
  102.    
  103. //    DEBUG10f("click: %c \n", c);
  104.    
  105. };
  106.  
  107. void menu_action_start() {
  108.     game.status = STATUS_PLAYING;
  109.    
  110.     game.tx = GAME_WIDTH/2 - 50;
  111.     game.ty = GAME_HEIGHT/2 - 10;
  112.    
  113. };
  114.  
  115. void menu_action_exit() {
  116.     #ifndef RS_LINUX
  117.         GameTerm();
  118.     #endif
  119.     rskos_exit();
  120. };
  121.  
  122. void menu_action_change_window_scale() {
  123.     game_change_window_scale(1);
  124. };
  125.