1 | package CFPlus::Macro; |
1 | package DC::Macro; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use List::Util (); |
5 | use List::Util (); |
6 | use CFPlus::UI; |
6 | use DC::UI; |
7 | |
7 | |
8 | our $REFRESH_MACRO_LIST; |
8 | our $REFRESH_MACRO_LIST; |
9 | |
9 | |
10 | our %DEFAULT_KEYMAP = ( |
10 | our %DEFAULT_KEYMAP = ( |
11 | (map +("($_)" => "!completer $_"), "a" .. "z"), |
11 | (map +("($_)" => "!completer $_"), "a" .. "z"), |
12 | "(!)" => "!completer shout ", |
12 | "(!)" => "!completer shout ", |
13 | "(\")" => "!completer say ", |
13 | "(\")" => "!completer say ", |
14 | "(')" => "!completer", |
14 | "(')" => "!completer", |
15 | |
15 | |
16 | "LShift-tab" => "!toggle-messagewindow", |
16 | # "LShift-tab" => "!toggle-messagewindow", |
17 | "RShift-tab" => "!toggle-messagewindow", |
17 | # "RShift-tab" => "!toggle-messagewindow", |
18 | "tab" => "!toggle-playerbook", |
18 | "tab" => "!toggle-playerbook", |
19 | "f1" => "!toggle-help", |
19 | "f1" => "!toggle-help", |
20 | "f2" => "!toggle-stats", |
20 | "f2" => "!toggle-stats", |
21 | "f3" => "!toggle-skills", |
21 | "f3" => "!toggle-skills", |
22 | "f4" => "!toggle-spells", |
22 | "f4" => "!toggle-spells", |
23 | "f5" => "!toggle-inventory", |
23 | "f5" => "!toggle-inventory", |
24 | "f9" => "!toggle-setup", |
24 | "f9" => "!toggle-setup", |
|
|
25 | |
25 | (map +("LAlt-$_" => "!switch-tab $_"), 0..9), |
26 | (map +("LRAM-$_" => "!switch-tab $_"), 0..9), |
26 | (map +("RAlt-$_" => "!switch-tab $_"), 0..9), |
27 | "LRAM-x" => "!close-current-tab", |
|
|
28 | |
27 | "return" => "!activate-chat", |
29 | "return" => "!activate-chat", |
28 | "." => "!repeat-command", |
30 | "." => "!repeat-command", |
29 | |
31 | |
30 | "," => "take", |
32 | "," => "take", |
31 | "space" => "apply", |
33 | "space" => "apply", |
|
|
34 | "enter" => "examine", |
32 | "[+]" => "rotateshoottype +", |
35 | "[+]" => "rotateshoottype +", |
33 | "[-]" => "rotateshoottype -", |
36 | "[-]" => "rotateshoottype -", |
|
|
37 | |
|
|
38 | "LRAM-e" => "examine", |
34 | "LAlt-s" => "ready_skill find traps", |
39 | "LRAM-s" => "ready_skill find traps", |
35 | "LAlt-d" => "ready_skill disarm traps", |
40 | "LRAM-d" => "ready_skill disarm traps", |
36 | "LAlt-p" => "ready_skill praying", |
41 | "LRAM-p" => "ready_skill praying", |
37 | ); |
42 | ); |
38 | |
43 | |
39 | # allowed modifiers |
44 | # allowed modifiers |
40 | our %MODIFIER = ( |
45 | our %MODIFIER = ( |
41 | "LShift" => CFPlus::KMOD_LSHIFT, |
46 | "LShift" => DC::KMOD_LSHIFT, |
42 | "RShift" => CFPlus::KMOD_RSHIFT, |
47 | "RShift" => DC::KMOD_RSHIFT, |
43 | # "Shift" => CFPlus::KMOD_LSHIFT | CFPlus::KMOD_RSHIFT, |
48 | # "Shift" => DC::KMOD_LSHIFT | DC::KMOD_RSHIFT, |
44 | "LCtrl" => CFPlus::KMOD_LCTRL, |
49 | "LCtrl" => DC::KMOD_LCTRL, |
45 | "RCtrl" => CFPlus::KMOD_RCTRL, |
50 | "RCtrl" => DC::KMOD_RCTRL, |
46 | # "Ctrl" => CFPlus::KMOD_LCTRL | CFPlus::KMOD_RCTRL, |
51 | # "Ctrl" => DC::KMOD_LCTRL | DC::KMOD_RCTRL, |
47 | "LAlt" => CFPlus::KMOD_LALT, |
52 | "LAlt" => DC::KMOD_LALT, |
48 | "RAlt" => CFPlus::KMOD_RALT, |
53 | "RAlt" => DC::KMOD_RALT, |
49 | # "Alt" => CFPlus::KMOD_LALT | CFPlus::KMOD_RALT, |
54 | # "Alt" => DC::KMOD_LALT | DC::KMOD_RALT, |
50 | "LMeta" => CFPlus::KMOD_LMETA, |
55 | "LMeta" => DC::KMOD_LMETA, |
51 | "RMeta" => CFPlus::KMOD_RMETA, |
56 | "RMeta" => DC::KMOD_RMETA, |
52 | # "Meta" => CFPlus::KMOD_LMETA | CFPlus::KMOD_RMETA, |
57 | # "Meta" => DC::KMOD_LMETA | DC::KMOD_RMETA, |
|
|
58 | "LRAM" => DC::KMOD_LRAM, # left/right/alt/meta |
53 | ); |
59 | ); |
54 | |
60 | |
55 | # allowed modifiers |
61 | # allowed modifiers |
56 | our $MODIFIER_MASK |= $_ for values %MODIFIER; |
62 | our $MODIFIER_MASK |= $_ for values %MODIFIER; |
57 | |
63 | |
58 | # can bind to these without any modifier |
64 | # can bind to these without any modifier |
59 | our @DIRECT_CHARS = qw(0 1 2 3 4 5 6 7 8 9); |
65 | our @DIRECT_CHARS = qw(0 1 2 3 4 5 6 7 8 9); |
60 | |
66 | |
61 | our @DIRECT_KEYS = ( |
67 | our @DIRECT_KEYS = ( |
62 | CFPlus::SDLK_F1, |
68 | DC::SDLK_F1, |
63 | CFPlus::SDLK_F2, |
69 | DC::SDLK_F2, |
64 | CFPlus::SDLK_F3, |
70 | DC::SDLK_F3, |
65 | CFPlus::SDLK_F4, |
71 | DC::SDLK_F4, |
66 | CFPlus::SDLK_F5, |
72 | DC::SDLK_F5, |
67 | CFPlus::SDLK_F6, |
73 | DC::SDLK_F6, |
68 | CFPlus::SDLK_F7, |
74 | DC::SDLK_F7, |
69 | CFPlus::SDLK_F8, |
75 | DC::SDLK_F8, |
70 | CFPlus::SDLK_F9, |
76 | DC::SDLK_F9, |
71 | CFPlus::SDLK_F10, |
77 | DC::SDLK_F10, |
72 | CFPlus::SDLK_F11, |
78 | DC::SDLK_F11, |
73 | CFPlus::SDLK_F12, |
79 | DC::SDLK_F12, |
74 | CFPlus::SDLK_F13, |
80 | DC::SDLK_F13, |
75 | CFPlus::SDLK_F14, |
81 | DC::SDLK_F14, |
76 | CFPlus::SDLK_F15, |
82 | DC::SDLK_F15, |
77 | ); |
83 | ); |
78 | |
84 | |
79 | our %MACRO_FUNCTION = ( |
85 | our %MACRO_FUNCTION = ( |
80 | "toggle-messagewindow" => sub { $::MESSAGE_WINDOW->toggle_visibility }, |
86 | "toggle-messagewindow" => sub { $::MESSAGE_WINDOW->toggle_visibility }, |
81 | "toggle-playerbook" => sub { $::PL_WINDOW->toggle_visibility }, |
87 | "toggle-playerbook" => sub { $::PL_WINDOW->toggle_visibility }, |
… | |
… | |
86 | "toggle-inventory" => sub { ::toggle_player_page ($::INVENTORY_PAGE) }, |
92 | "toggle-inventory" => sub { ::toggle_player_page ($::INVENTORY_PAGE) }, |
87 | "toggle-pickup" => sub { ::toggle_player_page ($::PICKUP_PAGE) }, |
93 | "toggle-pickup" => sub { ::toggle_player_page ($::PICKUP_PAGE) }, |
88 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
94 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
89 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
95 | "toggle-setup" => sub { $::SETUP_DIALOG->toggle_visibility }, |
90 | "switch-tab" => sub { $::MESSAGE_WINDOW->user_switch_to_page (0 + shift) }, |
96 | "switch-tab" => sub { $::MESSAGE_WINDOW->user_switch_to_page (0 + shift) }, |
|
|
97 | "close-current-tab" => sub { $::MESSAGE_WINDOW->close_current_tab }, |
91 | "activate-chat" => sub { $::MESSAGE_WINDOW->activate_current }, |
98 | "activate-chat" => sub { $::MESSAGE_WINDOW->activate_current }, |
92 | "repeat-command" => sub { |
99 | "repeat-command" => sub { |
93 | $::CONN->user_send ($::COMPLETER->{last_command}) |
100 | $::CONN->user_send ($::COMPLETER->{last_command}) |
94 | if $::CONN && exists $::COMPLETER->{last_command}; |
101 | if $::CONN && exists $::COMPLETER->{last_command}; |
95 | }, |
102 | }, |
… | |
… | |
103 | |
110 | |
104 | our $DEFAULT_KEYMAP; |
111 | our $DEFAULT_KEYMAP; |
105 | |
112 | |
106 | sub init { |
113 | sub init { |
107 | $DEFAULT_KEYMAP ||= do { |
114 | $DEFAULT_KEYMAP ||= do { |
108 | my %sym = map +(CFPlus::SDL_GetKeyName $_, $_), CFPlus::SDLK_FIRST .. CFPlus::SDLK_LAST; |
115 | my %sym = map +(DC::SDL_GetKeyName $_, $_), DC::SDLK_FIRST .. DC::SDLK_LAST; |
109 | my $map; |
116 | my $map; |
110 | |
117 | |
111 | while (my ($k, $v) = each %DEFAULT_KEYMAP) { |
118 | while (my ($k, $v) = each %DEFAULT_KEYMAP) { |
112 | if ($k =~ /^\((.)\)$/) { |
119 | if ($k =~ /^\((.)\)$/) { |
113 | $map->{U}{ord $1} = $v; |
120 | $map->{U}{ord $1} = $v; |
… | |
… | |
116 | my $sym = $sym{pop @mod} |
123 | my $sym = $sym{pop @mod} |
117 | or warn "unknown keysym $k\n"; |
124 | or warn "unknown keysym $k\n"; |
118 | |
125 | |
119 | my $mod = 0; $mod |= $MODIFIER{$_} for @mod; |
126 | my $mod = 0; $mod |= $MODIFIER{$_} for @mod; |
120 | |
127 | |
121 | $map->{K}[CFPlus::popcount $mod]{$mod}{$sym} = $v; |
128 | $map->{K}[DC::popcount $mod]{$mod}{$sym} = $v; |
122 | } |
129 | } |
123 | } |
130 | } |
124 | |
131 | |
125 | %DEFAULT_KEYMAP = (); |
132 | %DEFAULT_KEYMAP = (); |
126 | $map |
133 | $map |
… | |
… | |
128 | } |
135 | } |
129 | |
136 | |
130 | sub accelkey_to_string($) { |
137 | sub accelkey_to_string($) { |
131 | join "-", |
138 | join "-", |
132 | (grep $_[0][0] & $MODIFIER{$_}, keys %MODIFIER), |
139 | (grep $_[0][0] & $MODIFIER{$_}, keys %MODIFIER), |
133 | CFPlus::SDL_GetKeyName $_[0][1] |
140 | DC::SDL_GetKeyName $_[0][1] |
134 | } |
141 | } |
135 | |
142 | |
136 | sub trigger_to_string($) { |
143 | sub trigger_to_string($) { |
137 | my ($macro) = @_; |
144 | my ($macro) = @_; |
138 | |
145 | |
… | |
… | |
165 | $window->disconnect_all ("focus_out"); |
172 | $window->disconnect_all ("focus_out"); |
166 | $window->destroy; |
173 | $window->destroy; |
167 | &$end_cb; |
174 | &$end_cb; |
168 | }; |
175 | }; |
169 | |
176 | |
170 | $window = new CFPlus::UI::Toplevel |
177 | $window = new DC::UI::Toplevel |
171 | title => "Edit Macro Trigger", |
178 | title => "Edit Macro Trigger", |
172 | x => "center", |
179 | x => "center", |
173 | y => "center", |
180 | y => "center", |
174 | z => 1000, |
181 | z => 1000, |
175 | can_events => 1, |
182 | can_events => 1, |
… | |
… | |
183 | $done->(0); |
190 | $done->(0); |
184 | 1 |
191 | 1 |
185 | }, |
192 | }, |
186 | ; |
193 | ; |
187 | |
194 | |
188 | $window->add (my $vb = new CFPlus::UI::VBox); |
195 | $window->add (my $vb = new DC::UI::VBox); |
189 | |
196 | |
190 | $vb->add (new CFPlus::UI::Label |
197 | $vb->add (new DC::UI::Label |
191 | text => "To bind the macro to a key,\n" |
198 | text => "To bind the macro to a key,\n" |
192 | . "press a modifier (Ctrl, Alt\n" |
199 | . "press a modifier (Ctrl, Alt\n" |
193 | . "and/or Shift) and a key, or\n" |
200 | . "and/or Shift) and a key, or\n" |
194 | . "0-9 and F1-F15 without any modifier\n\n" |
201 | . "0-9 and F1-F15 without any modifier\n\n" |
195 | . "To cancel press Escape or close this.\n\n" |
202 | . "To cancel press Escape or close this.\n\n" |
196 | . "Accelerator key combo:", |
203 | . "Accelerator key combo:", |
197 | ellipsise => 0, |
204 | ellipsise => 0, |
198 | ); |
205 | ); |
199 | |
206 | |
200 | $vb->add (my $entry = new CFPlus::UI::Label |
207 | $vb->add (my $entry = new DC::UI::Label |
201 | fg => [0, 0, 0, 1], |
208 | fg => [0, 0, 0, 1], |
202 | bg => [1, 1, 0, 1], |
209 | bg => [1, 1, 0, 1], |
203 | ); |
210 | ); |
204 | |
211 | |
205 | my $key_cb = sub { |
212 | my $key_cb = sub { |
… | |
… | |
218 | map "$_-", |
225 | map "$_-", |
219 | grep $mod & $MODIFIER{$_}, |
226 | grep $mod & $MODIFIER{$_}, |
220 | keys %MODIFIER |
227 | keys %MODIFIER |
221 | ); |
228 | ); |
222 | |
229 | |
223 | return if $sym >= CFPlus::SDLK_MODIFIER_MIN |
230 | return if $sym >= DC::SDLK_MODIFIER_MIN |
224 | && $sym <= CFPlus::SDLK_MODIFIER_MAX; |
231 | && $sym <= DC::SDLK_MODIFIER_MAX; |
225 | |
232 | |
226 | if ($mod |
233 | if ($mod |
227 | || ((grep $_ eq chr $ev->{unicode}, @DIRECT_CHARS) |
234 | || ((grep $_ eq chr $ev->{unicode}, @DIRECT_CHARS) |
228 | || (grep $_ == $sym, @DIRECT_KEYS))) |
235 | || (grep $_ == $sym, @DIRECT_KEYS))) |
229 | { |
236 | { |
230 | $macro->{accelkey} = [$mod, $sym]; |
237 | $macro->{accelkey} = [$mod, $sym]; |
231 | $done->(1); |
238 | $done->(1); |
232 | } else { |
239 | } else { |
233 | $entry->set_text ("cannot bind " . (CFPlus::SDL_GetKeyName $sym) . " without modifier."); |
240 | $entry->set_text ("cannot bind " . (DC::SDL_GetKeyName $sym) . " without modifier."); |
234 | } |
241 | } |
235 | 1 |
242 | 1 |
236 | }; |
243 | }; |
237 | |
244 | |
238 | $window->connect (key_up => $key_cb); |
245 | $window->connect (key_up => $key_cb); |
… | |
… | |
242 | $window->show; |
249 | $window->show; |
243 | } |
250 | } |
244 | |
251 | |
245 | sub find_default($) { |
252 | sub find_default($) { |
246 | my ($ev) = @_; |
253 | my ($ev) = @_; |
247 | |
|
|
248 | if (my $cmd = $DEFAULT_KEYMAP->{U}{$ev->{unicode}}) { |
|
|
249 | return $cmd; |
|
|
250 | } |
|
|
251 | |
254 | |
252 | for my $m (reverse grep $_, @{ $DEFAULT_KEYMAP->{K} }) { |
255 | for my $m (reverse grep $_, @{ $DEFAULT_KEYMAP->{K} }) { |
253 | for (keys %$m) { |
256 | for (keys %$m) { |
254 | if ($_ == ($ev->{mod} & $_)) { |
257 | if ($_ == ($ev->{mod} & $_)) { |
255 | if (defined (my $cmd = $m->{$_}{$ev->{sym}})) { |
258 | if (defined (my $cmd = $m->{$_}{$ev->{sym}})) { |
256 | return $cmd; |
259 | return $cmd; |
257 | } |
260 | } |
258 | } |
261 | } |
259 | } |
262 | } |
|
|
263 | } |
|
|
264 | |
|
|
265 | if (my $cmd = $DEFAULT_KEYMAP->{U}{$ev->{unicode}}) { |
|
|
266 | return $cmd; |
260 | } |
267 | } |
261 | |
268 | |
262 | () |
269 | () |
263 | } |
270 | } |
264 | |
271 | |
… | |
… | |
303 | } |
310 | } |
304 | } |
311 | } |
305 | } |
312 | } |
306 | |
313 | |
307 | sub keyboard_setup { |
314 | sub keyboard_setup { |
308 | my $kbd_setup = new CFPlus::UI::VBox; |
315 | my $kbd_setup = new DC::UI::VBox; |
309 | |
316 | |
310 | $kbd_setup->add (my $list = new CFPlus::UI::VBox); |
317 | $kbd_setup->add (my $list = new DC::UI::VBox); |
311 | |
318 | |
312 | $list->add (new CFPlus::UI::FancyFrame |
319 | $list->add (new DC::UI::FancyFrame |
313 | label => "Options", |
320 | label => "Options", |
314 | child => (my $hb = new CFPlus::UI::HBox), |
321 | child => (my $hb = new DC::UI::HBox), |
315 | ); |
322 | ); |
316 | $hb->add (new CFPlus::UI::Label text => "only shift-up stops fire"); |
323 | $hb->add (new DC::UI::Label text => "only shift-up stops fire"); |
317 | $hb->add (new CFPlus::UI::CheckBox |
324 | $hb->add (new DC::UI::CheckBox |
318 | expand => 1, |
325 | expand => 1, |
319 | state => $::CFG->{shift_fire_stop}, |
326 | state => $::CFG->{shift_fire_stop}, |
320 | tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift.", |
327 | tooltip => "If this checkbox is enabled you will stop fire only if you stop pressing shift.", |
321 | on_changed => sub { |
328 | on_changed => sub { |
322 | my ($cbox, $value) = @_; |
329 | my ($cbox, $value) = @_; |
323 | $::CFG->{shift_fire_stop} = $value; |
330 | $::CFG->{shift_fire_stop} = $value; |
324 | 0 |
331 | 0 |
325 | }, |
332 | }, |
326 | ); |
333 | ); |
327 | |
334 | |
328 | $list->add (new CFPlus::UI::FancyFrame |
335 | $list->add (new DC::UI::FancyFrame |
329 | label => "Macros", |
336 | label => "Macros", |
330 | child => (my $macros = new CFPlus::UI::VBox), |
337 | child => (my $macros = new DC::UI::VBox), |
331 | ); |
338 | ); |
332 | |
339 | |
333 | my $refresh; |
340 | my $refresh; |
334 | |
341 | |
335 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
342 | my $tooltip_common = "\n\n<small>Left click - edit macro\nMiddle click - invoke macro\nRight click - further options</small>"; |
… | |
… | |
338 | |
345 | |
339 | my $edit_macro = sub { |
346 | my $edit_macro = sub { |
340 | my ($macro) = @_; |
347 | my ($macro) = @_; |
341 | |
348 | |
342 | $kbd_setup->clear; |
349 | $kbd_setup->clear; |
343 | $kbd_setup->add (new CFPlus::UI::Button |
350 | $kbd_setup->add (new DC::UI::Button |
344 | text => "Return", |
351 | text => "Return", |
345 | tooltip => "Return to the macro list.", |
352 | tooltip => "Return to the macro list.", |
346 | on_activate => sub { |
353 | on_activate => sub { |
347 | $kbd_setup->clear; |
354 | $kbd_setup->clear; |
348 | $kbd_setup->add ($list); |
355 | $kbd_setup->add ($list); |
349 | $refresh->(); |
356 | $refresh->(); |
350 | 1 |
357 | 1 |
351 | }, |
358 | }, |
352 | ); |
359 | ); |
353 | $kbd_setup->add (new CFPlus::UI::FancyFrame |
360 | $kbd_setup->add (new DC::UI::FancyFrame |
354 | label => "Edit Macro", |
361 | label => "Edit Macro", |
355 | child => (my $editor = new CFPlus::UI::Table col_expand => [0, 1]), |
362 | child => (my $editor = new DC::UI::Table col_expand => [0, 1]), |
356 | ); |
363 | ); |
357 | |
364 | |
358 | $editor->add_at (0, 1, new CFPlus::UI::Label |
365 | $editor->add_at (0, 1, new DC::UI::Label |
359 | text => "Trigger", |
366 | text => "Trigger", |
360 | tooltip => $tooltip_trigger, |
367 | tooltip => $tooltip_trigger, |
361 | can_hover => 1, |
368 | can_hover => 1, |
362 | can_events => 1, |
369 | can_events => 1, |
363 | ); |
370 | ); |
364 | $editor->add_at (0, 2, new CFPlus::UI::Label |
371 | $editor->add_at (0, 2, new DC::UI::Label |
365 | text => "Actions", |
372 | text => "Actions", |
366 | tooltip => $tooltip_commands, |
373 | tooltip => $tooltip_commands, |
367 | can_hover => 1, |
374 | can_hover => 1, |
368 | can_events => 1, |
375 | can_events => 1, |
369 | ); |
376 | ); |
370 | |
377 | |
371 | $editor->add_at (1, 2, my $textedit = new CFPlus::UI::TextEdit |
378 | $editor->add_at (1, 2, my $textedit = new DC::UI::TextEdit |
372 | text => macro_to_text $macro, |
379 | text => macro_to_text $macro, |
373 | tooltip => $tooltip_commands, |
380 | tooltip => $tooltip_commands, |
374 | on_changed => sub { |
381 | on_changed => sub { |
375 | $macro->{action} = macro_from_text $macro, $_[1]; |
382 | $macro->{action} = macro_from_text $macro, $_[1]; |
376 | }, |
383 | }, |
377 | ); |
384 | ); |
378 | |
385 | |
379 | $editor->add_at (1, 1, my $accel = new CFPlus::UI::Button |
386 | $editor->add_at (1, 1, my $accel = new DC::UI::Button |
380 | text => trigger_to_string $macro, |
387 | text => trigger_to_string $macro, |
381 | tooltip => "To change the trigger for a macro, activate this button.", |
388 | tooltip => "To change the trigger for a macro, activate this button.", |
382 | on_activate => sub { |
389 | on_activate => sub { |
383 | my ($accel) = @_; |
390 | my ($accel) = @_; |
384 | trigger_edit $macro, sub { |
391 | trigger_edit $macro, sub { |
… | |
… | |
387 | 1 |
394 | 1 |
388 | }, |
395 | }, |
389 | ); |
396 | ); |
390 | |
397 | |
391 | my $recording; |
398 | my $recording; |
392 | $editor->add_at (1, 3, new CFPlus::UI::Button |
399 | $editor->add_at (1, 3, new DC::UI::Button |
393 | text => "Start Recording", |
400 | text => "Start Recording", |
394 | tooltip => "Start/Stop command recording: when recording, " |
401 | tooltip => "Start/Stop command recording: when recording, " |
395 | . "actions and commands you invoke are appended to this macro. " |
402 | . "actions and commands you invoke are appended to this macro. " |
396 | . "You can only record when you are logged in.", |
403 | . "You can only record when you are logged in.", |
397 | on_destroy => sub { |
404 | on_destroy => sub { |
… | |
… | |
413 | } |
420 | } |
414 | }, |
421 | }, |
415 | ); |
422 | ); |
416 | }; |
423 | }; |
417 | |
424 | |
418 | $macros->add (new CFPlus::UI::Button |
425 | $macros->add (new DC::UI::Button |
419 | text => "New Macro", |
426 | text => "New Macro", |
420 | tooltip => "Creates a new, empty, macro you can edit.", |
427 | tooltip => "Creates a new, empty, macro you can edit.", |
421 | on_activate => sub { |
428 | on_activate => sub { |
422 | my $macro = { }; |
429 | my $macro = { }; |
423 | push @{ $::PROFILE->{macro} }, $macro; |
430 | push @{ $::PROFILE->{macro} }, $macro; |
424 | $edit_macro->($macro); |
431 | $edit_macro->($macro); |
425 | }, |
432 | }, |
426 | ); |
433 | ); |
427 | |
434 | |
428 | $macros->add (my $macrolist = new CFPlus::UI::Table col_expand => [0, 1]); |
435 | $macros->add (my $macrolist = new DC::UI::Table col_expand => [0, 1]); |
429 | |
436 | |
430 | $REFRESH_MACRO_LIST = $refresh = sub { |
437 | $REFRESH_MACRO_LIST = $refresh = sub { |
431 | $macrolist->clear; |
438 | $macrolist->clear; |
432 | |
439 | |
433 | $macrolist->add_at (0, 1, new CFPlus::UI::Label |
440 | $macrolist->add_at (0, 1, new DC::UI::Label |
434 | text => "Trigger", |
441 | text => "Trigger", |
|
|
442 | tooltip => $tooltip_trigger . $tooltip_common, |
|
|
443 | ); |
|
|
444 | $macrolist->add_at (1, 1, new DC::UI::Label |
|
|
445 | text => "Actions", |
435 | align => 0, |
446 | align => 0, |
436 | tooltip => $tooltip_trigger . $tooltip_common, |
|
|
437 | ); |
|
|
438 | $macrolist->add_at (1, 1, new CFPlus::UI::Label |
|
|
439 | text => "Commands", |
|
|
440 | tooltip => $tooltip_commands . $tooltip_common, |
447 | tooltip => $tooltip_commands . $tooltip_common, |
441 | ); |
448 | ); |
442 | |
449 | |
443 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
450 | for my $idx (0 .. $#{$::PROFILE->{macro} || []}) { |
444 | my $macro = $::PROFILE->{macro}[$idx]; |
451 | my $macro = $::PROFILE->{macro}[$idx]; |
… | |
… | |
450 | if ($ev->{button} == 1) { |
457 | if ($ev->{button} == 1) { |
451 | $edit_macro->($macro), |
458 | $edit_macro->($macro), |
452 | } elsif ($ev->{button} == 2) { |
459 | } elsif ($ev->{button} == 2) { |
453 | $::CONN->macro_send ($macro) if $::CONN; |
460 | $::CONN->macro_send ($macro) if $::CONN; |
454 | } elsif ($ev->{button} == 3) { |
461 | } elsif ($ev->{button} == 3) { |
455 | (new CFPlus::UI::Menu |
462 | (new DC::UI::Menu |
456 | items => [ |
463 | items => [ |
457 | ["Edit" => sub { $edit_macro->($macro) }], |
464 | ["Edit" => sub { $edit_macro->($macro) }], |
458 | ["Invoke" => sub { $::CONN->macro_send ($macro) if $::CONN }], |
465 | ["Invoke" => sub { $::CONN->macro_send ($macro) if $::CONN }], |
459 | ["Delete" => sub { |
466 | ["Delete" => sub { |
460 | # might want to use grep instead |
467 | # might want to use grep instead |
… | |
… | |
468 | } |
475 | } |
469 | |
476 | |
470 | 1 |
477 | 1 |
471 | }; |
478 | }; |
472 | |
479 | |
473 | $macrolist->add_at (0, $y, new CFPlus::UI::Label |
480 | $macrolist->add_at (0, $y, new DC::UI::Label |
474 | text => trigger_to_string $macro, |
481 | text => trigger_to_string $macro, |
475 | tooltip => $tooltip_trigger . $tooltip_common, |
482 | tooltip => $tooltip_trigger . $tooltip_common, |
476 | align => 0, |
483 | fg => [1, 0.8, 0.8], |
477 | can_hover => 1, |
484 | can_hover => 1, |
478 | can_events => 1, |
485 | can_events => 1, |
479 | on_button_down => $macro_cb, |
486 | on_button_down => $macro_cb, |
480 | ); |
487 | ); |
481 | |
488 | |
482 | $macrolist->add_at (1, $y, new CFPlus::UI::Label |
489 | $macrolist->add_at (1, $y, new DC::UI::Label |
483 | text => (join "; ", @{ $macro->{action} || [] }), |
490 | text => (join "; ", @{ $macro->{action} || [] }), |
484 | tooltip => $tooltip_commands . $tooltip_common, |
491 | tooltip => $tooltip_commands . $tooltip_common, |
|
|
492 | fg => [0.9, 0.9, 0.9], |
|
|
493 | align => 0, |
485 | expand => 1, |
494 | expand => 1, |
486 | ellipsise => 3, |
495 | ellipsise => 3, |
487 | can_hover => 1, |
496 | can_hover => 1, |
488 | can_events => 1, |
497 | can_events => 1, |
489 | on_button_down => $macro_cb, |
498 | on_button_down => $macro_cb, |