ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Item.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Item.pm (file contents):
Revision 1.2 by root, Sat Dec 9 21:26:46 2006 UTC vs.
Revision 1.13 by root, Thu May 8 20:19:49 2008 UTC

1package CFPlus::Item; 1package DC::Item;
2 2
3use strict; 3use strict;
4use utf8;
5use Encode;
6
4use Crossfire::Protocol::Constants; 7use Deliantra::Protocol::Constants;
5 8
6my $last_enter_count = 1; 9my $last_enter_count = 1;
7 10
8sub desc_string { 11sub desc_string {
9 my ($self) = @_; 12 my ($self) = @_;
40} 43}
41 44
42sub do_n_dialog { 45sub do_n_dialog {
43 my ($cb) = @_; 46 my ($cb) = @_;
44 47
45 my $w = new CFPlus::UI::Toplevel 48 my $w = new DC::UI::Toplevel
46 on_delete => sub { $_[0]->destroy; 1 }, 49 on_delete => sub { $_[0]->destroy; 1 },
47 has_close_button => 1, 50 has_close_button => 1,
48 ; 51 ;
49 52
50 $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center"); 53 $w->add (my $vb = new DC::UI::VBox x => "center", y => "center");
51 $vb->add (new CFPlus::UI::Label text => "Enter item count:"); 54 $vb->add (new DC::UI::Label text => "Enter item count:");
52 $vb->add (my $entry = new CFPlus::UI::Entry 55 $vb->add (my $entry = new DC::UI::Entry
53 text => $last_enter_count, 56 text => $last_enter_count,
54 on_activate => sub { 57 on_activate => sub {
55 my ($entry) = @_; 58 my ($entry) = @_;
56 $last_enter_count = $entry->get_text; 59 $last_enter_count = $entry->get_text;
57 $cb->($last_enter_count); 60 $cb->($last_enter_count);
68 71
69sub update_widgets { 72sub update_widgets {
70 my ($self) = @_; 73 my ($self) = @_;
71 74
72 # necessary to avoid cyclic references 75 # necessary to avoid cyclic references
73 CFPlus::weaken $self; 76 DC::weaken $self;
74 77
75 my $button_cb = sub { 78 my $button_cb = sub {
76 my (undef, $ev, $x, $y) = @_; 79 my (undef, $ev, $x, $y) = @_;
77 80
78 my $targ = $::CONN->{player}{tag}; 81 my $targ = $::CONN->{player}{tag};
79 82
80 if ($self->{container} == $::CONN->{player}{tag}) { 83 if ($self->{container} == $::CONN->{player}{tag}) {
81 $targ = $::CONN->{open_container}; 84 $targ = $::CONN->{open_container};
82 } 85 }
83 86
84 if (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 1) { 87 if (($ev->{mod} & DC::KMOD_SHIFT) && $ev->{button} == 1) {
85 $::CONN->send ("move $targ $self->{tag} 0") 88 $::CONN->send ("move $targ $self->{tag} 0")
86 if $targ || !($self->{flags} & F_LOCKED); 89 if $targ || !($self->{flags} & F_LOCKED);
87 } elsif (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 2) { 90 } elsif (($ev->{mod} & DC::KMOD_SHIFT) && $ev->{button} == 2) {
88 $self->{flags} & F_LOCKED 91 $self->{flags} & F_LOCKED
89 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) 92 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
90 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) 93 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
91 } elsif ($ev->{button} == 1) { 94 } elsif ($ev->{button} == 1) {
92 $::CONN->send ("examine $self->{tag}"); 95 $::CONN->send ("examine $self->{tag}");
96 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop'; 99 my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop';
97 if ($self->{container} == $::CONN->{open_container}) { 100 if ($self->{container} == $::CONN->{open_container}) {
98 $move_prefix = "take"; 101 $move_prefix = "take";
99 } 102 }
100 103
101 my $shortname = CFPlus::shorten $self->{name}, 14; 104 my $shortname = DC::shorten $self->{name}, 14;
102 105
103 my @menu_items = ( 106 my @menu_items = (
104 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 107 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
105 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 108 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
106 ["ignite/thaw", # first try of an easier use of flint&steel 109 ["ignite/thaw", # first try of an easier use of flint&steel
112 ["inscribe", # first try of an easier use of flint&steel 115 ["inscribe", # first try of an easier use of flint&steel
113 sub { 116 sub {
114 &::open_string_query ("Text to inscribe", sub { 117 &::open_string_query ("Text to inscribe", sub {
115 my ($entry, $txt) = @_; 118 my ($entry, $txt) = @_;
116 $::CONN->send ("mark ". pack "N", $self->{tag}); 119 $::CONN->send ("mark ". pack "N", $self->{tag});
117 $::CONN->send ("command use_skill inscription $txt"); 120 $::CONN->send_utf8 ("command use_skill inscription $txt");
118 }); 121 });
119 } 122 }
120 ], 123 ],
121 ["rename", # first try of an easier use of flint&steel 124 ["rename", # first try of an easier use of flint&steel
122 sub { 125 sub {
123 &::open_string_query ("Rename item to:", sub { 126 &::open_string_query ("Rename item to:", sub {
124 my ($entry, $txt) = @_; 127 my ($entry, $txt) = @_;
125 $::CONN->send ("mark ". pack "N", $self->{tag}); 128 $::CONN->send ("mark ". pack "N", $self->{tag});
126 $::CONN->send ("command rename to <$txt>"); 129 $::CONN->send_utf8 ("command rename to <$txt>");
127 }, $self->{name}, 130 }, $self->{name},
128 "If you input no name or erase the current custom name, the custom name will be unset"); 131 "If you input no name or erase the current custom name, the custom name will be unset");
129 } 132 }
130 ], 133 ],
131 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 134 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
142 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) 145 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
143 } 146 }
144 ] 147 ]
145 ) 148 )
146 ), 149 ),
147 ["bind <i>apply $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["apply $self->{name}"] }], 150 ["bind <i>apply $shortname</i> to a key" => sub { DC::Macro::quick_macro ["apply $self->{name}"] }],
148 ); 151 );
149 152
150 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 153 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
151 } 154 }
152 155
153 1 156 1
154 }; 157 };
155 158
156 my $tooltip_std = "<small>" 159 my $tooltip_std =
160 "<small>"
157 . "Left click - examine item\n" 161 . "Left click - examine item\n"
158 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" 162 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n"
159 . "Middle click - apply\n" 163 . "Middle click - apply\n"
160 . "Shift-Middle click - lock/unlock\n" 164 . "Shift-Middle click - lock/unlock\n"
161 . "Right click - further options" 165 . "Right click - further options"
162 . "</small>\n"; 166 . "</small>\n";
163 167
164 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] 168 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5]
165 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] 169 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5]
166 : undef; 170 : undef;
167 171
172 my $desc = DC::Item::desc_string $self;
173
168 $self->{face_widget} ||= new CFPlus::UI::Face 174 $self->{face_widget} ||= new DC::UI::Face
169 can_events => 1, 175 can_events => 1,
170 can_hover => 1, 176 can_hover => 1,
171 anim => $self->{anim}, 177 anim => $self->{anim},
172 animspeed => $self->{animspeed}, # TODO# must be set at creation time 178 animspeed => $self->{animspeed}, # TODO# must be set at creation time
173 on_button_down => $button_cb, 179 on_button_down => $button_cb,
174 ; 180 ;
175 $self->{face_widget}{bg} = $bg; 181 $self->{face_widget}{bg} = $bg;
176 $self->{face_widget}{face} = $self->{face}; 182 $self->{face_widget}{face} = $self->{face};
177 $self->{face_widget}{anim} = $self->{anim}; 183 $self->{face_widget}{anim} = $self->{anim};
178 $self->{face_widget}{animspeed} = $self->{animspeed}; 184 $self->{face_widget}{animspeed} = $self->{animspeed};
179 $self->{face_widget}->set_tooltip ( 185# $self->{face_widget}->set_tooltip (
180 "<b>Face/Animation.</b>\n" 186# "<b>Face/Animation.</b>\n"
181 . "Item uses face #$self->{face}. " 187# . "Item uses face #$self->{face}. "
182 . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ") 188# . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ")
183 . "\n\n$tooltip_std" 189# . "\n\n$tooltip_std"
184 ); 190# );
191 $self->{face_widget}->set_tooltip ("<b>$desc</b>\n\n$tooltip_std");
185 192
186 $self->{desc_widget} ||= new CFPlus::UI::Label 193 $self->{desc_widget} ||= new DC::UI::Label
187 can_events => 1, 194 can_events => 1,
188 can_hover => 1, 195 can_hover => 1,
189 ellipsise => 2, 196 ellipsise => 2,
190 align => -1, 197 align => 0,
198
191 on_button_down => $button_cb, 199 on_button_down => $button_cb,
200 on_tooltip_show => sub {
201 my ($widget) = @_;
202
203 $::CONN && $::CONN->ex ($self->{tag}, sub {
204 my ($long_desc) = @_;
205
206 $long_desc = DC::Protocol::sanitise_xml ($long_desc);
207
208 $self->{long_desc} = $long_desc;
209 $widget->set_tooltip ("<b>$long_desc</b>\n\n$tooltip_std");
210 });
211 },
192 ; 212 ;
193 my $desc = CFPlus::Item::desc_string $self; 213
194 $self->{desc_widget}{bg} = $bg; 214 $self->{desc_widget}{bg} = $bg;
195 $self->{desc_widget}->set_text ($desc); 215 $self->{desc_widget}->set_text ($desc);
216
217 my $long_desc = $self->{long_desc} || $desc;
196 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 218 $self->{desc_widget}->set_tooltip ("<b>$long_desc</b>\n\n$tooltip_std");
197 219
198 $self->{weight_widget} ||= new CFPlus::UI::Label 220 $self->{weight_widget} ||= new DC::UI::Label
199 can_events => 1, 221 can_events => 1,
200 can_hover => 1, 222 can_hover => 1,
201 ellipsise => 0, 223 ellipsise => 0,
202 align => 0,
203 on_button_down => $button_cb, 224 on_button_down => $button_cb,
204 ; 225 ;
205 $self->{weight_widget}{bg} = $bg; 226 $self->{weight_widget}{bg} = $bg;
206 $self->{weight_widget}->set_text (CFPlus::Item::weight_string $self); 227 $self->{weight_widget}->set_text (DC::Item::weight_string $self);
207 $self->{weight_widget}->set_tooltip ( 228 $self->{weight_widget}->set_tooltip (
208 "<b>Weight</b>.\n" 229 "<b>Weight</b>.\n"
209 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") 230 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ")
210 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 231 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
211 . "\n\n$tooltip_std" 232 . "\n\n$tooltip_std"
212 ); 233 );
213} 234}
235

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines