ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Main.pm
Revision: 1.8
Committed: Wed Jan 4 11:23:23 2012 UTC (12 years, 5 months ago) by root
Branch: MAIN
Changes since 1.7: +175 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package DC::Main;
2
3 # "dummy" package, which contains the real "main" program
4 # bin/deliantra is just a wrapper, to reduce the amount
5 # of code that needs to be in BEGIN clauses, and
6 # to make upgrades easier.
7
8 package main;
9
10 if ($ENV{DELIANTRA_CORO_DEBUG}) {
11 eval '
12 use Coro;
13 use Coro::EV;
14 use Coro::Debug;
15 our $debug = new_unix_server Coro::Debug "/tmp/dc";
16 ';
17 die if $@;
18 }
19
20 use common::sense;
21 use Carp 'verbose';
22 use Cwd ();
23 use EV;
24 BEGIN { *time = \&EV::time }
25
26 use List::Util qw(max min);
27
28 use Deliantra;
29 use Deliantra::Protocol::Constants;
30
31 use AnyEvent::Util ();
32 use AnyEvent::Socket ();
33 use AnyEvent::DNS ();
34
35 use Compress::LZF;
36 use JSON::XS;
37
38 use DC;
39
40 sub crash($;$) {
41 # nop at compiletime
42 }
43
44 BEGIN {
45 $SIG{__DIE__} = sub {
46 return if $^S; # quick reject
47
48 # return if there are any eval contexts in the csall stack
49 for my $i (0..999) {
50 my ($sub, $is_require) = (caller $i)[3, 7]
51 or last;
52 return if $sub eq "(eval)" && !$is_require;
53 }
54
55 crash "CRASH/DIE: $_[0]" => 1;
56 DC::fatal Carp::longmess "$_[0]";
57 }
58 }
59
60 use DC::OpenGL ();
61 use DC::Protocol;
62 use DC::DB;
63 use DC::UI;
64 use DC::UI::Canvas;
65 use DC::UI::Inventory;
66 use DC::UI::SpellList;
67 use DC::UI::Dockable;
68 use DC::UI::Dockbar;
69 use DC::UI::ChatView;
70 use DC::MessageDistributor;
71 use DC::Pod;
72 use DC::MapWidget;
73 use DC::Macro;
74
75 $SIG{QUIT} = sub { Carp::cluck "QUIT" };
76 $SIG{PIPE} = 'IGNORE';
77
78 $EV::DIED = sub {
79 crash "CRASH/EV::DIED: $@" => 0;
80 DC::fatal Carp::longmess $@;
81 };
82
83 # initialise the resolver before going fullscreen,
84 # as vista forces us back to the desktop
85 # when doing this later.
86 use AnyEvent::DNS;
87 AnyEvent::DNS::resolver ();
88
89 our $MAX_FPS = 60;
90
91 our $DEFAULT_SERVER = "gameserver.deliantra.net";
92
93 our $META_SERVER = "http://metaserver.schmorp.de/current.json";
94
95 our $LAST_REFRESH;
96 our $NOW;
97
98 our $CFG;
99 our $PROFILE; # current profile
100 our $FAST; # fast, low-quality mode, possibly useful for software-rendering
101 our $DELIANTRA_DEBUG = $ENV{DELIANTRA_DEBUG} * 1;
102
103 our $WANT_REFRESH;
104
105 our $MODE_SLIDER;
106 our $CAVEAT_LABEL;
107
108 our @SDL_MODES;
109 our $SDL_REINIT = 1;
110 our $WIDTH;
111 our $HEIGHT;
112 our $FULLSCREEN;
113 our $FONTSIZE;
114
115 our $FONT_PROP;
116 our $FONT_FIXED;
117
118 our $CONN;
119
120 our $MAP;
121 our $MAPMAP;
122 our $MAPWIDGET;
123 our $COMPLETER;
124 our $MENUFRAME; # the rectangle at the top
125 our $MENUBAR; # the hbox at the top
126 our $MENUPOPUP;
127 our $BUTTONBAR; # the menu buttons
128 our $METASERVER;
129 our $LOGIN_BUTTON;
130 our $QUIT_DIALOG;
131 our $HOST_ENTRY;
132 our $FULLSCREEN_ENABLE;
133 our $PICKUP_ENABLE;
134 our $SERVER_INFO;
135
136 our $SETUP_DIALOG;
137 our $SETUP_NOTEBOOK;
138 our $SETUP_SERVER;
139 our $SETUP_LOGIN;
140 our $SETUP_KEYBOARD;
141
142 our $PL_NOTEBOOK;
143 our $PL_WINDOW;
144
145 our $MUSIC_PLAYING_WIDGET;
146 our $LICENSE_WIDGET;
147 our $DOWNLOADS_WIDGET;
148
149 our $PICKUP_PAGE;
150 our $INVENTORY_PAGE;
151 our $STATS_PAGE;
152 our $SKILL_PAGE;
153 our $SPELL_PAGE;
154 our $SPELL_LIST;
155
156 our $HELP_WINDOW;
157 our $MESSAGE_WINDOW;
158 our $MESSAGE_DIST;
159 our $FLOORBOX;
160 our $GAUGES;
161 our $STATWIDS;
162
163 our $SDL_ACTIVE;
164 our @SDL_CB;
165
166 our $ALT_ENTER_MESSAGE;
167 our $STATUSBOX;
168 our $MODBOX;
169 our $DEBUG_STATUS;
170
171 our $INV;
172 our $INVR;
173 our $INVR_HB;
174
175 #############################################################################
176
177 # write a crash message blockingly to the socket, if possible
178 # this is a bit too complicated for my tastes, but it was easy.
179 *crash = sub($;$) {
180 my ($msg, $backtrace) = @_;
181
182 warn $msg;
183
184 return unless $CONN;
185
186 my $fh = $CONN->{fh}
187 or return;
188
189 my $buf = delete $CONN->{wbuf};
190
191 $buf .= pack "n/a*", "exti " . JSON::XS::encode_json [clientlog => undef, substr $msg, 0, 8000];
192
193 AnyEvent::Util::fh_nonblocking $fh, 0;
194 syswrite $fh, $buf;
195 AnyEvent::Util::fh_nonblocking $fh, 1;
196
197 $msg =~ s/\s+$//;
198
199 # backtrace as second step, in case it crashes, too
200 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated"
201 if $backtrace;
202 };
203
204 sub clienterror($;$) {
205 my ($msg, $backtrace) = @_;
206
207 warn $msg;
208
209 return unless $CONN;
210
211 $CONN->send_exti_msg (clientlog => $msg);
212 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace;
213 }
214
215 #############################################################################
216
217 sub status {
218 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
219 }
220
221 sub debug {
222 $DEBUG_STATUS->set_text ($_[0]);
223 }
224
225 sub message {
226 $MESSAGE_DIST->message (@_);
227 }
228
229 sub update_modbox {
230 my $mod = DC::SDL_GetModState;
231
232 my $markup;
233
234 $markup .= $mod & DC::KMOD_CTRL
235 ? ($MAPWIDGET->{ctrl} ? "[REPEAT]" : "[<span foreground='#888'>REPEAT</span>]")
236 : "[<span foreground='#888'> once </span>]";
237
238 $markup .= $mod & DC::KMOD_SHIFT
239 ? ($MAPWIDGET->{shft} ? "[FIRE]" : "[<span foreground='#888'>FIRE</span>]")
240 : "[<span foreground='#888'>move</span>]";
241
242 $markup .= $mod & (DC::KMOD_ALT | DC::KMOD_META)
243 ? "[ALT]"
244 : "[<span foreground='#888'>alt</span>]";
245
246 $markup .= $mod & DC::KMOD_NUM
247 ? "[NUM]"
248 : "[<span foreground='#888'>num</span>]";
249
250 # <tt> around next statement works around some bug that keeps the
251 # "font =>" from being used on windows
252 $MODBOX->set_markup ("<tt>$markup</tt>");
253 }
254
255 #############################################################################
256 #TODO: maybe move into own audio module...
257
258 our $SDL_MIXER;
259
260 our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
261 our $MUSIC_WANT; # arryref of ambient music we want to play
262 our @MUSIC_HAVE; # ambient music we have on disk
263 our $MUSIC_START;
264 our @MUSIC_JINGLE; # which jingles to play next
265 our $MUSIC_PLAYING_DATA;
266 our $MUSIC_PLAYING_META;
267 our $MUSIC_PLAYER;
268 our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before
269
270 our %AUDIO_CHUNK; # audio "files"
271 our %AUDIO_PLAY; # which audio faces should be played
272
273 sub audio_channel_finished {
274 my ($channel) = @_;
275
276 # warn "channel $channel finished\n";#d#
277 }
278
279 sub audio_sound_push($) {
280 my ($face) = @_;
281
282 $CFG->{effects_enable}
283 or return;
284
285 $AUDIO_PLAY{$face}
286 or return;
287
288 if (my $chunk = $AUDIO_CHUNK{$face}) {
289 for (grep $_->[0] >= EV::now, @{(delete $AUDIO_PLAY{$face}) || []}) {
290 my (undef, $dx, $dy, $vol) = @$_;
291
292 my $channel = DC::Channel::find;
293 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
294 $channel->set_position_r ($dx, $dy, 20);
295 $chunk->play ($channel);
296 }
297 } else {
298 # sound_meta not set means data is in flight either way
299 my $meta = $CONN->{face}[$face]
300 or return;
301
302 $meta->{data}
303 or return;
304
305 # if it's a jingle, play it as ambient music
306 if ($meta->{data}{jingle}) {
307 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
308 push @MUSIC_JINGLE, $meta; # push it unto the music/jingle queue
309 &audio_music_push ($face);
310 }
311 } else {
312 # fetch from database
313 DC::DB::get res_data => $meta->{name}, sub {
314 my $rwops = new DC::RW $_[0];
315 my $chunk = new DC::MixChunk $rwops
316 or Carp::confess "sound face " . (JSON::XS::encode_json $meta) . " (" . (unpack "H64", $_[0]) . ") unloadable: " . DC::Mix_GetError;
317 $chunk->volume (($meta->{data}{volume} || 1) * 128);
318 $AUDIO_CHUNK{$face} = $chunk;
319
320 audio_sound_push ($face);
321 };
322 }
323 }
324 }
325
326 sub audio_sound_play {
327 my ($face, $dx, $dy, $vol) = @_;
328
329 $SDL_MIXER
330 or return;
331 $CFG->{effects_enable}
332 or return;
333
334 my $queue = $AUDIO_PLAY{$face} ||= [];
335 push @$queue, [EV::now + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
336 audio_sound_push $face
337 unless @$queue > 1;
338 }
339
340 sub audio_music_set_meta {
341 my ($meta) = @_;
342
343 $MUSIC_PLAYING_META = $meta;
344 $MUSIC_PLAYING_WIDGET->set_markup (
345 "<b>Name</b>: " . (DC::asxml $meta->{data}{name}) . "\n"
346 . "<b>Author</b>: " . (DC::asxml $meta->{data}{author}) . "\n"
347 . "<b>Source</b>: " . (DC::asxml $meta->{data}{source}) . "\n"
348 . "<b>License</b>: " . (DC::asxml $meta->{data}{license})
349 );
350 }
351
352 sub audio_music_update_volume {
353 return unless $MUSIC_PLAYING_META;
354 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
355 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
356 DC::MixMusic::volume $base * $volume * 128;
357 }
358
359 sub audio_music_start {
360 my $meta = $MUSIC_PLAYING_META;
361
362 DC::DB::get res_data => $meta->{name}, sub {
363 return unless $SDL_MIXER;
364
365 # music might have changed...
366 $meta eq $MUSIC_PLAYING_META
367 or return &audio_music_start ();
368
369 audio_music_update_volume;
370
371 $MUSIC_PLAYING_DATA = \$_[0];
372
373 $meta->{path} or length $_[0]
374 or return clienterror "empty music face from res_data ($meta->{face})";#d#
375
376 my $rwops = $meta->{path}
377 ? (new_from_file DC::RW $meta->{path} or return clienterror "unable to load music face $meta->{path}: $!")#d#clienterror
378 : new DC::RW $$MUSIC_PLAYING_DATA;
379
380 $MUSIC_PLAYER = new DC::MixMusic $rwops
381 or return clienterror "music face $meta->{face} unloadable: " . DC::Mix_GetError => 1;
382
383 my $NOW = time;
384
385 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
386 my $pos = $MUSIC_PLAYING_META->{stop_pos};
387 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
388 $MUSIC_START = time - $pos;
389 } else {
390 $MUSIC_PLAYER->play (0);
391 $MUSIC_START = time;
392 }
393
394 delete $meta->{stop_time};
395 delete $meta->{stop_pos};
396 }
397 }
398
399 sub audio_music_push {
400 return unless $SDL_MIXER;
401
402 my $fade_out;
403
404 if (@MUSIC_JINGLE) {
405 $fade_out = 333;
406 @MUSIC_HAVE = $MUSIC_JINGLE[0];
407
408 } else {
409 return unless $CFG->{bgm_enable};
410
411 $fade_out = 700;
412
413 @MUSIC_HAVE =
414 grep $_ && $_->{data},
415 map $CONN->{face}[$_],
416 @$MUSIC_WANT;
417
418 # randomize music a bit so that the order is not always the same
419 $_->{stop_time} ||= rand for @MUSIC_HAVE;
420
421 # default MUSIC_HAVE == MUSIC_DEFAULT
422 @MUSIC_HAVE = { path => DC::find_rcfile "music/$MUSIC_DEFAULT" }
423 unless @MUSIC_HAVE;
424 }
425
426 # if the currently playing song is acceptable, let it continue
427 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
428
429 my $NOW = time;
430
431 if ($MUSIC_PLAYING_META) {
432 $MUSIC_PLAYING_META->{stop_time} = $NOW;
433 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
434 DC::MixMusic::fade_out $fade_out;
435 } else {
436 # sort by stop time, oldest first
437 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
438
439 # if the most recently-played piece played very recently,
440 # resume it, else choose the oldest piece for rotation.
441 audio_music_set_meta
442 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
443 ? $MUSIC_HAVE[-1]
444 : $MUSIC_HAVE[0];
445
446 audio_music_start;
447 }
448 }
449
450 sub audio_music_set_ambient {
451 my ($songs) = @_;
452
453 $MUSIC_WANT = $songs;
454 audio_music_push;
455 }
456
457 sub audio_music_finished {
458 if ($MUSIC_PLAYING_META) {
459 $MUSIC_PLAYING_META->{stop_time} = time;
460 }
461
462 # we compress multiple jingles of the same type
463 shift @MUSIC_JINGLE
464 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
465
466 $MUSIC_PLAYING_WIDGET->clear;
467
468 undef $MUSIC_PLAYER;
469 undef $MUSIC_PLAYING_META;
470 undef $MUSIC_PLAYING_DATA;
471
472 audio_music_push;
473 }
474
475 sub audio_init {
476 if ($CFG->{audio_enable}) {
477 if (length $CFG->{audio_driver}) {
478 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
479 DC::SDL_Init DC::SDL_INIT_AUDIO
480 and die "SDL::Init failed!\n";
481 } else {
482 DC::SDL_Init DC::SDL_INIT_AUDIO
483 and die "SDL::Init failed!\n";
484 }
485
486 $ENV{MIX_EFFECTSMAXSPEED} = 1;
487 $SDL_MIXER = !DC::Mix_OpenAudio
488 $CFG->{audio_hw_frequency},
489 DC::MIX_DEFAULT_FORMAT,
490 $CFG->{audio_hw_channels},
491 $CFG->{audio_hw_chunksize};
492
493 if ($SDL_MIXER) {
494 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
495
496 audio_music_finished;
497 } else {
498 status "Unable to open sound device: there will be no sound";
499 }
500 } else {
501 undef $SDL_MIXER;
502 }
503
504 sub audio_tab_update;
505 audio_tab_update;
506 }
507
508 sub audio_shutdown {
509 if ($SDL_MIXER) {
510 DC::MixMusic::halt;
511 DC::Mix_AllocateChannels 0;
512 }
513
514 undef $MUSIC_PLAYER;
515 undef $MUSIC_PLAYING_META;
516 undef $MUSIC_PLAYING_DATA;
517
518 $MUSIC_WANT = [];
519 @MUSIC_JINGLE = ();
520 %AUDIO_PLAY = ();
521 %AUDIO_CHUNK = ();
522
523 DC::Mix_CloseAudio if $SDL_MIXER;
524 undef $SDL_MIXER;
525
526 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
527 }
528
529 #############################################################################
530 # Over-the-air updates
531
532 sub ota_update_finish {
533 $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] });
534 }
535
536 sub ota_update_status {
537 }
538
539 sub ota_update {
540 my ($face, $size) = @_;
541
542 my $coro = Coro::async_pool {
543 my $override = "$Urlader::EXE_DIR/override";
544
545 $MESSAGE_DIST->add_channel ({
546 id => "ota_update",
547 title => "Update",
548 tooltip => "<b>Software Update Log</b>",
549 });
550
551 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
552
553 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
554
555 unless ($fh) {
556 ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!";
557 return;
558 }
559
560 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
561
562 my $cv = AE::cv;
563 my $error;
564
565 $cv->begin (Coro::rouse_cb);
566
567 $CONN->ask_face (
568 $face,
569 -1000,
570 sub {
571 $STATUSBOX->add (
572 (sprintf "update download: %d/%d", $size - $_[1], $size),
573 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
574 );
575
576 $cv->begin;
577 my $len = length $_[2];
578 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
579 $error ||= $_[0] != $len;
580 $cv->end;
581 };
582 },
583 sub {
584 $cv->end;
585 },
586 );
587
588 Coro::rouse_wait;
589
590 $STATUSBOX->clr_group ("ota_update");
591
592 $error ||= Coro::AIO::aio_fsync $fh;
593 $error ||= Coro::AIO::aio_close $fh;
594
595 if ($error) {
596 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
597 Coro::AIO::aio_unlink "$override.tmp";
598 return;
599 }
600
601 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
602
603 if (Coro::AIO::aio_rename "$override.tmp", $override) {
604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
605 Coro::AIO::aio_unlink "$override.tmp";
606 }
607
608 $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." });
609 };
610
611 $CONN->{ota_update} = Guard::guard {
612 $coro->cancel;
613 };
614 }
615
616 sub ota_update_ask {
617 my ($ok, $face, $ver, $size, $changes) = @_;
618
619 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
620 x => "center",
621 y => "center",
622 max_w => $::WIDTH * 0.7,
623 max_h => $::WIDTH * 0.7,
624 title => "Software update available",
625 child => my $vbox = new DC::UI::VBox,
626 ;
627
628 $vbox->add (new DC::UI::Label
629 ellipsise => 0,
630 text => "The server offers a software update, "
631 . "do you want to start downloading this update in the background?",
632 );
633
634 $vbox->add (new DC::UI::FancyFrame
635 expand => 1,
636 label => "Changes",
637 child => (new DC::UI::TextScroller
638 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
639 par => [{
640 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
641 . "New revision: $ver\n"
642 . "Download size: $size bytes</tt>\n\n"
643 . DC::asxml $changes
644 }],
645 ),
646 );
647
648 $vbox->add (my $hbox = new DC::UI::HBox);
649
650 $hbox->add (new DC::UI::Button
651 expand => 1,
652 text => "Not now",
653 on_activate => sub {
654 $dialog->destroy;
655 0
656 }
657 );
658 $hbox->add (new DC::UI::Button
659 expand => 1,
660 text => "Yes, start downloading",
661 on_activate => sub {
662 $dialog->destroy;
663 ota_update $face, $size;
664 0
665 },
666 );
667
668 $dialog->show;
669 }
670
671 sub ota_update_check {
672 return unless defined $Urlader::EXE_ID;
673
674 ::message { markup => "Checking for software update..." };
675
676 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
677 my ($ok, $face, $ver, $size, $changes) = @_;
678
679 if ($ok) {
680 if (defined $ver) {
681 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
682 &ota_update_ask;
683 } else {
684 ::message { markup => "Server has no newer version." };
685 }
686 } else {
687 ::message { markup => "Server does not support software update." };
688 }
689
690 # $self->register_face_handler ($exp_table, sub {
691 # my ($face) = @_;
692
693 # $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
694 # $_->() for values %{ $self->{on_exp_update} || {} };
695 # });
696
697 ()
698 });
699 }
700
701 #############################################################################
702
703 sub destroy_query_dialog {
704 (delete $_[0]{query_dialog})->destroy
705 if $_[0]{query_dialog};
706 }
707
708 # FIXME: a very ugly hack to wait for stat update look below! #d#
709 our $QUERY_TIMER; #d#
710
711 # server query dialog
712 sub server_query {
713 my ($conn, $flags, $prompt) = @_;
714
715 # FIXME: a very ugly hack to wait for stat update #d#
716 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) {
717 unless ($QUERY_TIMER) {
718 $QUERY_TIMER = EV::timer 1, 0, sub {
719 server_query ($conn, $flags, $prompt, 1);
720 $QUERY_TIMER = undef
721 };
722
723 return;
724 }
725 }
726
727 $conn->{query_dialog} = my $dialog = new DC::UI::Toplevel
728 x => "center",
729 y => "center",
730 title => "Server Query",
731 child => my $vbox = new DC::UI::VBox,
732 ;
733
734 my @dialog = my $label = new DC::UI::Label
735 max_w => $::WIDTH * 0.8,
736 ellipsise => 0,
737 text => $prompt;
738
739 if ($flags & CS_QUERY_YESNO) {
740 push @dialog, my $hbox = new DC::UI::HBox;
741
742 $hbox->add (new DC::UI::Button
743 text => "No",
744 on_activate => sub {
745 $conn->send ("reply n");
746 $dialog->destroy;
747 0
748 }
749 );
750 $hbox->add (new DC::UI::Button
751 text => "Yes",
752 on_activate => sub {
753 $conn->send ("reply y");
754 destroy_query_dialog $conn;
755 0
756 },
757 );
758
759 $dialog->grab_focus;
760
761 } elsif ($flags & CS_QUERY_SINGLECHAR) {
762 if ($prompt =~ /Now choose a character|Press any key for the next race/i) {
763 $dialog->{tooltip} = "#charcreation_focus";
764
765 unshift @dialog, new DC::UI::Label
766 max_w => $::WIDTH * 0.8,
767 ellipsise => 0,
768 markup => "\nOr use your keyboard and the text entry below:\n";
769
770 unshift @dialog, my $table = new DC::UI::Table;
771
772 $table->add_at (0, 0, new DC::UI::Button
773 text => "Next Race",
774 on_activate => sub {
775 $conn->send ("reply n");
776 destroy_query_dialog $conn;
777 0
778 },
779 );
780 $table->add_at (2, 0, new DC::UI::Button
781 text => "Accept",
782 on_activate => sub {
783 $conn->send ("reply d");
784 destroy_query_dialog $conn;
785 0
786 },
787 );
788
789 if ($conn->{chargen_race_description}) {
790 unshift @dialog, new DC::UI::Label
791 max_w => $::WIDTH * 0.8,
792 ellipsise => 0,
793 markup => "<span foreground='#ccccff'>$conn->{chargen_race_description}</span>",
794 ;
795 }
796
797 unshift @dialog, new DC::UI::Face
798 face => $conn->{player}{face},
799 bg => [.2, .2, .2, 1],
800 min_w => 64,
801 min_h => 64,
802 ;
803
804 if ($conn->{chargen_race_title}) {
805 unshift @dialog, new DC::UI::Label
806 allign => 1,
807 ellipsise => 0,
808 markup => "<span foreground='#ccccff' size='large'>Race: $conn->{chargen_race_title}</span>",
809 ;
810 }
811
812 unshift @dialog, new DC::UI::Label
813 max_w => $::WIDTH * 0.4,
814 ellipsise => 0,
815 markup => (DC::Pod::section_label ui => "chargen_race"),
816 ;
817
818 } elsif ($prompt =~ /roll new stats/) {
819 if (my $stat = delete $conn->{stat_change_with}) {
820 $conn->send ("reply $stat");
821 destroy_query_dialog $conn;
822 return;
823 }
824
825 unshift @dialog, new DC::UI::Label
826 max_w => $::WIDTH * 0.4,
827 ellipsise => 0,
828 markup => "\nOr use your keyboard and the text entry below:\n";
829
830 unshift @dialog, my $table = new DC::UI::Table;
831
832 # left: re-roll
833 $table->add_at (0, 0, new DC::UI::Button
834 text => "Roll Again",
835 on_activate => sub {
836 $conn->send ("reply y");
837 destroy_query_dialog $conn;
838 0
839 },
840 );
841
842 # center: swap stats
843 my ($sw1, $sw2) = map +(new DC::UI::Selector
844 expand => 1,
845 value => $_,
846 options => [
847 [1 => "Str", "Strength ($conn->{stat}{+CS_STAT_STR})"],
848 [2 => "Dex", "Dexterity ($conn->{stat}{+CS_STAT_DEX})"],
849 [3 => "Con", "Constitution ($conn->{stat}{+CS_STAT_CON})"],
850 [4 => "Int", "Intelligence ($conn->{stat}{+CS_STAT_INT})"],
851 [5 => "Wis", "Wisdom ($conn->{stat}{+CS_STAT_WIS})"],
852 [6 => "Pow", "Power ($conn->{stat}{+CS_STAT_POW})"],
853 [7 => "Cha", "Charisma ($conn->{stat}{+CS_STAT_CHA})"],
854 ],
855 ), 1 .. 2;
856
857 $table->add_at (2, 0, new DC::UI::Button
858 text => "Swap Stats",
859 on_activate => sub {
860 $conn->{stat_change_with} = $sw2->{value};
861 $conn->send ("reply $sw1->{value}");
862 destroy_query_dialog $conn;
863 0
864 },
865 );
866 $table->add_at (2, 1, new DC::UI::HBox children => [$sw1, $sw2]);
867
868 # right: accept
869 $table->add_at (4, 0, new DC::UI::Button
870 text => "Accept",
871 on_activate => sub {
872 $conn->send ("reply n");
873 destroy_query_dialog $conn;
874 0
875 },
876 );
877
878 unshift @dialog, my $hbox = new DC::UI::HBox;
879 for (
880 [Str => CS_STAT_STR],
881 [Dex => CS_STAT_DEX],
882 [Con => CS_STAT_CON],
883 [Int => CS_STAT_INT],
884 [Wis => CS_STAT_WIS],
885 [Pow => CS_STAT_POW],
886 [Cha => CS_STAT_CHA],
887 ) {
888 my ($name, $id) = @$_;
889 $hbox->add (new DC::UI::Label
890 markup => "$conn->{stat}{$id} <span foreground='yellow'>$name</span>",
891 expand => 1,
892 can_events => 1,
893 can_hover => 1,
894 tooltip => "#stat_$name",
895 );
896 }
897
898 unshift @dialog, new DC::UI::Label
899 max_w => $::WIDTH * 0.4,
900 ellipsise => 0,
901 markup => (DC::Pod::section_label ui => "chargen_stats"),
902 ;
903 }
904
905 push @dialog, my $entry = new DC::UI::Entry
906 on_changed => sub {
907 $conn->send ("reply $_[1]");
908 destroy_query_dialog $conn;
909 0
910 },
911 ;
912
913 $entry->grab_focus;
914
915 } else {
916 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)";
917
918 push @dialog, my $entry = new DC::UI::Entry
919 $flags & CS_QUERY_HIDEINPUT ? (hidden => "*") : (),
920 on_activate => sub {
921 $conn->send ("reply $_[1]");
922 destroy_query_dialog $conn;
923 0
924 },
925 ;
926
927 $entry->grab_focus;
928 }
929
930 $vbox->add (@dialog);
931 $dialog->show;
932 }
933
934 sub dc_connect {
935 my ($host, $port) = @_;
936
937 my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32;
938 my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
939
940 $CONN =
941 new DC::Protocol
942 host => $host,
943 port => $port,
944 user => $PROFILE->{user},
945 pass => $PROFILE->{password},
946 mapw => $mapw,
947 maph => $maph,
948
949 c_version => {
950 client => "deliantra",
951 clientver => $DC::VERSION,
952 gl_vendor => DC::OpenGL::gl_vendor,
953 gl_version => DC::OpenGL::gl_version,
954 },
955
956 map_widget => $MAPWIDGET,
957 statusbox => $STATUSBOX,
958 map => $MAP,
959 mapmap => $MAPMAP,
960 query => \&server_query,
961
962 setup_req => {
963 smoothing => $CFG->{map_smoothing}*1,
964 },
965
966 on_connect => sub {
967 if ($_[0]) {
968 DC::lowdelay fileno $CONN->{fh};
969
970 ota_update_check;
971
972 status "successfully connected to the server";
973 } else {
974 undef $CONN;
975 status "unable to connect: $!";
976 stop_game();
977 }
978 },
979 ;
980 }
981
982 sub start_game {
983 status "logging in...";
984
985 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
986 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
987 or return status "$server: unable to parse server address, try an empty field.";
988
989 $LOGIN_BUTTON->set_text ("Logout");
990 $SETUP_DIALOG->hide;
991
992 $MAP = new DC::Map;
993
994 # hack to make SURE we find the IP address all right
995 # can be removed once AnyEvent::DNS is proven stable.
996 if ($host eq "gameserver.deliantra.net") {
997 AnyEvent::DNS::a "dnstest.deliantra.net", sub {
998 if ($_[0] ne "80.101.114.108") { # P-e-r-l
999 status "dns failure, trying differently";
1000 $host = eval { Socket::inet_ntoa Socket::inet_aton "gameserver.deliantra.net" };
1001 unless (defined $host) {
1002 status "dns failure, using hardcoded address";
1003 $host = "194.126.175.154";
1004 }
1005 }
1006
1007 dc_connect $host, $port;
1008 };
1009 } else {
1010 dc_connect $host, $port;
1011 }
1012 }
1013
1014 sub stop_game {
1015 crash "stop_game";
1016
1017 $LOGIN_BUTTON->set_text ("Login / Register");
1018 $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN);
1019 $SETUP_DIALOG->show;
1020 $PL_WINDOW->hide;
1021 $SPELL_LIST->clear_spells;
1022 $DC::UI::ROOT->emit (stop_game => ! ! $CONN);
1023
1024 &audio_music_set_ambient ([]);
1025
1026 return unless $CONN;
1027
1028 status "connection closed";
1029
1030 destroy_query_dialog $CONN;
1031 $CONN->destroy;
1032 $CONN = 0; # false, does not autovivify
1033
1034 undef $MAP;
1035 }
1036
1037 sub graphics_setup {
1038 my $vbox = new DC::UI::VBox;
1039
1040 {
1041 $vbox->add (my $frame = new DC::UI::FancyFrame expand => 1, label => "Video Mode");
1042
1043 $frame->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
1044
1045 my $row = 0;
1046
1047 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "OpenGL Info");
1048 $table->add_at (1, $row++, new DC::UI::Label fontsize => 0.8, text => DC::OpenGL::gl_vendor . ", " . DC::OpenGL::gl_version,
1049 can_events => 1,
1050 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>");
1051
1052 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Caveats");
1053 $table->add_at (1, $row++, $CAVEAT_LABEL = new DC::UI::Label fontsize => 0.8,
1054 can_events => 1,
1055 tooltip => "This field shows any known issues with your config or driver, such as "
1056 . "a non-accelerated display format. You can try to work around these issues "
1057 . "by selecting a different video mode, changing the settings below or "
1058 . "by installing the right driver for your graphics card.");
1059
1060 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "UI Theme");
1061 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::Selector
1062 value => $CFG->{uitheme},
1063 options => [
1064 [wood => "Wood (the default)"],
1065 [plain => "Plain (very)"],
1066 [blue => "Blue (dark)"],
1067 [metal => "Metal (light)"],
1068 ],
1069 tooltip => "Choose the User Interface theme that you like most :)",
1070 on_changed => sub { my ($self, $value) = @_; $CFG->{uitheme} = $value; 0 }
1071 );
1072
1073 my $vidmode_tooltip =
1074 "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). "
1075 . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>.";
1076
1077 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode");
1078 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox);
1079
1080 $hbox->add ($MODE_SLIDER = new DC::UI::Slider
1081 c_rescale => 1,
1082 force_w => $WIDTH * 0.1, expand => 1,
1083 range => [ ($CFG->{sdl_mode}) x 3 ],
1084 tooltip => $vidmode_tooltip);
1085 $hbox->add (my $mode_label = new DC::UI::Label
1086 height => 0.8, template => "9999x9999@9+9",
1087 can_events => 1, tooltip => $vidmode_tooltip);
1088
1089 $MODE_SLIDER->connect (changed => sub {
1090 my ($self, $value) = @_;
1091
1092 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
1093 $mode_label->set_text (sprintf '%dx%d@%d+%d', @{$SDL_MODES[$value]});
1094 });
1095 $MODE_SLIDER->emit (changed => $MODE_SLIDER->{range}[0]);
1096
1097 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fullscreen");
1098 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::CheckBox
1099 state => $CFG->{fullscreen},
1100 tooltip => "Bring the client into fullscreen mode.",
1101 on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
1102 );
1103
1104 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Force OpenGL 1.1");
1105 $table->add_at (1, $row++, new DC::UI::CheckBox
1106 state => $CFG->{force_opengl11},
1107 tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in "
1108 . "higher memory usage and slower performance. It will, however, help tremendously on "
1109 . "cards that claim to support a feature but fall back to software rendering. "
1110 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
1111 . "but cards and drivers from other vendors (ATI) are often just as bad. "
1112 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>",
1113 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
1114 );
1115
1116 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha");
1117 $table->add_at (1, $row++, new DC::UI::CheckBox
1118 state => $CFG->{disable_alpha},
1119 tooltip => "Forbid the use of the alpha channel. This makes Deliantra look a lot worse "
1120 . "by disabling a number of textures and transparency effects. Normally, these "
1121 . "effects do not cost a lot of resources, but some graphics cards might fall "
1122 . "back to extremely slow rendering if this is enabled. If disabling this option "
1123 . "noticably improves the framerate of the client please report this! "
1124 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>",
1125 on_changed => sub {
1126 my ($self, $value) = @_;
1127 $CFG->{disable_alpha} = $value;
1128 $SDL_REINIT = 1; # SDL_SetVideoMode ignores GL attr changes
1129 0
1130 }
1131 );
1132
1133 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
1134 $table->add_at (1, $row++, new DC::UI::CheckBox
1135 state => $CFG->{texture_compression},
1136 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
1137 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). "
1138 . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in "
1139 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
1140 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
1141 );
1142
1143 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
1144 $table->add_at (1, $row++, new DC::UI::CheckBox
1145 state => $CFG->{fast},
1146 tooltip => "Lower the visual quality considerably to speed up rendering.",
1147 on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 }
1148 );
1149
1150 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "GUI Fontsize");
1151 $table->add_at (1, $row++, new DC::UI::Slider
1152 range => [$CFG->{gui_fontsize}, 0.5, 2, 0, 0.1],
1153 tooltip => "The base font size used by most GUI elements that do not have their own setting.",
1154 on_changed => sub { $CFG->{gui_fontsize} = $_[1]; 0 },
1155 );
1156
1157 $table->add_at (1, $row++, new DC::UI::Button
1158 expand => 1, text => "Apply",
1159 tooltip => "Apply the video settings above.",
1160 on_activate => sub {
1161 video_shutdown ();
1162 video_init ();
1163 0
1164 }
1165 );
1166 }
1167
1168 {
1169 $vbox->add (my $frame = new DC::UI::FancyFrame expand => 1, label => "Other Settings");
1170
1171 $frame->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
1172
1173 my $row = 0;
1174 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Smooth Movement");
1175 $table->add_at (1, $row++, new DC::UI::CheckBox
1176 state => $CFG->{smooth_movement},
1177 tooltip => "<b>Smooth Movement</b> tries to make movement, well, smoother, but also increases the framerate. "
1178 . "If you have a very slow system, non-accelerated drivers or plain dislike smooth scrolling, "
1179 . "then disable this option. Changes take effect immdiately.",
1180 on_changed => sub { my ($self, $value) = @_; $CFG->{smooth_movement} = $value; 0 }
1181 );
1182
1183 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Smooth Transitions");
1184 $table->add_at (1, $row++, new DC::UI::CheckBox
1185 state => $CFG->{smooth_transitions},
1186 tooltip => "<b>Smooth Transitions</b> tries to blend the fog of war and lighting smoothly between updates. "
1187 . "If you have a very slow system, non-accelerated drivers or plain dislike smooth scrolling, "
1188 . "then disable this option. Requires Smooth Movement and OpenGL Multitexturing. Changes take effect immdiately.",
1189 on_changed => sub { my ($self, $value) = @_; $CFG->{smooth_transitions} = $value; 0 }
1190 );
1191
1192
1193 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Map Scale");
1194 $table->add_at (1, $row++, new DC::UI::Slider
1195 range => [(log $CFG->{map_scale}) / (log 2), -3, 1, 0, 1],
1196 tooltip => "Enlarge or shrink the displayed map. Changes are instant.",
1197 on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 }
1198 );
1199
1200 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Map Smoothing");
1201 $table->add_at (1, $row++, new DC::UI::CheckBox
1202 state => $CFG->{map_smoothing},
1203 tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. "
1204 . "This increases load on the graphics subsystem and works only with TRT servers. "
1205 . "Changes take effect at next login only.",
1206 on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
1207 );
1208
1209 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fog of War");
1210 $table->add_at (1, $row++, new DC::UI::CheckBox
1211 state => $CFG->{fow_enable},
1212 tooltip => "<b>Fog-of-War</b> marks areas that cannot be seen by the player. Changes are instant.",
1213 on_changed => sub { my ($self, $value) = @_; $CFG->{fow_enable} = $value; 0 }
1214 );
1215
1216 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "FoW Pattern");
1217 $table->add_at (1, $row++, new DC::UI::ImageButton
1218 tex => $DC::MapWidget::TEX_HIDDEN[$CFG->{fow_texture}],
1219 bg => [0.3, 0.3, 0.2],
1220 force_w => 64,
1221 force_h => 64,
1222 tooltip => "<b>Fog of War Pattern.</b> The pattern that is overlaid over areas hidden from view. Click to cycle through various alternatives. Changes are instant.",
1223 on_activate => sub {
1224 my ($self) = @_;
1225 $CFG->{fow_texture} = ($CFG->{fow_texture} + 1) % @DC::MapWidget::TEX_HIDDEN;
1226 $self->set_texture ($DC::MapWidget::TEX_HIDDEN[$CFG->{fow_texture}]);
1227 $MAPWIDGET->update;
1228 }
1229 );
1230
1231 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "FoW Intensity");
1232 $table->add_at (1, $row++, new DC::UI::Slider
1233 range => [$CFG->{fow_intensity}, 0, 1, 0, 1 / 256],
1234 tooltip => "<b>Fog of War Lightness.</b> The higher the intensity, the lighter the Fog-of-War color. Changes are instant.",
1235 on_changed => sub { my ($self, $value) = @_; $CFG->{fow_intensity} = $value; 0 }
1236 );
1237
1238 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Fontsize");
1239 $table->add_at (1, $row++, new DC::UI::Slider
1240 range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
1241 tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, "
1242 . "but you still need to press apply to correctly re-layout the widget.",
1243 on_changed => sub { $MESSAGE_DIST->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
1244 );
1245
1246 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Gauge fontsize");
1247 $table->add_at (1, $row++, new DC::UI::Slider
1248 range => [$CFG->{gauge_fontsize}, 0.5, 2, 0, 0.1],
1249 tooltip => "Adjusts the fontsize of the gauges at the bottom right. Changes are instant.",
1250 on_changed => sub {
1251 $CFG->{gauge_fontsize} = $_[1];
1252 &set_gauge_window_fontsize;
1253 0
1254 }
1255 );
1256
1257 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Gauge size");
1258 $table->add_at (1, $row++, new DC::UI::Slider
1259 range => [$CFG->{gauge_size}, 0.2, 0.8],
1260 tooltip => "Adjust the size of the stats gauges at the bottom right. Changes are instant.",
1261 on_changed => sub {
1262 $CFG->{gauge_size} = $_[1];
1263 $GAUGES->{win}->set_size ($WIDTH, int $HEIGHT * $CFG->{gauge_size});
1264 0
1265 }
1266 );
1267 }
1268
1269 $vbox
1270 }
1271
1272 our $AUDIO_HW_CHUNKSIZE;
1273 our $AUDIO_INFO;
1274
1275 sub audio_tab_update {
1276 my ($freq, $format, $chans) = DC::Mix_QuerySpec;
1277
1278 $AUDIO_HW_CHUNKSIZE->set_options ([
1279 [0, "default", "Use System Default"],
1280 map {
1281 my $ms = sprintf "%dms", 1000 * $_ / ($CFG->{audio_hw_frequency} || 22050);
1282 [$_, $ms, "$ms ($_ samples)"],
1283 } 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
1284 ]);
1285
1286 my $text = !$freq
1287 ? "audio is off"
1288 : "audio is enabled\n"
1289 . "driver: " . DC::SDL_AudioDriverName . "\n"
1290 . "frequency (Hz): $freq\n"
1291 . "channels: $chans\n"
1292 . "chunk decoders available: " . (join ", ", DC::MixChunk::decoders) . "\n"
1293 . "music decoders available: " . (join ", ", DC::MixMusic::decoders);
1294
1295 $AUDIO_INFO->set_text ($text);
1296 }
1297
1298 sub audio_setup {
1299 my $vbox = new DC::UI::VBox;
1300
1301 $vbox->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 0, 1]);
1302
1303 my $row = 0;
1304
1305 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Audio Enable");
1306 $table->add_at (1, $row, new DC::UI::CheckBox
1307 state => $CFG->{audio_enable},
1308 tooltip => "<b>Master Audio Enable.</b> If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.",
1309 on_changed => sub { $CFG->{audio_enable} = $_[1]; 1 }
1310 );
1311 $table->add_at (2, $row++, my $driver = new DC::UI::HBox expand => 1);
1312
1313 $driver->add (new DC::UI::Label align => 1, text => " Audio driver override");
1314 $driver->add (new DC::UI::Entry
1315 text => $CFG->{audio_driver},
1316 template => "dsound1234",
1317 tooltip => "You can override the audio driver to use here. Leaving it empty will result "
1318 . "in Deliantra picking one automatically. GNU/Linux users often prefer specific "
1319 . "drivers though, and can experiment with <b>alsa</b>, <b>dsp</b>, <b>esd</b>, <b>pulse</b>, <b>arts</b>, <b>nas</b> "
1320 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1321 . "in no sound.",
1322 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1323 );
1324
1325 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1326 $table->add_at (1, $row, new DC::UI::CheckBox
1327 expand => 1, state => $CFG->{effects_enable},
1328 tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
1329 on_changed => sub {
1330 $CFG->{effects_enable} = $_[1];
1331 $CONN->update_fx_want if $CONN;
1332 1
1333 }
1334 );
1335 $table->add_at (2, $row++, new DC::UI::Slider
1336 expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
1337 tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
1338 . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
1339 on_changed => sub { $CFG->{effects_volume} = $_[1]; 1 }
1340 );
1341
1342 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Background Music");
1343 $table->add_at (1, $row, new DC::UI::CheckBox
1344 expand => 1, state => $CFG->{bgm_enable},
1345 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played. Needs server reconnect to take effect.",
1346 on_changed => sub {
1347 $CFG->{bgm_enable} = $_[1];
1348 $CONN->update_fx_want if $CONN;
1349 audio_music_push;
1350 1
1351 }
1352 );
1353 $table->add_at (2, $row++, new DC::UI::Slider
1354 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
1355 tooltip => "The volume of the background music. Changes are instant.",
1356 on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
1357 );
1358
1359 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Frequency");
1360 $table->add_at (1, $row++, new DC::UI::Selector
1361 c_colspan => 2, expand => 1,
1362 value => $CFG->{audio_hw_frequency},
1363 options => [
1364 [ 0, "default" , "Use System Default"],
1365 [11025, "11 kHz" , "11kHz (low quality)"],
1366 [22050, "22 kHz" , "22kHz (reduced quality, recommended)"],
1367 [44100, "44.1 kHz", "44.1kHz (cd quality)"],
1368 [48000, "48 kHz" , "48kHz (studio quality, not recommended)"],
1369 ],
1370 tooltip => "The sampling frequency to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.",
1371 on_changed => sub {
1372 $CFG->{audio_hw_frequency} = $_[1];
1373 audio_tab_update;
1374 1
1375 }
1376 );
1377
1378 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Channels");
1379 $table->add_at (1, $row++, new DC::UI::Selector
1380 c_colspan => 2, expand => 1,
1381 value => $CFG->{audio_hw_channels},
1382 options => [
1383 [0, "default" , "Use System Default"],
1384 [1, "Mono" , "Mono (single channel, low quality)"],
1385 [2, "Stereo" , "Stereo (dual channel, standard quality)"],
1386 [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"],
1387 [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"],
1388 ],
1389 tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.",
1390 on_changed => sub {
1391 $CFG->{audio_hw_channels} = $_[1];
1392 audio_tab_update;
1393 1
1394 }
1395 );
1396
1397 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Latency");
1398 $table->add_at (1, $row++, $AUDIO_HW_CHUNKSIZE = new DC::UI::Selector
1399 c_colspan => 2, expand => 1,
1400 value => $CFG->{audio_hw_chunksize},
1401 tooltip => "The guarenteed latency. Lower is better, but also more cpu-intensive and might cause stuttering. If music playback "
1402 . "is stuttering, increase this value. Values of 50-150ms are optimal.",
1403 on_changed => sub {
1404 $CFG->{audio_hw_chunksize} = $_[1];
1405 audio_tab_update;
1406 1
1407 }
1408 );
1409
1410 # should really be a slider
1411 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Mixer Voices");
1412 $table->add_at (1, $row++, new DC::UI::ValSlider
1413 c_colspan => 2, expand => 1,
1414 tooltip => "The number of simultaneous sound effects possible. Higher is better, but also more cpu-intensive and might cause stuttering.",
1415 range => [$::CFG->{audio_mix_channels}, 4, 32, 0, 1],
1416 template => ">= 99",
1417 on_changed => sub {
1418 my ($slider, $value) = @_;
1419
1420 $CFG->{audio_mix_channels} = $value
1421 if $value;
1422 1;
1423 }
1424 );
1425
1426 $table->add_at (1, $row++, new DC::UI::Button
1427 c_colspan => 2, expand => 1, text => "Apply",
1428 tooltip => "Apply the audio settings",
1429 on_activate => sub {
1430 audio_shutdown ();
1431 audio_init ();
1432 0
1433 }
1434 );
1435
1436 $vbox->add (new DC::UI::FancyFrame
1437 expand => 1,
1438 label => "Audio Info",
1439 child => ($AUDIO_INFO = new DC::UI::Label ellipsise => 0),
1440 );
1441
1442 audio_tab_update;
1443
1444 $vbox
1445 }
1446
1447 sub set_gauge_window_fontsize {
1448 for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) {
1449 $_->set_fontsize ($::CFG->{gauge_fontsize});
1450 }
1451 }
1452
1453 sub make_gauge_window {
1454 my $gh = int $HEIGHT * $CFG->{gauge_size};
1455
1456 $GAUGES->{win} = my $win = new DC::UI::Frame (
1457 force_x => 0,
1458 force_y => "max",
1459 force_w => $WIDTH,
1460 force_h => $gh,
1461 );
1462
1463 $win->add (my $hbox = new DC::UI::HBox
1464 children => [
1465 (new DC::UI::HBox expand => 1),
1466 (new DC::UI::VBox children => [
1467 (new DC::UI::Empty expand => 1),
1468 (new DC::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new DC::UI::Table)),
1469 ]),
1470 (my $vbox = new DC::UI::VBox),
1471 ],
1472 );
1473
1474 $vbox->add (new DC::UI::HBox
1475 expand => 1,
1476 children => [
1477 (new DC::UI::Empty expand => 1),
1478 (my $hb = new DC::UI::HBox),
1479 ],
1480 );
1481
1482 $hb->add ($GAUGES->{hp} = new DC::UI::Gauge type => 'hp', tooltip => "#stat_health");
1483 $hb->add ($GAUGES->{mana} = new DC::UI::Gauge type => 'mana', tooltip => "#stat_mana");
1484 $hb->add ($GAUGES->{grace} = new DC::UI::Gauge type => 'grace', tooltip => "#stat_grace");
1485 $hb->add ($GAUGES->{food} = new DC::UI::Gauge type => 'food', tooltip => "#stat_food");
1486
1487 &set_gauge_window_fontsize;
1488
1489 $win
1490 }
1491
1492 our $BW_WATCHER;
1493
1494 sub debug_toggle($) {
1495 $DELIANTRA_DEBUG ^= $_[0];
1496
1497 if ($DELIANTRA_DEBUG & 16) {
1498 $BW_WATCHER = EV::periodic 0, 1, 0, sub {
1499 return unless $CONN;
1500 debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3;
1501 $CONN->{octets_in} = 0;
1502 };
1503 } else {
1504 undef $BW_WATCHER;
1505 }
1506
1507 }
1508
1509 sub debug_setup {
1510 my $table = new DC::UI::Table;
1511
1512 $table->add_at (0, 0, new DC::UI::Label text => "Widget Borders");
1513 $table->add_at (1, 0, new DC::UI::CheckBox on_changed => sub { debug_toggle 1; 0 });
1514 $table->add_at (0, 1, new DC::UI::Label text => "Tooltip Widget Info");
1515 $table->add_at (1, 1, new DC::UI::CheckBox on_changed => sub { debug_toggle 2; 0 });
1516 $table->add_at (0, 2, new DC::UI::Label text => "Show FPS");
1517 $table->add_at (1, 2, new DC::UI::CheckBox on_changed => sub { debug_toggle 4; 0 });
1518 $table->add_at (0, 3, new DC::UI::Label text => "Suppress Tooltips");
1519 $table->add_at (1, 3, new DC::UI::CheckBox on_changed => sub { debug_toggle 8; 0 });
1520 $table->add_at (0, 4, new DC::UI::Label text => "Show Bandwidth");
1521 $table->add_at (1, 4, new DC::UI::CheckBox on_changed => sub { debug_toggle 16; 0 });
1522
1523 $table->add_at (0, 6, new DC::UI::Button text => "die on click(tm)", on_activate => sub { &DC::debug() } );
1524 $table->add_at (0, 7, new DC::UI::TextEdit text => "line1\0152\0153\nµikachu\nづx゙つ゛");#d#
1525
1526 $table->add_at (7,7, my $t = new DC::UI::Table expand => 0);
1527 $t->add_at (0,0, new DC::UI::Label text => "a a", c_rowspan => 1, c_colspan => 2);
1528 $t->add_at (2,0, new DC::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1, ellipsise => 0 );
1529 $t->add_at (1,2, new DC::UI::Label text => "c c", c_rowspan => 1, c_colspan => 2);
1530 $t->add_at (0,1, new DC::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1, ellipsise => 0 );
1531 $t->add_at (1,1, new DC::UI::Label text => "e");
1532
1533 $table->add_at (7, 6, my $c = new DC::UI::Canvas);
1534
1535 $c->add_items ({
1536 type => "line_loop",
1537 color => [0, 1, 0],
1538 width => 9,
1539 coord_mode => "abs",
1540 coord => [[10, 5], [5, 50], [20, 5], [5, 60]],
1541 });
1542
1543 $c->add_items ({
1544 type => "lines",
1545 color => [1, 1, 0],
1546 width => 2,
1547 coord_mode => "rel",
1548 coord => [[0,0], [1,1], [1,0], [0,1]],
1549 });
1550
1551 $c->add_items ({
1552 type => "polygon",
1553 color => [0, 0.43, 0],
1554 width => 2,
1555 coord_mode => "rel",
1556 coord => [[0,0.2], [1,.4], [1,.6], [0,.8]],
1557 });
1558
1559 $table
1560 }
1561
1562 sub stats_window {
1563 my $r = new DC::UI::ScrolledWindow (
1564 expand => 1,
1565 scroll_y => 1
1566 );
1567 $r->add (my $vb = new DC::UI::VBox);
1568
1569 $vb->add (new DC::UI::FancyFrame
1570 label => "Player",
1571 child => (my $pi = new DC::UI::VBox),
1572 );
1573
1574 $pi->add ($STATWIDS->{title} = new DC::UI::Label text => "Title:", expand => 1, align => 0,
1575 can_hover => 1, can_events => 1,
1576 tooltip => "Your name and title. You can change your title by using the <b>title</b> command, if supported by the server.");
1577 $pi->add ($STATWIDS->{map} = new DC::UI::Label align => 0, text => "Map:", expand => 1,
1578 can_hover => 1, can_events => 1,
1579 tooltip => "The map you are currently on (if supported by the server).");
1580
1581 $pi->add (my $hb0 = new DC::UI::HBox);
1582 $hb0->add ($STATWIDS->{weight} = new DC::UI::Label text => "Weight:", expand => 1, align => 0,
1583 can_hover => 1, can_events => 1,
1584 tooltip => "The weight of the player including all inventory items.");
1585 $hb0->add ($STATWIDS->{m_weight} = new DC::UI::Label align => 0, text => "Max weight:", expand => 1,
1586 can_hover => 1, can_events => 1,
1587 tooltip => "The weight limit: you cannot carry more than this.");
1588
1589 $vb->add (new DC::UI::FancyFrame
1590 label => "Primary/Secondary Statistics",
1591 child => (my $hb = new DC::UI::HBox expand => 1),
1592 );
1593 $hb->add (my $tbl = new DC::UI::Table expand => 1);
1594
1595 my $color2 = [1, 1, 0];
1596
1597 for (
1598 [0, 0, st_str => "Str", 30],
1599 [0, 1, st_dex => "Dex", 30],
1600 [0, 2, st_con => "Con", 30],
1601 [0, 3, st_int => "Int", 30],
1602 [0, 4, st_wis => "Wis", 30],
1603 [0, 5, st_pow => "Pow", 30],
1604 [0, 6, st_cha => "Cha", 30],
1605
1606 [2, 0, st_wc => "Wc", -120],
1607 [2, 1, st_ac => "Ac", -120],
1608 [2, 2, st_dam => "Dam", 120],
1609 [2, 3, st_arm => "Arm", 120],
1610 [2, 4, st_spd => "Spd", 10.54],
1611 [2, 5, st_wspd => "WSp", 10.54],
1612 ) {
1613 my ($col, $row, $id, $label, $template) = @$_;
1614
1615 $tbl->add_at ($col , $row, $STATWIDS->{$id} = new DC::UI::Label
1616 font => $FONT_FIXED, can_hover => 1, can_events => 1,
1617 align => 1, template => $template, tooltip => "#stat_$label");
1618 $tbl->add_at ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new DC::UI::Label
1619 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2,
1620 align => 0, text => $label, tooltip => "#stat_$label");
1621 }
1622
1623 $vb->add (new DC::UI::FancyFrame
1624 label => "Resistancies",
1625 child => (my $tbl2 = new DC::UI::Table expand => 1, col_expand => [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]),
1626 );
1627
1628 my $row = 0;
1629 my $col = 0;
1630
1631 my %resist_names = (
1632 slow => ["Slow",
1633 "<b>Slow</b> (slows you down when you are hit by the spell. Monsters will have an opportunity to come near you faster and hit you more often.)"],
1634 holyw => ["Holy Word",
1635 "<b>Holy Word</b> (resistance you against getting the fear when someone whose god doesn't like you spells the holy word on you.)"],
1636 conf => ["Confusion",
1637 "<b>Confusion</b> (If you are hit by confusion you will move into random directions, and likely into monsters.)"],
1638 fire => ["Fire",
1639 "<b>Fire</b> (just your resistance to fire spells like burning hands, dragonbreath, meteor swarm fire, ...)"],
1640 depl => ["Depletion",
1641 "<b>Depletion</b> (some monsters and other effects can cause stats depletion)"],
1642 magic => ["Magic",
1643 "<b>Magic</b> (resistance to magic spells like magic missile or similar)"],
1644 drain => ["Draining",
1645 "<b>Draining</b> (some monsters (e.g. vampires) and other effects can steal experience)"],
1646 acid => ["Acid",
1647 "<b>Acid</b> (resistance to acid, acid hurts pretty much and also corrodes your weapons)"],
1648 pois => ["Poison",
1649 "<b>Poison</b> (resistance to getting poisoned)"],
1650 para => ["Paralysation",
1651 "<b>Paralysation</b> (this resistance affects the chance you get paralysed)"],
1652 deat => ["Death",
1653 "<b>Death</b> (resistance against death spells)"],
1654 phys => ["Physical",
1655 "<b>Physical</b> (this is the resistance against physical attacks, like when a monster hit you in melee combat. The value displayed here is also displayed as the 'Arm' secondary stat.)"],
1656 blind => ["Blind",
1657 "<b>Blind</b> (blind resistance affects the chance of a successful blinding attack)"],
1658 fear => ["Fear",
1659 "<b>Fear</b> (this attack will drive you away from monsters who cast this and hit you successfully, being resistant to this helps a lot when fighting those monsters)"],
1660 tund => ["Turn undead",
1661 "<b>Turn undead</b> (affects your resistancy to various forms of 'turn undead' spells. Only relevant when you are, in fact, undead..."],
1662 elec => ["Electricity",
1663 "<b>Electricity</b> (resistance against electricity, spells like large lightning, small lightning, ...)"],
1664 cold => ["Cold",
1665 "<b>Cold</b> (this is your resistance against cold spells like icestorm, snowstorm, ...)"],
1666 ghit => ["Ghost hit",
1667 "<b>Ghost hit</b> (special attack used by ghosts and ghost-like beings)"],
1668 );
1669
1670 for (qw/slow holyw conf fire depl magic
1671 drain acid pois para deat phys
1672 blind fear tund elec cold ghit/)
1673 {
1674 $tbl2->add_at ($col + 2, $row,
1675 $STATWIDS->{"res_$_"} =
1676 new DC::UI::Label
1677 font => $FONT_FIXED,
1678 template => "-100%",
1679 align => 1,
1680 can_events => 1,
1681 can_hover => 1,
1682 tooltip => $resist_names{$_}->[1],
1683 );
1684 $tbl2->add_at ($col + 1, $row, new DC::UI::Image
1685 font => $FONT_FIXED,
1686 can_hover => 1,
1687 can_events => 1,
1688 path => "ui/resist/resist_$_.png",
1689 tooltip => $resist_names{$_}->[1],
1690 );
1691 $tbl2->add_at ($col + 0, $row, new DC::UI::Label
1692 text => $resist_names{$_}->[0],
1693 font => $FONT_FIXED,
1694 align => 1,
1695 can_hover => 1,
1696 can_events => 1,
1697 tooltip => $resist_names{$_}->[1],
1698 );
1699
1700 $row++;
1701 if ($row % 6 == 0) {
1702 $col += 4;
1703 $row = 0;
1704 }
1705 }
1706
1707 #update_stats_window ({});
1708
1709 $r
1710 }
1711
1712 sub skill_window {
1713 my $sw = new DC::UI::ScrolledWindow (expand => 1);
1714
1715 $sw->add ($STATWIDS->{skill_tbl} = new DC::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1716
1717 $sw
1718 }
1719
1720 sub formsep($) {
1721 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1722 }
1723
1724 my $METASERVER_ATIME;
1725
1726 sub update_metaserver {
1727 my ($metaserver_dialog) = @_;
1728
1729 $METASERVER = $metaserver_dialog
1730 if defined $metaserver_dialog;
1731
1732 return if $METASERVER_ATIME > time;
1733 $METASERVER_ATIME = time + 60;
1734
1735 my $table = $METASERVER->{table};
1736 $table->clear;
1737 $table->add_at (0, 0, my $label = new DC::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
1738
1739 my $ok = 0;
1740
1741 DC::background {
1742 my $ua = DC::lwp_useragent;
1743
1744 DC::background_msg DC::decode_json +(DC::lwp_check $ua->get ($META_SERVER))->decoded_content;
1745 } sub {
1746 my ($msg) = @_;
1747 if ($msg) {
1748 $table->clear;
1749
1750 my @tip = (
1751 "The current number of users logged in on the server.",
1752 "The hostname of the server.",
1753 "The time this server has been running without being restarted.",
1754 "Short information about this server provided by its admins.",
1755 );
1756 my @col = qw(#Users Host Uptime Version Description);
1757 $table->add_at ($_, 0, new DC::UI::Label
1758 can_hover => 1, can_events => 1, fg => [1, 1, 0],
1759 text => $col[$_], tooltip => $tip[$_])
1760 for 0 .. $#col;
1761
1762 my @align = qw(1 0.5 1 1 0);
1763
1764 my $y = 0;
1765 for my $m (@{ $msg->{servers} }) {
1766 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime, $highlight) =
1767 @$m{qw(ip age hostname users version description ibytes obytes uptime highlight)};
1768
1769 for ($desc) {
1770 s/<br>/\n/gi;
1771 s/<li>/\n· /gi;
1772 s/<.*?>//sgi;
1773 s/&amp;/&/g;
1774 s/&lt;/</g;
1775 s/&gt;/>/g;
1776 }
1777
1778 $uptime = sprintf "%dd %02d:%02d:%02d",
1779 (int $uptime / 86400),
1780 (int $uptime / 3600) % 24,
1781 (int $uptime / 60) % 60,
1782 $uptime % 60;
1783
1784 $m = [$users, $host, $uptime, $version, $desc];
1785
1786 $y++;
1787
1788 $table->add_at (scalar @$m, $y, new DC::UI::VBox children => [
1789 (new DC::UI::Button
1790 text => "Use",
1791 tooltip => "Put this server into the <b>Host:Port</b> field",
1792 on_activate => sub {
1793 $HOST_ENTRY->set_text ($CFG->{profile}{default}{host} = $host);
1794 $METASERVER->hide;
1795 0
1796 },
1797 ),
1798 (new DC::UI::Empty expand => 1),
1799 ]);
1800
1801 $table->add_at ($_, $y, new DC::UI::Label
1802 max_w => $::WIDTH * 0.4,
1803 ellipsise => 0,
1804 align => $align[$_],
1805 text => $m->[$_],
1806 tooltip => $tip[$_],
1807 fg => ($highlight ? [1, 1, 1] : [.7, .7, .7]),
1808 can_hover => 1,
1809 can_events => 1,
1810 fontsize => 0.8)
1811 for 0 .. $#$m;
1812 }
1813 } else {
1814 $ok or $label->set_text ("error while contacting metaserver");
1815 }
1816 };
1817
1818 }
1819
1820 sub metaserver_dialog {
1821 my $vbox = new DC::UI::VBox;
1822 my $table = new DC::UI::Table;
1823 $vbox->add (new DC::UI::ScrolledWindow expand => 1, child => $table);
1824
1825 my $dialog = new DC::UI::Toplevel
1826 title => "Server List",
1827 name => 'metaserver_dialog',
1828 x => 'center',
1829 y => 'center',
1830 z => 3,
1831 force_w => $::WIDTH * 0.9,
1832 force_h => $::HEIGHT * 0.7,
1833 child => $vbox,
1834 has_close_button => 1,
1835 table => $table,
1836 on_visibility_change => sub {
1837 update_metaserver ($_[0]) if $_[1];
1838 0
1839 },
1840 ;
1841
1842 $dialog
1843 }
1844
1845 sub login_setup {
1846 my $vbox = new DC::UI::VBox;
1847
1848 $vbox->add (new DC::UI::FancyFrame
1849 label => "Login Settings",
1850 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
1851 );
1852
1853 $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username");
1854 $table->add_at (1, 4, new DC::UI::Entry
1855 text => $PROFILE->{user},
1856 tooltip => "The name of your character on the server. The name is case-sensitive!",
1857 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1858 );
1859
1860 $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password");
1861 $table->add_at (1, 5, new DC::UI::Entry
1862 text => $PROFILE->{password},
1863 hidden => 1,
1864 tooltip => "The password for your character.",
1865 on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 }
1866 );
1867
1868 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button
1869 expand => 1,
1870 text => "Login / Register",
1871 tooltip => "This button will either login to the account configured above or register a new account.",
1872 on_activate => sub {
1873 $CONN ? stop_game
1874 : start_game;
1875 1
1876 },
1877 );
1878
1879 $vbox->add (new DC::UI::FancyFrame
1880 label => "How to Play",
1881 min_h => 240,
1882 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1883 markup =>
1884 "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n"
1885 . "Then register a new account (or use an existing one if you have one). "
1886 . "To register an account, choose a username that hasn't been taken yet (just guess) and "
1887 . "try to log-in. Follow the instructions in the Log tab in the message window.",
1888 ),
1889 );
1890
1891 $vbox
1892 }
1893
1894 sub server_setup {
1895 my $vbox = new DC::UI::VBox;
1896
1897 $vbox->add (new DC::UI::FancyFrame
1898 label => "Connection Settings",
1899 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
1900 );
1901
1902 my $row = 0;
1903
1904 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Host:Port");
1905 {
1906 $table->add_at (1, $row, my $vbox = new DC::UI::VBox);
1907
1908 $vbox->add (
1909 $HOST_ENTRY = new DC::UI::Entry
1910 expand => 1,
1911 text => $PROFILE->{host},
1912 tooltip => "The hostname or ip address of the Deliantra server to connect to (e.g. <b>gameserver.deliantra.net</b>)",
1913 on_changed => sub {
1914 my ($self, $value) = @_;
1915 $PROFILE->{host} = $value;
1916 1
1917 }
1918 );
1919
1920 if (0) { #d# disabled
1921 $vbox->add (new DC::UI::Button
1922 expand => 1,
1923 text => "Server List",
1924 other => $METASERVER,
1925 tooltip => "Show a list of available Deliantra servers",
1926 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1927 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1928 );
1929 }#d#
1930 }
1931
1932 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Map Size");
1933 $table->add_at (1, $row, new DC::UI::Slider
1934 force_w => 100,
1935 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1936 tooltip => "This is the size of the portion of the map update the server sends you. "
1937 . "If you set this to a high value you will be able to see further, "
1938 . "but you also increase bandwidth requirements and latency. "
1939 . "This option is only used once at log-in.",
1940 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1941 );
1942
1943 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate");
1944 $table->add_at (1, $row, new DC::UI::Entry
1945 text => $CFG->{output_rate},
1946 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1947 . "when sending data. When 0 or unset, the server "
1948 . "default will be used, which is usually around 100kb/s. Most servers will "
1949 . "dynamically find an optimal rate, so adjust this only when necessary.",
1950 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1951 );
1952
1953 $vbox->add (new DC::UI::FancyFrame
1954 label => "Server Info",
1955 child => ($SERVER_INFO = new DC::UI::Label ellipsise => 0),
1956 );
1957
1958 $vbox
1959 }
1960
1961 sub client_setup {
1962 my $vbox = new DC::UI::VBox;
1963
1964 $vbox->add (my $top = new DC::UI::FancyFrame expand => 1, label => "Client Settings");
1965 $vbox->add (my $bot = new DC::UI::FancyFrame expand => 1, label => "Client Info");
1966
1967 {
1968 $top->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
1969
1970 my $row = 0;
1971
1972 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day");
1973 $table->add_at (1, $row++, new DC::UI::CheckBox
1974 c_colspan => 2,
1975 state => $CFG->{show_tips},
1976 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1977 on_changed => sub {
1978 my ($self, $value) = @_;
1979 $CFG->{show_tips} = $value;
1980 0
1981 }
1982 );
1983
1984 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size");
1985 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1986 c_colspan => 2,
1987 text => $CFG->{logview_max_par},
1988 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server "
1989 . "sends more messages than this number, older messages get removed to save memory and "
1990 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1991 on_changed => sub {
1992 my ($self, $value) = @_;
1993 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1994 0
1995 },
1996 );
1997
1998 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave");
1999 $table->add_at (1, $row, new DC::UI::CheckBox
2000 state => $CFG->{config_autosave},
2001 tooltip => "Normally, configuration settings and the user interface layout "
2002 . "are saved on client exit. You can disable this behaviour by "
2003 . "unchecking this checkbox.",
2004 on_changed => sub {
2005 my ($self, $value) = @_;
2006 $CFG->{config_autosave} = $value;
2007 0
2008 }
2009 );
2010 $table->add_at (2, $row++, new DC::UI::Button
2011 text => "Save Now",
2012 tooltip => "Use this to manually save configuration and UI layout when "
2013 . "autosave is disabled.",
2014 on_activate => sub {
2015 DC::write_cfg;
2016 0
2017 }
2018 );
2019 }
2020
2021 {
2022 $bot->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
2023
2024 my $row = 0;
2025
2026 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
2027 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
2028 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
2029 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2030 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2031 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
2032 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
2034 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
2036 }
2037
2038 $vbox
2039 }
2040
2041 sub autopickup_setup {
2042 my $r = new DC::UI::ScrolledWindow (
2043 expand => 1,
2044 scroll_y => 1
2045 );
2046 $r->add (my $table = new DC::UI::Table
2047 row_expand => [0],
2048 col_expand => [0, 1, 0, 1],
2049 );
2050
2051 for (
2052 ["General", 0, 0,
2053 # ["Inhibit autopickup" => PICKUP_INHIBIT],
2054 ["Stop before pickup" => PICKUP_STOP],
2055 ["Debug autopickup" => PICKUP_DEBUG],
2056 ],
2057 ["Weapons", 0, 6,
2058 ["All weapons" => PICKUP_ALLWEAPON],
2059 ["Missile weapons" => PICKUP_MISSILEWEAPON],
2060 ["Bows" => PICKUP_BOW],
2061 ["Arrows" => PICKUP_ARROW],
2062 ],
2063 ["Armour", 0, 12,
2064 ["Helmets" => PICKUP_HELMET],
2065 ["Shields" => PICKUP_SHIELD],
2066 ["Body Armour" => PICKUP_ARMOUR],
2067 ["Boots" => PICKUP_BOOTS],
2068 ["Gloves" => PICKUP_GLOVES],
2069 ["Cloaks" => PICKUP_CLOAK],
2070 ],
2071
2072 ["Readables", 2, 0,
2073 ["Spellbooks" => PICKUP_SPELLBOOK],
2074 ["Skillscrolls" => PICKUP_SKILLSCROLL],
2075 ["Normal Books/Scrolls" => PICKUP_READABLES],
2076 ],
2077 ["Misc", 2, 5,
2078 ["Food" => PICKUP_FOOD],
2079 ["Drinks" => PICKUP_DRINK],
2080 ["Valuables (Money, Gems)" => PICKUP_VALUABLES],
2081 ["Keys" => PICKUP_KEY],
2082 ["Magical Items" => PICKUP_MAGICAL],
2083 ["Potions" => PICKUP_POTION],
2084 ["Magic Devices" => PICKUP_MAGIC_DEVICE],
2085 ["Ignore cursed" => PICKUP_NOT_CURSED],
2086 ["Jewelery" => PICKUP_JEWELS],
2087 ["Flesh" => PICKUP_FLESH],
2088 ],
2089 ["Value/Weight ratio", 2, 17]
2090 )
2091 {
2092 my ($title, $x, $y, @bits) = @$_;
2093 $table->add_at ($x, $y, new DC::UI::Label text => $title, align => 1, fg => [1, 1, 0]);
2094
2095 for (@bits) {
2096 ++$y;
2097
2098 my $mask = $_->[1];
2099 $table->add_at ($x , $y, new DC::UI::Label text => $_->[0], align => 1, expand => 1);
2100 $table->add_at ($x+1, $y, my $checkbox = new DC::UI::CheckBox
2101 state => $::CFG->{pickup} & $mask,
2102 on_changed => sub {
2103 my ($box, $value) = @_;
2104
2105 if ($value) {
2106 $::CFG->{pickup} |= $mask;
2107 } else {
2108 $::CFG->{pickup} &= ~$mask;
2109 }
2110
2111 $::CONN->send_pickup ($::CFG->{pickup})
2112 if defined $::CONN;
2113
2114 0
2115 });
2116
2117 ${$_->[2]} = $checkbox if $_->[2];
2118 }
2119 }
2120
2121 $table->add_at (2, 18, new DC::UI::ValSlider
2122 range => [$::CFG->{pickup} & 0xF, 0, 16, 1, 1],
2123 template => ">= 99",
2124 tooltip => "Pick up items whose value/weight (silver/kg) ratio is equal or higher than this setting (which is specified in gold coins).",
2125 to_value => sub { ">= " . 5 * $_[0] },
2126 on_changed => sub {
2127 my ($slider, $value) = @_;
2128
2129 $::CFG->{pickup} &= ~0xF;
2130 $::CFG->{pickup} |= int $value
2131 if $value;
2132 1;
2133 });
2134
2135 $table->add_at (3, 18, new DC::UI::Button
2136 text => "set",
2137 on_activate => sub {
2138 $::CONN->send_pickup ($::CFG->{pickup})
2139 if defined $::CONN;
2140 0
2141 });
2142
2143 $r
2144 }
2145
2146 my %SORT_ORDER = (
2147 type => sub {
2148 use sort 'stable';
2149 sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
2150 },
2151 mtime => sub {
2152 use sort 'stable';
2153 my $NOW = time;
2154 sort {
2155 my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6;
2156 my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
2157
2158 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED)
2159 or $btime <=> $atime
2160 or $a->{type} <=> $b->{type}
2161 } @_
2162 },
2163 weight => sub {
2164 use sort 'stable';
2165 sort {
2166 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
2167 or $a->{type} <=> $b->{type}
2168 } @_
2169 },
2170 );
2171
2172 sub inventory_widget {
2173 my $hb = new DC::UI::HBox homogeneous => 1;
2174
2175 $hb->add (my $vb1 = new DC::UI::VBox);
2176 $vb1->add (new DC::UI::Label text => "Player");
2177
2178 $vb1->add (my $hb1 = new DC::UI::HBox);
2179
2180 use sort 'stable';
2181
2182 $hb1->add (new DC::UI::Selector
2183 value => $::CFG->{inv_sort},
2184 options => [
2185 [type => "Type/Name"],
2186 [mtime => "Recent/Normal/Locked"],
2187 [weight => "Weight/Type"],
2188 ],
2189 on_changed => sub {
2190 $::CFG->{inv_sort} = $_[1];
2191 $INV->set_sort_order ($SORT_ORDER{$_[1]});
2192 },
2193 );
2194 $hb1->add (new DC::UI::Label text => "Weight: ", align => 1, expand => 1);
2195 #TODO# update to weight/maxweight
2196 $hb1->add ($STATWIDS->{i_weight} = new DC::UI::Label align => 0);
2197
2198 $vb1->add (my $sw1 = new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2199 $sw1->add ($INV = new DC::UI::Inventory);
2200 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
2201
2202 $hb->add (my $vb2 = new DC::UI::VBox);
2203
2204 $vb2->add ($INVR_HB = new DC::UI::HBox);
2205
2206 $vb2->add (my $sw2 = new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2207 $sw2->add ($INVR = new DC::UI::Inventory);
2208
2209 # XXX: Call after $INVR = ... because set_opencont sets the items
2210 DC::Protocol::set_opencont ($::CONN, 0, "Floor");
2211
2212 $hb
2213 }
2214
2215 sub media_window {
2216 my $vb = new DC::UI::VBox;
2217
2218 $vb->add (new DC::UI::FancyFrame
2219 label => "Current background music",
2220 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2221 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2222 );
2223
2224 $vb->add (new DC::UI::FancyFrame
2225 label => "Current downloads",
2226 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2227 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2228 );
2229
2230 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2231 my ($self) = @_;
2232
2233 delete $self->{updater};
2234 return unless $_[1];
2235
2236 $self->{updater} = AE::timer 0, 0.7, sub {
2237 $self->clear;
2238
2239 return unless $CONN;
2240
2241 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2242 return unless @nums;
2243
2244 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2245 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2246
2247 for my $row (0 .. $#nums) {
2248 my $num = $nums[$row];
2249
2250 my $total = length $CONN->{ix_recv_buf}{$num};
2251 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2252
2253 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2254 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2255 }
2256 };
2257 });
2258
2259 $vb->add (new DC::UI::FancyFrame
2260 label => "Other media used in this session",
2261 expand => 1,
2262 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2263 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2264 );
2265
2266 $vb
2267 }
2268
2269 sub add_license {
2270 my ($meta) = @_;
2271
2272 $meta = $meta->{data}
2273 or return;
2274
2275 $meta->{license} || $meta->{author} || $meta->{source}
2276 or return;
2277
2278 $LICENSE_WIDGET->add_paragraph ({
2279 fg => [1, 1, 1, 1],
2280 markup => "<small>"
2281 . "<b>Name:</b> " . (DC::asxml $meta->{name}) . "\n"
2282 . "<b>Author:</b> " . (DC::asxml $meta->{author}) . "\n"
2283 . "<b>Source:</b> " . (DC::asxml $meta->{source}) . "\n"
2284 . "<b>License:</b> " . (DC::asxml $meta->{license}) . "\n"
2285 . "</small>",
2286 });
2287 $LICENSE_WIDGET->scroll_to_bottom;
2288 }
2289
2290 sub toggle_player_page {
2291 my ($widget) = @_;
2292
2293 if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) {
2294 $PL_WINDOW->hide;
2295 } else {
2296 $PL_NOTEBOOK->set_current_page ($widget);
2297 $PL_WINDOW->show;
2298 }
2299 }
2300
2301 sub make_playerbook {
2302 my $plwin = $PL_WINDOW = new DC::UI::Toplevel
2303 x => "center",
2304 y => "center",
2305 force_w => $WIDTH * 9/10,
2306 force_h => $HEIGHT * 9/10,
2307 title => "Player",
2308 name => "playerbook",
2309 has_close_button => 1
2310 ;
2311
2312 my $ntb =
2313 $PL_NOTEBOOK =
2314 new DC::UI::Notebook expand => 1;
2315
2316 $ntb->add_tab (
2317 "Statistics (F2)" => $STATS_PAGE = stats_window,
2318 "Shows statistics, where all your Stats and Resistances are shown."
2319 );
2320 $ntb->add_tab (
2321 "Skills (F3)" => $SKILL_PAGE = skill_window,
2322 "Shows all your Skills."
2323 );
2324
2325 my $spellsw = $SPELL_PAGE = new DC::UI::ScrolledWindow (expand => 1, scroll_y => 1);
2326 $spellsw->add ($SPELL_LIST = new DC::UI::SpellList);
2327 $ntb->add_tab (
2328 "Spellbook (F4)" => $spellsw,
2329 "Displays all spells you have and lets you edit keyboard shortcuts for them."
2330 );
2331 $ntb->add_tab (
2332 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
2333 "Toggles the inventory window, where you can manage your loot (or treasures :). "
2334 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
2335 );
2336 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
2337 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
2338
2339 $ntb->add_tab (Media => media_window,
2340 "License, Author and Source info for media sent by the server.");
2341
2342 $ntb->set_current_page ($INVENTORY_PAGE);
2343
2344 $plwin->add ($ntb);
2345 }
2346
2347 sub keyboard_setup {
2348 DC::Macro::keyboard_setup
2349 }
2350
2351 sub make_help_window {
2352 my $win = new DC::UI::Toplevel
2353 x => 'center',
2354 y => 'center',
2355 z => 4,
2356 name => 'doc_browser',
2357 force_w => int $WIDTH * 7/8,
2358 force_h => int $HEIGHT * 7/8,
2359 title => "Help Browser",
2360 has_close_button => 1;
2361
2362 $win->add (my $vbox = new DC::UI::VBox);
2363
2364 $vbox->add (new DC::UI::FancyFrame
2365 label => "Navigation",
2366 child => (my $buttons = new DC::UI::HBox),
2367 );
2368 $vbox->add (my $viewer = new DC::UI::TextScroller
2369 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
2370
2371 my @history;
2372 my @future;
2373 my $curnode;
2374
2375 my $load_node; $load_node = sub {
2376 my ($node, $para) = @_;
2377
2378 $buttons->clear;
2379
2380 $buttons->add (new DC::UI::Button
2381 text => "⇤",
2382 tooltip => "back to the starting page",
2383 on_activate => sub {
2384 unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
2385 unshift @future, @history;
2386 @history = ();
2387 $load_node->(@{shift @future});
2388 },
2389 );
2390
2391 if (@history) {
2392 $buttons->add (new DC::UI::Button
2393 text => "⋘",
2394 tooltip => "back to <i>" . (DC::asxml DC::Pod::full_path $history[-1][0]) . "</i>",
2395 on_activate => sub {
2396 unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
2397 $load_node->(@{pop @history});
2398 },
2399 );
2400 }
2401
2402 if (@future) {
2403 $buttons->add (new DC::UI::Button
2404 text => "⋙",
2405 tooltip => "forward to <i>" . (DC::asxml DC::Pod::full_path $future[0][0]) . "</i>",
2406 on_activate => sub {
2407 push @history, [$curnode, $viewer->current_paragraph];
2408 $load_node->(@{shift @future});
2409 },
2410 );
2411 }
2412
2413 $buttons->add (new DC::UI::Label text => " ");
2414
2415 my @path = DC::Pod::full_path_of $node;
2416 pop @path; # drop current node
2417
2418 for my $node (@path) {
2419 $buttons->add (new DC::UI::Button
2420 text => $node->[DC::Pod::N_KW][0],
2421 tooltip => "go to <i>" . (DC::asxml DC::Pod::full_path $node) . "</i>",
2422 on_activate => sub {
2423 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
2424 $load_node->($node);
2425 },
2426 );
2427 $buttons->add (new DC::UI::Label text => "/");
2428 }
2429
2430 $buttons->add (new DC::UI::Label text => $node->[DC::Pod::N_KW][0], padding_x => 4, padding_y => 4);
2431
2432 $curnode = $node;
2433
2434 $viewer->clear;
2435 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $curnode);
2436 $viewer->scroll_to ($para);
2437 };
2438
2439 $load_node->(DC::Pod::find pod => "mainpage");
2440
2441 $DC::Pod::goto_document = sub {
2442 my (@path) = @_;
2443
2444 push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
2445
2446 $load_node->((DC::Pod::find @path)[0]);
2447 $win->show;
2448 };
2449
2450 $HELP_WINDOW = $win;
2451 }
2452
2453 sub open_quit_dialog {
2454 unless ($QUIT_DIALOG) {
2455 $QUIT_DIALOG = new DC::UI::Toplevel
2456 x => "center",
2457 y => "center",
2458 z => 50,
2459 title => "Really Quit?",
2460 on_key_down => sub {
2461 my ($dialog, $ev) = @_;
2462 $ev->{sym} == 27 and $dialog->hide;
2463 }
2464 ;
2465
2466 $QUIT_DIALOG->add (my $vb = new DC::UI::VBox expand => 1);
2467
2468 $vb->add (new DC::UI::Label
2469 text => "You should find a savebed and apply it first!",
2470 max_w => $WIDTH * 0.25,
2471 ellipsize => 0,
2472 );
2473 $vb->add (my $hb = new DC::UI::HBox expand => 1);
2474 $hb->add (new DC::UI::Button
2475 text => "Ok",
2476 expand => 1,
2477 on_activate => sub { $QUIT_DIALOG->hide; 0 },
2478 );
2479 $hb->add (new DC::UI::Button
2480 text => "Quit anyway",
2481 expand => 1,
2482 on_activate => sub {
2483 crash "Quit anyway";
2484 EV::break EV::BREAK_ALL;
2485 },
2486 );
2487 }
2488
2489 $QUIT_DIALOG->show;
2490 $QUIT_DIALOG->grab_focus;
2491 }
2492
2493 sub make_menubar {
2494 $MENUFRAME = new DC::UI::Toplevel
2495 border => 0,
2496 force_x => 0,
2497 force_y => 0,
2498 force_w => $::WIDTH,
2499 child => ($MENUBAR = new DC::UI::HBox),
2500 ;
2501
2502 $MENUBAR->add ($BUTTONBAR = new DC::UI::Buttonbar);
2503
2504 # XXX: this has to be done before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
2505 make_gauge_window->show;
2506
2507 # $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
2508 # tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
2509
2510 make_playerbook;
2511
2512 $MENUPOPUP = DC::UI::Menu->new (items => [
2513 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2514 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2515 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2516 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2517 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2518 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2519 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2520 ["Quit…" , sub {
2521 if ($CONN) {
2522 open_quit_dialog;
2523 } else {
2524 EV::unloop EV::UNLOOP_ALL;
2525 }
2526 }],
2527 ]);
2528
2529 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2530 tooltip => "Shows the main menu",
2531 on_button_down => sub {
2532 my ($self, $ev) = @_;
2533 local $ev->{x} = 0;
2534 local $ev->{y} = 0;
2535 $MENUPOPUP->popup ($ev);
2536 },
2537 );
2538
2539 $MENUBAR->add ($GAUGES->{exp} = new DC::UI::ExperienceProgress
2540 padding_x => 6,
2541 padding_y => 3,
2542 tooltip => "This progress bar shows your overall experience and your progress towards the next character level.",
2543 template => " Exp: 888,888,888,888 (lvl 188) ",
2544 );
2545
2546 $MENUBAR->add ($PICKUP_ENABLE = new DC::UI::CheckBox # checkbox bad, button better?
2547 tooltip => "Automatic Pickup Enable - when this checkbox is enabled, then your character "
2548 . "will automatically pick up items as defined by your item pickup settings "
2549 . "in the playerbook. Often (e.g. in apartments) you want to temporarily "
2550 . "disable autopickup by disabling this checkbox.",
2551 state => $CFG->{pickup} & PICKUP_INHIBIT ? 0 : 1,
2552 on_changed => sub {
2553 my ($self, $value) = @_;
2554 $CFG->{pickup} &= ~PICKUP_INHIBIT;
2555 $CFG->{pickup} |= PICKUP_INHIBIT unless $_[1];
2556 $CONN->send_pickup ($CFG->{pickup})
2557 if $CONN;
2558 },
2559 );
2560
2561 $MENUBAR->add ($GAUGES->{skillexp} = new DC::UI::ExperienceProgress
2562 c_rescale => 1,
2563 padding_x => 6,
2564 padding_y => 3,
2565 force_w => $::WIDTH * 0.2,
2566 tooltip => "This progress bar shows the currently used skill and your progress towards the next skill level of that skill.",
2567 template => "two handed weapons 99%",
2568 );
2569
2570 $MENUBAR->add ($GAUGES->{range} = new DC::UI::Label
2571 expand => 1,
2572 align => 1, can_hover => 1, can_events => 1,
2573 text => "Range and Combat Slots",
2574 tooltip => "#stat_ranged",
2575 );
2576
2577 $MENUFRAME->show;
2578 }
2579
2580 sub open_string_query {
2581 my ($title, $cb, $txt, $tooltip) = @_;
2582 my $dialog = new DC::UI::Toplevel
2583 x => "center",
2584 y => "center",
2585 z => 50,
2586 force_w => $WIDTH * 4/5,
2587 title => $title;
2588
2589 $dialog->add (
2590 my $e = new DC::UI::Entry
2591 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
2592 on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
2593 tooltip => $tooltip
2594 );
2595
2596 $e->grab_focus;
2597 $e->set_text ($txt) if $txt;
2598 $dialog->show;
2599 }
2600
2601 sub show_tip_of_the_day {
2602 # find all tips
2603 my @tod = DC::Pod::find tip_of_the_day => "*";
2604
2605 DC::DB::get state => "tip_of_the_day", sub {
2606 my ($todindex) = @_;
2607 $todindex = 0 if $todindex >= @tod;
2608 DC::DB::put state => tip_of_the_day => $todindex + 1, sub { };
2609
2610 # create dialog
2611 my $dialog;
2612
2613 my $close = sub {
2614 $dialog->destroy;
2615 };
2616
2617 $dialog = new DC::UI::Toplevel
2618 x => "center",
2619 y => "center",
2620 z => 3,
2621 name => 'tip_of_the_day',
2622 force_w => int $WIDTH * 4/9,
2623 force_h => int $WIDTH * 2/9,
2624 title => "Tip of the day #" . (1 + $todindex),
2625 child => my $vbox = new DC::UI::VBox,
2626 has_close_button => 1,
2627 on_delete => $close,
2628 ;
2629
2630 $vbox->add (my $viewer = new DC::UI::TextScroller
2631 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
2632 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $tod[$todindex]);
2633
2634 $vbox->add (my $table = new DC::UI::Table col_expand => [0, 1]);
2635
2636 $table->add_at (0, 0, new DC::UI::Button
2637 text => "Close",
2638 tooltip => "Close the tip of the day window. To never see it again, disable the tip of the day in the <b>Server Setup</b>.",
2639 on_activate => $close,
2640 );
2641
2642 $table->add_at (2, 0, new DC::UI::Button
2643 text => "Next",
2644 tooltip => "Show the next <b>Tip of the day</b>.",
2645 on_activate => sub {
2646 $close->();
2647 &show_tip_of_the_day;
2648 },
2649 );
2650
2651 $dialog->show;
2652 };
2653 }
2654
2655 sub video_init {
2656 DC::set_theme $CFG->{uitheme};
2657
2658 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2659 $SDL_REINIT = 0;
2660
2661 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8;
2662 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2663 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2664 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2665
2666 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2667
2668 if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) {
2669 $CFG->{sdl_mode} = 0; # lowest resolution by default
2670
2671 # now choose biggest mode <= 1024x768
2672 for (0 .. $#SDL_MODES) {
2673 if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) {
2674 $CFG->{sdl_mode} = $_;
2675 }
2676 }
2677 }
2678
2679 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2680
2681 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2682 $FULLSCREEN = $CFG->{fullscreen};
2683 $FAST = $CFG->{fast};
2684
2685 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error
2686 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2687 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2688 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2689
2690 $SDL_ACTIVE = 1;
2691 $LAST_REFRESH = time - 0.01;
2692
2693 DC::OpenGL::init;
2694 DC::Macro::init;
2695
2696 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
2697
2698 $DC::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
2699
2700 #############################################################################
2701
2702 if ($DEBUG_STATUS) {
2703 DC::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
2704 } else {
2705 # create/configure the widgets
2706
2707 $DC::UI::ROOT->connect (key_down => sub {
2708 my (undef, $ev) = @_;
2709
2710 if (my @macros = DC::Macro::find $ev) {
2711 DC::Macro::execute $_ for @macros;
2712
2713 return 1;
2714 }
2715
2716 0
2717 });
2718
2719 $DEBUG_STATUS = new DC::UI::Label
2720 padding => 0,
2721 z => 100,
2722 force_x => "max",
2723 force_y => 20;
2724 $DEBUG_STATUS->show;
2725
2726 $STATUSBOX = new DC::UI::Statusbox;
2727
2728 $MODBOX = new DC::UI::Label
2729 can_events => 1,
2730 can_hover => 1,
2731 markup => "",
2732 align => 0,
2733 font => $FONT_FIXED,
2734 tooltip => "#modifier_box",
2735 tooltip_width => 0.67,
2736 ;
2737
2738 update_modbox;
2739
2740 (new DC::UI::Frame
2741 bg => [0, 0, 0, 0.4],
2742 force_x => 0,
2743 force_y => "max",
2744 child => (my $LL = new DC::UI::VBox),
2745 )->show;
2746
2747 $LL->add ($STATUSBOX);
2748 $LL->add ($MODBOX);
2749 $LL->add (new DC::UI::Label
2750 align => 0,
2751 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode",
2752 fontsize => 0.5,
2753 fg => [1, 1, 0, 0.7],
2754 );
2755
2756 DC::UI::Toplevel->new (
2757 title => "Minimap",
2758 name => "mapmap",
2759 x => 0,
2760 y => $::FONTSIZE + 8,#d# hack to move messages window below the menubar
2761 border_bg => [1, 1, 1, 192/255],
2762 bg => [1, 1, 1, 0],
2763 child => ($MAPMAP = new DC::MapWidget::MapMap
2764 tooltip => "<b>Minimap</b>. This will display an overview of the surrounding areas.",
2765 ),
2766 )->show;
2767
2768 $MAPWIDGET = new DC::MapWidget;
2769 $MAPWIDGET->connect (activate_console => sub {
2770 my ($mapwidget, $preset) = @_;
2771
2772 $MESSAGE_DIST->activate_console ($preset)
2773 if $MESSAGE_DIST;
2774 });
2775 $MAPWIDGET->show;
2776 $MAPWIDGET->grab_focus;
2777
2778 $COMPLETER = new DC::MapWidget::Command::
2779 command => { },
2780 tooltip => "#completer_help",
2781 ;
2782
2783 $SETUP_DIALOG = new DC::UI::Toplevel
2784 title => "Setup",
2785 name => "setup_dialog",
2786 x => 'center',
2787 y => 'center',
2788 z => 2,
2789 force_w => $::WIDTH * 0.6,
2790 force_h => $::HEIGHT * 0.6,
2791 has_close_button => 1,
2792 ;
2793
2794 $METASERVER = metaserver_dialog;
2795 # the name is changed to not conflict with the older name as users could have hidden it
2796 $MESSAGE_WINDOW = new DC::UI::Dockbar
2797 name => "message_window2",
2798 title => 'Messages',
2799 y => $::FONTSIZE + 8,#d# hack to move messages window below the menubar
2800 force_w => $::WIDTH * 0.6,
2801 force_h => $::HEIGHT * 0.25,
2802 ;
2803
2804 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW;
2805
2806 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1,
2807 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2808
2809 $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup,
2810 "Configure the server to play on, your username and password.");
2811 $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
2812 "Configure other server related options.");
2813 $SETUP_NOTEBOOK->add_tab (Client => client_setup,
2814 "Configure various client-specific settings.");
2815 $SETUP_NOTEBOOK->add_tab (Graphics => graphics_setup,
2816 "Configure the video mode, performance, fonts and other graphical aspects of the game.");
2817 $SETUP_NOTEBOOK->add_tab (Audio => audio_setup,
2818 "Configure the use of audio, sound effects and background music.");
2819 $SETUP_NOTEBOOK->add_tab (Keyboard => $SETUP_KEYBOARD = keyboard_setup,
2820 "Lets you define, edit and delete key bindings."
2821 . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor "
2822 . "with nothing set and the recording started. After doing the actions you "
2823 . "want to record press <b>Insert</b> and you will be asked to press a key-combo. "
2824 . "After pressing the combo the binding will be saved automatically and the "
2825 . "binding editor closes");
2826 $SETUP_NOTEBOOK->add_tab (Debug => debug_setup,
2827 "Some debuggin' options. Do not ask.");
2828
2829 make_help_window;
2830 make_menubar;
2831
2832 $SETUP_DIALOG->show;
2833 $MESSAGE_WINDOW->show;
2834 }
2835
2836 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]);
2837 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode});
2838
2839 $CAVEAT_LABEL->set_text ("None :)");
2840 $CAVEAT_LABEL->set_text ("Apple/NVIDIA Texture bug (slow)")
2841 if $DC::OpenGL::APPLE_NVIDIA_BUG;
2842 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)")
2843 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL;
2844
2845 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2846 }
2847
2848 sub video_shutdown {
2849 DC::OpenGL::shutdown;
2850 DC::SDL_QuitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2851
2852 undef $SDL_ACTIVE;
2853 }
2854
2855 my %animate_object;
2856 my $animate_timer;
2857
2858 my $fps = 9;
2859
2860 sub force_refresh {
2861 if ($DELIANTRA_DEBUG & 4) {
2862 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2863 debug sprintf "%3.2f", $fps;
2864 }
2865
2866 undef $WANT_REFRESH;
2867 $_[0]->stop;
2868
2869 $DC::UI::ROOT->draw;
2870 DC::SDL_GL_SwapBuffers;
2871 $LAST_REFRESH = $NOW;
2872 }
2873
2874 my $want_refresh = EV::prepare_ns \&force_refresh;
2875
2876 our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub {
2877 $NOW = EV::now;
2878
2879 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_)
2880 for DC::peep_events;
2881
2882 if (%animate_object) {
2883 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2884 $WANT_REFRESH = 1;
2885 }
2886
2887 $want_refresh->start
2888 if $WANT_REFRESH;
2889 };
2890
2891 sub animation_start {
2892 my ($widget) = @_;
2893 $animate_object{$widget} = $widget;
2894 }
2895
2896 sub animation_stop {
2897 my ($widget) = @_;
2898 delete $animate_object{$widget};
2899 }
2900
2901 $SDL_CB[DC::SDL_QUIT] = sub {
2902 crash "SDL_QUIT";
2903 EV::unloop EV::UNLOOP_ALL;
2904 };
2905 $SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2906 $SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2907 DC::UI::full_refresh;
2908 };
2909 $SDL_CB[DC::SDL_ACTIVEEVENT] = sub {
2910 # not useful, as APPACTIVE includes only iconified state, not unmapped
2911 # printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, DC::SDL_GetAppState;#d#
2912 # printf "a %x\n", DC::SDL_GetAppState & DC::SDL_APPACTIVE;#d#
2913 # printf "A\n" if $_[0]{state} & DC::SDL_APPACTIVE;
2914 # printf "K\n" if $_[0]{state} & DC::SDL_APPINPUTFOCUS;
2915 # printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS;
2916 };
2917 $SDL_CB[DC::SDL_KEYDOWN] = sub {
2918 if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) {
2919 # alt-enter
2920 video_shutdown;
2921 $FULLSCREEN_ENABLE->toggle;
2922 video_init;
2923 } else {
2924 &DC::UI::feed_sdl_key_down_event;
2925 }
2926 update_modbox;
2927 };
2928 $SDL_CB[DC::SDL_KEYUP] = sub {
2929 &DC::UI::feed_sdl_key_up_event;
2930 update_modbox;
2931 };
2932 $SDL_CB[DC::SDL_MOUSEMOTION] = \&DC::UI::feed_sdl_motion_event,
2933 $SDL_CB[DC::SDL_MOUSEBUTTONDOWN] = \&DC::UI::feed_sdl_button_down_event,
2934 $SDL_CB[DC::SDL_MOUSEBUTTONUP] = \&DC::UI::feed_sdl_button_up_event,
2935 $SDL_CB[DC::SDL_USEREVENT] = sub {
2936 if ($_[0]{code} == 1) {
2937 audio_channel_finished $_[0]{data1};
2938 } elsif ($_[0]{code} == 0) {
2939 audio_music_finished;
2940 }
2941 };
2942
2943 #############################################################################
2944
2945 $SIG{INT} = $SIG{TERM} = sub {
2946 EV::unloop;
2947 #d# TODO calling exit here hangs the process in some futex
2948 };
2949
2950 # due to mac os x + sdl combined braindamage, we need this contortion
2951 sub DC::Main::main {
2952 {
2953 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2954
2955 if (-e "$Deliantra::VARDIR/client.cf") {
2956 DC::read_cfg "$Deliantra::VARDIR/client.cf";
2957 } else {
2958 #TODO: compatibility cruft
2959 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2960 print STDERR "INFO: used old configuration file\n";
2961 }
2962
2963 DC::DB::Server::run;
2964
2965 if ($CFG->{db_schema} < 1) {
2966 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2967 DC::DB::nuke_db;
2968 $CFG->{db_schema} = 1;
2969 DC::write_cfg;
2970 }
2971
2972 DC::DB::open_db;
2973
2974 DC::UI::set_layout ($::CFG->{layout});
2975
2976 my %DEF_CFG = (
2977 config_autosave => 1,
2978 sdl_mode => undef,
2979 fullscreen => 1,
2980 fast => 0,
2981 force_opengl11 => undef,
2982 disable_alpha => 0,
2983 smooth_movement => 1,
2984 smooth_transitions => 1,
2985 texture_compression => 1,
2986 map_scale => 1,
2987 fow_enable => 1,
2988 fow_intensity => 0,
2989 fow_texture => 0,
2990 map_smoothing => 1,
2991 gui_fontsize => 1,
2992 log_fontsize => 0.7,
2993 gauge_fontsize => 1,
2994 gauge_size => 0.35,
2995 stat_fontsize => 0.7,
2996 mapsize => 100,
2997 audio_enable => 1,
2998 audio_hw_channels => 0,
2999 audio_hw_frequency => 0,
3000 audio_hw_chunksize => 0,
3001 audio_mix_channels => 8,
3002 effects_enable => 1,
3003 effects_volume => 1,
3004 bgm_enable => 1,
3005 bgm_volume => 0.5,
3006 output_rate => "",
3007 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3008 inv_sort => "mtime",
3009 default => "profile", # default profile
3010 show_tips => 1,
3011 logview_max_par => 1000,
3012 shift_fire_stop => 0,
3013 uitheme => "wood",
3014 map_shift_x => -24, # arbitrary
3015 map_shift_y => +24, # arbitrary
3016 );
3017
3018 while (my ($k, $v) = each %DEF_CFG) {
3019 $CFG->{$k} = $v unless exists $CFG->{$k};
3020 }
3021
3022 my @args = @ARGV;
3023
3024 # OS X passes some process serial number of other shit. they
3025 # could have used an env var or any other sane mechanism. but
3026 # would it be os x then? no...
3027 shift @args if $args[0] =~ /^-psn_/;
3028
3029 my $profile = 'default';
3030
3031 for (my $i = 0; $i < @args; $i++) {
3032 if ($args[$i] =~ /^--?profile$/) {
3033 $profile = $args[$i + 1];
3034 splice @args, $i, 2, ();
3035 $i = 0;
3036 } elsif ($args[$i] =~ /^--?h/) {
3037 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3038 exit 0;
3039 }
3040 }
3041
3042 $CFG->{profile}{$profile} ||= {};
3043 $PROFILE = $CFG->{profile}{$profile};
3044 $PROFILE->{host} ||= "gameserver.deliantra.net";
3045
3046 $PROFILE->{host} = $args[0] if @args > 0;
3047 $PROFILE->{user} = $args[1] if @args > 1;
3048 $PROFILE->{password} = $args[2] if @args > 2;
3049
3050 # convert old bindings (only default profile matters)
3051 if (my $bindings = delete $PROFILE->{bindings}) {
3052 while (my ($mod, $syms) = each %$bindings) {
3053 while (my ($sym, $cmds) = each %$syms) {
3054 push @{ $PROFILE->{macro} }, {
3055 accelkey => [$mod*1, $sym*1],
3056 action => $cmds,
3057 };
3058 }
3059 }
3060 }
3061
3062 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3063 # these are ignored under windows, for some reason, and thus set in the loader
3064 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3065 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3066 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3067
3068 {
3069 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3070 DejaVuSans.ttf
3071 DejaVuSansMono.ttf
3072 DejaVuSans-Bold.ttf
3073 DejaVuSansMono-Bold.ttf
3074 DejaVuSans-Oblique.ttf
3075 DejaVuSansMono-Oblique.ttf
3076 DejaVuSans-BoldOblique.ttf
3077 DejaVuSansMono-BoldOblique.ttf
3078 mona.ttf
3079 );
3080
3081 DC::add_font $_ for @fonts;
3082
3083 $FONT_PROP = new_from_file DC::Font $fonts[0];
3084 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3085
3086 $FONT_PROP->make_default;
3087
3088 DC::pango_init;
3089 }
3090
3091 # compare mono (ft) vs. rgba (cairo)
3092 # ft - 1.8s, cairo 3s, even in alpha-only mode
3093 # for my $rgba (0..1) {
3094 # my $t1 = Time::HiRes::time;
3095 # for (1..1000) {
3096 # my $layout = DC::Layout->new ($rgba);
3097 # $layout->set_text ("hallo" x 100);
3098 # $layout->render;
3099 # }
3100 # my $t2 = Time::HiRes::time;
3101 # warn $t2-$t1;
3102 # }
3103
3104 DC::IMG_Init; video_init;
3105 DC::Mix_Init; audio_init;
3106 }
3107
3108 show_tip_of_the_day if $CFG->{show_tips};
3109
3110 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3111 undef $STARTUP_CANCEL;
3112 (pop @::STARTUP_DONE)->()
3113 while @::STARTUP_DONE;
3114 };
3115
3116 debug_toggle 0;
3117
3118 delete $SIG{__DIE__};
3119 EV::loop;
3120
3121 DC::write_cfg if $CFG->{config_autosave};
3122
3123 #video_shutdown;
3124 #audio_shutdown;
3125
3126 DC::OpenGL::quit;
3127 DC::SDL_Quit;
3128 DC::DB::Server::stop;
3129 }
3130
3131 *DC::Main::run = \&DC::SDL_braino; # see sub above
3132
3133 1