ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.125 by elmex, Mon Apr 17 20:29:37 2006 UTC vs.
Revision 1.137 by elmex, Tue Apr 18 21:31:48 2006 UTC

8 8
9use SDL; 9use SDL;
10use SDL::App; 10use SDL::App;
11use SDL::Event; 11use SDL::Event;
12use SDL::Surface; 12use SDL::Surface;
13
14use SDL::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
13use SDL::OpenGL; 18use SDL::OpenGL;
14 19
15use Crossfire; 20use Crossfire;
16use Crossfire::Protocol; 21use Crossfire::Protocol;
17 22
55 60
56our $SDL_ACTIVE; 61our $SDL_ACTIVE;
57our $SDL_EV; 62our $SDL_EV;
58our %SDL_CB; 63our %SDL_CB;
59 64
65our $SDL_MIXER;
66our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files
68
60our $ALT_ENTER_MESSAGE; 69our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 70our $STATUS_LINE;
62our $DEBUG_STATUS; 71our $DEBUG_STATUS;
63 72
64sub status { 73sub status {
65 $STATUS_LINE->set_text ($_[0]); 74 $STATUS_LINE->set_text ($_[0]);
66 my ($w, $h) = $STATUS_LINE->size_request;
67 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 75 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
68} 76}
69 77
70sub debug { 78sub debug {
71 $DEBUG_STATUS->set_text ($_[0]); 79 $DEBUG_STATUS->set_text ($_[0]);
72 my ($w, $h) = $DEBUG_STATUS->size_request; 80 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
73 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
74} 81}
75 82
76sub start_game { 83sub start_game {
77 status "logging in..."; 84 status "logging in...";
78 85
148 155
149 $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");
150 $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 {
151 my ($self, $value) = @_; 158 my ($self, $value) = @_;
152 $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;
153 }); 161 });
154 162
155 $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");
156 $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 {
157 my ($self, $value) = @_; 165 my ($self, $value) = @_;
158 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value);
159 }); 167 });
160 168
161 $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 {
162 destroy_screen (); 170 video_shutdown ();
163 init_screen (); 171 video_init ();
172 });
173
174 $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound");
175 $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{sound} = $value;
178 });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bg_music_enable} = $value;
183 });
184 $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
185 audio_shutdown ();
186 audio_init ();
164 }); 187 });
165 188
166 $dialog 189 $dialog
167} 190}
168 191
356 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 379 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
357 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 380 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
358 and die "SDL::Init failed!\n"; 381 and die "SDL::Init failed!\n";
359} 382}
360 383
361sub init_screen { 384sub video_init {
362 sdl_init; 385 sdl_init;
363 386
364 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 387 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
365 $FULLSCREEN = $CFG->{fullscreen}; 388 $FULLSCREEN = $CFG->{fullscreen};
366 $FAST = $CFG->{fast}; 389 $FAST = $CFG->{fast};
440 status "Configuration Saved"; 463 status "Configuration Saved";
441 }); 464 });
442 465
443 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 466 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
444 467
445 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 150, y => 0); 468 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
446 $tgw->add (my $hb = new CFClient::UI::HBox (req_w => 60, req_h => 150)); 469 $tgw->add (my $hbox = new CFClient::UI::HBox ());
447 $hb->add (my $fg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'food', expand => 1)); 470
471 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
448 $hb->add (my $mg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'mana', expand => 1)); 472 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
449 $hb->add (my $hg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'hp', expand => 1));
450 $hb->add (my $gg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'grace', expand => 1)); 473 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
474 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
451 475
452 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 476 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
453 $CFClient::UI::ROOT->add ($tgw); 477 $CFClient::UI::ROOT->add ($tgw);
454} 478}
455 479
456sub destroy_screen { 480sub video_shutdown {
457 $CFClient::UI::ROOT->{children} = []; 481 $CFClient::UI::ROOT->{children} = [];
458 undef $SDL_ACTIVE; 482 undef $SDL_ACTIVE;
459 undef $SDL_EV; 483 undef $SDL_EV;
460 SDL::Quit; 484}
485
486my $bgmusic;#TODO#hack#d#
487
488sub audio_init {
489 if ($CFG->{sound} || 1) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer;
492 $SDL_MIXER->allocate_channels (8);
493
494 if ($CFG->{bg_music_enable}) {
495 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
496 $SDL_MIXER->play_music ($bgmusic, -1);
497 }
498
499 while (<$fh>) {
500 next if /^\s*#/;
501 next if /^\s*$/;
502
503 my ($file, $volume, $event) = split /\s+/, $_, 3;
504
505 push @SOUNDS, "$volume,$file";
506
507 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
508 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
509 $chunk->volume ($volume * 128 / 100);
510 $chunk
511 };
512 }
513 } else {
514 status "unable to open sound config: $!";
515 }
516 }
517}
518
519sub audio_shutdown {
520 undef $SDL_MIXER;
521 @SOUNDS = ();
522 %AUDIO_CHUNKS = ();
461} 523}
462 524
463my %animate_object; 525my %animate_object;
464my $animate_timer; 526my $animate_timer;
465 527
635 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 697 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
636 698
637 $self->flush_map; 699 $self->flush_map;
638 700
639 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 701 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
640
641 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
642 702
643 my $mapmapw = 250; 703 my $mapmapw = 250;
644 my $mapmaph = 250; 704 my $mapmaph = 250;
645 705
646 $self->flood_fill ("", $hash, $flags, 706 $self->flood_fill ("", $hash, $flags,
708 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 768 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
709 $MAPWIDGET->update; 769 $MAPWIDGET->update;
710 770
711 $tex 771 $tex
712 }; 772 };
773}
774
775sub conn::sound_play {
776 my ($self, $x, $y, $soundnum, $type) = @_;
777
778 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
779 or return;
780
781 $SDL_MIXER->play_channel (-1, $chunk);
782 warn "sound $x,$y,$soundnum,$type\n";#d#
713} 783}
714 784
715sub conn::query { 785sub conn::query {
716 my ($self, $flags, $prompt) = @_; 786 my ($self, $flags, $prompt) = @_;
717 787
751 refresh; 821 refresh;
752 }, 822 },
753 SDL_KEYDOWN() => sub { 823 SDL_KEYDOWN() => sub {
754 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 824 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
755 # alt-enter 825 # alt-enter
756 destroy_screen; 826 video_shutdown;
757 $CFG->{fullscreen} = !$CFG->{fullscreen}; 827 $CFG->{fullscreen} = !$CFG->{fullscreen};
758 init_screen; 828 video_init;
759 } else { 829 } else {
760 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 830 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
761 } 831 }
762 }, 832 },
763 SDL_KEYUP() => sub { 833 SDL_KEYUP() => sub {
777 }, 847 },
778); 848);
779 849
780############################################################################# 850#############################################################################
781 851
852$SIG{INT} = $SIG{TERM} = sub { exit };
853
782$TILECACHE = CFClient::db_table "tilecache"; 854$TILECACHE = CFClient::db_table "tilecache";
783$FACEMAP = CFClient::db_table "facemap"; 855$FACEMAP = CFClient::db_table "facemap";
784 856
785CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 857CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
786 858
819 891
820 CFClient::add_font $_ for @fonts; 892 CFClient::add_font $_ for @fonts;
821 CFClient::set_font $fonts[0]; 893 CFClient::set_font $fonts[0];
822} 894}
823 895
824init_screen; 896video_init;
897audio_init;
825 898
826Event::loop; 899Event::loop;
827 900
901END { SDL::Quit }
828 902
903

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines