Games-Axmud

 view release on metacpan or  search on metacpan

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

        my $menuItem_display = Gtk3::MenuItem->new('_Display');
        $menuItem_display->set_submenu($menuColumn_display);
        $menuBar->append($menuItem_display);

        # 'Commands' column
        my $menuColumn_commands = $self->drawCommandsColumn();
        my $menuItem_commands = Gtk3::MenuItem->new('_Commands');
        $menuItem_commands->set_submenu($menuColumn_commands);
        $menuBar->append($menuItem_commands);

        # 'Recordings' column
        my $menuColumn_recordings = $self->drawRecordingsColumn();
        my $menuItem_recordings = Gtk3::MenuItem->new('_Recordings');
        $menuItem_recordings->set_submenu($menuColumn_recordings);
        $menuBar->append($menuItem_recordings);

        # 'Axbasic' column
        my $menuColumn_basic = $self->drawAxbasicColumn();
        my $menuItem_basic = Gtk3::MenuItem->new('_' . $axmud::BASIC_NAME);
        $menuItem_basic->set_submenu($menuColumn_basic);
        $menuBar->append($menuItem_basic);

        # 'Plugins' column
        my $menuColumn_plugins = $self->drawPluginsColumn();
        my $menuItem_plugins = Gtk3::MenuItem->new('_Plugins');
        $menuItem_plugins->set_submenu($menuColumn_plugins);
        $menuBar->append($menuItem_plugins);

        # 'Help' column
        my $menuColumn_help = $self->drawHelpColumn();
        my $menuItem_help = Gtk3::MenuItem->new('_Help');
        $menuItem_help->set_submenu($menuColumn_help);
        $menuBar->append($menuItem_help);

        # Update IVs
        $self->ivPoke('packingBox', $vBox);
        $self->ivPoke('menuBar', $menuBar);
        $self->ivPoke('pluginMenu', $menuColumn_plugins);

        # If any plugins have registered their desire to create sub-menus, call those plugins and
        #   create the sub-menus now
        foreach my $pluginObj (sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivValues('pluginHash'))) {

            my ($funcRef, $subMenu);

            if (
                $pluginObj->enabledFlag
                && $axmud::CLIENT->ivExists('pluginMenuFuncHash', $pluginObj->name)
            ) {
                $funcRef = $axmud::CLIENT->ivShow('pluginMenuFuncHash', $pluginObj->name);
                $subMenu = $self->addPluginWidgets($pluginObj->name);

                if ($funcRef && $subMenu) {

                    &$funcRef($self, $subMenu);
                }
            }
        }

        # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
        $axmud::CLIENT->desktopObj->restrictWidgets();

        return 1;
    }

    sub objDestroy {

        # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
        #   parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
        #   to do any necessary tidying up
        #
        # 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 . '->objDestroy', @_);
        }

        # (No tidying up required for this type of strip object)
        #   ...

        return 1;
    }

#   sub setWidgetsIfSession {}              # Inherited from GA::Generic::Strip

#   sub setWidgetsChangeSession {}          # Inherited from GA::Generic::Strip

    # ->signal_connects are stored in $self->drawWorldColumn, etc

    # Other functions

    sub drawWorldColumn {

        # Called by $self->enableMenu
        # Sets up the menu's 'World' column
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments, or if the menu can't be created
        #   Otherwise returns the Gtk3::Menu created

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

        # Local variables
        my ($mode, $choice);

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

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

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

            });
            $subMenu_saveFile->append($menuItem_saveFile_winmaps);

            my $menuItem_saveFile_ttsObjs = Gtk3::MenuItem->new('Te_xt-to-speech file');
            $menuItem_saveFile_ttsObjs->signal_connect('activate' => sub {

                $self->winObj->visibleSession->pseudoCmd('save -x' . $forceSwitch, $mode);
            });
            $subMenu_saveFile->append($menuItem_saveFile_ttsObjs);

        my $menuItem_saveFile = Gtk3::MenuItem->new('S_ave files');
        $menuItem_saveFile->set_submenu($subMenu_saveFile);
        $menuColumn_file->append($menuItem_saveFile);
        # (Requires a visible session whose status is 'connected' or 'offline' and
        #   $self->saveAllSessionsFlag set to FALSE)
        $self->ivAdd('menuItemHash', 'save_file', $menuItem_saveFile);

            # 'Save options' submenu
            my $subMenu_saveOptions = Gtk3::Menu->new();

            my $menuColumn_forced_radio1 = Gtk3::RadioMenuItem->new_with_mnemonic(
                undef,
                'Forced saves o_ff',
            );
            $menuColumn_forced_radio1->signal_connect('toggled' => sub {

                if ($menuColumn_forced_radio1->get_active()) {
                    $forceSwitch = '';
                } else {
                    $forceSwitch = ' -f';
                }
            });
            $subMenu_saveOptions->append($menuColumn_forced_radio1);

            my $menuColumn_forced_radio2 = Gtk3::RadioMenuItem->new_with_mnemonic(
                $menuColumn_forced_radio1->get_group(),
                'Forced saves o_n',
            );
            $subMenu_saveOptions->append($menuColumn_forced_radio2);

            $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new());  # Separator

            my $menuColumn_allSession_radio1 = Gtk3::RadioMenuItem->new_with_mnemonic(
                undef,
                'Save in _this session',
            );
            $menuColumn_allSession_radio1->signal_connect('toggled' => sub {

                if ($menuColumn_allSession_radio1->get_active()) {

                    $allSessionSwitch = '';
                    $self->ivPoke('saveAllSessionsFlag', FALSE);

                } else {

                    $allSessionSwitch = ' -a';
                    $self->ivPoke('saveAllSessionsFlag', TRUE);
                }

                # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
                $axmud::CLIENT->desktopObj->restrictWidgets();
            });
            $subMenu_saveOptions->append($menuColumn_allSession_radio1);

            my $menuColumn_allSession_radio2 = Gtk3::RadioMenuItem->new_with_mnemonic(
                $menuColumn_allSession_radio1->get_group(),
                'Save in _all sessions',
            );
            $subMenu_saveOptions->append($menuColumn_allSession_radio2);

            $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new());  # Separator

            my $menuItem_autoSaves_off = Gtk3::MenuItem->new('T_urn auto-saves off');
            $menuItem_autoSaves_off->signal_connect('activate' => sub {

                $self->winObj->visibleSession->pseudoCmd('autosave off', $mode);
            });
            $subMenu_saveOptions->append($menuItem_autoSaves_off);

            my $menuItem_autoSaves_on = Gtk3::MenuItem->new('Tu_rn auto-saves on');
            $menuItem_autoSaves_on->signal_connect('activate' => sub {

                $self->winObj->visibleSession->pseudoCmd('autosave on', $mode);
            });
            $subMenu_saveOptions->append($menuItem_autoSaves_on);

            $subMenu_saveOptions->append(Gtk3::SeparatorMenuItem->new());  # Separator

            my $menuItem_autoSaves_setTime = Gtk3::MenuItem->new('_Set auto-save time...');
            $menuItem_autoSaves_setTime->signal_connect('activate' => sub {

                my $number = $self->winObj->showEntryDialogue(
                    'Set auto-save time',
                    'Enter a time in seconds',
                );

                if ($number) {

                    # Set the auto-save time
                    $self->winObj->visibleSession->pseudoCmd('autosave ' . $number, $mode);
                }
            });
            $subMenu_saveOptions->append($menuItem_autoSaves_setTime);

        my $menuItem_saveOptions = Gtk3::MenuItem->new('Sa_ve options');
        $menuItem_saveOptions->set_submenu($subMenu_saveOptions);
        $menuColumn_file->append($menuItem_saveOptions);
        # (Requires a visible session whose status is 'connected' or 'offline')
        $self->ivAdd('menuItemHash', 'save_options', $menuItem_saveOptions);

        $menuColumn_file->append(Gtk3::SeparatorMenuItem->new());   # Separator

        my $menuItem_importFile = Gtk3::MenuItem->new('I_mport files...');
        $menuItem_importFile->signal_connect('activate' => sub {

            $self->winObj->visibleSession->pseudoCmd('importfiles', $mode);
        });
        $menuColumn_file->append($menuItem_importFile);
        # (Requires a visible session whose status is 'connected' or 'offline')
        $self->ivAdd('menuItemHash', 'import_files', $menuItem_importFile);

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

                            # No sessions open, so terminate the client
                            $axmud::CLIENT->stop();
                        }

                    # If a session is open, then we can call ->doInstruct, as normal
                    } elsif ($self->winObj->visibleSession) {

                        $self->winObj->visibleSession->doInstruct($buttonObj->instruct);

                    # Process commands directly
                    } elsif ($buttonObj->instruct eq ';connect') {

                        # Check that the Connections window isn't already open
                        if ($axmud::CLIENT->connectWin) {

                            # Window already open; draw attention to the fact by 'present'ing it
                            $axmud::CLIENT->connectWin->restoreFocus();

                        } else {

                            # Open the Connections window
                            $winObj = $self->winObj->quickFreeWin(
                                'Games::Axmud::OtherWin::Connect',
                                $self->winObj->visibleSession,
                            );

                            if ($winObj) {

                                # Only one Connections window can be open at a time
                                $axmud::CLIENT->set_connectWin($winObj);
                            }
                        }

                    } elsif ($buttonObj->instruct eq ';openaboutwindow -h') {

                        # Check that the About window isn't already open
                        if ($axmud::CLIENT->aboutWin) {

                            # Window already open; draw attention to the fact by 'present'ing it
                            $axmud::CLIENT->aboutWin->restoreFocus();

                        } else {

                            # Open the About window
                            $winObj = $self->winObj->quickFreeWin(
                                'Games::Axmud::OtherWin::About',
                                $self->winObj->visibleSession,
                                # Config
                                'first_tab' => 'help',
                            );

                            if ($winObj) {

                                # Only one About window can be open at a time
                                $axmud::CLIENT->set_aboutWin($winObj);
                            }
                        }
                    }

                    # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
                    $axmud::CLIENT->desktopObj->restrictWidgets();
                });

                $iconName = 'icon_' . $buttonObj->name;
                if ($buttonObj->requireConnectFlag) {

                    # (Button requires a connection to a world, even if it's in 'offline' mode)
                    $self->ivAdd('requireConnectHash', $iconName, $toolButton_item);

                } elsif ($buttonObj->requireSessionFlag) {

                    # (Button requires a current session)
                    $self->ivAdd('requireSessionHash', $iconName, $toolButton_item);

                } else {

                    # (Button always sensitised)
                    $self->ivDelete('requireConnectHash', $iconName);
                    $self->ivDelete('requireSessionHash', $iconName);
                }

                # Add the toolbar button to the toolbar
                $self->toolbar->insert($toolButton_item, -1);
                push (@widgetList, $toolButton_item);
            }
        }

        $self->toolbar->show_all();

        # Store the list of buttons and separators
        $self->ivPoke('toolbarWidgetList', @widgetList);

        # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
        $axmud::CLIENT->desktopObj->restrictWidgets();

        # Setup complete
        return 1;
    }

    sub resetToolbar {

        # Called by GA::PrefWin::Client->toolbarTab to re-draw the list of toolbar buttons, after
        #   the GA::Client->toolbarHash and ->toolbarList have been modified
        #
        # 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 . '->resetToolbar', @_);
        }

        # Remove the existing buttons and separators
        foreach my $widget ($self->toolbarWidgetList) {

            $axmud::CLIENT->desktopObj->removeWidget($self->toolbar, $widget);
        }

        # Draw a new set of buttons and separators
        $self->fillToolbar();

        return 1;
    }

    sub sensitiseWidgets {

        # Can be called by anything, but usually called by GA::Win::Internal->restrictToolbars
        # Given a list of Gtk3 widgets (all of them toolbar items), sets them as sensitive
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   @widgetList - A list of widget names from $self->toolbarWidgetList (e.g. 'connect_me')
        #
        # Return values
        #   1

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

        # (No improper arguments to check)

        foreach my $widgetName (@widgetList) {

            my $widget;

            $widget = $self->ivShow('requireConnectHash', $widgetName);
            if (! $widget) {

                $widget = $self->ivShow('requireSessionHash', $widgetName);
            }

            if ($widget) {

                $widget->set_sensitive(TRUE);
            }
        }

        return 1;
    }

    sub desensitiseWidgets {

        # Can be called by anything, but usually called by GA::Win::Internal->restrictToolbars
        # Given a list of Gtk3 widgets (all of them toolbar items), sets them as insensitive
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   @widgetList - A list of widget names from $self->toolbarWidgetList (e.g. 'connect_me')
        #
        # Return values
        #   1

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

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

        # Removes a table object (inheriting GA::Generic::Table) from this strip object's Gtk3::Grid
        #
        # Expected arguments
        #   $tableObj   - The table object to remove
        #
        # Return values
        #   'undef' on improper arguments, if the table object is protected from removal or if the
        #       table object no longer exists on this strip
        #   1 otherwise

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

        # Local variables
        my ($existFlag, $matchFlag, $count);

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

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

        # Don't remove the table object if it's protected
        if (! $tableObj->allowRemoveFlag) {

            if ($axmud::CLIENT->debugTableFitFlag) {

                $self->writeError(
                    'Can\'t remove table object \'' . $tableObj->type . '\' as it is protected',
                    $self->_objClass . '->removeTableObj',
                )
            }

            return undef;
        }

        # Check the table object still exists on this strip
        OUTER: foreach my $obj ($self->ivValues('tableObjHash')) {

            if ($obj eq $tableObj) {

                $existFlag = TRUE;
                last OUTER;
            }
        }

        if (! $existFlag) {

            if ($axmud::CLIENT->debugTableFitFlag) {

                $self->writeError(
                    'Specified table object doesn\'t exist (or no longer exists)',
                    $self->_objClass . '->removeTableObj',
                )
            }

            return undef;
        }


        # Remove the table object
        $axmud::CLIENT->desktopObj->removeWidget($self->table, $tableObj->packingBox);

        # Update IVs
        $self->ivDelete('tableObjHash', $tableObj->number);
        $self->ivDelete('tablezoneHash', $tableObj->zoneObj->number);

        # Notify all of this window's strip objects of the table object's demise
        foreach my $stripObj (
            sort {$a->number <=> $b->number} ($self->winObj->ivValues('stripHash'))
        ) {
            $stripObj->notify_removeTableObj($tableObj);
        }

        # Notify all of this strip's table objects of the table object's demise
        foreach my $otherTableObj (
            sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))
        ) {
            if ($otherTableObj ne $tableObj) {

                $otherTableObj->notify_removeTableObj($tableObj);
            }
        }

        return 1;
    }

    sub removeAllTableObjs {

        # Can be called by anything
        # Removes all table objects (inheriting GA::Generic::Table) from this strip object's
        #   Gtk3::Grid
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments or if any of the removal operations fail
        #   Otherwise returns the number of objects removed (may be zero)

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

        # Local variables
        my ($count, $failFlag);

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

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

        # Remove all table objects
        $count = 0;
        foreach my $tableObj (
            sort {$a->number <=> $b->number} ($self->ivValues('tableObjHash'))
        ) {
            if (! $self->removeTableObj($tableObj)) {
                $failFlag = TRUE;
            } else {
                $count++;
            }
        }

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

        # Check that the specified space on the table is not already occupied by a tablezone
        foreach my $otherZoneObj ($self->ivValues('tablezoneHash')) {

            if (
                $tableObj->zoneObj ne $otherZoneObj
                && (
                    ($left >= $otherZoneObj->left && $left <= $otherZoneObj->right)
                    || ($right >= $otherZoneObj->left && $right <= $otherZoneObj->right)
                ) && (
                    ($top >= $otherZoneObj->top && $top <= $otherZoneObj->bottom)
                    || ($bottom >= $otherZoneObj->top && $bottom <= $otherZoneObj->bottom)
                )
            ) {
                if ($axmud::CLIENT->debugTableFitFlag) {

                    $self->writeError(
                        'Specified area ' . $string . ' is occupied by an existing table object',
                        $self->_objClass . '->resizeTableObj',
                    )
                }

               return undef;
            }
        }

        # Remove the old tablezone...
        $self->ivDelete('tablezoneHash', $tableObj->zoneObj->number);

        # ...and create a new one, assigning it to the table object
        $zoneObj = Games::Axmud::Obj::Tablezone->new(
            $self->tablezoneCount,
            $tableObj->_objClass,
            $left,
            $top,
            $right,
            $bottom,
        );

        if (! $zoneObj) {

            if ($axmud::CLIENT->debugTableFitFlag) {

                $self->writeError(
                    'Could not allocate space for the table object at the specified position '
                    . $string,
                    $self->_objClass . '->resizeTableObj',
                )
            }

            return undef;

        } else {

            $self->ivAdd('tablezoneHash', $zoneObj->number, $zoneObj);
            $self->ivIncrement('tablezoneCount');

            $tableObj->set_zoneObj($zoneObj);
        }

        # Resize the table object
        $axmud::CLIENT->desktopObj->removeWidget($self->table, $tableObj->packingBox);

        $self->table->attach(
            $tableObj->packingBox,
            $zoneObj->left,
            $zoneObj->top,
            # Axmud uses 59,59, but Gtk expects 60,60
            ($zoneObj->right - $zoneObj->left + 1),
            ($zoneObj->bottom - $zoneObj->top + 1),
        );

        # Inform the table object that it's been resized
        $tableObj->setWidgetsOnResize(
            $zoneObj->left,
            $zoneObj->right,
            $zoneObj->top,
            $zoneObj->bottom,
        );

        return 1;
    }

    sub replaceHolder {

        # Called by any code
        # Looks for a holder table object (GA::Table::Holder) with a specified ->id. If one is
        #   found, removes it and adds a different table object using the same size/position. If
        #   one is not found, returns 'undef'
        # (The calling code can call this function as often as it needs to, looking for various
        #   holders, and if none are found, can then call $self->addTableObj directly)
        #
        # Expected arguments
        #   $id - The holder ID; can be any non-empty string. If any holders have an ->id with this
        #           value, that is replaced. Values might include types of 'grid' window such as
        #           'map', or 'task' for task windows in general, or 'status_task' for the Status
        #           task in particular. If not specified, 'undef' or an empty string, 'task' is
        #           used as a default value
        #   $packageName
        #       - The package name of the replacement table object, e.g. GA::Table::Pane
        #
        # Optional arguments
        #   $objName
        #       - An optional name to give to the replacement table object, when it is created. If
        #           not specified, the table object's ->objName is given the same value as its
        #           ->number. If specified, $objName can be any string (avoid using short strings or
        #           numbers. No part of the code checks that table object names are unique; if two
        #           or more table objects share the same ->objName, usually the one with the lowest
        #           ->number 'wins')
        #   %initHash
        #       - A hash containing arbitrary data to use as the table object's initialisation
        #           settings. The table object should use default initialisation settings unless it
        #           can succesfully interpret one or more of the key-value pairs in the hash, if
        #           there are any
        #
        # Return values
        #   'undef' on improper arguments, if no holders with a matching ->id are found or if the
        #       replacement table object can't be created
        #   Otherwise returns the blessed reference to the replacement table object

        my ($self, $id, $packageName, $objName, %initHash) = @_;

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


        if ($self->visibleFlag) {

            # Only polite to destroy GooCanvas2 canvas objects when they're no longer needed
            foreach my $canvasObj ($self->gaugeCanvasList) {

                $canvasObj->remove();
            }
        }

        return 1;
    }

#   sub setWidgetsIfSession {}              # Inherited from GA::Generic::Strip

#   sub setWidgetsChangeSession {}          # Inherited from GA::Generic::Strip

    # ->signal_connects

    # Other functions

    sub drawGaugeBox {

        # Called by $self->objEnable and ->addGaugeLevel
        # Draws a Gtk3::HBox to contain gauge levels
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my (
            $levelCount,
            %sessionHash,
        );

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

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

        # Create a packing box, if one doesn't exist already
        my $packingBox;
        if (! $self->packingBox) {

            # This function is being called for the first time
            $packingBox = Gtk3::VBox->new(FALSE, 0);
            $packingBox->set_border_width(0);

        } else {

            # This function is being called for a subsequent time. Remove its current contents, so
            #   new widgets can be created
            $packingBox = $self->packingBox;
            $axmud::CLIENT->desktopObj->removeWidget($packingBox, $self->frame);
        }

        # Different sessions might be using different numbers of gauge levels. Find the highest
        #   number of gauge levels used by the greediest session (might be 0, if there are no gauge
        #   levels at the moment)
        $levelCount = 0;
        foreach my $gaugeLevelObj ($self->ivValues('gaugeLevelHash')) {

            my $num = $gaugeLevelObj->session->number;

            if (! exists $sessionHash{$num}) {
                $sessionHash{$num} = 1;
            } else {
                $sessionHash{$num} = $sessionHash{$num} + 1;
            }

            if ($levelCount < $sessionHash{$num}) {

                $levelCount = $sessionHash{$num};
            }
        }

        # If there are no gauges visible, draw a gauge box with room for one gauge level anyway, in
        #   the expectation that the first gauge might be added a moment from now
        if (! $levelCount) {

            $levelCount = 1;
        }

        # Add a frame
        my $frame = Gtk3::Frame->new(undef);
        $frame->set_border_width(0);
        $frame->set_size_request(
            -1,
            (
                2                           # Size of frame border
                + $self->gaugeSpacingY
                + ($levelCount * ($self->gaugeHeight + $self->gaugeSpacingY))
            ),
        );

        $packingBox->pack_start($frame, TRUE, TRUE, 0);

        # The only way to detect the frame's size reliably is to store the frame's size allocation
        #   whenever it is set
        $frame->signal_connect('size-allocate' => sub {

            my ($widget, $hashRef) = @_;

            $self->ivPoke('canvasFrameWidth', $$hashRef{width});
            $self->ivPoke('canvasFrameHeight', $$hashRef{height});

            if ($self->canvas) {

                $self->updateGauges();

                # The resized canvas won't be visible until a Gtk main loop occurs
                $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->drawGaugeBox');
            }
        });

        # Add a drawing canvas, inside the frame
        my $canvas = GooCanvas2::Canvas->new();
        $frame->add($canvas);

        # Update IVs
        $self->ivPoke('packingBox', $packingBox);
        $self->ivPoke('frame', $frame);
        $self->ivPoke('canvas', $canvas);

        # Setup complete
        return 1;
    }

    sub removeGaugeBox {

        # Called by GA::Client->spinClientLoop or $self->removeSessionGauges
        # If this window's gauge box has been empty for too long, remove the gauge box entirely
        # (By waiting for a few seconds, we don't have to remove then re-draw the gauge box within
        #   the space of a second if, for example, the Status task resets)
        #
        # 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 . '->removeGaugeBox', @_);
        }

        # Check that gauge box is actually drawn and doesn't currently contain any gauges
        if ($self->visibleFlag && ! $self->gaugeLevelHash) {

            # Destroy canvas objects
            foreach my $canvasObj ($self->gaugeCanvasList) {

                $canvasObj->remove();
            }

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

            # Mark the strip object as hidden
            $self->winObj->hideStripObj($self);
        }

        return 1;
    }

    sub addGaugeLevel {

        # Can be called by anything

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


        return $self;
    }

    ##################
    # Methods

    # Standard strip object functions

    sub objEnable {

        # Called by GA::Win::Internal->drawWidgets or ->addStripObj
        # Sets up the strip object's widgets
        #
        # Expected arguments
        #   $winmapObj  - The winmap object (GA::Obj::Winmap) that specifies the layout of the
        #                   parent window
        #
        # Return values
        #   'undef' on improper arguments
        #   1 on success

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

        # Local variables
        my ($mainText, $preText, $postText);

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

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

        # Create a packing box, if one doesn't exist already
        my $packingBox;
        if (! $self->packingBox) {

            # This function is being called for the first time
            $packingBox = Gtk3::HBox->new(FALSE, 0);
            $packingBox->set_border_width(0);

        } else {

            # This function is being called for a subsequent time. Temporarily store the contents
            #   of the entry box(es), so they can be replaced
            $mainText = $self->entry->get_text();
            if ($self->preEntry) {

                $preText = $self->preEntry->get_text();
            }

            if ($self->postEntry) {

                $postText = $self->postEntry->get_text();
            }

            # Remove the packing box's current contents, so new widgets can be created
            $packingBox = $self->packingBox;
            foreach my $child ($self->packingBox->get_children()) {

                $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $child);
            }
        }

        # Draw a Gtk3::Entry box (compulsory) and any buttons specified by $self->initHash
        #   (->signal_connects for each appear later in the function)

        # Draw a 'wipe entry' icon as a toolbutton (optional)
        my $wipeButton;
        if ($self->ivShow('initHash', 'wipe_flag') && ! $axmud::BLIND_MODE_FLAG) {

            $wipeButton = Gtk3::ToolButton->new(
                Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constWipeIconPath),
                'Clear command entry box',
            );
            $packingBox->pack_start($wipeButton, FALSE, FALSE, 0);
            $wipeButton->set_tooltip_text('Clear command entry box');
        }

        # Draw an 'add entries' icon as a toolbutton (optional)
        my $addButton;
        if ($self->ivShow('initHash', 'add_flag') && ! $axmud::BLIND_MODE_FLAG) {

            $addButton = Gtk3::ToolButton->new(
                Gtk3::Image->new_from_file($axmud::SHARE_DIR . $axmud::CLIENT->constAddIconPath),
                'Use additional entry boxes',
            );
            $packingBox->pack_start($addButton, FALSE, FALSE, 0);
            $addButton->set_tooltip_text('Use additional entry boxes');
        }

        # Draw one or more entry boxes, depending on the value of $self->entryBoxMode
        my ($entry, $preEntry, $postEntry);

        # Draw the prepending entry box, if allowed
        if ($self->entryBoxMode eq 'pre' || $self->entryBoxMode eq 'both') {

            $preEntry = Gtk3::Entry->new();
            $packingBox->pack_start($preEntry, FALSE, FALSE, 0);
            $preEntry->set_tooltip_text('Add to beginning of world commands');
            if (defined $preText && $preText ne '') {

                $preEntry->set_text($preText);
            }
        }

        # Draw the main entry box
        $entry = Gtk3::Entry->new();
        $packingBox->pack_start($entry, TRUE, TRUE, 0);
        $entry->set_tooltip_text('Command entry box');
        if (defined $mainText && $mainText ne '') {

            $entry->set_text($mainText);
        }

        # Draw the appending entry box, if allowed
        if ($self->entryBoxMode eq 'post' || $self->entryBoxMode eq 'both') {

            $postEntry = Gtk3::Entry->new();
            $packingBox->pack_start($postEntry, FALSE, FALSE, 0);
            $postEntry->set_tooltip_text('Add to end of world commands');

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

                        ),
                    );

                } else {

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

            if ($self->entry) {

                # If the current current session's server has suggested that the client stop
                #   ECHOing, and the client has agreed, text in the entry box(es) must be obscured
                # If not, or if special echo mode is on, it must be un-obscured (in case it was
                #   obscured by the previous session)
                # In either case, text in the entry box is removed when switching sessions
                if (
                    $self->winObj->visibleSession->echoMode eq 'client_agree'
                    && ! $self->specialEchoFlag
                ) {
                    $self->obscureEntry(TRUE);
                } else {
                    $self->obscureEntry(FALSE);
                }

                # Set (or reset) entry box icons. Those associated with recordings may have changed
                #   since the last time the session was the visible session
                $self->entry->set_icon_from_stock('primary', $self->primaryIcon);

                if ($self->winObj->visibleSession->recordingPausedFlag) {
                    $self->entry->set_icon_from_stock('secondary', 'gtk-media-pause');
                } elsif ($self->winObj->visibleSession->recordingFlag) {
                    $self->entry->set_icon_from_stock('secondary', 'gtk-media-record');
                } else {
                    $self->entry->set_icon_from_stock('secondary', undef);
                }
            }

        } else {

            # No visible session; use the default settings
            $self->ivPoke('specialEchoFlag', FALSE);
            $self->ivPoke('specialPreserveFlag', FALSE);
            $self->ivPoke('specialWorldCmd', '');
            $self->ivPoke('primaryIcon', undef);
            $self->ivPoke('prevVisibleSession', undef);

            if ($self->entry) {

                if (! $axmud::CLIENT->sessionHash) {

                    # If there are no sessions at all, the main entry box must be empty, and the
                    #   minor entry boxes must be removed entirely
                    $self->entry->set_text('');
                    if ($self->preEntry) {

                        $axmud::CLIENT->desktopObj->removeWidget(
                            $self->packingBox,
                            $self->preEntry,
                        );

                        $self->ivUndef('preEntry');
                    }

                    if ($self->postEntry) {

                        $axmud::CLIENT->desktopObj->removeWidget(
                            $self->packingBox,
                            $self->postEntry,
                        );

                        $self->ivUndef('postEntry');
                    }
                }
            }
        }

        return 1;
    }

    # ->signal_connects

    sub setEntrySignals {

        # Called by $self->objEnable
        # Set up a ->signal_connect to watch out for the user input in the entry box
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my %shortHash;

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

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

        # Deal with user pressing their ENTER key
        $self->entry->signal_connect('activate' => sub {

            my (
                $instruct, $thisFuncRef, $preText, $postText, $successFlag, $type,
                @instructList,
            );

            $instruct = $self->entry->get_text();
            $thisFuncRef = $self->funcRef;

            # The entry box's behaviour depends on whether the parent window is a 'main' window, or
            #   not
            if ($self->winObj->winType eq 'main') {

                if (
                    $self->specialEchoFlag
                    && ! $self->specialPreserveFlag
                    && $self->specialWorldCmd
                    && $self->winObj->visibleSession
                ) {
                    # Pass the stored world command to the visible session, calling ->dispatchCmd



( run in 1.232 second using v1.01-cache-2.11-cpan-bbc515a03b3 )