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.151 by root, Thu Apr 20 07:27:11 2006 UTC vs.
Revision 1.154 by elmex, Thu Apr 20 16:29:40 2006 UTC

45our $LOGVIEW; 45our $LOGVIEW;
46our $CONSOLE; 46our $CONSOLE;
47our $METASERVER; 47our $METASERVER;
48 48
49our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
50 51
51our $SDL_ACTIVE; 52our $SDL_ACTIVE;
52our %SDL_CB; 53our %SDL_CB;
53 54
54our $SDL_MIXER; 55our $SDL_MIXER;
187 audio_shutdown (); 188 audio_shutdown ();
188 audio_init (); 189 audio_init ();
189 }); 190 });
190 191
191 $dialog 192 $dialog
193}
194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats");
197 $tgw->add (my $vb = new CFClient::UI::VBox ());
198 $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1);
199 $vb->add (my $hb2 = new CFClient::UI::HBox);
200 $hb2->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
201 $hb2->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
202 $hb2->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
203 $hb2->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
204 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
205 $tgw
206}
207
208sub update_stats_window {
209 my ($stats) = @_;
210
211 $STATWIDS->{stat}->set_text (
212 "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28})
213 . " Level: $stats->{12}\n"
214 . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n",
215 @$stats{5,8,9,6,7,22,10, 13, 14})
216 . (sprintf "Dam %d Arm %d Speed %.2f/%.2f",
217 @$stats{15,16,17,19})
218 );
192} 219}
193 220
194sub metaserver_dialog { 221sub metaserver_dialog {
195 my $dialog = new CFClient::UI::FancyFrame 222 my $dialog = new CFClient::UI::FancyFrame
196 title => "Metaserver", 223 title => "Metaserver",
445 status "Configuration Saved"; 472 status "Configuration Saved";
446 }); 473 });
447 474
448 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 475 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
449 476
450 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats");
451 $tgw->add (my $hbox = new CFClient::UI::HBox ());
452 477
453 $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
454 $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
455 $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
456 $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
457
458 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
459 $CFClient::UI::ROOT->add ($tgw); 478 $CFClient::UI::ROOT->add (make_stats_window);
460} 479}
461 480
462sub video_shutdown { 481sub video_shutdown {
463 $CFClient::UI::ROOT->{children} = []; 482 $CFClient::UI::ROOT->{children} = [];
464 undef $SDL_ACTIVE; 483 undef $SDL_ACTIVE;
465} 484}
466 485
486my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
467my $bgmusic;#TODO#hack#d# 487my $bgmusic;#TODO#hack#d#
488
489sub audio_music_finished {
490 return unless $CFG->{bgm_enable};
491
492 # TODO: hack, do play loop and mood music
493 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
494 $bgmusic->play (0);
495
496 push @bgmusic, shift @bgmusic;
497}
468 498
469sub audio_init { 499sub audio_init {
470 if ($CFG->{audio_enable}) { 500 if ($CFG->{audio_enable}) {
471 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 501 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
472
473 $SDL_MIXER = !CFClient::Mix_OpenAudio; 502 $SDL_MIXER = !CFClient::Mix_OpenAudio;
474 CFClient::Mix_AllocateChannels 8; 503 CFClient::Mix_AllocateChannels 8;
475 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 504 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
476 505
477 # TODO: hack, do play loop and mood music 506 audio_music_finished;
478 if ($CFG->{bgm_enable}) {
479 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
480 $bgmusic->play;
481 }
482 507
483 while (<$fh>) { 508 while (<$fh>) {
484 next if /^\s*#/; 509 next if /^\s*#/;
485 next if /^\s*$/; 510 next if /^\s*$/;
486 511
580 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 605 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
581 $GAUGES->{hp} ->set_value ($hp, $hp_m); 606 $GAUGES->{hp} ->set_value ($hp, $hp_m);
582 $GAUGES->{mana} ->set_value ($sp, $sp_m); 607 $GAUGES->{mana} ->set_value ($sp, $sp_m);
583 $GAUGES->{food} ->set_value ($fo, $fo_m); 608 $GAUGES->{food} ->set_value ($fo, $fo_m);
584 $GAUGES->{grace}->set_value ($gr, $gr_m); 609 $GAUGES->{grace}->set_value ($gr, $gr_m);
610
611 update_stats_window ($stats);
585} 612}
586 613
587sub conn::user_send { 614sub conn::user_send {
588 my ($self, $command) = @_; 615 my ($self, $command) = @_;
589 616
614 641
615 my ($hash, $x, $y, $w, $h) = @$map_info; 642 my ($hash, $x, $y, $w, $h) = @$map_info;
616 643
617 my $data = $MAP->get_rect ($x, $y, $w, $h); 644 my $data = $MAP->get_rect ($x, $y, $w, $h);
618 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 645 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
619
620 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 646 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
621
622} 647}
623 648
624sub conn::map_clear { 649sub conn::map_clear {
625 my ($self) = @_; 650 my ($self) = @_;
626 651
634sub conn::load_map($$$) { 659sub conn::load_map($$$) {
635 my ($self, $hash, $x, $y) = @_; 660 my ($self, $hash, $x, $y) = @_;
636 661
637 if (defined (my $data = $MAPCACHE->get ($hash))) { 662 if (defined (my $data = $MAPCACHE->get ($hash))) {
638 $data = Compress::LZF::decompress $data; 663 $data = Compress::LZF::decompress $data;
639 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 664 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
640 for my $id ($MAP->set_rect ($x, $y, $data)) { 665 for my $id ($MAP->set_rect ($x, $y, $data)) {
641 my $data = $TILECACHE->get ($id) 666 my $data = $TILECACHE->get ($id)
642 or next; 667 or next;
643 668
644 $self->set_texture ($id => $data); 669 $self->set_texture ($id => $data);
645 } 670 }
646 } 671 }
647} 672}
648 673
674# this method does a "flood fill" into every tile direction
675# it assumes that tiles are arranged in a rectangular grid,
676# i.e. a map is the same as the left of the right map etc.
677# failure to comply are harmless and result in display errors
678# at worst.
649sub conn::flood_fill { 679sub conn::flood_fill {
650 my ($self, $gx, $gy, $path, $hash, $flags) = @_; 680 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
651 681
652 # the server does not allow map paths > 6 682 # the server does not allow map paths > 6
653 return if 6 <= length $path; 683 return if 6 <= length $path;
705 735
706 my $mapmapw = 250; 736 my $mapmapw = 250;
707 my $mapmaph = 250; 737 my $mapmaph = 250;
708 738
709 $self->{neigh_rect} = [ 739 $self->{neigh_rect} = [
710 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, 740 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
711 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5, 741 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
712 ]; 742 ];
713 743
714 delete $self->{neigh_grid}; 744 delete $self->{neigh_grid};
715 $self->flood_fill (0, 0, "", $hash, $flags); 745 $self->flood_fill (0, 0, "", $hash, $flags);
716 746
849 CFClient::SDL_QUIT => sub { 879 CFClient::SDL_QUIT => sub {
850 Event::unloop -1; 880 Event::unloop -1;
851 }, 881 },
852 CFClient::SDL_VIDEORESIZE => sub { 882 CFClient::SDL_VIDEORESIZE => sub {
853 }, 883 },
854 CFClient::SDL_VIDEOEXPOSE => sub { 884 CFClient::SDL_VIDEOEXPOSE => \&refresh,
855 refresh; 885 CFClient::SDL_ACTIVEEVENT => sub {
886# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
856 }, 887 },
857 CFClient::SDL_KEYDOWN => sub { 888 CFClient::SDL_KEYDOWN => sub {
858 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 889 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
859 # alt-enter 890 # alt-enter
860 video_shutdown; 891 video_shutdown;
862 video_init; 893 video_init;
863 } else { 894 } else {
864 CFClient::UI::feed_sdl_key_down_event ($_[0]); 895 CFClient::UI::feed_sdl_key_down_event ($_[0]);
865 } 896 }
866 }, 897 },
867 CFClient::SDL_KEYUP => sub { 898 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
868 CFClient::UI::feed_sdl_key_up_event ($_[0]); 899 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
869 }, 900 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
870 CFClient::SDL_MOUSEMOTION => sub { 901 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
871 CFClient::UI::feed_sdl_motion_event ($_[0]); 902 CFClient::SDL_USEREVENT => \&audio_music_finished,
872 },
873 CFClient::SDL_MOUSEBUTTONDOWN => sub {
874 CFClient::UI::feed_sdl_button_down_event ($_[0]);
875 },
876 CFClient::SDL_MOUSEBUTTONUP => sub {
877 CFClient::UI::feed_sdl_button_up_event ($_[0]);
878 },
879 CFClient::SDL_ACTIVEEVENT => sub {
880# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
881 },
882); 903);
883 904
884############################################################################# 905#############################################################################
885 906
886$SIG{INT} = $SIG{TERM} = sub { exit }; 907$SIG{INT} = $SIG{TERM} = sub { exit };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines