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.144 by root, Wed Apr 19 09:40:01 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
18use Compress::LZF; 23use Compress::LZF;
19 24
20use CFClient; 25use CFClient;
21use CFClient::UI; 26use CFClient::UI;
27use CFClient::MapWidget;
22 28
23our $VERSION = '0.1'; 29our $VERSION = '0.1';
24 30
25my $MAX_FPS = 60; 31my $MAX_FPS = 60;
26my $MIN_FPS = 5; # unused as of yet 32my $MIN_FPS = 5; # unused as of yet
49our $BUTTONBAR; 55our $BUTTONBAR;
50our $LOGVIEW; 56our $LOGVIEW;
51our $CONSOLE; 57our $CONSOLE;
52our $METASERVER; 58our $METASERVER;
53 59
60our $GAUGES;
61
54our $SDL_ACTIVE; 62our $SDL_ACTIVE;
55our $SDL_EV; 63our $SDL_EV;
56our %SDL_CB; 64our %SDL_CB;
57 65
66our $SDL_MIXER;
67our @SOUNDS; # event => file mapping
68our %AUDIO_CHUNKS; # audio files
69
58our $ALT_ENTER_MESSAGE; 70our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 71our $STATUS_LINE;
60our $DEBUG_STATUS; 72our $DEBUG_STATUS;
61 73
62sub status { 74sub status {
63 $STATUS_LINE->set_text ($_[0]); 75 $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); 76 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
66} 77}
67 78
68sub debug { 79sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 80 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 81 $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} 82}
73 83
74sub start_game { 84sub start_game {
75 status "logging in..."; 85 status "logging in...";
76 86
101} 111}
102 112
103sub client_setup { 113sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 114 my $dialog = new CFClient::UI::FancyFrame
105 child => (my $vbox = new CFClient::UI::VBox); 115 child => (my $vbox = new CFClient::UI::VBox);
106 $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");
107 $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]);
108 118
109 $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");
110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 120 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 121
112 $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]);
113 $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);
114 124
115 $mode_slider->connect (changed => sub { 125 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 126 my ($self, $value) = @_;
117 127
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 128 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 129 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 130 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 131 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 132
123 $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");
124 $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 {
125 my ($self, $value) = @_; 135 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 136 $CFG->{fullscreen} = $value;
127 }); 137 });
128 138
129 $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");
130 $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 {
131 my ($self, $value) = @_; 141 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 142 $CFG->{fast} = $value;
133 }); 143 });
134 144
135 $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");
136 $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 {
137 my ($self, $value) = @_; 147 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 148 $CFG->{fow_enable} = $value;
139 }); 149 });
140 150
141 $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");
142 $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 {
143 my ($self, $value) = @_; 153 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 154 $CFG->{fow_intensity} = $value;
145 }); 155 });
146 156
147 $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");
148 $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 {
149 my ($self, $value) = @_; 159 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 160 $CFG->{fow_smooth} = $value;
161 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 162 });
152 163
153 $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");
154 $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 {
155 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 172 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
157 }); 173 });
158 174
159 $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 {
160 destroy_screen (); 176 video_shutdown ();
161 init_screen (); 177 video_init ();
178 });
179
180 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
181 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
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];
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
198 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
199 audio_shutdown ();
200 audio_init ();
162 }); 201 });
163 202
164 $dialog 203 $dialog
165} 204}
166 205
230 $HOST->set_text ($CFG->{host} = $host); 269 $HOST->set_text ($CFG->{host} = $host);
231 }), 270 }),
232 (new CFClient::UI::Empty expand => 1), 271 (new CFClient::UI::Empty expand => 1),
233 ]); 272 ]);
234 273
235 $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)
236 for 0 .. $#$m; 275 for 0 .. $#$m;
237 } 276 }
238 } 277 }
239 }); 278 });
240} 279}
241 280
242sub server_setup { 281sub server_setup {
243 my $dialog = new CFClient::UI::FancyFrame 282 my $dialog = new CFClient::UI::FancyFrame
244 child => (my $vbox = new CFClient::UI::VBox); 283 child => (my $vbox = new CFClient::UI::VBox);
245 284
246 $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");
247 $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]);
248 $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");
249 288
250 { 289 {
251 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 290 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
252 291
253 $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 {
254 my ($self, $value) = @_; 293 my ($self, $value) = @_;
255 $CFG->{host} = $value; 294 $CFG->{host} = $value;
256 }); 295 });
257 296
258 $METASERVER = metaserver_dialog; 297 $METASERVER = metaserver_dialog;
259 298
260 $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 {
261 update_metaserver $HOST; 300 update_metaserver $HOST;
262 }); 301 });
263 } 302 }
264 303
265 $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");
266 $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 {
267 my ($self, $value) = @_; 306 my ($self, $value) = @_;
268 $CFG->{user} = $value; 307 $CFG->{user} = $value;
269 }); 308 });
270 309
271 $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");
272 $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 {
273 my ($self, $value) = @_; 312 my ($self, $value) = @_;
274 $CFG->{password} = $value; 313 $CFG->{password} = $value;
275 }); 314 });
276 315
277 $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");
278 $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 {
279 my ($self, $value) = @_; 318 my ($self, $value) = @_;
280 $CFG->{say_command} = $value; 319 $CFG->{say_command} = $value;
281 }); 320 });
282 321
283 $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");
284 $table->add (1, 7, new CFClient::UI::Slider 323 $table->add (1, 7, new CFClient::UI::Slider
285 req_w => 100, 324 req_w => 100,
286 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 325 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
287 connect_changed => sub { 326 connect_changed => sub {
288 my ($self, $value) = @_; 327 my ($self, $value) = @_;
300 339
301sub message_window { 340sub message_window {
302 my $window = new CFClient::UI::FancyFrame 341 my $window = new CFClient::UI::FancyFrame
303 border_bg => [1, 1, 1, 0.5], 342 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 343 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => $::WIDTH/4, 344 user_w => int $::WIDTH / 3,
306 user_h => $::HEIGHT, 345 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 346 child => (my $vbox = new CFClient::UI::VBox);
308 347
309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 348 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
310 expand => 1, 349 expand => 1,
311 fontsize => $::CFG->{log_fontsize}, 350 fontsize => $::CFG->{log_fontsize},
312 ); 351 );
313 352
314 $vbox->add (my $input = new CFClient::UI::LineEntry 353 $vbox->add (my $input = new CFClient::UI::Entry
315 connect_focus_in => sub { 354 connect_focus_in => sub {
316 my ($input, $prev_focus) = @_; 355 my ($input, $prev_focus) = @_;
317 356
318 delete $input->{refocus_map}; 357 delete $input->{refocus_map};
319 358
325 connect_activate => sub { 364 connect_activate => sub {
326 my ($input, $text) = @_; 365 my ($input, $text) = @_;
327 $input->set_text (''); 366 $input->set_text ('');
328 367
329 if ($text =~ /^\/(.*)/) { 368 if ($text =~ /^\/(.*)/) {
330 $::CONN->user_send ("command $1"); 369 $::CONN->user_send ($1);
331 } else { 370 } else {
332 my $say_cmd = $::CFG->{say_command} || 'say'; 371 my $say_cmd = $::CFG->{say_command} || 'say';
333 $::CONN->user_send ("command $say_cmd $text"); 372 $::CONN->user_send ("$say_cmd $text");
334 } 373 }
335 if ($input->{refocus_map}) { 374 if ($input->{refocus_map}) {
336 delete $input->{refocus_map}; 375 delete $input->{refocus_map};
337 $MAPWIDGET->focus_in 376 $MAPWIDGET->focus_in
338 } 377 }
354 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 393 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
355 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 394 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 395 and die "SDL::Init failed!\n";
357} 396}
358 397
359sub init_screen { 398sub video_init {
360 sdl_init; 399 sdl_init;
361 400
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 401 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 402 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 403 $FAST = $CFG->{fast};
391 430
392 $LAST_REFRESH = time - 0.01; 431 $LAST_REFRESH = time - 0.01;
393 432
394 CFClient::gl_init; 433 CFClient::gl_init;
395 434
396 $FONTSIZE = int $HEIGHT / 40; 435 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
397 436
398 ############################################################################# 437 #############################################################################
399 438
400 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 439 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
401 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 440 $DEBUG_STATUS->show;
402 441
403 $STATUS_LINE = new CFClient::UI::Label 442 $STATUS_LINE = new CFClient::UI::Label
404 padding => 0, 443 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 444 y => $HEIGHT - $FONTSIZE * 1.8;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 445 $STATUS_LINE->show;
407 446
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 447 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 448 padding => 0,
410 y => $HEIGHT * 44 / 45, 449 fontsize => 0.8,
411 height => $HEIGHT / 45,
412 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 450 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 451 $ALT_ENTER_MESSAGE->show;
452 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
414 453
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 454 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
416 $MAPWIDGET->focus_in; 455 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 456 $MAPWIDGET->connect (activate_console => sub {
418 my ($mapwidget, $preset) = @_; 457 my ($mapwidget, $preset) = @_;
419 458
420 if ($CONSOLE) { 459 if ($CONSOLE) {
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 476 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 477 status "Configuration Saved";
439 }); 478 });
440 479
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 480 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 481
444sub destroy_screen { 482 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
483 $tgw->add (my $hbox = new CFClient::UI::HBox ());
484
485 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
486 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
487 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
488 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
489
490 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
491 $CFClient::UI::ROOT->add ($tgw);
492}
493
494sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 495 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 496 undef $SDL_ACTIVE;
447 undef $SDL_EV; 497 undef $SDL_EV;
448 SDL::Quit; 498}
499
500my $bgmusic;#TODO#hack#d#
501
502sub audio_init {
503 if ($CFG->{audio_enable}) {
504 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
505
506 $SDL_MIXER = new SDL::Mixer
507 -rate => 22050,
508 -channels => 1, # mono
509 -size => 512;
510
511 $SDL_MIXER->allocate_channels (8);
512
513 # TODO: hack, do play loop and mood music
514 if ($CFG->{bgm_enable}) {
515 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
516 $SDL_MIXER->play_music ($bgmusic, -1);
517 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
518 }
519
520 while (<$fh>) {
521 next if /^\s*#/;
522 next if /^\s*$/;
523
524 my ($file, $volume, $event) = split /\s+/, $_, 3;
525
526 push @SOUNDS, "$volume,$file";
527
528 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
529 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
530 $chunk->volume ($volume * 128 / 100);
531 $chunk
532 };
533 }
534 } else {
535 status "unable to open sound config: $!";
536 }
537 }
538}
539
540sub audio_shutdown {
541 undef $SDL_MIXER;
542 @SOUNDS = ();
543 %AUDIO_CHUNKS = ();
449} 544}
450 545
451my %animate_object; 546my %animate_object;
452my $animate_timer; 547my $animate_timer;
453 548
502 delete $animate_object{$widget}; 597 delete $animate_object{$widget};
503} 598}
504 599
505@conn::ISA = Crossfire::Protocol::; 600@conn::ISA = Crossfire::Protocol::;
506 601
602sub conn::stats_update {
603 my ($self, $stats) = @_;
604
605 # i love text protocols!!!
606 # FIXME: the stats are somehow weird
607 my $hp = $stats->{1};
608 my $hp_m = $stats->{2};
609 my $sp = $stats->{3};
610 my $sp_m = $stats->{4};
611 my $fo = $stats->{18};
612 my $fo_m = 1000;
613 my $gr = $stats->{23};
614 my $gr_m = $stats->{24};
615
616 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
617 $GAUGES->{hp}->set_value ($hp, $hp_m);
618 $GAUGES->{mana}->set_value ($sp, $sp_m);
619 $GAUGES->{food}->set_value ($fo, $fo_m);
620 $GAUGES->{grace}->set_value ($gr, $gr_m);
621}
622
507sub conn::user_send { 623sub conn::user_send {
508 my ($self, $command) = @_; 624 my ($self, $command) = @_;
509 625
510 $self->send ($command); 626 $self->send_command ($command);
511 status $command; 627 status $command;
512} 628}
513 629
514sub conn::map_scroll { 630sub conn::map_scroll {
515 my ($self, $dx, $dy) = @_; 631 my ($self, $dx, $dy) = @_;
579 my $neigh = $self->{neigh}{$hash} ||= []; 695 my $neigh = $self->{neigh}{$hash} ||= [];
580 696
581 $self->send_mapinfo ("spatial $path$tile", sub { 697 $self->send_mapinfo ("spatial $path$tile", sub {
582 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 698 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
583 699
584 warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# 700 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
585 return if $mode ne "spatial"; 701 return if $mode ne "spatial";
586 702
587 $x += $MAP->ox; 703 $x += $MAP->ox;
588 $y += $MAP->oy; 704 $y += $MAP->oy;
589 705
590 $self->load_map ($hash, $x, $y); 706 $self->load_map ($hash, $x, $y)
707 unless $self->{neigh}{$hash}[5]++;#d#
591 708
592 $neigh->[$tile] = [$x, $y, $w, $h]; 709 $neigh->[$tile] = [$x, $y, $w, $h];
593 710
594 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 711 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1)
595 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 712 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
601 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 718 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
602 719
603 $self->flush_map; 720 $self->flush_map;
604 721
605 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 722 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
606
607 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
608 723
609 my $mapmapw = 250; 724 my $mapmapw = 250;
610 my $mapmaph = 250; 725 my $mapmaph = 250;
611 726
612 $self->flood_fill ("", $hash, $flags, 727 $self->flood_fill ("", $hash, $flags,
676 791
677 $tex 792 $tex
678 }; 793 };
679} 794}
680 795
796sub conn::sound_play {
797 my ($self, $x, $y, $soundnum, $type) = @_;
798
799 $SDL_MIXER
800 or return;
801
802 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
803 or return;
804
805 $SDL_MIXER->play_channel (-1, $chunk);
806# warn "sound $x,$y,$soundnum,$type\n";#d#
807}
808
681sub conn::query { 809sub conn::query {
682 my ($self, $flags, $prompt) = @_; 810 my ($self, $flags, $prompt) = @_;
683 811
684 #TODO 812 #TODO, display dialog with relevant information
685 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 813 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
686} 814}
687 815
688sub conn::drawinfo { 816sub conn::drawinfo {
689 my ($self, $color, $text) = @_; 817 my ($self, $color, $text) = @_;
705 ); 833 );
706 834
707 $LOGVIEW->add_paragraph ($color[$color], $text); 835 $LOGVIEW->add_paragraph ($color[$color], $text);
708} 836}
709 837
838sub conn::spell_add {
839 my ($self, $spell) = @_;
840
841 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
842 });
843 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
844 });
845}
846
847sub conn::spell_delete {
848 my ($self, $spell) = @_;
849}
850
851sub conn::addme_success {
852 my ($self) = @_;
853
854 for my $skill (values %{$self->{skill_info}}) {
855 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
856 });
857 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
858 });
859 }
860}
861
710%SDL_CB = ( 862%SDL_CB = (
711 SDL_QUIT() => sub { 863 SDL_QUIT() => sub {
712 Event::unloop -1; 864 Event::unloop -1;
713 }, 865 },
714 SDL_VIDEORESIZE() => sub { 866 SDL_VIDEORESIZE() => sub {
717 refresh; 869 refresh;
718 }, 870 },
719 SDL_KEYDOWN() => sub { 871 SDL_KEYDOWN() => sub {
720 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 872 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
721 # alt-enter 873 # alt-enter
722 destroy_screen; 874 video_shutdown;
723 $CFG->{fullscreen} = !$CFG->{fullscreen}; 875 $CFG->{fullscreen} = !$CFG->{fullscreen};
724 init_screen; 876 video_init;
725 } else { 877 } else {
726 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 878 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
727 } 879 }
728 }, 880 },
729 SDL_KEYUP() => sub { 881 SDL_KEYUP() => sub {
743 }, 895 },
744); 896);
745 897
746############################################################################# 898#############################################################################
747 899
900$SIG{INT} = $SIG{TERM} = sub { exit };
901
748$TILECACHE = CFClient::db_table "tilecache"; 902$TILECACHE = CFClient::db_table "tilecache";
749$FACEMAP = CFClient::db_table "facemap"; 903$FACEMAP = CFClient::db_table "facemap";
750 904
751CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 905CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
752 906
757 fullscreen => 0, 911 fullscreen => 0,
758 fast => 0, 912 fast => 0,
759 fow_enable => 1, 913 fow_enable => 1,
760 fow_intensity => 0.45, 914 fow_intensity => 0.45,
761 fow_smooth => 0, 915 fow_smooth => 0,
916 gui_fontsize => 1,
762 log_fontsize => 14, 917 log_fontsize => 14,
763 mapsize => 100, 918 mapsize => 100,
764 host => "crossfire.schmorp.de", 919 host => "crossfire.schmorp.de",
765 say_command => 'say', 920 say_command => 'say',
921 audio_enable => 1,
922 bgm_enable => 1,
923 bgm_volume => 64,
766); 924);
767 925
768while (my ($k, $v) = each %DEF_CFG) { 926while (my ($k, $v) = each %DEF_CFG) {
769 $CFG->{$k} = $v unless exists $CFG->{$k}; 927 $CFG->{$k} = $v unless exists $CFG->{$k};
770} 928}
778 936
779@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 937@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
780 938
781$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 939$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
782 940
783init_screen;
784
785{ 941{
786 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 942 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
787 943
788 CFClient::add_font $_ for @fonts; 944 CFClient::add_font $_ for @fonts;
789 CFClient::set_font $fonts[0]; 945 CFClient::set_font $fonts[0];
790} 946}
791 947
948video_init;
949audio_init;
950
792Event::loop; 951Event::loop;
793 952
953END { SDL::Quit }
794 954
955

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines