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

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.203 by root, Mon May 8 20:55:49 2006 UTC vs.
Revision 1.215 by root, Mon May 15 00:15:08 2006 UTC

37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use CFClient::MapWidget;
40 40
41$Event::DIED = sub { 41$Event::DIED = sub {
42 # TODO: display dialog box or so
42 CFClient::error $_[1]; 43 CFClient::error $_[1];
43}; 44};
44 45
45#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# 46#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
46 47
59our $NOW; 60our $NOW;
60 61
61our $CFG; 62our $CFG;
62our $CONN; 63our $CONN;
63our $FAST; # fast, low-quality mode, possibly useful for software-rendering 64our $FAST; # fast, low-quality mode, possibly useful for software-rendering
65
66our $WANT_REFRESH;
67our $CAN_REFRESH;
64 68
65our @SDL_MODES; 69our @SDL_MODES;
66our $WIDTH; 70our $WIDTH;
67our $HEIGHT; 71our $HEIGHT;
68our $FULLSCREEN; 72our $FULLSCREEN;
90our $SDL_MIXER; 94our $SDL_MIXER;
91our @SOUNDS; # event => file mapping 95our @SOUNDS; # event => file mapping
92our %AUDIO_CHUNKS; # audio files 96our %AUDIO_CHUNKS; # audio files
93 97
94our $ALT_ENTER_MESSAGE; 98our $ALT_ENTER_MESSAGE;
95our $STATUS_LINE; 99our $STATUSBOX;
96our $DEBUG_STATUS; 100our $DEBUG_STATUS;
97 101
98our $INVWIN; 102our $INVWIN;
99our $INV; 103our $INV;
100 104
101sub status { 105sub status {
102 $STATUS_LINE->set_text ($_[0]); 106 $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]);
103 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
104} 107}
105 108
106sub debug { 109sub debug {
107 $DEBUG_STATUS->set_text ($_[0]); 110 $DEBUG_STATUS->set_text ($_[0]);
108 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 111 my ($w, $h) = $DEBUG_STATUS->size_request;
112 $DEBUG_STATUS->move ($WIDTH - $w, 0);
109} 113}
110 114
111sub start_game { 115sub start_game {
112 status "logging in..."; 116 status "logging in...";
113 117
365# local $GAUGES->{win}{parent};#d# 369# local $GAUGES->{win}{parent};#d#
366# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D; 370# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D;
367} 371}
368 372
369sub make_gauge_window { 373sub make_gauge_window {
370 my $gh = int ($HEIGHT * $CFG->{gauge_size}); 374 my $gh = int $HEIGHT * $CFG->{gauge_size};
371# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
372 375
373 my $win = new CFClient::UI::Frame ( 376 my $win = new CFClient::UI::Frame (
374 y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh 377 req_y => -1,
378 user_w => $WIDTH,
379 user_h => $gh,
375 ); 380 );
381
376 $win->add (my $hbox = new CFClient::UI::HBox 382 $win->add (my $hbox = new CFClient::UI::HBox
377 children => [ 383 children => [
378 (new CFClient::UI::HBox expand => 1), 384 (new CFClient::UI::HBox expand => 1),
379 ($FLOORBOX = new CFClient::UI::VBox), 385 (new CFClient::UI::VBox children => [
386 (new CFClient::UI::Empty expand => 1),
387 (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::VBox)),
388 ]),
380 (my $vbox = new CFClient::UI::VBox), 389 (my $vbox = new CFClient::UI::VBox),
381 ], 390 ],
382 ); 391 );
383 392
384 $vbox->add (new CFClient::UI::HBox 393 $vbox->add (new CFClient::UI::HBox
838 847
839 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 848 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
840 849
841 ############################################################################# 850 #############################################################################
842 851
843 if ($DEBUG_STATUS) { 852 unless ($DEBUG_STATUS) {
844 # reconfigure all widgets
845 $CFClient::UI::ROOT->reconfigure;
846
847 } else {
848 # create the widgets 853 # create the widgets
849 854
850 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 855 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1;
851 $DEBUG_STATUS->show; 856 $DEBUG_STATUS->show;
852 857
853 $STATUS_LINE = new CFClient::UI::Label 858 $STATUSBOX = new CFClient::UI::Statusbox;
854 padding => 0, 859 $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, color => [1, 1, 1, 0.8]);
855 y => $HEIGHT - $FONTSIZE * 1.8;
856 $STATUS_LINE->show;
857 860
858 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 861 (new CFClient::UI::Frame
859 padding => 0, 862 bg => [0, 0, 0, 0.4],
860 fontsize => 0.8, 863 req_y => -1,
861 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 864 child => $STATUSBOX,
862 $ALT_ENTER_MESSAGE->show; 865 )->show;
863 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
864 866
865 CFClient::UI::FancyFrame->new ( 867 CFClient::UI::FancyFrame->new (
866 border_bg => [1, 1, 1, 192/255], 868 border_bg => [1, 1, 1, 192/255],
867 bg => [1, 1, 1, 0], 869 bg => [1, 1, 1, 0],
868 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 870 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
900 status "Configuration Saved"; 902 status "Configuration Saved";
901 }); 903 });
902 904
903 $BUTTONBAR->show; 905 $BUTTONBAR->show;
904 906
907 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
908
909 # delay till geometry is constant
910 $CFClient::UI::ROOT->on_post_alloc (startup => sub {
905 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 911 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
912 my $widget = $GAUGES->{win};
913 $widget->move (0, $HEIGHT - $widget->{h});#d# to in toplevel
914 });
915 force_refresh ();
906 } 916 }
907} 917}
908 918
909sub video_shutdown { 919sub video_shutdown {
910 undef $SDL_ACTIVE; 920 undef $SDL_ACTIVE;
966} 976}
967 977
968my %animate_object; 978my %animate_object;
969my $animate_timer; 979my $animate_timer;
970 980
971my $want_refresh;
972my $can_refresh;
973
974my $fps = 9; 981my $fps = 9;
975 982
976sub force_refresh { 983sub force_refresh {
977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 984 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
978 debug sprintf "%3.2f", $fps; 985 debug sprintf "%3.2f", $fps;
979 986
980 $want_refresh = 0;
981 $can_refresh = 0;
982
983 $CFClient::UI::ROOT->draw; 987 $CFClient::UI::ROOT->draw;
984
985 CFClient::SDL_GL_SwapBuffers; 988 CFClient::SDL_GL_SwapBuffers;
986 989
990 $WANT_REFRESH = 0;
991 $CAN_REFRESH = 0;
987 $LAST_REFRESH = $NOW; 992 $LAST_REFRESH = $NOW;
988} 993}
989 994
990my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 995my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
991 $NOW = time; 996 $NOW = time;
993 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 998 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
994 for CFClient::SDL_PollEvent; 999 for CFClient::SDL_PollEvent;
995 1000
996 if (%animate_object) { 1001 if (%animate_object) {
997 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 1002 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
998 $want_refresh++; 1003 $WANT_REFRESH++;
999 } 1004 }
1000 1005
1001 if ($want_refresh) { 1006 if ($WANT_REFRESH) {
1002 force_refresh; 1007 force_refresh;
1003 } else { 1008 } else {
1004 $can_refresh = 1; 1009 $CAN_REFRESH = 1;
1005 } 1010 }
1006}); 1011});
1007
1008sub refresh {
1009 $want_refresh++;
1010}
1011 1012
1012sub animation_start { 1013sub animation_start {
1013 my ($widget) = @_; 1014 my ($widget) = @_;
1014 $animate_object{$widget} = $widget; 1015 $animate_object{$widget} = $widget;
1015} 1016}
1327 [0.55, 0.41, 0.13], 1328 [0.55, 0.41, 0.13],
1328 [0.99, 0.77, 0.26], 1329 [0.99, 0.77, 0.26],
1329 [0.74, 0.65, 0.41], 1330 [0.74, 0.65, 0.41],
1330 ); 1331 );
1331 1332
1333 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
1334
1335 $text =~ s/&/&amp;/g; $text =~ s/</&lt;/g;
1336 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
1337 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
1338
1332 $LOGVIEW->add_paragraph ($color[$color], $text); 1339 $LOGVIEW->add_paragraph ($color[$color],
1340 join "\n", map "$time $_", split /\n/, $text);
1341
1342 $STATUSBOX->add ($text,
1343 group => $text,
1344 fg => $color[$color],
1345 timeout => 60,
1346 tooltip_font => $::FONT_FIXED,
1347 );
1348}
1349
1350sub conn::drawextinfo {
1351 my ($self, $color, $type, $subtype, $message) = @_;
1352
1353 $self->drawinfo ($color, $message);
1333} 1354}
1334 1355
1335sub conn::spell_add { 1356sub conn::spell_add {
1336 my ($self, $spell) = @_; 1357 my ($self, $spell) = @_;
1337 1358
1368 return unless $CONN; 1389 return unless $CONN;
1369 1390
1370 $FLOORBOX->clear; 1391 $FLOORBOX->clear;
1371 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1392 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1372 1393
1373 # we basically have to use the same sorting as everybody else 1394 my $count = 4;
1374 for my $item (@{ $CONN->{container}{0} }) { 1395 for (@{ $CONN->{container}{0} }) {
1396 if (--$count) {
1375 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1397 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1398 } else {
1399 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
1400 last;
1401 }
1376 } 1402 }
1377 }); 1403 });
1378 refresh; 1404
1405 $WANT_REFRESH++;
1379} 1406}
1380 1407
1381sub conn::container_add { 1408sub conn::container_add {
1382 my ($self, $tag, $items) = @_; 1409 my ($self, $tag, $items) = @_;
1383 1410
1416 my ($self, $item) = @_; 1443 my ($self, $item) = @_;
1417 1444
1418 update_floorbox if $item->{container} == 0; 1445 update_floorbox if $item->{container} == 0;
1419 1446
1420 $INV->set_items ($self->{container}{$item->{container}}) 1447 $INV->set_items ($self->{container}{$item->{container}})
1421 if $item->{container}; == $self->{player}{tag}; 1448 if $item->{container} == $self->{player}{tag};
1422} 1449}
1423 1450
1424%SDL_CB = ( 1451%SDL_CB = (
1425 CFClient::SDL_QUIT => sub { 1452 CFClient::SDL_QUIT => sub {
1426 Event::unloop -1; 1453 Event::unloop -1;
1427 }, 1454 },
1428 CFClient::SDL_VIDEORESIZE => sub { 1455 CFClient::SDL_VIDEORESIZE => sub {
1429 }, 1456 },
1430 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1457 CFClient::SDL_VIDEOEXPOSE => sub {
1458 $WANT_REFRESH++;
1459 },
1431 CFClient::SDL_ACTIVEEVENT => sub { 1460 CFClient::SDL_ACTIVEEVENT => sub {
1432# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1461# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1433 }, 1462 },
1434 CFClient::SDL_KEYDOWN => sub { 1463 CFClient::SDL_KEYDOWN => sub {
1435 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1464 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1456 1485
1457############################################################################# 1486#############################################################################
1458 1487
1459$SIG{INT} = $SIG{TERM} = sub { exit }; 1488$SIG{INT} = $SIG{TERM} = sub { exit };
1460 1489
1461CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1462
1463$TILECACHE = CFClient::db_table "tilecache";
1464$FACEMAP = CFClient::db_table "facemap";
1465
1466my %DEF_CFG = (
1467 sdl_mode => 0,
1468 width => 640,
1469 height => 480,
1470 fullscreen => 0,
1471 fast => 0,
1472 map_scale => 0.5,
1473 fow_enable => 1,
1474 fow_intensity => 0.45,
1475 fow_smooth => 0,
1476 gui_fontsize => 1,
1477 log_fontsize => 1,
1478 gauge_fontsize => 1,
1479 gauge_size => 0.35,
1480 stat_fontsize => 1,
1481 mapsize => 100,
1482 host => "crossfire.schmorp.de",
1483 say_command => 'say',
1484 audio_enable => 1,
1485 bgm_enable => 1,
1486 bgm_volume => 0.25,
1487);
1488
1489while (my ($k, $v) = each %DEF_CFG) {
1490 $CFG->{$k} = $v unless exists $CFG->{$k};
1491}
1492
1493sdl_init;
1494
1495@SDL_MODES = reverse
1496 grep $_->[0] >= 640 && $_->[1] >= 480,
1497 CFClient::SDL_ListModes;
1498
1499@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1500
1501$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1502
1503{ 1490{
1491 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1492
1493 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1494
1495 $TILECACHE = CFClient::db_table "tilecache";
1496 $FACEMAP = CFClient::db_table "facemap";
1497
1498 my %DEF_CFG = (
1499 sdl_mode => 0,
1500 width => 640,
1501 height => 480,
1502 fullscreen => 0,
1503 fast => 0,
1504 map_scale => 0.5,
1505 fow_enable => 1,
1506 fow_intensity => 0.45,
1507 fow_smooth => 0,
1508 gui_fontsize => 1,
1509 log_fontsize => 1,
1510 gauge_fontsize=> 1,
1511 gauge_size => 0.35,
1512 stat_fontsize => 1,
1513 mapsize => 100,
1514 host => "crossfire.schmorp.de",
1515 say_command => 'say',
1516 audio_enable => 1,
1517 bgm_enable => 1,
1518 bgm_volume => 0.25,
1519 );
1520
1521 while (my ($k, $v) = each %DEF_CFG) {
1522 $CFG->{$k} = $v unless exists $CFG->{$k};
1523 }
1524
1525 sdl_init;
1526
1527 @SDL_MODES = reverse
1528 grep $_->[0] >= 640 && $_->[1] >= 480,
1529 CFClient::SDL_ListModes;
1530
1531 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1532
1533 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1534
1535 {
1504 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1536 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1505 DejaVuSans.ttf 1537 DejaVuSans.ttf
1506 DejaVuSansMono.ttf 1538 DejaVuSansMono.ttf
1507 DejaVuSans-Bold.ttf 1539 DejaVuSans-Bold.ttf
1508 DejaVuSansMono-Bold.ttf 1540 DejaVuSansMono-Bold.ttf
1509 DejaVuSans-Oblique.ttf 1541 DejaVuSans-Oblique.ttf
1510 DejaVuSansMono-Oblique.ttf 1542 DejaVuSansMono-Oblique.ttf
1511 DejaVuSans-BoldOblique.ttf 1543 DejaVuSans-BoldOblique.ttf
1512 DejaVuSansMono-BoldOblique.ttf 1544 DejaVuSansMono-BoldOblique.ttf
1513 ); 1545 );
1514 1546
1515 CFClient::add_font $_ for @fonts; 1547 CFClient::add_font $_ for @fonts;
1516 1548
1549 CFClient::pango_init;
1550
1517 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1551 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1518 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1552 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1519 1553
1520 $FONT_PROP->make_default; 1554 $FONT_PROP->make_default;
1521} 1555 }
1522 1556
1523video_init; 1557 video_init;
1524audio_init; 1558 audio_init;
1559}
1525 1560
1526Event::loop; 1561Event::loop;
1527 1562
1528END { CFClient::SDL_Quit } 1563END { CFClient::SDL_Quit }
1529 1564

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines