1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
|
|
6 | # do things only needed for single-binary version (par) |
6 | BEGIN { |
7 | BEGIN { |
7 | if (%PAR::LibCache) { |
8 | if (%PAR::LibCache) { |
8 | @INC = grep ref, @INC; # weed out all paths except pars loader refs |
9 | @INC = grep ref, @INC; # weed out all paths except pars loader refs |
9 | |
10 | |
10 | while (my ($filename, $zip) = each %PAR::LibCache) { |
11 | while (my ($filename, $zip) = each %PAR::LibCache) { |
… | |
… | |
13 | $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1") |
14 | $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1") |
14 | unless -e "$ENV{PAR_TEMP}/$1"; |
15 | unless -e "$ENV{PAR_TEMP}/$1"; |
15 | } |
16 | } |
16 | } |
17 | } |
17 | |
18 | |
|
|
19 | # TODO: pango-rc file, anybody? |
|
|
20 | |
18 | unshift @INC, $ENV{PAR_TEMP}; |
21 | unshift @INC, $ENV{PAR_TEMP}; |
19 | |
|
|
20 | if ($^O eq "MSWin32") { |
|
|
21 | $ENV{GTK_RC_FILES} = "$ENV{PAR_TEMP}/share/themes/MS-Windows/gtk-2.0/gtkrc"; |
|
|
22 | } |
|
|
23 | } |
22 | } |
24 | } |
23 | } |
25 | |
24 | |
26 | # need to do it again because that pile of garbage called PAR nukes it before main |
25 | # need to do it again because that pile of garbage called PAR nukes it before main |
27 | unshift @INC, $ENV{PAR_TEMP}; |
26 | unshift @INC, $ENV{PAR_TEMP} |
|
|
27 | if %PAR::LibCache; |
28 | |
28 | |
29 | use Time::HiRes 'time'; |
29 | use Time::HiRes 'time'; |
|
|
30 | use Pod::POM; |
30 | use Event; |
31 | use Event; |
31 | |
32 | |
32 | use Crossfire; |
33 | use Crossfire; |
33 | use Crossfire::Protocol; |
34 | use Crossfire::Protocol; |
34 | |
35 | |
… | |
… | |
100 | our $DEBUG_STATUS; |
101 | our $DEBUG_STATUS; |
101 | |
102 | |
102 | our $INVWIN; |
103 | our $INVWIN; |
103 | our $INV; |
104 | our $INV; |
104 | our $INVR; |
105 | our $INVR; |
|
|
106 | our $INVR_LBL; |
105 | our $OPENCONT; |
107 | our $OPENCONT; |
106 | |
108 | |
107 | sub status { |
109 | sub status { |
108 | $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]); |
110 | $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]); |
109 | } |
111 | } |
… | |
… | |
134 | maph => $mapsize, |
136 | maph => $mapsize, |
135 | ; |
137 | ; |
136 | }; |
138 | }; |
137 | |
139 | |
138 | if ($CONN) { |
140 | if ($CONN) { |
|
|
141 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
142 | |
139 | $LOGIN_BUTTON->set_text ("Logout"); |
143 | $LOGIN_BUTTON->set_text ("Logout"); |
140 | |
|
|
141 | status "login successful"; |
144 | status "login successful"; |
142 | |
145 | |
143 | CFClient::lowdelay fileno $CONN->{fh}; |
146 | $BUTTONBAR->{children}[1]->emit ("activate") |
|
|
147 | if $BUTTONBAR->{children}[1]->{state}; |
|
|
148 | |
144 | } else { |
149 | } else { |
145 | status "unable to connect"; |
150 | status "unable to connect"; |
146 | stop_game(); |
151 | stop_game(); |
147 | } |
152 | } |
148 | } |
153 | } |
… | |
… | |
152 | |
157 | |
153 | status "connection closed"; |
158 | status "connection closed"; |
154 | $LOGIN_BUTTON->set_text ("Login"); |
159 | $LOGIN_BUTTON->set_text ("Login"); |
155 | $CONN->destroy; |
160 | $CONN->destroy; |
156 | $CONN = 0; # false, does not autovivify |
161 | $CONN = 0; # false, does not autovivify |
|
|
162 | |
|
|
163 | $BUTTONBAR->{children}[1]->emit ("activate") |
|
|
164 | unless $BUTTONBAR->{children}[1]->{state}; |
157 | |
165 | |
158 | undef $MAPCACHE; |
166 | undef $MAPCACHE; |
159 | undef $MAP; |
167 | undef $MAP; |
160 | } |
168 | } |
161 | |
169 | |
… | |
… | |
665 | $HOST->set_text ($CFG->{host} = $host); |
673 | $HOST->set_text ($CFG->{host} = $host); |
666 | }), |
674 | }), |
667 | (new CFClient::UI::Empty expand => 1), |
675 | (new CFClient::UI::Empty expand => 1), |
668 | ]); |
676 | ]); |
669 | |
677 | |
670 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
678 | $table->add ($_ + 1, $y, new CFClient::UI::Label |
|
|
679 | ellipsise => 0, align => $align[$_], text => $m->[$_], fontsize => 0.8) |
671 | for 0 .. $#$m; |
680 | for 0 .. $#$m; |
672 | } |
681 | } |
673 | } |
682 | } |
674 | }); |
683 | }); |
675 | } |
684 | } |
… | |
… | |
813 | sub make_inventory_window { |
822 | sub make_inventory_window { |
814 | my $invwin = new CFClient::UI::FancyFrame |
823 | my $invwin = new CFClient::UI::FancyFrame |
815 | user_w => $WIDTH * (4/5), user_h => $HEIGHT * (4/5), title => "Inventory"; |
824 | user_w => $WIDTH * (4/5), user_h => $HEIGHT * (4/5), title => "Inventory"; |
816 | |
825 | |
817 | $invwin->add (my $hb = new CFClient::UI::HBox); |
826 | $invwin->add (my $hb = new CFClient::UI::HBox); |
|
|
827 | |
|
|
828 | $hb->add (my $vb1 = new CFClient::UI::VBox expand => 1); |
|
|
829 | $vb1->add (my $lbl = new CFClient::UI::Label); |
|
|
830 | $lbl->set_text ("Player"); |
818 | $hb->add ($INV = new CFClient::UI::Inventory expand => 1); |
831 | $vb1->add ($INV = new CFClient::UI::Inventory expand => 1); |
|
|
832 | |
|
|
833 | $hb->add (my $vb2 = new CFClient::UI::VBox expand => 1); |
|
|
834 | $vb2->add ($INVR_LBL = new CFClient::UI::Label); |
|
|
835 | $INVR_LBL->set_text ("Floor"); |
819 | $hb->add ($INVR = new CFClient::UI::Inventory expand => 1); |
836 | $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); |
820 | |
837 | |
821 | $invwin |
838 | $invwin |
822 | } |
839 | } |
823 | |
840 | |
824 | sub sdl_init { |
841 | sub sdl_init { |
… | |
… | |
1022 | |
1039 | |
1023 | @conn::ISA = Crossfire::Protocol::; |
1040 | @conn::ISA = Crossfire::Protocol::; |
1024 | |
1041 | |
1025 | sub conn::stats_update { |
1042 | sub conn::stats_update { |
1026 | my ($self, $stats) = @_; |
1043 | my ($self, $stats) = @_; |
|
|
1044 | |
|
|
1045 | if (my $exp = $stats->{Crossfire::Protocol::CS_STAT_EXP64}) { |
|
|
1046 | my $diff = $exp - $self->{prev_exp}; |
|
|
1047 | $STATUSBOX->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) |
|
|
1048 | if exists $self->{prev_exp} && $diff; |
|
|
1049 | $self->{prev_exp} = $exp; |
|
|
1050 | } |
1027 | |
1051 | |
1028 | update_stats_window ($stats); |
1052 | update_stats_window ($stats); |
1029 | } |
1053 | } |
1030 | |
1054 | |
1031 | sub conn::user_send { |
1055 | sub conn::user_send { |
… | |
… | |
1330 | [0.74, 0.65, 0.41], |
1354 | [0.74, 0.65, 0.41], |
1331 | ); |
1355 | ); |
1332 | |
1356 | |
1333 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
1357 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
1334 | |
1358 | |
1335 | $text =~ s/&/&/g; $text =~ s/</</g; |
1359 | $text = CFClient::UI::Label::escape $text; |
1336 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
1360 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
1337 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
1361 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
1338 | |
1362 | |
1339 | $LOGVIEW->add_paragraph ($color[$color], |
1363 | $LOGVIEW->add_paragraph ($color[$color], |
1340 | join "\n", map "$time $_", split /\n/, $text); |
1364 | join "\n", map "$time $_", split /\n/, $text); |
… | |
… | |
1356 | sub conn::spell_add { |
1380 | sub conn::spell_add { |
1357 | my ($self, $spell) = @_; |
1381 | my ($self, $spell) = @_; |
1358 | |
1382 | |
1359 | # TODO |
1383 | # TODO |
1360 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
1384 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
1361 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}); |
1385 | $MAPWIDGET->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
1362 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}); |
1386 | $MAPWIDGET->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
1363 | } |
1387 | } |
1364 | |
1388 | |
1365 | sub conn::spell_delete { |
1389 | sub conn::spell_delete { |
1366 | my ($self, $spell) = @_; |
1390 | my ($self, $spell) = @_; |
1367 | } |
1391 | } |
1368 | |
1392 | |
1369 | sub conn::addme_success { |
1393 | sub conn::addme_success { |
1370 | my ($self) = @_; |
1394 | my ($self) = @_; |
1371 | |
1395 | |
|
|
1396 | $MAPWIDGET->clr_commands; |
|
|
1397 | |
1372 | for my $skill (values %{$self->{skill_info}}) { |
1398 | for my $skill (values %{$self->{skill_info}}) { |
1373 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
1399 | $MAPWIDGET->add_command ("ready_skill $skill", CFClient::UI::Label::escape "Ready the skill '$skill'"); |
1374 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
1400 | $MAPWIDGET->add_command ("use_skill $skill", CFClient::UI::Label::escape "Immediately use the skill '$skill'"); |
1375 | } |
1401 | } |
1376 | |
1402 | |
1377 | $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you"); |
1403 | $MAPWIDGET->add_command ("petmode defend", "Tell pets to stay close to you and defend you"); |
1378 | $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players"); |
1404 | $MAPWIDGET->add_command ("petmode arena", "Same as petmode sad, but also attack other players"); |
1379 | $MAPWIDGET->add_command ("pet\\_mode sad", "Search & Destroy - tell pets to roam about and attack enemies"); |
1405 | $MAPWIDGET->add_command ("petmode sad", "Search & Destroy - tell pets to roam about and attack enemies"); |
1380 | $MAPWIDGET->add_command ("kill\\_pets", "kill your pets"); |
1406 | $MAPWIDGET->add_command ("killpets", "Kill your pets"); |
|
|
1407 | $MAPWIDGET->add_command ("chat", "chat TEXT\nChat with all other players"); |
|
|
1408 | $MAPWIDGET->add_command ("shout", "shout TEXT\nShout loudly, used for emergencies"); |
|
|
1409 | $MAPWIDGET->add_command ("tell", "tell USERNAME TEXT\nPrivately tell a specific player"); |
|
|
1410 | |
|
|
1411 | my $parser = new Pod::POM; |
|
|
1412 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
|
|
1413 | |
|
|
1414 | for my $head2 ($pod->head2) { |
|
|
1415 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
|
|
1416 | or next; |
|
|
1417 | |
|
|
1418 | my $cmd = $1; |
|
|
1419 | my @args = split /\|/, $2; |
|
|
1420 | @args = (".*") unless @args; |
|
|
1421 | |
|
|
1422 | my $text = CFClient::pod_to_pango $head2->content; |
|
|
1423 | |
|
|
1424 | for my $arg (@args) { |
|
|
1425 | $arg = $arg eq ".*" ? "" : " $arg"; |
|
|
1426 | |
|
|
1427 | $MAPWIDGET->add_command ("$cmd$arg", $text); |
|
|
1428 | } |
|
|
1429 | } |
1381 | } |
1430 | } |
1382 | |
1431 | |
1383 | sub conn::eof { |
1432 | sub conn::eof { |
|
|
1433 | $MAPWIDGET->clr_commands; |
|
|
1434 | |
1384 | stop_game; |
1435 | stop_game; |
1385 | } |
1436 | } |
1386 | |
1437 | |
1387 | sub update_floorbox { |
1438 | sub update_floorbox { |
1388 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1439 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
… | |
… | |
1406 | } |
1457 | } |
1407 | |
1458 | |
1408 | sub conn::container_add { |
1459 | sub conn::container_add { |
1409 | my ($self, $tag, $items) = @_; |
1460 | my ($self, $tag, $items) = @_; |
1410 | |
1461 | |
|
|
1462 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
|
|
1463 | |
1411 | if ($tag == 0) { |
1464 | if ($tag == 0) { |
1412 | update_floorbox; |
1465 | update_floorbox; |
|
|
1466 | $OPENCONT = 0; |
|
|
1467 | $INVR_LBL->set_text ("Floor"); |
1413 | $INVR->set_items ($self->{container}{0}); |
1468 | $INVR->set_items ($self->{container}{0}); |
1414 | $OPENCONT = 0; |
|
|
1415 | } elsif ($tag == $self->{player}{tag}) { |
1469 | } elsif ($tag == $self->{player}{tag}) { |
|
|
1470 | $INVR_LBL->set_text ("Player"); |
1416 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1471 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1417 | } else { |
1472 | } else { |
1418 | $OPENCONT = $tag; |
1473 | $OPENCONT = $tag; |
|
|
1474 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
1419 | $INVR->set_items ($self->{container}{$tag}); |
1475 | $INVR->set_items ($self->{container}{$tag}); |
1420 | } |
1476 | } |
1421 | |
1477 | |
1422 | # $self-<{player}{tag} => player inv |
1478 | # $self-<{player}{tag} => player inv |
1423 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1479 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1424 | } |
1480 | } |
1425 | |
1481 | |
1426 | sub conn::container_clear { |
1482 | sub conn::container_clear { |
1427 | my ($self, $tag) = @_; |
1483 | my ($self, $tag) = @_; |
1428 | |
1484 | |
|
|
1485 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
|
|
1486 | |
1429 | if ($tag == 0) { |
1487 | if ($tag == 0) { |
1430 | update_floorbox; |
1488 | update_floorbox; |
|
|
1489 | $OPENCONT = 0; |
|
|
1490 | $INVR_LBL->set_text ("Floor"); |
1431 | $INVR->set_items ($self->{container}{0}); |
1491 | $INVR->set_items ($self->{container}{0}); |
1432 | $OPENCONT = 0; |
|
|
1433 | } elsif ($tag == $self->{player}{tag}) { |
1492 | } elsif ($tag == $self->{player}{tag}) { |
|
|
1493 | $INVR_LBL->set_text ("Player"); |
1434 | $INV->set_items ($self->{container}{$tag}) |
1494 | $INV->set_items ($self->{container}{$tag}) |
1435 | } else { |
1495 | } else { |
|
|
1496 | $OPENCONT = $tag; |
|
|
1497 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
1436 | $INVR->set_items ($self->{container}{$tag}); |
1498 | $INVR->set_items ($self->{container}{$tag}); |
1437 | $OPENCONT = $tag; |
|
|
1438 | } |
1499 | } |
1439 | |
1500 | |
1440 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1501 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1441 | } |
1502 | } |
1442 | |
1503 | |
1443 | sub conn::item_delete { |
1504 | sub conn::item_delete { |
1444 | my ($self, @items) = @_; |
1505 | my ($self, @items) = @_; |
1445 | |
1506 | |
1446 | for (@items) { |
1507 | for (@items) { |
|
|
1508 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
|
|
1509 | |
1447 | if ($_->{container} == 0) { |
1510 | if ($_->{container} == 0) { |
1448 | update_floorbox; |
1511 | update_floorbox; |
|
|
1512 | $OPENCONT = 0; |
|
|
1513 | $INVR_LBL->set_text ("Floor"); |
1449 | $INVR->set_items ($self->{container}{0}); |
1514 | $INVR->set_items ($self->{container}{0}); |
1450 | } elsif ($_->{container} == $self->{player}{tag}) { |
1515 | } elsif ($_->{container} == $self->{player}{tag}) { |
|
|
1516 | $INVR_LBL->set_text ("Player"); |
1451 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1517 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1452 | } else { |
1518 | } else { |
|
|
1519 | $OPENCONT = $_->{container}; |
|
|
1520 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
1453 | $INVR->set_items ($self->{container}{0}); |
1521 | $INVR->set_items ($self->{container}{$_->{container}}); |
1454 | } |
1522 | } |
1455 | } |
1523 | } |
1456 | } |
1524 | } |
1457 | |
1525 | |
1458 | sub conn::item_update { |
1526 | sub conn::item_update { |
1459 | my ($self, $item) = @_; |
1527 | my ($self, $item) = @_; |
1460 | |
1528 | |
1461 | if ($item->{container} == 0) { |
1529 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($OPENCONT)\n"; |
1462 | update_floorbox; |
1530 | |
|
|
1531 | if ($item->{tag} == $OPENCONT && not ($item->{flags} & Crossfire::Protocol::F_OPEN)) { |
|
|
1532 | $OPENCONT = 0; |
|
|
1533 | $INVR_LBL->set_text ("Floor"); |
1463 | $INVR->set_items ($self->{container}{0}); |
1534 | $INVR->set_items ($self->{container}{0}); |
|
|
1535 | |
|
|
1536 | $item->{widget}->update_item |
|
|
1537 | if $item->{widget}; |
|
|
1538 | } else { |
|
|
1539 | if ($item->{container} == 0) { |
|
|
1540 | update_floorbox; |
|
|
1541 | $OPENCONT = 0; |
|
|
1542 | $INVR_LBL->set_text ("Floor"); |
|
|
1543 | $INVR->set_items ($self->{container}{0}); |
1464 | } elsif ($item->{container} == $self->{player}{tag}) { |
1544 | } elsif ($item->{container} == $self->{player}{tag}) { |
1465 | $INV->set_items ($self->{container}{$item->{container}}) |
1545 | $INV->set_items ($self->{container}{$item->{container}}) |
|
|
1546 | } |
1466 | } |
1547 | } |
1467 | } |
1548 | } |
1468 | |
1549 | |
1469 | %SDL_CB = ( |
1550 | %SDL_CB = ( |
1470 | CFClient::SDL_QUIT => sub { |
1551 | CFClient::SDL_QUIT => sub { |
… | |
… | |
1570 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1651 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1571 | |
1652 | |
1572 | $FONT_PROP->make_default; |
1653 | $FONT_PROP->make_default; |
1573 | } |
1654 | } |
1574 | |
1655 | |
|
|
1656 | # compare mono (ft) vs. rgba (cairo) |
|
|
1657 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
|
|
1658 | # for my $rgba (0..1) { |
|
|
1659 | # my $t1 = Time::HiRes::time; |
|
|
1660 | # for (1..1000) { |
|
|
1661 | # my $layout = CFClient::Layout->new ($rgba); |
|
|
1662 | # $layout->set_text ("hallo" x 100); |
|
|
1663 | # $layout->render; |
|
|
1664 | # } |
|
|
1665 | # my $t2 = Time::HiRes::time; |
|
|
1666 | # warn $t2-$t1; |
|
|
1667 | # } |
|
|
1668 | |
1575 | video_init; |
1669 | video_init; |
1576 | audio_init; |
1670 | audio_init; |
1577 | } |
1671 | } |
1578 | |
1672 | |
1579 | Event::loop; |
1673 | Event::loop; |