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.124 by root, Mon Apr 17 19:50:23 2006 UTC vs.
Revision 1.134 by root, Tue Apr 18 05:13:15 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::Sound;
15use SDL::Mixer;
16
13use SDL::OpenGL; 17use SDL::OpenGL;
14 18
15use Crossfire; 19use Crossfire;
16use Crossfire::Protocol; 20use Crossfire::Protocol;
17 21
49our $BUTTONBAR; 53our $BUTTONBAR;
50our $LOGVIEW; 54our $LOGVIEW;
51our $CONSOLE; 55our $CONSOLE;
52our $METASERVER; 56our $METASERVER;
53 57
58our $GAUGES;
59
54our $SDL_ACTIVE; 60our $SDL_ACTIVE;
55our $SDL_EV; 61our $SDL_EV;
56our %SDL_CB; 62our %SDL_CB;
57 63
64our $SDL_MIXER;
65our @SOUNDS; # event => file mapping
66our %AUDIO_CHUNKS; # audio files
67
58our $ALT_ENTER_MESSAGE; 68our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 69our $STATUS_LINE;
60our $DEBUG_STATUS; 70our $DEBUG_STATUS;
61 71
62sub status { 72sub status {
63 $STATUS_LINE->set_text ($_[0]); 73 $STATUS_LINE->set_text ($_[0]);
64 my ($w, $h) = $STATUS_LINE->size_request;
65 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 74 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
66} 75}
67 76
68sub debug { 77sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 78 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 79 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
71 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
72} 80}
73 81
74sub start_game { 82sub start_game {
75 status "logging in..."; 83 status "logging in...";
76 84
146 154
147 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 155 $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 { 156 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
149 my ($self, $value) = @_; 157 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 158 $CFG->{fow_smooth} = $value;
159 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 160 });
152 161
153 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 162 $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 { 163 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub {
155 my ($self, $value) = @_; 164 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 165 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value);
157 }); 166 });
158 167
159 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 168 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
160 destroy_screen (); 169 video_shutdown ();
161 init_screen (); 170 video_init ();
162 }); 171 });
163 172
164 $dialog 173 $dialog
165} 174}
166 175
354 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 363 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
355 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 364 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 365 and die "SDL::Init failed!\n";
357} 366}
358 367
359sub init_screen { 368sub video_init {
360 sdl_init; 369 sdl_init;
361 370
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 371 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 372 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 373 $FAST = $CFG->{fast};
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 446 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 447 status "Configuration Saved";
439 }); 448 });
440 449
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 450 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 451
444sub destroy_screen { 452 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
453 $tgw->add (my $hbox = new CFClient::UI::HBox ());
454
455 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
456 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
457 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
458 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
459
460 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
461 $CFClient::UI::ROOT->add ($tgw);
462}
463
464sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 465 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 466 undef $SDL_ACTIVE;
447 undef $SDL_EV; 467 undef $SDL_EV;
448 SDL::Quit; 468}
469
470sub audio_init {
471 if ($CFG->{sound} || 1) {
472 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
473 $SDL_MIXER = new SDL::Mixer;
474 $SDL_MIXER->allocate_channels (8);
475
476 while (<$fh>) {
477 next if /^\s*#/;
478 next if /^\s*$/;
479
480 my ($file, $volume, $event) = split /\s+/, $_, 3;
481
482 push @SOUNDS, "$volume,$file";
483
484 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
485 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
486 $chunk->volume ($volume * 128 / 100);
487 $chunk
488 };
489 }
490 } else {
491 status "unable to open sound config: $!";
492 }
493 }
494}
495
496sub audio_shutdown {
497 undef $SDL_MIXER;
498 @SOUNDS = ();
499 %AUDIO_CHUNKS = ();
449} 500}
450 501
451my %animate_object; 502my %animate_object;
452my $animate_timer; 503my $animate_timer;
453 504
502 delete $animate_object{$widget}; 553 delete $animate_object{$widget};
503} 554}
504 555
505@conn::ISA = Crossfire::Protocol::; 556@conn::ISA = Crossfire::Protocol::;
506 557
558sub conn::stats_update {
559 my ($self, $stats) = @_;
560
561 # i love text protocols!!!
562 # FIXME: the stats are somehow weird
563 my $hp = $stats->{1};
564 my $hp_m = $stats->{2};
565 my $sp = $stats->{3};
566 my $sp_m = $stats->{4};
567 my $fo = $stats->{18};
568 my $fo_m = 1000;
569 my $gr = $stats->{23};
570 my $gr_m = $stats->{24};
571
572 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
573 $GAUGES->{hp}->set_value ($hp, $hp_m);
574 $GAUGES->{mana}->set_value ($sp, $sp_m);
575 $GAUGES->{food}->set_value ($fo, $fo_m);
576 $GAUGES->{grace}->set_value ($gr, $gr_m);
577}
578
507sub conn::user_send { 579sub conn::user_send {
508 my ($self, $command) = @_; 580 my ($self, $command) = @_;
509 581
510 $self->send_command ($command); 582 $self->send_command ($command);
511 status $command; 583 status $command;
602 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 674 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
603 675
604 $self->flush_map; 676 $self->flush_map;
605 677
606 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 678 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
607
608 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
609 679
610 my $mapmapw = 250; 680 my $mapmapw = 250;
611 my $mapmaph = 250; 681 my $mapmaph = 250;
612 682
613 $self->flood_fill ("", $hash, $flags, 683 $self->flood_fill ("", $hash, $flags,
675 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 745 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
676 $MAPWIDGET->update; 746 $MAPWIDGET->update;
677 747
678 $tex 748 $tex
679 }; 749 };
750}
751
752sub conn::sound_play {
753 my ($self, $x, $y, $soundnum, $type) = @_;
754
755 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
756 or return;
757
758 $SDL_MIXER->play_channel (-1, $chunk);
759 warn "sound $x,$y,$soundnum,$type\n";#d#
680} 760}
681 761
682sub conn::query { 762sub conn::query {
683 my ($self, $flags, $prompt) = @_; 763 my ($self, $flags, $prompt) = @_;
684 764
718 refresh; 798 refresh;
719 }, 799 },
720 SDL_KEYDOWN() => sub { 800 SDL_KEYDOWN() => sub {
721 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 801 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
722 # alt-enter 802 # alt-enter
723 destroy_screen; 803 video_shutdown;
724 $CFG->{fullscreen} = !$CFG->{fullscreen}; 804 $CFG->{fullscreen} = !$CFG->{fullscreen};
725 init_screen; 805 video_init;
726 } else { 806 } else {
727 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 807 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
728 } 808 }
729 }, 809 },
730 SDL_KEYUP() => sub { 810 SDL_KEYUP() => sub {
744 }, 824 },
745); 825);
746 826
747############################################################################# 827#############################################################################
748 828
829$SIG{INT} = $SIG{TERM} = sub { exit };
830
749$TILECACHE = CFClient::db_table "tilecache"; 831$TILECACHE = CFClient::db_table "tilecache";
750$FACEMAP = CFClient::db_table "facemap"; 832$FACEMAP = CFClient::db_table "facemap";
751 833
752CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 834CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
753 835
786 868
787 CFClient::add_font $_ for @fonts; 869 CFClient::add_font $_ for @fonts;
788 CFClient::set_font $fonts[0]; 870 CFClient::set_font $fonts[0];
789} 871}
790 872
791init_screen; 873video_init;
874audio_init;
792 875
793Event::loop; 876Event::loop;
794 877
878END { SDL::Quit }
795 879
880

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines