Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
}
}
if ($dictFlag) {
# Update the dictionary's ->primaryOppHash and ->primaryOppAbbrevHash IVs
$dictObj->updateOppDirHash();
}
if ($self->ivShow('ivChangeHash', 'definiteList')) {
$dictObj->ivPoke('definiteList', $self->definiteList);
}
if ($self->ivShow('ivChangeHash', 'indefiniteList')) {
$dictObj->ivPoke('indefiniteList', $self->indefiniteList);
}
if ($self->ivShow('ivChangeHash', 'andList')) {
$dictObj->ivPoke('andList', $self->andList);
}
if ($self->ivShow('ivChangeHash', 'orList')) {
$dictObj->ivPoke('orList', $self->orList);
}
if ($self->ivShow('ivChangeHash', 'numberList')) {
if (@numberList && (scalar @numberList) == 10) {
for (my $num = 1; $num <= 10; $num++) {
$dictObj->ivAdd(
'numberHash',
shift @numberList,
$num,
);
}
}
}
# If the user clicked one of the language buttons in either of the first two windows, ask
# them if they'd like to set the dictionary's language
# $self->dirPageLang and ->dictPageLang, if set, are the names of the equivalent phrasebook
# objects
if ($self->dirPageLang) {
$pbObjDir = $axmud::CLIENT->ivShow('constPhrasebookHash', $self->dirPageLang);
}
if ($self->dictPageLang) {
$pbObjDict = $axmud::CLIENT->ivShow('constPhrasebookHash', $self->dirPageLang);
}
if ($pbObjDir && $pbObjDict && $pbObjDir->name ne $pbObjDict->name) {
# Open a 'dialogue' window with a combobox, so the user can choose between the languages
$declineString = 'Don\'t change the language';
# @comboList should only contain languages that aren't the current dictionary's language
push (@comboList, $declineString);
if ($pbObjDir->targetName ne $dictObj->language) {
push (@comboList, $pbObjDir->targetName);
}
if ($pbObjDict->targetName ne $dictObj->language) {
push (@comboList, $pbObjDict->targetName);
}
# Prompt the user
$choice = $self->showComboDialogue(
'Change dictionary language',
'Do you want to change the current dictionary\'s language?',
\@comboList,
);
if ($choice && $choice ne $declineString) {
$dictObj->ivPoke('language', $choice);
# Also set the dictionary's noun-adjective word order, while we're at it
if ($pbObjDir->targetName eq $choice) {
$dictObj->ivPoke('nounPosn', $pbObjDir->nounPosn);
} else {
$dictObj->ivPoke('nounPosn', $pbObjDict->nounPosn);
}
}
} elsif ($pbObjDir || $pbObjDict) {
# Open a 'dialogue' window with yes/no buttons, so the user can choose a language
if ($pbObjDir) {
$string = $pbObjDir->targetName;
} else {
$string = $pbObjDict->targetName;
}
$choice = $self->showMsgDialogue(
'Change dictionary language',
'question',
'Do you want to change the current dictionary\'s language to \'' . $string . '\'?',
'yes-no',
);
if ($choice && $choice eq 'yes') {
$dictObj->ivPoke('language', $string);
if ($pbObjDir->targetName eq $choice) {
$dictObj->ivPoke('nounPosn', $pbObjDir->nounPosn);
} else {
$dictObj->ivPoke('nounPosn', $pbObjDict->nounPosn);
}
}
}
lib/Games/Axmud/WizWin.pm view on Meta::CPAN
$self->grid,
"Starting from the top, please identify the component to which every line belongs.",
1, 12, 1, 2);
# Add some widgets immediately below the labels
my $button = $self->addButton(
$self->grid,
undef,
'Update lines',
'Use the most recently-received lines',
1, 3, 2, 3);
my $button2 = $self->addButton(
$self->grid,
undef,
'More lines',
'Use more lines',
3, 5, 2, 3);
my $button3 = $self->addButton(
$self->grid,
undef,
'Fewer lines',
'Use fewer lines',
5, 7, 2, 3);
my ($radioButton, $radioButton2, $radioButton3, $group);
($group, $radioButton) = $self->addRadioButton(
$self->grid,
undef,
undef,
'Verbose',
FALSE,
TRUE,
8, 10, 2, 3);
($group, $radioButton2) = $self->addRadioButton(
$self->grid,
undef,
$group,
'Short verbose',
FALSE,
TRUE,
10, 11, 2, 3);
($group, $radioButton3) = $self->addRadioButton(
$self->grid,
undef,
$group,
'Brief',
FALSE,
TRUE,
11, 12, 2, 3);
# ->signal_connects appear further down...
if ($self->analysisType eq 'short') {
$radioButton2->set_active(TRUE);
} elsif ($self->analysisType eq 'brief') {
$radioButton3->set_active(TRUE);
}
# Set the row at which the remaining widgets start to be drawn
$row = 3;
# Add a list of entry and comboboxes, one for each line of recently-received text
$self->capturePage_drawWidgets($row, \@labelList, \@entryList, \@comboList);
# If no capture has yet been performed, set their initial values
if (! $self->bufferObjList) {
# No capture has yet been performed, so set their initial values
$self->capturePage_resetWidgets(\@entryList, \@comboList);
} else {
# Show data in the entries and comboboxes from the previous capture
$self->capturePage_updateWidgets(\@entryList, \@comboList);
}
# Give the comboboxes their own ->signal_connect methods
$self->capturePage_connectCombos(\@comboList);
# Here's the ->signal_connect methods from earlier
$button->signal_connect('clicked' => sub {
# 'Update list' button. Reset the list of lines recently received from the world
$self->capturePage_resetWidgets(\@entryList, \@comboList);
$self->capturePage_connectCombos(\@comboList);
});
$button2->signal_connect('clicked' => sub {
# 'More lines' button. Add more lines to the number displayed, then re-draw the entries
# and comboboxes.
$self->ivPoke('analysisLength', $self->analysisLength + $self->analysisInc);
# Prevent the user from setting more lines than the maximum by desensitising the button
if (
$self->analysisLength >= $self->analysisMaxLength
|| (
$self->analysisLength > $self->analysisMinLength
&& $self->analysisLength >= $self->session->displayBufferCount
)
) {
$button2->set_sensitive(FALSE);
} else {
$button2->set_sensitive(TRUE);
}
# (The opposite button must be sensitised)
$button3->set_sensitive(TRUE);
# 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');
});
$button3->signal_connect('clicked' => sub {
# 'Fewer lines' button. Remove more lines to the number displayed, then re-draw the
# entries and comboboxes.
$self->ivPoke('analysisLength', $self->analysisLength - $self->analysisInc);
# Prevent the user setting fewer lines than the minimum by desensitising the button
if ($self->analysisLength <= $self->analysisMinLength) {
$button3->set_sensitive(FALSE);
} else {
$button3->set_sensitive(TRUE);
}
# (The opposite button must be sensitised)
$button2->set_sensitive(TRUE);
# 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');
});
$radioButton->signal_connect('toggled' => sub {
if ($radioButton->get_active()) {
$self->ivPoke('analysisType', 'verbose');
}
# 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');
});
$radioButton2->signal_connect('toggled' => sub {
if ($radioButton2->get_active()) {
$self->ivPoke('analysisType', 'short');
}
# 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');
});
$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
# Resets the entry/combo boxes (one for each line in the display buffer displayed on this
# page)
#
# Expected arguments
# $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
# lines
# $comboListRef - Reference to a list of Gtk3::ComboBox-s in which to display components
#
# Return values
# An empty list on improper arguments
# Otherwise, returns the list of lines displayed
my ($self, $entryListRef, $comboListRef, $check) = @_;
# Local variables
my (
$startLine, $stopLine, $count,
@emptyList, @entryList, @lineList,
);
# Check for improper arguments
if (! defined $entryListRef || ! defined $comboListRef || defined $check) {
$axmud::CLIENT->writeImproper($self->_objClass . '->capturePage_resetWidgets', @_);
return @emptyList;
}
$self->ivEmpty('bufferObjList');
$self->ivEmpty('bufferTypeList');
# Show the last $self->analysisLength lines received by the world, but don't exceed the
# boundaries of the display buffer
if ($self->session->displayBufferCount) {
$stopLine = $self->session->displayBufferLast;
$startLine = $self->session->displayBufferLast - ($self->analysisLength - 1);
if ($startLine < $self->session->displayBufferFirst) {
# Don't look before the first line in the buffer
$startLine = $self->session->displayBufferFirst;
}
$count = -1;
for (my $line = $startLine; $line <= $stopLine; $line++) {
my ($bufferObj, $text, $entry);
$count++;
$bufferObj = $self->session->ivShow('displayBufferHash', $line);
$text = $bufferObj->modLine;
# Set the value displayed in the entry box numbered $count
$entry = $$entryListRef[$count];
$entry->set_text($text);
push (@lineList, $text);
# Update the record stored in the IV
$self->ivPush('bufferObjList', $bufferObj);
}
}
# Reset the comboboxes to contain the first component in the component list (which is
# 'outside_statement' for verbose, short verbose and brief statements)
foreach my $comboBox (@$comboListRef) {
$comboBox->set_active(0);
if ($self->analysisType eq 'verbose') {
$self->ivPush('bufferTypeList', $self->ivFirst('verboseComponentList'));
} elsif ($self->analysisType eq ' short') {
$self->ivPush('bufferTypeList', $self->ivFirst('shortComponentList'));
} else {
$self->ivPush('bufferTypeList', $self->ivFirst('briefComponentList'));
}
}
return @lineList;
}
sub capturePage_updateWidgets {
# Called by $self->capturePage
# Updates the entry/combo boxes (one for each line in the display buffer displayed on this
# page) after the initial call to ->capturePage, in order to display data from the last
# capture
#
# Expected arguments
# $entryListRef - Reference to a list of Gtk3::Entry boxes in which to display received
# lines
# $comboListRef - Reference to a list of Gtk3::ComboBox-s in which to display components
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $entryListRef, $comboListRef, $check) = @_;
# Local variables
my (
$count,
@bufferObjList,
);
# Check for improper arguments
if (! defined $entryListRef || ! defined $comboListRef || defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->capturePage_updateWidgets',
@_,
);
}
# Import the previously-captured list of display buffer objects
@bufferObjList = $self->bufferObjList;
# Update the entry boxes
$count = -1;
foreach my $bufferObj (@bufferObjList) {
my $entry;
$count++;
$entry = $$entryListRef[$count];
$entry->set_text($bufferObj->modLine);
}
# Update the combos
$count = -1;
OUTER: foreach my $component ($self->bufferTypeList) {
my ($combo, $posn);
$count++;
$combo = $$comboListRef[$count];
if (defined $combo) {
# Find the position of the component in the ordered list
if ($self->analysisType eq 'verbose') {
$posn = $self->ivFind('verboseComponentList', $component);
} elsif ($self->analysisType eq 'short') {
$posn = $self->ivFind('shortComponentList', $component);
} else {
$posn = $self->ivFind('briefComponentList', $component);
}
# Set the combobox to that position (if it was found)
if (defined $posn) {
$combo->set_active($posn);
}
}
}
return 1;
}
sub capturePage_connectCombos {
# Called by $self->capturePage, usually after a call to ->capturePage_drawWidgets
# Gives each combobox a ->signal_connect method
#
# Expected arguments
# $comboListRef - Reference to a list of Gtk3::ComboBoxes in which to display components
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $comboListRef, $check) = @_;
# Check for improper arguments
if (! defined $comboListRef || defined $check) {
return $axmud::CLIENT->writeImproper(
$self->_objClass . '->capturePage_connectCombos',
@_,
);
}
OUTER: foreach my $comboBox (@$comboListRef) {
$comboBox->signal_connect('changed' => sub {
my ($textIndex, $match, $updateFlag);
$textIndex = $comboBox->get_active();
# Find the index of this combobox, as stored in $comboListRef
INNER: for (my $count = 0; $count < $self->analysisLength; $count++) {
if ($$comboListRef[$count] eq $comboBox) {
$match = $count;
last INNER;
}
}
# Update the record stored in the IV
if ($self->analysisType eq 'verbose') {
$self->ivReplace(
'bufferTypeList',
$match,
$self->ivIndex('verboseComponentList', $textIndex),
);
} elsif ($self->analysisType eq 'short') {
$self->ivReplace(
'bufferTypeList',
$match,
$self->ivIndex('shortComponentList', $textIndex),
);
} else {
$self->ivReplace(
'bufferTypeList',
$match,
$self->ivIndex('briefComponentList', $textIndex),
);
}
# Change the contents of every combobox beneath this one to match
if ($match < ($self->analysisLength - 1)) {
$$comboListRef[$match + 1]->set_active($textIndex);
}
});
}
return 1;
}
sub analysisPage {
# Analysis 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 ($result, $msg, $row, $string, $listRef, $bufferObj);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->analysisPage', @_);
}
$self->addLabel($self->grid, '<b>Analysis (' . $self->getPageString() . ')</b>',
0, 12, 0, 1);
# Perform the analysis of the data gathered in the previous page
($result, $msg) = $self->analyseLines();
# Analysis failed
if (! $result) {
$self->addLabel($self->grid, 'Room statement analysis <u>FAILED</u>. Failure message:',
1, 12, 1, 2);
$self->addLabel($self->grid, '<i>' . $msg . '</i>',
1, 12, 2, 3);
$self->addLabel(
$self->grid,
"Try analysing a different room statement. Send your character to the new room,"
. " then click\nthe <b>\'Previous\'</b> button to return to the previous page.",
1, 12, 3, 4);
$self->addLabel(
$self->grid,
"(N.B. The wizard uses a set of rules which are stricter than the normal rules. If"
. " you want to\ndo something that\'s not allowed here, you can try editing the"
. " world profile directly\nusing its 'edit' window.)",
1, 12, 4, 5);
# If the user had already analysed a room statement, allow them to move on to the last
# page (skipping the next one); otherwise, de-sensitise the 'Next' button, forcing
# them to go back
( run in 1.581 second using v1.01-cache-2.11-cpan-8dfa8b56332 )