Games-Axmud

 view release on metacpan or  search on metacpan

lib/Games/Axmud/EditWin.pm  view on Meta::CPAN


        # Add tabs to the inner notebook
        $self->contents1Tab($innerNotebook);
        $self->contents2Tab($innerNotebook);
        $self->contents3Tab($innerNotebook);

        return 1;
    }

    sub contents1Tab {

        # Contents1 tab
        #
        # Expected arguments
        #   $innerNotebook  - The Gtk3::Notebook object inside $self->notebook
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $innerNotebook, $check) = @_;

        # Local variables
        my @columnList;

        # Check for improper arguments
        if (! defined $innerNotebook || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->contents1Tab', @_);
        }

        # Tab setup
        my $grid = $self->addTab(
            $innerNotebook,
            'Page _1',
            ['Death words', 'Ignore words'],
        );

        # Death words
        $self->addLabel($grid, '<b>Death words</b>',
            0, 6, 0, 2);
        $self->addLabel($grid, '<i>List of words which mark an object as dead</i>',
            1, 6, 2, 4);
        my ($textView) = $self->addTextView($grid, undef, TRUE,
            1, 6, 4, 6,
            TRUE, TRUE, TRUE, FALSE,  # Treat as list, remove empty lines, do remove whitespace
        );
        my $buffer = $textView->get_buffer();
        $buffer->set_text(join("\n", $self->editObj->ivKeys('deathWordHash')));
        $buffer->signal_connect('changed' => sub {

            # (The 'edit' window presents this IV as a list, but the dictionary object stores it as
            #   a hash)

            my (
                $text,
                @list, @finalList,
                %hash,
            );

            $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);
                }

                # From @finalList, compile the hash
                foreach my $word (@finalList) {

                    $hash{$word} = undef;
                }

                # Set the IV using the hash
                $self->ivAdd('editHash', 'deathWordHash', \%hash);
            }
        });

        # Ignore words
        $self->addLabel($grid, '<b>Ignore words</b>',
            0, 6, 6, 8);
        $self->addLabel($grid,
            '<i>List of words that should be ignored (never added to the unknown words list)</i>',
            1, 6, 8, 10);
        my $textView2 = $self->addTextView($grid, undef, TRUE,
            1, 6, 10, 12,
            TRUE, TRUE, TRUE, FALSE,  # Treat as list, remove empty lines, do remove whitespace
        );
        my $buffer2 = $textView2->get_buffer();
        $buffer2->set_text(join("\n", $self->editObj->ivKeys('ignoreWordHash')));
        $buffer2->signal_connect('changed' => sub {

            # (The 'edit' window presents this IV as a list, but the dictionary object stores it as
            #   a hash)

            my (
                $text,
                @list, @finalList,
                %hash,
            );

            $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);
                }

                # From @finalList, compile the hash
                foreach my $word (@finalList) {

                    $hash{$word} = 'ignore_word';
                }

                # Set the IV using the hash
                $self->ivAdd('editHash', 'ignoreWordHash', \%hash);
            }
        });

        # Tab complete
        return 1;
    }

    sub contents2Tab {

        # Contents2 tab
        #
        # Expected arguments
        #   $innerNotebook  - The Gtk3::Notebook object inside $self->notebook
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $innerNotebook, $check) = @_;

        # Local variables
        my (
            $listRef,
            @columnList, @comboList,
            %ivHash,
        );

        # Check for improper arguments
        if (! defined $innerNotebook || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->contents2Tab', @_);
        }

        # Tab setup
        my $grid = $self->addTab(
            $innerNotebook,
            'Page _2',
            ['Unknown words'],

lib/Games/Axmud/EditWin.pm  view on Meta::CPAN

        my $button = $self->addButton($grid,
            'Unselect', 'Unselect the selected direction', undef,
            1, 2, 8, 9);
        $button->signal_connect('clicked' => sub {

            $slWidget->get_selection->unselect_all();
        });

        # 'Add/Edit direction' button
        my $button2 = $self->addButton($grid,
            'Add/Edit dir', 'Add a new direction or edit the selected one', undef,
            2, 4, 8, 9);
        $button2->signal_connect('clicked' => sub {

            my ($dir, $abbrev, $opp, $oppAbbrev, $auto, $posn);

            ($dir, $abbrev, $opp, $oppAbbrev, $auto)
                = $self->getSimpleListData($slWidget, 0, 1, 2, 3, 4);

            # Sensitise the widgets
            $self->sensitiseWidgets($entry, $entry2, $entry3, $entry4, $combo);

            if (! $dir) {

                # 'Add' direction. Make sure the entry boxes are empty
                $entry->set_text('');
                $entry2->set_text('');
                $entry3->set_text('');
                $entry4->set_text('');
                # Make sure the 'Don't auto-allocate' string is visible at the top of the combo
                $combo->set_active(0);

                # If the user clicks 'Use changes', it's a completely new secondary direction
                $thisDir = undef;

            } else {

                # 'Edit' direction. Fill the entry boxes with the selected direction's data
                $entry->set_text($dir);
                if (defined $abbrev) {

                    $entry2->set_text($abbrev);
                }
                $entry3->set_text($opp);
                $entry4->set_text($oppAbbrev);
                # Make the right choice visible in the combobox
                $posn = 0;  # Default is the 'don't auto-allocate' string
                if ($auto) {

                    OUTER: for (my $index = 0; $index < 18; $index++) {

                        if ($comboList[$index] eq $auto) {

                            $posn = $index;
                            last OUTER;
                        }
                    }
                }

                $combo->set_active($posn);
                $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->directions2Tab');

                # Store the direction that's being edited because the 'Use changes' button needs it
                $thisDir = $dir;
            }
        });

        # 'Delete direction' button
        my $button3 = $self->addButton($grid,
            'Delete dir', 'Delete the selected direction', undef,
            4, 6, 8, 9);
        $button3->signal_connect('clicked' => sub {

            my (
                $dir, $listRef, $hashRef, $count,
                @dirList,
                %dirHash, %abbrevHash, %oppHash, %oppAbbrevHash, %autoHash,
            );

            ($dir) = $self->getSimpleListData($slWidget, 0);
            if ($dir) {

                # Import data from the affected IVs
                if ($self->ivExists('editHash', 'secondaryDirList')) {

                    $listRef = $self->ivShow('editHash', 'secondaryDirList');
                    @dirList = @$listRef;
                    $hashRef = $self->ivShow('editHash', 'secondaryDirHash');
                    %dirHash = %$hashRef;
                    $hashRef = $self->ivShow('editHash', 'secondaryAbbrevHash');
                    %abbrevHash = %$hashRef;
                    $hashRef = $self->ivShow('editHash', 'secondaryOppHash');
                    %oppHash = %$hashRef;
                    $hashRef = $self->ivShow('editHash', 'secondaryOppAbbrevHash');
                    %oppAbbrevHash = %$hashRef;
                    $hashRef = $self->ivShow('editHash', 'secondaryAutoHash');
                    %autoHash = %$hashRef;

                } else {

                    @dirList = $self->editObj->secondaryDirList;
                    %dirHash = $self->editObj->secondaryDirHash;
                    %abbrevHash = $self->editObj->secondaryAbbrevHash;
                    %oppHash = $self->editObj->secondaryOppHash;
                    %oppAbbrevHash = $self->editObj->secondaryOppAbbrevHash;
                    %autoHash = $self->editObj->secondaryAutoHash;
                }

                # Remove $dir from the list of secondary directions
                $count = -1;
                OUTER: foreach my $otherDir (@dirList) {

                    $count++;

                    if ($otherDir eq $dir) {

                        # Remove the entry
                        splice (@dirList, $count, 1);
                        last OUTER;
                    }
                }

lib/Games/Axmud/EditWin.pm  view on Meta::CPAN

                $grid,
                '<i>(NB All splitter triggers are tested before any other kind of trigger is'
                . ' tested)</i>',
                1, 12, 12, 14);
        }

        # Tab complete
        return 1;
    }

    sub beforeAfterTab_addTextView {

        # Called by $self->beforeAfterTab to create a Gtk3::TextView whose contents are treated as
        #   lists, and saved in $self->beforeList or $self->afterList
        # (We don't use the standard GA::Generic::EditWin->addTextView because we need these
        #   textviews to create lists, which are saved as hashes in $self->editObj)
        #
        # Expected arguments
        #   $grid       - The Gtk3::Grid for this tab
        #   $type       - 'before' or 'after'
        #   $row        - The Gtk3::Grid row where the textview is drawn
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $grid, $type, $row, $check) = @_;

        # Local variables
        my @sortedList;

        # Check for improper arguments
        if (! defined $grid || ! defined $type || ! defined $row || defined $check) {

            return $axmud::CLIENT->writeImproper(
                $self->_objClass . '->beforeAfterTab_addTextView',
                @_,
            );
        }

        # Create the textview
        my $textView = $self->addTextView($grid, undef, TRUE,
            1, 12, $row, ($row + 2),
            TRUE, TRUE, TRUE, FALSE,    # Treat as list, remove empty lines, do remove whitespace
        );
        my $buffer = $textView->get_buffer();

        # Display a list of the keys in $self->editObj->beforeHash / ->afterHash (sort them
        #   alphabetically, for good measure)
        @sortedList = sort {lc($a) cmp lc($b)} ($self->editObj->ivKeys($type . 'Hash'));
        $buffer->set_text(join("\n", @sortedList));

        # Store any changes the user makes in $self->$localIV
        $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, if allowed
            foreach my $line (@list) {

                $line =~ s/^\s+//;  # Remove leading whitespace
                $line =~ s/\s+$//;  # Remove trailing whitespace

                if ($line) {

                    push (@finalList, $line);
                }
            }

            # Store the contents, temporarily, so that they're available to $self->saveChanges
            $self->ivPoke($type . 'List', @finalList);
            # Set a flag, to mark that changes have been made
            $self->ivPoke($type . 'Flag', TRUE);
        });

        return $textView;
    }

    ##################
    # Accessors - set

    ##################
    # Accessors - get

    sub attribHash
        { my $self = shift; return %{$self->{attribHash}}; }
    sub beforeList
        { my $self = shift; return @{$self->{beforeList}}; }
    sub afterList
        { my $self = shift; return @{$self->{afterList}}; }
    sub beforeFlag
        { $_[0]->{beforeFlag} }
    sub afterFlag
        { $_[0]->{afterFlag} }
}

{ package Games::Axmud::EditWin::Generic::InterfaceCage;

    use strict;
    use warnings;
#   use diagnostics;

    use Glib qw(TRUE FALSE);

    our @ISA = qw(
        Games::Axmud::EditWin::Generic::Cage Games::Axmud::Generic::EditWin
        Games::Axmud::Generic::ConfigWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
        Games::Axmud
    );

    ##################
    # Constructors

lib/Games/Axmud/EditWin.pm  view on Meta::CPAN

        my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
            1, 12, 2, 10);

        # Initialise the list
        $self->gridsTab_refreshList($slWidget, scalar (@columnList / 2));

        # Add editing widgets
        $self->addLabel($grid, 'Zonemap',
            1, 3, 10, 11);
        @comboList = sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivKeys('zonemapHash'));
        $existString = '(use existing zonemap)';
        my $combo = $self->addComboBox($grid, undef, \@comboList, $existString,
            TRUE,               # No 'undef' value used
            3, 5, 10, 11);

        my $button = $self->addButton(
            $grid,
            'Reset',
            'Reset selected workspace grid using the specified default zonemap',
            undef,
            5, 7, 10, 11,
            TRUE,           # Irreversible
        );
        $button->signal_connect('clicked' => sub {

            my ($number, $cmd, $zonemap);

            ($number) = $self->getSimpleListData($slWidget, 0);
            if (defined $number) {

                $cmd = 'resetgrid ' . $number;

                $zonemap = $combo->get_active_text();
                if ($zonemap ne $existString) {

                    $cmd .= ' ' . $zonemap;
                }

                $self->session->pseudoCmd($cmd, $self->pseudoCmdMode);
            }

            # Refresh the list
            $self->gridsTab_refreshList($slWidget, scalar (@columnList / 2));
            # Update widgets
            $combo->set_active(0);
        });

        my $button2 = $self->addButton(
            $grid,
            'View...',
            'View settings for the selected workspace grid',
            undef,
            8, 10, 10, 11);
        $button2->signal_connect('clicked' => sub {

            my ($number, $obj);

            ($number) = $self->getSimpleListData($slWidget, 0);
            if (defined $number) {

                $obj = $axmud::CLIENT->desktopObj->ivShow('gridHash', $number);
                if ($obj) {

                    # Open an 'edit' window to edit the workspace grid
                    $self->createFreeWin(
                        'Games::Axmud::EditWin::WorkspaceGrid',
                        $self,
                        $self->session,
                        'Edit workspace grid #' . $number,
                        $obj,
                        FALSE,                          # Not temporary
                    );
                }
            }

            # Refresh the list
            $self->gridsTab_refreshList($slWidget, scalar (@columnList / 2));
            # Update widgets
            $combo->set_active(0);
        });

        my $button3 = $self->addButton(
            $grid,
            'Refresh list',
            'Refresh the list of workspace grids',
            undef,
            10, 12, 10, 11);
        $button3->signal_connect('clicked' => sub {

            # Refresh the list
            $self->gridsTab_refreshList($slWidget, scalar (@columnList / 2));
            # Update widgets
            $combo->set_active(0);
        });

        # Tab complete
        return 1;
    }

    sub gridsTab_refreshList {

        # Called by $self->gridTab to refresh the first GA::Obj::SimpleList
        #
        # Expected arguments
        #   $slWidget   - The GA::Obj::SimpleList
        #   $columns    - The number of columns in the list
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $slWidget, $columns, $check) = @_;

        # Local variables
        my @dataList;

        # Check for improper arguments
        if (! defined $slWidget || ! defined $columns || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->gridsTab_refreshList', @_);
        }

lib/Games/Axmud/EditWin.pm  view on Meta::CPAN


        my ($self, $check) = @_;

        # Local variables
        my @columnList;

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->windowsTab', @_);
        }

        # Tab setup
        # N.B. No sub-headings
        my $grid = $self->addTab($self->notebook, '_Windows');

        # Windows
        $self->addLabel($grid, '<b>Windows</b>',
            0, 12, 0, 1);
        $self->addLabel($grid,
            '<i>List of \'grid\' windows arranged on this workspace grid</i>',
            1, 6, 1, 2);

        # Add a simple list
        @columnList = (
            'Window', 'int',
            'Area', 'int',
            'Zone', 'int',
            'Layer', 'int',
            'Left (blocks)', 'int',
            'Right', 'int',
            'Top', 'int',
            'Bottom', 'int',
            'Wid', 'int',
            'Hei', 'int',
            'X (pixels)', 'int',
            'Y', 'int',
            'Wid', 'int',
            'Hei', 'int',
        );

        my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
            1, 12, 2, 10);

        # Initialise the list
        $self->windowsTab_refreshList($slWidget, scalar (@columnList / 2));

        # Add buttons
        my $button = $self->addButton(
            $grid,
            'View...',
            'View settings for the selected \'grid\' window', undef,
            8, 10, 10, 11);
        $button->signal_connect('clicked' => sub {

            my ($num, $obj);

            ($num) = $self->getSimpleListData($slWidget, 0);
            if (defined $num) {

                $obj = $axmud::CLIENT->desktopObj->ivShow('gridWinHash', $num);
                if ($obj) {

                    # Open an 'edit' window for the 'grid' window
                    $self->createFreeWin(
                        'Games::Axmud::EditWin::Window',
                        $self,
                        $self->session,
                        'Edit \'grid\' window #' . $obj->number,
                        $obj,
                        FALSE,                          # Not temporary
                    );
                }
            }

            # Refresh the list
            $self->windowsTab_refreshList($slWidget, scalar (@columnList / 2));
        });

        my $button2 = $self->addButton(
            $grid,
            'Refresh list',
            'Refresh the list of windows on this workspace grid', undef,
            10, 12, 10, 11);
        $button2->signal_connect('clicked' => sub {

            # Refresh the list
            $self->windowsTab_refreshList($slWidget, scalar (@columnList / 2));
        });

        # Tab complete
        return 1;
    }

    sub windowsTab_refreshList {

        # Called by $self->windowsTab to refresh the first GA::Obj::SimpleList
        #
        # Expected arguments
        #   $slWidget   - The GA::Obj::SimpleList
        #   $columns    - The number of columns in the list
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $slWidget, $columns, $check) = @_;

        # Local variables
        my @dataList;

        # Check for improper arguments
        if (! defined $slWidget || ! defined $columns || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->windowsTab_refreshList', @_);
        }

        # Compile the simple list data
        foreach my $obj (
            sort {$a->number <=> $b->number} ($self->editObj->ivValues('gridWinHash'))
        ) {



( run in 0.699 second using v1.01-cache-2.11-cpan-f56aa216473 )