ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
Revision: 1.56
Committed: Sat Jul 19 20:33:47 2008 UTC (15 years, 10 months ago) by root
Branch: MAIN
Changes since 1.55: +12 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3 root 1.7 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 root 1.1 # 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 root 1.17 # prepend private library directory
81     BEGIN {
82     for (grep !ref, @INC) {
83 root 1.24 my $path = "$_/Deliantra/Client/private";
84 root 1.17 if (-d $path) {
85     unshift @INC, $path;
86     last;
87     }
88     }
89     }
90    
91 root 1.1 # 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 root 1.4 use EV;
97 root 1.1 use List::Util qw(max min);
98    
99 root 1.14 use Deliantra;
100     use Deliantra::Protocol::Constants;
101 root 1.1
102 root 1.46 use AnyEvent::DNS;
103 root 1.51 use AnyEvent::Socket ();
104 root 1.46
105 root 1.1 use Compress::LZF;
106    
107 root 1.44 use DC;
108 root 1.52 BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } }
109 root 1.18 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 elmex 1.23 use DC::UI::Dockbar;
118 root 1.18 use DC::UI::MessageWindow;
119     use DC::UI::ChatView;
120 elmex 1.23 use DC::MessageDistributor;
121 root 1.18 use DC::Pod;
122     use DC::MapWidget;
123     use DC::Macro;
124 root 1.1
125     $SIG{QUIT} = sub { Carp::cluck "QUIT" };
126     $SIG{PIPE} = 'IGNORE';
127    
128 root 1.4 $EV::DIED = sub {
129 root 1.18 DC::fatal Carp::longmess $@;
130 root 1.1 };
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 root 1.53 our $MODE_SLIDER;
147     our $CAVEAT_LABEL;
148    
149 root 1.1 our @SDL_MODES;
150 root 1.52 our $SDL_REINIT = 1;
151 root 1.1 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 elmex 1.23 our $MESSAGE_DIST;
194 root 1.1 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 root 1.29 our $MODBOX;
204 root 1.1 our $DEBUG_STATUS;
205    
206     our $INV;
207     our $INVR;
208     our $INVR_HB;
209    
210     #############################################################################
211    
212     sub status {
213 root 1.18 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
214 root 1.1 }
215    
216     sub debug {
217     $DEBUG_STATUS->set_text ($_[0]);
218     }
219    
220     sub message {
221 elmex 1.23 $MESSAGE_DIST->message (@_);
222 root 1.1 }
223    
224 root 1.29 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 root 1.30 # <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 root 1.29 }
249    
250 root 1.1 #############################################################################
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 root 1.4 for (grep $_->[0] >= EV::now, @{(delete $AUDIO_PLAY{$face}) || []}) {
285 root 1.1 my (undef, $dx, $dy, $vol) = @$_;
286    
287 root 1.18 my $channel = DC::Channel::find;
288 root 1.1 $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 root 1.18 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 root 1.1 $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 root 1.4 push @$queue, [EV::now + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
331 root 1.1 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 root 1.18 "<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 root 1.1 );
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 root 1.18 DC::MixMusic::volume $base * $volume * 128;
352 root 1.1 }
353    
354     sub audio_music_start {
355     my $meta = $MUSIC_PLAYING_META;
356    
357 root 1.18 DC::DB::get res_data => $meta->{name}, sub {
358 root 1.1 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 root 1.18 ? new_from_file DC::RW $meta->{path}
370     : new DC::RW $$MUSIC_PLAYING_DATA;
371 root 1.1
372 root 1.18 $MUSIC_PLAYER = new DC::MixMusic $rwops
373     or Carp::confess "music face $meta->{face} unloadable: " . DC::Mix_GetError;
374 root 1.1
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 root 1.9 $fade_out = 333;
398 root 1.1 @MUSIC_HAVE = $MUSIC_JINGLE[0];
399 root 1.9
400 root 1.1 } else {
401     return unless $CFG->{bgm_enable};
402    
403 root 1.9 $fade_out = 700;
404    
405     @MUSIC_HAVE =
406 root 1.1 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 root 1.9 $_->{stop_time} ||= rand for @MUSIC_HAVE;
412 root 1.1
413     # default MUSIC_HAVE == MUSIC_DEFAULT
414 root 1.18 @MUSIC_HAVE = { path => DC::find_rcfile "music/$MUSIC_DEFAULT" }
415 root 1.9 unless @MUSIC_HAVE;
416 root 1.1 }
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 root 1.18 DC::MixMusic::fade_out $fade_out;
427 root 1.1 } 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 root 1.18 $SDL_MIXER = !DC::Mix_OpenAudio
471 root 1.1 $CFG->{audio_hw_frequency},
472 root 1.18 DC::MIX_DEFAULT_FORMAT,
473 root 1.1 $CFG->{audio_hw_channels},
474     $CFG->{audio_hw_chunksize};
475    
476     if ($SDL_MIXER) {
477 root 1.18 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
478 root 1.1
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 root 1.18 DC::Mix_CloseAudio if $SDL_MIXER;
502 root 1.1 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 root 1.10 $QUERY_TIMER = EV::timer 1, 0, sub {
523     server_query ($conn, $flags, $prompt, 1);
524     $QUERY_TIMER = undef
525     };
526    
527 root 1.1 return;
528     }
529     }
530    
531 root 1.18 $conn->{query_dialog} = my $dialog = new DC::UI::Toplevel
532 root 1.1 x => "center",
533     y => "center",
534     title => "Server Query",
535 root 1.18 child => my $vbox = new DC::UI::VBox,
536 root 1.1 ;
537    
538 root 1.18 my @dialog = my $label = new DC::UI::Label
539 root 1.1 max_w => $::WIDTH * 0.8,
540     ellipsise => 0,
541     text => $prompt;
542    
543     if ($flags & CS_QUERY_YESNO) {
544 root 1.18 push @dialog, my $hbox = new DC::UI::HBox;
545 root 1.1
546 root 1.18 $hbox->add (new DC::UI::Button
547 root 1.1 text => "No",
548     on_activate => sub {
549     $conn->send ("reply n");
550     $dialog->destroy;
551     0
552     }
553     );
554 root 1.18 $hbox->add (new DC::UI::Button
555 root 1.1 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 root 1.18 unshift @dialog, new DC::UI::Label
570 root 1.1 max_w => $::WIDTH * 0.8,
571     ellipsise => 0,
572     markup => "\nOr use your keyboard and the text entry below:\n";
573    
574 root 1.18 unshift @dialog, my $table = new DC::UI::Table;
575 root 1.1
576 root 1.18 $table->add_at (0, 0, new DC::UI::Button
577 root 1.1 text => "Next Race",
578     on_activate => sub {
579     $conn->send ("reply n");
580     destroy_query_dialog $conn;
581     0
582     },
583     );
584 root 1.18 $table->add_at (2, 0, new DC::UI::Button
585 root 1.1 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 root 1.18 unshift @dialog, new DC::UI::Label
595 root 1.1 max_w => $::WIDTH * 0.8,
596     ellipsise => 0,
597     markup => "<span foreground='#ccccff'>$conn->{chargen_race_description}</span>",
598     ;
599     }
600    
601 root 1.18 unshift @dialog, new DC::UI::Face
602 root 1.1 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 root 1.18 unshift @dialog, new DC::UI::Label
610 root 1.1 allign => 1,
611     ellipsise => 0,
612     markup => "<span foreground='#ccccff' size='large'>Race: $conn->{chargen_race_title}</span>",
613     ;
614     }
615    
616 root 1.18 unshift @dialog, new DC::UI::Label
617 root 1.1 max_w => $::WIDTH * 0.4,
618     ellipsise => 0,
619 root 1.18 markup => (DC::Pod::section_label ui => "chargen_race"),
620 root 1.1 ;
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 root 1.18 unshift @dialog, new DC::UI::Label
630 root 1.1 max_w => $::WIDTH * 0.4,
631     ellipsise => 0,
632     markup => "\nOr use your keyboard and the text entry below:\n";
633    
634 root 1.18 unshift @dialog, my $table = new DC::UI::Table;
635 root 1.1
636     # left: re-roll
637 root 1.18 $table->add_at (0, 0, new DC::UI::Button
638 root 1.1 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 root 1.18 my ($sw1, $sw2) = map +(new DC::UI::Selector
648 root 1.1 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 root 1.18 $table->add_at (2, 0, new DC::UI::Button
662 root 1.1 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 root 1.18 $table->add_at (2, 1, new DC::UI::HBox children => [$sw1, $sw2]);
671 root 1.1
672     # right: accept
673 root 1.18 $table->add_at (4, 0, new DC::UI::Button
674 root 1.1 text => "Accept",
675     on_activate => sub {
676     $conn->send ("reply n");
677     destroy_query_dialog $conn;
678     0
679     },
680     );
681    
682 root 1.18 unshift @dialog, my $hbox = new DC::UI::HBox;
683 root 1.1 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 root 1.18 $hbox->add (new DC::UI::Label
694 root 1.1 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 root 1.18 unshift @dialog, new DC::UI::Label
703 root 1.1 max_w => $::WIDTH * 0.4,
704     ellipsise => 0,
705 root 1.18 markup => (DC::Pod::section_label ui => "chargen_stats"),
706 root 1.1 ;
707     }
708    
709 root 1.18 push @dialog, my $entry = new DC::UI::Entry
710 root 1.1 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 root 1.18 push @dialog, my $entry = new DC::UI::Entry
723 root 1.1 $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 root 1.46 sub dc_connect {
739     my ($host, $port) = @_;
740 root 1.1
741     my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
742    
743 root 1.44 $CONN =
744 root 1.18 new DC::Protocol
745 root 1.1 host => $host,
746 root 1.51 port => $port,
747 root 1.1 user => $PROFILE->{user},
748     pass => $PROFILE->{password},
749     mapw => $mapsize,
750     maph => $mapsize,
751    
752 root 1.26 client => "$DC::VERSION $] $^O",
753 root 1.1
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 root 1.44 on_connect => sub {
765     if ($_[0]) {
766     DC::lowdelay fileno $CONN->{fh};
767 root 1.1
768 root 1.44 status "login successful";
769     } else {
770     undef $CONN;
771     status "unable to connect: $!";
772     stop_game();
773     }
774     },
775     ;
776 root 1.1 }
777    
778 root 1.46 sub start_game {
779     status "logging in...";
780    
781     $LOGIN_BUTTON->set_text ("Logout");
782     $SETUP_DIALOG->hide;
783    
784 root 1.51 my ($host, $port) = AnyEvent::Socket::parse_hostport $PROFILE->{host}, "deliantra=13327";
785 root 1.46
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 root 1.1 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 root 1.18 $DC::UI::ROOT->emit (stop_game => ! ! $CONN);
811 root 1.1
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 root 1.18 my $vbox = new DC::UI::VBox;
827 root 1.1
828 root 1.18 $vbox->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
829 root 1.1
830     my $row = 0;
831    
832 root 1.22 $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 root 1.1 can_events => 1,
835 root 1.18 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>");
836 root 1.1
837 root 1.53 $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 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode");
850 root 1.18 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox);
851 root 1.1
852 root 1.53 $hbox->add ($MODE_SLIDER = new DC::UI::Slider
853     force_w => $WIDTH * 0.1, expand => 1,
854 root 1.56 range => [ ($CFG->{sdl_mode}) x 3 ],
855 root 1.1 tooltip => $vidmode_tooltip);
856 root 1.18 $hbox->add (my $mode_label = new DC::UI::Label
857 root 1.22 height => 0.8, template => "9999x9999@9+9",
858 root 1.1 can_events => 1, tooltip => $vidmode_tooltip);
859    
860 root 1.53 $MODE_SLIDER->connect (changed => sub {
861 root 1.1 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 root 1.53 $MODE_SLIDER->emit (changed => $MODE_SLIDER->{range}[0]);
867 root 1.1
868 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fullscreen");
869 root 1.18 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::CheckBox
870 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Force OpenGL 1.1");
876 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
877 root 1.1 state => $CFG->{force_opengl11},
878 elmex 1.23 tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in "
879 root 1.1 . "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 root 1.52 . "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 root 1.1 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
885     );
886    
887 root 1.52 $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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
905 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
906 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
915 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
916 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "GUI Fontsize");
922 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
923 root 1.1 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 root 1.18 $table->add_at (1, $row++, new DC::UI::Button
929 root 1.22 expand => 1, text => "Apply",
930 root 1.1 tooltip => "Apply the video settings above.",
931     on_activate => sub {
932     video_shutdown ();
933     video_init ();
934     0
935     }
936     );
937    
938 root 1.56 $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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Map Scale");
948 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
949 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Map Smoothing");
955 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
956 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fog of War");
964 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
965 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "FoW Intensity");
971 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
972 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Fontsize");
978 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
979 root 1.1 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 elmex 1.23 on_changed => sub { $MESSAGE_DIST->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
983 root 1.1 );
984    
985 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Gauge fontsize");
986 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
987 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Gauge size");
997 root 1.18 $table->add_at (1, $row++, new DC::UI::Slider
998 root 1.1 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 root 1.18 my ($freq, $format, $chans) = DC::Mix_QuerySpec;
1015 root 1.1
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 root 1.18 my $vbox = new DC::UI::VBox;
1035 root 1.1
1036 root 1.18 $vbox->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 0, 1]);
1037 root 1.1
1038     my $row = 0;
1039    
1040 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Audio Enable");
1041 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
1042 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1048 root 1.18 $table->add_at (1, $row, new DC::UI::CheckBox
1049 root 1.1 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 root 1.18 $table->add_at (2, $row++, new DC::UI::Slider
1058 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Background Music");
1065 root 1.18 $table->add_at (1, $row, new DC::UI::CheckBox
1066 root 1.1 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 root 1.18 $table->add_at (2, $row++, new DC::UI::Slider
1076 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Frequency");
1082 root 1.18 $table->add_at (1, $row++, new DC::UI::Selector
1083 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Channels");
1101 root 1.18 $table->add_at (1, $row++, new DC::UI::Selector
1102 root 1.1 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 root 1.6 [2, "Stereo" , "Stereo (dual channel, standard quality)"],
1108 root 1.1 [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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Latency");
1120 root 1.18 $table->add_at (1, $row++, $AUDIO_HW_CHUNKSIZE = new DC::UI::Selector
1121 root 1.1 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 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Mixer Voices");
1134 root 1.18 $table->add_at (1, $row++, new DC::UI::ValSlider
1135 root 1.1 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 root 1.18 $table->add_at (1, $row++, new DC::UI::Button
1149 root 1.22 c_colspan => 2, expand => 1, text => "Apply",
1150 root 1.1 tooltip => "Apply the audio settings",
1151     on_activate => sub {
1152     audio_shutdown ();
1153     audio_init ();
1154     0
1155     }
1156     );
1157    
1158 root 1.18 $vbox->add (new DC::UI::FancyFrame
1159 root 1.1 expand => 1,
1160     label => "Audio Info",
1161 root 1.18 child => ($AUDIO_INFO = new DC::UI::Label ellipsise => 0),
1162 root 1.1 );
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 root 1.18 my $win = new DC::UI::Frame (
1179 root 1.1 force_x => 0,
1180     force_y => "max",
1181     force_w => $WIDTH,
1182     force_h => $gh,
1183     );
1184    
1185 root 1.18 $win->add (my $hbox = new DC::UI::HBox
1186 root 1.1 children => [
1187 root 1.18 (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 root 1.1 ]),
1192 root 1.18 (my $vbox = new DC::UI::VBox),
1193 root 1.1 ],
1194     );
1195    
1196 root 1.18 $vbox->add (new DC::UI::HBox
1197 root 1.1 expand => 1,
1198     children => [
1199 root 1.18 (new DC::UI::Empty expand => 1),
1200     (my $hb = new DC::UI::HBox),
1201 root 1.1 ],
1202     );
1203    
1204 root 1.18 $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 root 1.22 $vbox->add (my $exp = new DC::UI::Label align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
1210 root 1.18 $vbox->add (my $prg = new DC::UI::ExperienceProgress);
1211     $vbox->add (my $sklprg = new DC::UI::ExperienceProgress);
1212 root 1.22 $vbox->add (my $rng = new DC::UI::Label align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
1213 root 1.1
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 root 1.18 my $table = new DC::UI::Table;
1227 root 1.1
1228 root 1.18 $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 root 1.21 $table->add_at (0, 5, new DC::UI::TextEdit text => "line1\0152\0153\nµikachu\nづx゙つ゛");#d#
1239 root 1.18
1240     $table->add_at (7,7, my $t = new DC::UI::Table expand => 0);
1241 root 1.20 $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 root 1.18 $t->add_at (1,1, new DC::UI::Label text => "e");
1246 root 1.1
1247 root 1.18 $table->add_at (7, 6, my $c = new DC::UI::Canvas);
1248 root 1.1
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 root 1.18 my $r = new DC::UI::ScrolledWindow (
1278 root 1.1 expand => 1,
1279     scroll_y => 1
1280     );
1281 root 1.18 $r->add (my $vb = new DC::UI::VBox);
1282 root 1.1
1283 root 1.18 $vb->add (new DC::UI::FancyFrame
1284 root 1.1 label => "Player",
1285 root 1.18 child => (my $pi = new DC::UI::VBox),
1286 root 1.1 );
1287    
1288 root 1.22 $pi->add ($STATWIDS->{title} = new DC::UI::Label text => "Title:", expand => 1, align => 0,
1289 root 1.1 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 root 1.22 $pi->add ($STATWIDS->{map} = new DC::UI::Label align => 0, text => "Map:", expand => 1,
1292 root 1.1 can_hover => 1, can_events => 1,
1293     tooltip => "The map you are currently on (if supported by the server).");
1294    
1295 root 1.18 $pi->add (my $hb0 = new DC::UI::HBox);
1296 root 1.22 $hb0->add ($STATWIDS->{weight} = new DC::UI::Label text => "Weight:", expand => 1, align => 0,
1297 root 1.1 can_hover => 1, can_events => 1,
1298     tooltip => "The weight of the player including all inventory items.");
1299 root 1.22 $hb0->add ($STATWIDS->{m_weight} = new DC::UI::Label align => 0, text => "Max weight:", expand => 1,
1300 root 1.1 can_hover => 1, can_events => 1,
1301     tooltip => "The weight limit: you cannot carry more than this.");
1302    
1303 root 1.18 $vb->add (new DC::UI::FancyFrame
1304 root 1.1 label => "Primary/Secondary Statistics",
1305 root 1.18 child => (my $hb = new DC::UI::HBox expand => 1),
1306 root 1.1 );
1307 root 1.18 $hb->add (my $tbl = new DC::UI::Table expand => 1);
1308 root 1.1
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 root 1.18 $tbl->add_at ($col , $row, $STATWIDS->{$id} = new DC::UI::Label
1330 root 1.22 font => $FONT_FIXED, can_hover => 1, can_events => 1,
1331     align => 1, template => $template, tooltip => "#stat_$label");
1332 root 1.18 $tbl->add_at ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new DC::UI::Label
1333 root 1.22 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $color2,
1334     align => 0, text => $label, tooltip => "#stat_$label");
1335 root 1.1 }
1336    
1337 root 1.18 $vb->add (new DC::UI::FancyFrame
1338 root 1.1 label => "Resistancies",
1339 root 1.22 child => (my $tbl2 = new DC::UI::Table expand => 1, col_expand => [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]),
1340 root 1.1 );
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 root 1.22 $tbl2->add_at ($col + 2, $row,
1389 root 1.1 $STATWIDS->{"res_$_"} =
1390 root 1.18 new DC::UI::Label
1391 root 1.1 font => $FONT_FIXED,
1392     template => "-100%",
1393 root 1.22 align => 1,
1394 root 1.1 can_events => 1,
1395     can_hover => 1,
1396     tooltip => $resist_names{$_}->[1],
1397     );
1398 root 1.18 $tbl2->add_at ($col + 1, $row, new DC::UI::Image
1399 root 1.1 font => $FONT_FIXED,
1400     can_hover => 1,
1401     can_events => 1,
1402     path => "ui/resist/resist_$_.png",
1403     tooltip => $resist_names{$_}->[1],
1404     );
1405 root 1.22 $tbl2->add_at ($col + 0, $row, new DC::UI::Label
1406 root 1.1 text => $resist_names{$_}->[0],
1407     font => $FONT_FIXED,
1408 root 1.22 align => 1,
1409 root 1.1 can_hover => 1,
1410     can_events => 1,
1411     tooltip => $resist_names{$_}->[1],
1412     );
1413    
1414     $row++;
1415     if ($row % 6 == 0) {
1416 root 1.22 $col += 4;
1417 root 1.1 $row = 0;
1418     }
1419     }
1420    
1421     #update_stats_window ({});
1422    
1423     $r
1424     }
1425    
1426     sub skill_window {
1427 root 1.18 my $sw = new DC::UI::ScrolledWindow (expand => 1);
1428 root 1.1
1429 root 1.18 $sw->add ($STATWIDS->{skill_tbl} = new DC::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1430 root 1.1
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 root 1.18 $table->add_at (0, 0, my $label = new DC::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
1452 root 1.1
1453     my $ok = 0;
1454    
1455 root 1.18 DC::background {
1456     my $ua = DC::lwp_useragent;
1457 root 1.1
1458 root 1.18 DC::background_msg DC::decode_json +(DC::lwp_check $ua->get ($META_SERVER))->decoded_content;
1459 root 1.1 } 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 root 1.18 $table->add_at ($_, 0, new DC::UI::Label
1472 root 1.22 can_hover => 1, can_events => 1, fg => [1, 1, 0],
1473 root 1.1 text => $col[$_], tooltip => $tip[$_])
1474     for 0 .. $#col;
1475    
1476 root 1.22 my @align = qw(1 0.5 1 1 0);
1477 root 1.1
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 root 1.18 $table->add_at (scalar @$m, $y, new DC::UI::VBox children => [
1503     (new DC::UI::Button
1504 root 1.1 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 root 1.18 (new DC::UI::Empty expand => 1),
1513 root 1.1 ]);
1514    
1515 root 1.18 $table->add_at ($_, $y, new DC::UI::Label
1516 root 1.1 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 root 1.18 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 root 1.1
1539 root 1.18 my $dialog = new DC::UI::Toplevel
1540 root 1.1 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 root 1.18 my $vbox = new DC::UI::VBox;
1561 root 1.1
1562 root 1.18 $vbox->add (new DC::UI::FancyFrame
1563 root 1.1 label => "Login Settings",
1564 root 1.18 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
1565 root 1.1 );
1566    
1567 root 1.22 $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username");
1568 root 1.18 $table->add_at (1, 4, new DC::UI::Entry
1569 root 1.1 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 root 1.22 $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password");
1575 root 1.18 $table->add_at (1, 5, new DC::UI::Entry
1576 root 1.1 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 root 1.18 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button
1583 root 1.1 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 root 1.18 $vbox->add (new DC::UI::FancyFrame
1594 root 1.1 label => "Registering",
1595     min_h => 200,
1596 root 1.22 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1597 root 1.1 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 root 1.18 my $vbox = new DC::UI::VBox;
1608 root 1.1
1609 root 1.18 $vbox->add (new DC::UI::FancyFrame
1610 root 1.1 label => "Connection Settings",
1611 root 1.18 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
1612 root 1.1 );
1613    
1614     my $row = 0;
1615    
1616 root 1.22 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Host:Port");
1617 root 1.1 {
1618 root 1.18 $table->add_at (1, $row, my $vbox = new DC::UI::VBox);
1619 root 1.1
1620     $vbox->add (
1621 root 1.18 $HOST_ENTRY = new DC::UI::Entry
1622 root 1.1 expand => 1,
1623     text => $CFG->{profile}{default}{host},
1624 root 1.28 tooltip => "The hostname or ip address of the Deliantra server to connect to (e.g. <b>gameserver.deliantra.net</b>)",
1625 root 1.1 on_changed => sub {
1626     my ($self, $value) = @_;
1627     $CFG->{profile}{default}{host} = $value;
1628     1
1629     }
1630     );
1631    
1632 root 1.5 if (0) { #d# disabled
1633 root 1.18 $vbox->add (new DC::UI::Button
1634 root 1.1 expand => 1,
1635     text => "Server List",
1636     other => $METASERVER,
1637 root 1.28 tooltip => "Show a list of available Deliantra servers",
1638 root 1.1 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1639     on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1640     );
1641 root 1.5 }#d#
1642 root 1.1 }
1643    
1644 root 1.22 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Map Size");
1645 root 1.18 $table->add_at (1, $row, new DC::UI::Slider
1646 root 1.1 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 root 1.22 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate");
1656 root 1.18 $table->add_at (1, $row, new DC::UI::Entry
1657 root 1.1 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 root 1.18 $vbox->add (new DC::UI::FancyFrame
1666 root 1.1 label => "Server Info",
1667 root 1.18 child => ($SERVER_INFO = new DC::UI::Label ellipsise => 0),
1668 root 1.1 );
1669    
1670     $vbox
1671     }
1672    
1673     sub client_setup {
1674 root 1.18 my $table = new DC::UI::Table expand => 1, col_expand => [0, 1];
1675 root 1.1
1676     my $row = 0;
1677    
1678 root 1.22 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day");
1679 root 1.18 $table->add_at (1, $row++, new DC::UI::CheckBox
1680 root 1.1 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 root 1.37 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size");
1690 root 1.18 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1691 root 1.1 text => $CFG->{logview_max_par},
1692 root 1.37 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server "
1693 root 1.1 . "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 root 1.28 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1698 root 1.1 0
1699     },
1700     );
1701    
1702     $table
1703     }
1704    
1705     sub autopickup_setup {
1706 root 1.18 my $r = new DC::UI::ScrolledWindow (
1707 root 1.1 expand => 1,
1708     scroll_y => 1
1709     );
1710 root 1.18 $r->add (my $table = new DC::UI::Table
1711 root 1.1 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     ["Weight/Value ratio", 2, 17]
1755     )
1756     {
1757     my ($title, $x, $y, @bits) = @$_;
1758 root 1.18 $table->add_at ($x, $y, new DC::UI::Label text => $title, align => 1, fg => [1, 1, 0]);
1759 root 1.1
1760     for (@bits) {
1761     ++$y;
1762    
1763     my $mask = $_->[1];
1764 root 1.18 $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 root 1.1 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 root 1.18 $table->add_at (2, 18, new DC::UI::ValSlider
1787 root 1.1 range => [$::CFG->{pickup} & 0xF, 0, 16, 1, 1],
1788     template => ">= 99",
1789     to_value => sub { ">= " . 5 * $_[0] },
1790     on_changed => sub {
1791     my ($slider, $value) = @_;
1792    
1793     $::CFG->{pickup} &= ~0xF;
1794     $::CFG->{pickup} |= int $value
1795     if $value;
1796     1;
1797     });
1798    
1799 root 1.18 $table->add_at (3, 18, new DC::UI::Button
1800 root 1.1 text => "set",
1801     on_activate => sub {
1802     $::CONN->send_command ("pickup $::CFG->{pickup}")
1803     if defined $::CONN;
1804     0
1805     });
1806    
1807     $r
1808     }
1809    
1810     my %SORT_ORDER = (
1811 elmex 1.41 type => sub {
1812     sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_
1813     },
1814 root 1.1 mtime => sub {
1815     my $NOW = time;
1816     sort {
1817     my $atime = $a->{mtime} - $NOW; $atime = $atime < 5 * 60 ? int $atime / 60 : 6;
1818     my $btime = $b->{mtime} - $NOW; $btime = $btime < 5 * 60 ? int $btime / 60 : 6;
1819    
1820     ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED)
1821     or $btime <=> $atime
1822     or $a->{type} <=> $b->{type}
1823     } @_
1824     },
1825     weight => sub { sort {
1826     $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1827     or $a->{type} <=> $b->{type}
1828     } @_ },
1829     );
1830    
1831     sub inventory_widget {
1832 root 1.18 my $hb = new DC::UI::HBox homogeneous => 1;
1833 root 1.1
1834 root 1.18 $hb->add (my $vb1 = new DC::UI::VBox);
1835 root 1.22 $vb1->add (new DC::UI::Label text => "Player");
1836 root 1.1
1837 root 1.18 $vb1->add (my $hb1 = new DC::UI::HBox);
1838 root 1.1
1839     use sort 'stable';
1840    
1841 root 1.18 $hb1->add (new DC::UI::Selector
1842 root 1.1 value => $::CFG->{inv_sort},
1843     options => [
1844     [type => "Type/Name"],
1845     [mtime => "Recent/Normal/Locked"],
1846     [weight => "Weight/Type"],
1847     ],
1848     on_changed => sub {
1849     $::CFG->{inv_sort} = $_[1];
1850     $INV->set_sort_order ($SORT_ORDER{$_[1]});
1851     },
1852     );
1853 root 1.18 $hb1->add (new DC::UI::Label text => "Weight: ", align => 1, expand => 1);
1854 root 1.1 #TODO# update to weigh/maxweight
1855 root 1.22 $hb1->add ($STATWIDS->{i_weight} = new DC::UI::Label align => 0);
1856 root 1.1
1857 root 1.18 $vb1->add (my $sw1 = new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
1858     $sw1->add ($INV = new DC::UI::Inventory);
1859 root 1.1 $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}});
1860    
1861 root 1.18 $hb->add (my $vb2 = new DC::UI::VBox);
1862 root 1.1
1863 root 1.18 $vb2->add ($INVR_HB = new DC::UI::HBox);
1864 root 1.1
1865 root 1.18 $vb2->add (my $sw2 = new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
1866     $sw2->add ($INVR = new DC::UI::Inventory);
1867 root 1.1
1868     # XXX: Call after $INVR = ... because set_opencont sets the items
1869 root 1.18 DC::Protocol::set_opencont ($::CONN, 0, "Floor");
1870 root 1.1
1871     $hb
1872     }
1873    
1874     sub media_window {
1875 root 1.18 my $vb = new DC::UI::VBox;
1876 root 1.1
1877 root 1.18 $vb->add (new DC::UI::FancyFrame
1878 root 1.1 label => "Currently playing music",
1879 root 1.18 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
1880     child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
1881 root 1.1 );
1882    
1883 root 1.18 $vb->add (new DC::UI::FancyFrame
1884 root 1.1 label => "Other media used in this session",
1885     expand => 1,
1886 root 1.18 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
1887 root 1.1 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
1888     );
1889    
1890     $vb
1891     }
1892    
1893     sub add_license {
1894     my ($meta) = @_;
1895    
1896     $meta = $meta->{data}
1897     or return;
1898    
1899     $meta->{license} || $meta->{author} || $meta->{source}
1900     or return;
1901    
1902     $LICENSE_WIDGET->add_paragraph ({
1903     fg => [1, 1, 1, 1],
1904     markup => "<small>"
1905 root 1.18 . "<b>Name:</b> " . (DC::asxml $meta->{name}) . "\n"
1906     . "<b>Author:</b> " . (DC::asxml $meta->{author}) . "\n"
1907     . "<b>Source:</b> " . (DC::asxml $meta->{source}) . "\n"
1908     . "<b>License:</b> " . (DC::asxml $meta->{license}) . "\n"
1909 root 1.1 . "</small>",
1910     });
1911     $LICENSE_WIDGET->scroll_to_bottom;
1912     }
1913    
1914     sub toggle_player_page {
1915     my ($widget) = @_;
1916    
1917     if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) {
1918     $PL_WINDOW->hide;
1919     } else {
1920     $PL_NOTEBOOK->set_current_page ($widget);
1921     $PL_WINDOW->show;
1922     }
1923     }
1924    
1925     sub player_window {
1926 root 1.18 my $plwin = $PL_WINDOW = new DC::UI::Toplevel
1927 root 1.1 x => "center",
1928     y => "center",
1929     force_w => $WIDTH * 9/10,
1930     force_h => $HEIGHT * 9/10,
1931     title => "Player",
1932     name => "playerbook",
1933     has_close_button => 1
1934     ;
1935    
1936     my $ntb =
1937     $PL_NOTEBOOK =
1938 root 1.18 new DC::UI::Notebook expand => 1;
1939 root 1.1
1940     $ntb->add_tab (
1941     "Statistics (F2)" => $STATS_PAGE = stats_window,
1942     "Shows statistics, where all your Stats and Resistances are shown."
1943     );
1944     $ntb->add_tab (
1945     "Skills (F3)" => $SKILL_PAGE = skill_window,
1946     "Shows all your Skills."
1947     );
1948    
1949 root 1.18 my $spellsw = $SPELL_PAGE = new DC::UI::ScrolledWindow (expand => 1, scroll_y => 1);
1950     $spellsw->add ($SPELL_LIST = new DC::UI::SpellList);
1951 root 1.1 $ntb->add_tab (
1952     "Spellbook (F4)" => $spellsw,
1953     "Displays all spells you have and lets you edit keyboard shortcuts for them."
1954     );
1955     $ntb->add_tab (
1956     "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1957     "Toggles the inventory window, where you can manage your loot (or treasures :). "
1958     . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1959     );
1960     $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1961     "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1962    
1963     $ntb->add_tab (Media => media_window,
1964     "License, Author and Source info for media sent by the server.");
1965    
1966     $ntb->set_current_page ($INVENTORY_PAGE);
1967    
1968     $plwin->add ($ntb);
1969     $plwin
1970     }
1971    
1972     sub keyboard_setup {
1973 root 1.18 DC::Macro::keyboard_setup
1974 root 1.1 }
1975    
1976     sub help_window {
1977 root 1.18 my $win = new DC::UI::Toplevel
1978 root 1.1 x => 'center',
1979     y => 'center',
1980     z => 4,
1981     name => 'doc_browser',
1982     force_w => int $WIDTH * 7/8,
1983     force_h => int $HEIGHT * 7/8,
1984     title => "Help Browser",
1985     has_close_button => 1;
1986    
1987 root 1.18 $win->add (my $vbox = new DC::UI::VBox);
1988 root 1.1
1989 root 1.18 $vbox->add (new DC::UI::FancyFrame
1990 root 1.1 label => "Navigation",
1991 root 1.18 child => (my $buttons = new DC::UI::HBox),
1992 root 1.1 );
1993 root 1.18 $vbox->add (my $viewer = new DC::UI::TextScroller
1994 root 1.1 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
1995    
1996     my @history;
1997     my @future;
1998     my $curnode;
1999    
2000     my $load_node; $load_node = sub {
2001     my ($node, $para) = @_;
2002    
2003     $buttons->clear;
2004    
2005 root 1.18 $buttons->add (new DC::UI::Button
2006 root 1.1 text => "⇤",
2007     tooltip => "back to the starting page",
2008     on_activate => sub {
2009     unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
2010     unshift @future, @history;
2011     @history = ();
2012     $load_node->(@{shift @future});
2013     },
2014     );
2015    
2016     if (@history) {
2017 root 1.18 $buttons->add (new DC::UI::Button
2018 root 1.1 text => "⋘",
2019 root 1.18 tooltip => "back to <i>" . (DC::asxml DC::Pod::full_path $history[-1][0]) . "</i>",
2020 root 1.1 on_activate => sub {
2021     unshift @future, [$curnode, $viewer->current_paragraph] if $curnode;
2022     $load_node->(@{pop @history});
2023     },
2024     );
2025     }
2026    
2027     if (@future) {
2028 root 1.18 $buttons->add (new DC::UI::Button
2029 root 1.1 text => "⋙",
2030 root 1.18 tooltip => "forward to <i>" . (DC::asxml DC::Pod::full_path $future[0][0]) . "</i>",
2031 root 1.1 on_activate => sub {
2032     push @history, [$curnode, $viewer->current_paragraph];
2033     $load_node->(@{shift @future});
2034     },
2035     );
2036     }
2037    
2038 root 1.18 $buttons->add (new DC::UI::Label text => " ");
2039 root 1.1
2040 root 1.18 my @path = DC::Pod::full_path_of $node;
2041 root 1.1 pop @path; # drop current node
2042    
2043     for my $node (@path) {
2044 root 1.18 $buttons->add (new DC::UI::Button
2045 root 1.31 text => $node->[DC::Pod::N_KW][0],
2046 root 1.18 tooltip => "go to <i>" . (DC::asxml DC::Pod::full_path $node) . "</i>",
2047 root 1.1 on_activate => sub {
2048     push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
2049     $load_node->($node);
2050     },
2051     );
2052 root 1.18 $buttons->add (new DC::UI::Label text => "/");
2053 root 1.1 }
2054    
2055 root 1.31 $buttons->add (new DC::UI::Label text => $node->[DC::Pod::N_KW][0], padding_x => 4, padding_y => 4);
2056 root 1.1
2057     $curnode = $node;
2058    
2059     $viewer->clear;
2060 root 1.18 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $curnode);
2061 root 1.1 $viewer->scroll_to ($para);
2062     };
2063    
2064 root 1.18 $load_node->(DC::Pod::find pod => "mainpage");
2065 root 1.1
2066 root 1.18 $DC::Pod::goto_document = sub {
2067 root 1.1 my (@path) = @_;
2068    
2069     push @history, [$curnode, $viewer->current_paragraph] if $curnode; @future = ();
2070    
2071 root 1.18 $load_node->((DC::Pod::find @path)[0]);
2072 root 1.1 $win->show;
2073     };
2074    
2075     $win
2076     }
2077    
2078     sub open_string_query {
2079     my ($title, $cb, $txt, $tooltip) = @_;
2080 root 1.18 my $dialog = new DC::UI::Toplevel
2081 root 1.1 x => "center",
2082     y => "center",
2083     z => 50,
2084     force_w => $WIDTH * 4/5,
2085     title => $title;
2086    
2087     $dialog->add (
2088 root 1.18 my $e = new DC::UI::Entry
2089 root 1.1 on_activate => sub { $cb->(@_); $dialog->hide; 0 },
2090     on_key_down => sub { $_[1]->{sym} == 27 and $dialog->hide; 0 },
2091     tooltip => $tooltip
2092     );
2093    
2094     $e->grab_focus;
2095     $e->set_text ($txt) if $txt;
2096     $dialog->show;
2097     }
2098    
2099     sub open_quit_dialog {
2100     unless ($QUIT_DIALOG) {
2101 root 1.18 $QUIT_DIALOG = new DC::UI::Toplevel
2102 root 1.1 x => "center",
2103     y => "center",
2104     z => 50,
2105     title => "Really Quit?",
2106     on_key_down => sub {
2107     my ($dialog, $ev) = @_;
2108     $ev->{sym} == 27 and $dialog->hide;
2109     }
2110     ;
2111    
2112 root 1.18 $QUIT_DIALOG->add (my $vb = new DC::UI::VBox expand => 1);
2113 root 1.1
2114 root 1.18 $vb->add (new DC::UI::Label
2115 root 1.1 text => "You should find a savebed and apply it first!",
2116     max_w => $WIDTH * 0.25,
2117     ellipsize => 0,
2118     );
2119 root 1.18 $vb->add (my $hb = new DC::UI::HBox expand => 1);
2120     $hb->add (new DC::UI::Button
2121 root 1.1 text => "Ok",
2122     expand => 1,
2123     on_activate => sub { $QUIT_DIALOG->hide; 0 },
2124     );
2125 root 1.18 $hb->add (new DC::UI::Button
2126 root 1.1 text => "Quit anyway",
2127     expand => 1,
2128 root 1.4 on_activate => sub { EV::unloop EV::UNLOOP_ALL },
2129 root 1.1 );
2130     }
2131    
2132     $QUIT_DIALOG->show;
2133     $QUIT_DIALOG->grab_focus;
2134     }
2135    
2136     sub show_tip_of_the_day {
2137     # find all tips
2138 root 1.18 my @tod = DC::Pod::find tip_of_the_day => "*";
2139 root 1.1
2140 root 1.18 DC::DB::get state => "tip_of_the_day", sub {
2141 root 1.1 my ($todindex) = @_;
2142     $todindex = 0 if $todindex >= @tod;
2143 root 1.18 DC::DB::put state => tip_of_the_day => $todindex + 1, sub { };
2144 root 1.1
2145     # create dialog
2146     my $dialog;
2147    
2148     my $close = sub {
2149     $dialog->destroy;
2150     };
2151    
2152 root 1.18 $dialog = new DC::UI::Toplevel
2153 root 1.1 x => "center",
2154     y => "center",
2155     z => 3,
2156     name => 'tip_of_the_day',
2157     force_w => int $WIDTH * 4/9,
2158     force_h => int $WIDTH * 2/9,
2159     title => "Tip of the day #" . (1 + $todindex),
2160 root 1.18 child => my $vbox = new DC::UI::VBox,
2161 root 1.1 has_close_button => 1,
2162     on_delete => $close,
2163     ;
2164    
2165 root 1.18 $vbox->add (my $viewer = new DC::UI::TextScroller
2166 root 1.1 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4);
2167 root 1.18 $viewer->add_paragraph (DC::Pod::as_paragraphs DC::Pod::section_of $tod[$todindex]);
2168 root 1.1
2169 root 1.18 $vbox->add (my $table = new DC::UI::Table col_expand => [0, 1]);
2170 root 1.1
2171 root 1.18 $table->add_at (0, 0, new DC::UI::Button
2172 root 1.1 text => "Close",
2173     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>.",
2174     on_activate => $close,
2175     );
2176    
2177 root 1.18 $table->add_at (2, 0, new DC::UI::Button
2178 root 1.1 text => "Next",
2179     tooltip => "Show the next <b>Tip of the day</b>.",
2180     on_activate => sub {
2181     $close->();
2182     &show_tip_of_the_day;
2183     },
2184     );
2185    
2186     $dialog->show;
2187     };
2188     }
2189    
2190     sub sdl_init {
2191 root 1.52 DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE
2192 root 1.1 and die "SDL::Init failed!\n";
2193     }
2194    
2195     sub video_init {
2196 root 1.52 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2197     $SDL_REINIT = 0;
2198    
2199     @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8;
2200     @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2201     @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2202     @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2203    
2204     @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2205    
2206 root 1.56 if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) {
2207 root 1.52 $CFG->{sdl_mode} = 0;
2208     for (reverse 0 .. $#SDL_MODES) {
2209     $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600;
2210     }
2211     }
2212 root 1.1
2213     my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2214    
2215     ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2216     $FULLSCREEN = $CFG->{fullscreen};
2217     $FAST = $CFG->{fast};
2218    
2219 root 1.18 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2220     or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2221 root 1.1
2222     $SDL_ACTIVE = 1;
2223     $LAST_REFRESH = time - 0.01;
2224    
2225 root 1.18 DC::OpenGL::init;
2226     DC::Macro::init;
2227 root 1.1
2228     $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
2229    
2230 root 1.18 $DC::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
2231 root 1.1
2232     #############################################################################
2233    
2234     if ($DEBUG_STATUS) {
2235 root 1.18 DC::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
2236 root 1.1 } else {
2237     # create/configure the widgets
2238    
2239 root 1.18 $DC::UI::ROOT->connect (key_down => sub {
2240 root 1.1 my (undef, $ev) = @_;
2241    
2242 root 1.18 if (my @macros = DC::Macro::find $ev) {
2243     DC::Macro::execute $_ for @macros;
2244 root 1.1
2245     return 1;
2246     }
2247    
2248     0
2249     });
2250    
2251 root 1.18 $DEBUG_STATUS = new DC::UI::Label
2252 root 1.1 padding => 0,
2253     z => 100,
2254     force_x => "max",
2255     force_y => 0;
2256     $DEBUG_STATUS->show;
2257    
2258 root 1.18 $STATUSBOX = new DC::UI::Statusbox;
2259 root 1.29
2260     $MODBOX = new DC::UI::Label
2261     can_events => 1,
2262     can_hover => 1,
2263     markup => "",
2264     align => 0,
2265     font => $FONT_FIXED,
2266 root 1.30 tooltip => "#modifier_box",
2267     tooltip_width => 0.67,
2268     ;
2269 root 1.29
2270     update_modbox;
2271 root 1.1
2272 root 1.18 (new DC::UI::Frame
2273 root 1.1 bg => [0, 0, 0, 0.4],
2274     force_x => 0,
2275     force_y => "max",
2276 root 1.29 child => (my $LR = new DC::UI::VBox),
2277 root 1.1 )->show;
2278    
2279 root 1.29 $LR->add ($STATUSBOX);
2280     $LR->add ($MODBOX);
2281     $LR->add (new DC::UI::Label
2282     align => 0,
2283     markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode",
2284     fontsize => 0.5,
2285     fg => [1, 1, 0, 0.7],
2286     );
2287    
2288 root 1.18 DC::UI::Toplevel->new (
2289 root 1.2 title => "Minimap",
2290 root 1.1 name => "mapmap",
2291     x => 0,
2292     y => $FONTSIZE + 8,
2293     border_bg => [1, 1, 1, 192/255],
2294     bg => [1, 1, 1, 0],
2295 root 1.18 child => ($MAPMAP = new DC::MapWidget::MapMap
2296 root 1.1 tooltip => "<b>Map</b>. On servers that support this feature, this will display an overview of the surrounding areas.",
2297     ),
2298     )->show;
2299    
2300 root 1.18 $MAPWIDGET = new DC::MapWidget;
2301 root 1.1 $MAPWIDGET->connect (activate_console => sub {
2302     my ($mapwidget, $preset) = @_;
2303    
2304 elmex 1.23 $MESSAGE_DIST->activate_console ($preset)
2305     if $MESSAGE_DIST;
2306 root 1.1 });
2307     $MAPWIDGET->show;
2308     $MAPWIDGET->grab_focus;
2309    
2310 root 1.18 $COMPLETER = new DC::MapWidget::Command::
2311 root 1.1 command => { },
2312     tooltip => "#completer_help",
2313     ;
2314    
2315 root 1.18 $SETUP_DIALOG = new DC::UI::Toplevel
2316 root 1.1 title => "Setup",
2317     name => "setup_dialog",
2318     x => 'center',
2319     y => 'center',
2320     z => 2,
2321     force_w => $::WIDTH * 0.6,
2322     force_h => $::HEIGHT * 0.6,
2323     has_close_button => 1,
2324     ;
2325    
2326     $METASERVER = metaserver_dialog;
2327 root 1.39 # the name is changed to not conflict with the older name as users could have hidden it
2328 root 1.40 $MESSAGE_WINDOW = new DC::UI::Dockbar
2329     name => "message_window2",
2330     title => 'Messages',
2331     force_w => $::WIDTH * 0.6,
2332     force_h => $::HEIGHT * 0.25,
2333     ;
2334    
2335 elmex 1.23 $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW;
2336 root 1.1
2337 root 1.38 $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1,
2338 root 1.18 filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1);
2339 root 1.1
2340     $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup,
2341     "Configure the server to play on, your username and password.");
2342     $SETUP_NOTEBOOK->add_tab (Server => $SETUP_SERVER = server_setup,
2343     "Configure other server related options.");
2344     $SETUP_NOTEBOOK->add_tab (Client => client_setup,
2345     "Configure various client-specific settings.");
2346     $SETUP_NOTEBOOK->add_tab (Graphics => graphics_setup,
2347     "Configure the video mode, performance, fonts and other graphical aspects of the game.");
2348     $SETUP_NOTEBOOK->add_tab (Audio => audio_setup,
2349     "Configure the use of audio, sound effects and background music.");
2350     $SETUP_NOTEBOOK->add_tab (Keyboard => $SETUP_KEYBOARD = keyboard_setup,
2351     "Lets you define, edit and delete key bindings."
2352     . "There is a shortcut for making bindings: <b>Control-Insert</b> opens the binding editor "
2353     . "with nothing set and the recording started. After doing the actions you "
2354     . "want to record press <b>Insert</b> and you will be asked to press a key-combo. "
2355     . "After pressing the combo the binding will be saved automatically and the "
2356     . "binding editor closes");
2357     $SETUP_NOTEBOOK->add_tab (Debug => debug_setup,
2358     "Some debuggin' options. Do not ask.");
2359    
2360 root 1.18 $BUTTONBAR = new DC::UI::Buttonbar x => 0, y => 0, z => 200; # put on top
2361 root 1.1
2362 root 1.18 $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG,
2363 root 1.1 tooltip => "Toggles a dialog where you can configure all aspects of this client.");
2364    
2365 root 1.37 # $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW,
2366     # tooltip => "Toggles the server message log, where the client collects <i>all</i> messages from the server.");
2367 root 1.1
2368     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
2369    
2370 root 1.18 $BUTTONBAR->add (new DC::UI::Flopper text => "Playerbook", other => player_window,
2371 root 1.1 tooltip => "Toggles the player view, where you can manage Inventory, Spells, Skills and see your Stats.");
2372    
2373 root 1.18 $BUTTONBAR->add (new DC::UI::Button
2374 root 1.1 text => "Save Config",
2375     tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.",
2376     on_activate => sub {
2377 root 1.18 $::CFG->{layout} = DC::UI::get_layout;
2378 root 1.35 DC::write_cfg;
2379 root 1.1 status "Configuration Saved";
2380     0
2381     },
2382     );
2383    
2384 root 1.18 $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window,
2385 root 1.1 tooltip => "View Documentation");
2386    
2387 root 1.18 $BUTTONBAR->add (new DC::UI::Button
2388 root 1.1 text => "Quit",
2389     tooltip => "Terminates the program",
2390     on_activate => sub {
2391     if ($CONN) {
2392     open_quit_dialog;
2393     } else {
2394 root 1.4 EV::unloop EV::UNLOOP_ALL;
2395 root 1.1 }
2396     0
2397     },
2398     );
2399    
2400     $BUTTONBAR->show;
2401     $SETUP_DIALOG->show;
2402     $MESSAGE_WINDOW->show;
2403     }
2404    
2405 root 1.53 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]);
2406     $MODE_SLIDER->emit (changed => $CFG->{sdl_mode});
2407    
2408     $CAVEAT_LABEL->set_text ("None :)");
2409 root 1.55 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)")
2410 root 1.53 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL;
2411    
2412 root 1.1 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2413     }
2414    
2415     sub video_shutdown {
2416 root 1.18 DC::OpenGL::shutdown;
2417 root 1.52 DC::SDL_QuitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2418 root 1.1
2419     undef $SDL_ACTIVE;
2420     }
2421    
2422     my %animate_object;
2423     my $animate_timer;
2424    
2425     my $fps = 9;
2426    
2427     sub force_refresh {
2428     if ($ENV{CFPLUS_DEBUG} & 4) {
2429     $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2430     debug sprintf "%3.2f", $fps;
2431     }
2432    
2433 root 1.16 undef $WANT_REFRESH;
2434     $_[0]->stop;
2435 root 1.12
2436 root 1.18 $DC::UI::ROOT->draw;
2437     DC::SDL_GL_SwapBuffers;
2438 root 1.1 $LAST_REFRESH = $NOW;
2439     }
2440    
2441 root 1.19 my $want_refresh = EV::prepare_ns \&force_refresh;
2442 root 1.1
2443 root 1.19 my $input = EV::periodic 0, 1 / $MAX_FPS, undef, sub {
2444     $NOW = EV::now;
2445 root 1.1
2446     ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2447 root 1.18 for DC::poll_events;
2448 root 1.1
2449     if (%animate_object) {
2450     $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2451 root 1.16 $WANT_REFRESH = 1;
2452 root 1.1 }
2453 root 1.16
2454     $want_refresh->start
2455     if $WANT_REFRESH;
2456 root 1.4 };
2457 root 1.1
2458     sub animation_start {
2459     my ($widget) = @_;
2460     $animate_object{$widget} = $widget;
2461     }
2462    
2463     sub animation_stop {
2464     my ($widget) = @_;
2465     delete $animate_object{$widget};
2466     }
2467    
2468     %SDL_CB = (
2469 root 1.18 DC::SDL_QUIT => sub {
2470 root 1.4 EV::unloop EV::UNLOOP_ALL;
2471 root 1.1 },
2472 root 1.18 DC::SDL_VIDEORESIZE => sub {
2473 root 1.1 },
2474 root 1.18 DC::SDL_VIDEOEXPOSE => sub {
2475     DC::UI::full_refresh;
2476 root 1.1 },
2477 root 1.18 DC::SDL_ACTIVEEVENT => sub {
2478 root 1.12 # not useful, as APPACTIVE includes only iconified state, not unmapped
2479 root 1.18 # printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, DC::SDL_GetAppState;#d#
2480     # printf "a %x\n", DC::SDL_GetAppState & DC::SDL_APPACTIVE;#d#
2481     # printf "A\n" if $_[0]{state} & DC::SDL_APPACTIVE;
2482     # printf "K\n" if $_[0]{state} & DC::SDL_APPINPUTFOCUS;
2483     # printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS;
2484 root 1.1 },
2485 root 1.18 DC::SDL_KEYDOWN => sub {
2486     if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) {
2487 root 1.1 # alt-enter
2488 root 1.52 video_shutdown;
2489 root 1.1 $FULLSCREEN_ENABLE->toggle;
2490     video_init;
2491     } else {
2492 root 1.29 &DC::UI::feed_sdl_key_down_event;
2493 root 1.1 }
2494 root 1.29 update_modbox;
2495     },
2496     DC::SDL_KEYUP => sub {
2497     &DC::UI::feed_sdl_key_up_event;
2498     update_modbox;
2499 root 1.1 },
2500 root 1.18 DC::SDL_MOUSEMOTION => \&DC::UI::feed_sdl_motion_event,
2501     DC::SDL_MOUSEBUTTONDOWN => \&DC::UI::feed_sdl_button_down_event,
2502     DC::SDL_MOUSEBUTTONUP => \&DC::UI::feed_sdl_button_up_event,
2503     DC::SDL_USEREVENT => sub {
2504 root 1.1 if ($_[0]{code} == 1) {
2505     audio_channel_finished $_[0]{data1};
2506     } elsif ($_[0]{code} == 0) {
2507     audio_music_finished;
2508     }
2509     },
2510     );
2511    
2512     #############################################################################
2513    
2514 root 1.11 $SIG{INT} = $SIG{TERM} = sub {
2515     EV::unloop;
2516     #d# TODO calling exit here hangs the process in some futex
2517     };
2518 root 1.1
2519     {
2520 root 1.34 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2521    
2522 root 1.15 if (-e "$Deliantra::VARDIR/client.cf") {
2523 root 1.18 DC::read_cfg "$Deliantra::VARDIR/client.cf";
2524 root 1.15 } else {
2525     #TODO: compatibility cruft
2526 root 1.18 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2527 root 1.27 print STDERR "INFO: used old configuration file\n";
2528 root 1.15 }
2529    
2530 root 1.18 DC::DB::Server::run;
2531 root 1.35
2532     if ($CFG->{db_schema} < 1) {
2533     warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2534     DC::DB::nuke_db;
2535     $CFG->{db_schema} = 1;
2536     DC::write_cfg;
2537     }
2538    
2539 root 1.33 DC::DB::open_db;
2540 root 1.1
2541 root 1.18 DC::UI::set_layout ($::CFG->{layout});
2542 root 1.1
2543     my %DEF_CFG = (
2544     sdl_mode => 0,
2545 root 1.3 fullscreen => 1,
2546 root 1.1 fast => 0,
2547     force_opengl11 => undef,
2548 root 1.52 disable_alpha => 0,
2549 root 1.56 smooth_movement => 1,
2550 root 1.1 texture_compression => 1,
2551     map_scale => 1,
2552     fow_enable => 1,
2553     fow_intensity => 0,
2554     map_smoothing => 1,
2555     gui_fontsize => 1,
2556     log_fontsize => 0.7,
2557     gauge_fontsize => 1,
2558     gauge_size => 0.35,
2559     stat_fontsize => 0.7,
2560     mapsize => 100,
2561     audio_enable => 1,
2562     audio_hw_channels => 0,
2563     audio_hw_frequency => 0,
2564     audio_hw_chunksize => 0,
2565     audio_mix_channels => 8,
2566     effects_enable => 1,
2567     effects_volume => 1,
2568     bgm_enable => 1,
2569     bgm_volume => 0.5,
2570     output_rate => "",
2571     pickup => 0,
2572     inv_sort => "mtime",
2573     default => "profile", # default profile
2574     show_tips => 1,
2575     logview_max_par => 1000,
2576 elmex 1.42 shift_fire_stop => 0,
2577 root 1.1 );
2578    
2579     while (my ($k, $v) = each %DEF_CFG) {
2580     $CFG->{$k} = $v unless exists $CFG->{$k};
2581     }
2582    
2583     $CFG->{profile}{default}{host} ||= "gameserver.deliantra.net";
2584     $PROFILE = $CFG->{profile}{default};
2585    
2586     # convert old bindings (only default profile matters)
2587     if (my $bindings = delete $PROFILE->{bindings}) {
2588     while (my ($mod, $syms) = each %$bindings) {
2589     while (my ($sym, $cmds) = each %$syms) {
2590     push @{ $PROFILE->{macro} }, {
2591     accelkey => [$mod*1, $sym*1],
2592     action => $cmds,
2593     };
2594     }
2595     }
2596     }
2597    
2598     sdl_init;
2599    
2600     {
2601 root 1.18 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2602 root 1.1 DejaVuSans.ttf
2603     DejaVuSansMono.ttf
2604     DejaVuSans-Bold.ttf
2605     DejaVuSansMono-Bold.ttf
2606     DejaVuSans-Oblique.ttf
2607     DejaVuSansMono-Oblique.ttf
2608     DejaVuSans-BoldOblique.ttf
2609     DejaVuSansMono-BoldOblique.ttf
2610     );
2611    
2612 root 1.18 DC::add_font $_ for @fonts;
2613 root 1.1
2614 root 1.18 $FONT_PROP = new_from_file DC::Font $fonts[0];
2615     $FONT_FIXED = new_from_file DC::Font $fonts[1];
2616 root 1.1
2617     $FONT_PROP->make_default;
2618 root 1.30
2619     DC::pango_init;
2620 root 1.1 }
2621    
2622     # compare mono (ft) vs. rgba (cairo)
2623     # ft - 1.8s, cairo 3s, even in alpha-only mode
2624     # for my $rgba (0..1) {
2625     # my $t1 = Time::HiRes::time;
2626     # for (1..1000) {
2627 root 1.18 # my $layout = DC::Layout->new ($rgba);
2628 root 1.1 # $layout->set_text ("hallo" x 100);
2629     # $layout->render;
2630     # }
2631     # my $t2 = Time::HiRes::time;
2632     # warn $t2-$t1;
2633     # }
2634    
2635     video_init;
2636     audio_init;
2637     }
2638    
2639     show_tip_of_the_day if $CFG->{show_tips};
2640    
2641 root 1.4 our $STARTUP_CANCEL = EV::idle sub {
2642     undef $::STARTUP_CANCEL;
2643 root 1.1 $startup_done->();
2644 root 1.4 };
2645 root 1.1
2646 root 1.36 delete $SIG{__DIE__};
2647 root 1.4 EV::loop;
2648 root 1.1
2649     #video_shutdown;
2650     #audio_shutdown;
2651 root 1.18 DC::OpenGL::quit;
2652     DC::SDL_Quit;
2653     DC::DB::Server::stop;
2654 root 1.1
2655     =head1 NAME
2656    
2657     deliantra - A Deliantra MORPG game client
2658    
2659     =head1 SYNOPSIS
2660    
2661     Just run it - no commandline arguments are supported.
2662    
2663     =head1 USAGE
2664    
2665     deliantra utilises OpenGL for all UI elements and the game. It is supposed to
2666     be used in fullscreen mode and interactively.
2667    
2668     =head1 DEBUGGING
2669    
2670    
2671     CFPLUS_DEBUG - environment variable
2672    
2673     1 draw borders around widgets
2674     2 add low-level widget info to tooltips
2675     4 show fps
2676     8 suppress tooltips
2677    
2678     =head1 AUTHOR
2679    
2680     Marc Lehmann <crossfire@schmorp.de>, Robin Redeker <elmex@ta-sa.org>
2681    
2682    
2683