Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Win/Map.pm view on Meta::CPAN
});
$popupMenu->append($menu_item);
}
# Add a 'remove all' menu item
$popupMenu->append(Gtk3::SeparatorMenuItem->new()); # Separator
my $remove_all_item = Gtk3::MenuItem->new('Remove all');
$remove_all_item->signal_connect('activate' => sub {
my ($total, $choice);
$total = scalar $self->worldModelObj->preferBGColourList;
# If there's more than one colour, prompt the user for confirmation
if ($total > 1) {
$choice = $self->showMsgDialogue(
'Remove all colour buttons',
'question',
'Are you sure you want to remove all ' . $total . ' colour buttons?',
'yes-no',
);
} else {
$choice = 'yes';
}
if (defined $choice && $choice eq 'yes') {
# Reset the world model's list of preferred background colour...
$self->worldModelObj->reset_preferBGColourList();
# ...then redraw the window component containing the toolbar(s)
$self->redrawWidgets('toolbar');
}
});
$popupMenu->append($remove_all_item);
# Also add a 'Cancel' menu item, which does nothing
my $cancel_item = Gtk3::MenuItem->new('Cancel');
$cancel_item->signal_connect('activate' => sub {
return undef;
});
$popupMenu->append($cancel_item);
# Display the popup menu
$popupMenu->popup(
undef, undef, undef, undef,
1, # Left mouse button
Gtk3::get_current_event_time(),
);
$popupMenu->show_all();
# Operation complete. Now wait for the user's response
return 1;
}
# Treeview widget methods
sub enableTreeView {
# Called by $self->drawWidgets
# Sets up the Automapper window's treeview widget
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if the widget can't be created
# Otherwise returns the Gtk3::ScrolledWindow containing the Gtk3::TreeView created
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->enableTreeView', @_);
}
# Create the treeview
my $objectModel = Gtk3::TreeStore->new( ['Glib::String'] );
my $treeView = Gtk3::TreeView->new($objectModel);
if (! $objectModel || ! $treeView) {
return undef;
}
# No interactive searches required
$treeView->set_enable_search(FALSE);
# Append a single column to the treeview
$treeView->append_column(
Gtk3::TreeViewColumn->new_with_attributes(
'Regions',
Gtk3::CellRendererText->new,
markup => 0,
)
);
# Make the treeview scrollable
my $treeViewScroller = Gtk3::ScrolledWindow->new;
$treeViewScroller->add($treeView);
$treeViewScroller->set_policy(qw/automatic automatic/);
# Make the branches of the list tree clickable, so the rows can be expanded and collapsed
$treeView->signal_connect('row_activated' => sub {
my ($treeView, $path, $column) = @_;
$self->treeViewRowActivatedCallback();
});
$treeView->get_selection->set_mode('browse');
$treeView->get_selection->signal_connect('changed' => sub {
my ($selection) = @_;
$self->treeViewRowChangedCallback($selection);
lib/Games/Axmud/Win/Map.pm view on Meta::CPAN
sub expandTreeView {
# Called by $self->resetTreeView and by this function, recursively
# Expands rows in the tree model, to make sure that a certain region is visible.
#
# Expected arguments
# $model - The treeview model (a Gtk3::TreeModel object)
# $expandRegion - The name of a region that should be visible. This function expands
# the row belonging to $expandRegion's parent (if any), then calls
# this function recursively, to expand the row for the parent's
# parent (if any)
#
# Return values
# 'undef' on improper arguments or if no further expansions are required
# 1 otherwise
my ($self, $model, $expandRegion, $check) = @_;
# Local variables
my ($expandObj, $parentObj, $pointer, $path);
# Check for improper arguments
if (! defined $model || ! defined $expandRegion || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->expandTreeView', @_);
}
# Find the corresponding world model object
$expandObj = $self->findRegionObj($expandRegion);
if (! $expandObj || ! $expandObj->parent) {
# No further expansions required
return undef;
}
# Get the parent object's name
$parentObj = $self->worldModelObj->ivShow('modelHash', $expandObj->parent);
# Expand the parent's row (if it's not already expanded)
if (
$self->ivExists('treeViewRegionHash', $parentObj->name)
&& ! $self->ivShow('treeViewRegionHash', $parentObj->name)
) {
# This row must be expanded
$pointer = $self->ivShow('treeViewPointerHash', $parentObj->name);
$path = $model->get_path($pointer);
$self->treeView->expand_row($path, TRUE);
# Mark it as expanded
$self->ivAdd('treeViewRegionHash', $parentObj->name, TRUE);
}
# Call this function recursively, to expand the parent's parent (if it has one)
$self->expandTreeView($model, $parentObj->name);
return 1;
}
sub treeViewRowActivatedCallback {
# Treeview's 'row_activated' callback - called when the user double-clicks on one of the
# treeview's cells
# Called from an anonymous sub in $self->enableTreeView
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Local variables
my $regionName;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->treeViewRowActivatedCallback',
@_,
);
}
# Don't do anything if the canvas is currently invisible
if ($self->worldModelObj->showCanvasFlag) {
# Get the selected region
$regionName = $self->treeViewSelectedLine;
if ($regionName) {
if ($self->worldModelObj->ivExists('regionmapHash', $regionName)) {
# Make it the selected region, and draw it on the map
$self->setCurrentRegion($regionName);
} else {
# Remove any markup to get the actual region name
$regionName =~ s/^\<[iu]\>//;
$regionName =~ s/\<\/[iu]\>$//;
if ($self->worldModelObj->ivExists('regionmapHash', $regionName)) {
# Make it the selected region, and draw it on the map
$self->setCurrentRegion($regionName);
}
}
}
}
# Sensitise/desensitise menu bar/toolbar items, depending on current conditions
$self->restrictWidgets();
return 1;
}
sub treeViewRowChangedCallback {
# Treeview's 'changed' callback - called when the user single-clicks on one of the
# treeview's cells
# Called from an anonymous sub in $self->enableTreeView
#
# Expected arguments
# $selection - A Gtk3::Selection
#
# Return values
# 'undef' on improper arguments or if the selection is not recognised
# 1 otherwise
my ($self, $selection, $check) = @_;
# Local variables
my ($model, $iter, $region);
# Check for improper arguments
if (! defined $selection || defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->treeViewRowChangedCallback',
@_,
);
}
($model, $iter) = $selection->get_selected();
if (! $iter) {
return undef;
} else {
# Get the region on the selected line
$region = $model->get($iter, 0);
# Store it, so that other methods can access the region on the selected line
$self->ivPoke('treeViewSelectedLine', $region);
# Sensitise/desensitise menu bar/toolbar items, depending on current conditions
$self->restrictWidgets();
return 1;
}
}
sub treeViewRowExpandedCallback {
# Treeview's 'row_expanded' callback - called when the user expands one of the treeview's
# rows to reveal a region's child regions
# Called from an anonymous sub in $self->enableTreeView
#
# Expected arguments
# $iter - A Gtk3::TreeIter
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $iter, $check) = @_;
# Local variables
my $region;
# Check for improper arguments
if (! defined $iter || defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->treeViewRowExpandedCallback',
@_,
);
}
# Get the region in the expanded row
$region = $self->treeViewModel->get($iter, 0);
# Mark the row as expanded
$self->ivAdd('treeViewRegionHash', $region, TRUE);
return 1;
}
sub treeViewRowCollapsedCallback {
# Treeview's 'row_collapsed' callback - called when the user collapses one of the treeview's
# rows to hide a region's child regions
# Called from an anonymous sub in $self->enableTreeView
#
# Expected arguments
# $iter - A Gtk3::TreeIter
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $iter, $check) = @_;
# Local variables
my $region;
# Check for improper arguments
if (! defined $iter || defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->treeViewRowCollapsedCallback',
@_,
);
}
# Get the region in the collapsed row
$region = $self->treeViewModel->get($iter, 0);
# Mark the row as collapsed
$self->ivAdd('treeViewRegionHash', $region, FALSE);
return 1;
}
sub treeViewSelectRow {
# Called by $self->setCurrentRegion when the current region is set (or unset)
# Makes sure that, if there's a new current region, it is the one highlighted in the
# treeview's list
#
# Expected arguments
# $region - The name of the highlighted region (matches $self->currentRegionmap->name)
# - if not specified, there is no current region
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $region, $check) = @_;
# Local variables
my ($pointer, $path);
# Check for improper arguments
if (! defined $region || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->treeViewSelectRow', @_);
}
# Highlight the region named $region
$pointer = $self->ivShow('treeViewPointerHash', $region);
( run in 0.731 second using v1.01-cache-2.11-cpan-39bf76dae61 )