… | |
… | |
8 | |
8 | |
9 | use SDL; |
9 | use SDL; |
10 | use SDL::App; |
10 | use SDL::App; |
11 | use SDL::Event; |
11 | use SDL::Event; |
12 | use SDL::Surface; |
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
13 | use SDL::OpenGL; |
18 | use SDL::OpenGL; |
14 | |
19 | |
15 | use Crossfire; |
20 | use Crossfire; |
16 | use Crossfire::Protocol; |
21 | use Crossfire::Protocol; |
17 | |
22 | |
… | |
… | |
54 | our $GAUGES; |
59 | our $GAUGES; |
55 | |
60 | |
56 | our $SDL_ACTIVE; |
61 | our $SDL_ACTIVE; |
57 | our $SDL_EV; |
62 | our $SDL_EV; |
58 | our %SDL_CB; |
63 | our %SDL_CB; |
|
|
64 | |
|
|
65 | our $SDL_MIXER; |
|
|
66 | our @SOUNDS; # event => file mapping |
|
|
67 | our %AUDIO_CHUNKS; # audio files |
59 | |
68 | |
60 | our $ALT_ENTER_MESSAGE; |
69 | our $ALT_ENTER_MESSAGE; |
61 | our $STATUS_LINE; |
70 | our $STATUS_LINE; |
62 | our $DEBUG_STATUS; |
71 | our $DEBUG_STATUS; |
63 | |
72 | |
… | |
… | |
146 | |
155 | |
147 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
156 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
148 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
157 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
149 | my ($self, $value) = @_; |
158 | my ($self, $value) = @_; |
150 | $CFG->{fow_smooth} = $value; |
159 | $CFG->{fow_smooth} = $value; |
|
|
160 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
151 | }); |
161 | }); |
152 | |
162 | |
153 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
163 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
154 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
164 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
155 | my ($self, $value) = @_; |
165 | my ($self, $value) = @_; |
156 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
166 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
157 | }); |
167 | }); |
158 | |
168 | |
159 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
169 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
160 | destroy_screen (); |
170 | video_shutdown (); |
161 | init_screen (); |
171 | video_init (); |
162 | }); |
172 | }); |
163 | |
173 | |
164 | $dialog |
174 | $dialog |
165 | } |
175 | } |
166 | |
176 | |
… | |
… | |
354 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
364 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
355 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
365 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
356 | and die "SDL::Init failed!\n"; |
366 | and die "SDL::Init failed!\n"; |
357 | } |
367 | } |
358 | |
368 | |
359 | sub init_screen { |
369 | sub video_init { |
360 | sdl_init; |
370 | sdl_init; |
361 | |
371 | |
362 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
372 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
363 | $FULLSCREEN = $CFG->{fullscreen}; |
373 | $FULLSCREEN = $CFG->{fullscreen}; |
364 | $FAST = $CFG->{fast}; |
374 | $FAST = $CFG->{fast}; |
… | |
… | |
441 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
451 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
442 | |
452 | |
443 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
453 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
444 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
454 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
445 | |
455 | |
446 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food', expand => 1)); |
456 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
447 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana', expand => 1)); |
457 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
448 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp', expand => 1)); |
|
|
449 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace', expand => 1)); |
458 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
459 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
450 | |
460 | |
451 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
461 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
452 | $CFClient::UI::ROOT->add ($tgw); |
462 | $CFClient::UI::ROOT->add ($tgw); |
453 | } |
463 | } |
454 | |
464 | |
455 | sub destroy_screen { |
465 | sub video_shutdown { |
456 | $CFClient::UI::ROOT->{children} = []; |
466 | $CFClient::UI::ROOT->{children} = []; |
457 | undef $SDL_ACTIVE; |
467 | undef $SDL_ACTIVE; |
458 | undef $SDL_EV; |
468 | undef $SDL_EV; |
459 | SDL::Quit; |
469 | } |
|
|
470 | |
|
|
471 | my $bgmusic;#TODO#hack#d# |
|
|
472 | |
|
|
473 | sub audio_init { |
|
|
474 | if ($CFG->{sound} || 1) { |
|
|
475 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
476 | $SDL_MIXER = new SDL::Mixer; |
|
|
477 | $SDL_MIXER->allocate_channels (8); |
|
|
478 | |
|
|
479 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
480 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
481 | |
|
|
482 | while (<$fh>) { |
|
|
483 | next if /^\s*#/; |
|
|
484 | next if /^\s*$/; |
|
|
485 | |
|
|
486 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
487 | |
|
|
488 | push @SOUNDS, "$volume,$file"; |
|
|
489 | |
|
|
490 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
491 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
|
|
492 | $chunk->volume ($volume * 128 / 100); |
|
|
493 | $chunk |
|
|
494 | }; |
|
|
495 | } |
|
|
496 | } else { |
|
|
497 | status "unable to open sound config: $!"; |
|
|
498 | } |
|
|
499 | } |
|
|
500 | } |
|
|
501 | |
|
|
502 | sub audio_shutdown { |
|
|
503 | undef $SDL_MIXER; |
|
|
504 | @SOUNDS = (); |
|
|
505 | %AUDIO_CHUNKS = (); |
460 | } |
506 | } |
461 | |
507 | |
462 | my %animate_object; |
508 | my %animate_object; |
463 | my $animate_timer; |
509 | my $animate_timer; |
464 | |
510 | |
… | |
… | |
634 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
680 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
635 | |
681 | |
636 | $self->flush_map; |
682 | $self->flush_map; |
637 | |
683 | |
638 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
684 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
639 | |
|
|
640 | warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# |
|
|
641 | |
685 | |
642 | my $mapmapw = 250; |
686 | my $mapmapw = 250; |
643 | my $mapmaph = 250; |
687 | my $mapmaph = 250; |
644 | |
688 | |
645 | $self->flood_fill ("", $hash, $flags, |
689 | $self->flood_fill ("", $hash, $flags, |
… | |
… | |
707 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
751 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
708 | $MAPWIDGET->update; |
752 | $MAPWIDGET->update; |
709 | |
753 | |
710 | $tex |
754 | $tex |
711 | }; |
755 | }; |
|
|
756 | } |
|
|
757 | |
|
|
758 | sub conn::sound_play { |
|
|
759 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
760 | |
|
|
761 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
762 | or return; |
|
|
763 | |
|
|
764 | $SDL_MIXER->play_channel (-1, $chunk); |
|
|
765 | warn "sound $x,$y,$soundnum,$type\n";#d# |
712 | } |
766 | } |
713 | |
767 | |
714 | sub conn::query { |
768 | sub conn::query { |
715 | my ($self, $flags, $prompt) = @_; |
769 | my ($self, $flags, $prompt) = @_; |
716 | |
770 | |
… | |
… | |
750 | refresh; |
804 | refresh; |
751 | }, |
805 | }, |
752 | SDL_KEYDOWN() => sub { |
806 | SDL_KEYDOWN() => sub { |
753 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
807 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
754 | # alt-enter |
808 | # alt-enter |
755 | destroy_screen; |
809 | video_shutdown; |
756 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
810 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
757 | init_screen; |
811 | video_init; |
758 | } else { |
812 | } else { |
759 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
813 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
760 | } |
814 | } |
761 | }, |
815 | }, |
762 | SDL_KEYUP() => sub { |
816 | SDL_KEYUP() => sub { |
… | |
… | |
776 | }, |
830 | }, |
777 | ); |
831 | ); |
778 | |
832 | |
779 | ############################################################################# |
833 | ############################################################################# |
780 | |
834 | |
|
|
835 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
836 | |
781 | $TILECACHE = CFClient::db_table "tilecache"; |
837 | $TILECACHE = CFClient::db_table "tilecache"; |
782 | $FACEMAP = CFClient::db_table "facemap"; |
838 | $FACEMAP = CFClient::db_table "facemap"; |
783 | |
839 | |
784 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
840 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
785 | |
841 | |
… | |
… | |
818 | |
874 | |
819 | CFClient::add_font $_ for @fonts; |
875 | CFClient::add_font $_ for @fonts; |
820 | CFClient::set_font $fonts[0]; |
876 | CFClient::set_font $fonts[0]; |
821 | } |
877 | } |
822 | |
878 | |
823 | init_screen; |
879 | video_init; |
|
|
880 | audio_init; |
824 | |
881 | |
825 | Event::loop; |
882 | Event::loop; |
826 | |
883 | |
|
|
884 | END { SDL::Quit } |
827 | |
885 | |
|
|
886 | |