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.4 by root, Mon Apr 23 19:17:41 2007 UTC vs.
Revision 1.16 by root, Mon Jan 12 03:18:13 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines