| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # General Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Games::Axmud::Obj::Toolbar | ||
| 16 | # Handles a 'main' window's toolbar button object | ||
| 17 | |||
| 18 | { package Games::Axmud::Obj::Toolbar; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | # use diagnostics; | ||
| 23 | |||
| 24 | use Glib qw(TRUE FALSE); | ||
| 25 | |||
| 26 | our @ISA = qw(Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Called by GA::Client->initialiseToolbar or GA::PrefWin::Client->windows4Tab | ||
| 34 | # Creates a new instance of the toolbar button object | ||
| 35 | # | ||
| 36 | # Expected arguments | ||
| 37 | # $name - A unique string name for this toolbar button object (max 16 chars, | ||
| 38 | # containing A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets | ||
| 39 | # acceptable. Must not exist as a key in the global hash of reserved | ||
| 40 | # names, $axmud::CLIENT->constReservedHash) | ||
| 41 | # $descrip - A short description, e.g. 'Do something' (max 32 chars) | ||
| 42 | # $customFlag - Flag set to TRUE if this is a custom toolbar button (can be modified by | ||
| 43 | # the user), set to FALSE if this is one of the default toolbar buttons | ||
| 44 | # listed in GA::Client->constToolbarList (which can't be modified by the | ||
| 45 | # user) | ||
| 46 | # $iconPath - File path for the icon to use. If $customFlag is TRUE, an absolute path; | ||
| 47 | # otherwise, the name of a file in /icons/main | ||
| 48 | # $instruct - The instruction to execute, when the toolbar button is clicked | ||
| 49 | # $requireSessionFlag | ||
| 50 | # - Flag set to TRUE if the icon should only be sensitised when there's a | ||
| 51 | # current session (set to FALSE otherwise) | ||
| 52 | # $requireConnectFlag | ||
| 53 | # - Flag set to TRUE if the icon should only be sensitised when connected to a | ||
| 54 | # world (set to FALSE otherwise) | ||
| 55 | # | ||
| 56 | # Return values | ||
| 57 | # 'undef' on improper arguments or if $number or $time are invalid | ||
| 58 | # Blessed reference to the newly-created object on success | ||
| 59 | |||
| 60 | my ( | ||
| 61 | $class, $name, $descrip, $customFlag, $iconPath, $instruct, $requireSessionFlag, | ||
| 62 | $requireConnectFlag, $check | ||
| 63 | ) = @_; | ||
| 64 | |||
| 65 | # Check for improper arguments | ||
| 66 | if ( | ||
| 67 | ! defined $class || ! defined $name || ! defined $descrip || ! defined $customFlag | ||
| 68 | || ! defined $iconPath || ! defined $instruct || ! defined $requireSessionFlag | ||
| 69 | || ! defined $requireConnectFlag || defined $check | ||
| 70 | ) { | ||
| 71 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 72 | } | ||
| 73 | |||
| 74 | # Setup | ||
| 75 | my $self = { | ||
| 76 | _objName => $name, | ||
| 77 | _objClass => $class, | ||
| 78 | _parentFile => 'toolbar', | ||
| 79 | _parentWorld => undef, # No parent file object | ||
| 80 | _privFlag => FALSE, # All IVs are public | ||
| 81 | |||
| 82 | # IVs | ||
| 83 | # --- | ||
| 84 | |||
| 85 | # Unique name for the toolbar object (max 16 characters) | ||
| 86 | name => $name, | ||
| 87 | # A short description, e.g. 'Do something' (max 32 characters) | ||
| 88 | descrip => $descrip, | ||
| 89 | # Flag set to TRUE if this is a custom toolbar button (can be modified by the user), set | ||
| 90 | # to FALSE if this is one of the default toolbar buttons listed in | ||
| 91 | # GA::Client->constToolbarList (which can't be modified by the user) | ||
| 92 | customFlag => $customFlag, | ||
| 93 | # File path for the icon to use. If $customFlag is TRUE, an absolute path; otherwise, | ||
| 94 | # the name of a file in /icons/main | ||
| 95 | iconPath => $iconPath, | ||
| 96 | # The instruction to execute, when the toolbar button is clicked | ||
| 97 | instruct => $instruct, | ||
| 98 | # Flag set to TRUE if the icon should only be sensitised when there's a current session | ||
| 99 | # (set to FALSE otherwise) | ||
| 100 | requireSessionFlag => $requireSessionFlag, | ||
| 101 | # Flag set to TRUE if the icon should only be sensitised when connected to a world (set | ||
| 102 | # to FALSE otherwise) | ||
| 103 | requireConnectFlag => $requireConnectFlag, | ||
| 104 | }; | ||
| 105 | |||
| 106 | # Bless the object into existence | ||
| 107 | bless $self, $class; | ||
| 108 | return $self; | ||
| 109 | } | ||
| 110 | |||
| 111 | ################## | ||
| 112 | # Methods | ||
| 113 | |||
| 114 | ################## | ||
| 115 | # Accessors - set | ||
| 116 | |||
| 117 | ################## | ||
| 118 | # Accessors - get | ||
| 119 | |||
| 120 | sub name | ||
| 121 | { $_[0]->{name} } | ||
| 122 | sub descrip | ||
| 123 | { $_[0]->{descrip} } | ||
| 124 | sub customFlag | ||
| 125 | { $_[0]->{customFlag} } | ||
| 126 | sub iconPath | ||
| 127 | { $_[0]->{iconPath} } | ||
| 128 | sub instruct | ||
| 129 | { $_[0]->{instruct} } | ||
| 130 | sub requireSessionFlag | ||
| 131 | { $_[0]->{requireSessionFlag} } | ||
| 132 | sub requireConnectFlag | ||
| 133 | { $_[0]->{requireConnectFlag} } | ||
| 134 | } | ||
| 135 | |||
| 136 | # Package must return a true value | ||
| 137 | 1 |