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.121 by root, Mon Apr 17 09:33:12 2006 UTC vs.
Revision 1.136 by root, Tue Apr 18 06:34:30 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
49our $BUTTONBAR; 54our $BUTTONBAR;
50our $LOGVIEW; 55our $LOGVIEW;
51our $CONSOLE; 56our $CONSOLE;
52our $METASERVER; 57our $METASERVER;
53 58
59our $GAUGES;
60
54our $SDL_ACTIVE; 61our $SDL_ACTIVE;
55our $SDL_EV; 62our $SDL_EV;
56our %SDL_CB; 63our %SDL_CB;
57 64
65our $SDL_MIXER;
66our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files
68
58our $ALT_ENTER_MESSAGE; 69our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 70our $STATUS_LINE;
60our $DEBUG_STATUS; 71our $DEBUG_STATUS;
61 72
62sub status { 73sub status {
63 $STATUS_LINE->set_text ($_[0]); 74 $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); 75 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
66} 76}
67 77
68sub debug { 78sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 79 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 80 $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} 81}
73 82
74sub start_game { 83sub start_game {
75 status "logging in..."; 84 status "logging in...";
76 85
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
300 310
301sub message_window { 311sub message_window {
302 my $window = new CFClient::UI::FancyFrame 312 my $window = new CFClient::UI::FancyFrame
303 border_bg => [1, 1, 1, 0.5], 313 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 314 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => $::WIDTH/4, 315 user_w => int $::WIDTH / 3,
306 user_h => $::HEIGHT, 316 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 317 child => (my $vbox = new CFClient::UI::VBox);
308 318
309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 319 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
310 expand => 1, 320 expand => 1,
311 fontsize => $::CFG->{log_fontsize}, 321 fontsize => $::CFG->{log_fontsize},
312 ); 322 );
313 323
314 $vbox->add (my $input = new CFClient::UI::LineEntry 324 $vbox->add (my $input = new CFClient::UI::Entry
315 connect_focus_in => sub { 325 connect_focus_in => sub {
316 my ($input, $prev_focus) = @_; 326 my ($input, $prev_focus) = @_;
317 327
318 delete $input->{refocus_map}; 328 delete $input->{refocus_map};
319 329
325 connect_activate => sub { 335 connect_activate => sub {
326 my ($input, $text) = @_; 336 my ($input, $text) = @_;
327 $input->set_text (''); 337 $input->set_text ('');
328 338
329 if ($text =~ /^\/(.*)/) { 339 if ($text =~ /^\/(.*)/) {
330 $::CONN->user_send ("command $1"); 340 $::CONN->user_send ($1);
331 } else { 341 } else {
332 my $say_cmd = $::CFG->{say_command} || 'say'; 342 my $say_cmd = $::CFG->{say_command} || 'say';
333 $::CONN->user_send ("command $say_cmd $text"); 343 $::CONN->user_send ("$say_cmd $text");
334 } 344 }
335 if ($input->{refocus_map}) { 345 if ($input->{refocus_map}) {
336 delete $input->{refocus_map}; 346 delete $input->{refocus_map};
337 $MAPWIDGET->focus_in 347 $MAPWIDGET->focus_in
338 } 348 }
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
359sub init_screen { 369sub 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};
404 padding => 0, 414 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 415 y => $HEIGHT * 44 / 45 - $FONTSIZE;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 416 $CFClient::UI::ROOT->add ($STATUS_LINE);
407 417
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 418 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 419 padding => 0,
410 y => $HEIGHT * 44 / 45, 420 y => $HEIGHT * 44 / 45,
411 height => $HEIGHT / 45, 421 fontsize => $HEIGHT / 45,
412 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 422 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 423 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE);
414 424
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 425 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
416 $MAPWIDGET->focus_in; 426 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 427 $MAPWIDGET->connect (activate_console => sub {
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 447 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 448 status "Configuration Saved";
439 }); 449 });
440 450
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 451 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 452
444sub destroy_screen { 453 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
454 $tgw->add (my $hbox = new CFClient::UI::HBox ());
455
456 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
457 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
458 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
459 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
460
461 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
462 $CFClient::UI::ROOT->add ($tgw);
463}
464
465sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 466 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 467 undef $SDL_ACTIVE;
447 undef $SDL_EV; 468 undef $SDL_EV;
448 SDL::Quit; 469}
470
471my $bgmusic;#TODO#hack#d#
472
473sub 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
502sub audio_shutdown {
503 undef $SDL_MIXER;
504 @SOUNDS = ();
505 %AUDIO_CHUNKS = ();
449} 506}
450 507
451my %animate_object; 508my %animate_object;
452my $animate_timer; 509my $animate_timer;
453 510
502 delete $animate_object{$widget}; 559 delete $animate_object{$widget};
503} 560}
504 561
505@conn::ISA = Crossfire::Protocol::; 562@conn::ISA = Crossfire::Protocol::;
506 563
564sub conn::stats_update {
565 my ($self, $stats) = @_;
566
567 # i love text protocols!!!
568 # FIXME: the stats are somehow weird
569 my $hp = $stats->{1};
570 my $hp_m = $stats->{2};
571 my $sp = $stats->{3};
572 my $sp_m = $stats->{4};
573 my $fo = $stats->{18};
574 my $fo_m = 1000;
575 my $gr = $stats->{23};
576 my $gr_m = $stats->{24};
577
578 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
579 $GAUGES->{hp}->set_value ($hp, $hp_m);
580 $GAUGES->{mana}->set_value ($sp, $sp_m);
581 $GAUGES->{food}->set_value ($fo, $fo_m);
582 $GAUGES->{grace}->set_value ($gr, $gr_m);
583}
584
507sub conn::user_send { 585sub conn::user_send {
508 my ($self, $command) = @_; 586 my ($self, $command) = @_;
509 587
510 $self->send ($command); 588 $self->send_command ($command);
511 status $command; 589 status $command;
512} 590}
513 591
514sub conn::map_scroll { 592sub conn::map_scroll {
515 my ($self, $dx, $dy) = @_; 593 my ($self, $dx, $dy) = @_;
579 my $neigh = $self->{neigh}{$hash} ||= []; 657 my $neigh = $self->{neigh}{$hash} ||= [];
580 658
581 $self->send_mapinfo ("spatial $path$tile", sub { 659 $self->send_mapinfo ("spatial $path$tile", sub {
582 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 660 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
583 661
584 warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# 662 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
585 return if $mode ne "spatial"; 663 return if $mode ne "spatial";
586 664
587 $x += $MAP->ox; 665 $x += $MAP->ox;
588 $y += $MAP->oy; 666 $y += $MAP->oy;
589 667
590 $self->load_map ($hash, $x, $y); 668 $self->load_map ($hash, $x, $y)
669 unless $self->{neigh}{$hash}[5]++;#d#
591 670
592 $neigh->[$tile] = [$x, $y, $w, $h]; 671 $neigh->[$tile] = [$x, $y, $w, $h];
593 672
594 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 673 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1)
595 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 674 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
601 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 680 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
602 681
603 $self->flush_map; 682 $self->flush_map;
604 683
605 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 684 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
606
607 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
608 685
609 my $mapmapw = 250; 686 my $mapmapw = 250;
610 my $mapmaph = 250; 687 my $mapmaph = 250;
611 688
612 $self->flood_fill ("", $hash, $flags, 689 $self->flood_fill ("", $hash, $flags,
674 $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}});
675 $MAPWIDGET->update; 752 $MAPWIDGET->update;
676 753
677 $tex 754 $tex
678 }; 755 };
756}
757
758sub 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#
679} 766}
680 767
681sub conn::query { 768sub conn::query {
682 my ($self, $flags, $prompt) = @_; 769 my ($self, $flags, $prompt) = @_;
683 770
717 refresh; 804 refresh;
718 }, 805 },
719 SDL_KEYDOWN() => sub { 806 SDL_KEYDOWN() => sub {
720 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) {
721 # alt-enter 808 # alt-enter
722 destroy_screen; 809 video_shutdown;
723 $CFG->{fullscreen} = !$CFG->{fullscreen}; 810 $CFG->{fullscreen} = !$CFG->{fullscreen};
724 init_screen; 811 video_init;
725 } else { 812 } else {
726 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 813 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
727 } 814 }
728 }, 815 },
729 SDL_KEYUP() => sub { 816 SDL_KEYUP() => sub {
743 }, 830 },
744); 831);
745 832
746############################################################################# 833#############################################################################
747 834
835$SIG{INT} = $SIG{TERM} = sub { exit };
836
748$TILECACHE = CFClient::db_table "tilecache"; 837$TILECACHE = CFClient::db_table "tilecache";
749$FACEMAP = CFClient::db_table "facemap"; 838$FACEMAP = CFClient::db_table "facemap";
750 839
751CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 840CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
752 841
778 867
779@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 868@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
780 869
781$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 870$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
782 871
783init_screen;
784
785{ 872{
786 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 873 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
787 874
788 CFClient::add_font $_ for @fonts; 875 CFClient::add_font $_ for @fonts;
789 CFClient::set_font $fonts[0]; 876 CFClient::set_font $fonts[0];
790} 877}
791 878
879video_init;
880audio_init;
881
792Event::loop; 882Event::loop;
793 883
884END { SDL::Quit }
794 885
886

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines