ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/deliantra (file contents):
Revision 1.5 by root, Wed Nov 14 23:50:29 2007 UTC vs.
Revision 1.106 by root, Sat Apr 3 03:02:28 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines