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.133 by root, Tue Apr 18 02:38:51 2006 UTC vs.
Revision 1.140 by root, Wed Apr 19 06:06:46 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
54our $GAUGES; 59our $GAUGES;
55 60
56our $SDL_ACTIVE; 61our $SDL_ACTIVE;
57our $SDL_EV; 62our $SDL_EV;
58our %SDL_CB; 63our %SDL_CB;
64
65our $SDL_MIXER;
66our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files
59 68
60our $ALT_ENTER_MESSAGE; 69our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 70our $STATUS_LINE;
62our $DEBUG_STATUS; 71our $DEBUG_STATUS;
63 72
101} 110}
102 111
103sub client_setup { 112sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 113 my $dialog = new CFClient::UI::FancyFrame
105 child => (my $vbox = new CFClient::UI::VBox); 114 child => (my $vbox = new CFClient::UI::VBox);
106 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 115 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
107 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 116 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
108 117
109 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 118 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 120
112 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 121 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
113 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 122 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
114 123
115 $mode_slider->connect (changed => sub { 124 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 125 my ($self, $value) = @_;
117 126
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 129 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 130 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 131
123 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 132 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
124 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
125 my ($self, $value) = @_; 134 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 135 $CFG->{fullscreen} = $value;
127 }); 136 });
128 137
129 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 138 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
130 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
131 my ($self, $value) = @_; 140 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 141 $CFG->{fast} = $value;
133 }); 142 });
134 143
135 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 144 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
136 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
137 my ($self, $value) = @_; 146 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 147 $CFG->{fow_enable} = $value;
139 }); 148 });
140 149
141 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 150 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
142 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
143 my ($self, $value) = @_; 152 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 153 $CFG->{fow_intensity} = $value;
145 }); 154 });
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 valign => 0, 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;
151 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
152 }); 161 });
153 162
154 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 163 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.5, 1.5, 0.1], connect_changed => sub {
165 $CFG->{gui_fontsize} = 0.1 * int $_[0] * 10;
166# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
167 });
168
169 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize");
155 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 170 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.5, 0.1], connect_changed => sub {
156 my ($self, $value) = @_;
157 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 171 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[0] * 10);
158 }); 172 });
159 173
160 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 174 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
161 destroy_screen (); 175 video_shutdown ();
162 init_screen (); 176 video_init ();
177 });
178
179 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
181 $CFG->{audio_enable} = $_[1];
182 });
183# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
184# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
185# $CFG->{effects_volume} = $_[1];
186# });
187 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Bg. Music");
188 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
189 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
190 $CFG->{bgm_enable} = $_[1];
191 });
192 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub {
193 $CFG->{bgm_volume} = $_[1];
194 $SDL_MIXER->music_volume ($_[1]);
195 });
196
197 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
198 audio_shutdown ();
199 audio_init ();
163 }); 200 });
164 201
165 $dialog 202 $dialog
166} 203}
167 204
231 $HOST->set_text ($CFG->{host} = $host); 268 $HOST->set_text ($CFG->{host} = $host);
232 }), 269 }),
233 (new CFClient::UI::Empty expand => 1), 270 (new CFClient::UI::Empty expand => 1),
234 ]); 271 ]);
235 272
236 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 273 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
237 for 0 .. $#$m; 274 for 0 .. $#$m;
238 } 275 }
239 } 276 }
240 }); 277 });
241} 278}
355 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 392 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
356 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 393 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
357 and die "SDL::Init failed!\n"; 394 and die "SDL::Init failed!\n";
358} 395}
359 396
360sub init_screen { 397sub video_init {
361 sdl_init; 398 sdl_init;
362 399
363 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 400 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
364 $FULLSCREEN = $CFG->{fullscreen}; 401 $FULLSCREEN = $CFG->{fullscreen};
365 $FAST = $CFG->{fast}; 402 $FAST = $CFG->{fast};
392 429
393 $LAST_REFRESH = time - 0.01; 430 $LAST_REFRESH = time - 0.01;
394 431
395 CFClient::gl_init; 432 CFClient::gl_init;
396 433
397 $FONTSIZE = int $HEIGHT / 40; 434 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
398 435
399 ############################################################################# 436 #############################################################################
400 437
401 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 438 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
402 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 439 $DEBUG_STATUS->show;
403 440
404 $STATUS_LINE = new CFClient::UI::Label 441 $STATUS_LINE = new CFClient::UI::Label
405 padding => 0, 442 padding => 0,
406 y => $HEIGHT * 44 / 45 - $FONTSIZE; 443 y => $HEIGHT - $FONTSIZE * 1.8;
407 $CFClient::UI::ROOT->add ($STATUS_LINE); 444 $STATUS_LINE->show;
408 445
409 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 446 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
410 padding => 0, 447 padding => 0,
411 y => $HEIGHT * 44 / 45,
412 fontsize => $HEIGHT / 45, 448 fontsize => 0.8,
413 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 449 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
414 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 450 $ALT_ENTER_MESSAGE->show;
451 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
415 452
416 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 453 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
417 $MAPWIDGET->focus_in; 454 $MAPWIDGET->focus_in;
418 $MAPWIDGET->connect (activate_console => sub { 455 $MAPWIDGET->connect (activate_console => sub {
419 my ($mapwidget, $preset) = @_; 456 my ($mapwidget, $preset) = @_;
451 488
452 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 489 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
453 $CFClient::UI::ROOT->add ($tgw); 490 $CFClient::UI::ROOT->add ($tgw);
454} 491}
455 492
456sub destroy_screen { 493sub video_shutdown {
457 $CFClient::UI::ROOT->{children} = []; 494 $CFClient::UI::ROOT->{children} = [];
458 undef $SDL_ACTIVE; 495 undef $SDL_ACTIVE;
459 undef $SDL_EV; 496 undef $SDL_EV;
460 SDL::Quit; 497}
498
499my $bgmusic;#TODO#hack#d#
500
501sub audio_init {
502 if ($CFG->{audio_enable}) {
503 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
504 $SDL_MIXER = new SDL::Mixer;
505 $SDL_MIXER->allocate_channels (8);
506
507 # TODO: hack, do play loop and mood music
508 if ($CFG->{bgm_enable}) {
509 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
510 $SDL_MIXER->play_music ($bgmusic, -1);
511 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
512 }
513
514 while (<$fh>) {
515 next if /^\s*#/;
516 next if /^\s*$/;
517
518 my ($file, $volume, $event) = split /\s+/, $_, 3;
519
520 push @SOUNDS, "$volume,$file";
521
522 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
523 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
524 $chunk->volume ($volume * 128 / 100);
525 $chunk
526 };
527 }
528 } else {
529 status "unable to open sound config: $!";
530 }
531 }
532}
533
534sub audio_shutdown {
535 undef $SDL_MIXER;
536 @SOUNDS = ();
537 %AUDIO_CHUNKS = ();
461} 538}
462 539
463my %animate_object; 540my %animate_object;
464my $animate_timer; 541my $animate_timer;
465 542
706 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 783 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
707 $MAPWIDGET->update; 784 $MAPWIDGET->update;
708 785
709 $tex 786 $tex
710 }; 787 };
788}
789
790sub conn::sound_play {
791 my ($self, $x, $y, $soundnum, $type) = @_;
792
793 $SDL_MIXER
794 or return;
795
796 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
797 or return;
798
799 $SDL_MIXER->play_channel (-1, $chunk);
800 warn "sound $x,$y,$soundnum,$type\n";#d#
711} 801}
712 802
713sub conn::query { 803sub conn::query {
714 my ($self, $flags, $prompt) = @_; 804 my ($self, $flags, $prompt) = @_;
715 805
749 refresh; 839 refresh;
750 }, 840 },
751 SDL_KEYDOWN() => sub { 841 SDL_KEYDOWN() => sub {
752 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 842 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
753 # alt-enter 843 # alt-enter
754 destroy_screen; 844 video_shutdown;
755 $CFG->{fullscreen} = !$CFG->{fullscreen}; 845 $CFG->{fullscreen} = !$CFG->{fullscreen};
756 init_screen; 846 video_init;
757 } else { 847 } else {
758 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 848 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
759 } 849 }
760 }, 850 },
761 SDL_KEYUP() => sub { 851 SDL_KEYUP() => sub {
791 fullscreen => 0, 881 fullscreen => 0,
792 fast => 0, 882 fast => 0,
793 fow_enable => 1, 883 fow_enable => 1,
794 fow_intensity => 0.45, 884 fow_intensity => 0.45,
795 fow_smooth => 0, 885 fow_smooth => 0,
886 gui_fontsize => 1,
796 log_fontsize => 14, 887 log_fontsize => 14,
797 mapsize => 100, 888 mapsize => 100,
798 host => "crossfire.schmorp.de", 889 host => "crossfire.schmorp.de",
799 say_command => 'say', 890 say_command => 'say',
891 audio_enable => 1,
892 bgm_enable => 1,
893 bgm_volume => 64,
800); 894);
801 895
802while (my ($k, $v) = each %DEF_CFG) { 896while (my ($k, $v) = each %DEF_CFG) {
803 $CFG->{$k} = $v unless exists $CFG->{$k}; 897 $CFG->{$k} = $v unless exists $CFG->{$k};
804} 898}
819 913
820 CFClient::add_font $_ for @fonts; 914 CFClient::add_font $_ for @fonts;
821 CFClient::set_font $fonts[0]; 915 CFClient::set_font $fonts[0];
822} 916}
823 917
824init_screen; 918video_init;
919audio_init;
825 920
826Event::loop; 921Event::loop;
827 922
828END { SDL::Quit } 923END { SDL::Quit }
829 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines