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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines