| 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::Gauge | ||
| 16 | # Handles a 'main' window gauge | ||
| 17 | |||
| 18 | { package Games::Axmud::Obj::Gauge; | ||
| 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::Strip::GaugeBox->addGauge or ->addTextGauge | ||
| 34 | # Prepare a new instance of the Axmud gauge object which handles a single text of graphical | ||
| 35 | # gauge in the 'main' window | ||
| 36 | # | ||
| 37 | # Expected arguments | ||
| 38 | # $session - The calling GA::Session, which is responsible for keeping the gauge | ||
| 39 | # up-to-date | ||
| 40 | # $number - Unique number for this gauge | ||
| 41 | # $level - The unique number of the GA::Obj::GaugeLevel object, representing the | ||
| 42 | # gauge level on which this gauge is drawn (matches a key in | ||
| 43 | # GA::Strip::GaugeBox->gaugeLevelHash) | ||
| 44 | # $textFlag - TRUE if this is a text gauge, FALSE if this is a graphical gauge | ||
| 45 | # | ||
| 46 | # Return values | ||
| 47 | # 'undef' on improper arguments | ||
| 48 | # Blessed reference to the newly-created object on success | ||
| 49 | |||
| 50 | my ($class, $session, $number, $level, $textFlag, $check) = @_; | ||
| 51 | |||
| 52 | # Check for improper arguments | ||
| 53 | if ( | ||
| 54 | ! defined $class || ! defined $session || ! defined $number || ! defined $level || | ||
| 55 | ! defined $textFlag || defined $check | ||
| 56 | ) { | ||
| 57 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 58 | } | ||
| 59 | |||
| 60 | # Setup | ||
| 61 | my $self = { | ||
| 62 | _objName => $number, | ||
| 63 | _objClass => $class, | ||
| 64 | _parentFile => undef, # No parent file | ||
| 65 | _parentWorld => undef, # No parent world | ||
| 66 | _privFlag => FALSE, # All IVs are public | ||
| 67 | |||
| 68 | # Object IVs | ||
| 69 | # ---------- | ||
| 70 | |||
| 71 | # Unique number for this gauge | ||
| 72 | number => $number, | ||
| 73 | # The unique number of the gauge level on which this gauge is drawn (matches a key in | ||
| 74 | # GA::Strip::GaugeBox->gaugeLevelHash) | ||
| 75 | level => $level, | ||
| 76 | # The number of the GA::Session that's responsible for keeping the gauge up-to-date | ||
| 77 | session => $session, | ||
| 78 | |||
| 79 | # IVs used with both text and graphical gauges | ||
| 80 | |||
| 81 | # Flag set to TRUE for text gauges, FALSE for graphical gauges | ||
| 82 | textFlag => $textFlag, | ||
| 83 | # The value and maximum value displayed by the gauge (both number >=0, | ||
| 84 | # $value <= $maxValue) | ||
| 85 | value => 1, | ||
| 86 | maxValue => 1, | ||
| 87 | # If TRUE, the total size of the gauge is ($value + $maxValue). If FALSE (or 'undef'), | ||
| 88 | # the total size is $maxValue | ||
| 89 | addFlag => FALSE, | ||
| 90 | # The label to use. If 'undef' or an empty string, no label is used | ||
| 91 | label => undef, | ||
| 92 | # For MXP gauges, the entity used to set ->value (compulsory), and the entity used to | ||
| 93 | # set ->maxValue (optional) | ||
| 94 | mxpEntity => undef, | ||
| 95 | mxpMaxEntity => undef, | ||
| 96 | |||
| 97 | # IVs used with graphical gauges only | ||
| 98 | |||
| 99 | # The colour to use in the 'full' part of the gauge (an RGB colour tag, default white) | ||
| 100 | fullColour => '#FFFFFF', | ||
| 101 | # The colour to use in the 'empty' part of the gauge (an RGB colour tag, default black) | ||
| 102 | emptyColour => '#000000', | ||
| 103 | # The label colour (an RGB colour tag, default red) | ||
| 104 | labelColour => '#FF0000', | ||
| 105 | # If flag is TRUE, the label text (if displayed) is supplemented with the values; e.g. | ||
| 106 | # 'HP: 37/100'. If FALSE (or 'undef'), only the text in $label is visible | ||
| 107 | labelFlag => FALSE, | ||
| 108 | |||
| 109 | # Hash of data for use by whatever part of the code is controlling the gauge (for | ||
| 110 | # example, the Status task uses it to remember which of its IVs contains the | ||
| 111 | # numerical values to display in the gauge) | ||
| 112 | privateHash => {}, | ||
| 113 | }; | ||
| 114 | |||
| 115 | # Bless the object into existence | ||
| 116 | bless $self, $class; | ||
| 117 | return $self; | ||
| 118 | } | ||
| 119 | |||
| 120 | ################## | ||
| 121 | # Methods | ||
| 122 | |||
| 123 | ################## | ||
| 124 | # Accessors - set | ||
| 125 | |||
| 126 | ################## | ||
| 127 | # Accessors - get | ||
| 128 | |||
| 129 | sub number | ||
| 130 | { $_[0]->{number} } | ||
| 131 | sub level | ||
| 132 | { $_[0]->{level} } | ||
| 133 | sub session | ||
| 134 | { $_[0]->{session} } | ||
| 135 | |||
| 136 | sub textFlag | ||
| 137 | { $_[0]->{textFlag} } | ||
| 138 | sub value | ||
| 139 | { $_[0]->{value} } | ||
| 140 | sub maxValue | ||
| 141 | { $_[0]->{maxValue} } | ||
| 142 | sub addFlag | ||
| 143 | { $_[0]->{addFlag} } | ||
| 144 | sub label | ||
| 145 | { $_[0]->{label} } | ||
| 146 | sub mxpEntity | ||
| 147 | { $_[0]->{mxpEntity} } | ||
| 148 | sub mxpMaxEntity | ||
| 149 | { $_[0]->{mxpMaxEntity} } | ||
| 150 | |||
| 151 | sub fullColour | ||
| 152 | { $_[0]->{fullColour} } | ||
| 153 | sub emptyColour | ||
| 154 | { $_[0]->{emptyColour} } | ||
| 155 | sub labelColour | ||
| 156 | { $_[0]->{labelColour} } | ||
| 157 | sub labelFlag | ||
| 158 | { $_[0]->{labelFlag} } | ||
| 159 | |||
| 160 | sub privateHash | ||
| 161 | { my $self = shift; return %{$self->{privateHash}}; } | ||
| 162 | } | ||
| 163 | |||
| 164 | # Package must return a true value | ||
| 165 | 1 |