Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
'launch' => FALSE,
'notepad' => FALSE,
},
# Initial task settings
taskSettingHash => {
'status_win' => TRUE,
'status_gauge' => TRUE,
'locator_win' => TRUE,
},
# Instruction sigils
sigilHash => {
'echo' => FALSE,
'perl' => FALSE,
'script' => FALSE,
'multi' => FALSE,
'speed' => FALSE,
'bypass' => FALSE,
},
};
# Bless the object into existence
bless $self, $class;
return $self;
}
##################
# Methods
# Standard window object functions
sub winSetup {
# Called by GA::Generic::Win->createFreeWin, after the call to $self->new
# Creates the Gtk3::Window itself
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments or if the window can't be opened
# 1 on success
my ($self, $check) = @_;
# Local variables
my ($hAdjust, $vAdjust, $ratioX, $ratioY, $newX, $newY);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
}
# Most of the code is in the generic function
if (! $self->Games::Axmud::Generic::FreeWin::winSetup()) {
return undef;
}
# Some desktop managers use a bigger font than the author's desktop manager; as a result,
# 'free' windows like this one will be too small for comfort
# This window is (usually) only seen the first time Axmud is run. If the user's destkop
# manager font is too big, this window's Gtk3::ScrolledWindow will contain scrollbars
# If the scrollbars are present, we can increase the size of default 'free' windows to
# compensate, which removes the scrollbars in this window and (hopefully) most other
# 'free' windows, too
# Typically, this process makes the default 'free' window size slightly larger than it
# strictly needs to be, but that's still better than a Connections window with none of
# the 'Connect' buttons visible
# Drawing the window early makes the scrollbars testable (->winShowAll() is normally first
# called by $self->winEnable)
$self->winShowAll($self->_objClass . '->winSetup');
# Detect the presence of any scrollbars and decide by which ratio the window's size should
# be increased
$hAdjust = $self->scroller->get_hadjustment();
if ($hAdjust->get_upper() != $hAdjust->get_page_size()) {
$ratioX = $hAdjust->get_upper() / $hAdjust->get_page_size();
} else {
$ratioX = 1;
}
$vAdjust = $self->scroller->get_vadjustment();
if ($vAdjust->get_upper() != $vAdjust->get_page_size()) {
$ratioY = $vAdjust->get_upper() / $vAdjust->get_page_size();
} else {
$ratioY = 1;
}
if ($ratioX != 1 || $ratioY != 1) {
# One (or both) scrollbars detected
$newX = int($self->widthPixels * $ratioX);
$newY = int($self->heightPixels * $ratioY);
# Adjust the size of this window to compensate
$self->winWidget->resize($newX, $newY);
# Adjust the default size of future 'free' windows to compensate
$axmud::CLIENT->set_customFreeWinSize($newX, $newY);
}
return 1;
}
# sub winEnable {} # Inherited from GA::Generic::WizWin
# sub winDesengage {} # Inherited from GA::Generic::FreeWin
sub winDestroy {
# Can be called by anything
# Updates IVs
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments, if the window can't be destroyed or if it has already
# been destroyed
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
# Most of the code is in the generic function
$result = $self->Games::Axmud::Generic::WizWin::winDestroy();
if ($result) {
# Window closed. The Connections window must now be opened
$axmud::CLIENT->mainWin->quickFreeWin('Games::Axmud::OtherWin::Connect');
}
return $result;
}
# sub winShowAll {} # Inherited from GA::Generic::Win
# sub drawWidgets {} # Inherited from GA::Generic::WizWin
# sub redrawWidgets {} # Inherited from GA::Generic::Win
# ->signal_connects
# Other functions
sub saveChanges {
# Called by $self->buttonNext when the user clicks the 'Finish' button
# Saves changes to the current world profile and/or current dictionary, before closing the
# window
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Local variables
my (
$zonemapObj, $slWidget, $initStatusObj, $initLocatorObj,
@taskList,
%checkHash,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
}
# Update Client IVs
if (! $self->shareMainWinFlag) {
$axmud::CLIENT->set_shareMainWinFlag(FALSE);
} else {
$axmud::CLIENT->set_shareMainWinFlag(TRUE);
}
if ($self->zonemap eq 'none') {
$axmud::CLIENT->set_activateGridFlag(TRUE);
$axmud::CLIENT->desktopObj->defaultWorkspaceObj->disableWorkspaceGrids();
$axmud::CLIENT->desktopObj->defaultWorkspaceObj->reset_defaultZonemap();
} else {
$axmud::CLIENT->ivAdd('initWorkspaceHash', 0, $self->zonemap);
$zonemapObj = $axmud::CLIENT->ivShow('zonemapHash', $self->zonemap);
if ($zonemapObj) {
$axmud::CLIENT->desktopObj->defaultWorkspaceObj->set_defaultZonemap($zonemapObj);
}
}
# In v1.2.0, window tiling was enabled for MSWin users. For those users with existing Axmud
# installations, this 'wiz' window is called a second time
# For that reason, check that Locator/Status tasks don't already exist in the global
# tasklist. If they do, update their settings, rather than creating a new task
foreach my $initTaskObj ($axmud::CLIENT->ivValues('initTaskHash')) {
if ($initTaskObj->name eq 'status_task') {
$initStatusObj = $initTaskObj;
} elsif ($initTaskObj->name eq 'locator_task') {
$initLocatorObj = $initTaskObj;
}
# While we're at it, compile a hash of global initial tasks, containing only the first
# instance of each type of task
$checkHash{$initTaskObj->name} = undef;
}
# Remove pre-configured worlds, as required
$slWidget = $self->slWidget;
OUTER: foreach my $listRef (@{$slWidget->{data}}) {
my ($worldObj, $fileObj);
# $listRef is in the form [remove_flag, profile_name...]
if ($$listRef[0]) {
# Remove this world profile
$worldObj = $axmud::CLIENT->ivShow('worldProfHash', $$listRef[1]);
if ($worldObj) {
# (It should not be possible for any session to be running, but in case someone
# is testing this window, we'll check anyway)
INNER: foreach my $session ($axmud::CLIENT->listSessions()) {
if (defined $session->currentWorld && $session->currentWorld eq $worldObj) {
# (Not a fatal error)
$axmud::CLIENT->writeWarning(
'Could not delete world profile \'' . $worldObj->name
. '\' - it is in use by a session',
$self->_objClass . '->saveChanges',
);
next OUTER;
}
}
# Delete the world's data files. First find the file object
$fileObj = $axmud::CLIENT->ivShow('fileObjHash', $worldObj->name);
if (! $fileObj) {
# (Not a fatal error)
$axmud::CLIENT->writeWarning(
'Could not delete world profile \'' . $worldObj->name
. '\' - file object is missing',
$self->_objClass . '->saveChanges',
);
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
# (->signal_connects from above)
if ($self->shareMainWinFlag) {
$radioButton->set_active(TRUE);
} else {
$radioButton2->set_active(TRUE);
}
$radioButton->signal_connect('toggled' => sub {
if ($radioButton->get_active()) {
$self->ivPoke('shareMainWinFlag', TRUE);
$self->ivPoke('zonemap', 'basic');
}
});
$radioButton2->signal_connect('toggled' => sub {
if ($radioButton2->get_active()) {
$self->ivPoke('shareMainWinFlag', FALSE);
$self->ivPoke('zonemap', 'horizontal');
}
});
# (Empty labels for spacing)
my $label = $self->addLabel($self->grid, '',
1, 12, 9, 10);
$label->set_vexpand(TRUE);
return 1;
}
sub zonemapPage {
# Zonemap page - called by $self->setupGrid or ->updateGrid
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Local variables
my @spacingList;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->zonemapPage', @_);
}
# Zonemaps
$self->addLabel($self->grid, '<b>Zonemaps (' . $self->getPageString() . ')</b>',
0, 12, 0, 1);
$self->addLabel(
$self->grid,
"<i>A zonemap is a plan for arranging windows on the desktop. Select the best zonemap"
. " for your system.</i>",
1, 12, 1, 2);
if ($self->shareMainWinFlag) {
$self->addSimpleImage(
$self->grid,
$axmud::SHARE_DIR . '/icons/setup/basic_zonemap.png',
undef,
1, 4, 2, 5);
my ($radioButton, $radioButton2, $radioButton3, $group);
($group, $radioButton) = $self->addRadioButton(
$self->grid,
undef,
undef,
'Basic',
FALSE,
TRUE,
4, 6, 3, 4);
$self->addSimpleImage(
$self->grid,
$axmud::SHARE_DIR . '/icons/setup/extended_zonemap.png',
undef,
7, 10, 2, 5);
($group, $radioButton2) = $self->addRadioButton(
$self->grid,
undef,
$group,
'Extended',
FALSE,
TRUE,
10, 12, 3, 4);
# (Empty labels for spacing)
$self->addLabel($self->grid, '',
1, 12, 5, 6);
$self->addSimpleImage(
$self->grid,
$axmud::SHARE_DIR . '/icons/setup/widescreen_zonemap.png',
undef,
1, 4, 6, 9);
($group, $radioButton3) = $self->addRadioButton(
$self->grid,
undef,
$group,
'Widescreen',
FALSE,
TRUE,
4, 6, 7, 8);
# (->signal_connects from above)
# As a convenience for users, auto-set the 'widescreen' zonemap (but only do this once,
# otherwise widescreen will be re-selected if the 'Previous' button is clicked)
# Use 1800, rather than 1920, as the test in case there are desktop panels on the
# left and/or right sides
if (
defined $self->workspaceObj->currentWidth
&& $self->workspaceObj->currentWidth >= 1800
&& ! $self->widescreenFlag
) {
$radioButton3->set_active(TRUE);
$self->ivPoke('zonemap', 'widescreen');
$self->ivPoke('widescreenFlag', TRUE);
} elsif ($self->zonemap eq 'basic') {
$radioButton->set_active(TRUE);
} elsif ($self->zonemap eq 'extended') {
$radioButton2->set_active(TRUE);
} else {
$radioButton3->set_active(TRUE);
}
$radioButton->signal_connect('toggled' => sub {
if ($radioButton->get_active()) {
$self->ivPoke('zonemap', 'basic');
}
});
$radioButton2->signal_connect('toggled' => sub {
if ($radioButton2->get_active()) {
$self->ivPoke('zonemap', 'extended');
}
});
$radioButton3->signal_connect('toggled' => sub {
if ($radioButton3->get_active()) {
$self->ivPoke('zonemap', 'widescreen');
}
});
} else {
$self->addSimpleImage(
$self->grid,
$axmud::SHARE_DIR . '/icons/setup/horizontal_zonemap.png',
undef,
1, 4, 2, 5);
my ($radioButton, $radioButton2, $radioButton3, $group);
($group, $radioButton) = $self->addRadioButton(
$self->grid,
undef,
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
$radioButton3->signal_connect('toggled' => sub {
if ($radioButton3->get_active()) {
$self->ivPoke('analysisType', 'brief');
}
# Redraw the entries and comboboxes
$self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
$self->capturePage_resetWidgets(\@entryList, \@comboList);
$self->capturePage_connectCombos(\@comboList);
# Make the changes visible
$self->winShowAll($self->_objClass . '->capturePage');
});
return 1;
}
sub capturePage_drawWidgets {
# Called by $self->capturePage
# Draws a Gtk3::Entry and a Gtk3::Combobox, one for each line in the display buffer
# displayed on this page
#
# Expected arguments
# $startRow - The row on which the first entry/combobox is drawn
# $labelListRef - Reference to a list of Gtk3::Labels at the beginning of each line
# (an empty list if none have been drawn yet)
# $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
# lines (an empty list if none have been drawn yet)
# $comboListRef - Reference to a list of Gtk3::ComboBoxes in which to display components
# (an empty list if none have been drawn yet)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $startRow, $labelListRef, $entryListRef, $comboListRef, $check) = @_;
# Local variables
my $row;
# Check for improper arguments
if (
! defined $startRow || ! defined $labelListRef || ! defined $entryListRef
|| ! defined $comboListRef || defined $check
) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->capturePage_drawWidgets',
@_,
);
}
# If any labels/entries/combo boxes have already been drawn, remove them from the grid
if (@$labelListRef) {
foreach my $label (@$labelListRef) {
$axmud::CLIENT->desktopObj->removeWidget($self->grid, $label);
}
@$labelListRef = ();
foreach my $entry (@$entryListRef) {
$axmud::CLIENT->desktopObj->removeWidget($self->grid, $entry);
}
@$entryListRef = ();
foreach my $comboBox (@$comboListRef) {
$axmud::CLIENT->desktopObj->removeWidget($self->grid, $comboBox);
}
@$comboListRef = ();
}
# Add a list of entry boxes, one for each line
$row = $startRow;
for (my $line = 0; $line < $self->analysisLength; $line++) {
$row++;
my $label = $self->addLabel($self->grid, '#' . ($line + 1),
1, 2, $row, ($row + 1));
push (@$labelListRef, $label);
my $entry = $self->addEntry($self->grid, undef, undef, TRUE,
2, 9, $row, ($row + 1),
40); # Fixed width
# (Rather than desensitising the entry boxes, just make them un-editable)
$entry->set_editable(FALSE);
push (@$entryListRef, $entry);
}
# Add combo boxes, one for each entry box
$row = $startRow;
for (my $line = 0; $line < $self->analysisLength; $line++) {
my (@componentList, @comboList);
$row++;
# The comboboxes show the default list of components (for verbose, short verbose or
# brief statements)
if ($self->analysisType eq 'verbose') {
@componentList = $self->verboseComponentList;
} elsif ($self->analysisType eq 'short') {
@componentList = $self->shortComponentList;
} elsif ($self->analysisType eq 'brief') {
@componentList = $self->briefComponentList;
}
foreach my $component (@componentList) {
push (@comboList, $self->ivShow('componentTypeHash', $component));
}
my $comboBox = $self->addComboBox($self->grid, undef, \@comboList, undef,
9, 12, $row, ($row + 1));
push (@$comboListRef, $comboBox);
}
return 1;
}
sub capturePage_resetWidgets {
# Called by $self->capturePage, sometimes after a call to $self->capturePage_drawWidgets
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
$string = lc($string);
# $self->tempDelimList contains a list of brief exit delimiters stored by the previous page.
# Sort the delimiter list by size, so that a delimiter which is just a comma isn't
# processed before a delimiter which is <, > - which would be ignored, if the comma
# had already been extracted
@delimList = sort {length ($b) <=> length ($a)} ($self->tempDelimList);
# Initialise @returnArray with the string containing the list of exits to process
push (@returnArray, $string);
foreach my $delim (@delimList) {
# For each delimiter, move everything already in @returnArray into @tempArray
# For each element now in @tempArray, split it into a list using the delimiter, and push
# it back into @returnArray
# After each iteration, @returnArray will contain the same number of, or more, elements
# than it did before
@tempArray = @returnArray;
@returnArray = ();
foreach my $item (@tempArray) {
my @list = split ($delim, $item);
push (@returnArray, @list);
}
}
return @returnArray;
}
sub textViewSignalConnect {
# Called by several functions
# Extracts the data from a textview buffer (added with $self->addTextView). Splits it
# into lines of text, removes leading/trailing whitespace, and stores the result in one
# of this object's list IVs
# (Code used is very similar to the ->signal_connect in GA::Generic::EditWin->addTextView)
#
# Expected arguments
# $buffer - The Gtk3::TextView's buffer
# $iv - The list IV in which the lines should be stored
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $buffer, $iv, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->textViewSignalConnect', @_);
}
$buffer->signal_connect('changed' => sub {
my (
$text,
@list, @finalList,
);
$text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
# Split the contents of the textview into a list of lines, separated by newline
# characters
@list = split("\n", $text);
# Remove any empty lines and leading/trailing whitespace
foreach my $line (@list) {
if ($line) {
$line =~ s/^\s*//; # Remove leading whitespace
$line =~ s/\s*$//; # Remove trailing whitepsace
(push @finalList, $line);
}
}
# Set the IV
$self->ivPoke($iv, @finalList);
# Update the hash of changed IVs
$self->ivAdd('ivChangeHash', $iv, TRUE);
});
return 1;
}
sub updateTextView {
# Called by $self->analysisPage and later pages
# Fills a Gtk3::TextView with the lines in a single component
#
# Expected arguments
# $textView - The Gtk3::TextView to fill up
# $component - The component to use - a key in $self->analysisHash
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $textView, $component, $check) = @_;
# Local variables
my (
$textViewBuffer, $listRef,
@bufferObjList, @stringList,
);
# Check for improper arguments
if (! defined $textView || ! defined $component || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->updateTextView', @_);
}
$textViewBuffer = $textView->get_buffer();
# If $component doesn't exist as a key in $self->analysisHash - meaning that the user
# didn't allocate any lines to this component - just make sure the textview is empty
if (! $self->ivExists('analysisHash', $component)) {
( run in 0.801 second using v1.01-cache-2.11-cpan-bbc515a03b3 )