--- deliantra/Deliantra-Client/bin/cfplus 2006/07/23 16:11:12 1.100 +++ deliantra/Deliantra-Client/bin/cfplus 2006/07/24 08:23:28 1.103 @@ -45,13 +45,21 @@ $SIG{QUIT} = sub { Carp::cluck "QUIT" }; $SIG{PIPE} = 'IGNORE'; +$Event::Eval = 0; $Event::DIED = sub { # TODO: display dialog box or so - Carp::confess $_[1];#d#TODO: remove when stable + Carp::cluck $_[1];#d#TODO: remove when stable CFClient::error $_[1]; }; -#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# +$SIG{__DIE__} = sub { + return if CFClient::in_destruct; + Carp::cluck $_[0]; + CFClient::error $_[0]; + return;#d# + #return unless defined $^S && !$^S; + $Event::DIED->(undef, $_[0]); +}; our $VERSION = '0.1'; @@ -254,7 +262,7 @@ ); # center: swap stats - my ($sw1, $sw2) = map +(new CFClient::UI::Combobox + my ($sw1, $sw2) = map +(new CFClient::UI::Selector expand => 1, value => $_, options => [ @@ -690,7 +698,6 @@ can_hover => 1, can_events => 1, tooltip => "The weight limit: you cannot carry more than this."); - $vb->add (my $hb = new CFClient::UI::HBox expand => 1); $hb->add (my $tbl = new CFClient::UI::Table expand => 1); @@ -1135,6 +1142,10 @@ y => "center", z => 50, title => "Really Quit?", + on_key_down => sub { + my ($dialog, $ev) = @_; + $ev->{sym} == 27 and $dialog->hide; + } ; $QUIT_DIALOG->add (my $vb = new CFClient::UI::VBox expand => 1); @@ -1158,6 +1169,7 @@ } $QUIT_DIALOG->show; + $QUIT_DIALOG->grab_focus; } sub autopickup_setup { @@ -1257,6 +1269,19 @@ $table } +my %SORT_ORDER = ( + type => undef, + mtime => sub { sort { + ($a->{flags} & F_LOCKED) <=> ($b->{flags} & F_LOCKED) + or $b->{mtime} <=> $a->{mtime} + or $a->{type} <=> $b->{type} + } @_ }, + weight => sub { sort { + $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) + or $a->{type} <=> $b->{type} + } @_ }, +); + sub inventory_widget { my $hb = new CFClient::UI::HBox homogeneous => 1; @@ -1267,21 +1292,16 @@ use sort 'stable'; - $hb1->add (new CFClient::UI::Combobox - value => undef, + $hb1->add (new CFClient::UI::Selector + value => $::CFG->{inv_sort}, options => [ - [undef, "Type/Name"], - [ - sub { sort { - $a->{weight} * ($a->{nrof} || 1) <=> $b->{weight} * ($b->{nrof} || 1) - or $a->{type} <=> $b->{type} - } @_ }, - "Weight/Type", - ], - [sub { } => "#TODO#"], + [type => "Type/Name"], + [mtime => "Recent/Normal/Locked"], + [weight => "Weight/Type"], ], on_changed => sub { - $INV->set_sort_order ($_[1]); + $::CFG->{inv_sort} = $_[1]; + $INV->set_sort_order ($SORT_ORDER{$_[1]}); }, ); $hb1->add (new CFClient::UI::Label text => "Weight: ", align => 1, expand => 1); @@ -1469,83 +1489,6 @@ $vb } -# just weirdness, pls. ignore -sub load_html_page { - my ($viewer, $base) = @_; - - $viewer->clear; - - require LWP::Simple; - require HTML::Parser; - require URI; - - my $page = LWP::Simple::get ($base) - or return; - - my @s = { }; - my %passthrough = map ($_ => undef), qw(b i u s tt big small sub sup); - - my $parser = HTML::Parser->new ( - text_h => [sub { - my ($text) = @_; - $text =~ s/\s+/ /g; - $s[-1]{text} .= CFClient::asxml $text; - }, "dtext"], - start_h => [sub { - my ($tag, $attr) = @_; - if ($passthrough{$tag}) { - $s[-1]{text} .= "<$tag>"; - } elsif ($tag eq "h1") { - push @s, { text => "" }; - } elsif ($tag eq "h2") { - push @s, { text => "" }; - } elsif ($tag eq "h3") { - push @s, { text => "" }; - } elsif ($tag eq "a") { - push @s, { text => "", url => $attr->{href} }; - } elsif ($tag eq "p") { - push @s, { }; - } elsif ($tag eq "img") { - eval { - push @{$s[-1]{obj}}, new CFClient::UI::Image - tex => (new_from_image CFClient::Texture LWP::Simple::get (URI->new ($attr->{src}, $base)->abs ($base))); - $s[-1]{text} .= "\x{fffc}"; - }; - } - }, "tagname, attr"], - end_h => [sub { - my ($tag) = @_; - if ($passthrough{$tag}) { - $s[-1]{text} .= ""; - } elsif ($tag =~ /^h\d$/) { - $s[-1]{text} .= ""; - push @s, { }; - } elsif ($tag eq "a") { - my $S = pop @s; - $s[-1]{text} .= "\x{fffc}"; - push @{$s[-1]{obj}}, new CFClient::UI::Label - fg => [0.8, 0.8, 1], - markup => "$S->{text}", - fontsize => 0.8, - can_events => 1, - can_focus => 1, - on_button_up => sub { - load_html_page ($viewer, URI->new ($S->{url}, $base)->abs ($base)); - }, - ; - } - }, "tagname"], - ); - - $parser->parse ($page); - $parser->eof; - - $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent}) - for @s; - - $viewer->set_offset (0); -} - sub help_window { my $win = new CFClient::UI::FancyFrame x => 'center', @@ -1564,7 +1507,7 @@ expand => 1, fontsize => 0.8, padding_x => 4); $buttons->add (new CFClient::UI::Label text => "Choose a document to display: "); - $buttons->add (my $combo = new CFClient::UI::Combobox + $buttons->add (my $combo = new CFClient::UI::Selector value => undef, options => [ [intro => "Introduction"], @@ -1573,34 +1516,12 @@ [command_help => "Command Reference"], [dmcommand_help => "DM Commands"], [COPYING => "License Terms"], - [test => "test (do not select)"], #d#TODO ], on_changed => sub { my ($self, $pod) = @_; - if ($pod eq "test") {#d#TODO - eval { - load_html_page $viewer, "http://crossfire.real-time.com/guides/walkthrough/newbie-tower.html"; - }; - warn "$@" if $@; - return; - } - - my $pom = CFClient::Pod::load CFClient::find_rcfile "pod/$pod.pod", - doc_viewer => 1, sub { CFClient::Pod::as_paragraphs $_[0] }; - - #use Data::Dumper; warn Dumper $pom;#d# - $viewer->clear; - -# $viewer->add_paragraph ([1, 1, 1, 1], ["Test\n\n \x{fffc} \x{fffc}\n", -# (new CFClient::UI::Image path => "x.png", can_hover => 1, can_events => 1), -# (new CFClient::UI::Label text => "üüüü", can_hover => 1, can_events => 1, tooltip => "??"), -# ]);#d# - - $viewer->add_paragraph ([1, 1, 1, 1], [$_->{text}, @{ $_->{obj} || [] }], $_->{indent}) - for @$pom; - + $viewer->add_paragraph (@{ CFClient::Pod::pod_paragraphs $pod }); $viewer->set_offset (0); 0 @@ -1954,12 +1875,6 @@ $SIG{INT} = $SIG{TERM} = sub { exit }; { - local $SIG{__DIE__} = sub { - return unless defined $^S && !$^S; - Carp::confess $_[0];#d#TODO: remove when stable - CFClient::fatal $_[0]; - }; - CFClient::read_cfg "$Crossfire::VARDIR/cfplusrc"; CFClient::UI::set_layout ($::CFG->{layout}); @@ -1987,6 +1902,7 @@ output_sync => 1, output_count => 1, pickup => 0, + inv_sort => "mtime", default => "profile", # default profile );