Games-Axmud

 view release on metacpan or  search on metacpan

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


    sub removeSessionGauges {

        # Can be called by anything
        # Complementing $self->removeGauges, this is a short-cut which removes all gauges for a
        #   particular session, without the need for the calling function to specify the gauges
        #   to remove
        # (If the specified session isn't this window's visible session, then no visible gauges are
        #   removed, but IVs are still updated)
        #
        # Expected arguments
        #   $session        - The GA::Session whose gauges should be removed
        #
        # Optional arguments
        #   $boxFlag        - Set to TRUE when called by GA::Session->reactDisconnect. If there are
        #                       no gauges left, the 'main' window code normally waits a few seconds
        #                       before removing the gauge box. However, that won't work if the only
        #                       session has just disconnected, as its timer loop has terminated.
        #                       When the flag is TRUE, the gauge box is removed immediately. Set to
        #                       FALSE (or 'undef') otherwise
        #
        # Return values
        #   'undef' on improper arguments or if we're not allowed to draw gauges at all
        #   Otherwise returns the number of gauges removed (might be 0)

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

        # Local variables
        my (
            $result,
            @removeList,
        );

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

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

        # Get a list of gauges belonging to the specified session
        foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {

            if ($gaugeLevelObj->session eq $session) {

                push (@removeList, $gaugeLevelObj->ivValues('gaugeHash'));
            }
        }

        # The FALSE argument means 'don't keep an empty gauge level'
        $result = $self->removeGauges($session, FALSE, @removeList);

        # Remove the gauge box immediately, if instructed
        if (! $self->gaugeLevelHash && $boxFlag) {

            $self->removeGaugeBox();
        }

        return $result;
    }

    sub updateGauges {

        # Can be called by anything
        # Updates the gauges currently drawn in the gauge box, redrawing them. If this window's
        #   visible session has changed, a new set of gauges is drawn, replacing the previous ones
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my (
            $result,
            @drawList,
        );

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

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

        # Do nothing if the gauge box isn't actually visible (because no gauges have been drawn by
        #   any session), or if another call to this function is still being processed
        if (! $self->visibleFlag || $self->gaugeUpdateFlag) {
            return undef;
        } else {
            $self->ivPoke('gaugeUpdateFlag', TRUE);
        }

        # If a recent call to $self->addGaugeLevel specified that the gauge box shouldn't be
        #   redrawn yet, then redraw it now
        if ($self->gaugeNoDrawFlag) {

            $self->drawGaugeBox();
            $self->winObj->replaceStripObj($self);
            $self->ivPoke('gaugeNoDrawFlag', FALSE);
        }

        # Compile an ordered list of gauges that should be visible (so that gauge levels and gauges
        #   are always drawn in the same order)
        foreach my $gaugeLevelObj (
            sort {$a->number <=> $b->number} ($self->ivValues('gaugeLevelHash'))
        ) {
            # (Session-specific gauges typically only apply to the main window)
            if (
                ! $self->winObj->visibleSession
                || $self->winObj->visibleSession eq $gaugeLevelObj->session
            ) {
                push (
                    @drawList,
                    sort {$a->number <=> $b->number} ($gaugeLevelObj->ivValues('gaugeHash')),
                );
            }
        }

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


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

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

        if (! $self->winObj->visibleSession || $self->winObj->visibleSession ne $session) {

            # Do nothing
            return undef;

        } else {

            $self->entry->set_text($cmd);
            $self->entry->set_visibility(TRUE);
            $self->entry->grab_focus();

            $self->winObj->winShowAll($self->_objClass . '->commandeerEntry');

            return 1;
        }
    }

    sub applyBackspace {

        # Called by GA::Win::Internal->setKeyPressEvent when the user presses the backspace key in
        #   special echo mode
        # $self->specialWorldCmd stores a copy of the world command that's being sent to the world,
        #   one character at a time; amend the copy by removing its final character
        # (This doesn't guarantee that the world command stored in ->specialWorldCmd is exactly the
        #   same as the command the world thinks it's receiving, but it should be close enough)
        #
        # 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 . '->applyBackspace', @_);
        }

        # The calling function has done most of the checking, so just update ->specialWorldCmd
        if ($self->specialWorldCmd ne '') {

            $self->ivPoke(
                'specialWorldCmd',
                substr($self->specialWorldCmd, 0, ((length ($self->specialWorldCmd)) - 1)),
            );
        }

        return 1;
    }

    sub updateScrollButton {

        # Called by GA::Table::Pane->toggleScrollLock and ->toggleSplitScreen, and by
        #   $self->setScrollSignals
        # Updates the icon shown on the 'scroll lock' button, which indicates whether the scroll
        #   lock is applied to the active textview, or not
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   $flag   - TRUE if the scroll lock is applied on the active textview, FALSE if it is not.
        #               Set to 'undef' if the calling function doesn't know whether the scroll lock
        #               is applied in the active textview, or not
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my ($paneObj, $tabNum, $tabObj);

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

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

        if (! defined $flag) {

            # Is there an active textview, and is its scroll lock applied?
            if ($self->paneObjList) {

                $paneObj = $self->ivFirst('paneObjList');
                if ($paneObj) {

                    if (! $paneObj->notebook) {
                        $tabNum = 0;
                    } else {
                        $tabNum = $paneObj->notebook->get_current_page();
                    }

                    if (defined $tabNum) {

                        $tabObj = $paneObj->ivShow('tabObjHash', $tabNum);
                        $flag = $tabObj->textViewObj->scrollLockFlag;
                    }
                }
            }
        }

        # Do nothing if the button isn't visible...
        if ($self->scrollButton) {

            if (! $flag) {

                $self->scrollButton->set_icon_widget(
                    Gtk3::Image->new_from_file(
                        $axmud::SHARE_DIR . $axmud::CLIENT->constScrollIconPath
                    ),
                );

            } else {

                # (Default)
                $self->scrollButton->set_icon_widget(
                    Gtk3::Image->new_from_file(
                        $axmud::SHARE_DIR . $axmud::CLIENT->constLockIconPath
                    ),
                );
            }

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

        return 1;
    }

    sub updateSplitButton {

        # Called by GA::Table::Pane->toggleSplitScreen
        # Updates the icon shown on the 'split screen' button, which indicates whether the split
        #   screen is applied to the active textview, or not
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   $flag   - TRUE if the split screen is applied on the active textview, FALSE if it is
        #               not. Set to 'undef' if the calling function doesn't know whether the split
        #               screen lock is applied in the active textview, or not
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my ($paneObj, $tabNum, $tabObj);

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

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

        if (! defined $flag) {

            # Is there an active textview, and is its split screen applied?
            if ($self->paneObjList) {

                $paneObj = $self->ivFirst('paneObjList');
                if ($paneObj) {

                    if (! $paneObj->notebook) {
                        $tabNum = 0;
                    } else {
                        $tabNum = $paneObj->notebook->get_current_page();
                    }

                    if (defined $tabNum) {

                        $tabObj = $paneObj->ivShow('tabObjHash', $tabNum);
                        if ($tabObj->textViewObj->splitScreenMode eq 'split') {
                            $flag = TRUE;
                        } else {
                            $flag = FALSE;
                        }
                    }
                }
            }
        }

        # Do nothing if the button isn't visible...
        if ($self->splitButton) {

            if (! $flag) {

                $self->splitButton->set_icon_widget(
                    Gtk3::Image->new_from_file(
                        $axmud::SHARE_DIR . $axmud::CLIENT->constRestoreIconPath
                    ),
                );

            } else {

                # (Default)
                $self->splitButton->set_icon_widget(
                    Gtk3::Image->new_from_file(
                        $axmud::SHARE_DIR . $axmud::CLIENT->constSplitIconPath
                    ),
                );
            }

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

        return 1;
    }

    sub updateConsoleButton {

        # Called by GA::Session->add_systemMsg and ->reset_systemMsg
        # The argument corresponds to the icon to draw on the console button
        #
        # Expected arguments
        #   $type       - One of the strings 'empty', 'system', 'debug' or 'error', corresponding to
        #                   one of the icons in ../share/icons/button that's used to draw the
        #                   button when it's not flashing
        #
        # Optional arguments
        #   $tempType   - One of the strings 'system', 'debug' or 'error', corresponding to the icon
        #                   that's used to draw the button when it's flashing ('undef' when $type is
        #                   'empty')
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my $iv;

        # Check for improper arguments
        if (
            ! defined $type
            || ($type ne 'empty' && $type ne 'system' && $type ne 'debug' && $type ne 'error')
            || (
                defined $tempType && $tempType ne 'system' && $tempType ne 'debug'
                && $tempType ne 'error'
            )
            || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->updateConsoleButton', @_);
        }

        if ($self->consoleButton) {

            if (! $self->consoleIconFlashFlag) {
                $iv = 'constEmptyIconPath';
            } elsif ($tempType) {
                $iv = 'const' . ucfirst($tempType) . 'IconPath';
            } else {
                $iv = 'const' . ucfirst($type) . 'IconPath';
            }

            $self->consoleButton->set_icon_widget(
                Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->$iv),
            );

            $self->ivPoke('consoleIconType', $type);
            $self->ivPoke('consoleIconTempType', $tempType);
            $self->ivPoke('consoleIconFlashFlag', TRUE);

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

        return 1;
    }



( run in 0.722 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )