Deliantra-Client
view release on metacpan or search on metacpan
DC/Macro.pm view on Meta::CPAN
. "actions and commands you invoke are appended to this macro. "
. "You can only record when you are logged in.",
on_destroy => sub {
$::CONN->record if $::CONN;
},
on_activate => sub {
my ($widget) = @_;
$recording = $::CONN && !$recording;
if ($recording) {
$widget->set_text ("Stop Recording");
$::CONN->record (sub {
push @{ $macro->{action} }, $_[0];
$textedit->set_text (macro_to_text $macro);
}) if $::CONN;
} else {
$widget->set_text ("Start Recording");
$::CONN->record if $::CONN;
}
},
);
};
$macros->add (new DC::UI::Button
text => "New Macro",
tooltip => "Creates a new, empty, macro you can edit.",
on_activate => sub {
my $macro = { };
push @{ $::PROFILE->{macro} }, $macro;
$edit_macro->($macro);
},
);
$macros->add (my $macrolist = new DC::UI::Table col_expand => [0, 1]);
$REFRESH_MACRO_LIST = $refresh = sub {
$macrolist->clear;
$macrolist->add_at (0, 1, new DC::UI::Label
text => "Trigger",
tooltip => $tooltip_trigger . $tooltip_common,
);
$macrolist->add_at (1, 1, new DC::UI::Label
text => "Actions",
align => 0,
tooltip => $tooltip_commands . $tooltip_common,
);
for my $idx (0 .. $#{$::PROFILE->{macro} || []}) {
my $macro = $::PROFILE->{macro}[$idx];
my $y = $idx + 2;
my $macro_cb = sub {
my ($widget, $ev) = @_;
if ($ev->{button} == 1) {
$edit_macro->($macro),
} elsif ($ev->{button} == 2) {
execute ($macro);
} elsif ($ev->{button} == 3) {
(new DC::UI::Menu
items => [
["Edit" => sub { $edit_macro->($macro) }],
["Invoke" => sub { execute ($macro) }],
["Delete" => sub {
# might want to use grep instead
splice @{$::PROFILE->{macro}}, $idx, 1, ();
$refresh->();
}],
],
)->popup ($ev);
} else {
return 0;
}
1
};
$macrolist->add_at (0, $y, new DC::UI::Label
text => trigger_to_string $macro,
tooltip => $tooltip_trigger . $tooltip_common,
fg => [1, 0.8, 0.8],
can_hover => 1,
can_events => 1,
on_button_down => $macro_cb,
);
$macrolist->add_at (1, $y, new DC::UI::Label
text => (join "; ", @{ $macro->{action} || [] }),
tooltip => $tooltip_commands . $tooltip_common,
fg => [0.9, 0.9, 0.9],
align => 0,
expand => 1,
ellipsise => 3,
can_hover => 1,
can_events => 1,
on_button_down => $macro_cb,
);
}
};
$refresh->();
$kbd_setup
}
# this is a shortcut method that asks for a binding
# and then just binds it.
sub quick_macro {
my ($cmds, $end_cb) = @_;
my $macro = {
action => $cmds,
};
trigger_edit $macro, sub {
if ($_[0]) {
push @{ $::PROFILE->{macro} }, $macro;
$REFRESH_MACRO_LIST->();
}
( run in 1.411 second using v1.01-cache-2.11-cpan-39bf76dae61 )