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.138 by elmex, Tue Apr 18 21:37:48 2006 UTC vs.
Revision 1.141 by root, Wed Apr 19 06:21:07 2006 UTC

22 22
23use Compress::LZF; 23use Compress::LZF;
24 24
25use CFClient; 25use CFClient;
26use CFClient::UI; 26use CFClient::UI;
27use CFClient::MapWidget;
27 28
28our $VERSION = '0.1'; 29our $VERSION = '0.1';
29 30
30my $MAX_FPS = 60; 31my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 32my $MIN_FPS = 5; # unused as of yet
110} 111}
111 112
112sub client_setup { 113sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 114 my $dialog = new CFClient::UI::FancyFrame
114 child => (my $vbox = new CFClient::UI::VBox); 115 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 116 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
116 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 117 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
117 118
118 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 119 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 120 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
120 121
121 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 122 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
122 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 123 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
123 124
124 $mode_slider->connect (changed => sub { 125 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 126 my ($self, $value) = @_;
126 127
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 128 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 129 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
129 }); 130 });
130 $mode_slider->emit (changed => $mode_slider->{range}[0]); 131 $mode_slider->emit (changed => $mode_slider->{range}[0]);
131 132
132 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 133 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 134 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
134 my ($self, $value) = @_; 135 my ($self, $value) = @_;
135 $CFG->{fullscreen} = $value; 136 $CFG->{fullscreen} = $value;
136 }); 137 });
137 138
138 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 139 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 140 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
140 my ($self, $value) = @_; 141 my ($self, $value) = @_;
141 $CFG->{fast} = $value; 142 $CFG->{fast} = $value;
142 }); 143 });
143 144
144 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 145 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 146 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
146 my ($self, $value) = @_; 147 my ($self, $value) = @_;
147 $CFG->{fow_enable} = $value; 148 $CFG->{fow_enable} = $value;
148 }); 149 });
149 150
150 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 151 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 152 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
152 my ($self, $value) = @_; 153 my ($self, $value) = @_;
153 $CFG->{fow_intensity} = $value; 154 $CFG->{fow_intensity} = $value;
154 }); 155 });
155 156
156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 157 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
157 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 158 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
158 my ($self, $value) = @_; 159 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 160 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 161 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
161 }); 162 });
162 163
163 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 164 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
165 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
166 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
167# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
168 });
169
170 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 171 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
165 my ($self, $value) = @_;
166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 172 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
167 }); 173 });
168 174
169 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 175 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
170 video_shutdown (); 176 video_shutdown ();
171 video_init (); 177 video_init ();
172 }); 178 });
173 179
174 $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); 180 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
175 $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{sound} = $value;
178 });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { 181 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bg_music_enable} = $value; 182 $CFG->{audio_enable} = $_[1];
183 });
184# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
185# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
186# $CFG->{effects_volume} = $_[1];
183 }); 187# });
188 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
189 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
190 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
191 $CFG->{bgm_enable} = $_[1];
192 });
193 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub {
194 $CFG->{bgm_volume} = $_[1];
195 $SDL_MIXER->music_volume ($_[1]);
196 });
197
184 $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 198 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
185 audio_shutdown (); 199 audio_shutdown ();
186 audio_init (); 200 audio_init ();
187 }); 201 });
188 202
189 $dialog 203 $dialog
255 $HOST->set_text ($CFG->{host} = $host); 269 $HOST->set_text ($CFG->{host} = $host);
256 }), 270 }),
257 (new CFClient::UI::Empty expand => 1), 271 (new CFClient::UI::Empty expand => 1),
258 ]); 272 ]);
259 273
260 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 274 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
261 for 0 .. $#$m; 275 for 0 .. $#$m;
262 } 276 }
263 } 277 }
264 }); 278 });
265} 279}
266 280
267sub server_setup { 281sub server_setup {
268 my $dialog = new CFClient::UI::FancyFrame 282 my $dialog = new CFClient::UI::FancyFrame
269 child => (my $vbox = new CFClient::UI::VBox); 283 child => (my $vbox = new CFClient::UI::VBox);
270 284
271 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 285 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
272 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 286 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
273 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 287 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
274 288
275 { 289 {
276 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 290 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
277 291
278 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 292 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
279 my ($self, $value) = @_; 293 my ($self, $value) = @_;
280 $CFG->{host} = $value; 294 $CFG->{host} = $value;
281 }); 295 });
282 296
283 $METASERVER = metaserver_dialog; 297 $METASERVER = metaserver_dialog;
284 298
285 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 299 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
286 update_metaserver $HOST; 300 update_metaserver $HOST;
287 }); 301 });
288 } 302 }
289 303
290 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 304 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
291 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 305 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
292 my ($self, $value) = @_; 306 my ($self, $value) = @_;
293 $CFG->{user} = $value; 307 $CFG->{user} = $value;
294 }); 308 });
295 309
296 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 310 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
297 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 311 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
298 my ($self, $value) = @_; 312 my ($self, $value) = @_;
299 $CFG->{password} = $value; 313 $CFG->{password} = $value;
300 }); 314 });
301 315
302 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 316 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
303 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 317 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
304 my ($self, $value) = @_; 318 my ($self, $value) = @_;
305 $CFG->{say_command} = $value; 319 $CFG->{say_command} = $value;
306 }); 320 });
307 321
308 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 322 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
309 $table->add (1, 7, new CFClient::UI::Slider 323 $table->add (1, 7, new CFClient::UI::Slider
310 req_w => 100, 324 req_w => 100,
311 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 325 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
312 connect_changed => sub { 326 connect_changed => sub {
313 my ($self, $value) = @_; 327 my ($self, $value) = @_;
416 430
417 $LAST_REFRESH = time - 0.01; 431 $LAST_REFRESH = time - 0.01;
418 432
419 CFClient::gl_init; 433 CFClient::gl_init;
420 434
421 $FONTSIZE = int $HEIGHT / 40; 435 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
422 436
423 ############################################################################# 437 #############################################################################
424 438
425 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 439 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
426 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 440 $DEBUG_STATUS->show;
427 441
428 $STATUS_LINE = new CFClient::UI::Label 442 $STATUS_LINE = new CFClient::UI::Label
429 padding => 0, 443 padding => 0,
430 y => $HEIGHT * 44 / 45 - $FONTSIZE; 444 y => $HEIGHT - $FONTSIZE * 1.8;
431 $CFClient::UI::ROOT->add ($STATUS_LINE); 445 $STATUS_LINE->show;
432 446
433 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 447 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
434 padding => 0, 448 padding => 0,
435 y => $HEIGHT * 44 / 45,
436 fontsize => $HEIGHT / 45, 449 fontsize => 0.8,
437 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 450 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
438 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 451 $ALT_ENTER_MESSAGE->show;
452 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
439 453
440 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 454 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
441 $MAPWIDGET->focus_in; 455 $MAPWIDGET->focus_in;
442 $MAPWIDGET->connect (activate_console => sub { 456 $MAPWIDGET->connect (activate_console => sub {
443 my ($mapwidget, $preset) = @_; 457 my ($mapwidget, $preset) = @_;
444 458
445 if ($CONSOLE) { 459 if ($CONSOLE) {
484} 498}
485 499
486my $bgmusic;#TODO#hack#d# 500my $bgmusic;#TODO#hack#d#
487 501
488sub audio_init { 502sub audio_init {
489 if ($CFG->{sound} || 1) { 503 if ($CFG->{audio_enable}) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 504 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer; 505 $SDL_MIXER = new SDL::Mixer;
492 $SDL_MIXER->allocate_channels (8); 506 $SDL_MIXER->allocate_channels (8);
493 507
508 # TODO: hack, do play loop and mood music
494 if ($CFG->{bg_music_enable}) { 509 if ($CFG->{bgm_enable}) {
495 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 510 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
496 $SDL_MIXER->play_music ($bgmusic, -1); 511 $SDL_MIXER->play_music ($bgmusic, -1);
512 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
497 } 513 }
498 514
499 while (<$fh>) { 515 while (<$fh>) {
500 next if /^\s*#/; 516 next if /^\s*#/;
501 next if /^\s*$/; 517 next if /^\s*$/;
772 }; 788 };
773} 789}
774 790
775sub conn::sound_play { 791sub conn::sound_play {
776 my ($self, $x, $y, $soundnum, $type) = @_; 792 my ($self, $x, $y, $soundnum, $type) = @_;
793
794 $SDL_MIXER
795 or return;
777 796
778 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 797 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
779 or return; 798 or return;
780 799
781 $SDL_MIXER->play_channel (-1, $chunk); 800 $SDL_MIXER->play_channel (-1, $chunk);
863 fullscreen => 0, 882 fullscreen => 0,
864 fast => 0, 883 fast => 0,
865 fow_enable => 1, 884 fow_enable => 1,
866 fow_intensity => 0.45, 885 fow_intensity => 0.45,
867 fow_smooth => 0, 886 fow_smooth => 0,
887 gui_fontsize => 1,
868 log_fontsize => 14, 888 log_fontsize => 14,
869 mapsize => 100, 889 mapsize => 100,
870 host => "crossfire.schmorp.de", 890 host => "crossfire.schmorp.de",
871 say_command => 'say', 891 say_command => 'say',
872 sound => 1, 892 audio_enable => 1,
873 bg_music_enable => 1, 893 bgm_enable => 1,
894 bgm_volume => 64,
874); 895);
875 896
876while (my ($k, $v) = each %DEF_CFG) { 897while (my ($k, $v) = each %DEF_CFG) {
877 $CFG->{$k} = $v unless exists $CFG->{$k}; 898 $CFG->{$k} = $v unless exists $CFG->{$k};
878} 899}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines