Games-Axmud

 view release on metacpan or  search on metacpan

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


        # Reset the 'create world' button's label (it gets modified by $self->updateGridWidgets)
        $self->createWorldButton->set_label('Create world');
        $self->createWorldButton->set_tooltip_text('Create a world profile');

        # Reset the grid widgets
        $self->entry->set_text('');
        $self->entry2->set_text('');
        $self->entry3->set_text('');
        $self->checkButton->set_active(FALSE);

        $self->radioButton->set_active(TRUE);

        my $comboBox = $self->resetComboBox(TRUE);
        $self->ivPoke('comboBox', $comboBox);

        $self->websiteLabel->set_text($self->noWebsiteString);
        $self->connectionLabel->set_text($self->noConnectString);
        $self->descripBuffer->set_text('');

        # (These calls eliminate flashing when the screenshot is updated rapidly, for example when
        #   the user scrolls through the list of worlds)
        $self->winShowAll($self->_objClass . '->resetGridWidgets');
        $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->resetGridWidgets');

        # Update the world screenshot, using the default logo
        # If a logo for this world exists, use it; otherwise use the default logo
        my $image = Gtk3::Image->new_from_file($self->defaultIcon);
        $axmud::CLIENT->desktopObj->removeWidget($self->frame, $self->image);
        $self->frame->add($image);
        $self->ivPoke('image', $image);

        # (A repeat of those calls eliminates it entirely)
        $self->winShowAll($self->_objClass . '->resetGridWidgets');
        $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->resetGridWidgets');

        # The entry box for the world's name must be made editable
        $self->entry->set_editable(TRUE);
        # The 'pwd' / 'account' buttons start insensitive, but can be sensitised if the user selects
        #   a character
        $self->editPwdButton->set_sensitive(FALSE);
        $self->editAccButton->set_sensitive(FALSE);
        # The 'reset world' button must be insensitive when there isn't a corresponding world
        #   profile
        $self->resetWorldButton->set_sensitive(FALSE);
        # The 'add', 'connect offline' and 'connect to world' buttons must be insensitive until the
        #   user at least types something in the 'host address' entry box
        $self->addCharButton->set_sensitive(FALSE);
        $self->offlineButton->set_sensitive(FALSE);
        $self->connectButton->set_sensitive(FALSE);

        # Update complete
        $self->ivPoke('updateFlag', FALSE);

        # The call to ->show_all() causes the image to appear
        $self->winShowAll($self->_objClass . '->resetGridWidgets');

        return 1;
    }

    sub updateGridWidgets {

        # Called by $self->selectWorldCallback when the user clicks on a line in the treeview
        #   corresponding to a world profile
        # Also called by $self->testModeLoginCallback
        #
        # Updates IVs and updates the widgets in the window's Gtk3::Grid, so they show details about
        #   the world
        #
        # Expected arguments
        #   $worldObj   - The GA::Profile::World object corresponding to the clicked line
        #   $line       - The text of the treeview line that the user clicked
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my (
            $displayFlag, $modName, $host, $port, $website, $connections, $logoPath,
            @charList,
        );

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

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

        # Decide which list should be displayed. Default display mode is 'undef', representing
        #   a list of world profiles
        if ($self->otherWorldButton->get_active()) {

            $displayFlag = TRUE;
        }

        # Set the IV which stores the currently displayed world
        $self->ivPoke('worldObj', $worldObj);
        # Get the equivalent GA::Obj::MiniWorld
        $self->ivPoke('miniWorldObj', $self->ivShow('miniWorldHash', $worldObj->name));
        # Set a flag to TRUE to stop the mini-world object being updated, as we change the values
        #   displayed in the grid's widgets
        $self->ivPoke('updateFlag', TRUE);

        # Modify the 'create world' button's label (it gets reset by $self->resetGridWidgets)
        if (! $displayFlag) {

            $self->createWorldButton->set_label('Apply changes');
            $self->createWorldButton->set_tooltip_text('Apply changes to this world profile');

        } else {

            $self->createWorldButton->set_label('Create world');
            $self->createWorldButton->set_tooltip_text('Create a world profile');
        }

        # Display details about the world. For each IV, if there's an entry in the mini-world
        #   object, then use its value; otherwise use the value stored in the world profile itself

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

        if ($self->miniWorldObj && $self->miniWorldObj->selectChar) {

            $count = -1;
            OUTER: foreach my $string (@charList) {

                $count++;

                if ($string eq $self->miniWorldObj->selectChar) {

                    $index = $count;
                    last OUTER;
                }
            }
        }

        $comboBox->set_active($index);
        # Also, the 'pwd'/'account' buttons should only be sensitised when there's a selected
        #   character
        if ($self->miniWorldObj) {

            if ($self->miniWorldObj->selectChar) {

                $self->editPwdButton->set_sensitive(TRUE);
                $self->editAccButton->set_sensitive(TRUE);

            } else {

                $self->editPwdButton->set_sensitive(FALSE);
                $self->editAccButton->set_sensitive(FALSE);
            }
        }

        # Now we can add the combobox's ->signal_connect, which updates the mini-world object when
        #   a character is selected
        $comboBox->signal_connect('changed' => sub {

            my $char = $comboBox->get_active_text();

            if ($char eq $self->noCharString) {

                $self->miniWorldObj->ivUndef('selectChar');
                # When no character is selected, the 'pwd'/'account' buttons must be desensitised
                $self->editPwdButton->set_sensitive(FALSE);
                $self->editAccButton->set_sensitive(FALSE);

            } else {

                $self->miniWorldObj->ivPoke('selectChar', $char);
                # When no character is selected, the 'pwd'/'account' buttons must be desensitised
                $self->editPwdButton->set_sensitive(TRUE);
                $self->editAccButton->set_sensitive(TRUE);
            }
        });

        # The call to ->show_all() makes the new combobox visible
        $self->winShowAll($self->_objClass . '->resetComboBox');

        return $comboBox;
    }

    sub updateProfile {

        # Called by $self->applyChangesCallback and ->connectWorldCallback
        # Copies changes to values, stored in the specified mini-world object, to the corresponding
        #   world profile (if it exists)
        #
        # Expected arguments
        #   $miniWorldObj   - A GA::Obj::MiniWorld
        #
        # Return values
        #   'undef' on improper arguments or if there is no world profile to update
        #   1 otherwise

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

        # Local variables
        my (
            $worldObj, $profFlag, $host, $port, $descrip,
            %newHash,
        );

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

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

        # Import the equivalent world profile object, for convenience
        $worldObj = $miniWorldObj->worldObj;
        # Is it actually a world profile, or is it a basic world object (GA::Obj::BasicWorld), which
        #   has different IVs?
        if (! $worldObj->isa('Games::Axmud::Profile::World')) {

            # It's a basic world object; nothing for this function to do
            return undef;
        }

        # (We can't change the profile's ->name)

        # ->host and ->port
        # If the host address is in the form 'deathmud.com:8888', then extract the port. Although
        #   it technically possible to use ports with only one digit, don't recognise it
        # If, at the same time, the port was specified in the other entry box, ignore the other
        $host = $miniWorldObj->ivShow('propHash', 'host');
        if ($host && $host =~ m/^(.*)\:(\d{2,5})\s*$/) {
            $host = $1;
            $port = $2;
        } else {
            $port = $miniWorldObj->ivShow('propHash', 'port');
        }

        if ($host && $host =~ m/\w/) {

            $host = $axmud::CLIENT->trimWhitespace($host);

            if ($profFlag) {

                if ($axmud::CLIENT->ipv6Check($host)) {
                    $worldObj->ivPoke('ipv6', $host);
                } elsif ($axmud::CLIENT->ipv4Check($host)) {
                    $worldObj->ivPoke('ipv4', $host);

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

    sub entry
        { $_[0]->{entry} }
    sub entry2
        { $_[0]->{entry2} }
    sub entry3
        { $_[0]->{entry3} }
    sub checkButton
        { $_[0]->{checkButton} }
    sub radioButton
        { $_[0]->{radioButton} }
    sub radioButton2
        { $_[0]->{radioButton2} }
    sub radioButton3
        { $_[0]->{radioButton3} }
    sub radioButton4
        { $_[0]->{radioButton4} }
    sub comboBox
        { $_[0]->{comboBox} }
    sub addCharButton
        { $_[0]->{addCharButton} }
    sub editPwdButton
        { $_[0]->{editPwdButton} }
    sub editAccButton
        { $_[0]->{editAccButton} }
    sub websiteLabel
        { $_[0]->{websiteLabel} }
    sub connectionLabel
        { $_[0]->{connectionLabel} }
    sub descripTextView
        { $_[0]->{descripTextView} }
    sub descripBuffer
        { $_[0]->{descripBuffer} }
    sub createWorldButton
        { $_[0]->{createWorldButton} }
    sub resetWorldButton
        { $_[0]->{resetWorldButton} }
    sub offlineButton
        { $_[0]->{offlineButton} }
    sub connectButton
        { $_[0]->{connectButton} }

    sub defaultIcon
        { $_[0]->{defaultIcon} }
    sub imageWidth
        { $_[0]->{imageWidth} }
    sub imageHeight
        { $_[0]->{imageHeight} }
    sub tableWidth
        { $_[0]->{tableWidth} }
    sub tableHeight
        { $_[0]->{tableHeight} }

    sub worldHash
        { my $self = shift; return %{$self->{worldHash}}; }
    sub miniWorldHash
        { my $self = shift; return %{$self->{miniWorldHash}}; }
    sub worldObj
        { $_[0]->{worldObj} }
    sub miniWorldObj
        { $_[0]->{miniWorldObj} }
    sub updateFlag
        { $_[0]->{updateFlag} }

    sub newWorldString
        { $_[0]->{newWorldString} }
    sub noCharString
        { $_[0]->{noCharString} }
    sub noWebsiteString
        { $_[0]->{noWebsiteString} }
    sub noConnectString
        { $_[0]->{noConnectString} }

    sub searchRegex
        { $_[0]->{searchRegex} }
    sub searchLanguage
        { $_[0]->{searchLanguage} }
}

{ package Games::Axmud::OtherWin::ClientConsole;

    use strict;
    use warnings;
#   use diagnostics;

    use Glib qw(TRUE FALSE);

    our @ISA = qw(
        Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
        Games::Axmud
    );

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

    sub new {

        # Called by GA::Generic::Win->createFreeWin
        # Creates a new instance of the Client Console window, which can display system messages
        #   when there is no session running
        #
        # Expected arguments
        #   $number         - Unique number for this window object
        #   $workspaceObj   - The GA::Obj::Workspace handling the workspace in which this window
        #                       should be created
        #   $owner          - The owner; a 'grid' window object (but not an 'external' window) or a
        #                       'free' window object. When this window opens/closes, the owner is
        #                       informed via calls to its ->add_childFreeWin / ->del_childFreeWin
        #                       functions
        #
        # Optional arguments
        #   $session        - The GA::Session from which this function was called. 'undef' if the
        #                       calling function didn't specify a session and $owner's ->session IV
        #                       is also 'undef'
        #   $title          - Ignored if set (all 'other' windows define their own title)
        #   $editObj        - Ignored if set
        #   $tempFlag       - Ignored if set
        #   %configHash     - Hash containing any number of key-value pairs needed for this
        #                       particular 'other' window; set to an empty hash if not required
        #                   - This type of window object recognises these initialisation settings:
        #
        #                       ...

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


#   sub redrawWidgets {}    # Inherited from GA::Generic::Win

    # ->signal_connects

    # Other functions

    sub createColourTags {

        # Called by $self->drawWidgets
        # Create some Gtk3::TextTags, so that system messages can be shown in their usual colours
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

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

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

        $self->buffer->create_tag(
            'system',
            'foreground'
                => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowSystemTextColour),
        );

        $self->buffer->create_tag(
            'error',
            'foreground'
                => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowErrorColour),
        );

        $self->buffer->create_tag(
            'warning',
            'foreground'
                => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowWarningColour),
        );

        $self->buffer->create_tag(
            'debug',
            'foreground'
                => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowDebugColour),
        );

        $self->buffer->create_tag(
            'improper',
            'foreground'
                => $axmud::CLIENT->returnRGBColour($axmud::CLIENT->customShowImproperColour),
        );

        return 1;
    }

    sub update {

        # Called by $self->winEnable and $axmud::CLIENT->add_systemMsg
        # Adds a system message to the window's textview
        #
        # Expected arguments
        #   $type   - The type of message (which determines the colour in which it's displayed) -
        #               'system', 'error', 'warning', 'debug' or 'improper'. If an invalid value or
        #               'undef', then the error message colour is used
        #   $msg    - The message to display. If 'undef' (for some reason), nothing is displayed
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

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

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

        if ($self->enabledFlag && defined $msg) {

            if (
                ! defined $type
                || (
                    $type ne 'system' && $type ne 'error' && $type ne 'warning' && $type ne 'debug'
                    && $type ne 'improper'
                )
            ) {
                $type = 'error';
            }

            # Only one newline character at the end of the message
            chomp $msg;
            $self->buffer->insert_with_tags_by_name(
                $self->buffer->get_end_iter(),
                $msg . "\n",
                $type,
            );

            # Scroll to the bottom
            $self->textView->scroll_to_mark($self->buffer->get_mark('end'), 0.0, TRUE, 0, 0);

            $self->winShowAll($self->_objClass . '->update');
        }

        return 1;
    }

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

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

    sub textView
        { $_[0]->{textView} }
    sub buffer

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


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

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

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

        if (! $self->winBox) {

            # Window already destroyed in a previous call to this function
            return undef;
        }

        # Close any 'free' windows for which this window is a parent
        foreach my $winObj ($self->ivValues('childFreeWinHash')) {

            $winObj->winDestroy();
        }

        # Destroy the Gtk3::Window
        eval { $self->winBox->destroy(); };
        if ($@) {

            # Window can't be destroyed
            return undef;

        } else {

            $self->ivUndef('winWidget');
            $self->ivUndef('winBox');
        }

        # Inform the owner and the desktop object of this 'free' window's demise
        $axmud::CLIENT->desktopObj->del_freeWin($self);
        if ($self->owner) {

            $self->owner->del_childFreeWin($self);
        }

        # This type of window is unique (only one can be open per session); inform the GA::Session
        #   it has closed
        $self->session->set_consoleWin();

        return 1;
    }

#   sub winShowAll {}       # Inherited from GA::Generic::Win

#   sub drawWidgets {}      # Inherited from GA::OtherWin::ClientConsole

#   sub redrawWidgets {}    # Inherited from GA::Generic::Win

    # ->signal_connects

    # Other functions

#   sub createColourTags {} # Inherited from GA::OtherWin::ClientConsole

#   sub update {}           # Inherited from GA::OtherWin::ClientConsole

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

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

{ package Games::Axmud::OtherWin::Simulate;

    use strict;
    use warnings;
#   use diagnostics;

    use Glib qw(TRUE FALSE);

    our @ISA = qw(
        Games::Axmud::Generic::OtherWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
        Games::Axmud
    );

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

    sub new {

        # Called by GA::Generic::Win->createFreeWin
        # Creates a new instance of the Simulate window (an 'other' window). The window contains a
        #   textview in which the user can type text. When the 'Simulate' button is clicked, the
        #   contents of the textview (if any) is combined into a single string (with multiple lines
        #   separated by newline characters). The string is then used in a ';simulateworld' command,
        #   and appears in the session's default textview, as if it had been received from the world
        #
        # Expected arguments
        #   $number         - Unique number for this window object
        #   $workspaceObj   - The GA::Obj::Workspace handling the workspace in which this window
        #                       should be created
        #   $owner          - The owner; a 'grid' window object (but not an 'external' window) or a
        #                       'free' window object. When this window opens/closes, the owner is
        #                       informed via calls to its ->add_childFreeWin / ->del_childFreeWin
        #                       functions
        #
        # Optional arguments
        #   $session        - The GA::Session from which this function was called. 'undef' if the
        #                       calling function didn't specify a session and $owner's ->session IV
        #                       is also 'undef'
        #   $title          - Ignored if set (all 'other' windows define their own title)
        #   $editObj        - Ignored if set
        #   $tempFlag       - Ignored if set
        #   %configHash     - Hash containing any number of key-value pairs needed for this
        #                       particular 'other' window; set to an empty hash if not required
        #                   - This type of window object recognises these initialisation settings:
        #
        #                       'type' => Which client command to use with the contents of the
        #                           textview, when the 'Simulate' button is clicked - 'world' or
        #                           'prompt'. If not specified, 'world' is used
        #
        # Return values
        #   'undef' on improper arguments
        #   Blessed reference to the newly-created object on success

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

        # Local variables
        my $label;

        # Check for improper arguments
        if (! defined $tab) {

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

        # If the button strip is visible, do some repacking
        if ($self->hPaned2) {

            $axmud::CLIENT->desktopObj->removeWidget($self->hPaned2, $self->notebook);
            $axmud::CLIENT->desktopObj->removeWidget($self->hPaned, $self->hPaned2);

            $self->hPaned->add2($self->notebook);

            $self->hPaned->set_position($self->leftWidth);
        }

        # Update IVs
        $self->ivUndef('hPaned2');
        $self->ivUndef('vBox');

        # Remove the existing notebook content
        $self->resetNotebook();

        # Create a scrolled window
        my $scrolled = Gtk3::ScrolledWindow->new(undef, undef);
        $scrolled->set_shadow_type($axmud::CLIENT->constShadowType);
        $scrolled->set_policy('automatic', 'automatic');
        $scrolled->set_border_width(5);

        # Create a textview with default colours/fonts
        my $textView = Gtk3::TextView->new();
        my $buffer = Gtk3::TextBuffer->new();
        $textView->set_buffer($buffer);
        $textView->set_editable(FALSE);
        $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);

        # Copy the text into the textview
        $buffer->set_text(join("\n", @list));

        # Complete setup
        $scrolled->add($textView);

        # Add a label
        $label = Gtk3::Label->new_with_mnemonic($tab);
        $self->notebook->append_page($scrolled, $label);

        # Render the changes
        $self->winShowAll($self->_objClass . '->refreshTextView');

        # Update IVs
        $self->ivAdd('notebookTabHash', $tab, $label);
        $self->ivPoke('notebookMode', 'text');

        return 1;
    }

    sub updateNotebook {

        # Called whenever the current notebook changes (when a new profile or cage is created or
        #   deleted - eg by $self->refreshNotebook)
        # Updates the notebook by calling the same method called when a header in the treeview is
        #   selected
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   @list   - The rows in the notebook's GA::Obj::SimpleList which should be marked as
        #               'selected' (as if the user had clicked on them). If the list is empty,
        #               no rows are marked as 'selected'
        #
        # Return values
        #   'undef' on improper arguments or if the notebook isn't displaying anything
        #   1 otherwise

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

        # Local variables
        my ($method, $currentTab);

        # (No improper arguments to check)

        if (
            $self->notebookCurrentHeader
            && $self->ivExists('headerHash', $self->notebookCurrentHeader)
        ) {
            # Remember the currently selected tab
            $currentTab = $self->notebook->get_current_page();

            # Call the method specified by $self->headerHash
            $method = $self->ivShow('headerHash', $self->notebookCurrentHeader);
            $self->$method($self->notebookCurrentHeader);

            # If @list isn't empty, mark some of the rows as selected
            if (@list) {

                $self->notebookSetSelectedLines(@list);
            }

            # Open the previously selected tab
            $self->notebook->set_current_page($currentTab);

            return 1;

        } else {

            return undef;
        }
    }

    # Notebook support functions

    sub notebookGetTab {

        # Can be called by anything
        # Finds the name of the current tab in the notebook
        #



( run in 3.043 seconds using v1.01-cache-2.11-cpan-0d23b851a93 )