ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
Revision: 1.58
Committed: Sun Aug 17 01:27:33 2008 UTC (15 years, 9 months ago) by root
Branch: MAIN
Changes since 1.57: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

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