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

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.101 by elmex, Sun Jul 23 17:03:44 2006 UTC vs.
Revision 1.103 by root, Mon Jul 24 08:23:28 2006 UTC

43use CFClient::MapWidget; 43use CFClient::MapWidget;
44 44
45$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 45$SIG{QUIT} = sub { Carp::cluck "QUIT" };
46$SIG{PIPE} = 'IGNORE'; 46$SIG{PIPE} = 'IGNORE';
47 47
48$Event::Eval = 0;
48$Event::DIED = sub { 49$Event::DIED = sub {
49 # TODO: display dialog box or so 50 # TODO: display dialog box or so
50 Carp::confess $_[1];#d#TODO: remove when stable 51 Carp::cluck $_[1];#d#TODO: remove when stable
51 CFClient::error $_[1]; 52 CFClient::error $_[1];
52}; 53};
53 54
54#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# 55$SIG{__DIE__} = sub {
56 return if CFClient::in_destruct;
57 Carp::cluck $_[0];
58 CFClient::error $_[0];
59 return;#d#
60 #return unless defined $^S && !$^S;
61 $Event::DIED->(undef, $_[0]);
62};
55 63
56our $VERSION = '0.1'; 64our $VERSION = '0.1';
57 65
58my $MAX_FPS = 60; 66my $MAX_FPS = 60;
59my $MIN_FPS = 5; # unused as of yet 67my $MIN_FPS = 5; # unused as of yet
252 0 260 0
253 }, 261 },
254 ); 262 );
255 263
256 # center: swap stats 264 # center: swap stats
257 my ($sw1, $sw2) = map +(new CFClient::UI::Combobox 265 my ($sw1, $sw2) = map +(new CFClient::UI::Selector
258 expand => 1, 266 expand => 1,
259 value => $_, 267 value => $_,
260 options => [ 268 options => [
261 [1 => "Str", "Strength ($conn->{stat}{+CS_STAT_STR})"], 269 [1 => "Str", "Strength ($conn->{stat}{+CS_STAT_STR})"],
262 [2 => "Dex", "Dexterity ($conn->{stat}{+CS_STAT_DEX})"], 270 [2 => "Dex", "Dexterity ($conn->{stat}{+CS_STAT_DEX})"],
687 can_hover => 1, can_events => 1, 695 can_hover => 1, can_events => 1,
688 tooltip => "The weight of the player including all inventory items."); 696 tooltip => "The weight of the player including all inventory items.");
689 $hb0->add ($STATWIDS->{m_weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1, 697 $hb0->add ($STATWIDS->{m_weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1,
690 can_hover => 1, can_events => 1, 698 can_hover => 1, can_events => 1,
691 tooltip => "The weight limit: you cannot carry more than this."); 699 tooltip => "The weight limit: you cannot carry more than this.");
692
693 700
694 $vb->add (my $hb = new CFClient::UI::HBox expand => 1); 701 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
695 $hb->add (my $tbl = new CFClient::UI::Table expand => 1); 702 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
696 703
697 my $color2 = [1, 1, 0]; 704 my $color2 = [1, 1, 0];
1260 }); 1267 });
1261 1268
1262 $table 1269 $table
1263} 1270}
1264 1271
1272my %SORT_ORDER = (
1273 type => undef,
1274 mtime => sub { sort {
1275 ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED)
1276 or $b->{mtime} <=> $a->{mtime}
1277 or $a->{type} <=> $b->{type}
1278 } @_ },
1279 weight => sub { sort {
1280 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1281 or $a->{type} <=> $b->{type}
1282 } @_ },
1283);
1284
1265sub inventory_widget { 1285sub inventory_widget {
1266 my $hb = new CFClient::UI::HBox homogeneous => 1; 1286 my $hb = new CFClient::UI::HBox homogeneous => 1;
1267 1287
1268 $hb->add (my $vb1 = new CFClient::UI::VBox); 1288 $hb->add (my $vb1 = new CFClient::UI::VBox);
1269 $vb1->add (new CFClient::UI::Label align => 0, text => "Player"); 1289 $vb1->add (new CFClient::UI::Label align => 0, text => "Player");
1270 1290
1271 $vb1->add (my $hb1 = new CFClient::UI::HBox); 1291 $vb1->add (my $hb1 = new CFClient::UI::HBox);
1272 1292
1273 use sort 'stable'; 1293 use sort 'stable';
1274 1294
1275 $hb1->add (new CFClient::UI::Combobox 1295 $hb1->add (new CFClient::UI::Selector
1276 value => undef, 1296 value => $::CFG->{inv_sort},
1277 options => [ 1297 options => [
1278 [undef, "Type/Name"], 1298 [type => "Type/Name"],
1279 [ 1299 [mtime => "Recent/Normal/Locked"],
1280 sub { sort {
1281 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1282 or $a->{type} <=> $b->{type}
1283 } @_ },
1284 "Weight/Type", 1300 [weight => "Weight/Type"],
1285 ],
1286 [sub { } => "#TODO#"],
1287 ], 1301 ],
1288 on_changed => sub { 1302 on_changed => sub {
1303 $::CFG->{inv_sort} = $_[1];
1289 $INV->set_sort_order ($_[1]); 1304 $INV->set_sort_order ($SORT_ORDER{$_[1]});
1290 }, 1305 },
1291 ); 1306 );
1292 $hb1->add (new CFClient::UI::Label text => "Weight: ", align => 1, expand => 1); 1307 $hb1->add (new CFClient::UI::Label text => "Weight: ", align => 1, expand => 1);
1293 #TODO# update to weigh/maxweight 1308 #TODO# update to weigh/maxweight
1294 $hb1->add ($STATWIDS->{i_weight} = new CFClient::UI::Label align => -1); 1309 $hb1->add ($STATWIDS->{i_weight} = new CFClient::UI::Label align => -1);
1472 $refresh->(); 1487 $refresh->();
1473 1488
1474 $vb 1489 $vb
1475} 1490}
1476 1491
1477# just weirdness, pls. ignore
1478sub load_html_page {
1479 my ($viewer, $base) = @_;
1480
1481 $viewer->clear;
1482
1483 require LWP::Simple;
1484 require HTML::Parser;
1485 require URI;
1486
1487 my $page = LWP::Simple::get ($base)
1488 or return;
1489
1490 my @s = { };
1491 my %passthrough = map ($_ => undef), qw(b i u s tt big small sub sup);
1492
1493 my $parser = HTML::Parser->new (
1494 text_h => [sub {
1495 my ($text) = @_;
1496 $text =~ s/\s+/ /g;
1497 $s[-1]{text} .= CFClient::asxml $text;
1498 }, "dtext"],
1499 start_h => [sub {
1500 my ($tag, $attr) = @_;
1501 if ($passthrough{$tag}) {
1502 $s[-1]{text} .= "<$tag>";
1503 } elsif ($tag eq "h1") {
1504 push @s, { text => "<span foreground='#ffff00' size='x-large'>" };
1505 } elsif ($tag eq "h2") {
1506 push @s, { text => "<span foreground='#ccccff' size='large'>" };
1507 } elsif ($tag eq "h3") {
1508 push @s, { text => "<span size='large'>" };
1509 } elsif ($tag eq "a") {
1510 push @s, { text => "", url => $attr->{href} };
1511 } elsif ($tag eq "p") {
1512 push @s, { };
1513 } elsif ($tag eq "img") {
1514 eval {
1515 push @{$s[-1]{obj}}, new CFClient::UI::Image
1516 tex => (new_from_image CFClient::Texture LWP::Simple::get (URI->new ($attr->{src}, $base)->abs ($base)));
1517 $s[-1]{text} .= "\x{fffc}";
1518 };
1519 }
1520 }, "tagname, attr"],
1521 end_h => [sub {
1522 my ($tag) = @_;
1523 if ($passthrough{$tag}) {
1524 $s[-1]{text} .= "</$tag>";
1525 } elsif ($tag =~ /^h\d$/) {
1526 $s[-1]{text} .= "</span>";
1527 push @s, { };
1528 } elsif ($tag eq "a") {
1529 my $S = pop @s;
1530 $s[-1]{text} .= "\x{fffc}";
1531 push @{$s[-1]{obj}}, new CFClient::UI::Label
1532 fg => [0.8, 0.8, 1],
1533 markup => "<u>$S->{text}</u>",
1534 fontsize => 0.8,
1535 can_events => 1,
1536 can_focus => 1,
1537 on_button_up => sub {
1538 load_html_page ($viewer, URI->new ($S->{url}, $base)->abs ($base));
1539 },
1540 ;
1541 }
1542 }, "tagname"],
1543 );
1544
1545 $parser->parse ($page);
1546 $parser->eof;
1547
1548 $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent})
1549 for @s;
1550
1551 $viewer->set_offset (0);
1552}
1553
1554sub help_window { 1492sub help_window {
1555 my $win = new CFClient::UI::FancyFrame 1493 my $win = new CFClient::UI::FancyFrame
1556 x => 'center', 1494 x => 'center',
1557 y => 'center', 1495 y => 'center',
1558 z => 2, 1496 z => 2,
1567 $vbox->add (my $buttons = new CFClient::UI::HBox); 1505 $vbox->add (my $buttons = new CFClient::UI::HBox);
1568 $vbox->add (my $viewer = new CFClient::UI::TextScroller 1506 $vbox->add (my $viewer = new CFClient::UI::TextScroller
1569 expand => 1, fontsize => 0.8, padding_x => 4); 1507 expand => 1, fontsize => 0.8, padding_x => 4);
1570 1508
1571 $buttons->add (new CFClient::UI::Label text => "Choose a document to display: "); 1509 $buttons->add (new CFClient::UI::Label text => "Choose a document to display: ");
1572 $buttons->add (my $combo = new CFClient::UI::Combobox 1510 $buttons->add (my $combo = new CFClient::UI::Selector
1573 value => undef, 1511 value => undef,
1574 options => [ 1512 options => [
1575 [intro => "Introduction"], 1513 [intro => "Introduction"],
1576 [manual => "Main Manual"], 1514 [manual => "Main Manual"],
1577 [skill_help => "Skill Reference"], 1515 [skill_help => "Skill Reference"],
1578 [command_help => "Command Reference"], 1516 [command_help => "Command Reference"],
1579 [dmcommand_help => "DM Commands"], 1517 [dmcommand_help => "DM Commands"],
1580 [COPYING => "License Terms"], 1518 [COPYING => "License Terms"],
1581 [test => "test (do not select)"], #d#TODO
1582 ], 1519 ],
1583 on_changed => sub { 1520 on_changed => sub {
1584 my ($self, $pod) = @_; 1521 my ($self, $pod) = @_;
1585 1522
1586 if ($pod eq "test") {#d#TODO
1587 eval {
1588 load_html_page $viewer, "http://crossfire.real-time.com/guides/walkthrough/newbie-tower.html";
1589 };
1590 warn "$@" if $@;
1591 return;
1592 }
1593
1594 my $pom = CFClient::Pod::load CFClient::find_rcfile "pod/$pod.pod",
1595 doc_viewer => 1, sub { CFClient::Pod::as_paragraphs $_[0] };
1596
1597 #use Data::Dumper; warn Dumper $pom;#d#
1598
1599 $viewer->clear; 1523 $viewer->clear;
1600 1524 $viewer->add_paragraph (@{ CFClient::Pod::pod_paragraphs $pod });
1601# $viewer->add_paragraph ([1, 1, 1, 1], ["<big>Test</big>\n\n \x{fffc} \x{fffc}\n",
1602# (new CFClient::UI::Image path => "x.png", can_hover => 1, can_events => 1),
1603# (new CFClient::UI::Label text => "üüüü", can_hover => 1, can_events => 1, tooltip => "??"),
1604# ]);#d#
1605
1606 $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent})
1607 for @$pom;
1608
1609 $viewer->set_offset (0); 1525 $viewer->set_offset (0);
1610 1526
1611 0 1527 0
1612 }, 1528 },
1613 on_visibility_change => sub { 1529 on_visibility_change => sub {
1957############################################################################# 1873#############################################################################
1958 1874
1959$SIG{INT} = $SIG{TERM} = sub { exit }; 1875$SIG{INT} = $SIG{TERM} = sub { exit };
1960 1876
1961{ 1877{
1962 local $SIG{__DIE__} = sub {
1963 return unless defined $^S && !$^S;
1964 Carp::confess $_[0];#d#TODO: remove when stable
1965 CFClient::fatal $_[0];
1966 };
1967
1968 CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc"; 1878 CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc";
1969 CFClient::UI::set_layout ($::CFG->{layout}); 1879 CFClient::UI::set_layout ($::CFG->{layout});
1970 1880
1971 my %DEF_CFG = ( 1881 my %DEF_CFG = (
1972 sdl_mode => 0, 1882 sdl_mode => 0,
1990 bgm_volume => 0.25, 1900 bgm_volume => 0.25,
1991 face_prefetch => 0, 1901 face_prefetch => 0,
1992 output_sync => 1, 1902 output_sync => 1,
1993 output_count => 1, 1903 output_count => 1,
1994 pickup => 0, 1904 pickup => 0,
1905 inv_sort => "mtime",
1995 default => "profile", # default profile 1906 default => "profile", # default profile
1996 ); 1907 );
1997 1908
1998 while (my ($k, $v) = each %DEF_CFG) { 1909 while (my ($k, $v) = each %DEF_CFG) {
1999 $CFG->{$k} = $v unless exists $CFG->{$k}; 1910 $CFG->{$k} = $v unless exists $CFG->{$k};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines