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.118 by elmex, Sun Apr 16 17:43:17 2006 UTC vs.
Revision 1.146 by root, Wed Apr 19 21:17:16 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event; 9use SDL::Event;
12use SDL::Surface; 10
13use SDL::OpenGL; 11use SDL::OpenGL;
14 12
15use Crossfire; 13use Crossfire;
16use Crossfire::Protocol; 14use Crossfire::Protocol;
17 15
18use Compress::LZF; 16use Compress::LZF;
19 17
20use CFClient; 18use CFClient;
21use CFClient::UI; 19use CFClient::UI;
20use CFClient::MapWidget;
22 21
23our $VERSION = '0.1'; 22our $VERSION = '0.1';
24 23
25my $MAX_FPS = 60; 24my $MAX_FPS = 60;
26my $MIN_FPS = 5; # unused as of yet 25my $MIN_FPS = 5; # unused as of yet
49our $BUTTONBAR; 48our $BUTTONBAR;
50our $LOGVIEW; 49our $LOGVIEW;
51our $CONSOLE; 50our $CONSOLE;
52our $METASERVER; 51our $METASERVER;
53 52
53our $GAUGES;
54
54our $SDL_ACTIVE; 55our $SDL_ACTIVE;
55our $SDL_EV; 56our $SDL_EV;
56our %SDL_CB; 57our %SDL_CB;
57 58
59our $SDL_MIXER;
60our @SOUNDS; # event => file mapping
61our %AUDIO_CHUNKS; # audio files
62
58our $ALT_ENTER_MESSAGE; 63our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 64our $STATUS_LINE;
60our $DEBUG_STATUS; 65our $DEBUG_STATUS;
61 66
62sub status { 67sub status {
63 $STATUS_LINE->set_text ($_[0]); 68 $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); 69 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
66} 70}
67 71
68sub debug { 72sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 73 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 74 $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} 75}
73 76
74sub start_game { 77sub start_game {
75 status "logging in..."; 78 status "logging in...";
76 79
101} 104}
102 105
103sub client_setup { 106sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 107 my $dialog = new CFClient::UI::FancyFrame
105 child => (my $vbox = new CFClient::UI::VBox); 108 child => (my $vbox = new CFClient::UI::VBox);
106 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 109 $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]); 110 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
108 111
109 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 112 $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); 113 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 114
112 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 115 $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); 116 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
114 117
115 $mode_slider->connect (changed => sub { 118 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 119 my ($self, $value) = @_;
117 120
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 121 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 122 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 123 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 124 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 125
123 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 126 $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 { 127 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
125 my ($self, $value) = @_; 128 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 129 $CFG->{fullscreen} = $value;
127 }); 130 });
128 131
129 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 132 $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 { 133 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
131 my ($self, $value) = @_; 134 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 135 $CFG->{fast} = $value;
133 }); 136 });
134 137
135 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 138 $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 { 139 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
137 my ($self, $value) = @_; 140 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 141 $CFG->{fow_enable} = $value;
139 }); 142 });
140 143
141 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 144 $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 { 145 $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) = @_; 146 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 147 $CFG->{fow_intensity} = $value;
145 }); 148 });
146 149
147 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 150 $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 { 151 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
149 my ($self, $value) = @_; 152 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 153 $CFG->{fow_smooth} = $value;
154 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 155 });
152 156
153 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 157 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
158 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
159 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
160# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
161 });
162
163 $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 { 164 $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); 165 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
157 }); 166 });
158 167
159 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 168 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
160 destroy_screen (); 169 video_shutdown ();
161 init_screen (); 170 video_init ();
171 });
172
173 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
174 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
175 $CFG->{audio_enable} = $_[1];
176 });
177# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
178# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
179# $CFG->{effects_volume} = $_[1];
180# });
181 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
182 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
183 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
184 $CFG->{bgm_enable} = $_[1];
185 });
186 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
187 $CFG->{bgm_volume} = $_[1];
188 CFClient::Mix_VolumeMusic ($_[1]);
189 });
190
191 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
192 audio_shutdown ();
193 audio_init ();
162 }); 194 });
163 195
164 $dialog 196 $dialog
165} 197}
166 198
230 $HOST->set_text ($CFG->{host} = $host); 262 $HOST->set_text ($CFG->{host} = $host);
231 }), 263 }),
232 (new CFClient::UI::Empty expand => 1), 264 (new CFClient::UI::Empty expand => 1),
233 ]); 265 ]);
234 266
235 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 267 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
236 for 0 .. $#$m; 268 for 0 .. $#$m;
237 } 269 }
238 } 270 }
239 }); 271 });
240} 272}
241 273
242sub server_setup { 274sub server_setup {
243 my $dialog = new CFClient::UI::FancyFrame 275 my $dialog = new CFClient::UI::FancyFrame
244 child => (my $vbox = new CFClient::UI::VBox); 276 child => (my $vbox = new CFClient::UI::VBox);
245 277
246 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 278 $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]); 279 $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"); 280 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
249 281
250 { 282 {
251 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 283 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
252 284
253 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 285 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
254 my ($self, $value) = @_; 286 my ($self, $value) = @_;
255 $CFG->{host} = $value; 287 $CFG->{host} = $value;
256 }); 288 });
257 289
258 $METASERVER = metaserver_dialog; 290 $METASERVER = metaserver_dialog;
259 291
260 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 292 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
261 update_metaserver $HOST; 293 update_metaserver $HOST;
262 }); 294 });
263 } 295 }
264 296
265 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 297 $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 { 298 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
267 my ($self, $value) = @_; 299 my ($self, $value) = @_;
268 $CFG->{user} = $value; 300 $CFG->{user} = $value;
269 }); 301 });
270 302
271 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 303 $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 { 304 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
273 my ($self, $value) = @_; 305 my ($self, $value) = @_;
274 $CFG->{password} = $value; 306 $CFG->{password} = $value;
275 }); 307 });
276 308
277 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 309 $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 { 310 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
279 my ($self, $value) = @_; 311 my ($self, $value) = @_;
280 $CFG->{say_command} = $value; 312 $CFG->{say_command} = $value;
281 }); 313 });
282 314
283 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 315 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
284 $table->add (1, 7, new CFClient::UI::Slider 316 $table->add (1, 7, new CFClient::UI::Slider
285 req_w => 100, 317 req_w => 100,
286 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 318 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
287 connect_changed => sub { 319 connect_changed => sub {
288 my ($self, $value) = @_; 320 my ($self, $value) = @_;
300 332
301sub message_window { 333sub message_window {
302 my $window = new CFClient::UI::FancyFrame 334 my $window = new CFClient::UI::FancyFrame
303 border_bg => [1, 1, 1, 0.5], 335 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 336 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => $::WIDTH/4, 337 user_w => int $::WIDTH / 3,
306 user_h => $::HEIGHT, 338 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 339 child => (my $vbox = new CFClient::UI::VBox);
308 340
309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 341 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
310 expand => 1, 342 expand => 1,
311 fontsize => $::CFG->{log_fontsize}, 343 fontsize => $::CFG->{log_fontsize},
312 ); 344 );
313 345
314 $vbox->add (my $input = new CFClient::UI::LineEntry 346 $vbox->add (my $input = new CFClient::UI::Entry
315 connect_focus_in => sub { 347 connect_focus_in => sub {
316 my ($input, $prev_focus) = @_; 348 my ($input, $prev_focus) = @_;
317 349
318 delete $input->{refocus_map}; 350 delete $input->{refocus_map};
319 351
325 connect_activate => sub { 357 connect_activate => sub {
326 my ($input, $text) = @_; 358 my ($input, $text) = @_;
327 $input->set_text (''); 359 $input->set_text ('');
328 360
329 if ($text =~ /^\/(.*)/) { 361 if ($text =~ /^\/(.*)/) {
330 $::CONN->user_send ("command $1"); 362 $::CONN->user_send ($1);
331 } else { 363 } else {
332 my $say_cmd = $::CFG->{say_command} || 'say'; 364 my $say_cmd = $::CFG->{say_command} || 'say';
333 $::CONN->user_send ("command $say_cmd $text"); 365 $::CONN->user_send ("$say_cmd $text");
334 } 366 }
335 if ($input->{refocus_map}) { 367 if ($input->{refocus_map}) {
336 delete $input->{refocus_map}; 368 delete $input->{refocus_map};
337 $MAPWIDGET->focus_in 369 $MAPWIDGET->focus_in
338 } 370 }
349 381
350 $window 382 $window
351} 383}
352 384
353sub sdl_init { 385sub sdl_init {
354 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 386 CFClient::SDL_Init
355 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 387 and die "SDL::Init failed!\n";
357} 388}
358 389
359sub init_screen { 390sub video_init {
360 sdl_init; 391 sdl_init;
361 392
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 393 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 394 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 395 $FAST = $CFG->{fast};
365 396
366 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 397 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
367 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
368 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
369 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
370
371 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
372 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
373 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
374 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
375
376 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
377 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
378 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
379
380 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
381 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
382 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
383 or die "SDL::SetVideoMode failed!\n"; 398 or die "SDL_SetVideoMode failed!\n";
384
385 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
386 399
387 $SDL_EV = new SDL::Event; 400 $SDL_EV = new SDL::Event;
388 $SDL_EV->set_unicode (1); 401 $SDL_EV->set_unicode (1);
389 402
390 $SDL_ACTIVE = 1; 403 $SDL_ACTIVE = 1;
391 404
392 $LAST_REFRESH = time - 0.01; 405 $LAST_REFRESH = time - 0.01;
393 406
394 CFClient::gl_init; 407 CFClient::gl_init;
395 408
396 $FONTSIZE = int $HEIGHT / 40; 409 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
397 410
398 ############################################################################# 411 #############################################################################
399 412
400 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 413 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
401 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 414 $DEBUG_STATUS->show;
402 415
403 $STATUS_LINE = new CFClient::UI::Label 416 $STATUS_LINE = new CFClient::UI::Label
404 padding => 0, 417 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 418 y => $HEIGHT - $FONTSIZE * 1.8;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 419 $STATUS_LINE->show;
407 420
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 421 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 422 padding => 0,
410 y => $HEIGHT * 44 / 45, 423 fontsize => 0.8,
411 height => $HEIGHT / 45,
412 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 424 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 425 $ALT_ENTER_MESSAGE->show;
426 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
414 427
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 428 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
416 $MAPWIDGET->focus_in; 429 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 430 $MAPWIDGET->connect (activate_console => sub {
418 my ($mapwidget, $preset) = @_; 431 my ($mapwidget, $preset) = @_;
419 432
420 if ($CONSOLE) { 433 if ($CONSOLE) {
436 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 449 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 450 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 451 status "Configuration Saved";
439 }); 452 });
440 453
441 $BUTTONBAR->{children}[0]->emit ("activate"); 454 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 455
444sub destroy_screen { 456 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
457 $tgw->add (my $hbox = new CFClient::UI::HBox ());
458
459 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
460 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
461 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
462 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
463
464 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
465 $CFClient::UI::ROOT->add ($tgw);
466}
467
468sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 469 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 470 undef $SDL_ACTIVE;
447 undef $SDL_EV; 471 undef $SDL_EV;
448 SDL::Quit; 472}
473
474my $bgmusic;#TODO#hack#d#
475
476sub audio_init {
477 if ($CFG->{audio_enable}) {
478 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
479
480 $SDL_MIXER = !CFClient::Mix_OpenAudio;
481 CFClient::Mix_AllocateChannels 8;
482 CFClient::MixMusic::volume $CFG->{bgm_volume};
483
484 # TODO: hack, do play loop and mood music
485 if ($CFG->{bgm_enable}) {
486 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
487 $bgmusic->play;
488 }
489
490 while (<$fh>) {
491 next if /^\s*#/;
492 next if /^\s*$/;
493
494 my ($file, $volume, $event) = split /\s+/, $_, 3;
495
496 push @SOUNDS, "$volume,$file";
497
498 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
499 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
500 $chunk->volume ($volume * 128 / 100);
501 $chunk
502 };
503 }
504 } else {
505 status "unable to open sound config: $!";
506 }
507 }
508}
509
510sub audio_shutdown {
511 CFClient::Mix_CloseAudio if $SDL_MIXER;
512 undef $SDL_MIXER;
513 @SOUNDS = ();
514 %AUDIO_CHUNKS = ();
449} 515}
450 516
451my %animate_object; 517my %animate_object;
452my $animate_timer; 518my $animate_timer;
453 519
502 delete $animate_object{$widget}; 568 delete $animate_object{$widget};
503} 569}
504 570
505@conn::ISA = Crossfire::Protocol::; 571@conn::ISA = Crossfire::Protocol::;
506 572
573sub conn::stats_update {
574 my ($self, $stats) = @_;
575
576 # i love text protocols!!!
577 # FIXME: the stats are somehow weird
578 my $hp = $stats->{1};
579 my $hp_m = $stats->{2};
580 my $sp = $stats->{3};
581 my $sp_m = $stats->{4};
582 my $fo = $stats->{18};
583 my $fo_m = 1000;
584 my $gr = $stats->{23};
585 my $gr_m = $stats->{24};
586
587 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
588 $GAUGES->{hp}->set_value ($hp, $hp_m);
589 $GAUGES->{mana}->set_value ($sp, $sp_m);
590 $GAUGES->{food}->set_value ($fo, $fo_m);
591 $GAUGES->{grace}->set_value ($gr, $gr_m);
592}
593
507sub conn::user_send { 594sub conn::user_send {
508 my ($self, $command) = @_; 595 my ($self, $command) = @_;
509 596
510 $self->send ($command); 597 $self->send_command ($command);
511 status $command; 598 status $command;
599}
600
601sub conn::map_scroll {
602 my ($self, $dx, $dy) = @_;
603
604 $MAP->scroll ($dx, $dy);
512} 605}
513 606
514sub conn::feed_map1a { 607sub conn::feed_map1a {
515 my ($self, $data) = @_; 608 my ($self, $data) = @_;
516 609
517# $self->Crossfire::Protocol::feed_map1a ($data); 610# $self->Crossfire::Protocol::feed_map1a ($data);
518 611
519 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
520 $MAP->map1a_update ($data); 612 $MAP->map1a_update ($data);
521 $MAPWIDGET->update; 613 $MAPWIDGET->update;
522} 614}
523 615
524sub conn::flush_map { 616sub conn::flush_map {
538 630
539sub conn::map_clear { 631sub conn::map_clear {
540 my ($self) = @_; 632 my ($self) = @_;
541 633
542 $self->flush_map; 634 $self->flush_map;
635 delete $self->{neigh};
543 636
544 $MAP->clear; 637 $MAP->clear;
545} 638}
546 639
547sub conn::map_info {
548 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
549 640
550 $self->flush_map; 641sub conn::load_map($$$) {
551 642 my ($self, $hash, $x, $y) = @_;
552 $x = $::MAP->ox - $x;
553 $y = $::MAP->oy - $y;
554
555 $self->{map_info} = [$hash, $x, $y, $w, $h];
556 643
557 if (defined (my $data = $MAPCACHE->get ($hash))) { 644 if (defined (my $data = $MAPCACHE->get ($hash))) {
558 $data = Compress::LZF::decompress $data; 645 $data = Compress::LZF::decompress $data;
559 warn sprintf "LOADmap[%s] length %d\n", $hash, length $data;#d# 646 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
560 for my $id ($MAP->set_rect ($x, $y, $data)) { 647 for my $id ($MAP->set_rect ($x, $y, $data)) {
561 my $data = $TILECACHE->get ($id) 648 my $data = $TILECACHE->get ($id)
562 or next; 649 or next;
563 650
564 $self->set_texture ($id => $data); 651 $self->set_texture ($id => $data);
565 } 652 }
566 } 653 }
654}
655
656sub conn::flood_fill {
657 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_;
658
659 # the server does not allow map paths > 6
660 return if 6 <= length $path;
661
662 for my $tile (1..4) {
663 next if $self->{neigh}{$hash}[$tile];
664 next unless $flags & (1 << ($tile - 1));
665
666 my $neigh = $self->{neigh}{$hash} ||= [];
667
668 $self->send_mapinfo ("spatial $path$tile", sub {
669 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
670
671 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
672 return if $mode ne "spatial";
673
674 $x += $MAP->ox;
675 $y += $MAP->oy;
676
677 $self->load_map ($hash, $x, $y)
678 unless $self->{neigh}{$hash}[5]++;#d#
679
680 $neigh->[$tile] = [$x, $y, $w, $h];
681
682 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1)
683 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
684 });
685 }
686}
687
688sub conn::map_change {
689 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
690
691 $self->flush_map;
692
693 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
694
695 my $mapmapw = 250;
696 my $mapmaph = 250;
697
698 $self->flood_fill ("", $hash, $flags,
699 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
700 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
701
702 $x += $ox;
703 $y += $oy;
704
705 $self->{map_info} = [$hash, $x, $y, $w, $h];
706
707 $self->load_map ($hash, $x, $y);
567} 708}
568 709
569sub conn::face_find { 710sub conn::face_find {
570 my ($self, $facenum, $face) = @_; 711 my ($self, $facenum, $face) = @_;
571 712
621 762
622 $tex 763 $tex
623 }; 764 };
624} 765}
625 766
767sub conn::sound_play {
768 my ($self, $x, $y, $soundnum, $type) = @_;
769
770 $SDL_MIXER
771 or return;
772
773 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
774 or return;
775
776 $chunk->play;
777# warn "sound $x,$y,$soundnum,$type\n";#d#
778}
779
626sub conn::query { 780sub conn::query {
627 my ($self, $flags, $prompt) = @_; 781 my ($self, $flags, $prompt) = @_;
628 782
629 #TODO 783 #TODO, display dialog with relevant information
630 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 784 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
631} 785}
632 786
633sub conn::drawinfo { 787sub conn::drawinfo {
634 my ($self, $color, $text) = @_; 788 my ($self, $color, $text) = @_;
650 ); 804 );
651 805
652 $LOGVIEW->add_paragraph ($color[$color], $text); 806 $LOGVIEW->add_paragraph ($color[$color], $text);
653} 807}
654 808
809sub conn::spell_add {
810 my ($self, $spell) = @_;
811
812 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
813 });
814 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
815 });
816}
817
818sub conn::spell_delete {
819 my ($self, $spell) = @_;
820}
821
822sub conn::addme_success {
823 my ($self) = @_;
824
825 for my $skill (values %{$self->{skill_info}}) {
826 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
827 });
828 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
829 });
830 }
831}
832
655%SDL_CB = ( 833%SDL_CB = (
656 SDL_QUIT() => sub { 834 CFClient::SDL_QUIT => sub {
657 Event::unloop -1; 835 Event::unloop -1;
658 }, 836 },
659 SDL_VIDEORESIZE() => sub { 837 CFClient::SDL_VIDEORESIZE => sub {
660 }, 838 },
661 SDL_VIDEOEXPOSE() => sub { 839 CFClient::SDL_VIDEOEXPOSE => sub {
662 refresh; 840 refresh;
663 }, 841 },
664 SDL_KEYDOWN() => sub { 842 CFClient::SDL_KEYDOWN => sub {
665 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 843 if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) {
666 # alt-enter 844 # alt-enter
667 destroy_screen; 845 video_shutdown;
668 $CFG->{fullscreen} = !$CFG->{fullscreen}; 846 $CFG->{fullscreen} = !$CFG->{fullscreen};
669 init_screen; 847 video_init;
670 } else { 848 } else {
671 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 849 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
672 } 850 }
673 }, 851 },
674 SDL_KEYUP() => sub { 852 CFClient::SDL_KEYUP => sub {
675 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 853 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
676 }, 854 },
677 SDL_MOUSEMOTION() => sub { 855 CFClient::SDL_MOUSEMOTION => sub {
678 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 856 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
679 }, 857 },
680 SDL_MOUSEBUTTONDOWN() => sub { 858 CFClient::SDL_MOUSEBUTTONDOWN => sub {
681 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 859 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
682 }, 860 },
683 SDL_MOUSEBUTTONUP() => sub { 861 CFClient::SDL_MOUSEBUTTONUP => sub {
684 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 862 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
685 }, 863 },
686 SDL_ACTIVEEVENT() => sub { 864 CFClient::SDL_ACTIVEEVENT => sub {
687# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 865# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
688 }, 866 },
689); 867);
690 868
691############################################################################# 869#############################################################################
870
871$SIG{INT} = $SIG{TERM} = sub { exit };
692 872
693$TILECACHE = CFClient::db_table "tilecache"; 873$TILECACHE = CFClient::db_table "tilecache";
694$FACEMAP = CFClient::db_table "facemap"; 874$FACEMAP = CFClient::db_table "facemap";
695 875
696CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 876CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
702 fullscreen => 0, 882 fullscreen => 0,
703 fast => 0, 883 fast => 0,
704 fow_enable => 1, 884 fow_enable => 1,
705 fow_intensity => 0.45, 885 fow_intensity => 0.45,
706 fow_smooth => 0, 886 fow_smooth => 0,
887 gui_fontsize => 1,
707 log_fontsize => 14, 888 log_fontsize => 14,
708 mapsize => 100, 889 mapsize => 100,
709 host => "crossfire.schmorp.de", 890 host => "crossfire.schmorp.de",
710 say_command => 'say', 891 say_command => 'say',
892 audio_enable => 1,
893 bgm_enable => 1,
894 bgm_volume => 64,
711); 895);
712 896
713while (my ($k, $v) = each %DEF_CFG) { 897while (my ($k, $v) = each %DEF_CFG) {
714 $CFG->{$k} = $v unless exists $CFG->{$k}; 898 $CFG->{$k} = $v unless exists $CFG->{$k};
715} 899}
716 900
717sdl_init; 901sdl_init;
718 902
719@SDL_MODES = reverse 903@SDL_MODES = reverse
720 grep $_->[0] >= 640 && $_->[1] >= 480, 904 grep $_->[0] >= 640 && $_->[1] >= 480,
721 map [SDL::RectW ($_), SDL::RectH ($_)], 905 CFClient::SDL_ListModes;
722 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
723 906
724@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 907@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
725 908
726$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 909$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
727
728init_screen;
729 910
730{ 911{
731 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 912 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
732 913
733 CFClient::add_font $_ for @fonts; 914 CFClient::add_font $_ for @fonts;
734 CFClient::set_font $fonts[0]; 915 CFClient::set_font $fonts[0];
735} 916}
736 917
918video_init;
919audio_init;
920
737Event::loop; 921Event::loop;
738 922
923END { SDL::Quit }
739 924
925

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines