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.3 by root, Sat Dec 9 21:50:00 2006 UTC vs.
Revision 1.19 by root, Wed Nov 21 13:23:10 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines