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.100 by root, Sun Jul 23 16:11:12 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];
1133 $QUIT_DIALOG = new CFClient::UI::FancyFrame 1140 $QUIT_DIALOG = new CFClient::UI::FancyFrame
1134 x => "center", 1141 x => "center",
1135 y => "center", 1142 y => "center",
1136 z => 50, 1143 z => 50,
1137 title => "Really Quit?", 1144 title => "Really Quit?",
1145 on_key_down => sub {
1146 my ($dialog, $ev) = @_;
1147 $ev->{sym} == 27 and $dialog->hide;
1148 }
1138 ; 1149 ;
1139 1150
1140 $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); 1151 $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1);
1141 1152
1142 $vb->add (new CFClient::UI::Label 1153 $vb->add (new CFClient::UI::Label
1156 on_activate => sub { exit }, 1167 on_activate => sub { exit },
1157 ); 1168 );
1158 } 1169 }
1159 1170
1160 $QUIT_DIALOG->show; 1171 $QUIT_DIALOG->show;
1172 $QUIT_DIALOG->grab_focus;
1161} 1173}
1162 1174
1163sub autopickup_setup { 1175sub autopickup_setup {
1164 my $table = new CFClient::UI::Table; 1176 my $table = new CFClient::UI::Table;
1165 1177
1255 }); 1267 });
1256 1268
1257 $table 1269 $table
1258} 1270}
1259 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
1260sub inventory_widget { 1285sub inventory_widget {
1261 my $hb = new CFClient::UI::HBox homogeneous => 1; 1286 my $hb = new CFClient::UI::HBox homogeneous => 1;
1262 1287
1263 $hb->add (my $vb1 = new CFClient::UI::VBox); 1288 $hb->add (my $vb1 = new CFClient::UI::VBox);
1264 $vb1->add (new CFClient::UI::Label align => 0, text => "Player"); 1289 $vb1->add (new CFClient::UI::Label align => 0, text => "Player");
1265 1290
1266 $vb1->add (my $hb1 = new CFClient::UI::HBox); 1291 $vb1->add (my $hb1 = new CFClient::UI::HBox);
1267 1292
1268 use sort 'stable'; 1293 use sort 'stable';
1269 1294
1270 $hb1->add (new CFClient::UI::Combobox 1295 $hb1->add (new CFClient::UI::Selector
1271 value => undef, 1296 value => $::CFG->{inv_sort},
1272 options => [ 1297 options => [
1273 [undef, "Type/Name"], 1298 [type => "Type/Name"],
1274 [ 1299 [mtime => "Recent/Normal/Locked"],
1275 sub { sort {
1276 $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1)
1277 or $a->{type} <=> $b->{type}
1278 } @_ },
1279 "Weight/Type", 1300 [weight => "Weight/Type"],
1280 ],
1281 [sub { } => "#TODO#"],
1282 ], 1301 ],
1283 on_changed => sub { 1302 on_changed => sub {
1303 $::CFG->{inv_sort} = $_[1];
1284 $INV->set_sort_order ($_[1]); 1304 $INV->set_sort_order ($SORT_ORDER{$_[1]});
1285 }, 1305 },
1286 ); 1306 );
1287 $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);
1288 #TODO# update to weigh/maxweight 1308 #TODO# update to weigh/maxweight
1289 $hb1->add ($STATWIDS->{i_weight} = new CFClient::UI::Label align => -1); 1309 $hb1->add ($STATWIDS->{i_weight} = new CFClient::UI::Label align => -1);
1467 $refresh->(); 1487 $refresh->();
1468 1488
1469 $vb 1489 $vb
1470} 1490}
1471 1491
1472# just weirdness, pls. ignore
1473sub load_html_page {
1474 my ($viewer, $base) = @_;
1475
1476 $viewer->clear;
1477
1478 require LWP::Simple;
1479 require HTML::Parser;
1480 require URI;
1481
1482 my $page = LWP::Simple::get ($base)
1483 or return;
1484
1485 my @s = { };
1486 my %passthrough = map ($_ => undef), qw(b i u s tt big small sub sup);
1487
1488 my $parser = HTML::Parser->new (
1489 text_h => [sub {
1490 my ($text) = @_;
1491 $text =~ s/\s+/ /g;
1492 $s[-1]{text} .= CFClient::asxml $text;
1493 }, "dtext"],
1494 start_h => [sub {
1495 my ($tag, $attr) = @_;
1496 if ($passthrough{$tag}) {
1497 $s[-1]{text} .= "<$tag>";
1498 } elsif ($tag eq "h1") {
1499 push @s, { text => "<span foreground='#ffff00' size='x-large'>" };
1500 } elsif ($tag eq "h2") {
1501 push @s, { text => "<span foreground='#ccccff' size='large'>" };
1502 } elsif ($tag eq "h3") {
1503 push @s, { text => "<span size='large'>" };
1504 } elsif ($tag eq "a") {
1505 push @s, { text => "", url => $attr->{href} };
1506 } elsif ($tag eq "p") {
1507 push @s, { };
1508 } elsif ($tag eq "img") {
1509 eval {
1510 push @{$s[-1]{obj}}, new CFClient::UI::Image
1511 tex => (new_from_image CFClient::Texture LWP::Simple::get (URI->new ($attr->{src}, $base)->abs ($base)));
1512 $s[-1]{text} .= "\x{fffc}";
1513 };
1514 }
1515 }, "tagname, attr"],
1516 end_h => [sub {
1517 my ($tag) = @_;
1518 if ($passthrough{$tag}) {
1519 $s[-1]{text} .= "</$tag>";
1520 } elsif ($tag =~ /^h\d$/) {
1521 $s[-1]{text} .= "</span>";
1522 push @s, { };
1523 } elsif ($tag eq "a") {
1524 my $S = pop @s;
1525 $s[-1]{text} .= "\x{fffc}";
1526 push @{$s[-1]{obj}}, new CFClient::UI::Label
1527 fg => [0.8, 0.8, 1],
1528 markup => "<u>$S->{text}</u>",
1529 fontsize => 0.8,
1530 can_events => 1,
1531 can_focus => 1,
1532 on_button_up => sub {
1533 load_html_page ($viewer, URI->new ($S->{url}, $base)->abs ($base));
1534 },
1535 ;
1536 }
1537 }, "tagname"],
1538 );
1539
1540 $parser->parse ($page);
1541 $parser->eof;
1542
1543 $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent})
1544 for @s;
1545
1546 $viewer->set_offset (0);
1547}
1548
1549sub help_window { 1492sub help_window {
1550 my $win = new CFClient::UI::FancyFrame 1493 my $win = new CFClient::UI::FancyFrame
1551 x => 'center', 1494 x => 'center',
1552 y => 'center', 1495 y => 'center',
1553 z => 2, 1496 z => 2,
1562 $vbox->add (my $buttons = new CFClient::UI::HBox); 1505 $vbox->add (my $buttons = new CFClient::UI::HBox);
1563 $vbox->add (my $viewer = new CFClient::UI::TextScroller 1506 $vbox->add (my $viewer = new CFClient::UI::TextScroller
1564 expand => 1, fontsize => 0.8, padding_x => 4); 1507 expand => 1, fontsize => 0.8, padding_x => 4);
1565 1508
1566 $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: ");
1567 $buttons->add (my $combo = new CFClient::UI::Combobox 1510 $buttons->add (my $combo = new CFClient::UI::Selector
1568 value => undef, 1511 value => undef,
1569 options => [ 1512 options => [
1570 [intro => "Introduction"], 1513 [intro => "Introduction"],
1571 [manual => "Main Manual"], 1514 [manual => "Main Manual"],
1572 [skill_help => "Skill Reference"], 1515 [skill_help => "Skill Reference"],
1573 [command_help => "Command Reference"], 1516 [command_help => "Command Reference"],
1574 [dmcommand_help => "DM Commands"], 1517 [dmcommand_help => "DM Commands"],
1575 [COPYING => "License Terms"], 1518 [COPYING => "License Terms"],
1576 [test => "test (do not select)"], #d#TODO
1577 ], 1519 ],
1578 on_changed => sub { 1520 on_changed => sub {
1579 my ($self, $pod) = @_; 1521 my ($self, $pod) = @_;
1580 1522
1581 if ($pod eq "test") {#d#TODO
1582 eval {
1583 load_html_page $viewer, "http://crossfire.real-time.com/guides/walkthrough/newbie-tower.html";
1584 };
1585 warn "$@" if $@;
1586 return;
1587 }
1588
1589 my $pom = CFClient::Pod::load CFClient::find_rcfile "pod/$pod.pod",
1590 doc_viewer => 1, sub { CFClient::Pod::as_paragraphs $_[0] };
1591
1592 #use Data::Dumper; warn Dumper $pom;#d#
1593
1594 $viewer->clear; 1523 $viewer->clear;
1595 1524 $viewer->add_paragraph (@{ CFClient::Pod::pod_paragraphs $pod });
1596# $viewer->add_paragraph ([1, 1, 1, 1], ["<big>Test</big>\n\n \x{fffc} \x{fffc}\n",
1597# (new CFClient::UI::Image path => "x.png", can_hover => 1, can_events => 1),
1598# (new CFClient::UI::Label text => "üüüü", can_hover => 1, can_events => 1, tooltip => "??"),
1599# ]);#d#
1600
1601 $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent})
1602 for @$pom;
1603
1604 $viewer->set_offset (0); 1525 $viewer->set_offset (0);
1605 1526
1606 0 1527 0
1607 }, 1528 },
1608 on_visibility_change => sub { 1529 on_visibility_change => sub {
1952############################################################################# 1873#############################################################################
1953 1874
1954$SIG{INT} = $SIG{TERM} = sub { exit }; 1875$SIG{INT} = $SIG{TERM} = sub { exit };
1955 1876
1956{ 1877{
1957 local $SIG{__DIE__} = sub {
1958 return unless defined $^S && !$^S;
1959 Carp::confess $_[0];#d#TODO: remove when stable
1960 CFClient::fatal $_[0];
1961 };
1962
1963 CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc"; 1878 CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc";
1964 CFClient::UI::set_layout ($::CFG->{layout}); 1879 CFClient::UI::set_layout ($::CFG->{layout});
1965 1880
1966 my %DEF_CFG = ( 1881 my %DEF_CFG = (
1967 sdl_mode => 0, 1882 sdl_mode => 0,
1985 bgm_volume => 0.25, 1900 bgm_volume => 0.25,
1986 face_prefetch => 0, 1901 face_prefetch => 0,
1987 output_sync => 1, 1902 output_sync => 1,
1988 output_count => 1, 1903 output_count => 1,
1989 pickup => 0, 1904 pickup => 0,
1905 inv_sort => "mtime",
1990 default => "profile", # default profile 1906 default => "profile", # default profile
1991 ); 1907 );
1992 1908
1993 while (my ($k, $v) = each %DEF_CFG) { 1909 while (my ($k, $v) = each %DEF_CFG) {
1994 $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