1 /**
2  * @file supervisor_shop.h
3  * @brief Shop supervisor
4  * @date 2012-09-02
5  * @copyright 1991-2014 TLK Games
6  * @author Bruno Ethvignot
7  * @version $Revision: 24 $
8  */
9 /*
10  * copyright (c) 1991-2014 TLK Games all rights reserved
11  * $Id: supervisor_shop.h 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
12  *
13  * TecnoballZ is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * TecnoballZ is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  * MA  02110-1301, USA.
27  */
28 #ifndef __SUPERVISOR_SHOP__
29 #define __SUPERVISOR_SHOP__
30 
31 class supervisor_shop;
32 
33 #include "../include/list_sprites.h"
34 #include "../include/sprite_mouse_pointer.h"
35 #include "../include/sprite_object.h"
36 #include "../include/controller_capsules.h"
37 #include "../include/display_text_bitmap.h"
38 #include "../include/handler_players.h"
39 #include "../include/supervisor.h"
40 #include "../include/handler_popup_menu.h"
41 #include "../include/tiles_background.h"
42 #include "../include/handler_menu_events.h"
43 
44 class supervisor_shop:public supervisor
45   {
46   public:
47     /* number maximum of bonus capsules bought */
48     static const Uint32 MAX_OF_CAPSULES_BOUGHT = 19;
49   private:
50     typedef enum
51     {
52       TEXT_INFOS = 21,
53       TEXT_WELCOME = 32,
54       TEXT_PADDLES = 21,
55       TEXT_LIVES_LEFT = 22,
56       TEXT_HOPING_HELP = 24,
57       TEXT_WAITING_CHEAT_MODE = 25,
58       TEXT_ENABLED_CHEAT_MODE = 26,
59       TEXT_PADDLE_RIGHT = 27,
60       TEXT_PADDLE_TOP = 28,
61       TEXT_PADDLE_LEFT = 29,
62       TEXT_AREA_CODE = 30,
63       TEXT_NO_AREA_CODE = 31,
64       TEXT_NOT_ENOUGH_MONEY = 33,
65       TEXT_CANNOT_BUY_MORE = 34,
66       TEXT_ONLY_FOR_AREA_5 = 35
67     } TEXT_ENUM;
68 
69     /** Enumerate differents pages of the informations option */
70     typedef enum
71     {
72       INFO_PADDLES,
73       INFO_LIVES,
74       INFO_AREA_CODE,
75       INFO_END
76     } INFO_ENUM;
77     /** Length of a text line in chars */
78     static const Uint32 BOX_LENGTH_STRING = 22;
79     /** Object handle events of the menu */
80     handler_menu_events* menu_events;
81     /** All strings loaded from a file text */
82     char** box_texts;
83     /** tiles_background object only used to initialize
84      * the colors palette */
85     tiles_background *tiles_ground;
86     /** Pointer to the sprite mouse pointer */
87     sprite_mouse_pointer *mouse_pointer;
88     /** Led who indicates the option over the mouse */
89     sprite_object *led_indicator;
90     /** Control all capsules */
91     controller_capsules *power_up_capsules;
92     /** Object which draws three lines of texts */
93     display_text_bitmap *display_text;
94     /** Object who handles the "ESC" menu */
95     handler_popup_menu *popup_menu;
96     /** Option currently selected by pressing the left mouse button */
97     Sint32 current_selected_option;
98     /** Index of the currently displayed page: INFO_PADDLES,
99      * INFO_LIVES or INFO_AREA_CODE */
100     Uint32 some_infos_index;
101     /** If true info already seen at least once */
102     bool is_already_view_info;
103     /** Current price of the selected option */
104     Uint32 current_price;
105     /** The number of bought capsules */
106     Uint32 num_of_bought_capsules;
107     /** Pointer to the 3 lignes currently displayed */
108     char *current_text_displayed[3];
109     /** Current x-coordinate of the led indicator */
110     Sint32 led_indicator_xcoord;
111     /** Current y-coordinate of the led indicator */
112     Sint32 led_indicator_ycoord;
113     /** True if the current player drag a capsule */
114     bool is_caspule_drag;
115     /** Capsule which blinks in the list when it is draged with the mouse */
116     sprite_capsule *blink_capsule;
117     /** Capsule which draged with the mouse */
118     sprite_capsule *drag_sprite;
119     /** Pointer to the currently dragged capsule in the shopping cart of the
120       * player */
121     Sint32 *dragged_capsule_pt;
122     /** Temporary shopping cart used to change a position of a capsule
123      * in the capsules list */
124     Sint32 temporary_shopping_cart[MAX_OF_CAPSULES_BOUGHT + 1];
125     Sint32 options_frame_xmin;
126     Sint32 options_frame_xmax1;
127     Sint32 options_frame_xmax2;
128     Sint32 options_frame_ymax1;
129     Sint32 options_frame_ymax2;
130     /** Index on the selected capsule in the list of bonus capsules bought,
131      * otherwise negative value if no capsule is selected  */
132     Sint32 selected_capsule_index;
133     /** Index on the currently dragged capsule */
134     Sint32 dragged_capsule_index;
135     /** True if drawn the select cursor */
136     bool is_drawn_select_cursor;
137     /** Top coordinate of the frame  which contains the list of bonus capsules
138       * bought */
139     Sint32 capsules_frame_ymin;
140     /** Bottom coordinate of the frame  which contains the list of bonus
141       * capsules bought */
142     Sint32 capsules_frame_ymax;
143     /*** Current X coordinate of the select cursor */
144     Sint32 select_cursor_xcoord;
145     /*** Current Y coordinate of the select cursor */
146     Sint32 select_cursor_ycoord;
147     /** Maximum height of the select cursor in pixels */
148     Sint32 select_cursor_height;
149     /** Maximum width of the select cursor in pixels */
150     Uint32 select_cursor_width;
151     /** Sinus table index from 0 to 511 used to modify the size of the cursor */
152     Sint32 select_cursor_sin_index;
153     /** Indexed color of the select cursor from 0 to 32 */
154     Sint32 select_cursor_color;
155     /** Code of the last key pressed, used for input cheat code */
156     Uint32 previous_key_code_down;
157     /** Current cheat code which was typed by the player */
158     Uint32 cheat_code_input;
159     /** Cheat code is an unsigned 32 bits integer,
160      * a string of 4 chars containing the keycodes "ETB\n" */
161     Uint32 cheat_code;
162     /** Identifiers of the available options and bonus capsules */
163     static Sint32 available_options_id[];
164     /** Prices of all the available options in the shop */
165     static Uint32 options_prices[];
166     /** Indexes of the texts used for sales confirmation messages */
167     static unsigned char led_index_to_text_index[];
168 
169   public:
170     supervisor_shop ();
171     ~supervisor_shop ();
172     void first_init ();
173     Uint32 main_loop ();
174 
175   private:
176     Sint32 get_option_over_mouse_cursor (Sint32 x, Sint32 y);
177     void purchase_option_or_capsule (Uint32 option_id);
178     void display_info();
179     void display_capsules_bought ();
180     void purchase_bonus_capsule (Sint32 option_num);
181     void display_sales_confirmation (Sint32 option_index);
182     Uint32 get_price_and_update_led (Sint32 index);
183 
184     bool decrease_money_amount ();
185     void put_current_text (char *str);
186     void display_box_text ();
187     void capsule_drag_and_drop ();
188     Sint32 collisions ();
189     void set_select_cursor_coordinates ();
190     void draw_select_cursor ();
191     void check_if_enable_cheat ();
192 
193     static const unsigned char color_cycling[];
194   };
195 #endif
196