Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Task.pm view on Meta::CPAN
# I experimented with the table coordinates to stop the combobox/buttons appearing too
# high. For unknown reasons, the best arrangement is to leave a one-row gap between the
# textview and the combobox/buttons beneath it
$textTableObj = $self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::TextView',
0, 59, 0, 57,
undef,
# Init settings
'func' => $self->getMethodRef('textViewCallback'),
'text' => $string,
'edit_flag' => TRUE,
'colour_scheme' => 'edit',
'spacing' => 0,
);
# Add a combo to switch between profiles, displaying a list of current profiles in reverse
# priority order (so that the current world is always at the top)
$self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::Label',
0, 4, 58, 59,
undef,
# Init settings
'text' => 'Profile: ',
);
%profHash = $self->session->currentProfHash;
foreach my $category ($self->session->profPriorityList) {
my $profObj = $profHash{$category};
if (defined $profObj) {
delete $profHash{$category};
push (@comboList, $profObj->name);
}
}
@comboList = reverse @comboList; # Current world to top of list
foreach my $profObj (sort {lc($a->name) cmp lc($b->name)} (values %profHash)) {
push (@comboList, $profObj->name);
}
$comboTableObj = $self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::ComboBox',
5, 24, 58, 59,
undef,
# Init settings
'func' => $self->getMethodRef('comboCallback'),
'list_ref' => \@comboList,
);
# Add buttons - one to empty the textview of notes, another to restore the displayed notes
# to what they were, when the task started (or was last reset)
$self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::Button',
30, 39, 58, 59,
undef,
# Init settings
'func' => $self->getMethodRef('clipboardCallback'),
'text' => 'Paste',
'tooltips' => 'Insert any selected text in the session\'s default tab',
);
$self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::Button',
40, 49, 58, 59,
undef,
# Init settings
'func' => $self->getMethodRef('emptyCallback'),
'text' => 'Empty',
'tooltips' => 'Empty the notes for this profile',
);
$self->winObj->tableStripObj->addTableObj(
'Games::Axmud::Table::Button',
50, 59, 58, 59,
undef,
# Init settings
'func' => $self->getMethodRef('restoreCallback'),
'text' => 'Restore',
'tooltips' => 'Restore the notes that existed when this task started',
);
# Store the widgets created, so that callbacks can access them
$self->ivPoke('textTableObj', $textTableObj);
$self->ivPoke('comboTableObj', $comboTableObj);
# Display all the widgets
$self->winObj->winShowAll($self->_objClass . '->createWidgets');
return 1;
}
##################
# Response methods
sub textViewCallback {
# Called by a ->signal_connect in a GA::Table::TextView object when the user edits the
# textview's contents
# Stores the textview's contents in the selected profile's IV
#
# Expected arguments
# $tableObj - The GA::Table::TextView object for the textview
# $textView - The actual Gtk3::TextView edited
# $buffer - The textview's Gtk3::Buffer
# $id - The callback ID; in this case, an empty string
# $text - The contents of the buffer (a string containing one or more lines
# separated by newline characters)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $tableObj, $textView, $buffer, $id, $text, $check) = @_;
# Local variables
my ($profile, $profObj);
lib/Games/Axmud/Task.pm view on Meta::CPAN
}
# Get the combobox's active profile
$profile = $self->comboTableObj->get_text();
$profObj = $self->session->ivShow('profHash', $profile);
# Update the selected profile's IV
if ($profObj) {
if ($text) {
$profObj->ivPoke('notepadList', split("\n", $text));
} else {
$profObj->ivEmpty('notepadList');
}
}
return 1;
}
sub comboCallback {
# Called by a ->signal_connect in a GA::Table::Button object when the user selects a
# profile in the combobox
# Updates the contents of the textview to show notes for that profile
#
# Expected arguments
# $tableObj - The GA::Table::ComboBox object for the combobox
# $comboBox - The actual Gtk3::ComboBox used
# $id - The callback ID; in this case, an empty string
# $profile - The selected world profile
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $tableObj, $comboBox, $id, $profile, $check) = @_;
# Local variables
my $profObj;
# Check for improper arguments
if (
! defined $tableObj || ! defined $comboBox || ! defined $id || ! defined $profile
|| defined $check
) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->comboCallback', @_);
}
# Get the corresponding profile object
$profObj = $self->session->ivShow('profHash', $profile);
# Update the textview
if ($profObj) {
$self->textTableObj->set_text(join("\n", $profObj->notepadList));
}
return 1;
}
sub clipboardCallback {
# Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the
# 'Empty notes' button
# Pastes the contents of the clipboard into the textview
#
# Expected arguments
# $tableObj - The GA::Table::Button object for the button
# $button - The actual Gtk3::Button clicked
# $id - The callback ID; in this case, a keycode
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $tableObj, $button, $id, $check) = @_;
# Local variables
my ($textViewObj, $startIter, $endIter, $slice);
# Check for improper arguments
if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->clipboardCallback', @_);
}
$textViewObj = $self->session->defaultTabObj->textViewObj;
($startIter, $endIter) = $textViewObj->buffer->get_selection_bounds();
if (defined $endIter) {
$slice = $textViewObj->buffer->get_slice($startIter, $endIter, FALSE);
if (defined $slice && $slice ne '') {
$self->textTableObj->insert_text($slice);
}
return 1;
}
}
sub emptyCallback {
# Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the
# 'Empty' button
# Empties the textview and updates the selected profile's IV
#
# Expected arguments
# $tableObj - The GA::Table::Button object for the button
# $button - The actual Gtk3::Button clicked
# $id - The callback ID; in this case, a keycode
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $tableObj, $button, $id, $check) = @_;
# Check for improper arguments
if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->emptyCallback', @_);
}
# Empty the textview
$self->textTableObj->set_text();
return 1;
}
sub restoreCallback {
# Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the
# 'Restore' button
# Restores the notes displayed in the textview for the current profile, when the task
# started (or was last reset)
#
# Expected arguments
# $tableObj - The GA::Table::Button object for the button
# $button - The actual Gtk3::Button clicked
# $id - The callback ID; in this case, a keycode
#
# Return values
# 'undef' on improper arguments
( run in 1.807 second using v1.01-cache-2.11-cpan-84e82930d8c )