MENU.H
The menu.h file contains defs for the menu-class.
/****************************************************************
    GALVADERS (V1.0), BY AHARON HILLEL.
    gcc version 3.2 (mingw special 20020817-1)
    ALLEGRO VERSION: 4.1.12 (WIP)
    ALLEGRO DATE:    2003-11-10
****************************************************************/
#include "base.h"

#if !defined( _MENU_H_ )
#define _MENU_H_

#define CONTROLS_FILE_NAME "controls.dat"
#define HIGH_SCORES_FILE_NAME "high.dat"

#define GALVADERS_DEMO_FILE "glv_demo.dat"
#define INVADERS_DEMO_FILE "glx_demo.dat"
#define GALAXY_DEMO_FILE "inv_demo.dat"

#define NUMBER_OF_DEMOS 3
#define STATE_SHOW_CONTROLS 1
#define STATE_SHOW_SCORES_TABLE 2
#define STATE_SHOW_HIGH_SCORE_TABLE 3
#define STATE_GAME_DEMO 4
#define STATE_PLAY_THE_GAME 5
#define STATE_CHANGE_CONTROLS 6
#define STATE_SWITCH_GAME 7
#define STATE_PAUSE_GAME 8

#define SIMULATE_PAUSE_AFTER_GET_FOCUS 1
#define REPAINT_WINDOW_AFTER_GET_FOCUS 2

#define HIGH_SCORE_NAME_LENGTH 19
#define N_HIGH_SCORES 15

#define M_KEY_ESCAPE          KEY_ESC
#define M_KEY_START_1         KEY_1
#define M_KEY_START_2         KEY_2
#define M_KEY_SOUND           KEY_S
#define M_KEY_PAUSE           KEY_P
#define M_KEY_CHANGE_CONTROLS KEY_C
#define M_KEY_SWITCH_GAME     KEY_F1
#define M_KEY_VSYNC           KEY_F2
#define M_KEY_SHIELDS         KEY_F3
#define M_KEY_BULLETS         KEY_B
extern volatile int time_for_frame;

struct st_high_score_record_type
{
    char name[HIGH_SCORE_NAME_LENGTH + 1];
    int score;
};
typedef st_high_score_record_type st_high_score_record;

struct sprite_menu_item_type
{
    enemy *sprite;
    int x_inc;
    int y_inc;
    int times;
};
typedef struct sprite_menu_item_type sprite_menu_item;

struct text_menu_item_type
{
    text_msg *text;
    int x_inc;
    int y_inc;
    int times;
};
typedef struct text_menu_item_type text_menu_item;

typedef list<sprite_menu_item *> m_sprite_list;
typedef list<text_menu_item *> m_msg_list;

class menu
{
    private:
      static char *game_names[];
      static char default_menu_keys[];
      
      class stars *stars_layer_1;
      m_sprite_list s_list;
      m_msg_list m_list;
      m_sprite_list::iterator s_iter;
      m_msg_list::iterator m_iter;
      
      st_high_score_record high_scores[N_HIGH_SCORES];
      BITMAP *dest;
      BITMAP *game_footer;
      int menu_state;
      int pause_after_get_window_focus;
      char *menu_keys;
      int n_keys;
      int game_font;
     
      int player_1_last_game_score;
      int player_2_last_game_score;
      unsigned short *game_demo[NUMBER_OF_DEMOS];
      
      unsigned int sound_ok;
      unsigned int sound_inc;
      unsigned int sound_expr;

      st_controls player_keys[2];
      
      void get_key_name(char key, char *name);
      int play_menu(unsigned int frames, class text_msg *controls_text);
      void read_files(void);
      unsigned char get_key(void);
      void get_change_controls_text(unsigned char *key_set ,char *text);
      int change_controls(void);
      void clear_menu_items(void);
      void do_arcade_reset(unsigned char game_type);
      char *get_controls_text(char *buffer);
      int show_controls(void);
      int show_scores_table(void);
      int show_high_score_table(void);
      int update_hi_score_table(char *name, int new_score);
      void do_shields(void);
      int pause_game(void);
      void remove_shields(void);
      int handle_menu_input(void);
      void stop_sound(unsigned int old_sound_flag);
      int play_the_game(int n_players);
      void make_high_score(int h_score, char *text);
      
      void record_player_keys(unsigned short n_player, unsigned short *player_data, unsigned short *player_data_index);

      unsigned char menu_status_register;

/*  Menu status register masks  */
#define CLEAR_GAME_OVER       0x7F
#define CLEAR_VSYNC           0xBF
#define GET_VSYNC             ((menu_status_register & BIT_VSYNC) >> 6)
#define CLEAR_SHIELDS         0xDF
#define GET_SHIELDS           ((menu_status_register & BIT_SHIELDS) >> 5)
#define CLEAR_BULLETS_BITS    0xE7
#define CLEAR_GAME_TYPE_BITS  0xFC
#define GET_BULLETS_BITS             ((menu_status_register & 0x18) >> 3)
#define SET_BULLETS_BITS(S_BYTE)     (menu_status_register = ((menu_status_register & CLEAR_BULLETS_BITS) | (S_BYTE << 3)))
#define GET_GAME_TYPE                (menu_status_register & 3)
#define SET_GAME_TYPE(NEW_TYPE)      (menu_status_register = ((menu_status_register & CLEAR_GAME_TYPE_BITS) | (NEW_TYPE & 3)))
#define SOUND_INVADERS_INC 1
#define SOUND_GALAXY_INC 2

    public:
      menu();
      menu(BITMAP *dest, unsigned int s_ok_max);
      menu::menu(BITMAP *dest_bmp, unsigned int s_ok_max, int *m_keys, int n);
      inline int set_dest_bitmap(BITMAP *dest_bmp) { dest = dest_bmp; };
      inline void set_pause_after_get_focus(void) { stop_sound(0); set_palette((RGB *) s_data[GAME_P].dat); if(menu_state == STATE_PLAY_THE_GAME) pause_after_get_window_focus = SIMULATE_PAUSE_AFTER_GET_FOCUS; if(menu_state == STATE_PAUSE_GAME) pause_after_get_window_focus = REPAINT_WINDOW_AFTER_GET_FOCUS; };
      int test_menu_keys(void);
      int do_menu(void);
      void draw(void);
      void remove(void);
      ~menu();
};
#endif // _MENU_H_