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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines