--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/12/26 19:11:13 1.181 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2007/12/26 20:46:39 1.182 @@ -1,16 +1,16 @@ -package CFPlus::Protocol; +package dc::Protocol; use utf8; use strict; use Deliantra::Protocol::Constants; -use CFPlus; -use CFPlus::DB; -use CFPlus::UI; -use CFPlus::Pod; -use CFPlus::Macro; -use CFPlus::Item; +use dc; +use dc::DB; +use dc::UI; +use dc::Pod; +use dc::Macro; +use dc::Item; use base 'Deliantra::Protocol::Base'; @@ -36,8 +36,8 @@ my @args = split /\|/, $2; @args = (".*") unless @args; - my (undef, @par) = CFPlus::Pod::section_of $_; - my $text = CFPlus::Pod::as_label @par; + my (undef, @par) = dc::Pod::section_of $_; + my $text = dc::Pod::as_label @par; $_ = $_ eq ".*" ? "" : " $_" for @args; @@ -46,7 +46,7 @@ sort { (length $a) <=> (length $b) } @args } sort { $a->{par} <=> $b->{par} } - CFPlus::Pod::find command => "*"; + dc::Pod::find command => "*"; $self->{json_coder} ->convert_blessed @@ -72,14 +72,14 @@ for @cmd_help; { - $self->{dialogue} = my $tex = new_from_file CFPlus::Texture - CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; + $self->{dialogue} = my $tex = new_from_file dc::Texture + dc::find_rcfile "dialogue.png", minify => 1, mipmap => 1; $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); } { - $self->{noface} = my $tex = new_from_file CFPlus::Texture - CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; + $self->{noface} = my $tex = new_from_file dc::Texture + dc::find_rcfile "noface.png", minify => 1, mipmap => 1; $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); } @@ -144,7 +144,7 @@ sub widget_associate { my ($self, $ws, $id, $widget) = @_; - $widget ||= new CFPlus::UI::Bin; + $widget ||= new dc::UI::Bin; $widget->{s_id} = $id; $self->{widget}{$id} = $widget; @@ -190,7 +190,7 @@ $self->widget_associate ( $ws, $id => scalar eval { local $SIG{__DIE__}; - "CFPlus::UI::$class"->new (%$args) + "dc::UI::$class"->new (%$args) } ); } @@ -201,8 +201,8 @@ # everything that has a name, wether conceivably useful or not my %wkw = ( - root => $CFPlus::UI::ROOT, - tooltip => $CFPlus::UI::TOOLTIP, + root => $dc::UI::ROOT, + tooltip => $dc::UI::TOOLTIP, mapwidget => $::MAPWIDGET, buttonbar => $::BUTTONBAR, @@ -296,7 +296,7 @@ sub logprint { my ($self, @a) = @_; - CFPlus::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { }; + dc::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { }; } sub _stat_numdiff { @@ -478,14 +478,14 @@ $sktbl->clear; my $sw = $self->{skillwid}{""} ||= [ - 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), - 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), - 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), - 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), - 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), - 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), - 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), - 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), + 0, 0, (new dc::UI::Label text => "Experience", align => 1), + 1, 0, (new dc::UI::Label text => "Lvl.", align => 1), + 2, 0, (new dc::UI::Label text => "Progress", align => 0), + 3, 0, (new dc::UI::Label text => "Skill", expand => 1), + 4, 0, (new dc::UI::Label text => "Experience", align => 1), + 5, 0, (new dc::UI::Label text => "Lvl.", align => 1), + 6, 0, (new dc::UI::Label text => "Progress", align => 0), + 7, 0, (new dc::UI::Label text => "Skill", expand => 1), ]; my @add = @$sw; @@ -507,11 +507,11 @@ } elsif ($ev->{button} == 2) { $::CONN->user_send ("use_skill $name"); } elsif ($ev->{button} == 3) { - my $shortname = CFPlus::shorten $name, 14; - (new CFPlus::UI::Menu + my $shortname = dc::shorten $name, 14; + (new dc::UI::Menu items => [ - ["bind ready_skill $shortname to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }], - ["bind use_skill $shortname to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }], + ["bind ready_skill $shortname to a key" => sub { dc::Macro::quick_macro ["ready_skill $name"] }], + ["bind use_skill $shortname to a key" => sub { dc::Macro::quick_macro ["use_skill $name"] }], ], )->popup ($ev); } else { @@ -523,19 +523,19 @@ my $sw = $self->{skillwid}{$idx} ||= [ # exp - (new CFPlus::UI::Label + (new dc::UI::Label align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), # level - (new CFPlus::UI::Label + (new dc::UI::Label text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), # progress - (new CFPlus::UI::ExperienceProgress), + (new dc::UI::ExperienceProgress), # label - (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, - can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), + (new dc::UI::Label text => $name, on_button_down => $spell_cb, + can_events => 1, can_hover => 1, tooltip => (dc::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), ]; push @add, @@ -640,7 +640,7 @@ my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); $self->{map_cache_new}{$hash} = \$data; - CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; + dc::DB::put $self->{mapcache} => $hash => $data, sub { }; } sub map_clear { @@ -663,7 +663,7 @@ or return; } while $self->{texture}[$tile]; - CFPlus::DB::get tilecache => $tile, sub { + dc::DB::get tilecache => $tile, sub { my ($data) = @_; return unless $self->{map}; # stop when destroyed @@ -701,7 +701,7 @@ if (my $rdata = $self->{map_cache_old}{$hash}) { $cb->($$rdata); } else { - CFPlus::DB::get $self->{mapcache} => $hash, $cb; + dc::DB::get $self->{mapcache} => $hash, $cb; } } @@ -835,18 +835,18 @@ my ($self, $facenum, $face, $cb) = @_; if ($face->{type} == 0) { # FT_FACE - my $id = CFPlus::DB::get_tile_id_sync $face->{name}; + my $id = dc::DB::get_tile_id_sync $face->{name}; $face->{id} = $id; $self->{map}->set_tileid ($facenum => $id); - CFPlus::DB::get tilecache => $id, $cb; + dc::DB::get tilecache => $id, $cb; } elsif ($face->{type} & 1) { # with metadata - CFPlus::DB::get res_meta => $face->{name}, $cb; + dc::DB::get res_meta => $face->{name}, $cb; } else { # no metadata - CFPlus::DB::get res_data => $face->{name}, $cb; + dc::DB::get res_data => $face->{name}, $cb; } } @@ -855,7 +855,7 @@ if ($face->{type} == 0) { # image, FT_FACE - CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } + dc::DB::put tilecache => $face->{id} => $face->{data}, sub { } if $changed; $self->have_tile ($face->{id}, delete $face->{data}); @@ -867,13 +867,13 @@ $face->{data} = $meta; # rely on strict ordering here and also on later fetch - CFPlus::DB::put res_data => $face->{name} => $data, sub { }; - CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; + dc::DB::put res_data => $face->{name} => $data, sub { }; + dc::DB::put res_meta => $face->{name} => $meta, sub { }; } $face->{data} = $self->{json_coder}->decode ($face->{data}); ::add_license ($face); - ::message ({ markup => CFPlus::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." }) + ::message ({ markup => dc::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." }) if $changed; if ($face->{type} == 3) { # FT_MUSIC @@ -884,7 +884,7 @@ } else { # flat resource case, FT_RSRC - CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } + dc::DB::put res_data => $face->{name} => $face->{data}, sub { } if $changed; } @@ -905,7 +905,7 @@ return unless $self->{map}; my $tex = $self->{texture}[$tile] ||= - new CFPlus::Texture + new dc::Texture tile => $tile, image => $data, delete_image => 1, minify => 1, mipmap => 1; @@ -923,7 +923,7 @@ push @{$self->{face_cb}{$num}}, $cb; defined wantarray - ? CFPlus::guard { + ? dc::guard { @{$self->{face_cb}{$num}} = grep $_ != $cb, @{$self->{face_cb}{$num}}; @@ -1070,8 +1070,8 @@ $::SPELL_LIST->add_spell ($spell); - $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); - $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); + $self->{map_widget}->add_command ("invoke $spell->{name}", dc::asxml $spell->{message}); + $self->{map_widget}->add_command ("cast $spell->{name}", dc::asxml $spell->{message}); } sub spell_delete { @@ -1092,17 +1092,17 @@ my %skill_help; - for my $node (CFPlus::Pod::find skill_description => "*") { - my (undef, @par) = CFPlus::Pod::section_of $node; - $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; + for my $node (dc::Pod::find skill_description => "*") { + my (undef, @par) = dc::Pod::section_of $node; + $skill_help{$node->{kw}[0]} = dc::Pod::as_label @par; }; for my $skill (values %{$self->{skill_info}}) { $self->{map_widget}->add_command ("ready_skill $skill", - (CFPlus::asxml "Ready the skill '$skill'\n\n") + (dc::asxml "Ready the skill '$skill'\n\n") . $skill_help{$skill}); $self->{map_widget}->add_command ("use_skill $skill", - (CFPlus::asxml "Immediately use the skill '$skill'\n\n") + (dc::asxml "Immediately use the skill '$skill'\n\n") . $skill_help{$skill}); } } @@ -1116,7 +1116,7 @@ } sub update_floorbox { - $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { + $dc::UI::ROOT->on_refresh ($::FLOORBOX => sub { return unless $::CONN; $::FLOORBOX->clear; @@ -1128,7 +1128,7 @@ if ($row < 6) { local $_->{face_widget}; # hack to force recreation of widget local $_->{desc_widget}; # hack to force recreation of widget - CFPlus::Item::update_widgets $_; + dc::Item::update_widgets $_; push @add, 0, $row, $_->{face_widget}, @@ -1136,7 +1136,7 @@ $row++; } else { - push @add, 1, $row, new CFPlus::UI::Button + push @add, 1, $row, new dc::UI::Button text => "More...", on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, ; @@ -1144,7 +1144,7 @@ } } if ($::CONN->{open_container}) { - push @add, 1, $row++, new CFPlus::UI::Button + push @add, 1, $row++, new dc::UI::Button text => "Close container", on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } ; @@ -1162,10 +1162,10 @@ update_floorbox; $::INVR_HB->clear (); - $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); + $::INVR_HB->add (new dc::UI::Label align => 0, expand => 1, text => $name); if ($tag != 0) { # Floor isn't closable, is it? - $::INVR_HB->add (new CFPlus::UI::Button + $::INVR_HB->add (new dc::UI::Button text => "Close container", tooltip => "Close the currently open container (if one is open)", on_activate => sub { @@ -1182,7 +1182,7 @@ sub update_containers { my ($self) = @_; - $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { + $dc::UI::ROOT->on_refresh ("update_containers_$self" => sub { my $todo = delete $self->{update_container} or return; @@ -1229,13 +1229,13 @@ #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; - CFPlus::Item::update_widgets $item; + dc::Item::update_widgets $item; if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { set_opencont ($::CONN, 0, "Floor"); } elsif ($item->{flags} & F_OPEN) { - set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); + set_opencont ($::CONN, $item->{tag}, dc::Item::desc_string $item); } else { $self->{update_container}{$item->{container}}++; @@ -1317,7 +1317,7 @@ if (exists $msg{npc_dialog}) { # start npc chat dialog - $self->{npc_dialog} = new CFPlus::NPCDialog:: + $self->{npc_dialog} = new dc::NPCDialog:: token => $msg{npc_dialog}, title => "$msg{npc_dialog}[0] (NPC)", conn => $self, @@ -1340,9 +1340,9 @@ %$self = (); } -package CFPlus::NPCDialog; +package dc::NPCDialog; -our @ISA = 'CFPlus::UI::Toplevel'; +our @ISA = 'dc::UI::Toplevel'; sub new { my $class = shift; @@ -1359,18 +1359,18 @@ @_, ); - CFPlus::weaken (my $this = $self); + dc::weaken (my $this = $self); $self->connect (delete => sub { $this->destroy; 1 }); # better use a pane... - $self->add (my $hbox = new CFPlus::UI::HBox); - $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); + $self->add (my $hbox = new dc::UI::HBox); + $hbox->add ($self->{textview} = new dc::UI::TextScroller expand => 1); - $hbox->add (my $vbox = new CFPlus::UI::VBox); + $hbox->add (my $vbox = new dc::UI::VBox); - $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); - $vbox->add ($self->{entry} = new CFPlus::UI::Entry + $vbox->add (new dc::UI::Label text => "Message Entry:"); + $vbox->add ($self->{entry} = new dc::UI::Entry tooltip => "#npc_message_entry", on_activate => sub { my ($entry, $text) = @_; @@ -1384,9 +1384,9 @@ }, ); - $vbox->add ($self->{options} = new CFPlus::UI::VBox); + $vbox->add ($self->{options} = new dc::UI::VBox); - $self->{bye_button} = new CFPlus::UI::Button + $self->{bye_button} = new dc::UI::Button text => "Bye (close)", tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", on_activate => sub { $this->destroy; 1 }, @@ -1415,13 +1415,13 @@ sub update_options { my ($self) = @_; - CFPlus::weaken $self; + dc::weaken $self; $self->{options}->clear; $self->{options}->add ($self->{bye_button}); for my $kw (sort keys %{ $self->{kw} }) { - $self->{options}->add (new CFPlus::UI::Button + $self->{options}->add (new dc::UI::Button text => $kw, on_activate => sub { $self->send ($kw); @@ -1434,7 +1434,7 @@ sub feed { my ($self, $type, @arg) = @_; - CFPlus::weaken $self; + dc::weaken $self; if ($type eq "update") { my (%info) = @arg; @@ -1443,7 +1443,7 @@ $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; if (exists $info{msg}) { - my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; + my $text = "\n" . dc::Protocol::sanitise_xml $info{msg}; my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; my @link; $text =~ s{ @@ -1451,7 +1451,7 @@ }{ my $kw = $1; - push @link, new CFPlus::UI::Label + push @link, new dc::UI::Label markup => "$kw", can_hover => 1, can_events => 1, @@ -1479,7 +1479,7 @@ sub send { my ($self, $msg) = @_; - $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); + $self->{textview}->add_paragraph ({ markup => "\n" . dc::asxml $msg }); $self->{textview}->scroll_to_bottom; $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);