1 /* GNU Robbo
2 * Copyright (C) 2002-2010 The GNU Robbo Team (see AUTHORS).
3 *
4 * GNU Robbo is free software - you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * GNU Robbo is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the impled warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with GNU CC; see the file COPYING. If not, write to the
16 * Free Software Foundation, 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 */
20
21 #include "game.h"
22
23 /* Defines */
24 /*
25 #define DEBUG_POINTER_CONTROLS
26 */
27
28 #define BUTTON_ALPHA_NORMAL 48
29 #define BUTTON_ALPHA_MOVE_SHOOT 80
30 #define BUTTON_COLOUR_SHOOT_PRESS 0xff8000
31 #define BUTTON_COLOUR_SHOOT_CLICK 0xff0000
32 #define BUTTON_COLOUR_DIRECTIONS 0xffffff
33 #define BUTTON_COLOUR_HIGHLIGHT 0x505050
34
35 /* Variables */
36 SDL_Rect toolbar_intro_screen_image_srcrect;
37 SDL_Rect toolbar_options_image_srcrect;
38 SDL_Rect toolbar_designer_image_srcrect;
39 SDL_Rect toolbar_restart_image_srcrect;
40 SDL_Rect toolbar_hide_image_srcrect;
41
42 /* Function prototypes */
43
44
45 /***************************************************************************
46 * Pointer Controls Event Processor *
47 ***************************************************************************/
48 /* This receives events from the ROB engine for the pointer controls */
49
pointer_controls_event_processor(ROB_Event * rob_event)50 void pointer_controls_event_processor(ROB_Event *rob_event) {
51 int move_actionid = 0, shoot_actionid = 0, set = FALSE;
52
53 #ifdef DEBUG_POINTER_CONTROLS
54 ROB_ShowEvent(rob_event, __func__);
55 #endif
56
57 /* We're only interested in pointer controls events */
58 if (rob_event->rob_object->id >= POINTER_CONTROLS_ID &&
59 rob_event->rob_object->id <= POINTER_CONTROLS_TOOLBAR_HIDE_ID) {
60
61 /* Most of this is state changing but if something needs to be executed on-click
62 then it is done from here */
63 switch (rob_event->rob_object->id) {
64 case POINTER_CONTROLS_ID:
65 if (rob_event->klasse == ROB_EVENT_CLICK) {
66 pointer_controls.state = POINTER_CONTROLS_MODE_ON;
67 show_pointer_controls_toolbar();
68 } else if (rob_event->klasse == ROB_EVENT_RELEASE) {
69 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_OFF_DRAG) {
70 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_OFF;
71 } else if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_CLICK_DRAG) {
72 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_CLICK;
73 }
74 }
75 break;
76 case POINTER_CONTROLS_SHOOT_ID:
77 if (rob_event->klasse == ROB_EVENT_PRESS) {
78 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_OFF) {
79 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_OFF_DRAG;
80 } else if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_CLICK) {
81 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_CLICK_DRAG;
82 }
83 } else if (rob_event->klasse == ROB_EVENT_CLICK) {
84 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_OFF_DRAG) {
85 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_CLICK;
86 } else if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_CLICK_DRAG) {
87 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_OFF;
88 }
89 }
90 break;
91 case POINTER_CONTROLS_UP_ID:
92 move_actionid = ACTION_UP; shoot_actionid = ACTION_SHOOT_UP; set = TRUE;
93 case POINTER_CONTROLS_RIGHT_ID:
94 if (!set) {
95 move_actionid = ACTION_RIGHT; shoot_actionid = ACTION_SHOOT_RIGHT; set = TRUE;
96 }
97 case POINTER_CONTROLS_DOWN_ID:
98 if (!set) {
99 move_actionid = ACTION_DOWN; shoot_actionid = ACTION_SHOOT_DOWN; set = TRUE;
100 }
101 case POINTER_CONTROLS_LEFT_ID:
102 if (!set) {
103 move_actionid = ACTION_LEFT; shoot_actionid = ACTION_SHOOT_LEFT; set = TRUE;
104 }
105 if (rob_event->klasse == ROB_EVENT_RELEASE) {
106 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_OFF_DRAG) {
107 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_OFF;
108 manage_game_on_input(shoot_actionid);
109 } else if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_CLICK_DRAG) {
110 pointer_controls.shoot_state = POINTER_CONTROLS_SHOOT_CLICK;
111 manage_game_on_input(shoot_actionid);
112 }
113 } else if (rob_event->klasse == ROB_EVENT_SELECT) {
114 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_CLICK) {
115 manage_game_on_input(shoot_actionid);
116 } else {
117 manage_game_on_input(move_actionid);
118 }
119 }
120 break;
121 case POINTER_CONTROLS_TOOLBAR_ID:
122 if (rob_event->klasse == ROB_EVENT_CLICK) {
123 }
124 break;
125 case POINTER_CONTROLS_TOOLBAR_INTRO_SCREEN_ID:
126 if (rob_event->klasse == ROB_EVENT_CLICK) {
127 manage_game_on_input(ACTION_EXIT);
128 }
129 break;
130 case POINTER_CONTROLS_TOOLBAR_OPTIONS_ID:
131 if (rob_event->klasse == ROB_EVENT_CLICK) {
132 manage_game_on_input(ACTION_OPTIONS);
133 }
134 break;
135 case POINTER_CONTROLS_TOOLBAR_DESIGNER_ID:
136 if (rob_event->klasse == ROB_EVENT_CLICK) {
137 manage_game_on_input(ACTION_TOGGLE_DESIGNER);
138 }
139 break;
140 case POINTER_CONTROLS_TOOLBAR_RESTART_ID:
141 if (rob_event->klasse == ROB_EVENT_CLICK) {
142 manage_game_on_input(ACTION_RESTART);
143 }
144 break;
145 case POINTER_CONTROLS_TOOLBAR_HIDE_ID:
146 if (rob_event->klasse == ROB_EVENT_CLICK) {
147 pointer_controls.state = POINTER_CONTROLS_MODE_OFF;
148 hide_pointer_controls_pad();
149 hide_pointer_controls_toolbar();
150 game_area.redraw |= REDRAW_EVERYTHING;
151 }
152 break;
153 }
154 }
155 }
156
157 /***************************************************************************
158 * Create Pointer Controls *
159 ***************************************************************************/
160 /*
161 ---------------------------------------- There's a transparent rectangle that covers the entire screen
162 | |#|#|#|#| which is always manipulatable in-game. This rectangle is the
163 | ---------------------------------- | ancestor of all the pointer controls and when clicked will
164 | | | | | | make visible the pointer controls pad and toolbar.
165 | | | | | |
166 | | | | | | Centred over Robbo is a shoot rectangle that is the parent to
167 | | | | | | the four directional rectangles that extend to the viewport
168 | |--------------|--|--------------| | edges. Pressing the directional buttons sends Robbo off in the
169 | | | | | | corresponding direction. Dragging from the shoot button to one
170 | |--------------|--|--------------| | of the direction buttons shoots once. Clicking the shoot button
171 | | | | | | toggles shoot mode on and off. If shoot mode is on then pressing
172 | | | | | | a direction makes Robbo repeatedly shoot instead of walk.
173 | | | | | |
174 | | | | | | Top right is a toolbar parent with currently four buttons that
175 | ---------------------------------- | perform useful and necessary tasks. Clicking the left-most button
176 | | will make invisible the pad and toolbar.
177 ----------------------------------------
178 Note that when the pointer controls are visible, the entire viewport must be redrawn every frame which
179 is not the norm and increases CPU usage. Normally only the tiles that have changed are redrawn. If the
180 direction buttons extend outside of the viewport then the entire screen must be redrawn every frame which
181 increases CPU usage even more and that is the reason why the default boundary is the viewport.
182 */
183
create_pointer_controls(void)184 void create_pointer_controls(void) {
185 ROB_Object rob_object;
186
187 if (video.field_size == 16) {
188 toolbar_intro_screen_image_srcrect = set_rect(188, 1, video.field_size, video.field_size);
189 toolbar_options_image_srcrect = set_rect(188, 18, video.field_size, video.field_size);
190 toolbar_designer_image_srcrect = set_rect(188, 69, video.field_size, video.field_size);
191 toolbar_restart_image_srcrect = set_rect(188, 35, video.field_size, video.field_size);
192 toolbar_hide_image_srcrect = set_rect(188, 52, video.field_size, video.field_size);
193 } else if (video.field_size == 32) {
194 toolbar_intro_screen_image_srcrect = set_rect(376, 2, video.field_size, video.field_size);
195 toolbar_options_image_srcrect = set_rect(376, 36, video.field_size, video.field_size);
196 toolbar_designer_image_srcrect = set_rect(376, 138, video.field_size, video.field_size);
197 toolbar_restart_image_srcrect = set_rect(376, 70, video.field_size, video.field_size);
198 toolbar_hide_image_srcrect = set_rect(376, 104, video.field_size, video.field_size);
199 }
200
201 /* Create the parent object which will be used to identify the group */
202 if (ROB_SetObjectDefaults(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
203 rob_object.id = POINTER_CONTROLS_ID;
204 rob_object.w = screen->w;
205 rob_object.h = screen->h;
206 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
207
208 /* Create the pointer controls pad */
209 /* Create the shoot button which will be the parent to the directions */
210 if (ROB_SetObjectDefaults(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
211 rob_object.id = POINTER_CONTROLS_SHOOT_ID;
212 rob_object.pid = POINTER_CONTROLS_ID;
213 rob_object.alpha = BUTTON_ALPHA_NORMAL;
214 rob_object.alpha_press = BUTTON_ALPHA_MOVE_SHOOT;
215 rob_object.bgcolour_press = BUTTON_COLOUR_SHOOT_PRESS;
216 rob_object.x = 0;
217 rob_object.y = 0;
218 rob_object.w = video.field_size * 2;
219 rob_object.h = video.field_size * 2;
220 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
221 /* Create the up button */
222 if (ROB_SetObjectDefaults(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
223 rob_object.id = POINTER_CONTROLS_UP_ID;
224 rob_object.pid = POINTER_CONTROLS_SHOOT_ID;
225 rob_object.alpha = BUTTON_ALPHA_NORMAL;
226 rob_object.alpha_press = BUTTON_ALPHA_MOVE_SHOOT;
227 rob_object.bgcolour = BUTTON_COLOUR_DIRECTIONS;
228 rob_object.x = 0;
229 rob_object.y = 0;
230 rob_object.w = video.field_size * 2;
231 rob_object.h = 0;
232 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
233 /* Create the right button */
234 rob_object.id = POINTER_CONTROLS_RIGHT_ID;
235 rob_object.x = video.field_size * 2;
236 rob_object.y = 0;
237 rob_object.w = 0;
238 rob_object.h = video.field_size * 2;
239 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
240 /* Create the down button */
241 rob_object.id = POINTER_CONTROLS_DOWN_ID;
242 rob_object.x = 0;
243 rob_object.y = video.field_size * 2;
244 rob_object.w = video.field_size * 2;
245 rob_object.h = 0;
246 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
247 /* Create the left button */
248 rob_object.id = POINTER_CONTROLS_LEFT_ID;
249 rob_object.x = 0;
250 rob_object.y = 0;
251 rob_object.w = 0;
252 rob_object.h = video.field_size * 2;
253 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
254
255 /* Create the pointer controls toolbar */
256 /* Create the toolbar which will be the parent to the toolbar buttons */
257 if (ROB_SetObjectDefaults(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
258 rob_object.id = POINTER_CONTROLS_TOOLBAR_ID;
259 rob_object.pid = POINTER_CONTROLS_ID;
260 rob_object.w = video.field_size * 5 + video.field_size / 4 * 6;
261 rob_object.h = video.field_size + video.field_size / 4 * 2;
262 rob_object.x = screen->w - rob_object.w;
263 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
264 /* Create the Intro Screen button */
265 if (ROB_SetObjectDefaults(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
266 rob_object.id = POINTER_CONTROLS_TOOLBAR_INTRO_SCREEN_ID;
267 rob_object.pid = POINTER_CONTROLS_TOOLBAR_ID;
268 rob_object.w = rob_object.h = video.field_size;
269 rob_object.x = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)->w - rob_object.w - video.field_size / 4;
270 rob_object.y = video.field_size / 4;
271 rob_object.img_surface = icons;
272 rob_object.img_x = toolbar_intro_screen_image_srcrect.x;
273 rob_object.img_y = toolbar_intro_screen_image_srcrect.y;
274 rob_object.img_w = toolbar_intro_screen_image_srcrect.w;
275 rob_object.img_h = toolbar_intro_screen_image_srcrect.h;
276 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
277 /* Create the Options button */
278 rob_object.id = POINTER_CONTROLS_TOOLBAR_OPTIONS_ID;
279 rob_object.x = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)->w - rob_object.w * 2 - video.field_size / 4 * 2;
280 rob_object.img_x = toolbar_options_image_srcrect.x;
281 rob_object.img_y = toolbar_options_image_srcrect.y;
282 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
283 /* Create the Designer button */
284 rob_object.id = POINTER_CONTROLS_TOOLBAR_DESIGNER_ID;
285 rob_object.x = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)->w - rob_object.w * 3 - video.field_size / 4 * 3;
286 rob_object.img_x = toolbar_designer_image_srcrect.x;
287 rob_object.img_y = toolbar_designer_image_srcrect.y;
288 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
289 /* Create the Restart button */
290 rob_object.id = POINTER_CONTROLS_TOOLBAR_RESTART_ID;
291 rob_object.x = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)->w - rob_object.w * 4 - video.field_size / 4 * 4;
292 rob_object.img_x = toolbar_restart_image_srcrect.x;
293 rob_object.img_y = toolbar_restart_image_srcrect.y;
294 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
295 /* Create the hide button */
296 rob_object.id = POINTER_CONTROLS_TOOLBAR_HIDE_ID;
297 rob_object.x = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)->w - rob_object.w * 5 - video.field_size / 4 * 5;
298 rob_object.img_x = toolbar_hide_image_srcrect.x;
299 rob_object.img_y = toolbar_hide_image_srcrect.y;
300 if (ROB_CreateObject(&rob_object)) printf("%s: %s\n", __func__, ROB_GetError());
301
302 /* Set-up the controls depending on pointer_controls.state */
303 hide_pointer_controls();
304 if (pointer_controls.state == POINTER_CONTROLS_MODE_ON) {
305 show_pointer_controls_pad();
306 show_pointer_controls_toolbar();
307 } else {
308 hide_pointer_controls_pad();
309 hide_pointer_controls_toolbar();
310 }
311 update_pointer_controls_toolbar();
312 }
313
314 /***************************************************************************
315 * Show Pointer Controls *
316 ***************************************************************************/
317 /* This shows the parent which could reveal the pad and toolbar if they haven't
318 been independently hidden. It also currently enables/disables the parent
319 depending on the demo_mode state */
320
show_pointer_controls(void)321 void show_pointer_controls(void) {
322 ROB_Object *rob_object;
323
324 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_ID)) != NULL) {
325 rob_object->visible = rob_object->enabled = ROB_INHERITED;
326 if (demo_mode(DEMO_MODE_IS_ACTIVE, 0)) rob_object->enabled = FALSE;
327 }
328 }
329
330 /***************************************************************************
331 * Show Pointer Controls Pad *
332 ***************************************************************************/
333 /* This shows the pad only */
334
show_pointer_controls_pad(void)335 void show_pointer_controls_pad(void) {
336 ROB_Object *rob_object;
337
338 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID)) != NULL) rob_object->visible = ROB_INHERITED;
339 }
340
341 /***************************************************************************
342 * Show Pointer Controls Toolbar *
343 ***************************************************************************/
344 /* This shows the toolbar only */
345
show_pointer_controls_toolbar(void)346 void show_pointer_controls_toolbar(void) {
347 ROB_Object *rob_object;
348
349 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)) != NULL) rob_object->visible = ROB_INHERITED;
350 }
351
352 /***************************************************************************
353 * Hide Pointer Controls *
354 ***************************************************************************/
355 /* This will hide all the pointer controls because the visible property will be inherited */
356
hide_pointer_controls(void)357 void hide_pointer_controls(void) {
358 ROB_Object *rob_object;
359
360 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_ID)) != NULL) rob_object->visible = FALSE;
361 }
362
363 /***************************************************************************
364 * Hide Pointer Controls Pad *
365 ***************************************************************************/
366 /* This hides the pad only */
367
hide_pointer_controls_pad(void)368 void hide_pointer_controls_pad(void) {
369 ROB_Object *rob_object;
370
371 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID)) != NULL) rob_object->visible = FALSE;
372 }
373
374 /***************************************************************************
375 * Hide Pointer Controls Toolbar *
376 ***************************************************************************/
377 /* This hides the toolbar only */
378
hide_pointer_controls_toolbar(void)379 void hide_pointer_controls_toolbar(void) {
380 ROB_Object *rob_object;
381
382 if ((rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_ID)) != NULL) rob_object->visible = FALSE;
383 }
384
385 /***************************************************************************
386 * Update Pointer Controls Pad *
387 ***************************************************************************/
388 /* This function :-
389 * Centres the pad's shoot button over Robbo and adjusts it when he's up against the viewport edges if required
390 * Extends the visible pad direction buttons right up to the viewport or screen boundary
391 * Maintains object properties affected by the shoot state */
392
update_pointer_controls_pad(int robbo_xoffset,int robbo_yoffset)393 void update_pointer_controls_pad(int robbo_xoffset, int robbo_yoffset) {
394 ROB_Object *pob, *rob_object;
395
396 if (ROB_GetObject(POINTER_CONTROLS_ID) != NULL) {
397
398 /* Update shoot button position */
399 if (pointer_controls.pad_type == POINTER_CONTROLS_PAD_TYPE_VIEWPORT) {
400 /* Centre the shoot button over Robbo and offset it at the viewport edges */
401 pob = rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID);
402 if (robbo.x - viewport.x < 2) {
403 rob_object->x = robbo_xoffset;
404 } else if (robbo.x > viewport.x + viewport.w - 3) {
405 rob_object->x = robbo_xoffset - rob_object->w / 2;
406 } else {
407 rob_object->x = robbo_xoffset - rob_object->w / 4;
408 }
409 if (robbo.y - viewport.y < 2) {
410 rob_object->y = robbo_yoffset;
411 } else if (robbo.y > viewport.y + viewport.h - 3) {
412 rob_object->y = robbo_yoffset - rob_object->h / 2;
413 } else {
414 rob_object->y = robbo_yoffset - rob_object->h / 4;
415 }
416 } else { /* if (pointer_controls.pad_type == POINTER_CONTROLS_PAD_TYPE_SCREEN) { */
417 /* Centre the shoot button over Robbo */
418 pob = rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID);
419 rob_object->x = robbo_xoffset - rob_object->w / 4;
420 rob_object->y = robbo_yoffset - rob_object->h / 4;
421 }
422
423 /* Update direction button positions and dimensions */
424 if (pointer_controls.pad_type == POINTER_CONTROLS_PAD_TYPE_VIEWPORT) {
425 /* Stretch the up button all the way to the edge of the viewport */
426 rob_object = ROB_GetObject(POINTER_CONTROLS_UP_ID);
427 rob_object->y = 0 - (pob->y - viewport.yoffset);
428 rob_object->h = pob->y - viewport.yoffset;
429 /* Stretch the right button all the way to the edge of the viewport */
430 rob_object = ROB_GetObject(POINTER_CONTROLS_RIGHT_ID);
431 rob_object->w = viewport.xoffset + viewport.w * video.field_size - pob->x - pob->w;
432 /* Stretch the down button all the way to the edge of the viewport */
433 rob_object = ROB_GetObject(POINTER_CONTROLS_DOWN_ID);
434 rob_object->h = viewport.yoffset + viewport.h * video.field_size - pob->y - pob->h;
435 /* Stretch the left button all the way to the edge of the viewport */
436 rob_object = ROB_GetObject(POINTER_CONTROLS_LEFT_ID);
437 rob_object->x = 0 - (pob->x - viewport.xoffset);
438 rob_object->w = pob->x - viewport.xoffset;
439 } else if (pointer_controls.pad_type == POINTER_CONTROLS_PAD_TYPE_SCREEN) {
440 /* Stretch the up button all the way to the edge of the screen */
441 rob_object = ROB_GetObject(POINTER_CONTROLS_UP_ID);
442 rob_object->y = 0 - pob->y;
443 rob_object->h = pob->y;
444 /* Stretch the right button all the way to the edge of the screen */
445 rob_object = ROB_GetObject(POINTER_CONTROLS_RIGHT_ID);
446 rob_object->w = screen->w - pob->x - pob->w;
447 /* Stretch the down button all the way to the edge of the screen */
448 rob_object = ROB_GetObject(POINTER_CONTROLS_DOWN_ID);
449 rob_object->h = screen->h - pob->y - pob->h;
450 /* Stretch the left button all the way to the edge of the screen */
451 rob_object = ROB_GetObject(POINTER_CONTROLS_LEFT_ID);
452 rob_object->x = 0 - pob->x;
453 rob_object->w = pob->x;
454 }
455
456 /* Update some of the object properties for the current shoot state */
457 switch (pointer_controls.shoot_state) {
458 case POINTER_CONTROLS_SHOOT_OFF:
459 rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID);
460 rob_object->bgcolour = rob_object->bgcolour_over = ROB_UNDEFINED;
461 user_controls[ACTION_PRIMARY_CLICK].delay = 0;
462 user_controls[ACTION_PRIMARY_CLICK].interval = 0;
463 case POINTER_CONTROLS_SHOOT_CLICK:
464 ROB_GetObject(POINTER_CONTROLS_UP_ID)->alpha_over = ROB_UNDEFINED;
465 ROB_GetObject(POINTER_CONTROLS_RIGHT_ID)->alpha_over = ROB_UNDEFINED;
466 ROB_GetObject(POINTER_CONTROLS_DOWN_ID)->alpha_over = ROB_UNDEFINED;
467 ROB_GetObject(POINTER_CONTROLS_LEFT_ID)->alpha_over = ROB_UNDEFINED;
468 if (pointer_controls.shoot_state == POINTER_CONTROLS_SHOOT_OFF) break;
469 rob_object = ROB_GetObject(POINTER_CONTROLS_SHOOT_ID);
470 rob_object->bgcolour = BUTTON_COLOUR_SHOOT_CLICK;
471 user_controls[ACTION_PRIMARY_CLICK].delay = ACTION_SHOOT_REPEAT_DELAY_PERIOD;
472 user_controls[ACTION_PRIMARY_CLICK].interval = ACTION_SHOOT_REPEAT_DELAY_PERIOD;
473 break;
474 case POINTER_CONTROLS_SHOOT_OFF_DRAG:
475 case POINTER_CONTROLS_SHOOT_CLICK_DRAG:
476 ROB_GetObject(POINTER_CONTROLS_UP_ID)->alpha_over = BUTTON_ALPHA_MOVE_SHOOT;
477 ROB_GetObject(POINTER_CONTROLS_RIGHT_ID)->alpha_over = BUTTON_ALPHA_MOVE_SHOOT;
478 ROB_GetObject(POINTER_CONTROLS_DOWN_ID)->alpha_over = BUTTON_ALPHA_MOVE_SHOOT;
479 ROB_GetObject(POINTER_CONTROLS_LEFT_ID)->alpha_over = BUTTON_ALPHA_MOVE_SHOOT;
480 user_controls[ACTION_PRIMARY_CLICK].delay = ACTION_SHOOT_REPEAT_DELAY_PERIOD;
481 user_controls[ACTION_PRIMARY_CLICK].interval = ACTION_SHOOT_REPEAT_DELAY_PERIOD;
482 break;
483 }
484 }
485 }
486
487 /***************************************************************************
488 * Update Pointer Controls Toolbar *
489 ***************************************************************************/
490 /* This function :-
491 * Maintains the toolbar button colours to match the level
492 * Maintains the toolbar button image surface pointers
493 * Maintains the visibility of the toolbar buttons */
494
update_pointer_controls_toolbar(void)495 void update_pointer_controls_toolbar(void) {
496 ROB_Object *rob_object;
497 Uint32 level_colour;
498
499 if (ROB_GetObject(POINTER_CONTROLS_ID) != NULL) {
500 if (level.colour_override != UNDEFINED) {
501 level_colour = level.colour_override;
502 } else if (level.colour != UNDEFINED) {
503 level_colour = level.colour;
504 } else {
505 level_colour = DEFAULT_LEVEL_COLOUR;
506 }
507 rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_INTRO_SCREEN_ID);
508 rob_object->bgcolour = level_colour;
509 rob_object->bgcolour_over = level_colour | BUTTON_COLOUR_HIGHLIGHT;
510 rob_object->img_surface = icons;
511 rob_object->visible = ROB_INHERITED;
512 rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_OPTIONS_ID);
513 rob_object->bgcolour = level_colour;
514 rob_object->bgcolour_over = level_colour | BUTTON_COLOUR_HIGHLIGHT;
515 rob_object->img_surface = icons;
516 rob_object->visible = ROB_INHERITED;
517 rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_DESIGNER_ID);
518 rob_object->bgcolour = level_colour;
519 rob_object->bgcolour_over = level_colour | BUTTON_COLOUR_HIGHLIGHT;
520 rob_object->img_surface = icons;
521 rob_object->visible = ROB_INHERITED;
522 rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_RESTART_ID);
523 rob_object->bgcolour = level_colour;
524 rob_object->bgcolour_over = level_colour | BUTTON_COLOUR_HIGHLIGHT;
525 rob_object->img_surface = icons;
526 rob_object->visible = ROB_INHERITED;
527 rob_object = ROB_GetObject(POINTER_CONTROLS_TOOLBAR_HIDE_ID);
528 rob_object->bgcolour = level_colour;
529 rob_object->bgcolour_over = level_colour | BUTTON_COLOUR_HIGHLIGHT;
530 rob_object->img_surface = icons;
531 rob_object->visible = ROB_INHERITED;
532 }
533 }
534
535
536
537
538
539
540
541