Debian Codegraph @

lib/Games/FrozenBubble/LevelEditor.pm

raw
1 package Games::FrozenBubble::LevelEditor;
2
3 use POSIX(qw(floor ceil));
4 use SDL;
5 use SDLx::App;
6 use SDL::Video;
7 use SDL::Surface;
8 use SDL::Image;
9 use SDL::Events;
10 use SDL::Event;
11 use SDL::Mouse;
12 use SDL::Cursor;
13 use SDL::TTF;
14 use SDL::TTF::Font;
15 use SDLx::SFont;
16 use SDL::Mixer;
17 use File::Glob qw(bsd_glob);
18
19 use Games::FrozenBubble::Stuff;
20 use Games::FrozenBubble::Symbols;
21
22 use strict;
23 our ($NUM_ROWS, $NUM_BUBBLES_AVAIL,
24 $BUBBLES_PER_ROW, $BUBBLE_OPTION_SEPARATION, $BUBBLE_OPTION_INIT_X,
25 $ALPHA_BUBBLE_NO, $ALPHA_BUBBLE_YES, $WOOD_WIDTH, $WOOD_PLANK_HEIGHT,
26 $LEFT_WOOD_X, $RIGHT_WOOD_X, $BUBBLE_WOOD_Y, $NAV_WOOD_Y, $LEVELSET_WOOD_Y,
27 $LEVEL_WOOD_Y, $HELP_WOOD_Y, $colourblind, $app, $font, %bubble_rects, %bubble_hash, $color,
28 $action, $previousx, $previousy, $background, $highlight,
29 $highlighted_option, $curr_level, $displaying_dialog, $new_ls_name_text, $surface_dialog,
30 $levelset_name, $list_browser_file_start_offset, $list_browser_highlight_offset,
31 $surf_shrink, %file_browser_levelsets, @file_browser_levelsets_num_levels,
32 $deleted_current_levelset, $jump_to_level_value,
33 $modified_levelset, $modified_levelset_action, $button_hold, $command_line_fullscreen, %rect, $start_level);
34
35 $NUM_ROWS = 10;
36 $POS_1P{bottom_limit} = $POS_1P{p1}{top_limit} + $NUM_ROWS * $ROW_SIZE;
37 $NUM_BUBBLES_AVAIL = 8;
38 $BUBBLES_PER_ROW = 3;
39 $BUBBLE_OPTION_SEPARATION = 8;
40 $BUBBLE_OPTION_INIT_X = 18;
41 $ALPHA_BUBBLE_NO = 0;
42 $ALPHA_BUBBLE_YES = 1;
43
44 $WOOD_WIDTH = 150;
45 $WOOD_PLANK_HEIGHT = 40;
46 $LEFT_WOOD_X = 2;
47 $RIGHT_WOOD_X = 488;
48 $BUBBLE_WOOD_Y = 33;
49 $NAV_WOOD_Y = 209;
50 $LEVELSET_WOOD_Y = 30;
51 $LEVEL_WOOD_Y = 249;
52 $HELP_WOOD_Y = 428;
53
54 $highlighted_option = '';
55 $previousx = -1;
56 $previousy = -1;
57 $displaying_dialog = '';
58 $deleted_current_levelset = 0;
59 $button_hold = 0;
60
61
62 #- ----------- bubbles processing/drawing -----------------------------------------
63
64 # subroutine to calculate the left corner x of the given bubble option column (based on 0 start)
65 sub bubble_optionx {
66 my ($col) = @_;
67 return $BUBBLE_OPTION_INIT_X + $col * ($BUBBLE_SIZE + $BUBBLE_OPTION_SEPARATION);
68 }
69
70 # subroutine to calculate the left corner y of the given bubble option row (based on 0 start)
71 sub bubble_optiony {
72 my ($row) = @_;
73 return $BUBBLE_WOOD_Y + $WOOD_PLANK_HEIGHT + $row * ($BUBBLE_SIZE + $BUBBLE_OPTION_SEPARATION);
74 }
75
76 # subroutine to get the column
77 sub get_col {
78 my ($x, $y) = @_;
79 if (even(get_row($y))) {
80 return floor(($x-$POS_1P{p1}{left_limit})/$BUBBLE_SIZE);
81
82 } elsif ($POS_1P{p1}{left_limit} + $BUBBLE_SIZE/2 <= $x && $x < $POS_1P{p1}{right_limit} - $BUBBLE_SIZE/2) {
83 return floor(($x-($POS_1P{p1}{left_limit}+$BUBBLE_SIZE/2))/$BUBBLE_SIZE);
84
85 } else {
86 return -1;
87 }
88 }
89
90 # subroutine to get the row
91 sub get_row {
92 my ($y) = @_;
93 return floor(($y-$POS_1P{p1}{top_limit})/$ROW_SIZE);
94 }
95
96 # subroutine to draw bubbles
97 sub draw_bubble {
98 my ($bubbleid, $x, $y, $alpha, $surface_tmp, $ignore_update) = @_;
99 my ($bubble);
100
101 $surface_tmp or $surface_tmp = $app;
102 $bubble = SDL::Image::load( "$FPATH/gfx/balls/bubble-".($colourblind && 'colourblind-')."$bubbleid.gif");
103
104 $bubble_rects{$x}{$y} = SDL::Rect->new($x, $y, $bubble->w, $bubble->h);
105
106 $alpha and SDL::Video::set_alpha($bubble, SDL_SRCALPHA, 0x66);
107
108 SDL::Video::blit_surface($bubble, SDL::Rect->new(0,0,$bubble->w, $bubble->h), $surface_tmp, $bubble_rects{$x}{$y});
109 $ignore_update or SDL::Video::update_rects($surface_tmp, $bubble_rects{$x}{$y});
110
111 }
112
113 # subroutine to erase bubble
114 sub erase_bubble {
115 my ($x, $y) = @_;
116 SDL::Video::blit_surface( $background, $bubble_rects{$x}{$y}, $app, $bubble_rects{$x}{$y});
117 #- redraw close bubbles because the rectangular blit of the previous statement erased a bit of them
118 my $DISTANCE_CLOSE_SQRED = sqr($BUBBLE_SIZE*1.1);
119 foreach my $x_ (keys %bubble_rects) {
120 foreach my $y_ (%{$bubble_rects{$x_}}) {
121 $y != $y_ && sqr($x-$x_) + sqr($y-$y_) <= $DISTANCE_CLOSE_SQRED or next;
122 if ($bubble_hash{$curr_level}{my $col = get_col($x_, $y_)}{my $row = get_row($y_)} =~ /^\d+$/) {
123 draw_bubble($bubble_hash{$curr_level}{$col}{$row} + 1, $x_, $y_, $ALPHA_BUBBLE_NO, undef, 1);
124 }
125 }
126 }
127 SDL::Video::update_rects($app, $bubble_rects{$x}{$y});
128 }
129
130 # subroutine to place a bubble
131 sub place_bubble {
132 my ($x, $y, $alpha, $button) = @_;
133 my $col = get_col($x, $y);
134 my $row = get_row($y);
135 $y = $row * $ROW_SIZE + $POS_1P{p1}{top_limit};
136 if ($col != -1) {
137 if (even($row)) {
138 $x = get_col($x, $y) * $BUBBLE_SIZE + $POS_1P{p1}{left_limit};
139 } else {
140 $x = $col * $BUBBLE_SIZE + $POS_1P{p1}{left_limit} + $BUBBLE_SIZE/2;
141 }
142 if ($action eq 'erase' || $button == SDL_BUTTON_RIGHT) { #- when in motion, the right button is reported as button 4 !?
143 if (($previousx != $x || $previousy != $y) && $previousx != -1 && $previousy != -1
144 && $bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} ne '-') {
145 draw_bubble($bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} + 1,
146 $previousx, $previousy, $ALPHA_BUBBLE_NO);
147 }
148 if ($bubble_rects{$x}{$y}) {
149 if ($alpha && $bubble_hash{$curr_level}{$col}{$row} ne '-') {
150 if ($previousx != $x || $previousy != $y) {
151 erase_bubble($x, $y);
152 draw_bubble($bubble_hash{$curr_level}{$col}{$row} + 1, $x, $y, $alpha);
153 }
154 $previousx = $x;
155 $previousy = $y;
156 } else {
157 $bubble_hash{$curr_level}{$col}{$row} = '-';
158 erase_bubble($x, $y);
159 }
160 }
161 } elsif ($action eq 'add') {
162 if ($alpha) {
163 if ($previousx != $x || $previousy != $y) {
164 if ($previousx != -1 && $previousy != -1) {
165 if ($bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} eq '-') {
166 erase_bubble($previousx, $previousy);
167 } else {
168 draw_bubble($bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} + 1,
169 $previousx, $previousy, $ALPHA_BUBBLE_NO);
170 }
171 }
172 draw_bubble($color, $x, $y, $alpha);
173 $previousx = $x;
174 $previousy = $y;
175 }
176 } else {
177 $bubble_hash{$curr_level}{$col}{$row} = $color - 1;
178 draw_bubble($color, $x, $y, $alpha);
179 }
180 }
181 }
182 }
183
184
185 #- ----------- actions routing -----------------------------------------
186
187 # subroutine to change my color
188 sub change_color {
189 my ($new_color) = @_;
190 $color = $new_color;
191 $action = 'add';
192
193 draw_bubble($color,
194 $POS_1P{p1}{next_bubble}{x} + $POS_1P{p1}{left_limit},
195 $POS_1P{p1}{next_bubble}{y}, $ALPHA_BUBBLE_NO); #- }}})
196 }
197
198 sub highlight_option {
199 my ($option, $x, $y) = @_;
200
201 unhighlight_option($option);
202 if ($option ne $highlighted_option) {
203 $highlighted_option = $option;
204 $option =~ s/bubble-(\d+)/$1/;
205
206 if (0 < $option && $option <= $NUM_BUBBLES_AVAIL) {
207 SDL::Video::blit_surface( $highlight, $rect{bubble_option_highlight}, $app, $bubble_rects{$x}{$y});
208 SDL::Video::update_rects($app,$bubble_rects{$x}{$y});
209
210 } elsif ($option eq 'erase') {
211 SDL::Video::blit_surface( $highlight, $rect{bubble_option_highlight}, $app, $rect{erase});
212 SDL::Video::update_rects($app,$rect{erase});
213
214 } elsif ($option =~ m/arrow/){
215 eval "print_dialog_$option(1)";
216
217 } else {
218 eval "print_$option".'_text(1)';
219 }
220 }
221
222 }
223
224 sub unhighlight_option {
225 # note: will only have x and y for bubbles and erase
226 my ($no_highlight) = @_;
227 my ($col, $row);
228
229 # don't unhighlight currently highlighted option because it will cause flashing
230 if ($highlighted_option ne '' && $highlighted_option ne $no_highlight) {
231 $highlighted_option =~ s/bubble-(\d+)/$1/;
232 if (0 < $highlighted_option && $highlighted_option <= $NUM_BUBBLES_AVAIL) {
233 $col = ($highlighted_option - 1 ) % $BUBBLES_PER_ROW;
234 $row = floor(($highlighted_option - 1 ) / $BUBBLES_PER_ROW);
235
236 my $rect = $bubble_rects{bubble_optionx($col)}{bubble_optiony($row)};
237 SDL::Video::blit_surface( $background, $rect, $app, $rect);
238 SDL::Video::update_rects($app,$rect);
239
240 add_bubble_option($highlighted_option, $col, $row);
241
242 } elsif ($highlighted_option eq 'erase') {
243 SDL::Video::blit_surface( $background, $rect{erase}, $app, $rect{erase});
244 SDL::Video::update_rects($app,$rect{erase});
245
246 add_erase_option();
247
248 } elsif ($highlighted_option =~ m/arrow/) {
249 eval "print_dialog_$highlighted_option(0)";
250
251 } else {
252 eval "print_$highlighted_option".'_text(0)';
253 }
254
255 $highlighted_option = '';
256 }
257
258 }
259
260 # subroutine to decide what my mouse is telling me to do
261 sub choose_action {
262 my ($x, $y, $caller, $button) = @_;
263
264 # are we over the drawing area?
265 if ($POS_1P{p1}{left_limit} <= $x && $x < $POS_1P{p1}{right_limit} && $POS_1P{p1}{top_limit} <= $y && $y < $POS_1P{bottom_limit}) {
266 if ($caller eq 'motion' && $button_hold == 0) {
267 place_bubble($x, $y, $ALPHA_BUBBLE_YES, $button);
268 } elsif ($button_hold == 1) {
269 place_bubble($x, $y, $ALPHA_BUBBLE_NO, $button);
270 $modified_levelset = 1;
271 } else { # $caller is 'button'
272 place_bubble($x, $y, $ALPHA_BUBBLE_NO, $button);
273 $modified_levelset = 1;
274 }
275
276 # we will want to remove bubble highlight if we go out of our drawing area
277 } elsif ($previousx != -1 && $previousy != -1) {
278 if ($bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} eq '-') {
279 erase_bubble($previousx, $previousy);
280 } else {
281 draw_bubble($bubble_hash{$curr_level}{get_col($previousx, $previousy)}{get_row($previousy)} + 1,
282 $previousx, $previousy, $ALPHA_BUBBLE_NO);
283 }
284 # make sure that when we come back into the drawing area, we immediatly start
285 # doing our highlights - if we don't do this, you don't get a highlight
286 # if you come back to the same spot that you left
287 $previousx = -1;
288 $previousy = -1;
289 }
290
291 # selecting a bubble or erase bubble??
292 if ($y >= $BUBBLE_WOOD_Y + $WOOD_PLANK_HEIGHT && $y <= $BUBBLE_WOOD_Y + 4 * $WOOD_PLANK_HEIGHT
293 && $x > $BUBBLE_OPTION_INIT_X - $BUBBLE_OPTION_SEPARATION/2
294 && $x <= $BUBBLE_OPTION_INIT_X + $BUBBLES_PER_ROW * ($BUBBLE_SIZE + $BUBBLE_OPTION_SEPARATION) - $BUBBLE_OPTION_SEPARATION/2) {
295 my $col = ceil(($x - $BUBBLE_OPTION_INIT_X + $BUBBLE_OPTION_SEPARATION/2) / ($BUBBLE_SIZE + $BUBBLE_OPTION_SEPARATION));
296 my $row = ceil(($y - ($BUBBLE_WOOD_Y + $WOOD_PLANK_HEIGHT) + $BUBBLE_OPTION_SEPARATION/2) / ($BUBBLE_SIZE + $BUBBLE_OPTION_SEPARATION));
297
298 my $color_tmp = $BUBBLES_PER_ROW * ($row - 1) + $col;
299 if (0 < $color_tmp && $color_tmp <= $NUM_BUBBLES_AVAIL) {
300 highlight_option("bubble-$color_tmp", bubble_optionx($col - 1), bubble_optiony($row - 1));
301 if($caller eq 'button') {
302 change_color($color_tmp);
303 }
304 } elsif ($color_tmp == $NUM_BUBBLES_AVAIL + 1) {
305 highlight_option('erase');
306 if ($caller eq 'button') {
307 $action = 'erase';
308 erase_bubble($POS_1P{p1}{next_bubble}{x} + $POS_1P{p1}{left_limit}, $POS_1P{p1}{next_bubble}{'y'});
309 }
310 }
311
312 # check if over navigation options
313 } elsif ($LEFT_WOOD_X <= $x && $x <= $WOOD_WIDTH && $rect{prev}->y <= $y && $y <= $rect{last}->y + $rect{last}->h) {
314 my @nav_options = ({ name => 'prev',
315 unhighlight => $curr_level == 1,
316 action => sub { if ($curr_level != 1) {
317 prev_level();
318 $curr_level == 1 and unhighlight_option();
319 } } },
320 { name => 'next',
321 unhighlight => $curr_level == keys %bubble_hash,
322 action => sub { if ($curr_level != keys %bubble_hash) {
323 next_level();
324 $curr_level == keys %bubble_hash and unhighlight_option();
325 } } },
326 { name => 'first',
327 unhighlight => $curr_level == 1,
328 action => sub { if ($curr_level != 1) {
329 first_level();
330 unhighlight_option();
331 } } },
332 { name => 'last',
333 unhighlight => $curr_level == keys %bubble_hash,
334 action => sub { if ($curr_level != keys %bubble_hash) {
335 last_level();
336 unhighlight_option();
337 } } },
338 );
339
340 foreach (@nav_options) {
341 if ($rect{$_->{name}}->y <= $y && $y <= $rect{$_->{name}}->y + $rect{$_->{name}}->h) {
342 if ($_->{unhighlight}) {
343 unhighlight_option();
344 } else {
345 highlight_option($_->{name});
346 }
347 $caller eq 'button' and $_->{action}->();
348 }
349 }
350
351 # check if over levelset options
352 } elsif ($RIGHT_WOOD_X <= $x && $x <= $RIGHT_WOOD_X + $WOOD_WIDTH
353 && $y >= $rect{ls_new}->y && $y <= $rect{ls_delete}->y + $rect{ls_delete}->h) {
354 my @ls_options = ({ name => 'ls_new', action => sub { create_new_levelset_dialog() } },
355 { name => 'ls_open', action => sub { create_open_levelset_dialog() } },
356 { name => 'ls_save', action => sub { save_file() } },
357 { name => 'ls_delete', action => sub { create_delete_levelset_dialog() } });
358 foreach (@ls_options) {
359 if ($y >= $rect{$_->{name}}->y && $y <= $rect{$_->{name}}->y + $rect{$_->{name}}->h) {
360 highlight_option($_->{name});
361 $caller eq 'button' and $_->{action}->();
362 }
363 }
364
365 # check if over level options
366 } elsif ($RIGHT_WOOD_X <= $x && $x <= $RIGHT_WOOD_X + $WOOD_WIDTH
367 && $y >= $rect{lvl_insert}->y && $y <= $rect{lvl_delete}->y + $rect{lvl_delete}->h) {
368 my @lvl_options = ({ name => 'lvl_insert', action => sub { insert_level() } },
369 { name => 'lvl_append', action => sub { append_level() } },
370 { name => 'lvl_delete', action => sub { delete_level(); load_level() } });
371 foreach (@lvl_options) {
372 if ($y >= $rect{$_->{name}}->y && $y <= $rect{$_->{name}}->y + $rect{$_->{name}}->h) {
373 highlight_option($_->{name});
374 $caller eq 'button' and $_->{action}->();
375 }
376 }
377
378 # check if over help
379 } elsif ($RIGHT_WOOD_X <= $x && $x <= $RIGHT_WOOD_X + $WOOD_WIDTH
380 && $y >= $rect{help}->y && $y <= $rect{help}->y + $rect{help}->h) {
381
382 if ($caller eq 'button') {
383 create_help_dialog();
384 }
385 else {
386 highlight_option('help');
387 }
388
389 # not over an option so I may need to unhighlight
390 } else {
391 unhighlight_option();
392 }
393
394 }
395
396 # subroutine to return the list of levelsets in $FBLEVELS
397 sub get_levelset_list {
398 #my @levelsets = sort(my @dummy = all($FBLEVELS));
399 my @levelsets = map { $_ =~ s{^.*/(.*)$}{$1}; $_; } sort(bsd_glob("$FBLEVELS/*"));
400 $displaying_dialog eq 'ls_delete' and @levelsets = difference2(\@levelsets, [ 'default-levelset' ]);
401 return @levelsets;
402 }
403
404 sub betw {
405 my ($val, $min, $max) = @_;
406 $val > $min && $val < $max;
407 }
408
409 # subroutine to decide what my mouse is telling me to do in the dialog box
410 sub choose_dialog_action {
411 my ($x, $y, $caller, $event) = @_;
412 my ($ok_rect, $cancel_rect, $surface_tmp);
413
414 # todo - can we get this info somewhere else in a better way?
415 $surface_tmp = SDL::Image::load( "$FPATH/gfx/list_arrow_up.png");
416
417 $rect{middle} = get_dialog_rect();
418 # over left button
419 if (betw($x, $rect{middle}->x, $rect{middle}->x + $rect{middle}->w/2)
420 && betw($y, $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT, $rect{middle}->y + $rect{middle}->h)) {
421 if (member($displaying_dialog, qw(help ls_play ls_play_choose_level ls_nothing_to_delete ls_open_ok_only ls_new_ok_only))) {
422 # this dialog does not have a left button. return
423 unhighlight_option();
424 return 1;
425 }
426
427 if ($displaying_dialog eq 'jump') {
428 if ( is_ok_jump_value() == 1 ) {
429 highlight_option('ok');
430 } else {
431 unhighlight_option('ok');
432 return 1;
433 }
434 }
435
436 if ($displaying_dialog eq 'ls_new') {
437 if ( is_ok_filename() == 1) {
438 highlight_option('ok');
439 } else {
440 unhighlight_option('ok');
441 return 1;
442 }
443 }
444
445 $displaying_dialog ne 'ls_new' and highlight_option('ok');
446
447
448 if ($caller eq 'button') {
449 if ($displaying_dialog eq 'ls_new' && is_ok_filename() == 1) {
450 remove_dialog();
451 create_new_levelset();
452 } elsif ($displaying_dialog eq 'jump' && is_ok_jump_value() == 1) {
453 remove_dialog();
454 jump_to_level($jump_to_level_value);
455 } elsif ($displaying_dialog eq 'ls_open') {
456 open_levelset();
457 } elsif ($displaying_dialog eq 'ls_delete') {
458 delete_levelset();
459 } elsif ($displaying_dialog eq 'ls_deleted_current') {
460 create_open_levelset_dialog_ok_only();
461 } elsif ($displaying_dialog eq 'ls_save_changes') {
462 save_file();
463 $displaying_dialog = '';
464 eval($modified_levelset_action);
465 }
466 }
467
468 # over right button
469 } elsif (betw($x, $rect{middle}->x + $rect{middle}->w/2, $rect{middle}->x + $rect{middle}->w)
470 && betw($y, $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT, $rect{middle}->y + $rect{middle}->h)) {
471 if (member($displaying_dialog, qw(help ls_play ls_play_choose_level ls_nothing_to_delete ls_open_ok_only ls_new_ok_only))) {
472 if ($displaying_dialog eq 'ls_new_ok_only' && is_ok_filename() == 1) {
473 highlight_option('ok_right');
474 } else {
475 unhighlight_option('ok_right');
476 }
477
478 if ($displaying_dialog eq 'ls_nothing_to_delete') {
479 highlight_option('ok_right');
480 if ($caller eq 'button') {
481 $displaying_dialog = '';
482 remove_dialog();
483 }
484 }
485
486 $displaying_dialog ne 'ls_new_ok_only' and highlight_option('ok_right');
487
488 if ($caller eq 'button') {
489 if ($displaying_dialog eq 'help') {
490 $displaying_dialog = '';
491 remove_dialog();
492 }
493 if (member($displaying_dialog, qw(ls_play ls_play_choose_level))) {
494 my @levelsets = get_levelset_list();
495 $modified_levelset_action = "return $levelsets[$list_browser_highlight_offset]";
496 return 1;
497
498 } elsif ($displaying_dialog eq 'ls_open_ok_only') {
499 remove_dialog();
500 $displaying_dialog = '';
501 open_levelset();
502
503 } elsif ($displaying_dialog eq 'ls_new_ok_only' && is_ok_filename() == 1) {
504 remove_dialog();
505 create_new_levelset();
506 }
507 }
508 } else {
509 # still over right button, but for these dialogs, it is the cancel button
510 highlight_option('cancel');
511 if ($caller eq 'button') {
512 if ($displaying_dialog eq 'ls_open' && $deleted_current_levelset == 1) {
513 remove_dialog();
514 create_deleted_current_levelset_dialog();
515
516 } elsif ($displaying_dialog eq 'ls_deleted_current') {
517 $levelset_name = 'default-levelset';
518 %bubble_hash = read_file($levelset_name);
519 $curr_level = 1;
520 $displaying_dialog = '';
521 remove_dialog();
522 load_level();
523 print_levelset_name();
524 $deleted_current_levelset = 0;
525
526 } elsif ($displaying_dialog eq 'ls_save_changes') {
527 $displaying_dialog = '';
528 eval($modified_levelset_action);
529
530 } else {
531 # all other dialogs
532 remove_dialog();
533 }
534 }
535 }
536
537 } elsif (member($displaying_dialog, qw(ls_open_ok_only ls_open ls_delete ls_play ls_play_choose_level))) {
538 if (betw($x, $rect{middle}->x + 4 * $rect{middle}->w/6, $rect{middle}->x + 4 * $rect{middle}->w/6 + $surface_tmp->w)) {
539 my @arrows = ($rect{dialog_file_list}->y + 2,
540 $rect{dialog_file_list}->y + $rect{dialog_file_list}->h - $surface_tmp->h - 2);
541 if (betw($y, $arrows[0], $arrows[0] + $surface_tmp->h)) {
542 $caller eq 'button' and display_levelset_list_browser($list_browser_file_start_offset - 1, $list_browser_highlight_offset);
543 highlight_option('list_arrow_up');
544
545 } elsif (betw($y, $arrows[1], $arrows[1] + $surface_tmp->h)) {
546 $caller eq 'button' and display_levelset_list_browser($list_browser_file_start_offset + 1, $list_browser_highlight_offset);
547 highlight_option('list_arrow_down');
548
549 } else {
550 unhighlight_option();
551 }
552 } elsif (betw($x, $rect{dialog_file_list}->x, $rect{dialog_file_list}->x + $rect{dialog_file_list}->w)
553 && betw($y, $rect{dialog_file_list}->y, $rect{dialog_file_list}->y + $rect{dialog_file_list}->h)) {
554 if ($caller eq 'button') {
555 if ($y < $rect{dialog_file_list}->y + 25) {
556 display_levelset_list_browser($list_browser_file_start_offset, $list_browser_file_start_offset);
557 } elsif ($y < $rect{dialog_file_list}->y + 2 * 25) {
558 display_levelset_list_browser($list_browser_file_start_offset, $list_browser_file_start_offset + 1);
559 } elsif ($y < $rect{dialog_file_list}->y + 3 * 25) {
560 display_levelset_list_browser($list_browser_file_start_offset, $list_browser_file_start_offset + 2);
561 } else {
562 display_levelset_list_browser($list_browser_file_start_offset, $list_browser_file_start_offset + 3);
563 }
564 if ($displaying_dialog eq 'ls_play_choose_level') {
565 #- we've potentially selected another level. Make sure the start level
566 #- that was previously selected is valid
567 if (is_ok_select_start_value($start_level) == 0) {
568 #- we're over (since we can't be under) so go to the last
569 #- level in this new set
570 $start_level = $file_browser_levelsets_num_levels[$list_browser_highlight_offset];
571 show_selected_level();
572 }
573
574 }
575 }
576 } elsif ($displaying_dialog eq 'ls_play_choose_level' && betw($x, 435, 470)) {
577 my $more = $x > 452 ? '_more' : '';
578 if (betw($y, $rect{middle}->y + 180, $rect{middle}->y + 200)) {
579 highlight_option("select_level_arrow_up$more");
580 if ($caller eq 'button') {
581 modify_selected_level($event, "up$more");
582 }
583 } elsif (betw($y, $rect{middle}->y + 202, $rect{middle}->y + 222)) {
584 highlight_option("select_level_arrow_down$more");
585 if ($caller eq 'button') {
586 modify_selected_level($event, "down$more");
587 }
588 } else {
589 unhighlight_option();
590 }
591 } else {
592 unhighlight_option();
593 }
594 } else {
595 unhighlight_option();
596 }
597 }
598
599 # react to user's keyboard and mouse events
600 sub handle_events {
601 my $event = SDL::Event->new;
602
603 while (1) {
604 SDL::Events::pump_events();
605 if (SDL::Events::poll_event($event) != 0) {
606
607 if ($event->type == SDL_MOUSEMOTION) {
608 #TODO: Change this ->button_x stuff to new api
609 if ($displaying_dialog eq '') {
610 choose_action($event->button_x, $event->button_y, 'motion', $event->button_button); #- , )
611 } else {
612 choose_dialog_action($event->button_x, $event->button_y, 'motion'); #- ,, )
613 }
614 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
615
616 } elsif ($event->type == SDL_MOUSEBUTTONDOWN) {
617 $button_hold = 1;
618 if ($displaying_dialog eq '') {
619 choose_action($event->button_x, $event->button_y, 'button', $event->button_button); #- , )
620 } else {
621 choose_dialog_action($event->button_x, $event->button_y, 'button', $event); #- ,, )
622 }
623 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
624
625 } elsif ($event->type == SDL_MOUSEBUTTONUP) {
626 $button_hold = 0;
627
628 } elsif ($event->type == SDL_KEYDOWN) {
629 if ($displaying_dialog eq '') {
630 if ($event->key_sym == SDLK_ESCAPE() || $event->key_sym == SDLK_q() ) {
631 if ($modified_levelset == 1) {
632 $modified_levelset_action = '$modified_levelset_action = "return 1"';
633 create_save_changes_dialog();
634 } else {
635 return 1;
636 }
637 }
638 $event->key_sym == SDLK_LEFT() and prev_level();
639 $event->key_sym == SDLK_RIGHT() and next_level();
640 $event->key_sym == SDLK_UP() and first_level();
641 $event->key_sym == SDLK_DOWN() and last_level();
642 $event->key_sym == SDLK_a() and append_level();
643 $event->key_sym == SDLK_d() and do { delete_level(); Games::FrozenBubble::LevelEditor::load_level() };
644 $event->key_sym == SDLK_f() and $app->fullscreen;
645 $event->key_sym == SDLK_h() and prev_level();
646 $event->key_sym == SDLK_i() and insert_level();
647 $event->key_sym == SDLK_l() and next_level();
648 $event->key_sym == SDLK_n() and next_level();
649 $event->key_sym == SDLK_o() and create_open_levelset_dialog();
650 $event->key_sym == SDLK_p() and prev_level();
651 $event->key_sym == SDLK_s() and save_file();
652 $event->key_sym == SDLK_RIGHTBRACKET() and move_level_right();
653 $event->key_sym == SDLK_LEFTBRACKET() and move_level_left();
654 $event->key_sym == SDLK_F1() and create_help_dialog();
655 $event->key_sym == SDLK_j() and create_jump_to_level_dialog();
656 if ((($highlighted_option eq 'prev' || $highlighted_option eq 'first') && $curr_level == 1)
657 || (($highlighted_option eq 'next' || $highlighted_option eq 'last') && $curr_level == keys %bubble_hash)) {
658 unhighlight_option();
659 }
660 } elsif (member($displaying_dialog, qw(ls_new ls_new_ok_only))) {
661 print_new_ls_name($event->key_sym);
662 } elsif (member($displaying_dialog, qw(jump))) {
663 print_jump_to_level_value($event->key_sym);
664 } elsif ($displaying_dialog eq 'ls_open') {
665 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER()) {
666 highlight_option('ok');
667 SDL::delay(200);
668 open_levelset();
669 } elsif ($event->key_sym() == SDLK_ESCAPE()) {
670 highlight_option('cancel');
671 SDL::delay(200);
672 remove_dialog();
673 if ($deleted_current_levelset == 1) {
674 create_deleted_current_levelset_dialog();
675 }
676 } elsif ($event->key_sym() == SDLK_DOWN()) {
677 display_levelset_list_browser($FBLE::list_browser_file_start_offset + 1, $FBLE::list_browser_highlight_offset + 1);
678 } elsif ($event->key_sym() == SDLK_UP()) {
679 display_levelset_list_browser($FBLE::list_browser_file_start_offset - 1, $FBLE::list_browser_highlight_offset - 1);
680 }
681 } elsif ($displaying_dialog eq 'ls_open_ok_only') {
682 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER()) {
683 highlight_option('ok_right');
684 SDL::delay(200);
685 open_levelset();
686 } elsif ($event->key_sym() == SDLK_DOWN()) {
687 display_levelset_list_browser($FBLE::list_browser_file_start_offset + 1, $FBLE::list_browser_highlight_offset + 1);
688 } elsif ($event->key_sym() == SDLK_UP()) {
689 display_levelset_list_browser($FBLE::list_browser_file_start_offset - 1, $FBLE::list_browser_highlight_offset - 1);
690 }
691 } elsif ($displaying_dialog eq 'help') {
692 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER()) {
693 highlight_option('ok_right');
694 SDL::delay(200);
695 remove_dialog();
696 }
697
698 } elsif (member($displaying_dialog, qw(ls_play ls_play_choose_level))) {
699 if ($event->key_sym == SDLK_ESCAPE() || $event->key_sym == SDLK_q() ) {
700 $displaying_dialog = '';
701 return;
702 }
703 if ($event->key_sym == SDLK_RETURN() || $event->key_sym == SDLK_KP_ENTER()) {
704 highlight_option('ok_right');
705 SDL::delay(200);
706 my (@levelsets);
707 @levelsets = get_levelset_list();
708 $displaying_dialog = '';
709 my @retval = ($levelsets[$list_browser_highlight_offset], $start_level);
710 return @retval;
711 } elsif ($event->key_sym() == SDLK_DOWN()) {
712 display_levelset_list_browser($FBLE::list_browser_file_start_offset + 1, $FBLE::list_browser_highlight_offset + 1);
713 if (is_ok_select_start_value($start_level) == 0) {
714 #- we're over (since we can't be under) so go to the last
715 #- level in this new set
716 $start_level = $file_browser_levelsets_num_levels[$list_browser_highlight_offset];
717 if ($displaying_dialog eq 'ls_play_choose_level') {
718 show_selected_level();
719 }
720 }
721 } elsif ($event->key_sym() == SDLK_UP()) {
722 display_levelset_list_browser($FBLE::list_browser_file_start_offset - 1, $FBLE::list_browser_highlight_offset - 1);
723 if (is_ok_select_start_value($start_level) == 0) {
724 #- we're over (since we can't be under) so go to the last
725 #- level in this new set
726 $start_level = $file_browser_levelsets_num_levels[$list_browser_highlight_offset];
727 if ($displaying_dialog eq 'ls_play_choose_level') {
728 show_selected_level();
729 }
730 }
731 } elsif ($event->key_sym() == SDLK_LEFT()) {
732 modify_selected_level($event, 'down');
733 } elsif ($event->key_sym() == SDLK_RIGHT()) {
734 modify_selected_level($event, 'up');
735 }
736
737 } elsif ($displaying_dialog eq 'ls_delete') {
738 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER()) {
739 highlight_option('ok');
740 SDL::delay(200);
741 delete_levelset();
742 } elsif ($event->key_sym() == SDLK_ESCAPE()) {
743 highlight_option('cancel');
744 SDL::delay(200);
745 remove_dialog();
746 } elsif ($event->key_sym() == SDLK_DOWN()) {
747 display_levelset_list_browser($FBLE::list_browser_file_start_offset + 1, $FBLE::list_browser_highlight_offset + 1);
748 } elsif ($event->key_sym() == SDLK_UP()) {
749 display_levelset_list_browser($FBLE::list_browser_file_start_offset - 1, $FBLE::list_browser_highlight_offset - 1);
750 }
751 } elsif ($displaying_dialog eq 'ls_deleted_current') {
752 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER() ) {
753 highlight_option('ok');
754 SDL::delay(200);
755 remove_dialog();
756 create_open_levelset_dialog_ok_only();
757 } elsif ($event->key_sym() == SDLK_ESCAPE()) {
758 highlight_option('cancel');
759 SDL::delay(200);
760 $levelset_name = 'default-levelset';
761 %bubble_hash = read_file($levelset_name);
762 $curr_level = 1;
763 $displaying_dialog = '';
764 remove_dialog();
765 load_level();
766 print_levelset_name();
767 $deleted_current_levelset = 0;
768 }
769 } elsif ($displaying_dialog eq 'ls_nothing_to_delete') {
770 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER()) {
771 highlight_option('ok_right');
772 SDL::delay(200);
773 $displaying_dialog = '';
774 remove_dialog();
775 }
776 } elsif ($displaying_dialog eq 'ls_save_changes') {
777 if ($event->key_sym() == SDLK_RETURN() || $event->key_sym() == SDLK_KP_ENTER() ) {
778 highlight_option('ok');
779 SDL::delay(200);
780 save_file();
781 $displaying_dialog = '';
782 eval($modified_levelset_action);
783 } elsif ($event->key_sym() == SDLK_ESCAPE()) {
784 highlight_option('cancel');
785 SDL::delay(200);
786 $displaying_dialog = '';
787 eval($modified_levelset_action);
788 }
789 }
790
791 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
792
793 } elsif ($event->type == SDL_QUIT) {
794 if ($displaying_dialog eq '') {
795 if ($modified_levelset == 1) {
796 $modified_levelset_action = '$modified_levelset_action = "return 1"';
797 create_save_changes_dialog();
798 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
799 } else {
800 return 1;
801 }
802 }
803 }
804
805 if ($modified_levelset_action =~ /return (\S*)/ && $displaying_dialog ne 'ls_save_changes') {
806 $modified_levelset_action = '';
807 if ($displaying_dialog eq 'ls_play_choose_level') {
808 #- hokey, but I have to return an array here
809 $displaying_dialog = '';
810 return ($1, $start_level);
811 } else {
812 $displaying_dialog = '';
813 return $1;
814 }
815 }
816
817 } else {
818 SDL::delay(1);
819 }
820
821 }
822 }
823
824
825 #- ----------- dialogs -----------------------------------------
826
827 # subroutine to get the rect where the promt will go
828 sub get_dialog_rect {
829 SDL::Rect->new( $background->w/2 - $surface_dialog->w/2,
830 $background->h/2 - $surface_dialog->h/2,
831 $surface_dialog->w, $surface_dialog->h);
832 }
833
834 sub create_dialog_base {
835 my ($title_text) = @_;
836
837 unhighlight_option();
838 if ($displaying_dialog eq 'help') {
839 $surface_dialog = SDL::Image::load( "$FPATH/gfx/key_shortcuts.png");
840 } else {
841 $surface_dialog = SDL::Image::load( "$FPATH/gfx/menu/void_panel.png");
842 }
843 $rect{dialog} = SDL::Rect->new(0, 0, $surface_dialog->w, $surface_dialog->h);
844 $rect{middle} = get_dialog_rect();
845
846 SDL::Video::blit_surface( $surface_dialog, $rect{dialog}, $app, $rect{middle});
847
848 SDLx::SFont::print_text( $app,$rect{middle}->x + $rect{middle}->w/2 - 12 * length($title_text)/2, $rect{middle}->y + 5, uc($title_text));
849
850 }
851
852 # sub to create a blank dialog on the screen
853 sub create_dialog {
854 my ($title_text) = @_;
855 create_dialog_base($title_text);
856 print_cancel_text(0);
857 print_ok_text(0);
858
859 }
860
861 sub remove_dialog {
862 $rect{middle} = SDL::Rect->new( $background->w/2 - $surface_dialog->w/2,
863 $background->h/2 - $surface_dialog->h/2,
864 $surface_dialog->w, $surface_dialog->h);
865 SDL::Video::blit_surface( $background, $rect{middle}, $app, $rect{middle});
866 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
867
868 # update the screen
869 load_level();
870 $displaying_dialog = '';
871 }
872
873 # subroutine to ask the user what to do if they delete the current levelset
874 sub create_deleted_current_levelset_dialog {
875 $displaying_dialog = 'ls_deleted_current';
876 $deleted_current_levelset = 1;
877 create_dialog('DELETED CURRENT LEVELSET');
878 $rect{middle} = get_dialog_rect();
879 SDLx::SFont::print_text( $app,$rect{middle}->x + 25, $rect{middle}->y + 15 + $WOOD_PLANK_HEIGHT, "PRESS \"OK\" TO CHOOSE");
880
881 SDLx::SFont::print_text( $app,$rect{middle}->x + 25, $rect{middle}->y + 35 + $WOOD_PLANK_HEIGHT, "ANOTHER LEVELSET TO OPEN");
882
883 SDLx::SFont::print_text( $app,$rect{middle}->x + 25, $rect{middle}->y + 3 * $WOOD_PLANK_HEIGHT, "PRESS \"CANCEL\" TO OPEN");
884
885 SDLx::SFont::print_text( $app,$rect{middle}->x + 25, $rect{middle}->y + 25 + 3* $WOOD_PLANK_HEIGHT, "THE DEFAULT LEVELSET");
886
887
888 }
889
890 # subroutine to create a delete levelset dialog
891 sub create_delete_levelset_dialog {
892 if (all($FBLEVELS) > 1) {
893 $displaying_dialog = 'ls_delete';
894 create_dialog('SELECT LEVELSET TO DELETE');
895 $list_browser_highlight_offset = -1;
896 $list_browser_file_start_offset = -1;
897 display_levelset_list_browser(0, 0);
898 } else {
899 $displaying_dialog = 'ls_nothing_to_delete';
900 create_ok_dialog('NO LEVELSET TO DELETE');
901 $rect{middle} = get_dialog_rect();
902 SDLx::SFont::print_text( $app,$rect{middle}->x + 50, $rect{middle}->y + 30 + $WOOD_PLANK_HEIGHT, "THERE ARE NO CUSTOM");
903
904 SDLx::SFont::print_text( $app,$rect{middle}->x + 50, $rect{middle}->y + 55 + $WOOD_PLANK_HEIGHT, "LEVELSETS TO DELETE.");
905
906 SDLx::SFont::print_text( $app,$rect{middle}->x + 40, $rect{middle}->y + 125 + $WOOD_PLANK_HEIGHT, "PRESS \"OK\" TO CONTINUE");
907
908 }
909 }
910
911
912 #subroutine to display the help dialog.
913 sub create_help_dialog {
914 $displaying_dialog = 'help';
915 create_ok_dialog("HELP - KEY SHORTCUTS");
916 }
917
918
919 # subroutine to create a jump to level diaplog. This dialog asks the user what level they want to go directly to
920 sub create_jump_to_level_dialog {
921 $jump_to_level_value = '';
922 $displaying_dialog = 'jump';
923 create_dialog("ENTER LEVEL TO JUMP TO");
924 }
925
926 # subroutine to create a new levelset dialog. This dialog asks for the name of the new levelset
927 sub create_new_levelset_dialog {
928 if ($modified_levelset == 1) {
929 $modified_levelset_action = 'create_new_levelset_dialog_ok_only()';
930 create_save_changes_dialog();
931 } else {
932 $displaying_dialog = 'ls_new';
933 # create the blank dialog with the title of "enter new levelset name"
934 create_dialog('ENTER NEW LEVELSET NAME');
935 # inialize the new levelset name
936 $new_ls_name_text = '';
937 }
938
939 }
940
941 sub create_new_levelset_dialog_ok_only {
942 $displaying_dialog = 'ls_new_ok_only';
943 create_ok_dialog('ENTER NEW LEVELSET NAME');
944 $new_ls_name_text = '';
945 }
946
947 # sub to create a blank dialog on the screen
948 sub create_ok_dialog {
949 my ($title_text) = @_;
950 create_dialog_base($title_text);
951 print_ok_right_text(0);
952
953 }
954
955 sub create_open_levelset_dialog {
956 $start_level = undef;
957 if ($modified_levelset == 1) {
958 $modified_levelset_action = 'create_open_levelset_dialog_ok_only()';
959 create_save_changes_dialog();
960 } else {
961 $displaying_dialog = 'ls_open';
962 create_dialog('SELECT LEVELSET TO OPEN');
963 $list_browser_highlight_offset = -1;
964 $list_browser_file_start_offset = -1;
965 display_levelset_list_browser(0,0);
966 }
967 }
968
969 sub create_open_levelset_dialog_ok_only {
970
971 $displaying_dialog = 'ls_open_ok_only';
972 create_ok_dialog('SELECT LEVELSET TO OPEN');
973 $list_browser_highlight_offset = -1;
974 $list_browser_file_start_offset = -1;
975 display_levelset_list_browser(0,0);
976
977 }
978
979 sub iter_rowscols(&) {
980 my ($f) = @_;
981 local ($::row, $::col);
982 foreach $::row (0 .. $NUM_ROWS - 1) {
983 foreach $::col (0 .. ($POS_1P{p1}{right_limit}-$POS_1P{p1}{left_limit})/$BUBBLE_SIZE - 1 - odd($::row)) {
984 &$f;
985 }
986 }
987 }
988
989 sub save_file {
990 my @contents;
991 foreach my $lev (1 .. keys %bubble_hash) {
992 iter_rowscols {
993 if ($::col == 0) {
994 ($lev == 1 && $::row == 0) or push @contents, "\n";
995 odd($::row) and push @contents, " ";
996 }
997 push @contents, "$bubble_hash{$lev}{$::col}{$::row}";
998 $::col+odd($::row) < 7 and push @contents, " ";
999 };
1000 push @contents, "\n";
1001 }
1002 output("$FBLEVELS/$levelset_name", @contents);
1003 $modified_levelset = 0;
1004 }
1005
1006 sub create_play_levelset_dialog {
1007 my ($chooseStartingLevel, $defaultLevel) = @_;
1008
1009 #initialize the start level to the default level
1010 #this is only modified in ls_play_choose_level dialogs
1011 #but it is always referenced
1012 $start_level = $defaultLevel;
1013
1014 #we do the check for $chooseStartingLevel twice because create_ok_dialog
1015 #needs to know the displaying levelset but display_level_selector
1016 #needs things that are set up in display_levelset_list_browser
1017 if ($chooseStartingLevel ==1 ) {
1018 $displaying_dialog = 'ls_play_choose_level';
1019 } else {
1020 $displaying_dialog = 'ls_play';
1021 }
1022
1023 create_ok_dialog('SELECT LEVELSET TO PLAY');
1024 $list_browser_highlight_offset = -1;
1025 $list_browser_file_start_offset = -1;
1026 display_levelset_list_browser(0, 0);
1027 if ($chooseStartingLevel == 1) {
1028 display_level_selector();
1029 }
1030 }
1031
1032
1033 sub create_save_changes_dialog {
1034 $modified_levelset = 0;
1035 #reset the modified levelset flag
1036 $displaying_dialog = 'ls_save_changes';
1037 create_dialog('SAVE CHANGES?');
1038
1039 $rect{middle} = get_dialog_rect();
1040
1041 # write out the instructions
1042 SDLx::SFont::print_text( $app,$rect{middle}->x + 25, $rect{middle}->y + $WOOD_PLANK_HEIGHT, 'THERE ARE UNSAVED CHANGES');
1043
1044 SDLx::SFont::print_text( $app,$rect{middle}->x + 22, $rect{middle}->y + 35 + $WOOD_PLANK_HEIGHT, "PRESS \"OK\" TO SAVE");
1045
1046 SDLx::SFont::print_text( $app,$rect{middle}->x + 22, $rect{middle}->y + 55 + $WOOD_PLANK_HEIGHT, "CHANGES AND CONTINUE");
1047
1048 SDLx::SFont::print_text( $app,$rect{middle}->x + 22, $rect{middle}->y + 95 + $WOOD_PLANK_HEIGHT, "PRESS \"CANCEL\" TO CONTINUE");
1049
1050 SDLx::SFont::print_text( $app,$rect{middle}->x + 22, $rect{middle}->y + 115 + $WOOD_PLANK_HEIGHT, "WITHOUT SAVING");
1051
1052 }
1053
1054 sub display_level_selector {
1055
1056 $rect{middle} = get_dialog_rect();
1057 SDLx::SFont::print_text( $app,$rect{middle}->x + 15, $rect{middle}->y + 190, "START LEVEL:");
1058
1059 SDL::Video::update_rects($app,$rect{middle});
1060
1061 show_selected_level();
1062 print_dialog_select_level_arrow(0, 'down');
1063 print_dialog_select_level_arrow(0, 'up');
1064 print_dialog_select_level_arrow(0, 'down_more');
1065 print_dialog_select_level_arrow(0, 'up_more');
1066 }
1067
1068 sub is_ok_modify_selected_level {
1069 my ($modification) = @_;
1070
1071 if ($modification =~ /up/ && is_ok_select_start_value($start_level + 1)
1072 || $modification =~ /down/ && is_ok_select_start_value($start_level - 1)) {
1073 return 1;
1074 } else {
1075 return 0;
1076 }
1077 }
1078
1079 sub modify_selected_level {
1080
1081 my ($event, $modification) = @_;
1082 my $loops = 0;
1083
1084
1085 #loop until we get a keyup or a mouse up
1086 while (1) {
1087 SDL::Events::pump_events();
1088 if ( SDL::Events::poll_event($event) == 0 ) {
1089 if (is_ok_modify_selected_level($modification)) {
1090 if ($modification eq 'up') {
1091 $start_level++;
1092 }
1093 if ($modification eq 'down') {
1094 $start_level--;
1095 }
1096 if ($modification eq 'up_more') {
1097 if (is_ok_select_start_value($start_level + 10)) {
1098 $start_level += 10;
1099 } else {
1100 $start_level = $file_browser_levelsets_num_levels[$list_browser_highlight_offset];
1101 }
1102 }
1103 if ($modification eq 'down_more') {
1104 if (is_ok_select_start_value($start_level - 10)) {
1105 $start_level -= 10;
1106 } else {
1107 $start_level = 1;
1108 }
1109 }
1110 show_selected_level();
1111
1112 #- need to unhighlight when we got at one extremity
1113 if ($modification =~ /up/ && $start_level == $file_browser_levelsets_num_levels[$list_browser_highlight_offset]
1114 || $modification =~ /down/ && $start_level == 1) {
1115 unhighlight_option();
1116 }
1117
1118 }
1119
1120 #no change in the event, delay and then try again
1121 if ($loops <= 5) {
1122 #special case here. If the user hits the keys fast, we need
1123 #to compensate for that. delay 100 and then check the key again
1124 #if it has changed, just exit. Otherwise, they're holding the
1125 #key down and we follow the logic as usual
1126 SDL::delay(100);
1127 SDL::Events::pump_events();
1128 if ( SDL::Events::poll_event($event) == 0 || $event->type == SDL_MOUSEMOTION) { #mousemotion is when they are
1129 #holding the mouse key down and
1130 #jiggle it's position a litte bit
1131 SDL::delay(300);
1132 } else {
1133 goto done;
1134 }
1135
1136 } elsif ($loops <= 10) {
1137 SDL::delay(150);
1138
1139 } elsif ($loops <= 20) {
1140 SDL::delay(80);
1141
1142 } else {
1143 SDL::delay(35);
1144 }
1145
1146 $loops++;
1147
1148 } else {
1149 if ($event->type == SDL_MOUSEMOTION) {
1150 #let them move the mouse around in the arrow that's already highlighted
1151
1152 my $x = $event->button_x;
1153 my $y = $event->button_y; #;;
1154
1155 #if I'm outside of the x range, just exit
1156 if (!betw($x, 435, 470)) {
1157 goto done;
1158 }
1159
1160 if ($modification =~ /up/) {
1161 if ( !betw($y, $rect{middle}->y + 180, $rect{middle}->y + 200) ) {
1162 goto done;
1163 }
1164 } else {
1165 if ( !betw($y, $rect{middle}->y + 202, $rect{middle}->y + 222) ) {
1166 goto done;
1167 }
1168 }
1169
1170 } else {
1171 goto done;
1172 }
1173 }
1174 }
1175
1176 done:
1177
1178 }
1179
1180 #- from gentoo patch IIRC
1181 sub SDL_TEXTWIDTH {
1182 if (defined(&SDLx::App::SDL_TEXTWIDTH)) {
1183 SDLx::App::SDL_TEXTWIDTH(@_); # perl-sdl-1.x
1184 } else {
1185 SDLx::SFont::SDL_TEXTWIDTH(@_); # perl-sdl-2.x
1186 }
1187 }
1188
1189
1190 sub show_selected_level {
1191 my $surf_select_level_background
1192 = SDL::Image::load( "$FPATH/gfx/select_level_background.png");
1193
1194 $rect{select_level_background_src}
1195 = SDL::Rect->new(0, 0, $surf_select_level_background->w,
1196 $surf_select_level_background->h);
1197
1198 $rect{select_level_background_dest}
1199 = SDL::Rect->new( 305,
1200 $rect{middle}->y + 190, #==
1201 $rect{select_level_background_src}->w,
1202 $rect{select_level_background_src}->h);
1203
1204 SDL::Video::blit_surface( $surf_select_level_background, $rect{select_level_background_src}, $app, $rect{select_level_background_dest});
1205
1206 #now write the selected level
1207 $font = SDLx::SFont->new("$FPATH/gfx/font-hi.png");
1208 SDLx::SFont::print_text( $app,427 - SDL_TEXTWIDTH($start_level), $rect{middle}->y + 190, $start_level);
1209
1210 $font = SDLx::SFont->new("$FPATH/gfx/font.png");
1211
1212 SDL::Video::update_rects($app,$rect{select_level_background_dest});
1213
1214 display_levelset_screenshot();
1215 }
1216
1217
1218 # subroutine to display to the user a list of levelsets and allow them
1219 # to browse through and select one of them.
1220 sub display_levelset_list_browser {
1221 my ($file_start_offset, $file_highlight_offset) = @_;
1222 my ($surf_file_list_background, $surf_purple_highlight, $surf_scroll_list_background, $cnt);
1223
1224 my @levelsets = get_levelset_list();
1225 my $do_scroll = $file_start_offset != $list_browser_file_start_offset;
1226
1227 if ($file_highlight_offset > @levelsets - 1
1228 || $file_highlight_offset == $list_browser_highlight_offset && !$do_scroll) {
1229 # this is the case where the user either clicks on the same
1230 # file that is already selected, or clicks in the file box, but
1231 # not on a file (for example, the user click on the second
1232 # file section when only one file is displayed
1233 return;
1234 }
1235
1236 # we can display 4 files. If the offset makes us print less than 1, ignore it
1237 # also, make sure we don't let an offset of less than 0 go through
1238 if ($file_start_offset < @levelsets && $file_start_offset >= 0) {
1239 # save the current file offset
1240 $list_browser_file_start_offset = $file_start_offset;
1241 } else {
1242 # we don't need to draw anything. just exit
1243 return;
1244 }
1245
1246 $rect{middle} = get_dialog_rect();
1247 #I want the font to be blue in the dialogs
1248 $font = SDLx::SFont->new("$FPATH/gfx/font-hi.png");
1249 $surf_file_list_background = SDL::Image::load( "$FPATH/gfx/file_list_background.png");
1250 $rect{list_box_src} = SDL::Rect->new(0,0, $surf_file_list_background->w, 3 * $WOOD_PLANK_HEIGHT);
1251
1252 # if the user is choosing the start level, we need to move things up a little bit to make
1253 # room for the choose level widget
1254 my $widgetMove = 0;
1255 if ($displaying_dialog eq 'ls_play_choose_level') {
1256 $widgetMove = -25;
1257 }
1258 $rect{dialog_file_list} = SDL::Rect->new($rect{middle}->x + 9, $rect{middle}->y + $WOOD_PLANK_HEIGHT + 37 + $widgetMove,
1259 $rect{list_box_src}->w, $rect{list_box_src}->h);
1260
1261 $surf_purple_highlight = SDL::Image::load( "$FPATH/gfx/purple_hover.gif");
1262
1263 $rect{purple_highlight_src} = SDL::Rect->new(0,0, $surf_purple_highlight->w, $surf_purple_highlight->h);
1264
1265 # we only want to draw the arrows and background here once, when we first get launched
1266 if ($list_browser_highlight_offset == -1) {
1267 $surf_scroll_list_background = SDL::Image::load("$FPATH/gfx/scroll_list_background.png");
1268
1269 $rect{scroll_list_background_src} = SDL::Rect->new(0,0, $surf_scroll_list_background,
1270 3 * $WOOD_PLANK_HEIGHT);
1271
1272 $rect{scroll_list_background_dest} = SDL::Rect->new( $rect{dialog_file_list}->x + $rect{dialog_file_list}->w,
1273 $rect{dialog_file_list}->y,
1274 $rect{scroll_list_background_src}->w,
1275 $rect{scroll_list_background_src}->h);
1276
1277 SDL::Video::blit_surface( $surf_scroll_list_background, $rect{scroll_list_background_src}, $app, $rect{scroll_list_background_dest});
1278 SDL::Video::update_rects($app,$rect{scroll_list_background_dest});
1279
1280 print_dialog_list_arrow_down(0);
1281 print_dialog_list_arrow_up(0);
1282 }
1283
1284 if ($do_scroll == 1) {
1285 SDL::Video::blit_surface( $surf_file_list_background, $rect{list_box_src}, $app, $rect{dialog_file_list});
1286 SDL::Video::update_rects($app,$rect{dialog_file_list});
1287
1288 for ($cnt = $file_start_offset; $cnt < $file_start_offset + 4; $cnt++) {
1289 if ($file_highlight_offset == $cnt) {
1290 $rect{purple_highlight_dest}
1291 = SDL::Rect->new( $rect{middle}->x + 12,
1292 $rect{dialog_file_list}->y + 10 + 25 * ($cnt - $file_start_offset),
1293 $surf_purple_highlight->w, $surf_purple_highlight->h);
1294
1295 SDL::Video::blit_surface( $surf_purple_highlight, $rect{purple_highlight_src}, $app, $rect{purple_highlight_dest});
1296 SDL::Video::update_rects($app,$rect{purple_highlight_dest});
1297 }
1298 SDLx::SFont::print_text( $app,$rect{middle}->x + 19, $rect{dialog_file_list}->y + 8 + 25 * ($cnt - $file_start_offset),
1299
1300 uc($levelsets[$cnt]));
1301 }
1302 } else {
1303 # erase the old highlight
1304 $rect{old_highlight} = SDL::Rect->new(
1305 $rect{middle}->x + 12,
1306 $rect{dialog_file_list}->y + 10 + 25 * ($list_browser_highlight_offset - $list_browser_file_start_offset),
1307 $surf_purple_highlight->w, $surf_purple_highlight->h);
1308
1309 $rect{erase_highlight} = SDL::Rect->new(
1310 $rect{old_highlight}->x - $rect{dialog_file_list}->x,
1311 $rect{old_highlight}->y - $rect{dialog_file_list}->y,
1312 $surf_purple_highlight->w, $surf_purple_highlight->h);
1313
1314 # it is possible that the highlighed dude is off the screen. In this case, do not
1315 # call the blit, because there is no visible highlight to remove
1316 if ($list_browser_highlight_offset >= $list_browser_file_start_offset
1317 && $list_browser_highlight_offset <= $list_browser_file_start_offset + 3) {
1318 SDL::Video::blit_surface( $surf_file_list_background, $rect{erase_highlight}, $app, $rect{old_highlight});
1319 SDL::Video::update_rects($app,$rect{old_highlight});
1320 # draw the text of the old highligted dude
1321 SDLx::SFont::print_text( $app,$rect{middle}->x + 19,
1322
1323 $rect{dialog_file_list}->y + 8 + 25 * ($list_browser_highlight_offset - $list_browser_file_start_offset),
1324 uc($levelsets[$list_browser_highlight_offset]));
1325 }
1326
1327 # draw the highlight
1328 $rect{purple_highlight_dest} = SDL::Rect->new(
1329 $rect{middle}->x + 12,
1330 $rect{dialog_file_list}->y + 10 + 25 * ($file_highlight_offset - $file_start_offset),
1331 $surf_purple_highlight->w,
1332 $surf_purple_highlight->h);
1333 SDL::Video::blit_surface( $surf_purple_highlight, $rect{purple_highlight_src}, $app, $rect{purple_highlight_dest});
1334 SDL::Video::update_rects($app,$rect{purple_highlight_dest});
1335 SDLx::SFont::print_text( $app,$rect{middle}->x + 19,
1336
1337 $rect{dialog_file_list}->y + 8 + 25 * ($file_highlight_offset - $file_start_offset),
1338 uc($levelsets[$file_highlight_offset]));
1339
1340 }
1341
1342 # set the unhighlight so the app thinks nothing's highlighted and will highlight
1343 # the correct item in the next highlight function call
1344 unhighlight_option();
1345
1346 SDL::Video::update_rects($app,$rect{middle});
1347
1348 if ($file_highlight_offset != $list_browser_highlight_offset) {
1349 if ($list_browser_highlight_offset == -1) {
1350 $list_browser_highlight_offset = 0;
1351
1352 %file_browser_levelsets = ();
1353 @file_browser_levelsets_num_levels = ();
1354 my @levelset_list = get_levelset_list();
1355 foreach my $levelset (@levelset_list) {
1356 my %levelset = read_file($levelset);
1357 $file_browser_levelsets{$levelset} = \%levelset;
1358 push @file_browser_levelsets_num_levels, scalar keys %levelset;
1359 }
1360 }
1361 $list_browser_highlight_offset = $file_highlight_offset;
1362 display_levelset_screenshot();
1363 } else {
1364 $list_browser_highlight_offset = $file_highlight_offset;
1365 }
1366
1367 #reset the font back to white
1368 $font = SDLx::SFont->new("$FPATH/gfx/font.png");
1369 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
1370 }
1371
1372 our $surfstyle;
1373 sub surf {
1374 my ($surface) = @_;
1375 $surfstyle ||= UNIVERSAL::isa($surface, 'HASH') ? 'hashref' : 'scalarref';
1376 return $surfstyle eq 'hashref' ? $surface->{-surface} : $$surface;
1377 }
1378 sub rect {
1379 my ($rect) = @_;
1380 return $surfstyle eq 'hashref' ? $rect->{-rect} : $$rect;
1381 }
1382
1383 my $s_save;
1384 # display a scrrenshot (1/4 size) of the first level in a levelset on the current dialog
1385 sub display_levelset_screenshot {
1386 my @levelsets = get_levelset_list();
1387 my $name = $levelsets[$list_browser_highlight_offset];
1388 $rect{middle} = get_dialog_rect();
1389 $rect{screenshot} = SDL::Rect->new($POS_1P{p1}{left_limit} - 40, 0,
1390 $POS_1P{p1}{right_limit} - $POS_1P{p1}{left_limit} + 80,
1391 $POS_1P{bottom_limit} - $POS_1P{p1}{top_limit} + 190);
1392 # if the user is choosing the start level, we need to move things up a little bit to make
1393 # room for the choose level widget
1394 my $widgetMove = ($displaying_dialog eq 'ls_play_choose_level') ? -25 : 0;
1395 my $x = $rect{middle}->x + $rect{middle}->w - $rect{screenshot}->w/4 - 12;
1396 my $y = $rect{middle}->y + $rect{middle}->h/2 - $rect{screenshot}->h/8 - 3 + $widgetMove;
1397
1398 my %shrinks;
1399 my $current_nb = $start_level || 1;
1400 if (!exists $shrinks{$name}{$current_nb}) {
1401 my $surf = SDL::Image::load("$FPATH/gfx/menu/please_wait.png");
1402 SDL::Video::blit_surface($surf, SDL::Rect->new(0,0, $surf->w, $surf->h),
1403 $app, SDL::Rect->new($rect{scroll_list_background_dest}->x + $rect{scroll_list_background_dest}->w + 7,
1404 $rect{scroll_list_background_dest}->y + 20,
1405 $surf->w, $surf->w));
1406 SDL::Video::update_rects($app,$rect{middle});
1407
1408 #- sorta "read ahead": will compute next 10 levels screenshots as well
1409 $s_save = SDL::Image::load( "$FPATH/gfx/level_editor.png") unless $s_save;
1410 #- don't read-ahead if $start_level is void because it
1411 #- indicates we're just selecting a levelset in the editor
1412 my @read_ahead = $start_level ? ($current_nb - 10, $current_nb - 3 .. $current_nb + 10, $current_nb + 20)
1413 : ($current_nb);
1414 foreach my $nb (@read_ahead) {
1415 next if $nb < 1 || exists $shrinks{$name}{$nb};
1416 my %ls = %{$file_browser_levelsets{$name}};
1417 last if !exists $ls{$nb};
1418 my $s = SDL::Surface->new(SDL_SWSURFACE, $s_save->w, $s_save->h, 32);
1419 my $rect = SDL::Rect->new(0, 0, $app->w, $app->h);
1420 SDL::Video::blit_surface($s_save, $rect, $s, $rect);
1421 load_level($s, $nb, %ls);
1422 $shrinks{$name}{$nb} = SDL::Surface->new(SDL_SWSURFACE, $rect{screenshot}->w / 4, $rect{screenshot}->h / 4, 32);
1423 Games::FrozenBubble::CStuff::shrink($shrinks{$name}{$nb}, $s, 0, 0, $rect{screenshot}, 4);
1424 }
1425 }
1426
1427 if(defined $shrinks{$name}{$current_nb})
1428 {
1429 my $image = $shrinks{$name}{$current_nb};
1430 SDL::Video::blit_surface($image, SDL::Rect->new(0, 0, $image->w, $image->h),
1431 $app, SDL::Rect->new($x, $y, $image->w, $image->h));
1432 SDL::Video::update_rects($app,$rect{middle});
1433 }
1434 }
1435
1436
1437 #- ----------- levels and levelsets operations ------------------------------------------
1438
1439 # subroutine load_level
1440 sub load_level {
1441 my ($surface_tmp, $curr_lvl, %b) = @_;
1442
1443 if (!$surface_tmp) {
1444 $curr_lvl = $curr_level;
1445 %b = %bubble_hash;
1446 clear_level();
1447 print_level_nb();
1448 }
1449
1450 iter_rowscols {
1451 my $bub = \$b{$curr_lvl}{$::col}{$::row};
1452 defined($$bub) or $$bub = '-'; #- sanitize
1453 if ($$bub ne '-') {
1454 draw_bubble($$bub + 1,
1455 $::col * $BUBBLE_SIZE + $POS_1P{p1}{left_limit} + odd($::row)*$BUBBLE_SIZE/2,
1456 $::row * $ROW_SIZE + $POS_1P{p1}{top_limit},
1457 $ALPHA_BUBBLE_NO, $surface_tmp, undef, 1);
1458 }
1459 };
1460
1461 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
1462 }
1463
1464 # subroutine to clear level off the screen
1465 sub clear_level {
1466 $rect{clear} = SDL::Rect->new( $POS_1P{p1}{left_limit}, $POS_1P{p1}{top_limit},
1467 $POS_1P{p1}{right_limit} - $POS_1P{p1}{left_limit},
1468 $POS_1P{bottom_limit} - $POS_1P{p1}{top_limit} + $BUBBLE_SIZE
1469 );
1470
1471 SDL::Video::blit_surface( $background, $rect{clear}, $app, $rect{clear});
1472 }
1473
1474 sub delete_level {
1475
1476 delete $bubble_hash{$curr_level};
1477
1478 if ($curr_level - 1 == keys %bubble_hash) {
1479 $curr_level--;
1480 if ($curr_level == 0) {
1481 append_level();
1482 }
1483 } else {
1484 foreach my $lev ($curr_level .. keys %bubble_hash) {
1485 $bubble_hash{$lev} = $bubble_hash{$lev + 1};
1486 }
1487
1488 delete $bubble_hash{keys %bubble_hash};
1489 }
1490
1491 $modified_levelset = 1;
1492 }
1493
1494 # subroutine to actually create a new levelset
1495 sub create_new_levelset {
1496
1497 $levelset_name = lc($new_ls_name_text);
1498
1499 %bubble_hash = ();
1500 $curr_level = 0;
1501 append_level();
1502
1503 print_levelset_name();
1504 load_level();
1505 $modified_levelset = 0;
1506 }
1507
1508 # subroutine to delete a levelset
1509 sub delete_levelset {
1510
1511 my @levelsets = get_levelset_list();
1512 my $lvs_name = $levelsets[$list_browser_highlight_offset];
1513 unlink "$FBLEVELS/$lvs_name" or die "Can't remove $FBLEVELS/$lvs_name\n";
1514 remove_dialog();
1515
1516 $levelset_name eq $lvs_name and create_deleted_current_levelset_dialog();
1517 }
1518
1519 # this subroutine is mostly copied from frozen-bubble
1520 sub read_file {
1521 my ($file_name) = @_;
1522
1523 my $row = 0;
1524 my $lev_number = 1;
1525 my %tmp_hash;
1526 foreach my $line (cat_("$FBLEVELS/$file_name")) {
1527 if ($line !~ /\S/) {
1528 if ($row) {
1529 $lev_number++;
1530 $row = 0;
1531 }
1532 } else {
1533 my $col = 0;
1534 foreach (split ' ', $line) {
1535 $tmp_hash{$lev_number}{$col}{$row} = $_;
1536 $col++;
1537 }
1538 $row++;
1539 }
1540 }
1541
1542 return %tmp_hash;
1543
1544 }
1545
1546 # subroutine to open the levelset
1547 sub open_levelset {
1548 my (@levelsets);
1549 # reset the deleted_current_levelset flag in case
1550 # we were in that situation
1551
1552 $deleted_current_levelset = 0;
1553 @levelsets = get_levelset_list();
1554
1555 $levelset_name = $levelsets[$list_browser_highlight_offset];
1556 %bubble_hash = read_file($levelset_name);
1557 print_levelset_name();
1558 $curr_level = 1;
1559 remove_dialog();
1560 $modified_levelset = 0;
1561 }
1562
1563
1564 #- ----------- navigation in a levelset ------------------------------------------
1565
1566 sub prev_level {
1567 $curr_level > 1 and $curr_level--;
1568 load_level();
1569 }
1570
1571 sub next_level {
1572 $curr_level < keys %bubble_hash and $curr_level++;
1573 load_level();
1574 }
1575
1576 sub first_level {
1577 $curr_level = 1;
1578 load_level();
1579 }
1580
1581 sub last_level {
1582 $curr_level = keys %bubble_hash;
1583 load_level();
1584 }
1585
1586 sub jump_to_level {
1587 my ($n) = @_;
1588 if ($n >= 1 && $n <= keys %bubble_hash) {
1589 $curr_level = $_[0];
1590 load_level();
1591 }
1592 }
1593
1594 sub insert_level {
1595 for (my $lev = 1 + keys %bubble_hash; $lev > $curr_level; $lev--) {
1596 $bubble_hash{$lev} = $bubble_hash{$lev - 1};
1597 }
1598
1599 delete $bubble_hash{$curr_level};
1600
1601 # initialize our new level
1602 iter_rowscols { $bubble_hash{$curr_level}{$::col}{$::row} = '-' };
1603
1604 load_level();
1605 $modified_levelset = 1;
1606 }
1607
1608 sub append_level {
1609 $curr_level++;
1610 insert_level();
1611 }
1612
1613 sub move_level_left {
1614 $curr_level > 1 or return;
1615 ($bubble_hash{$curr_level-1}, $bubble_hash{$curr_level}) = ($bubble_hash{$curr_level}, $bubble_hash{$curr_level-1});
1616 $curr_level--;
1617 load_level();
1618 $modified_levelset = 1;
1619 }
1620
1621 sub move_level_right {
1622 $curr_level < keys(%bubble_hash) or return;
1623 ($bubble_hash{$curr_level+1}, $bubble_hash{$curr_level}) = ($bubble_hash{$curr_level}, $bubble_hash{$curr_level+1});
1624 $curr_level++;
1625 load_level();
1626 $modified_levelset = 1;
1627 }
1628
1629
1630 #- ----------- printing stuff ------------------------------------------
1631
1632 sub print_cancel_text {
1633 my ($do_highlight) = @_;
1634
1635 if ($displaying_dialog ne '') {
1636 $rect{middle} = get_dialog_rect();
1637
1638 $rect{cancel_src} = SDL::Rect->new( $rect{middle}->w - $rect{option_highlight}->w,
1639 6 * $WOOD_PLANK_HEIGHT - 4,
1640 $rect{middle}->w/2, $WOOD_PLANK_HEIGHT);
1641
1642 $rect{cancel} = SDL::Rect->new( $rect{middle}->x + $rect{middle}->w - $rect{option_highlight}->w,
1643 $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT - 4,
1644 $rect{middle}->w/2, $WOOD_PLANK_HEIGHT);
1645
1646 SDL::Video::blit_surface( $surface_dialog, $rect{cancel_src}, $app, $rect{cancel});
1647 SDL::Video::update_rects($app,$rect{cancel});
1648
1649 SDLx::SFont::print_text( $app,$rect{middle}->x + $rect{middle}->w - 120, $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT, 'CANCEL');
1650
1651 if ($do_highlight) {
1652 SDL::Video::blit_surface( $highlight, $rect{option_highlight}, $app, $rect{cancel});
1653 SDL::Video::update_rects($app,$rect{cancel});
1654 }
1655 }
1656 }
1657
1658 sub print_dialog_list_arrow {
1659 my ($do_highlight, $type) = @_;
1660
1661 $rect{middle} = get_dialog_rect();
1662
1663 my $surf_list_arrow = SDL::Image::load( "$FPATH/gfx/list_arrow_$type.png");
1664 $rect{list_arrow_src} = SDL::Rect->new( 0, 0, $surf_list_arrow->w, $surf_list_arrow->h);
1665 $rect{list_arrow_dest} = SDL::Rect->new(
1666 $rect{middle}->x + 4 * $rect{middle}->w/6 + 2,
1667 $type eq 'up' ? $rect{dialog_file_list}->y + 2
1668 : $rect{dialog_file_list}->y + $rect{dialog_file_list}->h - $surf_list_arrow->h - 2,
1669 $surf_list_arrow->w, $surf_list_arrow->h);
1670
1671 my $surf_scroll_list_background = SDL::Image::load( "$FPATH/gfx/scroll_list_background.png");
1672 $rect{erase_arrow} = SDL::Rect->new( $rect{list_arrow_dest}->x - $rect{scroll_list_background_dest}->x,
1673 $rect{list_arrow_dest}->y - $rect{scroll_list_background_dest}->y,
1674 $surf_list_arrow->w, $surf_list_arrow->h);
1675
1676 SDL::Video::blit_surface( $surf_scroll_list_background, $rect{erase_arrow}, $app, $rect{list_arrow_dest});
1677 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1678
1679 SDL::Video::blit_surface( $surf_list_arrow, $rect{list_arrow_src}, $app, $rect{list_arrow_dest});
1680 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1681
1682 if ($do_highlight) {
1683 SDL::Video::blit_surface( $highlight, $rect{list_arrow_src}, $app, $rect{list_arrow_dest});
1684 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1685 }
1686 }
1687
1688
1689 sub print_dialog_select_level_arrow {
1690 my ($do_highlight, $type, $more) = @_;
1691 $rect{middle} = get_dialog_rect();
1692
1693 my $surf_list_arrow = SDL::Image::load( "$FPATH/gfx/list_arrow_$type.png");
1694 $rect{list_arrow_src} = SDL::Rect->new(0,0, $surf_list_arrow->w, $surf_list_arrow->h);
1695 my $x = $type =~ /more/ ? 457 : 437;
1696 $rect{list_arrow_dest} = SDL::Rect->new(
1697 $x,
1698 $type =~ /up/ ? $rect{middle}->y + 180
1699 : $rect{middle}->y + 202,
1700 $surf_list_arrow->w, $surf_list_arrow->h);
1701
1702 my $surf_arrow_background = SDL::Image::load( "$FPATH/gfx/menu/void_panel.png");
1703 $rect{erase_arrow} = SDL::Rect->new( $x - $rect{middle}->x,
1704 $type =~ /up/ ? 180 : 202,
1705 $surf_list_arrow->w, $surf_list_arrow->h);
1706
1707 SDL::Video::blit_surface( $surf_arrow_background, $rect{erase_arrow}, $app, $rect{list_arrow_dest});
1708 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1709
1710 SDL::Video::blit_surface( $surf_list_arrow, $rect{list_arrow_src}, $app, $rect{list_arrow_dest});
1711 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1712
1713 if ($do_highlight && is_ok_modify_selected_level($type)) {
1714 SDL::Video::blit_surface( $highlight, $rect{list_arrow_src}, $app, $rect{list_arrow_dest});
1715 SDL::Video::update_rects($app,$rect{list_arrow_dest});
1716 }
1717 }
1718
1719 sub print_dialog_select_level_arrow_down {
1720 my ($do_highlight) = @_;
1721 print_dialog_select_level_arrow($do_highlight, 'down');
1722 }
1723
1724 sub print_dialog_select_level_arrow_up {
1725 my ($do_highlight) = @_;
1726 print_dialog_select_level_arrow($do_highlight, 'up');
1727 }
1728
1729 sub print_dialog_select_level_arrow_down_more {
1730 my ($do_highlight) = @_;
1731 print_dialog_select_level_arrow($do_highlight, 'down_more');
1732 }
1733
1734 sub print_dialog_select_level_arrow_up_more {
1735 my ($do_highlight) = @_;
1736 print_dialog_select_level_arrow($do_highlight, 'up_more');
1737 }
1738
1739 sub print_dialog_list_arrow_down {
1740 my ($do_highlight) = @_;
1741 print_dialog_list_arrow($do_highlight, 'down');
1742 }
1743
1744 sub print_dialog_list_arrow_up {
1745 my ($do_highlight) = @_;
1746 print_dialog_list_arrow($do_highlight, 'up');
1747 }
1748
1749 # subroutine to print out the levelset name at the top of the screen
1750 sub print_levelset_name {
1751 $rect{ls_name_erase} = SDL::Rect->new( 195, 0, 445-195, 35);
1752 SDL::Video::blit_surface( $background, $rect{ls_name_erase}, $app, $rect{ls_name_erase});
1753 SDLx::SFont::print_text( $app,($background->w - SDL_TEXTWIDTH(uc($levelset_name)))/2 - 6, 7, uc($levelset_name));
1754
1755 SDL::Video::update_rects($app, SDL::Rect->new(0,0,$app->w, $app->h) );
1756 }
1757
1758 sub print_text_generic {
1759 my ($do_highlight, $name, $xpos, $ypos, $text) = @_;
1760
1761 SDL::Video::blit_surface($background, $rect{$name}, $app, $rect{$name});
1762 SDL::Video::update_rects($app,$rect{$name});
1763
1764 SDLx::SFont::print_text( $app,$xpos, $ypos, $text || uc($name));
1765
1766 if ($do_highlight) {
1767 SDL::Video::blit_surface( $highlight, $rect{option_highlight}, $app, $rect{$name});
1768 SDL::Video::update_rects($app,$rect{$name});
1769 }
1770 }
1771
1772 sub print_first_text {
1773 print_text_generic($_[0], 'first', $WOOD_WIDTH/2, $rect{first}->y + 6);
1774 }
1775
1776 sub print_last_text {
1777 print_text_generic($_[0], 'last', 20, $rect{last}->y + 6);
1778 }
1779
1780 sub print_prev_text {
1781 print_text_generic($_[0], 'prev', $WOOD_WIDTH/2, $rect{prev}->y + 6);
1782 }
1783
1784 sub print_next_text {
1785 print_text_generic($_[0], 'next', 20, $rect{next}->y + 6);
1786 }
1787
1788 sub print_ls_delete_text {
1789 print_text_generic($_[0], 'ls_delete', $rect{ls_delete}->x + 12, $rect{ls_delete}->y + 6, 'DELETE');
1790 }
1791
1792 sub print_ls_new_text {
1793 print_text_generic($_[0], 'ls_new', $rect{ls_new}->x + $WOOD_WIDTH/2, $rect{ls_new}->y + 6, 'NEW');
1794 }
1795
1796 sub print_ls_open_text {
1797 print_text_generic($_[0], 'ls_open', $rect{ls_open}->x + 35, $rect{ls_open}->y + 6, 'OPEN');
1798 }
1799
1800 sub print_ls_save_text {
1801 print_text_generic($_[0], 'ls_save', $rect{ls_save}->x + $WOOD_WIDTH/2, $rect{ls_save}->y + 6, 'SAVE');
1802 }
1803
1804 sub print_lvl_append_text {
1805 print_text_generic($_[0], 'lvl_append', $rect{lvl_append}->x + 20, $rect{lvl_append}->y + 6, 'APPEND');
1806 }
1807
1808 sub print_lvl_delete_text {
1809 print_text_generic($_[0], 'lvl_delete', $rect{lvl_delete}->x + $WOOD_WIDTH/2, $rect{lvl_delete}->y + 6, 'DELETE');
1810 }
1811
1812 sub print_lvl_insert_text {
1813 print_text_generic($_[0], 'lvl_insert', $rect{lvl_insert}->x + $WOOD_WIDTH/2 - 5, $rect{lvl_insert}->y + 6, 'INSERT');
1814 }
1815
1816 sub print_help_text {
1817 print_text_generic($_[0], 'help', $rect{help}->x + 20, $rect{help}->y + 6, 'HELP!');
1818 }
1819
1820 # filename is OK == not blank or pre-existing
1821 sub is_ok_filename {
1822 length($new_ls_name_text) == 0 and return 0;
1823
1824 lc($new_ls_name_text) eq lc($_) and return 0 foreach get_levelset_list();
1825
1826 return 1;
1827 }
1828
1829
1830 # subroutine to determine if the entered jump to level value is OK
1831 sub is_ok_jump_value {
1832 if (length($jump_to_level_value) == 0 || $jump_to_level_value == 0 || $jump_to_level_value > keys %bubble_hash) {
1833 return 0;
1834 } else {
1835 return 1;
1836 }
1837
1838 }
1839
1840 sub is_ok_select_start_value {
1841
1842 my ($proposed_level) = @_;
1843 if ($proposed_level >= 1 && $proposed_level <= $file_browser_levelsets_num_levels[$list_browser_highlight_offset]) {
1844 return 1;
1845 } else {
1846 return 0;
1847 }
1848
1849 }
1850
1851 # subroutine to get the letter pressed by the user on the keyboard
1852 # this subroutine is taken from frozen-bubble code
1853 sub keysym_to_char($) {
1854 my ($key) = @_;
1855 my $name = SDL::Events::get_key_name($key);
1856 return uc($name) if $name;
1857 eval "$key eq SDLK_$_" and return uc($_) foreach @Games::FrozenBubble::Symbols::syms;
1858 }
1859
1860
1861 sub print_jump_to_level_value {
1862
1863 my ($key) = @_;
1864 if ($key == SDLK_ESCAPE()) {
1865 highlight_option('cancel');
1866 SDL::delay(200);
1867 remove_dialog();
1868 } elsif (($key == SDLK_RETURN() || $key == SDLK_KP_ENTER()) && length($jump_to_level_value) > 0 ) {
1869 highlight_option('ok');
1870 SDL::delay(200);
1871 remove_dialog();
1872 jump_to_level($jump_to_level_value);
1873 } elsif ($key == SDLK_BACKSPACE() || ($key >= SDLK_0() && $key <= SDLK_9()) || ( $key >= SDLK_KP0() && $key <= SDLK_KP9())) {
1874 #- translate keypad values to real values
1875 if ($key >= SDLK_KP0() && $key <= SDLK_KP9()) {
1876 foreach (0..9) {
1877 if (eval("$key == SDLK_KP$_()")) {
1878 $key = eval("SDLK_$_()");
1879 }
1880 }
1881 }
1882 # first erase the previous words
1883 $rect{dialog_blank} = SDL::Rect->new(0, 2 * $WOOD_PLANK_HEIGHT,
1884 $surface_dialog->w,
1885 $surface_dialog->h - 3 * $WOOD_PLANK_HEIGHT);
1886 $rect{dialog_new} = SDL::Rect->new( $background->w/2 - $surface_dialog->w/2,
1887 $background->h/2 - $surface_dialog->h/2 + 2 * $WOOD_PLANK_HEIGHT,
1888 $surface_dialog->w,
1889 $surface_dialog->h - 3*$WOOD_PLANK_HEIGHT);
1890 SDL::Video::blit_surface( $surface_dialog, $rect{dialog_blank}, $app, $rect{dialog_new});
1891 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
1892 if ($key == SDLK_BACKSPACE()) {
1893 chop $jump_to_level_value;
1894 } else {
1895 #- adjust the value, but then check to make sure its a valid value
1896 $jump_to_level_value .= keysym_to_char($key);
1897 if (!is_ok_jump_value()) {
1898 chop $jump_to_level_value;
1899 unhighlight_option();
1900 }
1901 }
1902
1903 SDLx::SFont::print_text( $app,$rect{dialog_new}->x + $rect{dialog_new}->w/2 - 12 * length($jump_to_level_value)/2, 210, $jump_to_level_value);
1904
1905 }
1906 }
1907
1908 # subroutine to print the name of the new levelset in the dialog
1909 sub print_new_ls_name {
1910 my ($key) = @_;
1911 if ($key == SDLK_ESCAPE()) {
1912 if ($displaying_dialog eq 'ls_new') {
1913 highlight_option('cancel');
1914 SDL::delay(200);
1915 remove_dialog();
1916 }
1917 } elsif (($key == SDLK_RETURN() || $key == SDLK_KP_ENTER()) && length($new_ls_name_text) > 0 && is_ok_filename() ) {
1918 if ($displaying_dialog eq 'ls_new') {
1919 highlight_option('ok');
1920 } elsif ($displaying_dialog eq 'ls_new_ok_only') {
1921 highlight_option('ok_right');
1922 }
1923 SDL::delay(200);
1924 remove_dialog();
1925 create_new_levelset();
1926 } elsif ($key == SDLK_BACKSPACE()
1927 || (length($new_ls_name_text) < 14 && ($key == SDLK_KP_MINUS()
1928 || $key >= SDLK_KP0() && $key <= SDLK_KP9()
1929 || $key >= SDLK_a() && $key <= SDLK_z()
1930 || $key == SDLK_MINUS()
1931 || $key >= SDLK_0 && $key <= SDLK_9()))) {
1932 # first erase the previous words
1933 $rect{dialog_blank} = SDL::Rect->new(0, 2 * $WOOD_PLANK_HEIGHT,
1934 $surface_dialog->w,
1935 $surface_dialog->h - 3 * $WOOD_PLANK_HEIGHT);
1936 $rect{dialog_new} = SDL::Rect->new( $background->w/2 - $surface_dialog->w/2,
1937 $background->h/2 - $surface_dialog->h/2 + 2 * $WOOD_PLANK_HEIGHT,
1938 $surface_dialog->w,
1939 $surface_dialog->h - 3*$WOOD_PLANK_HEIGHT);
1940 SDL::Video::blit_surface( $surface_dialog, $rect{dialog_blank}, $app, $rect{dialog_new});
1941 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
1942 if ($key == SDLK_BACKSPACE()) {
1943 chop $new_ls_name_text;
1944 } elsif ($key == SDLK_MINUS() || $key == SDLK_KP_MINUS()) {
1945 $new_ls_name_text .= '-';
1946 } elsif ($key >= SDLK_KP0() && $key <= SDLK_KP9()) {
1947 my $kp_num;
1948 eval("SDLK_KP$_() eq $key") and $new_ls_name_text .= $_ foreach 0..9;
1949 } else {
1950 $new_ls_name_text .= keysym_to_char($key);
1951 }
1952 SDLx::SFont::print_text( $app,$rect{dialog_new}->x + $rect{dialog_new}->w/2 - 12 * length($new_ls_name_text)/2, 210, $new_ls_name_text);
1953
1954 }
1955
1956 # if the filename is bad, unhighlight any option that is highlighted since
1957 # they can't do anything...
1958 is_ok_filename() == 0 and unhighlight_option();
1959
1960 }
1961
1962 # subroutine to print the ok text on the right side of the dialog
1963 sub print_ok_right_text {
1964 my ($do_highlight) = @_;
1965 if ($displaying_dialog ne '') {
1966 $rect{middle} = get_dialog_rect();
1967
1968 $rect{cancel_src} = SDL::Rect->new( $rect{middle}->w - $rect{option_highlight}->w,
1969 6 * $WOOD_PLANK_HEIGHT - 4,
1970 $rect{middle}->w/2,
1971 $WOOD_PLANK_HEIGHT);
1972
1973 $rect{cancel} = SDL::Rect->new( $rect{middle}->x + $rect{middle}->w - $rect{option_highlight}->w,
1974 $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT - 4,
1975 $rect{middle}->w/2,
1976 $WOOD_PLANK_HEIGHT);
1977
1978 SDL::Video::blit_surface( $surface_dialog, $rect{cancel_src}, $app, $rect{cancel});
1979 SDL::Video::update_rects($app,$rect{cancel});
1980
1981 SDLx::SFont::print_text( $app,$rect{middle}->x + $rect{middle}->w - 80, $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT, 'OK');
1982
1983 if ($do_highlight) {
1984 SDL::Video::blit_surface( $highlight, $rect{option_highlight}, $app, $rect{cancel});
1985 SDL::Video::update_rects($app,$rect{cancel});
1986 }
1987 }
1988 }
1989
1990 sub print_ok_text {
1991 my ($do_highlight) = @_;
1992
1993 if ($displaying_dialog ne '') {
1994 $rect{middle} = get_dialog_rect();
1995
1996 $rect{ok_src} = SDL::Rect->new(0, 6 * $WOOD_PLANK_HEIGHT - 4,
1997 $rect{middle}->w/2,
1998 $WOOD_PLANK_HEIGHT);
1999
2000 $rect{ok} = SDL::Rect->new( $rect{middle}->x,
2001 $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT - 4,
2002 $rect{middle}->w/2,
2003 $WOOD_PLANK_HEIGHT);
2004
2005 SDL::Video::blit_surface( $surface_dialog, $rect{ok_src}, $app, $rect{ok});
2006 SDL::Video::update_rects($app,$rect{ok});
2007
2008 SDLx::SFont::print_text( $app,$rect{middle}->x + 60, $rect{middle}->y + 6 * $WOOD_PLANK_HEIGHT, 'OK');
2009
2010 if ($do_highlight) {
2011 SDL::Video::blit_surface( $highlight, $rect{option_highlight}, $app, $rect{ok});
2012 SDL::Video::update_rects($app,$rect{ok});
2013 }
2014 }
2015 }
2016
2017 sub print_level_nb {
2018 my $posx = 183;
2019 my $posy = 421;
2020 my $level_sign_rect = SDL::Rect->new($posx - 50, $posy, 100, 25);
2021 SDL::Video::blit_surface( $background, $level_sign_rect, $app, $level_sign_rect);
2022 my $text = "$curr_level/" . keys %bubble_hash;
2023 SDLx::SFont::print_text( $app,$posx - 12 * length($text)/2, $posy, $text);
2024
2025 SDL::Video::update_rects($app,$level_sign_rect);
2026 }
2027
2028
2029 #- ----------- initialization stuff ------------------------------------------
2030
2031 # subroutine to add specific bubble option
2032 sub add_bubble_option {
2033 my ($bubble_id, $col, $row) = @_;
2034 draw_bubble($bubble_id, bubble_optionx($col), bubble_optiony($row), $ALPHA_BUBBLE_NO);
2035 }
2036
2037 # subroutine to add the bubble options
2038 sub add_bubble_options {
2039 my ($count, $col_count);
2040 # add my list of bubbles on the left
2041 $count = 0;
2042
2043 while ($count < $NUM_BUBBLES_AVAIL) {
2044 $col_count = 0;
2045 while ($col_count < $BUBBLES_PER_ROW && $count < $NUM_BUBBLES_AVAIL) {
2046 add_bubble_option($count + 1, $col_count, floor($count/$BUBBLES_PER_ROW));
2047 $col_count++;
2048 $count++;
2049 }
2050 }
2051
2052 if ($col_count >= $BUBBLES_PER_ROW) {
2053 $col_count = 0;
2054 }
2055
2056 }
2057
2058 # subroutine to add the erase option
2059 sub add_erase_option {
2060 my $erase = SDL::Image::load("$FPATH/gfx/balls/stick_effect_6.png");
2061 SDL::Video::blit_surface( $erase, SDL::Rect->new(0,0,$erase->w, $background->h), $app, $rect{erase});
2062 SDL::Video::update_rects( $app, $rect{erase});
2063 }
2064
2065 # subroutine to do the initial setup
2066 sub init_setup {
2067 my ($application_caller, $sdlapp) = @_;
2068
2069 init_app($application_caller, $sdlapp);
2070
2071 SDL::Video::blit_surface($background, SDL::Rect->new(0,0,$background->w, $background->h), $app, $rect{background});
2072 SDL::Video::update_rects( $app, $rect{background});
2073
2074 add_bubble_options();
2075 add_erase_option();
2076
2077 # set font
2078 $font = SDLx::SFont->new("$FPATH/gfx/font.png");
2079 SDLx::SFont::print_text( $app,5, $BUBBLE_WOOD_Y + 3, 'CHOOSE BUBBLE');
2080
2081
2082 # add navigation words
2083 SDLx::SFont::print_text( $app,20, $NAV_WOOD_Y + 8,'NAVIGATION');
2084
2085 print_prev_text(0);
2086 print_next_text(0);
2087 print_first_text(0);
2088 print_last_text(0);
2089
2090 # add levelset words
2091 SDLx::SFont::print_text( $app,$RIGHT_WOOD_X + 30, $LEVELSET_WOOD_Y + 8, 'LEVELSET');
2092
2093 print_ls_new_text(0);
2094 print_ls_open_text(0);
2095 print_ls_save_text(0);
2096 print_ls_delete_text(0);
2097
2098 # add level words
2099 SDLx::SFont::print_text( $app,$RIGHT_WOOD_X + 45, $LEVEL_WOOD_Y + 8, 'LEVEL');
2100
2101 print_lvl_insert_text(0);
2102 print_lvl_append_text(0);
2103 print_lvl_delete_text(0);
2104
2105 # add help words
2106 print_help_text(0);
2107
2108 # add initial bubble to draw
2109 change_color(1);
2110
2111 $modified_levelset = 0;
2112 -d "$FBLEVELS" or mkdir "$FBLEVELS" or die "Can't create $FBLEVELS directory.\n";
2113 -f "$FBLEVELS/default-levelset" or cp_af("$FPATH/data/levels", "$FBLEVELS/default-levelset");
2114
2115 %bubble_hash = read_file($levelset_name);
2116
2117 # if inputted level is > the number of levels than reset current level to 1
2118 $curr_level > keys %bubble_hash and $curr_level = 1;
2119 load_level();
2120
2121 SDL::Mouse::warp_mouse(320, 240);
2122
2123 print_levelset_name();
2124 SDL::Video::update_rect($app, 0 , 0, $app->w, $app->h);
2125
2126 $button_hold = 0;
2127 }
2128
2129 # subroutine to initialize the application
2130 sub init_app {
2131 my ($application_caller, $sdlapp) = @_;
2132 my @rcfile_data;
2133
2134 $app = $sdlapp;
2135 # we only want to check to see if we're in full screen if we're
2136 # running as a stand alone app. If we're running embedded in the
2137 # game, we'll use whatever is already set up
2138 if ($application_caller eq 'stand-alone') {
2139 @rcfile_data = cat_("$FBHOME/rc");
2140
2141 if ($command_line_fullscreen == 1) {
2142 $app->fullscreen;
2143 } elsif ($rcfile_data[0] eq "\$fullscreen = 1;\n") {
2144 $app->fullscreen;
2145 }
2146 } else {
2147 # we need to set the default levelset name to "default-levelset"
2148 $levelset_name = 'default-levelset';
2149 $curr_level = 1;
2150 }
2151
2152 $font = SDLx::SFont->new("$FPATH/gfx/font.png");
2153
2154 # background image
2155 $background = SDL::Image::load( "$FPATH/gfx/level_editor.png");
2156
2157 my @allrects =
2158 ({ name => 'background', width => $background->w, height => $background->h },
2159 # bubble wood rectangle (without heading part)
2160 { name => 'bubble_wood', x => $LEFT_WOOD_X, 'y' => $BUBBLE_WOOD_Y + $WOOD_PLANK_HEIGHT,
2161 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT * ($NUM_BUBBLES_AVAIL + 1)/$BUBBLES_PER_ROW },
2162 { name => 'erase', x => bubble_optionx($NUM_BUBBLES_AVAIL % $BUBBLES_PER_ROW),
2163 'y' => bubble_optiony(floor($NUM_BUBBLES_AVAIL / $BUBBLES_PER_ROW)),
2164 width => $BUBBLE_SIZE, height => $BUBBLE_SIZE },
2165
2166 # navigation rectangles
2167 { name => 'prev', x => $LEFT_WOOD_X, 'y' => $NAV_WOOD_Y + $WOOD_PLANK_HEIGHT,
2168 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2169 { name => 'next', x => $LEFT_WOOD_X, 'y' => $NAV_WOOD_Y + 2 * $WOOD_PLANK_HEIGHT,
2170 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2171 { name => 'first', x => $LEFT_WOOD_X, 'y' => $NAV_WOOD_Y + 3 * $WOOD_PLANK_HEIGHT,
2172 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2173 { name => 'last', x => $LEFT_WOOD_X, 'y' => $NAV_WOOD_Y + 4 * $WOOD_PLANK_HEIGHT,
2174 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2175
2176 # levelset rectangles
2177 { name => 'ls_new', x => $RIGHT_WOOD_X, 'y' => $LEVELSET_WOOD_Y + $WOOD_PLANK_HEIGHT,
2178 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2179 { name => 'ls_open', x => $RIGHT_WOOD_X, 'y' => $LEVELSET_WOOD_Y + 2 * $WOOD_PLANK_HEIGHT,
2180 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2181 { name => 'ls_save', x => $RIGHT_WOOD_X, 'y' => $LEVELSET_WOOD_Y + 3 * $WOOD_PLANK_HEIGHT,
2182 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2183 { name => 'ls_delete', x => $RIGHT_WOOD_X, 'y' => $LEVELSET_WOOD_Y + 4 * $WOOD_PLANK_HEIGHT,
2184 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2185
2186 # level rectangles
2187 { name => 'lvl_insert', x => $RIGHT_WOOD_X, 'y' => $LEVEL_WOOD_Y + $WOOD_PLANK_HEIGHT,
2188 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2189 { name => 'lvl_append', x => $RIGHT_WOOD_X, 'y' => $LEVEL_WOOD_Y + 2 * $WOOD_PLANK_HEIGHT,
2190 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2191 { name => 'lvl_delete', x => $RIGHT_WOOD_X, 'y' => $LEVEL_WOOD_Y + 3 * $WOOD_PLANK_HEIGHT,
2192 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT },
2193
2194 # help rectangle
2195 { name => 'help', x => $RIGHT_WOOD_X, 'y' => $HELP_WOOD_Y,
2196 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT},
2197
2198 { name => 'bubble_option_highlight', x => 0, 'y' => 0,
2199 width => $BUBBLE_SIZE, height => $BUBBLE_SIZE },
2200 { name => 'option_highlight', x => 0, 'y' => 0,
2201 width => $WOOD_WIDTH, height => $WOOD_PLANK_HEIGHT }
2202 );
2203
2204 $rect{$_->{name}} = SDL::Rect->new( $_->{x}, $_->{'y'}, $_->{width}, $_->{height}) foreach @allrects;
2205
2206 $highlight = SDL::Image::load("$FPATH/gfx/hover.gif");
2207 SDL::Video::set_alpha($highlight, SDL_SRCALPHA, 0x44);
2208 }
2209
2210
2211 1;
2212
2213 __END__
2214
2215 =encoding UTF-8
2216
2217 =head1 Frozen-Bubble Level Editor
2218
2219 Copyright © 2002 - 2003 Kim Joham and David Joham <[k|d][email protected]>
2220
2221 This program is free software; you can redistribute it and/or modify
2222 it under the terms of the GNU General Public License version 2, as
2223 published by the Free Software Foundation.
2224
2225 This program is distributed in the hope that it will be useful,
2226 but WITHOUT ANY WARRANTY; without even the implied warranty of
2227 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2228 GNU General Public License for more details.
2229
2230 You should have received a copy of the GNU General Public License
2231 along with this program; if not, write to the Free Software
2232 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2233
2234 Design & Programming by Kim Joham and David Joham, October 2002 - May 2003
2235
2236 Integration to Frozen-Bubble by Guillaume Cottenceau - change a few styles
2237 things, fix a few bugs, add a few features