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.116 by root, Sun Apr 16 07:25:30 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
347 connect_focus_in => sub {
348 my ($input, $prev_focus) = @_;
349
350 delete $input->{refocus_map};
351
352 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
353 $input->{refocus_map} = 1;
354 }
355 delete $input->{auto_activated};
356 },
315 connect_activate => sub { 357 connect_activate => sub {
316 my ($input, $text) = @_; 358 my ($input, $text) = @_;
317 $input->set_text (''); 359 $input->set_text ('');
318 360
319 if ($text =~ /^\/(.*)/) { 361 if ($text =~ /^\/(.*)/) {
320 $::CONN->user_send ("command $1"); 362 $::CONN->user_send ($1);
321 } else { 363 } else {
322 my $say_cmd = $::CFG->{say_command} || 'say'; 364 my $say_cmd = $::CFG->{say_command} || 'say';
323 $::CONN->user_send ("command $say_cmd $text"); 365 $::CONN->user_send ("$say_cmd $text");
366 }
367 if ($input->{refocus_map}) {
368 delete $input->{refocus_map};
369 $MAPWIDGET->focus_in
324 } 370 }
325 }, 371 },
326 connect_escape => sub { 372 connect_escape => sub {
327 $MAPWIDGET->focus_in 373 $MAPWIDGET->focus_in
328 }, 374 },
335 381
336 $window 382 $window
337} 383}
338 384
339sub sdl_init { 385sub sdl_init {
340 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 386 CFClient::SDL_Init
341 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
342 and die "SDL::Init failed!\n"; 387 and die "SDL::Init failed!\n";
343} 388}
344 389
345sub init_screen { 390sub video_init {
346 sdl_init; 391 sdl_init;
347 392
348 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 393 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
349 $FULLSCREEN = $CFG->{fullscreen}; 394 $FULLSCREEN = $CFG->{fullscreen};
350 $FAST = $CFG->{fast}; 395 $FAST = $CFG->{fast};
351 396
352 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 397 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
353 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
354 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
355 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
356
357 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
358 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
359 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
360 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
361
362 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
363 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
364 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
365
366 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
367 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
368 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
369 or die "SDL::SetVideoMode failed!\n"; 398 or die "SDL_SetVideoMode failed!\n";
370
371 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
372 399
373 $SDL_EV = new SDL::Event; 400 $SDL_EV = new SDL::Event;
374 $SDL_EV->set_unicode (1); 401 $SDL_EV->set_unicode (1);
375 402
376 $SDL_ACTIVE = 1; 403 $SDL_ACTIVE = 1;
377 404
378 $LAST_REFRESH = time - 0.01; 405 $LAST_REFRESH = time - 0.01;
379 406
380 CFClient::gl_init; 407 CFClient::gl_init;
381 408
382 $FONTSIZE = int $HEIGHT / 40; 409 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
383 410
384 ############################################################################# 411 #############################################################################
385 412
386 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 413 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
387 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 414 $DEBUG_STATUS->show;
388 415
389 $STATUS_LINE = new CFClient::UI::Label 416 $STATUS_LINE = new CFClient::UI::Label
390 padding => 0, 417 padding => 0,
391 y => $HEIGHT * 44 / 45 - $FONTSIZE; 418 y => $HEIGHT - $FONTSIZE * 1.8;
392 $CFClient::UI::ROOT->add ($STATUS_LINE); 419 $STATUS_LINE->show;
393 420
394 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 421 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
395 padding => 0, 422 padding => 0,
396 y => $HEIGHT * 44 / 45, 423 fontsize => 0.8,
397 height => $HEIGHT / 45,
398 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 424 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
399 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 425 $ALT_ENTER_MESSAGE->show;
426 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
400 427
401 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 428 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
402 $MAPWIDGET->focus_in; 429 $MAPWIDGET->focus_in;
403 $MAPWIDGET->connect (activate_console => sub { 430 $MAPWIDGET->connect (activate_console => sub {
404 my ($mapwidget, $preset) = @_; 431 my ($mapwidget, $preset) = @_;
405 432
406 if ($CONSOLE) { 433 if ($CONSOLE) {
434 $CONSOLE->{input}->{auto_activated} = 1;
407 $CONSOLE->{input}->focus_in; 435 $CONSOLE->{input}->focus_in;
408 436
409 if ($preset && $CONSOLE->{input}->get_text eq '') { 437 if ($preset && $CONSOLE->{input}->get_text eq '') {
410 $CONSOLE->{input}->set_text ($preset); 438 $CONSOLE->{input}->set_text ($preset);
411 } 439 }
421 $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 {
422 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 450 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
423 status "Configuration Saved"; 451 status "Configuration Saved";
424 }); 452 });
425 453
426 $BUTTONBAR->{children}[0]->emit ("activate"); 454 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
427}
428 455
429sub 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 {
430 $CFClient::UI::ROOT->{children} = []; 469 $CFClient::UI::ROOT->{children} = [];
431 undef $SDL_ACTIVE; 470 undef $SDL_ACTIVE;
432 undef $SDL_EV; 471 undef $SDL_EV;
433 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 = ();
434} 515}
435 516
436my %animate_object; 517my %animate_object;
437my $animate_timer; 518my $animate_timer;
438 519
487 delete $animate_object{$widget}; 568 delete $animate_object{$widget};
488} 569}
489 570
490@conn::ISA = Crossfire::Protocol::; 571@conn::ISA = Crossfire::Protocol::;
491 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
492sub conn::user_send { 594sub conn::user_send {
493 my ($self, $command) = @_; 595 my ($self, $command) = @_;
494 596
495 $self->send ($command); 597 $self->send_command ($command);
496 status $command; 598 status $command;
599}
600
601sub conn::map_scroll {
602 my ($self, $dx, $dy) = @_;
603
604 $MAP->scroll ($dx, $dy);
497} 605}
498 606
499sub conn::feed_map1a { 607sub conn::feed_map1a {
500 my ($self, $data) = @_; 608 my ($self, $data) = @_;
501 609
502# $self->Crossfire::Protocol::feed_map1a ($data); 610# $self->Crossfire::Protocol::feed_map1a ($data);
503 611
504 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
505 $MAP->map1a_update ($data); 612 $MAP->map1a_update ($data);
506 $MAPWIDGET->update; 613 $MAPWIDGET->update;
507} 614}
508 615
509sub conn::flush_map { 616sub conn::flush_map {
523 630
524sub conn::map_clear { 631sub conn::map_clear {
525 my ($self) = @_; 632 my ($self) = @_;
526 633
527 $self->flush_map; 634 $self->flush_map;
635 delete $self->{neigh};
528 636
529 $MAP->clear; 637 $MAP->clear;
530} 638}
531 639
532sub conn::map_info {
533 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
534 640
535 $self->flush_map; 641sub conn::load_map($$$) {
536 642 my ($self, $hash, $x, $y) = @_;
537 $x = $::MAP->ox - $x;
538 $y = $::MAP->oy - $y;
539
540 $self->{map_info} = [$hash, $x, $y, $w, $h];
541 643
542 if (defined (my $data = $MAPCACHE->get ($hash))) { 644 if (defined (my $data = $MAPCACHE->get ($hash))) {
543 $data = Compress::LZF::decompress $data; 645 $data = Compress::LZF::decompress $data;
544 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#
545 for my $id ($MAP->set_rect ($x, $y, $data)) { 647 for my $id ($MAP->set_rect ($x, $y, $data)) {
546 my $data = $TILECACHE->get ($id) 648 my $data = $TILECACHE->get ($id)
547 or next; 649 or next;
548 650
549 $self->set_texture ($id => $data); 651 $self->set_texture ($id => $data);
550 } 652 }
551 } 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);
552} 708}
553 709
554sub conn::face_find { 710sub conn::face_find {
555 my ($self, $facenum, $face) = @_; 711 my ($self, $facenum, $face) = @_;
556 712
606 762
607 $tex 763 $tex
608 }; 764 };
609} 765}
610 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
611sub conn::query { 780sub conn::query {
612 my ($self, $flags, $prompt) = @_; 781 my ($self, $flags, $prompt) = @_;
613 782
614 #TODO 783 #TODO, display dialog with relevant information
615 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 784 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
616} 785}
617 786
618sub conn::drawinfo { 787sub conn::drawinfo {
619 my ($self, $color, $text) = @_; 788 my ($self, $color, $text) = @_;
620 789
621 my @color = ( 790 my @color = (
622 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 791 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
623 [1.00, 1.00, 1.00], 792 [1.00, 1.00, 1.00],
624 [0.50, 0.50, 1.00], # changed 793 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
625 [1.00, 0.00, 0.00], 794 [1.00, 0.00, 0.00],
626 [1.00, 0.54, 0.00], 795 [1.00, 0.54, 0.00],
627 [0.11, 0.56, 1.00], 796 [0.11, 0.56, 1.00],
628 [0.93, 0.46, 0.00], 797 [0.93, 0.46, 0.00],
629 [0.18, 0.54, 0.34], 798 [0.18, 0.54, 0.34],
635 ); 804 );
636 805
637 $LOGVIEW->add_paragraph ($color[$color], $text); 806 $LOGVIEW->add_paragraph ($color[$color], $text);
638} 807}
639 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
640%SDL_CB = ( 833%SDL_CB = (
641 SDL_QUIT() => sub { 834 CFClient::SDL_QUIT => sub {
642 Event::unloop -1; 835 Event::unloop -1;
643 }, 836 },
644 SDL_VIDEORESIZE() => sub { 837 CFClient::SDL_VIDEORESIZE => sub {
645 }, 838 },
646 SDL_VIDEOEXPOSE() => sub { 839 CFClient::SDL_VIDEOEXPOSE => sub {
647 refresh; 840 refresh;
648 }, 841 },
649 SDL_KEYDOWN() => sub { 842 CFClient::SDL_KEYDOWN => sub {
650 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) {
651 # alt-enter 844 # alt-enter
652 destroy_screen; 845 video_shutdown;
653 $CFG->{fullscreen} = !$CFG->{fullscreen}; 846 $CFG->{fullscreen} = !$CFG->{fullscreen};
654 init_screen; 847 video_init;
655 } else { 848 } else {
656 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 849 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
657 } 850 }
658 }, 851 },
659 SDL_KEYUP() => sub { 852 CFClient::SDL_KEYUP => sub {
660 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 853 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
661 }, 854 },
662 SDL_MOUSEMOTION() => sub { 855 CFClient::SDL_MOUSEMOTION => sub {
663 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 856 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
664 }, 857 },
665 SDL_MOUSEBUTTONDOWN() => sub { 858 CFClient::SDL_MOUSEBUTTONDOWN => sub {
666 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 859 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
667 }, 860 },
668 SDL_MOUSEBUTTONUP() => sub { 861 CFClient::SDL_MOUSEBUTTONUP => sub {
669 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 862 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
670 }, 863 },
671 SDL_ACTIVEEVENT() => sub { 864 CFClient::SDL_ACTIVEEVENT => sub {
672# 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#
673 }, 866 },
674); 867);
675 868
676############################################################################# 869#############################################################################
870
871$SIG{INT} = $SIG{TERM} = sub { exit };
677 872
678$TILECACHE = CFClient::db_table "tilecache"; 873$TILECACHE = CFClient::db_table "tilecache";
679$FACEMAP = CFClient::db_table "facemap"; 874$FACEMAP = CFClient::db_table "facemap";
680 875
681CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 876CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
687 fullscreen => 0, 882 fullscreen => 0,
688 fast => 0, 883 fast => 0,
689 fow_enable => 1, 884 fow_enable => 1,
690 fow_intensity => 0.45, 885 fow_intensity => 0.45,
691 fow_smooth => 0, 886 fow_smooth => 0,
887 gui_fontsize => 1,
692 log_fontsize => 14, 888 log_fontsize => 14,
693 mapsize => 100, 889 mapsize => 100,
694 host => "crossfire.schmorp.de", 890 host => "crossfire.schmorp.de",
695 say_command => 'say', 891 say_command => 'say',
892 audio_enable => 1,
893 bgm_enable => 1,
894 bgm_volume => 64,
696); 895);
697 896
698while (my ($k, $v) = each %DEF_CFG) { 897while (my ($k, $v) = each %DEF_CFG) {
699 $CFG->{$k} = $v unless exists $CFG->{$k}; 898 $CFG->{$k} = $v unless exists $CFG->{$k};
700} 899}
701 900
702sdl_init; 901sdl_init;
703 902
704@SDL_MODES = reverse 903@SDL_MODES = reverse
705 grep $_->[0] >= 640 && $_->[1] >= 480, 904 grep $_->[0] >= 640 && $_->[1] >= 480,
706 map [SDL::RectW ($_), SDL::RectH ($_)], 905 CFClient::SDL_ListModes;
707 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
708 906
709@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)";
710 908
711$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 909$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
712
713init_screen;
714 910
715{ 911{
716 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);
717 913
718 CFClient::add_font $_ for @fonts; 914 CFClient::add_font $_ for @fonts;
719 CFClient::set_font $fonts[0]; 915 CFClient::set_font $fonts[0];
720} 916}
721 917
918video_init;
919audio_init;
920
722Event::loop; 921Event::loop;
723 922
923END { SDL::Quit }
724 924
925

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines