1 | package CFPlus::Item; |
1 | package CFPlus::Item; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
|
|
4 | use utf8; |
|
|
5 | |
4 | use Crossfire::Protocol::Constants; |
6 | use Crossfire::Protocol::Constants; |
5 | |
7 | |
6 | my $last_enter_count = 1; |
8 | my $last_enter_count = 1; |
7 | |
9 | |
8 | sub desc_string { |
10 | sub desc_string { |
… | |
… | |
68 | |
70 | |
69 | sub update_widgets { |
71 | sub update_widgets { |
70 | my ($self) = @_; |
72 | my ($self) = @_; |
71 | |
73 | |
72 | # necessary to avoid cyclic references |
74 | # necessary to avoid cyclic references |
73 | Scalar::Util::weaken $self; |
75 | CFPlus::weaken $self; |
74 | |
76 | |
75 | my $button_cb = sub { |
77 | my $button_cb = sub { |
76 | my (undef, $ev, $x, $y) = @_; |
78 | my (undef, $ev, $x, $y) = @_; |
77 | |
79 | |
78 | my $targ = $::CONN->{player}{tag}; |
80 | my $targ = $::CONN->{player}{tag}; |
… | |
… | |
151 | } |
153 | } |
152 | |
154 | |
153 | 1 |
155 | 1 |
154 | }; |
156 | }; |
155 | |
157 | |
156 | my $tooltip_std = "<small>" |
158 | my $tooltip_std = |
|
|
159 | "<small>" |
157 | . "Left click - examine item\n" |
160 | . "Left click - examine item\n" |
158 | . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" |
161 | . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" |
159 | . "Middle click - apply\n" |
162 | . "Middle click - apply\n" |
160 | . "Shift-Middle click - lock/unlock\n" |
163 | . "Shift-Middle click - lock/unlock\n" |
161 | . "Right click - further options" |
164 | . "Right click - further options" |
162 | . "</small>\n"; |
165 | . "</small>\n"; |
163 | |
166 | |
164 | my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] |
167 | my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] |
165 | : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] |
168 | : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] |
166 | : undef; |
169 | : undef; |
167 | |
170 | |
… | |
… | |
186 | $self->{desc_widget} ||= new CFPlus::UI::Label |
189 | $self->{desc_widget} ||= new CFPlus::UI::Label |
187 | can_events => 1, |
190 | can_events => 1, |
188 | can_hover => 1, |
191 | can_hover => 1, |
189 | ellipsise => 2, |
192 | ellipsise => 2, |
190 | align => -1, |
193 | align => -1, |
|
|
194 | |
191 | on_button_down => $button_cb, |
195 | on_button_down => $button_cb, |
|
|
196 | on_tooltip_show => sub { |
|
|
197 | my ($widget) = @_; |
|
|
198 | |
|
|
199 | $::CONN && $::CONN->ex ($self->{tag}, sub { |
|
|
200 | my ($long_desc) = @_; |
|
|
201 | |
|
|
202 | $long_desc =~ s/\s+$//; |
|
|
203 | |
|
|
204 | $self->{long_desc} = $long_desc; |
|
|
205 | $widget->set_tooltip ("<b>$long_desc</b>\n\n$tooltip_std"); |
|
|
206 | }); |
|
|
207 | }, |
192 | ; |
208 | ; |
|
|
209 | |
193 | my $desc = CFPlus::Item::desc_string $self; |
210 | my $desc = CFPlus::Item::desc_string $self; |
194 | $self->{desc_widget}{bg} = $bg; |
211 | $self->{desc_widget}{bg} = $bg; |
195 | $self->{desc_widget}->set_text ($desc); |
212 | $self->{desc_widget}->set_text ($desc); |
|
|
213 | |
|
|
214 | my $long_desc = $self->{long_desc} || $desc; |
196 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
215 | $self->{desc_widget}->set_tooltip ("<b>$long_desc</b>\n\n$tooltip_std"); |
197 | |
216 | |
198 | $self->{weight_widget} ||= new CFPlus::UI::Label |
217 | $self->{weight_widget} ||= new CFPlus::UI::Label |
199 | can_events => 1, |
218 | can_events => 1, |
200 | can_hover => 1, |
219 | can_hover => 1, |
201 | ellipsise => 0, |
220 | ellipsise => 0, |
… | |
… | |
209 | . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") |
228 | . ($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. ") |
229 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
211 | . "\n\n$tooltip_std" |
230 | . "\n\n$tooltip_std" |
212 | ); |
231 | ); |
213 | } |
232 | } |
|
|
233 | |