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

Comparing deliantra/Deliantra-Client/DC/Macro.pm (file contents):
Revision 1.1 by root, Sat Dec 9 02:21:25 2006 UTC vs.
Revision 1.5 by root, Sat Dec 9 23:06:39 2006 UTC

156 156
157 $window->grab_focus; 157 $window->grab_focus;
158 $window->show; 158 $window->show;
159} 159}
160 160
161# find macro by event
162sub match_event($) {
163 my ($ev) = @_;
164
165 grep {
166 if (my $key = $_->{accelkey}) {
167 $key->[1] == $ev->{sym}
168 && $key->[0] == ($ev->{mod} & $MODIFIER_MASK)
169 } else {
170 0
171 }
172 } @{ $::PROFILE->{macro} || [] }
173}
174
161sub keyboard_setup { 175sub keyboard_setup {
162 my $kbd_setup = new CFPlus::UI::VBox; 176 my $kbd_setup = new CFPlus::UI::VBox;
163 177
164 $kbd_setup->add (my $list = new CFPlus::UI::VBox); 178 $kbd_setup->add (my $list = new CFPlus::UI::VBox);
165 179
178 0 192 0
179 }, 193 },
180 ); 194 );
181 195
182 $list->add (new CFPlus::UI::FancyFrame 196 $list->add (new CFPlus::UI::FancyFrame
183 label => "Bindings", 197 label => "Macros",
184 child => (my $macros = new CFPlus::UI::Table), 198 child => (my $macros = new CFPlus::UI::VBox),
185 ); 199 );
186 200
187 my $refresh; 201 my $refresh;
188 202
189 my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; 203 my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>";
268 } 282 }
269 }, 283 },
270 ); 284 );
271 }; 285 };
272 286
287 $macros->add (new CFPlus::UI::Button
288 text => "New Macro",
289 tooltip => "Creates a new, empty, macro you can edit.",
290 on_activate => sub {
291 my $macro = { };
292 push @{ $::PROFILE->{macro} }, $macro;
293 $edit_macro->($macro);
294 },
295 );
296
297 $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]);
298
273 $REFRESH_MACRO_LIST = $refresh = sub { 299 $REFRESH_MACRO_LIST = $refresh = sub {
274 $macros->clear; 300 $macrolist->clear;
275 301
276 $macros->add (0, 0, new CFPlus::UI::Label 302 $macrolist->add (0, 1, new CFPlus::UI::Label
277 text => "Trigger", 303 text => "Trigger",
278 align => 0, 304 align => 0,
279 tooltip => $tooltip_trigger . $tooltip_common, 305 tooltip => $tooltip_trigger . $tooltip_common,
280 ); 306 );
281 $macros->add (1, 0, new CFPlus::UI::Label 307 $macrolist->add (1, 1, new CFPlus::UI::Label
282 text => "Commands", 308 text => "Commands",
283 tooltip => $tooltip_commands . $tooltip_common, 309 tooltip => $tooltip_commands . $tooltip_common,
284 ); 310 );
285 311
286 for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { 312 for my $idx (0 .. $#{$::PROFILE->{macro} || []}) {
287 my $macro = $::PROFILE->{macro}[$idx]; 313 my $macro = $::PROFILE->{macro}[$idx];
288 my $y = $idx + 1; 314 my $y = $idx + 2;
289 315
290 my $macro_cb = sub { 316 my $macro_cb = sub {
291 my ($widget, $ev) = @_; 317 my ($widget, $ev) = @_;
292 318
293 if ($ev->{button} == 1) { 319 if ($ev->{button} == 1) {
311 } 337 }
312 338
313 1 339 1
314 }; 340 };
315 341
316 $macros->add (0, $y, new CFPlus::UI::Label 342 $macrolist->add (0, $y, new CFPlus::UI::Label
317 text => trigger_to_string $macro, 343 text => trigger_to_string $macro,
318 tooltip => $tooltip_trigger . $tooltip_common, 344 tooltip => $tooltip_trigger . $tooltip_common,
319 align => 0, 345 align => 0,
320 can_hover => 1, 346 can_hover => 1,
321 can_events => 1, 347 can_events => 1,
322 on_button_down => $macro_cb, 348 on_button_down => $macro_cb,
323 ); 349 );
324 350
325 $macros->add (1, $y, new CFPlus::UI::Label 351 $macrolist->add (1, $y, new CFPlus::UI::Label
326 text => (join "; ", @{ $macro->{action} }), 352 text => (join "; ", @{ $macro->{action} || [] }),
327 tooltip => $tooltip_commands . $tooltip_common, 353 tooltip => $tooltip_commands . $tooltip_common,
328 expand => 1, 354 expand => 1,
329 ellipsise => 3, 355 ellipsise => 3,
330 can_hover => 1, 356 can_hover => 1,
331 can_events => 1, 357 can_events => 1,
340} 366}
341 367
342# this is a shortcut method that asks for a binding 368# this is a shortcut method that asks for a binding
343# and then just binds it. 369# and then just binds it.
344sub quick_macro { 370sub quick_macro {
345 my ($self, $cmds, $end_cb) = @_; 371 my ($cmds, $end_cb) = @_;
346 372
347 my $macro = { 373 my $macro = {
348 action => $cmds, 374 action => $cmds,
349 }; 375 };
350 376
351 trigger_edit $macro, sub { 377 trigger_edit $macro, sub {
352
353 if ($_[0]) { 378 if ($_[0]) {
354 push @{ $::PROFILE->{macro} }, $macro; 379 push @{ $::PROFILE->{macro} }, $macro;
355 $REFRESH_MACRO_LIST->(); 380 $REFRESH_MACRO_LIST->();
356 } 381 }
357 382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines