blib/lib/Games/Axmud/Generic.pm untested

filter: Statementstmt 0.0% 0 / 6961 Branchbran 0.0% 0 / 3164 Conditioncond 0.0% 0 / 2907 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 656 Podpod 0.0% 0 / 564 totaltotal 0.0% 0 / 14252 CC 1583 SCAR 53.4
CC
1583
Cov
0%
modifyInterface
1980.0
setProfile
1406.0
addInterface
1406.0
CRAP 208.4
1 # Copyright (C) 2011-2022 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::Generic::Atcp
16 # Generic ATCP object, inherited by GA::Obj::Atcp and GA::Obj::Gmcp
17 #
18 # Games::Axmud::Generic::Cage
19 # The generic cage object. Cages store interfaces (triggers, alias, macros, timers and hooks) for a
20 # particular profile object. When it's time to create active interfaces, the cage for each current
21 # profile is checked in profile priority order. Interfaces in a cage are made active if no
22 # interface with the same name (from a previously-checked cage) has already been made active. The
23 # generic cage is inherited by GA::Cage::XXX
24 # Games::Axmud::Generic::InterfaceCage
25 # A generic cage object for interfaces cages, inheriting from the generic cage, and inherited by
26 # GA::Cage::Trigger, etc
27 #
28 # Games::Axmud::Generic::CageMask
29 # The generic cage mask object. Cage masks are a way of initialising (or resetting) a task's IVs
30 # depending on which profiles are current profiles. Cage masks are checked in the usual profile
31 # priority order, and the task's IVs are only set by the first cage that wants to set them
32 # No part of the Axmud code uses a cage mask at present, but it might in the future
33 #
34 # Games::Axmud::Generic::Cmd
35 # Games::Axmud::Generic::Plugin::Cmd
36 # The generic command object, inherited by all client commands, and the generic private command
37 # object, inherited by all client commands loaded from a plugin
38 #
39 # Games::Axmud::Generic::ConfigWin
40 # The generic 'config' window object, inherited by all 'edit' and 'pref' windows
41 #
42 # Games::Axmud::Generic::EditWin
43 # The generic 'edit' window, inherited by all 'edit' and 'pref' windows
44 #
45 # Games::Axmud::Generic::FixedWin
46 # The generic 'fixed' window object, inherited by all 'fixed' windows
47 #
48 # Games::Axmud::Generic::FreeWin
49 # The generic 'free' window object, inherited by all 'free' window objects except 'dialogue' windows
50 #
51 # Games::Axmud::Generic::GridWin
52 # The generic 'grid' window object, inherited by all 'grid' window objects
53 #
54 # Games::Axmud::Generic::Interface, Games::Axmud::Generic::InterfaceModel
55 # The generic interface object, inherited by all interface objects, and the generic interface model
56 # object, inherited by all interface model objects
57 #
58 # Games::Axmud::Generic::MapWin
59 # The generic 'map' window object, inherited by all 'map' windows
60 #
61 # Games::Axmud::Generic::Mcp
62 # Generic MCP object, inherited by all MCP package objects
63 #
64 # Games::Axmud::Generic::ModelObj
65 # The generic model object, inherited by all model objects
66 #
67 # Games::Axmud::Generic::OtherWin
68 # The generic 'other' window object, inherited by all 'other' windows
69 #
70 # Games::Axmud::Generic::Profile
71 # The generic profile object, inherited by GA::Profile::XXX
72 #
73 # Games::Axmud::Generic::Strip
74 # The generic strip object, inherited by all strip objects
75 #
76 # Games::Axmud::Generic::Table
77 # The generic table object, inherited by all table objects
78 #
79 # Games::Axmud::Generic::Task
80 # The generic task object, inherited by all tasks
81 #
82 # Games::Axmud::Generic::Win
83 # The generic window object, inherited by all window objects
84 #
85 # Games::Axmud::Generic::WizWin
86 # The generic 'wiz' window object, inherited by all 'wiz' (wizard) windows
87  
88 { package Games::Axmud::Generic::Atcp;
89  
90 use strict;
91 use warnings;
92 use diagnostics;
93  
94 use Glib qw(TRUE FALSE);
95  
96 our @ISA = qw(Games::Axmud);
97  
98 ##################
99 # Constructors
100  
101 sub new {
102  
103 # Called by GA::Session->processAtcpData or ->processGmcpData
104 # Creates a new instance of the ATCP/GMCP object (which stores ATCP/GMCP data structures)
105 #
106 # Expected arguments
107 # $session - The GA::Session which called this function (not stored as an IV)
108 # $name - The name of the ATCP/GMCP module, a string in the form
109 # 'Package[.SubPackages][.Message]'
110 # $origData - The original data string, a scalar of undecoded JSON data, e.g.
111 # '{ "zone": "town" }'
112 #
113 # Return values
114 # 'undef' on improper arguments or if JSON conversion fails
115 # Blessed reference to the newly-created object on success
116  
117 my ($class, $session, $name, $origData, $check) = @_;
118  
119 # Local variables
120 my (
121 $msg, $data,
122 @packageList,
123 );
124  
125 # Check for improper arguments
126 if (
127 ! defined $class || ! defined $session || ! defined $name || ! defined $origData
128 || defined $check
129 ) {
130 return $axmud::CLIENT->writeImproper($class . '->new', @_);
131 }
132  
133 # Split $name into its components
134 @packageList = split(m/\./, $name);
135 if ((scalar @packageList) > 1) {
136  
137 $msg = pop @packageList;
138 }
139  
140 # Decode the JSON data. I'm still not sure what data format is allowed under ATCP (and
141 # neither is anyone else, apparently), so if ATCP isn't obviously in a JSON format, I'll
142 # enclose it in quotes to prevent GA::Client->decodeJson from throwing up an error
143 if ($class eq 'Games::Axmud::Obj::Atcp') {
144  
145 if ($origData =~ m/^[^\{\}\[\]\:]*$/) {
146  
147 $origData = '"' . $origData . '"';
148 }
149 }
150  
151 $data = $axmud::CLIENT->decodeJson($origData);
152 if (! defined $data) {
153  
154 return undef;
155 }
156  
157 # Setup
158 my $self = {
159 _objName => $name,
160 _objClass => $class,
161 _parentFile => $session->currentWorld->name,
162 _parentWorld => undef,
163 _privFlag => FALSE, # All IVs are public
164  
165 # IVs
166 # ---
167  
168 # The name of the ATCP/GMCP module, a string in the form
169 # 'Package[.SubPackages][.Message]'
170 name => $name,
171 # The components of $name - a list of package components, and the message (e.g.
172 # 'Foo.Bar.Baz' produces a package component list of 2 items ('Foo', 'Bar') and a
173 # scalar message 'Baz'
174 packageList => \@packageList,
175 msg => $msg,
176  
177 # The ATCP/GMCP data itself. The original data string, a scalar of undecoded JSON data,
178 # e.g. 'comm.repop { "zone": "town" }'. This string is not updated when $self->data
179 # is updated
180 origData => $origData,
181 # The interpreted JSON data. The key's corresponding value can be a scalar, or a
182 # list/hash reference, with further list/hash references embedded within
183 data => $data,
184 };
185  
186 # Bless the object into existence
187 bless $self, $class;
188 return $self;
189 }
190  
191 ##################
192 # Methods
193  
194 sub update {
195  
196 # Called by GA::Session->processAtcpData and ->processGmcpData
197 # Replaces the JSON data stored in $self->data with the new ATCP/GMCP package's data,
198 # merging embedded hashes but replacing embedded scalars and lists
199 #
200 # Expected arguments
201 # $jsonScalar - A scalar of undecoded JSON data, e.g. '{ "zone": "town" }'
202 #
203 # Return values
204 # 'undef' on improper arguments
205 # 1 otherwise
206  
207 my ($self, $jsonScalar, $check) = @_;
208  
209 # Local variables
210 my $newData;
211  
212 # Check for improper arguments
213 if (! defined $jsonScalar || defined $check) {
214  
215 return $axmud::CLIENT->writeImproper($self->_objClass . '->update', @_);
216 }
217  
218 # As described in ->new, ATCP must be handled with kid gloves
219 if ($self->isa('Games::Axmud::Obj::Atcp')) {
220  
221 if ($jsonScalar =~ m/^[^\{\}\[\]\:]*$/) {
222  
223 $jsonScalar = '"' . $jsonScalar . '"';
224 }
225 }
226  
227 $newData = $axmud::CLIENT->decodeJson($jsonScalar);
228 $self->{data} = $self->update_scalar($newData, $self->{data});
229  
230 return 1;
231 }
232  
233 sub update_scalar {
234  
235 # Called by $self->update and by this function recursively
236 # Replaces the JSON data stored in $self->data with the new ATCP/GMCP package's data,
237 # merging embedded hashes but replacing embedded scalars and lists
238 #
239 # Expected arguments
240 # (none besides $self)
241 #
242 # Optional arguments
243 # $newScalar - A scalar (might be a list/hash reference, might be embedded within other
244 # list/hash references) from the recently-received ATCP/GMCP package's
245 # data. If 'undef', the scalar was (probably) a JSON null value
246 # $oldScalar - The corresponding scalar in the previously-received ATCP/GMCP package's
247 # data. If 'undef', the scalar was (probably) a JSON null value
248 #
249 # Return values
250 # 'undef' on improper arguments
251 # 1 otherwise
252  
253 my ($self, $newScalar, $oldScalar, $check) = @_;
254  
255 # Check for improper arguments
256 if (defined $check) {
257  
258 return $axmud::CLIENT->writeImproper($self->_objClass . '->update_scalar', @_);
259 }
260  
261 if (
262 defined $newScalar
263 && ref $newScalar eq 'HASH'
264 && defined $oldScalar
265 && ref $oldScalar eq 'HASH'
266 ) {
267 # (Merge the hashes, and return the combined hash
268 foreach my $key (keys %$newScalar) {
269  
270 if (! exists $$oldScalar{$key}) {
271  
272 $$oldScalar{$key} = $$newScalar{$key};
273  
274 } else {
275  
276 $$oldScalar{$key} = $self->update_scalar($$newScalar{$key}, $$oldScalar{$key});
277 }
278 }
279  
280 return $oldScalar;
281  
282 } else {
283  
284 # (Scalar or list reference replaces the old scalar or list reference)
285 return $newScalar;
286 }
287 }
288  
289 ##################
290 # Accessors - set
291  
292 ##################
293 # Accessors - get
294  
295 sub name
296 { $_[0]->{name} }
297 sub packageList
298 { my $self = shift; return @{$self->{packageList}}; }
299 sub msg
300 { $_[0]->{msg} }
301  
302 sub origData
303 { $_[0]->{origData} }
304 sub data
305 { $_[0]->{data} }
306 }
307  
308 { package Games::Axmud::Generic::Cage;
309  
310 use strict;
311 use warnings;
312 use diagnostics;
313  
314 use Glib qw(TRUE FALSE);
315  
316 our @ISA = qw(Games::Axmud);
317  
318 # All cages should inherit from this object
319 # The generic object, Games::Axmud, provides generic accessor functions for accessing scalar /
320 # array / hash instance variables, analogous to Perl's functions for non-instance variables
321 # This object replaces a few of those functions, allowing a cage to retrieve values from its own
322 # instance variables or, if they aren't set, find the value in its inferior cages
323 # The relationship between a cage and its inferior is set by the GA::Session's
324 # ->cageInferiorHash; a hash in the form
325 # ->inferiorCageHash{cage_name} = blessed_reference_to_inferior_cage
326 # ->inferiorCageHash{cage_name} = undef (if there is no inferior cage)
327 # If two sessions are connected to the same world, they will almost certainly have different
328 # current characters; both of those sessions will therefore have an identical ->cageHash,
329 # but a differnt ->inferiorCageHash
330 #
331 # Each of the functions can operate in two modes.
332 # Normally, a cage accesses instance variables from itself if possible, or the equivalent
333 # instance variables in the inferior cages, if necessary
334 # However, the functions can be made to behave like their equivalent functions in Games::Axmud
335 # if the calling GA::Session is omitted
336 #
337 # ->ivGet($instVar, $session)
338 # - Get a scalar IV from this cage (if the IV is set to 'undef', consult the cage's
339 # inferiors, using the first defined value found)
340 # ->ivGet($instVar)
341 # - Get a scalar IV (from this cage only)
342 #
343 # ->ivShow($instVar, $key, $session)
344 # - Retrieve the value matching $key in a hash IV (if the value is set to 'undef', consult
345 # the cage's inferiors, using the first defined value found)
346 # ->ivShow($instVar, $key)
347 # - Retrieve the value matching $key in a hash IV (from this cage only)
348  
349 ##################
350 # Constructors
351  
352 ##################
353 # Methods
354  
355 # IV accessor replacement methods
356  
357 sub ivGet {
358  
359 # Retrieve variable function for scalar instance variables
360 #
361 # Expected arguments
362 # $iv - Which scalar instance variable to get
363 #
364 # Optional arguments
365 # $session - If defined and if the IV is set to 'undef', consult the same IV in
366 # inferior cages. Otherwise, only this cage is consulted
367 #
368 # Return values
369 # 'undef' on failure (because $iv doesn't exist in this cage, or isn't a scalar, or
370 # improper arguments supplied)
371 #
372 # If the instance variable exists in this cage and is not set to 'undef', returns it
373 # If the instance variable exists in this cage but is set to 'undef',
374 # - if $session is not defined or if there is no inferior cage, returns the value of
375 # the IV in this cage ('undef')
376 # - if $session is defined and there is an inferior cage, passes the arguments to the
377 # ->ivGet function in the inferior cage, and returns the value the inferior cage
378 # returns. (The inferior cage calls its own inferior cage recursively, if
379 # necessary)
380  
381 my ($self, $iv, $session, $check) = @_;
382  
383 # Local variables
384 my ($refType, $inferior);
385  
386 # Check for improper arguments
387 if (! defined $iv || defined $check) {
388  
389 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivGet', @_);
390 }
391  
392 # Check that the variable exists at all
393 if (! exists $self->{$iv}) {
394  
395 return undef;
396 }
397  
398 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
399 # a scalar instance variable; so treat it as a scalar
400 $refType = ref $self->{$iv};
401 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
402  
403 # This is a scalar
404  
405 # Get the inferior cage (if any)
406 if ($session) {
407  
408 $inferior = $session->ivShow('inferiorCageHash', $self->name);
409 # If $session is defined but there is no inferior cage, we'll have to confine our
410 # search to this cage
411 if (! $inferior) {
412  
413 $session = undef;
414 }
415 }
416  
417 if ($session && ! defined $self->{$iv}) {
418  
419 # Consult the inferior cage
420 return $inferior->ivGet($iv, $session);
421  
422 } else {
423  
424 # Return this cage's value, even if it is 'undef'
425 return $self->{$iv};
426 }
427  
428 } else {
429  
430 # Not a scalar
431 return undef;
432 }
433 }
434  
435 sub ivShow {
436  
437 # Function to retrieve the value of a key-value pair in hash instance variables
438 #
439 # Expected arguments
440 # $iv - Which hash instance variable to test
441 # $key - Which key-value pair to retrieve
442 #
443 # Optional arguments
444 # $session - If defined and if the key's corresponding value is set to 'undef', consult
445 # the same IV in inferior cages. Otherwise, only this cage is consulted
446 #
447 # Return values
448 # 'undef' on failure (because $iv doesn't exist in this cage, or isn't a hash, or improper
449 # arguments supplied)
450 #
451 # If the instance variable exists in this cage, but the key of the key-value pair doesn't
452 # exist, returns 'undef'
453 # If the instance variable exists in this cage and the value of the key-value pair is not
454 # 'undef', returns the value
455 # If the instance variable exists in this cage but the value of the key-value pair is
456 # 'undef',
457 # - if $session is not defined or if there is no inferior cage, returns the value of
458 # the key-value pair in this cage ('undef')
459 # - if $session is defined and there is an inferior cage, passes the arguments to the
460 # ->ivShow function in the inferior cage, and returns the value the inferior cage
461 # returns. (The inferior cage calls its own inferior cage recursively, if
462 # necessary)
463  
464 my ($self, $iv, $key, $session, $check) = @_;
465  
466 # Local variables
467 my ($refType, $inferior);
468  
469 # Check for improper arguments
470 if (! defined $iv || ! defined $key || defined $check) {
471  
472 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivShow', @_);
473 }
474  
475 # Check the variable exists at all
476 if (! exists $self->{$iv}) {
477  
478 return undef;
479 }
480  
481 $refType = ref $self->{$iv};
482 if ($refType eq 'HASH') {
483  
484 # This is a hash
485  
486 # Get the inferior cage (if any)
487 if ($session) {
488  
489 $inferior = $session->ivShow('inferiorCageHash', $self->name);
490 # If $session is defined but there is no inferior cage, we'll have to confine our
491 # search to this cage
492 if (! $inferior) {
493  
494 $session = undef;
495 }
496 }
497  
498  
499 if (
500 $session
501 && (
502 ! exists $self->{$iv}{$key}
503 || ! defined $self->{$iv}{$key}
504 )
505 ) {
506 # Consult the inferior cage
507 return $inferior->ivShow($iv, $key, $session);
508  
509 } else {
510  
511 # Return this cage's value, even if it is 'undef'
512 return $self->{$iv}{$key};
513 }
514  
515 } else {
516  
517 # Not a hash
518 return undef;
519 }
520 }
521  
522 ##################
523 # Accessors - set
524  
525 ##################
526 # Accessors - get
527  
528 sub name
529 { $_[0]->{name} }
530 sub cageType
531 { $_[0]->{cageType} }
532 sub standardFlag
533 { $_[0]->{standardFlag} }
534 sub profName
535 { $_[0]->{profName} }
536 sub profCategory
537 { $_[0]->{profCategory} }
538 }
539  
540 { package Games::Axmud::Generic::CageMask;
541  
542 use strict;
543 use warnings;
544 use diagnostics;
545  
546 use Glib qw(TRUE FALSE);
547  
548 our @ISA = qw(Games::Axmud::Generic::Cage Games::Axmud);
549  
550 ##################
551 # Constructors
552  
553 sub new {
554  
555 # Create a new instance of the generic cage mask with default instance variables
556 #
557 # Expected arguments
558 # $session - The calling function's GA::Session (not stored as an IV)
559 # $profName - The parent profile's name (e.g. matches the object's ->name)
560 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
561 #
562 # Return values
563 # 'undef' on improper arguments or if the cage already seems to exist
564 # Blessed reference to the newly-created object on success
565  
566 my ($class, $session, $profName, $profCategory, $check) = @_;
567  
568 # Local variables
569 my ($cageType, $name);
570  
571 # Check for improper arguments
572 if (
573 ! defined $session || ! defined $profName || ! defined $profCategory || defined $check
574 ) {
575 return $axmud::CLIENT->writeImproper($class . '->new', @_);
576 }
577  
578 # When you write your own cage masks, give them a cage type (max 8 chars)
579 $cageType = 'genmask';
580 # Compose the cage's unique name
581 $name = $cageType . '_' . $profCategory . '_' . $profName;
582  
583 # Check that $name is valid and not already in use by another profile
584 if (! $axmud::CLIENT->nameCheck($name, 42)) {
585  
586 return $session->writeError(
587 'Registry naming error: invalid name \'' . $name . '\'',
588 $class . '->new',
589 );
590  
591 } elsif ($session->ivExists('cageHash', $name)) {
592  
593 return $session->writeError(
594 'Registry naming error: cage \'' . $name . '\' already exists',
595 $class . '->new',
596 );
597 }
598  
599 # Setup
600 my $self = {
601 _objName => $name,
602 _objClass => $class,
603 _parentFile => 'otherprof', # Set below for world profiles
604 _parentWorld => $session->currentWorld->name,
605 _privFlag => FALSE, # All IVs are public
606  
607 # Standard cage IVs
608 # -----------------
609  
610 name => $name,
611 cageType => $cageType,
612 standardFlag => FALSE, # This is a custom cage
613 profName => $profName,
614 profCategory => $profCategory,
615  
616 # Generic cage mask IVs
617 # ---------------------
618  
619 # These IVs are set by a call to $self->composeMask() (which should be modified for
620 # each cage mask you write), and applied to the task by a call to $self->applyMask()
621 # (which should not be modified)
622 #
623 # Hash of the task's IVs that can be changed using this mask (it's up to the calling
624 # code to ensure that the right cage mask is used with the right kind of task)
625 # Each key in the hash is set to the name of a single task IV, and the corresponding
626 # values contain a reference to a scalar, list or hash (NOT a normal scalar, list
627 # reference or hash reference). The task's IV is set to the de-referenced scalar, list
628 # or hash
629 # If the corresponding value is 'undef', lower-priority masks are consulted; the first
630 # one which returns something other than 'undef' is used to set the task's IV
631 # If all of the lower-priority masks also return 'undef', the task's IV is not changed
632 maskHash => {},
633 # A list of keys from $self->maskHash, in a fixed order
634 maskList => [],
635 };
636  
637 # Bless the object into existence
638 bless $self, $class;
639  
640 # Compose the mask, which sets the ->maskHash and ->maskList IVs
641 $self->composeMask();
642  
643 return $self;
644 }
645  
646 sub clone {
647  
648 # Creates a clone of an existing cage mask with 'undef' IVs
649 #
650 # Expected arguments
651 # $session - The calling function's GA::Session (not stored as an IV)
652 # $profName - The parent profile's name (e.g. matches the object's ->name)
653 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
654 #
655 # Return values
656 # 'undef' on improper arguments or if the cage already seems to exist
657 # Blessed reference to the newly-created object on success
658  
659 my ($self, $session, $profName, $profCategory, $check) = @_;
660  
661 # Local variables
662 my $name;
663  
664 # Check for improper arguments
665 if (
666 ! defined $session || ! defined $profName || ! defined $profCategory
667 || defined $check
668 ) {
669 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
670 }
671  
672 # Compose the cage's unique name
673 $name = $self->cageType . '_' . $profCategory . '_' . $profName;
674  
675 # Check that $name is valid and not already in use by another profile
676 if (! $axmud::CLIENT->nameCheck($name, 42)) {
677  
678 return $axmud::CLIENT->writeError(
679 'Registry naming error: invalid name \'' . $name . '\'',
680 $self->_objClass . '->clone',
681 );
682  
683 } elsif ($session->ivExists('cageHash', $name)) {
684  
685 return $axmud::CLIENT->writeError(
686 'Registry naming error: cage \'' . $name . '\' already exists',
687 $self->_objClass . '->clone',
688 );
689 }
690  
691 # List/hash instance variables
692 my (%originalHash, %copyHash);
693  
694 # Setup
695 my $clone = {
696 _objName => $name,
697 _objClass => $self->_objClass,
698 _parentFile => 'otherprof',
699 _parentWorld => undef,
700 _privFlag => FALSE, # All IVs are public
701  
702 # Standard cage IVs
703 # -----------------
704  
705 name => $name,
706 cageType => $self->cageType,
707 standardFlag => FALSE, # This is a custom cage
708 profName => $profName,
709 profCategory => $profCategory,
710  
711  
712 # Generic cage mask IVs
713 # ---------------------
714  
715 maskHash => {$self->maskHash},
716 maskList => [$self->maskList],
717 };
718  
719 # Bless the cloned object into existence
720 bless $clone, $self->_objClass;
721 return $clone;
722 }
723  
724 ##################
725 # Methods
726  
727 sub composeMask {
728  
729 # Called by $self->new
730 # Composes the mask by setting the IVs used to initialise the task
731 #
732 # Expected arguments
733 # (none besides $self)
734 #
735 # Return values
736 # 'undef' on improper arguments
737 # 1 otherwise
738  
739 my ($self, $check) = @_;
740  
741 # Local variables
742 my (
743 @list, @maskList,
744 %maskHash,
745 );
746  
747 # Check for improper arguments
748 if (defined $check) {
749  
750 return $axmud::CLIENT->writeImproper($self->_objClass . '->composeMask', @_);
751 }
752  
753 # Compose the mask
754 @list = (
755 # The generic cage mask doesn't apply to any particular task and doesn't initialise or
756 # reset any task IVs
757 # To write your own cage masks, fill in this list. The keys should be IVs in the task to
758 # be initialised or reset; the corresponding value should be 'undef'. The user is then
759 # free to change the 'undef' value to (a reference to) a scalar, list or hash for
760 # each copy of this cage mask, one for each current profile
761 # It's possible to use cage masks to set task settings, but for the most part only task
762 # parameters should be set
763 # A good idea is to list all of the task's parameter IVs here, and then to comment out
764 # any which aren't going to be initialised by the cage mask
765 # someScalar => undef,
766 # someList => undef,
767 # someHash => undef,
768 );
769  
770 # Compile @maskList and %maskHash
771 while (@list) {
772  
773 my ($key, $value);
774  
775 $key = shift @list;
776 $value = shift @list;
777  
778 $maskHash{$key} = $value;
779 push (@maskList, $key);
780 }
781  
782 # Update IVs
783 $self->{maskHash} = \%maskHash;
784 $self->{maskList} = \@maskList;
785  
786 return 1;
787 }
788  
789 sub applyMask {
790  
791 # Can be called by anything
792 # Applies the cage mask, changing some of the task's parameters, or none of them,
793 # depending on the contents of $self->maskHash
794 # A good idea is to write a task with an ->activate function, that calls this cage mask
795 # function to initialise the task's IVs
796 #
797 # Expected arguments
798 # $session - The calling function's GA::Session
799 # $taskObj - Blessed reference of the task object
800 #
801 # Return values
802 # 'undef' on improper arguments
803 # 1 otherwise
804  
805 my ($self, $session, $taskObj, $check) = @_;
806  
807 # Local variables
808 my ($ref, $refType);
809  
810 # Check for improper arguments
811 if (! defined $session || ! defined $taskObj || defined $check) {
812  
813 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyMask', @_);
814 }
815  
816 foreach my $iv ($self->ivKeys('maskHash')) {
817  
818 # Use $session as an argument to consult lower-priority masks, if necessary
819 $ref = $self->ivShow('maskHash', $iv, $session);
820  
821 if (defined $ref) {
822  
823 # Is it a reference to a scalar, list or hash?
824 $refType = ref $ref;
825  
826 # Set the task's IVs
827 if ($refType eq 'ARRAY') {
828 $taskObj->ivPoke($iv, @$ref);
829 } elsif ($refType eq 'HASH') {
830 $taskObj->ivPoke($iv, %$ref);
831 } else {
832 $taskObj->ivPoke($iv, $$ref);
833 }
834 }
835 }
836  
837 # Operation complete
838 return 1;
839 }
840  
841 ##################
842 # Accessors
843  
844 # These methods set/return the cage's ACTUAL mask hash. To get/set values from this hash
845 # hash AND/OR its inferiors, use the generic cage's ->ivXXX functions
846 sub maskHash
847 { my $self = shift; return %{$self->{maskHash}}; }
848 sub maskList
849 { my $self = shift; return @{$self->{maskList}}; }
850 }
851  
852 { package Games::Axmud::Generic::Cmd;
853  
854 use strict;
855 use warnings;
856 use diagnostics;
857  
858 use Glib qw(TRUE FALSE);
859  
860 our @ISA = qw(Games::Axmud);
861  
862 ##################
863 # Constructors
864  
865 sub new {
866  
867 # Prepare a new instance of the generic command, which contains all the code for a single
868 # client command
869 #
870 # Expected arguments
871 # $standardCmd - The standard form of the command (in lower-case, e.g. 'about')
872 # $builtInFlag - Flag set to TRUE if this is a built-in client command, FALSE if it has
873 # been added by a modification to Axmud's code
874 # $disconnectFlag - Flag set to TRUE if this command can be used after disconnecting from
875 # a world, FALSE otherwise
876 #
877 # Optional arguments
878 # $noBracketFlag - Flag set to TRUE if brackets (..) and diamond brackets <..> should
879 # be ignored when parsing the command into words
880 #
881 # Return values
882 # 'undef' on improper arguments
883 # Reference to hash on success, which is blessed into existence by the calling function
884  
885 my ($class, $standardCmd, $builtInFlag, $disconnectFlag, $noBracketFlag, $check) = @_;
886  
887 # Check for improper arguments
888 if (
889 ! defined $class || ! defined $standardCmd || ! defined $builtInFlag
890 || ! defined $disconnectFlag || defined $check
891 ) {
892 return $axmud::CLIENT->writeImproper($class . '->new', @_);
893 }
894  
895 # Check that a command object with the same name hasn't already been created (this catches
896 # commands with duplicate names)
897 # (Must use $axmud::CLIENT-> rather than $session->, because client commands are session
898 # -independent)
899 # NB For client commands loaded from a plugin, whose $class is GA::Generic::Plugin::Cmd,
900 # we don't perform this check. If the new command has the same standard name as an
901 # existing one, the existing command is replaced
902 if (! $class =~ m/plugin/) {
903  
904 if ($axmud::CLIENT->ivExists('clientCmdHash', $standardCmd)) {
905  
906 return $axmud::CLIENT->writeError(
907 'Duplicate client command \'' . $standardCmd . '\'',
908 $class . '->new',
909 );
910 }
911 }
912  
913 # Check that the command name isn't longer than 32 characters
914 if (length ($standardCmd) > 32) {
915  
916 return $axmud::CLIENT->writeError(
917 'Client command \'' . $standardCmd . '\' is too long',
918 $class . '->new',
919 );
920 }
921  
922 # $noBracketFlag must be either TRUE or FALSE
923 if ($noBracketFlag) {
924 $noBracketFlag = TRUE;
925 } else {
926 $noBracketFlag = FALSE;
927 }
928  
929 # Setup
930 my $self = {
931 _objName => 'generic_cmd',
932 _parentFile => undef, # No parent file
933 _parentWorld => undef, # No parent file
934 _objClass => $class,
935 _privFlag => TRUE, # All IVs are private
936  
937 # Other IVs
938 # ---------
939  
940 # The standard form of the command (in lower-case, e.g. 'about')
941 standardCmd => $standardCmd,
942  
943 # Default list of user commands (user-defined abbreviations for this command)
944 defaultUserCmdList => [],
945 # Current list of user commands (for this command)
946 userCmdList => [],
947  
948 # A short description of the command
949 descrip => undef,
950 # Flag set to TRUE if this is a built-in client command, FALSE if it has been added by
951 # someone else's modifications to the Axmud code
952 builtInFlag => $builtInFlag,
953 # Flag set to TRUE if this command can be used after disconnecting from a world, FALSE
954 # otherwise
955 disconnectFlag => $disconnectFlag,
956 # Flag set to TRUE if brackets (..) and diamond brackets <..> should be ignored when
957 # parsing the command into words
958 noBracketFlag => $noBracketFlag,
959  
960 };
961  
962 # (The object is blessed into existence by the calling function)
963 return $self;
964 }
965  
966 ##################
967 # Methods
968  
969 sub do {
970  
971 # The generic command's ->do method should never be called. Returns 'undef'
972  
973 my ($self) = @_;
974  
975 return $axmud::CLIENT->writeError(
976 'Forbidden call to generic command object\'s own ->do method',
977 $self->_objClass . '->do',
978 );
979 }
980  
981 sub xyzzy {
982  
983 # Called by GA::Session->clientCmd
984 # Special arrangements for experienced spelunkers
985 #
986 # Expected arguments
987 # $session - The calling function's GA::Session
988 #
989 # Return value
990 # 'undef' on improper arguments
991 # 1 otherwise
992  
993 my ($self, $session, $check) = @_;
994  
995 # Local variables
996 my (
997 $mode,
998 @list,
999 );
1000  
1001 # Check for improper arguments
1002 if (! defined $session || defined $check) {
1003  
1004 return $axmud::CLIENT->writeImproper($self->_objClass . '->xyzzy', @_);
1005 }
1006  
1007 @list = (
1008 'Nothing happens.',
1009 'Almost nothing happens.',
1010 'Virtually nothing happens.',
1011 'Practically nothing happens.',
1012 'Very little is happening.',
1013 'Barely anything is happening.',
1014 'Nothing is happening, but something might start happening soon.',
1015 'Something is beginning to happen.',
1016 'Something is happening, no doubt about it.',
1017 'IT\'S HAPPENING!',
1018 'WHY DIDN\'T YOU STOP IT?',
1019 'YOU ONLY HAD TO LISTEN!',
1020 );
1021  
1022 $mode = $session->spelunkerMode;
1023  
1024 if ($mode < 9) {
1025 $session->writeText($list[$mode]);
1026 } elsif ($mode == 9) {
1027 $session->writeText($list[$mode], 'RED', 'ul_white', 'blink_fast');
1028 } elsif ($mode == 10) {
1029 $session->writeText($list[$mode], 'white', 'UL_RED', 'blink_fast');
1030 } else {
1031 $session->writeText($list[$mode], 'RED', 'ul_white', 'blink_slow');
1032 }
1033  
1034 $mode++;
1035 if ($mode > 11) {
1036  
1037 $mode = 0;
1038 }
1039  
1040 $session->set_spelunkerMode($mode);
1041  
1042 return 1;
1043 }
1044  
1045 # Methods
1046  
1047 sub extract {
1048  
1049 # Usually called by $self->do
1050 # Extracts a switch (and its arguments, if any) from a client command
1051 #
1052 # The calling function should make a call like this:
1053 # ($switch, $arg1, $arg2, @inputWord) = $self->extract('e', 2, @inputWord);
1054 # This function removes the switch and its arguments from @inputWord - no matter where in
1055 # the list they occur - and makes the switch and its arguments available in the return
1056 # variables $switch, $arg1 and $arg2.
1057 # @inputWord is returned with the switch and its arguments removed, ready for more calls
1058 # to this function, in order to remove other switches (and their arguments)
1059 # If the switch has no arguments, the call should look like this:
1060 # ($switch, @inputWord) = $self->extract('e', 0 @inputWord);
1061 #
1062 # In client commands, switches are a word containing a hyphen followed by one or more
1063 # letters, e.g. -e, -s, -a, -name, etc
1064 #
1065 # Examples
1066 # e.g. $switch = 'w', $numberArgs = 2,
1067 # Original command: 'command arg1 -w arg2 arg3 arg4'
1068 # @inputWord = ('command', 'arg1', '-w', 'arg2', 'arg3', 'arg4')
1069 # @returnArray = ('w', 'arg2', 'arg3', 'command', 'arg1', 'arg4')
1070 #
1071 # e.g. $switch = 'w', $numberArgs = 2,
1072 # Original command: 'command arg1 -w arg2 -e arg3 arg4'
1073 # @inputWord = ('command', 'arg1', '-w', 'arg2', '-e', 'arg3', 'arg4')
1074 # @returnArray = ('w', 'arg2', '', 'command', 'arg1', '-e', 'arg3', 'arg4')
1075 # (The switch -w gets exactly two arguments, regardless of how many were actually typed by
1076 # the user)
1077 #
1078 # e.g. $switch = 'x', $numberArgs = 2,
1079 # Original command: 'command arg1 -w arg2 -e arg3 arg4'
1080 # @inputWord = ('command', 'arg1', '-w', 'arg2', '-e', 'arg3', 'arg4')
1081 # @returnArray = (undef, '', '', @inputWord)
1082 # (If the supplied switch -x doesn't exist in @inputWord, the first element of
1083 # @returnArray is set to undef; that is followed by empty strings for the specified number
1084 # of arguments (as usual), and finally @inputWord unaltered)
1085 #
1086 # Expected arguments
1087 # $switch - the switch to extract, e.g. 'f' or 'z', or even 'foobar' ($switch can
1088 # begin with a hyphen, as the user would type it; or the hyphen can be
1089 # omitted, so '-f' and 'f' are equivalent). Besides the optional initial
1090 # hyphen, $switch must contain only letters (a-z, A-Z)
1091 # $numberArgs - the number of words (or groups of words) which belong to the switch. Set
1092 # to 0 if the switch has no arguments
1093 # @inputWord - a list of words (or groups of words) from which the switch and its
1094 # arguments should be extracted
1095 #
1096 # Return values
1097 # Returns an empty list on improper arguments
1098 #
1099 # Otherwise, @returnArray is now in the form
1100 # ($switch, 'arg1', 'arg2', ... , 'argN')
1101 # If the switch did prepend enough arguments, the missing arguments are returned as
1102 # 'undef'
1103 # e.g. for the call $self->extract('e', 2, @inputWord);
1104 # if $inputString is 'command -w arg1 -e arg2',
1105 # @returnArray = ($switch, 'arg1', undef);
1106 # If the $switch doesn't exist in @inputWord, @returnArray is an empty list
1107 #
1108 # Returns @returnArray followed by anything left in @inputWord as a single list
1109 # e.g. for the call $self->extract('e', 2, @inputWord);
1110 # if $inputString is 'command -w arg1 -e arg2',
1111 # the return list is ($switch, 'arg1', undef, '-e', 'arg1')
1112  
1113 my ($self, $switch, $numberArgs, @inputWord) = @_;
1114  
1115 # Local variables
1116 my (
1117 $count, $match, $failFlag,
1118 @emptyList, @returnArray,
1119 );
1120  
1121 # Check for improper arguments
1122 if (! defined $switch || ! defined $numberArgs) {
1123  
1124 $axmud::CLIENT->writeImproper($self->_objClass . '->extract', @_);
1125 return @emptyList;
1126 }
1127  
1128 # If $switch doesn't begin with a hyphen (the default situation), add one
1129 if ((substr $switch, 0, 1) ne '-') {
1130  
1131 $switch = '-' . $switch;
1132 }
1133  
1134 # $switch must now be a single hyphen, followed by one or more letters
1135 if (! ($switch =~ m/^\-[a-zA-Z]+$/)) {
1136  
1137 # Invalid switch. @returnArray should be filled with 'undef' values
1138 # i.e. return ($switch, $arg1, $arg2, @inputWord)
1139 # >>> return (undef, undef, undef, @inputWord)
1140 push @returnArray, undef;
1141 if ($numberArgs) {
1142  
1143 for (my $a = 0; $a < $numberArgs; $a++) {
1144  
1145 push (@returnArray, undef);
1146 }
1147 }
1148  
1149 return (@returnArray, @inputWord);
1150 }
1151  
1152 # Find out which array index contains the switch
1153 $count = -1;
1154 $match = -1;
1155 OUTER: foreach my $word (@inputWord) {
1156  
1157 $count++;
1158 if ($word eq $switch) {
1159  
1160 $match = $count;
1161 last OUTER;
1162 }
1163 }
1164  
1165 if ($match == -1) {
1166  
1167 # Switch doesn't exist. @returnArray should be filled with 'undef' values
1168 # i.e. return ($switch, $arg1, $arg2, @inputWord)
1169 # >>> return (undef, undef, undef, @inputWord)
1170 push @returnArray, undef;
1171 if ($numberArgs) {
1172  
1173 for (my $a = 0; $a < $numberArgs; $a++) {
1174  
1175 push (@returnArray, undef);
1176 }
1177 }
1178  
1179 return (@returnArray, @inputWord);
1180 };
1181  
1182 # Remove the switch from @inputWord
1183 @returnArray = splice (@inputWord, $match, 1);
1184  
1185 # If the switch has arguments, separate them, too
1186 if ($numberArgs > 0) {
1187  
1188 for (my $a = 0; $a < $numberArgs; $a++) {
1189  
1190 my $word = $inputWord[$match];
1191  
1192 # Switch begins with a hyphen, followed by one or more letters
1193 if (! $failFlag && defined $word && ! ($word =~ m/^\-[a-zA-Z]+$/)) {
1194  
1195 # Not a switch
1196 push (@returnArray, splice (@inputWord, $match, 1));
1197  
1198 } else {
1199  
1200 # It's a switch, or we found a switch on a previous iteration of the 'for' loop
1201 push (@returnArray, undef);
1202 # Don't check any more words, just add 'undef' to @returnArray for each
1203 # remaining iteration of the 'for' loop
1204 $failFlag = TRUE;
1205 }
1206 }
1207 }
1208  
1209 # Return the data in the format described above
1210 return (@returnArray, @inputWord);
1211 }
1212  
1213 sub composeHelpLine {
1214  
1215 # Usually called by GA::Cmd::Help->do and SearchHelp->do
1216 # Composes a line of text for the standard form of a client command, showing the shortest
1217 # corresponding user command, the standard form command, and a short description of the
1218 # client command
1219 #
1220 # Expected arguments
1221 # $session - The calling function's GA::Session
1222 # $standardCmd - The command about which to show help, e.g. 'about'
1223 #
1224 # Optional arguments
1225 # $disconnectFlag - If TRUE, adds an asterisk for commands which are available while the
1226 # the GA::Session's status is 'disconnected'. If FALSE (or 'undef'),
1227 # the asterisk is never added
1228 #
1229 # Return values
1230 # 'undef' on improper arguments or if $standardCmd isn't recognised
1231 # Otherwise, a string in the format:
1232 # ' ab / about Shows information about Axmud'
1233  
1234 my ($self, $session, $standardCmd, $disconnectFlag, $check) = @_;
1235  
1236 # Local variables
1237 my ($obj, $column, $string);
1238  
1239 # Check for improper arguments
1240 if (! defined $session || ! defined $standardCmd || defined $check) {
1241  
1242 return $axmud::CLIENT->writeImproper($self->_objClass . '->composeHelpLine', @_);
1243 }
1244  
1245 # Check the specified command exists
1246 if (! $axmud::CLIENT->ivExists('clientCmdHash', $standardCmd)) {
1247  
1248 return $session->writeError(
1249 'Could not find a client command whose standard form matches \'' . $standardCmd
1250 . '\'',
1251 $self->_objClass . '->composeHelpLine',
1252 );
1253  
1254 } else {
1255  
1256 $obj = $axmud::CLIENT->ivShow('clientCmdHash', $standardCmd);
1257  
1258 if ($disconnectFlag && $obj->disconnectFlag) {
1259 $column = ' * ';
1260 } else {
1261 $column = ' ';
1262 }
1263  
1264 # Compose the string and return it
1265 $string = $column . sprintf('%-30.30s', $obj->findShortestCmd() . ' / ' . $standardCmd)
1266 . $obj->descrip();
1267  
1268 return $string;
1269 }
1270 }
1271  
1272 sub composeBlindHelpLine {
1273  
1274 # Called by GA::Cmd::Help->do
1275 # A version of $self->composeHelpLine for use when blind mode is on
1276 # Composes a simpler line of text for a client command, showing the standard form command
1277 # and a short description only
1278 #
1279 # Expected arguments
1280 # $session - The calling function's GA::Session
1281 # $standardCmd - The command about which to show help, e.g. 'about'
1282 #
1283 # Return values
1284 # 'undef' on improper arguments or if $standardCmd isn't recognised
1285 # Otherwise, a string in the format:
1286 # ' about : Shows information about Axmud'
1287  
1288 my ($self, $session, $standardCmd, $check) = @_;
1289  
1290 # Local variables
1291 my ($obj, $column, $string);
1292  
1293 # Check for improper arguments
1294 if (! defined $session || ! defined $standardCmd || defined $check) {
1295  
1296 return $axmud::CLIENT->writeImproper($self->_objClass . '->composeBlindHelpLine', @_);
1297 }
1298  
1299 # Check the specified command exists
1300 if (! $axmud::CLIENT->ivExists('clientCmdHash', $standardCmd)) {
1301  
1302 return $session->writeError(
1303 'Could not find a client command whose standard form matches \'' . $standardCmd
1304 . '\'',
1305 $self->_objClass . '->composeHelpLine',
1306 );
1307  
1308 } else {
1309  
1310 $obj = $axmud::CLIENT->ivShow('clientCmdHash', $standardCmd);
1311  
1312 return ' ' . $standardCmd . ' : ' . $obj->descrip();
1313 }
1314 }
1315  
1316 sub findShortestCmd {
1317  
1318 # Called by many command's ->do / ->help functions, e.g. GA::Cmd::About->help, etc
1319 # Also called by GA::Generic::Cmd->composeHelpLine
1320 # Returns the shortest possible user command for this command object (e.g. for the
1321 # ';setworld' command, returns 'sw')
1322 #
1323 # Expected arguments
1324 # (none besides $self)
1325 #
1326 # Return values
1327 # 'undef' on improper arguments or if there are no user commands in $self->userCmdList
1328 # (unlikeley)
1329 # Otherwise returns the shortest user command
1330  
1331 my ($self, $check) = @_;
1332  
1333 # Local variables
1334 my $shortestCmd;
1335  
1336 # Check for improper arguments
1337 if (defined $check) {
1338  
1339 return $axmud::CLIENT->writeImproper($self->_objClass . '->findShortestCommand', @_);
1340 }
1341  
1342 # Go through the user command list, looking for the shortest user command
1343 foreach my $cmd ($self->userCmdList) {
1344  
1345 if (! defined $shortestCmd || (length $cmd) < (length $shortestCmd)) {
1346  
1347 $shortestCmd = $cmd;
1348 }
1349 }
1350  
1351 # Return the shortest user command found - return 'undef' if none were found
1352 return $shortestCmd;
1353 }
1354  
1355 sub getSortedUserCmds {
1356  
1357 # Usually called by GA::Cmd::Help->do; also by $self->getHelpEnd
1358 # Gets all the user commands for this standard command, sorts them in ascending order of
1359 # length, and returns the sorted list
1360 # e.g. for the ';listwindow' command, returns the list
1361 # ('lw', 'listwin', 'listwindow')
1362 #
1363 # Expected arguments
1364 # (none besides $self)
1365 #
1366 # Return values
1367 # An empty list on improper arguments or if there are no user commands in
1368 # $self->userCmdList (unlikely)
1369 # Otherwise returns the sorted list
1370  
1371 my ($self, $check) = @_;
1372  
1373 # Local variables
1374 my (@list, @emptyList);
1375  
1376 # Check for improper arguments
1377 if (defined $check) {
1378  
1379 $axmud::CLIENT->writeImproper($self->_objClass . '->getSortedUserCmds', @_);
1380 return @emptyList;
1381 }
1382  
1383 @list = sort {length($a) <=> length($b)} $self->userCmdList;
1384 return @list;
1385 }
1386  
1387 sub convertTrueFalse {
1388  
1389 # Usually called by $self->do
1390 # Converts a specified value, $value, into the Boolean values TRUE or FALSE
1391 # The values 1, TRUE and any word beginning with 't' or 'T' are converted into TRUE
1392 # The values 0, FALSE and any word beginning with 'f' or 'F' are converted into FALSE
1393 #
1394 # Expected arguments
1395 # $value - a value to be converted
1396 #
1397 # Return values
1398 # 'undef' on improper arguments or if if $value isn't a recognisable Boolean value (e.g.
1399 # 'hello')
1400 # Otherwise returns either TRUE or FALSE
1401  
1402 my ($self, $value, $check) = @_;
1403  
1404 # Check for improper arguments
1405 if (! defined $value || defined $check) {
1406  
1407 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertTrueFalse', @_);
1408 }
1409  
1410 # Check for Boolean values
1411 if ($value eq '1' || $value =~ m/^t/i || $value eq TRUE) {
1412  
1413 return TRUE;
1414  
1415 } elsif ($value eq '0' || $value =~ m/^f/i || $value eq FALSE) {
1416  
1417 return FALSE;
1418  
1419 } else {
1420  
1421 # Not a recognisable Boolean value
1422 return undef;
1423 }
1424 }
1425  
1426 sub convertArrayTrueFalse {
1427  
1428 # Usually called by $self->do
1429 # Converts a list of values, @list, into a list of the Boolean values TRUE or FALSE
1430 # (anything which is not a recognisable Boolean value is not modified)
1431 # The values 1, TRUE and any word beginning with 't' or 'T' are converted into TRUE
1432 # The values 0, FALSE and any word beginning with 'f' or 'F' are converted into FALSE
1433 #
1434 # Expected arguments
1435 # @list - the array to be checked
1436 #
1437 # Return values
1438 # An empty list on improper arguments, or if the specified @list is empty
1439 # Otherwise returns the modified array, @returnArray
1440  
1441 my ($self, @list) = @_;
1442  
1443 # Local variables
1444 my @returnArray;
1445  
1446 # (No improper arguments to check)
1447  
1448 foreach my $value (@list) {
1449  
1450 if ($value eq '1' || $value =~ m/^t/i || $value eq TRUE) {
1451  
1452 push (@returnArray, TRUE);
1453  
1454 } elsif ($value eq '0' || $value =~ m/^f/i || $value eq FALSE) {
1455  
1456 push (@returnArray, FALSE);
1457  
1458 } else {
1459  
1460 # Not a recognisable Boolean value
1461 push (@returnArray, $value);
1462 }
1463 }
1464  
1465 return @returnArray;
1466 }
1467  
1468 sub reverseHash {
1469  
1470 # Reverses a hash without losing keys belonging to non-unique values, since each new 'value'
1471 # is a string containing all the original 'keys', separated by spaces
1472 # Designed for Axmud commands like ';listtasklabel', when all the information in a hash
1473 # needs to be displayed in a comprehensible way
1474 #
1475 # e.g. When passed a hash like this...
1476 # KEY VALUE
1477 # 'fred' 'man'
1478 # 'wilma' 'woman'
1479 # 'barney' 'man'
1480 # 'betty' 'woman'
1481 # 'tony' 'man'
1482 # ...the function returns a hash that looks like this
1483 # KEY VALUE
1484 # 'man' 'fred barney tony'
1485 # 'woman' 'wilma betty'
1486 #
1487 # Expected arguments
1488 # %hash - The hash to reverse
1489 #
1490 # Return values
1491 # %returnHash - The reversed hash
1492  
1493 my ($self, %hash) = @_;
1494  
1495 # Local variables
1496 my (
1497 $count,
1498 @keyList, @valueList,
1499 %returnHash,
1500 );
1501  
1502 # No improper arguments to check (if %hash is empty, so is %returnHash)
1503  
1504 # Convert the original %hash into flat lists of keys and values
1505 @keyList = keys (%hash);
1506 @valueList = values (%hash);
1507  
1508 for ($count = 0; $count < scalar @keyList; $count++) {
1509  
1510 my $returnValue;
1511  
1512 # For each key in @keyList, see if the corresponding value already exists as a key in
1513 # %returnHash
1514 if (exists $returnHash{$valueList[$count]} ){
1515  
1516 # Tasklement the exiting key-value pair in %returnHash
1517 $returnValue = $returnHash{$valueList[$count]};
1518 $returnHash{$valueList[$count]} = $returnValue . ' ' . $keyList[$count];
1519  
1520 } else {
1521  
1522 # Create a new key-value pair in %returnHash
1523 $returnHash{$valueList[$count]} = $keyList[$count];
1524 }
1525 }
1526  
1527 return %returnHash;
1528 }
1529  
1530 # Methods called at end of $self->do
1531  
1532 sub complete {
1533  
1534 # Called by $self->do
1535 # Writes a standard message for when a command has achieved a successful result (unless
1536 # command messages have been suppressed)
1537 #
1538 # Expected arguments
1539 # $session - The calling function's GA::Session
1540 # $standardCmd - the standard form of the client command
1541 # $msg - a message describing the successful operation
1542 #
1543 # Return values
1544 # 'undef' on improper arguments
1545 # 1 otherwise
1546  
1547 my ($self, $session, $standardCmd, $msg, $check) = @_;
1548  
1549 # Local variables
1550 my $string;
1551  
1552 # Check for improper arguments
1553 if (! defined $session || ! defined $standardCmd || ! defined $msg || defined $check) {
1554  
1555 return $axmud::CLIENT->writeImproper($self->_objClass . '->complete', @_);
1556 }
1557  
1558 if ($session->cmdMode eq 'show_all' || $session->cmdMode eq 'win_error') {
1559  
1560 # In blind mode, say 'client command', otherwise, save space on the line by displaying
1561 # just 'client'
1562 if ($axmud::BLIND_MODE_FLAG) {
1563 $string = 'Client command \'';
1564 } else {
1565 $string = 'Client \'';
1566 }
1567  
1568 return $session->writeText(
1569 $string . $axmud::CLIENT->constClientSigil . $standardCmd . '\' : ' . $msg,
1570 );
1571  
1572 } else {
1573  
1574 # Command messages have been suppressed
1575 return 1;
1576 }
1577 }
1578  
1579 sub error {
1580  
1581 # Called by $self->do
1582 # Writes a standard message for when a command fails to complete the intended operation
1583 # (unless command error messages have been suppressed)
1584 #
1585 # Expected arguments
1586 # $session - The calling function's GA::Session
1587 # $inputString - A string containing the whole client command, e.g. 'setworld deathmud'
1588 # $msg - a message describing the failed operation
1589 #
1590 # Return values
1591 # 'undef'
1592  
1593 my ($self, $session, $inputString, $msg, $check) = @_;
1594  
1595 # Local variables
1596 my $standard;
1597  
1598 # Check for improper arguments
1599 if (! defined $session || ! defined $inputString || ! defined $msg || defined $check) {
1600  
1601 return $axmud::CLIENT->writeImproper($self->_objClass . '->error', @_);
1602 }
1603  
1604 if ($session->cmdMode eq 'show_all' || $session->cmdMode eq 'hide_complete') {
1605  
1606 # Remove any leading/trailing whitespace, in case the user typed something like
1607 # '; addchar'
1608 $inputString = $axmud::CLIENT->trimWhitespace($inputString);
1609 # Modify $inputString to replace a user command (e.g. 'ach') with the standard
1610 # command (e.g. 'addchar')
1611 $standard = $self->standardCmd;
1612 $inputString =~ s/^\w+/$standard/i;
1613  
1614 # Display the error. (Deliberately don't add the name of this function as the second
1615 # argument, to make the line less cluttered)
1616 return $session->writeError(
1617 '\'' . $axmud::CLIENT->constClientSigil . $inputString . '\' : ' . $msg,
1618 );
1619  
1620 } elsif ($session->cmdMode eq 'hide_system') {
1621  
1622 # Command error messages have been suppressed
1623 return undef;
1624  
1625 } elsif ($session->cmdMode eq 'win_error' || $session->cmdMode eq 'win_only') {
1626  
1627 # Show the error message in a 'dialogue' window
1628 $session->mainWin->showMsgDialogue(
1629 '\'' . $axmud::CLIENT->constClientSigil . $self->standardCmd . '\' error',
1630 'error',
1631 $msg,
1632 'ok',
1633 );
1634  
1635 return undef;
1636 }
1637 }
1638  
1639 sub improper {
1640  
1641 # Called by $self->do
1642 # Writes a standard message for when a command is supplied with a list of arguments that
1643 # isn't allowed (unless command error messages have been suppressed)
1644 #
1645 # Expected arguments
1646 # $session - The calling function's GA::Session
1647 # $inputString - A string containing the whole client command, e.g. 'setworld deathmud'
1648 # (not including the client command sigil)
1649 #
1650 # Return values
1651 # 'undef'
1652  
1653 my ($self, $session, $inputString, $check) = @_;
1654  
1655 # Local variables
1656 my (
1657 $standardCmd,
1658 @list,
1659 );
1660  
1661 # Check for improper arguments
1662 if (! defined $session || ! defined $inputString || defined $check) {
1663  
1664 return $axmud::CLIENT->writeImproper($self->_objClass . '->improper', @_);
1665 }
1666  
1667 if ($session->cmdMode eq 'show_all' || $session->cmdMode eq 'hide_complete') {
1668  
1669 # Remove any leading/trailing whitespace, in case the user typed something like
1670 # '; addchar'
1671 $inputString = $axmud::CLIENT->trimWhitespace($inputString);
1672  
1673 # Extract the actual user command typed (the first word in $inputString)
1674 @list = split(/ /, $inputString);
1675 $standardCmd = $axmud::CLIENT->ivShow('userCmdHash', $list[0]);
1676  
1677 # Display the error. (Deliberately don't add the name of this function as the second
1678 # argument, to make the line less cluttered)
1679 if (defined $standardCmd) {
1680  
1681 return $session->writeError(
1682 'Bad or missing arguments in \';' . $inputString . '\' - try \';help '
1683 . $standardCmd . '\'',
1684 );
1685  
1686 } elsif (
1687 $axmud::CLIENT->ivExists('constPrimaryDirList', $list[0])
1688 || defined $session->currentDict->checkPrimaryDir($list[0])
1689 ) {
1690 return $session->writeError(
1691 'Bad or missing arguments in \';' . $inputString . '\' - try'
1692 . ' \';help allocateexit\'',
1693 );
1694  
1695 } else {
1696  
1697 return $session->writeError(
1698 'Bad or missing arguments in \';' . $inputString . '\' - try \';help\'',
1699 );
1700 }
1701  
1702 } elsif ($session->cmdMode eq 'hide_system') {
1703  
1704 # Command error messages have been suppressed
1705 return undef;
1706  
1707 } elsif ($session->cmdMode eq 'win_error' || $session->cmdMode eq 'win_only') {
1708  
1709 # Show the error message in a 'dialogue' window
1710 $session->mainWin->showMsgDialogue(
1711 'Client command error',
1712 'error',
1713 'Bad or missing arguments in the client command: ' . $inputString,
1714 'ok',
1715 );
1716  
1717 return undef;
1718 }
1719 }
1720  
1721 # Methods inherited by more than one client command
1722  
1723 sub help {
1724  
1725 # Usually called by GA::Cmd::Help->do or GA::Cmd::HelpTest->do
1726 # Reads a data file corresponding to a specified client command. Returns each line from the
1727 # file as a list of strings
1728 # First looks in /help/cmd, then in /plugins/help/cmd, then in /private/help/cmd (which
1729 # doesn't exist in public releases of Axmud), then in the data directory's
1730 # /plugins/help/cmd
1731 #
1732 # Expected arguments
1733 # $session - The calling function's GA::Session
1734 #
1735 # Optional arguments
1736 # $literalFlag - Set to TRUE when called by GA::Cmd::HelpTest->do; does not discard any
1737 # lines from the beginning/end of the file (otherwise set to FALSE or
1738 # 'undef')
1739 # $noPluginFlag - Set to TRUE if we should only look in the usual help directory for
1740 # the help file. If FALSE (or 'undef'), look in the plugin help
1741 # directories as well
1742 #
1743 # Return values
1744 # An empty list on improper arguments, if the file doesn't exist or if it can't be read
1745 # Otherwise, returns the contents of the file as a list of strings
1746  
1747 my ($self, $session, $literalFlag, $noPluginFlag, $check) = @_;
1748  
1749 # Local variables
1750 my (
1751 $file, $fileHandle,
1752 @list, @emptyList,
1753 );
1754  
1755 # Check for improper arguments
1756 if (! defined $session || defined $check) {
1757  
1758 $axmud::CLIENT->writeImproper($self->_objClass . '->help', @_);
1759 return @emptyList;
1760 }
1761  
1762 # Check the file exists
1763 if ($noPluginFlag) {
1764  
1765 $file = $axmud::SHARE_DIR . '/help/cmd/' . $self->standardCmd;
1766  
1767 } else {
1768  
1769 $file = $axmud::DATA_DIR . '/plugins/help/cmd/' . $self->standardCmd;
1770 if (! (-e $file)) {
1771  
1772 $file = $axmud::SHARE_DIR . '/plugins/help/cmd/' . $self->standardCmd;
1773 if (! (-e $file)) {
1774  
1775 $file = $axmud::SHARE_DIR . '/private/help/cmd/' . $self->standardCmd;
1776 if (! (-e $file)) {
1777  
1778 $file = $axmud::SHARE_DIR . '/help/cmd/' . $self->standardCmd;
1779  
1780 }
1781 }
1782 }
1783 }
1784  
1785 if (! (-e $file)) {
1786  
1787 $session->writeError(
1788 'Can\'t find help file for client command \'' . $self->standardCmd
1789 . '\'',
1790 $self->_objClass . '->help',
1791 );
1792  
1793 return @emptyList;
1794 }
1795  
1796 # Open the file for reading
1797 if (! open ($fileHandle, "<$file")) {
1798  
1799 $session->writeError(
1800 'Failed to open file for client command \'' . $self->standardCmd
1801 . '\'',
1802 $self->_objClass . '->help',
1803 );
1804  
1805 return @emptyList;
1806 }
1807  
1808 # Read the file
1809 while (1) {
1810  
1811 my $line = <$fileHandle>;
1812  
1813 if (! defined $line) {
1814  
1815 # File can't be read, or end of file
1816  
1817 if (! $literalFlag) {
1818  
1819 # The next three lines of the file should contain the same text that's produced
1820 # by $self->getHelpStart, and the last three lines contains text produced by
1821 # $self->getHelpEnd, so we can ignore them
1822 shift @list; shift @list; shift @list;
1823 pop @list; pop @list; pop @list;
1824 }
1825  
1826 # Return the edited contents of the file
1827 return @list
1828  
1829 } else {
1830  
1831 chomp $line;
1832 push (@list, $line);
1833 }
1834 }
1835 }
1836  
1837 sub helpExists {
1838  
1839 # Usually called by GA::Cmd::HelpTest->do
1840 # Checks whether the data file corresponding to a specified client command exists, or not
1841 #
1842 # Expected arguments
1843 # $standardCmd - The standard form of the client command to check
1844 #
1845 # Return values
1846 # 'undef' on improper arguments or if the file doesn't exist
1847 # 1 if the file does exist
1848  
1849 my ($self, $standardCmd, $check) = @_;
1850  
1851 # Local variables
1852 my $file;
1853  
1854 # Check for improper arguments
1855 if (! defined $standardCmd || defined $check) {
1856  
1857 return $axmud::CLIENT->writeImproper($self->_objClass . '->helpExists', @_);
1858 }
1859  
1860 # Check the file exists
1861 $file = $axmud::DATA_DIR . '/plugins/help/cmd/' . $standardCmd;
1862 if (! (-e $file)) {
1863  
1864 $file = $axmud::SHARE_DIR . '/plugins/help/cmd/' . $standardCmd;
1865 if (! (-e $file)) {
1866  
1867 $file = $axmud::SHARE_DIR . '/private/help/cmd/' . $standardCmd;
1868 if (! (-e $file)) {
1869  
1870 $file = $axmud::SHARE_DIR . '/help/cmd/' . $standardCmd;
1871 }
1872 }
1873 }
1874  
1875 if (! (-e $file)) {
1876 return undef;
1877 } else {
1878 return 1;
1879 }
1880 }
1881  
1882 sub listHelpFiles{
1883  
1884 # Usually called by GA::Cmd::HelpTest->do
1885 # Gets a list of help files, ignoring any duplicates
1886 #
1887 # Expected arguments
1888 # (none besides $self)
1889 #
1890 # Return values
1891 # An empty list on improper arguments
1892 # Otherwise returns a list of help file names (matching the client commands they describe)
1893  
1894 my ($self, $check) = @_;
1895  
1896 # Local variables
1897 my (
1898 @emptyList, @dirList,
1899 %fileHash,
1900 );
1901  
1902 # Check for improper arguments
1903 if (defined $check) {
1904  
1905 $axmud::CLIENT->writeImproper($self->_objClass . '->listHelpFiles', @_);
1906 return @emptyList;
1907 }
1908  
1909 push (@dirList, $axmud::DATA_DIR . '/plugins/help/cmd/');
1910 push (@dirList, $axmud::SHARE_DIR . '/plugins/help/cmd/');
1911 push (@dirList, $axmud::SHARE_DIR . '/private/help/cmd/');
1912 push (@dirList, $axmud::SHARE_DIR . '/help/cmd/');
1913  
1914 foreach my $dir (@dirList) {
1915  
1916 foreach my $path (glob($dir . '*')) {
1917  
1918 # (Strip away the directory, and use only the command name matching the filename)
1919 if ($path =~ m/([A-Za-z0-9]*)$/) {
1920  
1921 $fileHash{$1} = undef;
1922 }
1923 }
1924 }
1925  
1926 return (keys %fileHash);
1927 }
1928  
1929 sub getHelpStart {
1930  
1931 # Called by GA::Cmd::Help->do, HelpTestCmd->do and HelpAllCmd->do
1932 # Returns a list of strings which are displayed at the beginning of the help for this
1933 # client command
1934 # (The list returned by $self->getHelpEnd is displayed at the end of it)
1935 #
1936 # Expected arguments
1937 # (none besides $self)
1938 #
1939 # Return values
1940 # An empty list on improper arguments
1941 # Otherwise, returns the list of strings to display
1942  
1943 my ($self, $check) = @_;
1944  
1945 # Local variables
1946 my (
1947 $shortestCmd,
1948 @list, @emptyList,
1949 );
1950  
1951 # Check for improper arguments
1952 if (defined $check) {
1953  
1954 $axmud::CLIENT->writeImproper($self->_objClass . '->getHelpStart', @_);
1955 return @emptyList;
1956 }
1957  
1958 # Get the shortest user command for this client command
1959 $shortestCmd = $self->findShortestCmd();
1960  
1961 # Compose the list and return it
1962 push (
1963 @list,
1964 sprintf(
1965 '%-30.30s', $shortestCmd . ' / ' . $self->standardCmd,
1966 ) . $self->descrip,
1967 );
1968 push (@list, ' ', ' Format:');
1969  
1970 return @list;
1971 }
1972  
1973 sub getHelpEnd {
1974  
1975 # Called by GA::Cmd::Help->do, HelpTest->do and HelpAll->do
1976 # Returns a list of strings which are displayed at the end of the help for each client
1977 # command
1978 # (The list returned by $self->getHelpStart is displayed at the beginning of it)
1979 #
1980 # Expected arguments
1981 # (none besides $self)
1982 #
1983 # Return values
1984 # An empty list on improper arguments
1985 # Otherwise, returns the list of strings to display
1986  
1987 my ($self, $check) = @_;
1988  
1989 # Local variables
1990 my @emptyList;
1991  
1992 # Check for improper arguments
1993 if (defined $check) {
1994  
1995 $axmud::CLIENT->writeImproper($self->_objClass . '->getHelpEnd', @_);
1996 return @emptyList;
1997 }
1998  
1999 # Compose the list and return it
2000 return (
2001 ' ',
2002 ' User commands:',
2003 ' ' . join(' / ', $self->getSortedUserCmds()),
2004 );
2005 }
2006  
2007 sub abHelp {
2008  
2009 # Usually called by GA::Cmd::AxbasicHelp->do
2010 # Reads a data file in /help/axbasic corresponding to a specified help topic
2011 # Returns each line from the file as a list of strings
2012 #
2013 # Expected arguments
2014 # $session - The calling function's GA::Session
2015 # $topic - The topic; can be a Axbasic keyword or intrinsic function
2016 # $type - The topic type - 'keyword' or 'func'
2017 #
2018 # Return values
2019 # An empty list on improper arguments, if the file doesn't exist or if it can't be read
2020 # Otherwise, returns the contents of the file as a list of strings
2021  
2022 my ($self, $session, $topic, $type, $check) = @_;
2023  
2024 # Local variables
2025 my (
2026 $file, $modTopic, $fileHandle,
2027 @list, @emptyList,
2028 );
2029  
2030 # Check for improper arguments
2031 if (! defined $session || ! defined $topic || ! defined $type || defined $check) {
2032  
2033 $axmud::CLIENT->writeImproper($self->_objClass . '->abHelp', @_);
2034 return @emptyList;
2035 }
2036  
2037 # Check the file exists
2038 if ($type eq 'keyword') {
2039  
2040 $file = $axmud::SHARE_DIR . '/help/axbasic/keyword/' . lc($topic);
2041  
2042 } else {
2043  
2044 # If the function ends with an $, the filename ends with an underline
2045 $modTopic = $topic;
2046 $modTopic =~ s/\$$/_/;
2047  
2048 $file = $axmud::SHARE_DIR . '/help/axbasic/func/' . lc($modTopic);
2049 }
2050  
2051 if (! (-e $file)) {
2052  
2053 $session->writeError(
2054 'Can\'t find ' . $axmud::BASIC_NAME . ' help file for \'' . $topic . '\'',
2055 $self->_objClass . '->abHelp',
2056 );
2057  
2058 return @emptyList;
2059 }
2060  
2061 # Open the file for reading
2062 if (! open ($fileHandle, "<$file")) {
2063  
2064 $session->writeError(
2065 'Failed to open ' . $axmud::BASIC_NAME . ' help file for \'' . $topic . '\'',
2066 $self->_objClass . '->abHelp',
2067 );
2068  
2069 return @emptyList;
2070 }
2071  
2072 # Read the file
2073 while (1) {
2074  
2075 my $line = <$fileHandle>;
2076  
2077 if (! defined $line) {
2078  
2079 # File can't be read, or end of file. Return the edited contents of the file
2080 return @list
2081  
2082 } else {
2083  
2084 chomp $line;
2085 push (@list, $line);
2086 }
2087 }
2088 }
2089  
2090 sub taskHelp {
2091  
2092 # Usually called by GA::Cmd::TaskHelp->do
2093 # Reads a data file corresponding to a specified task. Returns each line from the file as a
2094 # list of strings
2095 # First looks in /help/task, then in /plugins/help/task, then in /private/help/task (which
2096 # doesn't exist in public releases of Axmud), then in the data directory's
2097 # /plugins/help/task
2098 #
2099 # Expected arguments
2100 # $session - The calling function's GA::Session
2101 # $topic - The task's 'pretty' name (e.g. 'Status', 'TaskList'); case insensitive
2102 #
2103 # Return values
2104 # An empty list on improper arguments, if the file doesn't exist or if it can't be read
2105 # Otherwise, returns the contents of the file as a list of strings
2106  
2107 my ($self, $session, $topic, $check) = @_;
2108  
2109 # Local variables
2110 my (
2111 $file, $fileHandle,
2112 @emptyList, @list,
2113 );
2114  
2115 # Check for improper arguments
2116 if (! defined $session || ! defined $topic || defined $check) {
2117  
2118 $axmud::CLIENT->writeImproper($self->_objClass . '->taskHelp', @_);
2119 return @emptyList;
2120 }
2121  
2122 # Check the file exists
2123 $file = $axmud::SHARE_DIR . '/help/task/' . lc($topic);
2124 if (! (-e $file)) {
2125  
2126 $file = $axmud::SHARE_DIR . '/plugins/help/task/' . lc($topic);
2127 if (! (-e $file)) {
2128  
2129 $file = $axmud::SHARE_DIR . '/private/help/task/' . lc($topic);
2130 if (! (-e $file)) {
2131  
2132 $file = $axmud::DATA_DIR . '/plugins/help/task/' . lc($topic);
2133 if (! (-e $file)) {
2134  
2135 $session->writeError(
2136 'Can\'t find task help file for \'' . $topic . '\'',
2137 $self->_objClass . '->taskHelp',
2138 );
2139  
2140 return @emptyList;
2141 }
2142 }
2143 }
2144 }
2145  
2146 # Open the file for reading
2147 if (! open ($fileHandle, "<$file")) {
2148  
2149 $session->writeError(
2150 'Failed to open task help file for \'' . $topic . '\'',
2151 $self->_objClass . '->taskHelp',
2152 );
2153  
2154 return @emptyList;
2155 }
2156  
2157 # Read the file
2158 while (1) {
2159  
2160 my $line = <$fileHandle>;
2161  
2162 if (! defined $line) {
2163  
2164 # File can't be read, or end of file. Return the edited contents of the file
2165 return @list
2166  
2167 } else {
2168  
2169 chomp $line;
2170 push (@list, $line);
2171 }
2172 }
2173 }
2174  
2175 sub getAboutText {
2176  
2177 # Called by GA::Cmd::About->do (or by any other function)
2178 # Returns a list of strings which would be displayed in response to an ';about' command
2179 #
2180 # Expected arguments
2181 # (none besides $self)
2182 #
2183 # Return values
2184 # An empty list on improper arguments
2185 # Otherwise, returns the list of strings to display
2186  
2187 my ($self, $check) = @_;
2188  
2189 # Local variables
2190 my (
2191 $string,
2192 @emptyList, @returnList,
2193 );
2194  
2195 # Check for improper arguments
2196 if (defined $check) {
2197  
2198 $axmud::CLIENT->writeImproper($self->_objClass . '->getAboutText', @_);
2199 return @emptyList;
2200 }
2201  
2202 # Compose a list of strings
2203 push (@returnList,
2204 $axmud::SCRIPT . ' v' . $axmud::VERSION . ' (' . $axmud::DATE . ') by '
2205 . $axmud::AUTHORS,
2206 $axmud::COPYRIGHT,
2207 'Website: ' . $axmud::URL,
2208 ' ', # Empty line
2209 @axmud::LICENSE_LIST,
2210 );
2211  
2212 if (@axmud::CREDIT_LIST) {
2213  
2214 push (@returnList,
2215 ' ', # Empty line
2216 'Credits:',
2217 @axmud::CREDIT_LIST,
2218 );
2219 }
2220  
2221 return @returnList;
2222 }
2223  
2224 sub countDownUp {
2225  
2226 # Called by GA::Cmd::Countdown->do and Countup->do
2227 # Creates a Countdown task, or uses an existing one. Then sets the task's clock running
2228 #
2229 # Expected arguments
2230 # $session - The calling function's GA::Session
2231 # $inputString - The command actually typed, e.g. 'scd 5'
2232 # $standardCmd - Standard version of the client command, e.g. 'setcountdown'
2233 # $type - 'down' or 'up'
2234 #
2235 # Optional arguments
2236 # @args - Optional list of arguments supplied to the client command
2237 #
2238 # Return values
2239 # 'undef' on improper arguments or if there's an error
2240 # 1 on success
2241  
2242 my ($self, $session, $inputString, $standardCmd, $type, @args) = @_;
2243  
2244 # Local variables
2245 my ($flagCount, $switch, $secsFlag, $minsFlag, $hoursFlag, $number, $string, $taskObj);
2246  
2247 # Check for improper arguments
2248 if (
2249 ! defined $session || ! defined $inputString || ! defined $standardCmd
2250 || ! defined $type
2251 ) {
2252 return $axmud::CLIENT->writeImproper($self->_objClass . '->countDownUp', @_);
2253 }
2254  
2255 # Extract switches
2256 $flagCount = 0;
2257  
2258 ($switch, @args) = $self->extract('-s', 0, @args);
2259 if (defined $switch) {
2260  
2261 $secsFlag = TRUE;
2262 $flagCount++;
2263 }
2264  
2265 ($switch, @args) = $self->extract('-m', 0, @args);
2266 if (defined $switch) {
2267  
2268 $minsFlag = TRUE;
2269 $flagCount++;
2270 }
2271  
2272 ($switch, @args) = $self->extract('-h', 0, @args);
2273 if (defined $switch) {
2274  
2275 $hoursFlag = TRUE;
2276 $flagCount++;
2277 }
2278  
2279 # Extract remaining arguments (if any)
2280 $number = shift @args;
2281  
2282 # There should be nothing left in @args
2283 if (@args) {
2284  
2285 return $self->improper($session, $inputString);
2286 }
2287  
2288 # Switches can't be combined
2289 if ($flagCount > 1) {
2290  
2291 return $self->error(
2292 $session, $inputString,
2293 'The switches \'-s\', \'-m\' and \'-h\' can\'t be combined',
2294 );
2295 }
2296  
2297 # If $number was specified, check it's valid
2298 if (defined $number) {
2299  
2300 if (! $axmud::CLIENT->floatCheck($number, 0) || $number == 0) {
2301  
2302 return $self->error(
2303 $session, $inputString,
2304 'Invalid time \'' . $number . '\' (must be a positive number)',
2305 );
2306 }
2307  
2308 # Convert it to seconds, and create a partial confirmation message in advance
2309 if ($hoursFlag) {
2310  
2311 if ($number == 1) {
2312 $string = '1 hour';
2313 } else {
2314 $string = $number . ' hours';
2315 }
2316  
2317 $number *= 3600;
2318  
2319 } elsif ($minsFlag) {
2320  
2321 if ($number == 1) {
2322 $string = '1 minute';
2323 } else {
2324 $string = $number . ' minutes';
2325 }
2326  
2327 $number *= 60;
2328  
2329 } else {
2330  
2331 if ($number == 1) {
2332 $string = '1 second';
2333 } else {
2334 $string = $number . ' seconds';
2335 }
2336 }
2337 }
2338  
2339 # There can be multiple Countdown tasks running; find the most recent one
2340 $taskObj = $session->ivShow('currentTaskNameHash', 'countdown_task');
2341 if ($taskObj) {
2342  
2343 # Countdown task running. If it's already counting down/up, we need to start a new task
2344 # (or use one of the others)
2345 if ($taskObj->countMode ne 'default') {
2346  
2347 OUTER: foreach my $otherTaskObj ($session->ivValues('currentTaskHash')) {
2348  
2349 if (
2350 $otherTaskObj->name eq 'countdown_task'
2351 && $otherTaskObj->countMode eq 'default'
2352 ) {
2353 $taskObj = $otherTaskObj;
2354 last OUTER;
2355 }
2356 }
2357 }
2358 }
2359  
2360 if (! $taskObj) {
2361  
2362 # No countdown task running (or all existing tasks busy), so start a new one
2363 $taskObj = Games::Axmud::Task::Countdown->new($session, 'current');
2364 if (! $taskObj) {
2365  
2366 return $self->error(
2367 $session, $inputString,
2368 'General error creating a new Countdown task',
2369 );
2370  
2371 } elsif ($number) {
2372  
2373 # Give the task its initial settings
2374 $taskObj->initClock($type, $number);
2375  
2376 return $self->complete(
2377 $session, $standardCmd,
2378 'Countdown task initialised; counting ' . $type . ' from '. $string,
2379 );
2380  
2381 } else {
2382  
2383 return $self->complete($session, $standardCmd, 'Countdown task started');
2384 }
2385  
2386 } else {
2387  
2388 # Countdown task running and is available to start counting down/up
2389 $taskObj->startClock($type, $number);
2390  
2391 return $self->complete(
2392 $session, $standardCmd,
2393 'Countdown task updated; counting ' . $type . ' from '. $string,
2394 );
2395 }
2396 }
2397  
2398 sub findTask {
2399  
2400 # Called by GA::Cmd::HaltTask->do, KillTask->do, PauseTask->do, ResumeTask->do,
2401 # ResetTask->do, OpenWindow->do and CloseWindow->do (or by any other code)
2402 # Searches for tasks in the current tasklist matching the string $taskName, and returns the
2403 # blessed references of all matches in a list
2404 # $taskName can match a task label (stored in GA::Client->taskLabelHash), a task's formal
2405 # name (stored in GA::Client->taskPackageHash), or the unique name of a task in the
2406 # current tasklist (stored in GA::Session->currentTaskHash)
2407 # If $taskName is set to '-a', then all tasks in the current tasklist are returned
2408 #
2409 # Expected arguments
2410 # $session - The calling function's GA::Session
2411 # $string - The string to analyse (e.g. 'status'), or the switch '-a' to fetch all
2412 # current tasks
2413 #
2414 # Return values
2415 # An empty list on improper arguments or if no matching tasks are found
2416 # Otherwise returns a list of blessed references to matching tasks
2417  
2418 my ($self, $session, $string, $check) = @_;
2419  
2420 # Local variables
2421 my (
2422 $taskName,
2423 @emptyList, @returnArray,
2424 );
2425  
2426 # Check for improper arguments
2427 if (! defined $session || ! defined $string || defined $check) {
2428  
2429 $axmud::CLIENT->writeImproper($self->_objClass . '->findTask', @_);
2430 return @emptyList;
2431 }
2432  
2433 # e.g. ';halttask -a'
2434 if ($string eq '-a') {
2435  
2436 # Add every task in the current tasklist (if any)
2437 @returnArray = $session->ivValues('currentTaskHash');
2438  
2439 # e.g. ';halttask <task>'
2440 # Look for a task matching <task>. First check task labels...
2441 } elsif ($axmud::CLIENT->ivExists('taskLabelHash', $string)) {
2442  
2443 # <task> is a valid task label (e.g. 'status')
2444  
2445 # Get the task's formal name (e.g. 'status_task')
2446 $taskName = $axmud::CLIENT->ivShow('taskLabelHash', $string);
2447 # Add all running instances of this task
2448 foreach my $taskObj ($session->ivValues('currentTaskHash')) {
2449  
2450 if ($taskObj->name eq $taskName) {
2451  
2452 push (@returnArray, $taskObj);
2453 }
2454 }
2455  
2456 # ...then check formal names...
2457 } elsif ($axmud::CLIENT->ivExists('taskPackageHash', $string)) {
2458  
2459 # <task> is a valid formal name (e.g. 'status_task')
2460  
2461 # Add all running instances of this task
2462 foreach my $taskObj ($session->ivValues('currentTaskHash')) {
2463  
2464 if ($taskObj->name eq $string) {
2465  
2466 push (@returnArray, $taskObj);
2467 }
2468 }
2469  
2470 # ...finally, check unique names in the current tasklist
2471 } elsif ($session->ivExists('currentTaskHash', $string)) {
2472  
2473 # <task> is a task in the current tasklist
2474 push (@returnArray, $session->ivShow('currentTaskHash', $string));
2475 }
2476  
2477 # Return the list of matching tasks
2478 return @returnArray;
2479 }
2480  
2481 sub findGlobalInitialTask {
2482  
2483 # Called by GA::Cmd::Read->do, Switch->do, Alert->do (or by any other code)
2484 # Searches for tasks in the global initial tasklist matching the string $taskName, and
2485 # returns the blessed references of all matches in a list
2486 # $taskName can match a task label (stored in GA::Client->taskLabelHash), a task's formal
2487 # name (stored in GA::Client->taskPackageHash), or the unique name of a task in the
2488 # current tasklist (stored in GA::Session->currentTaskHash)
2489 #
2490 # Expected arguments
2491 # $string - The string to analyse (e.g. 'status')
2492 #
2493 # Return values
2494 # An empty list on improper arguments or if no matching tasks are found
2495 # Otherwise returns a list of blessed references to matching tasks
2496  
2497 my ($self, $string, $check) = @_;
2498  
2499 # Local variables
2500 my (
2501 $taskName,
2502 @emptyList, @returnArray,
2503 );
2504  
2505 # Check for improper arguments
2506 if (! defined $string || defined $check) {
2507  
2508 $axmud::CLIENT->writeImproper($self->_objClass . '->findGlobalInitialTask', @_);
2509 return @emptyList;
2510 }
2511  
2512 # Look for a task matching <task>. First check task labels...
2513 if ($axmud::CLIENT->ivExists('taskLabelHash', $string)) {
2514  
2515 # <task> is a valid task label (e.g. 'status')
2516  
2517 # Get the task's formal name (e.g. 'status_task')
2518 $taskName = $axmud::CLIENT->ivShow('taskLabelHash', $string);
2519 # Add all matching tasks in the global initial tasklist
2520 foreach my $taskObj ($axmud::CLIENT->ivValues('initTaskHash')) {
2521  
2522 if ($taskObj->name eq $taskName) {
2523  
2524 push (@returnArray, $taskObj);
2525 }
2526 }
2527  
2528 # ..then check formal names...
2529 } elsif ($axmud::CLIENT->ivExists('taskPackageHash', $string)) {
2530  
2531 # <task> is a valid formal name (e.g. 'status_task')
2532  
2533 # Add all matching tasks in the global initial tasklist
2534 foreach my $taskObj ($axmud::CLIENT->ivValues('initTaskHash')) {
2535  
2536 if ($taskObj->name eq $string) {
2537  
2538 push (@returnArray, $taskObj);
2539 }
2540 }
2541  
2542 # ...finally, check unique names in the global initial tasklist
2543 } elsif ($axmud::CLIENT->ivExists('initTaskHash', $string)) {
2544  
2545 # <task> is a task in the current tasklist
2546 push (@returnArray, $axmud::CLIENT->ivShow('initTaskHash', $string));
2547 }
2548  
2549 # Return the list of matching tasks
2550 return @returnArray;
2551 }
2552  
2553 sub findProfileInitialTask {
2554  
2555 # Called by GA::Cmd::WorldCompass->do (or by any other code)
2556 # An alternative to $self->findGlobalInitialTask, looking instead in a specified profile's
2557 # initial tasklist for a task matching the string $taskName, and which returns the blessed
2558 # references of all matches in a list
2559 # $taskName can match a task label (stored in GA::Client->taskLabelHash) or a task's formal
2560 # name (stored in GA::Client->taskPackageHash)
2561 #
2562 # Expected arguments
2563 # $string - The string to analyse (e.g. 'status')
2564 # $profObj - Blessed reference of the profile object
2565 #
2566 # Return values
2567 # An empty list on improper arguments or if no matching tasks are found
2568 # Otherwise returns a list of blessed references to matching tasks
2569  
2570 my ($self, $string, $profObj, $check) = @_;
2571  
2572 # Local variables
2573 my (
2574 $taskName,
2575 @emptyList, @returnArray,
2576 );
2577  
2578 # Check for improper arguments
2579 if (! defined $string || ! defined $profObj || defined $check) {
2580  
2581 $axmud::CLIENT->writeImproper($self->_objClass . '->findProfileInitialTask', @_);
2582 return @emptyList;
2583 }
2584  
2585 # Look for a task matching <task>. First check task labels...
2586 if ($axmud::CLIENT->ivExists('taskLabelHash', $string)) {
2587  
2588 # <task> is a valid task label (e.g. 'status')
2589  
2590 # Get the task's formal name (e.g. 'status_task')
2591 $taskName = $axmud::CLIENT->ivShow('taskLabelHash', $string);
2592 # Add all matching tasks in the world's initial tasklist
2593 foreach my $taskObj ($profObj->ivValues('initTaskHash')) {
2594  
2595 if ($taskObj->name eq $taskName) {
2596  
2597 push (@returnArray, $taskObj);
2598 }
2599 }
2600  
2601 # ..then check formal names...
2602 } elsif ($axmud::CLIENT->ivExists('taskPackageHash', $string)) {
2603  
2604 # <task> is a valid formal name (e.g. 'status_task')
2605  
2606 # Add all matching tasks in the world's initial tasklist
2607 foreach my $taskObj ($profObj->ivValues('initTaskHash')) {
2608  
2609 if ($taskObj->name eq $string) {
2610  
2611 push (@returnArray, $taskObj);
2612 }
2613 }
2614 }
2615  
2616 # Return the list of matching tasks
2617 return @returnArray;
2618 }
2619  
2620 sub findTaskPackageName {
2621  
2622 # Called by GA::Cmd::StartTask->do, AddInitTask->do or by any other function
2623 # Tries to find the package name for a task matching the specified string
2624 #
2625 # Tasks are matched in the following priority order:
2626 # 1. An exact match with one of the task labels in GA::Client->taskLabelHash
2627 # 2. An exact match with the task's formal name (e.g. 'locator_task', 'status_task')
2628 # 3. A match with the unique name of a currently running ('current') task
2629 # (e.g. 'locator_task_56', 'status_task_57')
2630 #
2631 # Expected arguments
2632 # $session - The calling function's GA::Session
2633 # $string - The string to analyse (e.g. 'status')
2634 #
2635 # Return values
2636 # 'undef' on improper arguments or if a match can't be found
2637 # Otherwise returns the package name, e.g. 'StatusTask', 'SocialTask'
2638  
2639 my ($self, $session, $string, $check) = @_;
2640  
2641 # Local variables
2642 my ($taskName, $taskObj);
2643  
2644 # Check for improper arguments
2645 if (! defined $session || ! defined $string || defined $check) {
2646  
2647 return $axmud::CLIENT->writeImproper($self->_objClass . '->findTaskPackageName', @_);
2648 }
2649  
2650 # Check task labels
2651 if ($axmud::CLIENT->ivExists('taskLabelHash', $string)) {
2652  
2653 $taskName = $axmud::CLIENT->ivShow('taskLabelHash', $string);
2654 if ($axmud::CLIENT->ivExists('taskPackageHash', $taskName)) {
2655  
2656 return $axmud::CLIENT->ivShow('taskPackageHash', $taskName);
2657 }
2658  
2659 # Check standard/external task package names
2660 } elsif ($axmud::CLIENT->ivExists('taskPackageHash', $string)) {
2661  
2662 return $axmud::CLIENT->ivShow('taskPackageHash', $string);
2663  
2664 # Check current tasklist
2665 } elsif ($session->ivExists('currentTaskHash', $string)) {
2666  
2667 OUTER: foreach my $uniqueName ($session->ivKeys('currentTaskHash')) {
2668  
2669 if ($uniqueName eq $string) {
2670  
2671 $taskObj = $session->ivShow('currentTaskHash', $uniqueName);
2672 last OUTER;
2673 }
2674 }
2675  
2676 if ($taskObj) {
2677  
2678 $taskName = $taskObj->name;
2679 if ($axmud::CLIENT->ivExists('taskPackageHash', $taskName)) {
2680  
2681 return $axmud::CLIENT->ivShow('taskPackageHash', $taskName);
2682 }
2683 }
2684 }
2685  
2686 # No match found
2687 return undef;
2688 }
2689  
2690 sub newTaskSettings {
2691  
2692 # Called by GA::Cmd::StartTask->do, AddInitTaskCommand->do and AddCustomTaskCommand->do
2693 # After a new task is created, the task's settings are set in the same way for each of the
2694 # above commands
2695 #
2696 # Expected arguments
2697 # $session - The calling function's GA::Session
2698 # $inputString - What the user actually typed (e.g. ';st status -i');
2699 # $standardCmd - The standard version of the command, i.e. 'starttask'
2700 # $newTask - Blessed reference to the new task's object
2701 #
2702 # Optional arguments
2703 # $otherTask - Blessed reference to another task, for which $newTask may have to
2704 # wait
2705 # $minutes, $runMinutes, $timer
2706 # - Time periods during which $newTask may have to wait
2707 # $immediateFlag, $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag,
2708 # $waitMinutesFlag, $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag
2709 # - Various flags that control how $newTask is set up
2710 #
2711 # Notes
2712 # Any or all of the optional arguments may have the value 'undef'
2713 #
2714 # Return values
2715 # 'undef' on improper arguments or if upon failure
2716 # 1 otherwise
2717  
2718 my (
2719 $self, $session, $inputString, $standardCmd, $newTask, $otherTask, $minutes,
2720 $runMinutes, $timer, $immediateFlag, $waitTaskExistFlag, $waitTaskNoExistFlag,
2721 $waitTaskStartStopFlag, $waitMinutesFlag, $unlimitedFlag, $runTaskForFlag,
2722 $runTaskUntilFlag, $noWindowFlag, $check
2723 ) = @_;
2724  
2725 # Local variables
2726 my $otherTaskName;
2727  
2728 # Check for improper arguments
2729 if (
2730 ! defined $inputString || ! defined $standardCmd || ! defined $newTask || defined $check
2731 ) {
2732 return $axmud::CLIENT->writeImproper($self->_objClass . '->newTaskSettings', @_);
2733 }
2734  
2735 # Set the task's settings, if necessary
2736 if ($immediateFlag) {
2737  
2738 # Insist that the task starts immediately (which it should be set up to do)
2739 $newTask->ivPoke('status', 'wait_init');
2740 $newTask->ivPoke('startTime', 0);
2741  
2742 } elsif ($waitTaskExistFlag || $waitTaskNoExistFlag || $waitTaskStartStopFlag) {
2743  
2744 if ($waitTaskExistFlag) {
2745  
2746 # Wait for a task to exist
2747 $newTask->ivPoke('status', 'wait_task_exist');
2748 $newTask->ivPoke('checkTime', $session->sessionTime);
2749  
2750 } elsif ($waitTaskNoExistFlag) {
2751  
2752 # Wait for a task to stop existing
2753 $newTask->ivPoke('status', 'wait_task_no_exist');
2754 $newTask->ivPoke('checkTime', $session->sessionTime);
2755  
2756 } elsif ($waitTaskStartStopFlag) {
2757  
2758 # Wait for a task to exist, then stop existing
2759 $newTask->ivPoke('status', 'wait_task_start_stop');
2760 $newTask->ivPoke('checkTime', $session->sessionTime);
2761 }
2762  
2763 # $otherTask can match GA::Generic::Task->name, a task label, or
2764 # GA::Generic::Task->uniqueName
2765 if ($session->ivExists('currentTaskHash', $otherTask)) {
2766  
2767 # e.g. 'status_task_7'
2768 $otherTaskName = $session->ivShow('currentTaskHash', $otherTask);
2769  
2770 } elsif ($axmud::CLIENT->ivExists('taskLabelHash', $otherTask)) {
2771  
2772 # e.g. 'status'
2773 $otherTaskName = $axmud::CLIENT->ivShow('taskLabelHash', $otherTask);
2774  
2775 } else {
2776  
2777 # e.g. 'status_task'
2778 $otherTaskName = $otherTask;
2779 }
2780  
2781 if (! defined $otherTaskName) {
2782  
2783 return $self->error(
2784 $session, $inputString,
2785 'Unrecognised task \'' . $otherTask . '\'',
2786 );
2787  
2788 } else {
2789  
2790 $newTask->ivPoke('waitForTask', $otherTaskName);
2791 }
2792  
2793 } elsif ($waitMinutesFlag) {
2794  
2795 # Wait for some minutes
2796 $newTask->ivPoke('status', 'wait_init');
2797 $newTask->ivPoke('startTime', $session->sessionTime + ($minutes * 60));
2798 }
2799  
2800 if ($unlimitedFlag) {
2801  
2802 # Insist that the task runs for an unlimited period (which it should be set up to do)
2803 $newTask->ivPoke('endStatus', 'unlimited');
2804  
2805 } elsif ($runTaskForFlag) {
2806  
2807 # Run for some minutes
2808 $newTask->ivPoke('endStatus', 'run_for');
2809 $newTask->ivPoke('endTime', $runMinutes);
2810  
2811 } elsif ($runTaskUntilFlag) {
2812  
2813 # Run until GA::Session->sessionTime reaches a certain value
2814 $newTask->ivPoke('endStatus', 'run_until');
2815 $newTask->ivPoke('endTime', $timer);
2816 }
2817  
2818 if ($noWindowFlag && $newTask->allowWinFlag == TRUE) {
2819  
2820 $newTask->ivPoke('startWithWinFlag', FALSE);
2821 }
2822  
2823 return 1;
2824 }
2825  
2826 sub addProfile {
2827  
2828 # Called by GA::Cmd::AddGuild->do, AddRace->do, AddChar->do
2829 # Adds a guild/race/char profile
2830 #
2831 # Expected arguments
2832 # $session - The calling function's GA::Session
2833 # $inputString - The command actually typed, e.g. 'ag thief'
2834 # $standardCmd - Standard version of the client command, e.g. 'addguild'
2835 # $name - The new profile's name
2836 # $category - The category of profile - 'guild', 'race' or 'char'
2837 #
2838 # Optional arguments
2839 # $pwd - For character profiles only, the password to set. If 'undef', don't
2840 # set a password
2841 # $account - For character profiles, only, the associated account name to set. If
2842 # 'undef', don't set an account name
2843 #
2844 # Return values
2845 # 'undef' on improper arguments or if there's an error
2846 # 1 on success
2847  
2848 my (
2849 $self, $session, $inputString, $standardCmd, $name, $category, $pwd, $account, $check,
2850 ) = @_;
2851  
2852 # Local variables
2853 my ($obj, $package);
2854  
2855 # Check for improper arguments
2856 if (
2857 ! defined $session || ! defined $inputString || ! defined $standardCmd
2858 || ! defined $name || ! defined $category || defined $check
2859 ) {
2860 return $axmud::CLIENT->writeImproper($self->_objClass . '->addProfile', @_);
2861 }
2862  
2863 # Check that $name is a valid name
2864 if (! $axmud::CLIENT->nameCheck($name, 16)) {
2865  
2866 return $self->error(
2867 $session, $inputString,
2868 'Could not add ' . $category . ' profile \'' . $name . '\' - invalid name',
2869 );
2870  
2871 # Check the profile doesn't already exist
2872 } elsif ($session->ivExists('profHash', $name)) {
2873  
2874 return $self->error(
2875 $session, $inputString,
2876 'Could not add ' . $category . ' profile \'' . $name . '\' - profile already'
2877 . ' exists',
2878 );
2879 }
2880  
2881 # Create a new profile
2882 $package = 'Games::Axmud::Profile::' . ucfirst($category);
2883 $obj = $package->new($session, $name, $session->currentWorld->name);
2884 if (! $obj) {
2885  
2886 return $self->error(
2887 $session, $inputString,
2888 'Could not add ' . $category . ' profile \'' . $name . '\'',
2889 );
2890 }
2891  
2892 # Create its associated cages
2893 if (! $session->createCages($obj)) {
2894  
2895 return $self->error(
2896 $session, $inputString,
2897 'Could not add ' . $category .' profile \'' . $name . '\' - errors while creating'
2898 . ' cages',
2899 );
2900 }
2901  
2902 # Update IVs
2903 $session->add_prof($obj);
2904 # Tell the current world it's acquired a new associated definiton
2905 $session->currentWorld->ivAdd('profHash', $name, $category);
2906 # If it's a character profile, update more IVs
2907 if ($category eq 'char') {
2908  
2909 # (The password can be 'undef')
2910 $session->currentWorld->ivAdd('passwordHash', $name, $pwd);
2911 # (The account name can be 'undef')
2912 $session->currentWorld->ivAdd('accountHash', $name, $account);
2913 }
2914  
2915 # Operation complete
2916 if (! $pwd) {
2917  
2918 return $self->complete(
2919 $session, $standardCmd,
2920 'Added ' . $category . ' profile \'' . $name . '\'',
2921 );
2922  
2923 } else {
2924  
2925 # Obfuscate the password, using the same number of asterisk characters as elsewhere
2926 return $self->complete(
2927 $session, $standardCmd,
2928 'Added ' . $category . ' profile \'' . $name . '\' with the password \'********\'',
2929 );
2930 }
2931 }
2932  
2933 sub setProfile {
2934  
2935 # Called by GA::Cmd::SetGuild->do, SetRace->do, SetChar->do
2936 # Sets the current guild/race/char profile
2937 #
2938 # Expected arguments
2939 # $session - The calling function's GA::Session
2940 # $inputString - The command actually typed, e.g. 'sg thief'
2941 # $standardCmd - Standard version of the client command, e.g. 'setguild'
2942 # $name - The profile's name
2943 # $category - The category of profile - 'guild', 'race' or 'char'
2944 #
2945 # Optional arguments
2946 # $pwd - For character profiles only, the password to set. If the character
2947 # also exists, the password is updated. If 'undef', don't set or
2948 # update a password
2949 # $account - For character profiles, only, the associated account name to set. If
2950 # 'undef', don't set an account name
2951 #
2952 # Return values
2953 # 'undef' on improper arguments or if there's an error
2954 # 1 on success
2955  
2956 my (
2957 $self, $session, $inputString, $standardCmd, $name, $category, $pwd, $account, $check,
2958 ) = @_;
2959  
2960 # Local variables
2961 my (
2962 $iv, $currentObj, $obj, $package, $historyObj,
2963 %customProfHash,
2964 );
2965  
2966 # Check for improper arguments
2967 if (
2968 ! defined $session || ! defined $inputString || ! defined $standardCmd
2969 || ! defined $name || ! defined $category || defined $check
2970 ) {
2971 return $axmud::CLIENT->writeImproper($self->_objClass . '->setProfile', @_);
2972 }
2973  
2974 # Check there are no 'free' windows open
2975 if ($axmud::CLIENT->desktopObj->listSessionFreeWins($session, TRUE)) {
2976  
2977 return $self->error(
2978 $session, $inputString,
2979 'Can\'t set a current profile while there are \'free\' windows (such as edit,'
2980 . ' preference and wizard windows) open - try closing them first',
2981 );
2982 }
2983  
2984 # If the profile already exists, check it isn't already a current profile
2985 if ($session->ivExists('currentProfHash', $category)) {
2986  
2987 $currentObj = $session->ivShow('currentProfHash', $category);
2988 if ($currentObj->name eq $name) {
2989  
2990 # Error message depends on whether it's the right kind of profile
2991 if ($currentObj->category eq $category) {
2992  
2993 return $self->error(
2994 $session, $inputString,
2995 'The profile \'' . $name . '\' is already the current ' . $category
2996 . ' profile',
2997 );
2998  
2999 } else {
3000  
3001 return $self->error(
3002 $session, $inputString,
3003 'The profile \'' . $name . '\' is the current ' . $currentObj->category
3004 . ' profile',
3005 );
3006 }
3007 }
3008 }
3009  
3010 # For character profiles, need to check that another session isn't already using the same
3011 # profile. The TRUE flag means 'ignore sessions whose ->status is 'disconnected')
3012 if (
3013 $category eq 'char'
3014 && $axmud::CLIENT->testSessions($session->currentWorld->name, $name, TRUE)
3015 ) {
3016 return $self->error(
3017 $session, $inputString,
3018 'You are already using \'' . $name . '\' as the current character profile in'
3019 . ' another session',
3020 );
3021 }
3022  
3023 # If the profile exists, use it
3024 if ($session->ivExists('profHash', $name)) {
3025  
3026 $obj = $session->ivShow('profHash', $name);
3027  
3028 # Check it's the right category of profile
3029 if ($obj->category ne $category) {
3030  
3031 return $self->error(
3032 $session, $inputString,
3033 'The profile \'' . $name . '\' is a ' . $obj->category . ' profile',
3034 );
3035 }
3036  
3037 # If there was already a current profile of this category, remove its interfaces
3038 # and any of its initial tasks/scripts which are now running in the current tasklist
3039 if ($currentObj) {
3040  
3041 $session->haltProfileTasks($currentObj->name);
3042 $session->resetProfileInterfaces($currentObj->name);
3043 }
3044  
3045 # Update IVs
3046 $session->add_currentProf($obj); # Also sets ->currentGuild etc, ->currentProfChangeFlag
3047 # Tell the current world it's acquired a new associated definiton
3048 $session->currentWorld->ivAdd('profHash', $name, $category);
3049 # If it's a character profile and a password/account name was specified, use it
3050 if ($category eq 'char') {
3051  
3052 if (defined $pwd) {
3053  
3054 $session->currentWorld->ivAdd('passwordHash', $name, $pwd);
3055 }
3056  
3057 if (defined $account) {
3058  
3059 $session->currentWorld->ivAdd('accountHash', $name, $account);
3060 }
3061 }
3062  
3063 # Set up cages for the new current profile
3064 $session->setCurrentCages($name, $category);
3065  
3066 # Guild/race profiles only - if there's a current character, inform it it's acquired a
3067 # new guild/race
3068 if ($category eq 'guild' || $category eq 'race') {
3069  
3070 if ($session->currentChar) {
3071  
3072 if ($category eq 'guild') {
3073 $session->currentChar->ivPoke('guild', $name);
3074 } elsif ($category eq 'race') {
3075 $session->currentChar->ivPoke('race', $name);
3076 }
3077 }
3078  
3079 # Character profiles only - if the character profile specifies a guild, race or custom
3080 # profiles set, mark them as current profiles too (creating them, if necessary)
3081 # If the character profile doesn't specify a guild, race or other custom profile, unset
3082 # the current profiles in those categories
3083 } elsif ($category eq 'char') {
3084  
3085 if ($obj->guild) {
3086 $session->pseudoCmd('setguild ' . $obj->guild, 'hide_complete');
3087 } else {
3088 $session->del_currentProf('guild');
3089 }
3090  
3091 if ($obj->race) {
3092 $session->pseudoCmd('setrace ' . $obj->race, 'hide_complete');
3093 } else {
3094 $session->del_currentProf('race');
3095 }
3096  
3097 %customProfHash = $obj->customProfHash;
3098 foreach my $customProf (keys %customProfHash) {
3099  
3100 my $customCategory = $customProfHash{$customProf};
3101  
3102 $session->pseudoCmd(
3103 'setcustomprofile ' . $customCategory . ' ' . $customProf,
3104 'hide_complete',
3105 );
3106 }
3107 }
3108  
3109 # Set cage inferiors
3110 $session->setCageInferiors();
3111 # Add new interfaces for this profile's cages
3112 $session->setProfileInterfaces($name);
3113  
3114 # If the current profile has any initial tasks or initial scripts, clone them into
3115 # the current tasklist. The FALSE argument means 'don't consult the global initial
3116 # tasklist/scriptlist'
3117 $session->startInitTasks(FALSE, $obj);
3118 $session->startInitScripts(FALSE, $obj);
3119  
3120 # If the character profile has been set and the session's connection history object
3121 # doesn't have a character marked, set it
3122 if ($category eq 'char' && $session->status eq 'connected') {
3123  
3124 $historyObj = $session->currentWorld->ivIndex(
3125 'connectHistoryList',
3126 $session->currentWorld->ivLast('connectHistoryList'),
3127 );
3128  
3129 if (
3130 $historyObj
3131 && $historyObj->_parentWorld eq $session->currentWorld->name
3132 && ! defined $historyObj->char
3133 ) {
3134 $historyObj->set_char($name);
3135 }
3136 }
3137  
3138 # If the Status task's counters are running, reset their values, and turn them off
3139 if ($session->statusTask) {
3140  
3141 $session->statusTask->update_profiles();
3142 }
3143  
3144 # Operation complete
3145 if (! $pwd) {
3146  
3147 return $self->complete(
3148 $session, $standardCmd,
3149 'Set \'' . $name . '\' as the current ' . $category . ' profile',
3150 );
3151  
3152 } else {
3153  
3154 return $self->complete(
3155 $session, $standardCmd,
3156 'Set \'' . $name . '\' as the current ' . $category . ' profile (and'
3157 . ' changed the password to \'********\')',
3158 );
3159 }
3160  
3161 # Otherwise create a new profile, and make it the current one
3162 } else {
3163  
3164 # Check that $name is a valid name
3165 if (! $axmud::CLIENT->nameCheck($name, 16)) {
3166  
3167 return $self->error(
3168 $session, $inputString,
3169 'Could not add ' . $category . ' profile \'' . $name . '\' - invalid name',
3170 );
3171 }
3172  
3173 # If there was already a current profile of this category, remove its interfaces and any
3174 # of its initial tasks/scripts which are now running in the current tasklist
3175 if ($currentObj) {
3176  
3177 $session->haltProfileTasks($currentObj->name);
3178 $session->resetProfileInterfaces($currentObj->name);
3179 }
3180  
3181 # Create a new profile
3182 $package = 'Games::Axmud::Profile::' . ucfirst($category);
3183 $obj = $package->new($session, $name, $session->currentWorld->name);
3184 if (! $obj) {
3185  
3186 return $self->error(
3187 $session, $inputString,
3188 'Could not add ' . $category . ' profile \'' . $name . '\'',
3189 );
3190 }
3191  
3192 # Update IVs now, because the call to ->createCages won't work without them
3193 $session->add_prof($obj);
3194 $session->add_currentProf($obj); # Also sets ->currentGuild, ->currentProfChangeFlag
3195 # If it's a character profile, update more IVs
3196 if ($category eq 'char') {
3197  
3198 # Either of both of $pwd and $account can be 'undef'
3199 $session->currentWorld->ivAdd('passwordHash', $name, $pwd);
3200 $session->currentWorld->ivAdd('accountHash', $name, $account);
3201  
3202 # Reset any current profiles beside the current world, and the (new) current
3203 # character
3204 foreach my $thisProf ($session->ivValues('currentProfHash')) {
3205  
3206 if ($thisProf->category ne 'world' && $thisProf->category ne 'char') {
3207  
3208 $session->del_currentProf($thisProf->category);
3209 }
3210 }
3211 }
3212  
3213 # Create its associated cages
3214 if (! $session->createCages($obj, TRUE)) {
3215  
3216 # Some objects couldn't be created. Destroy any newly-created cages, if any (don't
3217 # specify the TRUE flag because $obj isn't a current profile yet)
3218 $session->destroyCages($obj);
3219  
3220 # Unset the IVs set above
3221 $session->del_prof($obj);
3222 $session->del_currentProf($obj->category);
3223  
3224 return $self->error(
3225 $session, $inputString,
3226 'Could not add ' . $category .' profile \'' . $name . '\' - errors while'
3227 . ' creating cages',
3228 );
3229 }
3230  
3231 # Tell the current world it's acquired a new associated definiton
3232 $session->currentWorld->ivAdd('profHash', $name, $category);
3233 # If there's a current character, inform it it's acquired a new guild/race
3234 if ($session->currentChar) {
3235  
3236 if ($category eq 'guild') {
3237 $session->currentChar->ivPoke('guild', $name);
3238 } elsif ($category eq 'race') {
3239 $session->currentChar->ivPoke('race', $name);
3240 }
3241 }
3242  
3243 # If the current profile has any initial tasks or initial scripts, clone them into the
3244 # current tasklist. The FALSE argument means 'don't consult the global initial
3245 # tasklist/scriptlist'
3246 $session->startInitTasks(FALSE, $obj);
3247 $session->startInitScripts(FALSE, $obj);
3248  
3249 # If the character profile has been set and the session's connection history object
3250 # doesn't have a character marked, set it
3251 if ($category eq 'char' && $session->status eq 'connected') {
3252  
3253 $historyObj = $session->currentWorld->ivIndex(
3254 'connectHistoryList',
3255 $session->currentWorld->ivLast('connectHistoryList'),
3256 );
3257  
3258 if ($historyObj && ! defined $historyObj->char) {
3259  
3260 $historyObj->set_char($name);
3261 }
3262 }
3263  
3264 # If the Status task's counters are running, reset their values, and turn them off
3265 if ($session->statusTask) {
3266  
3267 $session->statusTask->update_profiles();
3268 }
3269  
3270 # Operation complete
3271 if (! $pwd) {
3272  
3273 return $self->complete(
3274 $session, $standardCmd,
3275 'Added \'' . $name . '\' as the current ' . $category . ' profile',
3276 );
3277  
3278 } else {
3279  
3280 return $self->complete(
3281 $session, $standardCmd,
3282 'Added \'' . $name . '\' with the password \'********\' as the current '
3283 . $category . ' profile',
3284 );
3285 }
3286 }
3287 }
3288  
3289 sub unsetProfile {
3290  
3291 # Called by GA::Cmd::UnsetGuild->do, UnsetRace->do, UnsetChar->do
3292 # Unsets the current guild/race/char profile (so that it's not a current profile
3293 # any more)
3294 #
3295 # Expected arguments
3296 # $session - The calling function's GA::Session
3297 # $inputString - The command actually typed, e.g. 'ug thief'
3298 # $standardCmd - Standard version of the client command, e.g. 'unsetguild'
3299 # $category - The category of profile - 'guild', 'race' or 'char'
3300 #
3301 # Return values
3302 # 'undef' on improper arguments or if there's an error
3303 # 1 on success
3304  
3305 my ($self, $session, $inputString, $standardCmd, $category, $check) = @_;
3306  
3307 # Local variables
3308 my (
3309 $obj,
3310 %customProfHash,
3311 );
3312  
3313 # Check for improper arguments
3314 if (
3315 ! defined $session || ! defined $inputString || ! defined $standardCmd
3316 || ! defined $category || defined $check
3317 ) {
3318 return $axmud::CLIENT->writeImproper($self->_objClass . '->unsetProfile', @_);
3319 }
3320  
3321 # Check there are no 'free' windows open in any session
3322 if ($axmud::CLIENT->desktopObj->freeWinHash) {
3323  
3324 return $self->error(
3325 $session, $inputString,
3326 'Can\'t delete a profile while there are \'free\' windows (such as edit,'
3327 . ' preference and wizard windows) open in any session - try closing them first',
3328 );
3329 }
3330  
3331 # Check there is a current profile of the right category
3332 if (! $session->ivExists('currentProfHash', $category)) {
3333  
3334 return $self->error(
3335 $session, $inputString,
3336 'There is no current ' . $category . ' profile',
3337 );
3338  
3339 } else {
3340  
3341 $obj = $session->ivShow('currentProfHash', $category);
3342 }
3343  
3344 # Guild/race profiles only - if there's a current character, inform it it has lost its
3345 # guild/race
3346 if ($category eq 'guild' || $category eq 'char') {
3347  
3348 if ($session->currentChar) {
3349  
3350 if ($category eq 'guild') {
3351 $session->currentChar->ivUndef('guild');
3352 } elsif ($category eq 'race') {
3353 $session->currentChar->ivUndef('race');
3354 }
3355 }
3356  
3357 # Character profiles only - if the character profile specifies a guild, race or custom
3358 # profiles as current profile, unset them, too
3359 } elsif ($category eq 'char') {
3360  
3361 if ($obj->guild) {
3362  
3363 $obj->ivUndef('guild');
3364 $session->pseudoCmd('unsetguild', 'hide_complete');
3365 }
3366  
3367 if ($obj->race) {
3368  
3369 $obj->ivUndef('race');
3370 $session->pseudoCmd('unsetrace', 'hide_complete');
3371 }
3372  
3373 if ($obj->customProfHash) {
3374  
3375 %customProfHash = $obj->customProfHash;
3376 foreach my $customProf (keys %customProfHash) {
3377  
3378 $session->pseudoCmd('unsetcustomprofile ' . $customProf, 'hide_complete');
3379 }
3380  
3381 $obj->ivEmpty('customProfHash');
3382 }
3383 }
3384  
3385 # Remove this profile's interfaces
3386 $session->resetProfileInterfaces($obj->name);
3387 # Unset any cages for this profile as current cages
3388 $session->unsetCurrentCages($obj->name, $category);
3389 # Unset the profile as a current defintitions
3390 $session->del_currentProf($category);
3391  
3392 # If the Status task's counters are running, reset their values, and turn them off
3393 if ($session->statusTask) {
3394  
3395 $session->statusTask->update_profiles();
3396 }
3397  
3398 return $self->complete(
3399 $session, $standardCmd,
3400 'The current ' . $category . ' profile has been unset as a current profile',
3401 );
3402 }
3403  
3404 sub cloneProfile {
3405  
3406 # Called by GA::Cmd::CloneGuild->do, CloneRace->do, CloneChar->do,
3407 # CloneCustomProfile->do
3408 # Clones a guild/race/char or custom profile
3409 #
3410 # Expected arguments
3411 # $session - The calling function's GA::Session
3412 # $inputString - The command actually typed, e.g. 'cg thief assassin'
3413 # $standardCmd - Standard version of the client command, e.g. 'cloneguild'
3414 # $original - The existing profile's name
3415 # $copy - The new cloned profile's name
3416 # $category - The category of profile - 'guild', 'race' or 'char' or a custom
3417 # profile category
3418 #
3419 # Return values
3420 # 'undef' on improper arguments or if there's an error
3421 # 1 on success
3422  
3423 my ($self, $session, $inputString, $standardCmd, $original, $copy, $category, $check) = @_;
3424  
3425 # Local variables
3426 my ($originalObj, $copyObj);
3427  
3428 # Check for improper arguments
3429 if (
3430 ! defined $session || ! defined $inputString || ! defined $standardCmd
3431 || ! defined $original || ! defined $copy || ! defined $category || defined $check
3432 ) {
3433 return $axmud::CLIENT->writeImproper($self->_objClass . '->cloneProfile', @_);
3434 }
3435  
3436 # Check that the $original profile exists, and that the $copy doesn't yet exist
3437 if (! $session->ivExists('profHash', $original)) {
3438  
3439 return $self->error(
3440 $session, $inputString,
3441 'Could not clone the ' . $category . ' profile \'' . $original . '\' - the profile'
3442 . ' doesn\'t exist',
3443 );
3444  
3445 } elsif ($session->ivExists('profHash', $copy)) {
3446  
3447 return $self->error(
3448 $session, $inputString,
3449 'Could not clone the ' . $category . ' profile \'' . $original . '\' - a profile'
3450 . ' called \'' . $copy . '\' already exists',
3451 );
3452  
3453 } else {
3454  
3455 $originalObj = $session->ivShow('profHash', $original);
3456 }
3457  
3458 # Check that $originalObj is the right category of profile
3459 if ($originalObj->category ne $category) {
3460  
3461 return $self->error(
3462 $session, $inputString,
3463 'The profile \'' . $original . '\' is a ' . $originalObj->category . ' profile',
3464 );
3465 }
3466  
3467 # Check that $copy is a valid profile name
3468 if (! $axmud::CLIENT->nameCheck($copy, 16)) {
3469  
3470 return $self->error(
3471 $session, $inputString,
3472 'Could not create the cloned ' . $category . ' profile \'' . $copy
3473 . '\' - invalid name',
3474 );
3475 }
3476  
3477 # Create the cloned profile
3478 $copyObj = $originalObj->clone($session, $copy);
3479 if (! $copyObj) {
3480  
3481 return $self->error(
3482 $session, $inputString,
3483 'Could not create the cloned ' . $category . ' profile \'' . $copy . '\'',
3484 );
3485 }
3486  
3487 # Create its associated cages
3488 if (! $session->cloneCages($originalObj, $copyObj)) {
3489  
3490 # Some objects couldn't be created. Destroy any newly-created cages, if any (don't
3491 # specify the TRUE flag because $obj isn't a current profile yet)
3492 $session->destroyCages($copyObj);
3493  
3494 return $self->error(
3495 $session, $inputString,
3496 'Could not create the cloned ' . $category .' profile \'' . $copy
3497 . '\' - errors while cloning cages',
3498 );
3499  
3500 } else {
3501  
3502 # Updates IVs
3503 $session->add_prof($copyObj);
3504 # Tell the current world it's acquired a new associated definiton
3505 $session->currentWorld->ivAdd('profHash', $copy, $category);
3506 # If it's a character profile, update more IVs
3507 if ($category eq 'char') {
3508  
3509 # Character's password and associated account names not yet known
3510 $session->currentWorld->ivAdd('passwordHash', $copy, undef);
3511 $session->currentWorld->ivAdd('accountHash', $copy, undef);
3512 }
3513  
3514 return $self->complete(
3515 $session, $standardCmd,
3516 'Created cloned ' . $category . ' profile \'' . $copy . '\'',
3517 );
3518 }
3519 }
3520  
3521 sub deleteProfile {
3522  
3523 # Called by GA::Cmd::DeleteGuild->do, DeleteRace->do, DeleteChar->do or
3524 # DeleteCustomProfile->do
3525 # Deletes a guild/race/char or custom profile
3526 #
3527 # Expected arguments
3528 # $session - The calling function's GA::Session
3529 # $inputString - The command actually typed, e.g. 'ug thief'
3530 # $standardCmd - Standard version of the client command, e.g. 'unsetguild'
3531 # $name - The profile's name
3532 # $category - The category of profile - 'guild', 'race' or 'char' or a custom
3533 # profile category
3534 #
3535 # Return values
3536 # 'undef' on improper arguments or if there's an error
3537 # 1 on success
3538  
3539 my ($self, $session, $inputString, $standardCmd, $name, $category, $check) = @_;
3540  
3541 # Local variables
3542 my (
3543 $obj,
3544 %customProfHash,
3545 );
3546  
3547 # Check for improper arguments
3548 if (
3549 ! defined $session || ! defined $inputString || ! defined $standardCmd
3550 || ! defined $name || ! defined $category || defined $check
3551 ) {
3552 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteProfile', @_);
3553 }
3554  
3555 # Check there are no 'free' windows open in any session
3556 if ($axmud::CLIENT->desktopObj->freeWinHash) {
3557  
3558 return $self->error(
3559 $session, $inputString,
3560 'Can\'t delete a profile while there are \'free\' windows (such as edit,'
3561 . ' preference and wizard windows) open in any session - try closing them first',
3562 );
3563 }
3564  
3565 # Check the profile exists
3566 if (! $session->ivExists('profHash', $name)) {
3567  
3568 return $self->error(
3569 $session, $inputString,
3570 'The profile \'' . $name . '\' doesn\'t exist',
3571 );
3572  
3573 } else {
3574  
3575 $obj = $session->ivShow('profHash', $name);
3576 }
3577  
3578 # Check the profile is the right category
3579 if ($obj->category ne $category) {
3580  
3581 return $self->error(
3582 $session, $inputString,
3583 'The profile \'' . $name . '\' is a ' . $obj->category . ' profile',
3584 );
3585 }
3586  
3587 # Delete a current profile
3588 if (defined $session->currentGuild && $session->currentGuild eq $obj) {
3589  
3590 # Remove this profile's interfaces
3591 $session->resetProfileInterfaces($obj->name);
3592 # Destroy its cages
3593 $session->destroyCages($obj, TRUE);
3594 # Unset the profile as a current defintition
3595 $session->del_currentProf($category);
3596 # Remove the profile
3597 $session->del_prof($obj);
3598  
3599 # Guild/race profiles only - if there's a current character, inform it that it has lost
3600 # its associated profile
3601 if ($category eq 'guild' || $category eq 'race') {
3602  
3603 if ($session->currentChar) {
3604  
3605 if ($category eq 'guild') {
3606 $session->currentChar->ivUndef('guild');
3607 } elsif ($category eq 'race') {
3608 $session->currentChar->ivUndef('race');
3609 }
3610 }
3611  
3612 # Character profiles only - if the character profile specifies a guild, race or custom
3613 # profiles as current profiles, unset them
3614 } elsif ($category eq 'char') {
3615  
3616 if ($obj->guild) {
3617  
3618 $obj->ivUndef('guild');
3619 $session->pseudoCmd('unsetguild', 'hide_complete');
3620 }
3621  
3622 if ($obj->race) {
3623  
3624 $obj->ivUndef('race');
3625 $session->pseudoCmd('unsetrace', 'hide_complete');
3626 }
3627  
3628 if ($obj->customProfHash) {
3629  
3630 %customProfHash = $obj->customProfHash;
3631 foreach my $customProf (keys %customProfHash) {
3632  
3633 $session->pseudoCmd('unsetcustomprofile ' . $customProf, 'hide_complete');
3634 }
3635  
3636 $obj->ivEmpty('customProfHash');
3637 }
3638 }
3639  
3640 # If there is a current world, remove the profile from its hash
3641 if ($session->currentWorld) {
3642  
3643 $session->currentWorld->ivDelete('profHash', $name);
3644 }
3645  
3646 # If it's a character profile, update more IVs
3647 if ($category eq 'char') {
3648  
3649 $session->currentWorld->ivDelete('passwordHash', $name);
3650 $session->currentWorld->ivDelete('accountHash', $name);
3651 }
3652  
3653 return $self->complete(
3654 $session, $standardCmd,
3655 'Deleted the current ' . $category . ' profile \'' . $name . '\'',
3656 );
3657  
3658 # Delete a non-current profile
3659 } else {
3660  
3661 # Destroy its cages
3662 $session->destroyCages($obj, FALSE);
3663 # Remove the profile
3664 $session->del_prof($obj);
3665  
3666 # If there is a current world, remove the profile from its hash
3667 if ($session->currentWorld) {
3668  
3669 $session->currentWorld->ivDelete('profHash', $name);
3670 }
3671  
3672 # If it's a character profile, update more IVs
3673 if ($category eq 'char') {
3674  
3675 $session->currentWorld->ivDelete('passwordHash', $name);
3676 $session->currentWorld->ivDelete('accountHash', $name);
3677 }
3678  
3679 return $self->complete(
3680 $session, $standardCmd,
3681 'Deleted the ' . $category . ' profile \'' . $name . '\'',
3682 );
3683 }
3684 }
3685  
3686 sub listProfile {
3687  
3688 # Called by GA::Cmd::ListGuild->do, ListRace->do, ListChar->do
3689 # Lists guild/race/char profiles
3690 #
3691 # Expected arguments
3692 # $session - The calling function's GA::Session
3693 # $inputString - The command actually typed, e.g. 'ug thief'
3694 # $standardCmd - Standard version of the client command, e.g. 'unsetguild'
3695 # $category - The category of profile - 'guild', 'race' or 'char'
3696 #
3697 # Return values
3698 # 'undef' on improper arguments or if there's an error
3699 # 1 on success
3700  
3701 my ($self, $session, $inputString, $standardCmd, $category, $check) = @_;
3702  
3703 # Local variables
3704 my (
3705 @profList, @sortedList,
3706 );
3707  
3708 # Check for improper arguments
3709 if (
3710 ! defined $session || ! defined $inputString || ! defined $standardCmd
3711 || ! defined $category || defined $check
3712 ) {
3713 return $axmud::CLIENT->writeImproper($self->_objClass . '->listProfile', @_);
3714 }
3715  
3716 # Get a list of profiles, and remove anything that's not the right category
3717 foreach my $obj ($session->ivValues('profHash')) {
3718  
3719 if ($obj->category eq $category) {
3720  
3721 push (@profList, $obj);
3722 }
3723 }
3724  
3725 # Sort the list
3726 @sortedList = sort {lc($a->name) cmp lc($b->name)} (@profList);
3727 if (! @sortedList) {
3728  
3729 return $self->complete(
3730 $session, $standardCmd,
3731 'The ' . $category . ' profile list is empty',
3732 );
3733 }
3734  
3735 # Display header
3736 $session->writeText(
3737 'List of ' . $category . ' profiles (* = current ' . $category . ')',
3738 );
3739  
3740 # Display list
3741 foreach my $obj (@sortedList) {
3742  
3743 my $column;
3744  
3745 if (
3746 $session->ivExists('currentProfHash', $category)
3747 && $session->ivShow('currentProfHash', $category) eq $obj
3748 ) {
3749 $column = ' * ';
3750 } else {
3751 $column = ' ';
3752 }
3753  
3754 $self->writeText($column . sprintf('%-16.16s', $obj->name));
3755 }
3756  
3757 # Display footer
3758 if (@sortedList == 1) {
3759  
3760 return $self->complete(
3761 $session, $standardCmd,
3762 'End of list (1 ' . $category . ' profile found)',
3763 );
3764  
3765 } else {
3766  
3767 return $self->complete(
3768 $session, $standardCmd,
3769 'End of list (' . scalar @sortedList . ' ' . $category . ' profiles found)',
3770 );
3771 }
3772 }
3773  
3774 sub addInterface {
3775  
3776 # Called by GA::Cmd::AddTrigger->do, AddAlias->do, AddMacro->do, AddTimer->do and
3777 # AddHook->do
3778 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
3779 # 'macro', 'timer' or 'hook')
3780 #
3781 # This function adds an independent trigger to a trigger cage in response to the client
3782 # command ';addtrigger'
3783 # Unless there is a superior cage with a trigger of the same name, also adds an active
3784 # trigger interface to the GA::Session's registry of active interfaces. In that case, if
3785 # there is an inferior cage with a trigger of the same name, the corresponding active
3786 # interface (if any) is destroyed. As a result, there will be exactly one active trigger
3787 # interface with this name
3788 #
3789 # Expected arguments
3790 # $session - The calling function's GA::Session
3791 # $inputString - The command actually typed, e.g. 'atr -p pattern -a action'
3792 # $standardCmd - Standard version of the client command, e.g. 'addtrigger'
3793 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
3794 # $categoryPlural - e.g. 'triggers'
3795 # $modelObj - The interface model object corresponding to $category
3796 # @args - The arguments specified by the user in the ';addtrigger' command
3797 #
3798 # Return values
3799 # 'undef' on improper arguments or if there's an error
3800 # 1 on success
3801  
3802 my (
3803 $self, $session, $inputString, $standardCmd, $category, $categoryPlural, $modelObj,
3804 @args,
3805 ) = @_;
3806  
3807 # Local variables
3808 my (
3809 $switch, $name, $value, $attribCount, $matchCount, $failFlag, $result, $profCategory,
3810 $profName, $profCount, $newObj, $newObjName, $proposedName, $cage, $package, $dummyObj,
3811 $newStimulus, $newResponse, $exitFlag,
3812 @superiorList, @inferiorList,
3813 %attribHash, %optionalAttribHash, %beforeHash, %afterHash,
3814 );
3815  
3816 # Check for improper arguments
3817 if (
3818 ! defined $session || ! defined $inputString || ! defined $standardCmd
3819 || ! defined $category || ! defined $categoryPlural || ! defined $modelObj || ! @args
3820 ) {
3821 return $axmud::CLIENT->writeImproper($self->_objClass . '->addInterface', @_);
3822 }
3823  
3824 # Extract group 4 (optional) switch options
3825 do {
3826  
3827 $exitFlag = TRUE;
3828  
3829 ($switch, $name, @args) = $self->extract('-b', 1, @args);
3830 if (defined $switch) {
3831  
3832 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -b switches
3833  
3834 if (! defined $name) {
3835  
3836 return $self->error(
3837 $session, $inputString,
3838 ucfirst($category) . ' interface not created - missing name',
3839 );
3840  
3841 } elsif (! exists $afterHash{$name}) {
3842  
3843 # If the user specifies the same interface name twice (or more), it's only used
3844 # once. If the same name is specified with the -b and -f flags, it's only
3845 # added to the 'after' hash
3846 $beforeHash{$name} = undef;
3847 }
3848 }
3849  
3850 ($switch, $name, @args) = $self->extract('-f', 1, @args);
3851 if (defined $switch) {
3852  
3853 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -f switches
3854  
3855 if (! defined $name) {
3856  
3857 return $self->error(
3858 $session, $inputString,
3859 ucfirst($category) . ' interface not created - missing name',
3860 );
3861  
3862 } else {
3863  
3864 # If the user specifies the same interface name twice (or more), it's only used
3865 # once
3866 $afterHash{$name} = undef;
3867 }
3868 }
3869  
3870 # Continue loop no more group 4 switches are found
3871 } until ($exitFlag);
3872  
3873 # Extract group 3 (optional) switch options
3874 foreach my $attrib ($modelObj->ivKeys('optionalSwitchHash')) {
3875  
3876 ($switch, $value, @args) = $self->extract(
3877 $modelObj->ivShow('optionalSwitchHash', $attrib),
3878 1,
3879 @args,
3880 );
3881  
3882 if (defined $switch) {
3883  
3884 if (! exists $attribHash{$attrib}) {
3885  
3886 $attribHash{$attrib} = $value;
3887 if ($modelObj->ivExists('optionalAttribHash', $attrib)) {
3888  
3889 $optionalAttribHash{$attrib} = $value;
3890 }
3891  
3892 } else {
3893  
3894 # Optional switch options can't be specified more than once
3895 return $self->error(
3896 $session, $inputString,
3897 ucfirst($category) . ' interface not created - duplicate optional switch'
3898 . ' patterns',
3899 );
3900 }
3901 }
3902 }
3903  
3904 # Extract group 2 (compulsory) switch options
3905 $attribCount = 0;
3906 $matchCount = 0;
3907 $failFlag = 0;
3908 foreach my $attrib ($modelObj->ivKeys('compulsorySwitchHash')) {
3909  
3910 $attribCount++;
3911 ($switch, $value, @args) = $self->extract(
3912 $modelObj->ivShow('compulsorySwitchHash', $attrib),
3913 1,
3914 @args,
3915 );
3916  
3917 if (defined $switch) {
3918  
3919 if (! exists $attribHash{$attrib}) {
3920  
3921 $matchCount++;
3922 $attribHash{$attrib} = $value;
3923 if ($modelObj->ivExists('optionalAttribHash', $attrib)) {
3924  
3925 $optionalAttribHash{$attrib} = $value;
3926 }
3927  
3928 } else {
3929  
3930 # Compulsory switch options can't be specified more than once
3931 $failFlag = TRUE;
3932 }
3933 }
3934 }
3935  
3936 # Check that all group 2 (compulsory) switch options were found exactly one once
3937 if ($attribCount != $matchCount || $failFlag) {
3938  
3939 return $self->error(
3940 $session, $inputString,
3941 ucfirst($category) . ' interface not created - missing or duplicate compulsory'
3942 . ' switch options',
3943 );
3944 }
3945  
3946 # Extract profile (group 1) switch options
3947 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
3948 $session,
3949 $inputString,
3950 $category,
3951 'add',
3952 @args,
3953 );
3954  
3955 if (! defined $profCount) {
3956  
3957 # Error in ->extractProfileSwitches - error message already displayed
3958 return undef;
3959  
3960 # 0 or 1 associated profiles can be specified, but no more
3961 } elsif ($profCount > 1) {
3962  
3963 return $self->error(
3964 $session, $inputString,
3965 'Can\'t create an interface associated with multiple profiles - choose one from'
3966 . ' -w, -g, -r, -c, -x, -d',
3967 );
3968  
3969 # If no associated profile specified, use the current world as the associated profile
3970 } elsif ($profCount == 0) {
3971  
3972 $profCount++;
3973 $profCategory = 'world';
3974 $profName = $session->currentWorld->name;
3975 }
3976  
3977 # @args should now be empty. If not, return an error message
3978 if (@args) {
3979  
3980 return $self->improper($session, $inputString);
3981 }
3982  
3983 # For macros, the stimulus can be one of Axmud's standard keycodes (like 'f5') or a keycode
3984 # string (like 'shift f5').
3985 # Keycodes in a keycode string must be in a given order (i.e. 'ctrl shift f5', not
3986 # 'shift ctrl f5' or even 'f5 shift ctrl'). Change the order of words in the keycode
3987 # string, if necessary
3988 if ($category eq 'macro') {
3989  
3990 $attribHash{'stimulus'} = $axmud::CLIENT->convertKeycodeString($attribHash{'stimulus'});
3991 }
3992  
3993 # %attribHash doesn't contain all possible attributes. Fill it in, using default values
3994 # for any attributes that haven't yet been entered into it
3995 foreach my $attrib ($modelObj->ivKeys('optionalAttribHash')) {
3996  
3997 if (! exists $attribHash{$attrib}) {
3998  
3999 $attribHash{$attrib} = $modelObj->ivShow('optionalAttribHash', $attrib);
4000 $optionalAttribHash{$attrib}
4001 = $modelObj->ivShow('optionalAttribHash', $attrib);
4002 }
4003 }
4004  
4005 # Decide what name to assign to the trigger
4006 if (defined $attribHash{'name'}) {
4007  
4008 # Use the name specified by the user, but only use the first 32 characters
4009 if (length $attribHash{'name'} > 32) {
4010  
4011 $attribHash{'name'} = substr($attribHash{'name'}, 0, 32);
4012 }
4013  
4014 $newObjName = $attribHash{'name'};
4015  
4016 } else {
4017  
4018 # Otherwise, use the ->stimulus as the name
4019  
4020 # We have a problem, for example in an alias with a stimulus (pattern) '^myalias$'
4021 # The user can't type ';deletealias ^myalias$' because doing that will cause the
4022 # pattern to be replaced by its substitution, before Axmud can react to the command
4023 # The solution is to change the pattern a little, before using it as the name. If it
4024 # contains any alphanumeric characters, remove them; otherwise introduce an
4025 # underline at the beginning of the stimulus to distinguish it from its name
4026 $proposedName = $newObjName = $attribHash{'stimulus'};
4027  
4028 # Remove non-alphanumeric characters (first transforming whitespaces to underlines)
4029 # For the benefit of timers whose stimulus is a clock time in the form HH:MM, change the
4030 # colon to an underline
4031 $newObjName =~ s/\:/_/g;
4032 $newObjName =~ s/\s/_/g;
4033 $newObjName =~ s/\W//g;
4034 # Remove any initial underline characters, and replace duplicate underline characters
4035 # with a single one
4036 $newObjName =~ s/^\_+//;
4037 $newObjName =~ s/\_+/_/g;
4038 if ($proposedName eq $newObjName) {
4039  
4040 # The proposed name didn't include any non-alphanumeric characters, so give it a
4041 # generic name
4042 $newObjName = $category . '_' . $proposedName;
4043  
4044 } elsif ($category eq 'timer') {
4045  
4046 # The timer stimulus will have only numbers (and possibly underlines) in its name,
4047 # so for aesthetics, convert something like '25' to 'timer_25'
4048 $newObjName = $category . '_' . $newObjName;
4049 }
4050  
4051 # Don't allow the creation of automatic names which are very long
4052 if (length $newObjName > 32) {
4053  
4054 $newObjName = substr($newObjName, 0, 32);
4055 }
4056  
4057 $attribHash{'name'} = $newObjName;
4058 }
4059  
4060 # If the 'enabled' attribute wasn't specified in the client command, set it now
4061 if (! exists $attribHash{'enabled'}) {
4062  
4063 $attribHash{'enabled'} = TRUE; # Interface enabled by default
4064  
4065 } else {
4066  
4067 # Convert values like '1', 't', 'True' to TRUE, and convert values like '0',
4068 # 'f', 'False' to FALSE
4069 $attribHash{'enabled'} = $self->convertTrueFalse($attribHash{'enabled'});
4070 }
4071  
4072 # Check the validity of the stimulus/response values. Create a dummy interface so that we
4073 # can check its ->checkAttribValue method, which may modify the values (a little)
4074 $package = 'Games::Axmud::Interface::' . ucfirst($category);
4075 $dummyObj = $package->new($session, 'test', 'test', 'test', 1);
4076  
4077 $newStimulus = $dummyObj->checkAttribValue(
4078 $session,
4079 'stimulus',
4080 $attribHash{'stimulus'},
4081 $modelObj->ivShow('attribTypeHash', 'stimulus'),
4082 );
4083  
4084 if (! defined $newStimulus) {
4085  
4086 return $self->error(
4087 $session, $inputString,
4088 'Can\'t create interface - invalid stimulus \'' . $attribHash{'stimulus'}
4089 . '\' (should be type \'' . $modelObj->ivShow('attribTypeHash', 'stimulus')
4090 . '\')',
4091 );
4092  
4093 } else {
4094  
4095 $attribHash{'stimulus'} = $newStimulus;
4096 }
4097  
4098 $newResponse = $dummyObj->checkAttribValue(
4099 $session,
4100 'response',
4101 $attribHash{'response'},
4102 $modelObj->ivShow('attribTypeHash', 'response'),
4103 );
4104  
4105 if (! defined $newResponse) {
4106  
4107 return $self->error(
4108 $session, $inputString,
4109 'Can\'t create interface - invalid response \'' . $attribHash{'response'}
4110 . '\' (should be type \'' . $modelObj->ivShow('attribTypeHash', 'response')
4111 . '\')',
4112 );
4113  
4114 } else {
4115  
4116 $attribHash{'response'} = $newResponse;
4117 }
4118  
4119 # Find the cage matching the specified profile
4120 $cage = $session->findCage($category, $profName);
4121 if (! $cage) {
4122  
4123 return $self->error(
4124 $session, $inputString,
4125 'Can\'t create interface because the ' . $category . ' cage for \'' . $profName
4126 . '\' is missing',
4127 );
4128 }
4129  
4130 # Check that the cage doesn't already have a trigger with the same name
4131 if ($cage->ivExists('interfaceHash', $newObjName)) {
4132  
4133 return $self->error(
4134 $session, $inputString,
4135 'Can\'t create interface because the ' . $category . ' cage already has an'
4136 . ' interface with the name \'' . $newObjName .'\'',
4137 );
4138 }
4139  
4140 # Create the interface object
4141 $newObj = $package->new(
4142 $session,
4143 $attribHash{'name'},
4144 $attribHash{'stimulus'},
4145 $attribHash{'response'},
4146 $attribHash{'enabled'},
4147 );
4148  
4149 if (! $newObj) {
4150  
4151 return $self->error(
4152 $session, $inputString,
4153 'General error creating the interface object',
4154 );
4155  
4156 } else {
4157  
4158 # Set the interface object's attributes
4159 if (%optionalAttribHash) {
4160  
4161 $result = $newObj->set_attribHash($session, %optionalAttribHash);
4162 if (! $result) {
4163  
4164 return $self->error(
4165 $session, $inputString,
4166 'Invalid attribute',
4167 );
4168 }
4169 }
4170  
4171 # Set the interface object's before and after hashes
4172 if (%beforeHash || %afterHash) {
4173  
4174 $result = $newObj->set_beforeAfterHashes($session, \%beforeHash, \%afterHash);
4175 if (! $result) {
4176  
4177 return $self->error(
4178 $session, $inputString,
4179 'Invalid before/after interfaces',
4180 );
4181 }
4182 }
4183 }
4184  
4185 # Tell the trigger cage that it has received a new trigger
4186 $cage->ivAdd('interfaceHash', $newObj->name, $newObj);
4187  
4188 # Get a list of profiles with higher priority than this one
4189 @superiorList = $session->findSuperiorList($profCategory);
4190 # Get a list of profiles with lower priority than this one
4191 @inferiorList = $session->findInferiorList($profCategory);
4192  
4193 # Check whether there are any triggers with the same name, belonging to a cage associated
4194 # with a superior profile to this cage's profile. If none, create an interface for the
4195 # trigger
4196 # Also, if there is a trigger, with the same name but belonging to a cage associated with an
4197 # inferior profile to this cage's profile, destroy its interface
4198 # As a result, there should be exactly one interface for a trigger with this name, no matter
4199 # how many triggers with that name exist
4200 $result = $session->injectInterface(
4201 $newObj,
4202 $newObjName,
4203 $profName,
4204 \@superiorList,
4205 \@inferiorList,
4206 );
4207  
4208 if (! $result) {
4209  
4210 return $self->error(
4211 $session, $inputString,
4212 'General error creating ' . $category . ' \'' . $newObjName . '\'',
4213 );
4214  
4215 } elsif ($result == 1) {
4216  
4217 return $self->complete(
4218 $session, $standardCmd,
4219 'Active ' . $category . ' interface \'' . $newObjName . '\' created',
4220 );
4221  
4222 } else {
4223  
4224 return $self->complete(
4225 $session, $standardCmd,
4226 'Inactive ' . $category . ' interface \'' . $newObjName . '\' created',
4227 );
4228 }
4229 }
4230  
4231 sub modifyInterface {
4232  
4233 # Called by GA::Cmd::ModifyTrigger->do, ModifyAlias->do, ModifyMacro->do,
4234 # ModifyTimer->do and ModifyHook->do
4235 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
4236 # 'macro', 'timer' or 'hook')
4237 #
4238 # This function modifies the attributes of an independent trigger stored in a trigger
4239 # cage. If there's a corresponding active interface, it is also modified
4240 #
4241 # This function can also be called to modify an active interface directly, without
4242 # changing the corresponding independent trigger stored in a trigger cage (if any)
4243 #
4244 # Expected arguments
4245 # $session - The calling function's GA::Session
4246 # $inputString - The command actually typed, e.g. 'mtr -p pattern -a action'
4247 # $standardCmd - Standard version of the client command, e.g. 'modifytrigger'
4248 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
4249 # $categoryPlural - e.g. 'triggers'
4250 # $modelObj - The interface model object corresponding to $category
4251 # @args - The arguments specified by the user in the ';modifytrigger' command
4252 #
4253 # Return values
4254 # 'undef' on improper arguments or if there's an error
4255 # 1 on success
4256  
4257 my (
4258 $self, $session, $inputString, $standardCmd, $category, $categoryPlural, $modelObj,
4259 @args,
4260 ) = @_;
4261  
4262 # Local variables
4263 my (
4264 $switch, $value, $attribCount, $profCount, $profCategory, $profName, $interface,
4265 $interfaceObj, $result, $currentObj, $currentObjName, $cage, $exitFlag, $name,
4266 %beforeHash, %afterHash, %beforeRemoveHash, %afterRemoveHash, %attribHash,
4267 );
4268  
4269 # Check for improper arguments
4270 if (
4271 ! defined $session || ! defined $inputString || ! defined $standardCmd
4272 || ! defined $category || ! defined $categoryPlural || ! defined $modelObj || ! @args
4273 ) {
4274 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyInterface', @_);
4275 }
4276  
4277 # Extract group 4 (optional) switch options
4278 do {
4279  
4280 $exitFlag = TRUE;
4281  
4282 ($switch, $name, @args) = $self->extract('-b', 1, @args);
4283 if (defined $switch) {
4284  
4285 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -b switches
4286  
4287 if (! defined $name) {
4288  
4289 return $self->error(
4290 $session, $inputString,
4291 ucfirst($category) . ' interface not created - missing name',
4292 );
4293  
4294 } elsif (! exists $afterHash{$name}) {
4295  
4296 # If the user specifies the same interface name twice (or more), it's only used
4297 # once. If the same name is specified with the -b and -f flags, it's only
4298 # added to the 'after' hash
4299 $beforeHash{$name} = undef;
4300 }
4301 }
4302  
4303 ($switch, $name, @args) = $self->extract('-f', 1, @args);
4304 if (defined $switch) {
4305  
4306 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -f switches
4307  
4308 if (! defined $name) {
4309  
4310 return $self->error(
4311 $session, $inputString,
4312 ucfirst($category) . ' interface not created - missing name',
4313 );
4314  
4315 } else {
4316  
4317 # If the user specifies the same interface name twice (or more), it's only used
4318 # once
4319 $afterHash{$name} = undef;
4320 }
4321 }
4322  
4323 ($switch, $name, @args) = $self->extract('-y', 1, @args);
4324 if (defined $switch) {
4325  
4326 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -b switches
4327  
4328 if (! defined $name) {
4329  
4330 return $self->error(
4331 $session, $inputString,
4332 ucfirst($category) . ' interface not created - missing name',
4333 );
4334  
4335 } elsif (! exists $afterRemoveHash{$name}) {
4336  
4337 # If the user specifies the same interface name twice (or more), it's only used
4338 # once. If the same name is specified with the -y and -z flags, it's only
4339 # added to the 'after' hash
4340 $beforeRemoveHash{$name} = undef;
4341 }
4342 }
4343  
4344 ($switch, $name, @args) = $self->extract('-z', 1, @args);
4345 if (defined $switch) {
4346  
4347 $exitFlag = FALSE; # Allow the loop to repeat, looking for more -f switches
4348  
4349 if (! defined $name) {
4350  
4351 return $self->error(
4352 $session, $inputString,
4353 ucfirst($category) . ' interface not created - missing name',
4354 );
4355  
4356 } else {
4357  
4358 # If the user specifies the same interface name twice (or more), it's only used
4359 # once
4360 $afterRemoveHash{$name} = undef;
4361 }
4362 }
4363  
4364 # Continue loop no more group 4 switches are found
4365 } until ($exitFlag);
4366  
4367 # Extract group 3 (optional) switch options
4368 foreach my $attrib ($modelObj->ivKeys('optionalSwitchHash')) {
4369  
4370 ($switch, $value, @args) = $self->extract(
4371 $modelObj->ivShow('optionalSwitchHash', $attrib),
4372 1,
4373 @args,
4374 );
4375  
4376 if (defined $switch) {
4377  
4378 if (! exists $attribHash{$attrib}) {
4379  
4380 $attribCount++;
4381 $attribHash{$attrib} = $value;
4382  
4383 } else {
4384  
4385 # Optional switch patterns can't be specified more than once
4386 return $self->error(
4387 $session, $inputString,
4388 ucfirst($category) . ' interface not modified - duplicate optional switch'
4389 . ' patterns',
4390 );
4391 }
4392 }
4393 }
4394  
4395 # Extract group 2 (compulsory) switch options
4396 foreach my $attrib ($modelObj->ivKeys('compulsorySwitchHash')) {
4397  
4398 ($switch, $value, @args) = $self->extract(
4399 $modelObj->ivShow('compulsorySwitchHash', $attrib),
4400 1,
4401 @args,
4402 );
4403  
4404 if (defined $switch) {
4405  
4406 if (! exists $attribHash{$attrib}) {
4407  
4408 $attribCount++;
4409 $attribHash{$attrib} = $value;
4410  
4411 } else {
4412  
4413 # Compulsory switch options can't be specified more than once
4414 return $self->error(
4415 $session, $inputString,
4416 ucfirst($category) . ' interface not modified - duplicate compulsory'
4417 . ' switch options',
4418 );
4419 }
4420 }
4421 }
4422  
4423 # Extract profile (group 1) switch options
4424 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
4425 $session,
4426 $inputString,
4427 $category,
4428 'modify',
4429 @args,
4430 );
4431  
4432 if (! defined $profCount) {
4433  
4434 # Error in ->extractProfileSwitches - error message already displayed
4435 return undef;
4436 }
4437  
4438 # Extract active interface (group 0) switch options
4439 ($switch, $interface, @args) = $self->extract('i', 1, @args);
4440 if (defined $switch) {
4441  
4442 if (! defined $interface) {
4443  
4444 return $self->error(
4445 $session, $inputString,
4446 'Missing switch arguments - use \'-i <name>\' or \'-i <number>\'',
4447 );
4448  
4449 } elsif (%beforeHash || %afterHash || %beforeRemoveHash || %afterRemoveHash) {
4450  
4451 return $self->error(
4452 $session, $inputString,
4453 'The switches -b, -y, -f and -z can\'t be used to modify active interfaces'
4454 . ' (try \';moveactiveinterface\' instead)',
4455 );
4456 }
4457 }
4458  
4459 # At least one group 2 (compulsory) or group 3 (optional) switch options must be present
4460 if (! $attribCount) {
4461  
4462 return $self->error(
4463 $session, $inputString,
4464 'Can\'t modify ' . $category . ' interface - no attributes specified',
4465 );
4466 }
4467  
4468 # ;modifytrigger (etc) can't be used to modify the 'name' attribute
4469 if (exists $attribHash{'name'}) {
4470  
4471 return $self->error(
4472 $session, $inputString,
4473 'Can\'t modify active ' . $category . ' interface - the \'name\' attribute'
4474 . ' can\'t be modified',
4475 );
4476 }
4477  
4478 # For macros, the stimulus can be one of Axmud's standard keycodes (like 'f5') or a keycode
4479 # string (like 'shift f5').
4480 # Keycodes in a keycode string must be in a given order (i.e. 'ctrl shift f5', not
4481 # 'shift ctrl f5' or even 'f5 shift ctrl'). Change the order of words in the keycode
4482 # string, if necessary
4483 if ($category eq 'macro' && exists $attribHash{'stimulus'}) {
4484  
4485 $attribHash{'stimulus'} = $axmud::CLIENT->convertKeycodeString($attribHash{'stimulus'});
4486 }
4487  
4488 # Now, if the group 0 '-i' switch was specified, modify only the active interface - don't
4489 # modify the corresponding parent interface (the one stored in a cage)
4490 if (defined $interface) {
4491  
4492 # @args should now be empty. If not, return an error message
4493 if (@args) {
4494  
4495 return $self->improper($session, $inputString);
4496 }
4497  
4498 # Group 0 and 1 switches can't be combined
4499 if ($profCount) {
4500  
4501 return $self->error(
4502 $session, $inputString,
4503 'Can\'t modify active ' . $category . ' interface - can\'t combine the -i'
4504 . ' switch with -w, -g, -r, -c, -x or -d',
4505 );
4506 }
4507  
4508 # If the -i switch was specified, and the user also specified a trigger name using the
4509 # -n switch, it's an error (this command mustn't be used to modify the interface name)
4510 if (exists $attribHash{'name'}) {
4511  
4512 return $self->error(
4513 $session, $inputString,
4514 'The ' . $category . ' interface\'s name can\'t be modified, once it is'
4515 . ' made active',
4516 );
4517 }
4518  
4519 # Check that the specified interface exists
4520 if (
4521 ! $session->ivExists('interfaceHash', $interface)
4522 && ! $session->ivExists('interfaceNumHash', $interface)
4523 ) {
4524 return $self->error(
4525 $session, $inputString,
4526 'Unrecognised active ' . $category . ' interface \'' . $interface . '\'',
4527 );
4528 }
4529  
4530 # If $interface is a number, convert it into an interface name
4531 if ($session->ivExists('interfaceNumHash', $interface)) {
4532  
4533 $interface = $session->ivShow('interfaceNumHash', $interface)->name;
4534 }
4535  
4536 $interfaceObj = $session->ivShow('interfaceHash', $interface);
4537  
4538 # Modify the interface
4539 $result = $interfaceObj->modifyAttribs($session, %attribHash);
4540 if (! $result) {
4541  
4542 return $self->error(
4543 $session, $inputString,
4544 'General error modifying active ' . $category . ' interface \''
4545 . $interface . '\'',
4546 );
4547  
4548 } else {
4549  
4550 return $self->complete(
4551 $session, $standardCmd,
4552 'Active ' . $category . ' interface \'' . $interface . '\' modified (but'
4553 . ' the corresponding cage interface, if any, was not modified)',
4554 );
4555 }
4556  
4557 # Otherwise, if a group 1 switch was specified, modify the specified interface stored in the
4558 # cage. If there's a corresponding active interface, modify that, too
4559 } else {
4560  
4561 # 0 or 1 associated profiles can be specified, but no more
4562 if ($profCount > 1) {
4563  
4564 return $self->error(
4565 $session, $inputString,
4566 'Can\'t modify an interface associated with multiple profiles - choose one from'
4567 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
4568 );
4569  
4570 # If no associatied profile specified, and the -i switch wasn't used, use the current
4571 # world as the associated profile
4572 } elsif ($profCount == 0) {
4573  
4574 $profCount++;
4575 $profCategory = 'world';
4576 $profName = $session->currentWorld->name;
4577 }
4578  
4579 # @args should now contain a single element, <name>. Check it exists
4580 if (@args > 1) {
4581  
4582 return $self->improper($session, $inputString);
4583  
4584 } elsif (! @args) {
4585  
4586 return $self->error(
4587 $session, $inputString,
4588 'Please specify the name of the ' . $category . ' interface to modify (or'
4589 . ' use \'-i <name>\' or \'-i <number>\'',
4590 );
4591  
4592 } else {
4593  
4594 $currentObjName = $args[0];
4595 }
4596  
4597 # Find the cage matching the specified profile
4598 $cage = $session->findCage($category, $profName);
4599 if (! $cage) {
4600  
4601 return $self->error(
4602 $inputString,
4603 'Can\'t modify ' . $category . ' interface because the ' . $category
4604 . ' cage for \'' . $profName . '\' is missing',
4605 );
4606 }
4607  
4608 # Check that the cage has a trigger with this name
4609 if (! $cage->ivExists('interfaceHash', $currentObjName)) {
4610  
4611 if ($category eq 'alias') {
4612  
4613 return $self->error(
4614 $session, $inputString,
4615 'Can\'t modify alias interface because the alias cage doesn\'t'
4616 . 'have an alias with the name \'' . $currentObjName
4617 . '\'',
4618 );
4619  
4620 } else {
4621  
4622 return $self->error(
4623 $session, $inputString,
4624 'Can\'t modify ' . $category . ' interface because the ' . $category
4625 . ' cage doesn\'t have a ' . $category . ' with the name \''
4626 . $currentObjName .'\'',
4627 );
4628 }
4629  
4630 } else {
4631  
4632 # Get the blessed reference of the trigger object (but don't consult inferior cages)
4633 $currentObj = $cage->ivShow('interfaceHash', $currentObjName);
4634 if (! $currentObj) {
4635  
4636 return $self->error(
4637 $session, $inputString,
4638 'General error modifying the ' . $category . ' interface object \''
4639 . $currentObjName . '\'',
4640 );
4641 }
4642 }
4643  
4644 # Modify any of the attributes that were specified
4645 if (%attribHash) {
4646  
4647 $result = $currentObj->modifyAttribs($session, %attribHash);
4648 if (! $result) {
4649  
4650 return $self->complete(
4651 $session, $inputString,
4652 'Failed to modify the ' . $category . ' interface \''
4653 . $currentObj->name . '\'',
4654 );
4655 }
4656 }
4657  
4658 # Modify the before/after hashes, if specified
4659 if (%beforeHash || %afterHash || %beforeRemoveHash || %afterRemoveHash) {
4660  
4661 $result = $currentObj->set_beforeAfterHashes(
4662 $session,
4663 \%beforeHash, \%afterHash,
4664 \%beforeRemoveHash, \%afterRemoveHash,
4665 );
4666  
4667 if (! $result) {
4668  
4669 return $self->error(
4670 $session, $inputString,
4671 'Failed to modify the ' . $category . ' interface \''
4672 . $currentObj->name . '\'',
4673 );
4674 }
4675 }
4676  
4677 # If there's an active interface based upon this interface object, we need to update the
4678 # active interface, too. We must do this in every session that shares the same world
4679  
4680 # Do the update in every affected session, except this one
4681 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
4682  
4683 if (
4684 $otherSession->currentWorld eq $session->currentWorld
4685 && $otherSession ne $self
4686 ) {
4687 $otherSession->updateInterfaces($currentObj, %attribHash);
4688 }
4689 }
4690  
4691 # Now apply to this session
4692 if (! $session->updateInterfaces($currentObj, %attribHash)) {
4693  
4694 return $self->complete(
4695 $session, $standardCmd,
4696 ucfirst($category) . ' interface \'' . $currentObj->name . '\' modified, but'
4697 . ' but general error while modifying the corresponding active interface(s)',
4698 );
4699  
4700 } else {
4701  
4702 # There is no active interface based on this trigger (etc)
4703 return $self->complete(
4704 $session, $standardCmd,
4705 'Inactive ' . $category . ' interface \'' . $currentObjName . '\' modified',
4706 );
4707 }
4708 }
4709 }
4710  
4711 sub deleteInterface {
4712  
4713 # Called by GA::Cmd::DeleteTrigger->do, DeleteAlias->do, DeleteMacro->do,
4714 # DeleteTimer->do and DeleteHook->do
4715 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
4716 # 'macro', 'timer' or 'hook')
4717 #
4718 # This function deletes an independent trigger stored in a trigger cage. If there's a
4719 # corresponding active interface, it is also deleted
4720 #
4721 # This function can also be called to delete an active interface directly, without
4722 # deleting the corresponding independent trigger stored in a trigger cage (if any)
4723 #
4724 # Expected arguments
4725 # $session - The calling function's GA::Session
4726 # $inputString - The command actually typed, e.g. 'dtr mytrig'
4727 # $standardCmd - Standard version of the client command, e.g. 'deletetrigger'
4728 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
4729 # $categoryPlural - e.g. 'triggers'
4730 # @args - The arguments specified by the user in the ';deletetrigger' command
4731 #
4732 # Return values
4733 # 'undef' on improper arguments or if there's an error
4734 # 1 on success
4735  
4736 my (
4737 $self, $session, $inputString, $standardCmd, $category, $categoryPlural,
4738 @args,
4739 ) = @_;
4740  
4741 # Local variables
4742 my (
4743 $profCount, $profCategory, $profName, $currentObj, $currentObjName, $cage, $result,
4744 @inferiorList
4745 );
4746  
4747 # Check for improper arguments
4748 if (
4749 ! defined $session || ! defined $inputString || ! defined $standardCmd
4750 || ! defined $category || ! defined $categoryPlural || ! @args
4751 ) {
4752 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteInterface', @_);
4753 }
4754  
4755 # Extract profile (group 1) switch option
4756 ($profCount, $profCategory, $profName, @args) = $self->extractProfileSwitches(
4757 $session,
4758 $inputString,
4759 $category,
4760 'delete',
4761 @args,
4762 );
4763  
4764 if (! defined $profCount) {
4765  
4766 # Error in ->extractProfileSwitches()
4767 return undef;
4768  
4769 # 0 or 1 associated profiles can be specified, but no more
4770 } elsif ($profCount > 1) {
4771  
4772 return $self->error(
4773 $session, $inputString,
4774 'Can\'t delete an interface associated with multiple profiles - choose one from'
4775 . ' -w, -g, -r, -c, -x, -d (or a named profile)',
4776 );
4777  
4778 # If no associatied profile specified, use the current world as the associated profile
4779 } elsif ($profCount == 0) {
4780  
4781 $profCount++;
4782 $profCategory = 'world';
4783 $profName = $session->currentWorld->name;
4784 }
4785  
4786 # @args should now contain a single element, <name>. Check it exists
4787 if (@args > 1) {
4788  
4789 return $self->improper($session, $inputString);
4790  
4791 } elsif (! @args) {
4792  
4793 return $self->error(
4794 $session, $inputString,
4795 'Please specify the name of the ' . $category . ' interface to delete',
4796 );
4797  
4798 } else {
4799  
4800 $currentObjName = $args[0];
4801 }
4802  
4803 # Find the cage matching the specified profile
4804 $cage = $session->findCage($category, $profName);
4805 if (! $cage) {
4806  
4807 return $self->error(
4808 $inputString,
4809 'Can\'t delete ' . $category . ' interface because the ' . $category
4810 . ' cage for \'' . $profName . '\' is missing',
4811 );
4812 }
4813  
4814 # Check that the cage has a trigger with this name
4815 if (! $cage->ivExists('interfaceHash', $currentObjName)) {
4816  
4817 if ($category eq 'alias') {
4818  
4819 return $self->error(
4820 $session, $inputString,
4821 'Can\'t delete alias interface because the alias cage doesn\'t have an alias'
4822 . ' with the name \'' . $currentObjName . '\'',
4823 );
4824  
4825 } else {
4826  
4827 return $self->error(
4828 $session, $inputString,
4829 'Can\'t delete ' . $category . ' interface because the ' . $category
4830 . ' cage doesn\'t have a ' . $category . ' with the name \'' . $currentObjName
4831 . '\'',
4832 );
4833 }
4834  
4835 } else {
4836  
4837 # Get the blessed reference of the trigger object (but don't consult inferior cages)
4838 $currentObj = $cage->ivShow('interfaceHash', $currentObjName);
4839 if (! $currentObj) {
4840  
4841 return $self->error(
4842 $session, $inputString,
4843 'General error deleting the ' . $category . ' interface object \''
4844 . $currentObjName . '\'',
4845 );
4846 }
4847 }
4848  
4849 # Delete the interface object
4850 $cage->ivDelete('interfaceHash', $currentObjName);
4851  
4852 # Get a list of profiles with lower priority than this one
4853 @inferiorList = $session->findInferiorList($profCategory);
4854  
4855 # If there's an active interface based on this trigger object, delete it also. At the
4856 # same time, if there's a trigger with the same name, belonging to an inferior
4857 # cage, create an interface for it to make it active
4858 $result = $session->recallInterface($currentObj, $currentObjName, \@inferiorList);
4859  
4860 if (! $result || $result == 1) {
4861  
4862 return $self->error(
4863 $session, $inputString,
4864 'General error deleting ' . $category . ' interface',
4865 );
4866  
4867 } elsif ($result == 2) {
4868  
4869 return $self->error(
4870 $session, $inputString,
4871 'Deleted ' . $category . ' interface, but couldn\'t create interface for a '
4872 . $category . ' belonging to an inferior profile',
4873 );
4874  
4875 } elsif ($result == 3) {
4876  
4877 return $self->complete(
4878 $session, $standardCmd,
4879 'Active ' . $category . ' interface \'' . $currentObjName . '\' deleted and'
4880 . ' interface created for a ' . $category . ' belonging to an inferior profile',
4881 );
4882  
4883 } elsif ($result == 4) {
4884  
4885 return $self->complete(
4886 $session, $standardCmd,
4887 'Active ' . $category . ' interface \'' . $currentObjName . '\' deleted (and'
4888 . ' no other interface created to replace it)',
4889 );
4890 }
4891 }
4892  
4893 sub listInterface {
4894  
4895 # Called by GA::Cmd::ListTrigger->do, ListAlias->do, ListMacro->do, ListTimer->do and
4896 # ListHook->do
4897 # (For the whole of this function, 'trigger' is taken to mean any of 'trigger', 'alias',
4898 # 'macro', 'timer' or 'hook')
4899 #
4900 # Lists triggers stored in a trigger cage, or lists active triggers
4901 #
4902 # Expected arguments
4903 # $session - The calling function's GA::Session
4904 # $inputString - The command actually typed, e.g. 'ltr -w'
4905 # $standardCmd - Standard version of the client command, e.g. 'listtrigger'
4906 # $category - 'trigger', 'alias', 'macro', 'timer', 'hook'
4907 # $categoryPlural - e.g. 'triggers'
4908 #
4909 # Optional arguments
4910 # @args - The arguments specified by the user in the ';listtrigger' command
4911 # (an empty list if none specified)
4912 #
4913 # Return values
4914 # 'undef' on improper arguments or if there's an error
4915 # 1 on success
4916  
4917 my (
4918 $self, $session, $inputString, $standardCmd, $category, $categoryPlural,
4919 @args,
4920 ) = @_;
4921  
4922 # Local variables
4923 my (
4924 $switch, $arg, $profObj, $owner, $cage, $string,
4925 @list,
4926 %hash, %modifiedHash,
4927 );
4928  
4929 # Check for improper arguments
4930 if (
4931 ! defined $session || ! defined $inputString || ! defined $standardCmd
4932 || ! defined $category || ! defined $categoryPlural
4933 ) {
4934 return $axmud::CLIENT->writeImproper($self->_objClass . '->listInterface', @_);
4935 }
4936  
4937 # Extract the optional switch and argument
4938 $switch = shift @args;
4939 $arg = shift @args;
4940 # There should be no arguments left
4941 if (
4942 @args
4943 || (
4944 defined $switch && $switch ne '-w' && $switch ne '-g' && $switch ne '-r'
4945 && $switch ne '-c' && $switch ne '-x' && $switch ne '-d' && $switch ne '-i'
4946 )
4947 ) {
4948 return $self->improper($session, $inputString);
4949 }
4950  
4951 # ;ltr
4952 # ;ltr -w , ;ltr -g , ;ltr -r , ;ltr -c
4953 # ;ltr -x <category>
4954 # ;ltr -d <profile>
4955 # (etc)
4956 if (! defined $switch || $switch ne '-i') {
4957  
4958 # ;ltr
4959 # ;ltr -w
4960 if (! $switch || $switch eq '-w') {
4961  
4962 $owner = $session->currentWorld->name;
4963 $cage = $session->findCurrentCage($category, 'world');
4964  
4965 } elsif ($switch eq '-g') {
4966  
4967 if (! defined $session->currentGuild) {
4968  
4969 return $self->error(
4970 $session, $inputString,
4971 'Can\'t list ' . $categoryPlural . ' for the current guild - no current'
4972 . ' guild set',
4973 );
4974  
4975 } else {
4976  
4977 $owner = $session->currentGuild->name;
4978 $cage = $session->findCurrentCage($category, 'guild');
4979 }
4980  
4981 } elsif ($switch eq '-r') {
4982  
4983 if (! defined $session->currentRace) {
4984  
4985 return $self->error(
4986 $session, $inputString,
4987 'Can\'t list ' . $categoryPlural . ' for the current race - no current'
4988 . ' race set',
4989 );
4990  
4991 } else {
4992  
4993 $owner = $session->currentRace->name;
4994 $cage = $session->findCurrentCage($category, 'race');
4995 }
4996  
4997 } elsif ($switch eq '-c') {
4998  
4999 if (! defined $session->currentChar) {
5000  
5001 return $self->error(
5002 $session, $inputString,
5003 'Can\'t list ' . $categoryPlural . ' for the current character - no current'
5004 . ' character set',
5005 );
5006  
5007 } else {
5008  
5009 $owner = $session->currentChar->name;
5010 $cage = $session->findCurrentCage($category, 'char');
5011 }
5012  
5013 } elsif ($switch eq '-x') {
5014  
5015 if (! defined $arg) {
5016  
5017 return $self->error(
5018 $session, $inputString,
5019 'List ' . $categoryPlural . ' for which category of custom profile?',
5020 );
5021  
5022 } elsif (! $session->ivExists('templateHash', $arg)) {
5023  
5024 return $self->error(
5025 $session, $inputString,
5026 'Unrecognised custom profile category \'' . $arg . '\'',
5027 );
5028  
5029 } elsif (! $session->ivExists('currentProfHash', $arg)) {
5030  
5031 return $self->error(
5032 $session, $inputString,
5033 'Can\'t list ' . $categoryPlural . ' for the current ' . $arg
5034 . ' custom profile - no current profile set',
5035 );
5036  
5037 } else {
5038  
5039 $profObj = $session->ivShow('currentProfHash', $arg);
5040 $owner = $profObj->name;
5041 $cage = $session->findCurrentCage($category, $owner);
5042 }
5043  
5044 } elsif ($switch eq '-d') {
5045  
5046 if (! defined $arg) {
5047  
5048 return $self->error(
5049 $session, $inputString,
5050 'List ' . $categoryPlural . ' for which profile?',
5051 );
5052  
5053 } elsif (! $session->ivExists('profHash', $arg)) {
5054  
5055 return $self->error(
5056 $session, $inputString,
5057 'Unrecognised profile \'' . $arg . '\'',
5058 );
5059  
5060 } else {
5061  
5062 $owner = $arg;
5063 $cage = $session->findCage($category, $owner);
5064 }
5065 }
5066  
5067 if ($cage) {
5068  
5069 # Import the cage's hash of interface objects
5070 %hash = $cage->interfaceHash;
5071 }
5072  
5073 # Check there is something to display
5074 @list = sort {lc($hash{$a}) cmp lc($hash{$b})} (keys %hash);
5075 if (! @list) {
5076  
5077 return $self->complete($session, $standardCmd, 'The specified list is empty');
5078 }
5079  
5080 # Display header
5081 $session->writeText(
5082 'Independent ' . $category . ' list for \'' . $owner . '\' (* = Active'
5083 . ' E = Enabled)',
5084 );
5085  
5086 $string = 'Stimulus (pattern) Response (action)';
5087  
5088  
5089 if ($category eq 'trigger') {
5090 $string = 'Stimulus (pattern) Response (instruction, rewriter: substitution)';
5091 } elsif ($category eq 'alias') {
5092 $string = 'Stimulus (pattern) Response (substitution)';
5093 } elsif ($category eq 'macro') {
5094 $string = 'Stimulus (key) Response (instruction)';
5095 } elsif ($category eq 'timer') {
5096 $string = 'Stimulus (interval) Response (instruction)';
5097 } elsif ($category eq 'hook') {
5098 $string = 'Stimulus (hook event) Response (instruction)';
5099 }
5100  
5101 $session->writeText(' Name ' . $string);
5102  
5103 # Display list
5104 foreach my $name (@list) {
5105  
5106 my ($obj, $column);
5107  
5108 $obj = $hash{$name};
5109  
5110 if (
5111 $session->ivExists('interfaceHash', $name)
5112 && $session->ivShow('interfaceHash', $name) eq $obj
5113 ) {
5114 $column = '*'; # Active trigger (etc)
5115 } else {
5116 $column = '*'; # Inactive trigger (etc)
5117 }
5118  
5119 if ($obj->enabledFlag) {
5120 $column .= 'E '; # Enabled
5121 } else {
5122 $column .= ' '; # Disabled
5123 }
5124  
5125 $session->writeText(
5126 $column . sprintf(
5127 '%-32.32s %-24.24s %-24.24s',
5128 $name,
5129 $obj->stimulus, # Shortened to fit
5130 $obj->response, # Shortened to fit
5131 )
5132 );
5133 }
5134  
5135 # ;ltr -i
5136 # (etc)
5137 } else {
5138  
5139 # Import the interface registry for the session
5140 %hash = $session->interfaceHash;
5141  
5142 # Compile a hash of active trigger (etc) interfaces
5143 foreach my $name (keys %hash) {
5144  
5145 my $obj = $hash{$name};
5146  
5147 if ($obj->category eq $category) {
5148  
5149 $modifiedHash{$name} = $obj;
5150 }
5151 }
5152  
5153 # Display header
5154 $session->writeText(
5155 'Active ' . $category . ' interface list (I = independent, D = dependent)',
5156 );
5157  
5158 # Display list
5159 @list = sort {lc($modifiedHash{$a}) cmp lc($modifiedHash{$b})} (keys %modifiedHash);
5160 foreach my $name (@list) {
5161  
5162 my ($obj, $column);
5163  
5164 $obj = $modifiedHash{$name};
5165  
5166 if ($obj->indepFlag) {
5167 $column = ' I '; # Independent trigger (etc)
5168 } else {
5169 $column = ' D '; # Dependent trigger (etc)
5170 }
5171  
5172 $session->writeText(
5173 $column . sprintf('Name: %-32.32s', $name) . ' (# ' . $obj->number . ')',
5174 );
5175  
5176 if (length ($obj->stimulus) > 64) {
5177 $session->writeText(sprintf (' Stimulus: %-64.64s...', $obj->stimulus));
5178 } else {
5179 $session->writeText(' Stimulus: ' . $obj->stimulus);
5180 }
5181  
5182 if (length ($obj->response) > 64) {
5183 $session->writeText(sprintf (' Response: %-64.64s...', $obj->response));
5184 } else {
5185 $session->writeText(' Response: ' . $obj->response);
5186 }
5187  
5188 if (! $obj->indepFlag) {
5189  
5190 $string = ref($obj->callClass) . '->' . $obj->callMethod;
5191 if (length $string > 64) {
5192 $session->writeText(sprintf (' Method: %-64.64s...', $string));
5193 } else {
5194 $session->writeText(' Method: ' . $string);
5195 }
5196 }
5197 }
5198 }
5199  
5200 # Display footer
5201 if (@list == 1) {
5202  
5203 return $self->complete(
5204 $session, $standardCmd,
5205 'End of list (1 ' . $category . ' interface found)',
5206 );
5207  
5208 } else {
5209  
5210 return $self->complete(
5211 $session, $standardCmd,
5212 'End of list (' . scalar @list . ' ' . $category . ' interfaces found)',
5213 );
5214 }
5215 }
5216  
5217 sub addRecordingString {
5218  
5219 # Called by GA::Cmd::WorldCommand->do, ClientCommand->do, Comment->do, Break->do
5220 # Adds a new string to the current recording
5221 #
5222 # Expected arguments
5223 # $session - The calling function's GA::Session
5224 # $string - The string to add
5225 #
5226 # Return values
5227 # 'undef' on improper arguments or if there is no current recording for the specified
5228 # session
5229 # 1 otherwise
5230  
5231 my ($self, $session, $string, $check) = @_;
5232  
5233 # Check for improper arguments
5234 if (! defined $session || ! defined $string || defined $check) {
5235  
5236 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRecordingString', @_);
5237 }
5238  
5239 # Check there is a current recording (should already have been checked, but let's be
5240 # thorough)
5241 if (! $session->recordingFlag) {
5242  
5243 return undef;
5244 }
5245  
5246 # If there's a defined insertion point, insert the string there
5247 if (
5248 defined $session->recordingPosn
5249 && $session->recordingPosn <= scalar $session->recordingList
5250 ) {
5251 # Insert the command at the insertion point
5252 $session->ivSplice(
5253 'recordingList',
5254 $session->recordingPosn,
5255 0,
5256 $string,
5257 );
5258  
5259 # The new insertion point is the line after this one
5260 $session->ivIncrement('recordingPosn');
5261  
5262 } else {
5263  
5264 # No insertion point specified, or the insertion point is at a line number that's bigger
5265 # than the size of the recording, so $string must be added to the end of the
5266 # recording
5267 $session->ivPush('recordingList', $string);
5268 # In case $self->recordingPosn was outside the list, make sure future commands are
5269 # just added to the end of the list
5270 $session->ivUndef('recordingPosn');
5271 }
5272  
5273 return 1;
5274 }
5275  
5276 sub useRoute {
5277  
5278 # Called by GA::Cmd::Drive->do, Road->do and Quick->do
5279 # Moves between one tagged room and another using pre-defined routes
5280 #
5281 # Expected arguments
5282 # $session - The calling function's GA::Session
5283 # $inputString, $standardCmd
5284 # - Standard arguments for a call to a GA::Cmd::XXX->do
5285 # $start - The room tag of the initial room
5286 # $stop - The room tag of the target room
5287 # $routeType - Which kind of routes to use - 'road', 'quick' or 'both'
5288 #
5289 # Return values
5290 # 'undef' on improper arguments or if there's an error
5291 # 1 otherwise
5292  
5293 my ($self, $session, $inputString, $standardCmd, $start, $stop, $routeType, $check) = @_;
5294  
5295 # Local variables
5296 my (
5297 $routeString, $routeObj, $cmdListRef, $cmdSequence, $cmdCount,
5298 @list,
5299 );
5300  
5301 # Check for improper arguments
5302 if (
5303 ! defined $session || ! defined $inputString || ! defined $standardCmd
5304 || ! defined $start || ! defined $stop || ! defined $routeType || defined $check
5305 ) {
5306 return $axmud::CLIENT->writeImproper($self->_objClass . '->useRoute', @_);
5307 }
5308  
5309 # Use this string for messages including the route type
5310 if ($routeType eq 'road' || $routeType eq 'quick') {
5311 $routeString = ' ' . $routeType;
5312 } else {
5313 $routeString = '';
5314 }
5315  
5316 # Look for a route object between the two tagged rooms. Start searching in the highest-
5317 # priority route cage
5318 OUTER: foreach my $category ($session->profPriorityList) {
5319  
5320 my $cage = $session->findCurrentCage('route', $category);
5321 if ($cage) {
5322  
5323 # Route objects are stored in the route cage's ->routeHash IV. Keys are in the form
5324 # r_start-room-tag@@@stop-room-tag (for road routes)
5325 # q_start-room-tag@@@stop-room-tag (for quick routes)
5326  
5327 # Find the route from this cage, or from inferior cages (if necessary). If the
5328 # calling function specified both road routes and quick routes, find road routes
5329 # first
5330 if ($routeType ne 'quick') {
5331  
5332 $routeObj = $cage->ivShow(
5333 'routeHash',
5334 'r_' . $start . '@@@' . $stop,
5335 $session, # Consult inferior cages
5336 );
5337 }
5338  
5339 if (! $routeObj) {
5340  
5341 $routeObj = $cage->ivShow(
5342 'routeHash',
5343 'q_' . $start . '@@@' . $stop,
5344 $session, # Consult inferior cages
5345 );
5346 }
5347  
5348 last OUTER;
5349 }
5350 }
5351  
5352 # If there is no pre-defined route between <start> and <stop>...
5353 if (! $routeObj) {
5354  
5355 # Try to work out the shortest path between the two rooms, using only the network of
5356 # interlinked GA::Obj::Route objects
5357 $cmdListRef = $session->worldModelObj->findRoutePath(
5358 $session,
5359 $start,
5360 $stop,
5361 $routeType,
5362 );
5363  
5364 if (! defined $cmdListRef || ! @$cmdListRef) {
5365  
5366 return $self->error(
5367 $session, $inputString,
5368 'No' . $routeString . ' route between \'' . $start . '\' and \'' . $stop
5369 . '\' found',
5370 );
5371  
5372 } else {
5373  
5374 # Use this route
5375 $cmdSequence = join($axmud::CLIENT->cmdSep, @$cmdListRef);
5376 $cmdCount = scalar @$cmdListRef;
5377 }
5378  
5379 } else {
5380  
5381 # Use the pre-defined route. If $routeObj->route is a speedwalk command, convert it into
5382 # a chain of world commands
5383 if (index($routeObj->route, $axmud::CLIENT->constSpeedSigil) == 0) {
5384  
5385 @list = $session->parseSpeedWalk($routeObj->route);
5386 $cmdSequence = join($axmud::CLIENT->cmdSep, @list);
5387 $cmdCount = scalar @list;
5388  
5389 } else {
5390  
5391 # $routeObj->route is already a single world command or a chain of world commands
5392 $cmdSequence = $routeObj->route;
5393 $cmdCount = $routeObj->stepCount;
5394 }
5395 }
5396  
5397 # Final check that we really have found a route
5398 if (! $cmdSequence) {
5399  
5400 return $self->error(
5401 $session, $inputString,
5402 'General error processing the route between \'' . $start . '\' and \'' . $stop
5403 . '\'',
5404 );
5405 }
5406  
5407 # If the Locator task is running, tell it about the target room's tag
5408 if ($session->locatorTask) {
5409  
5410 $session->locatorTask->set_arrivalTag($stop);
5411 }
5412  
5413 # Take the route
5414 $session->worldCmd($cmdSequence);
5415  
5416 if ($cmdCount == 1) {
5417  
5418 return $self->complete(
5419 $session, $standardCmd,
5420 'Taking' . $routeString . ' route from \'' . $start . '\' to \'' . $stop
5421 . '\' (in 1 step)',
5422 );
5423  
5424 } else {
5425  
5426 return $self->complete(
5427 $session, $standardCmd,
5428 'Taking' . $routeString . ' route from \'' . $start . '\' to \'' . $stop . '\' (in '
5429 . $cmdCount . ' steps)',
5430 );
5431 }
5432 }
5433  
5434 sub autoQuit {
5435  
5436 # Called by GA::Cmd::Quit->do, QQuit->do and QuitAll->do
5437 # Sends a standard 'quit' world command, sends a sequence of world commands, runs a task,
5438 # runs an Axbasic script or starts a mission, depending on the value of
5439 # GA::Profile::World->autoQuitMode
5440 #
5441 # Expected arguments
5442 # $session - The calling function's GA::Session
5443 # $inputString, $standardCmd
5444 # - Standard arguments for a call to a GA::Cmd::XXX->do
5445 # $simpleMsg - Success message to use in auto-quit mode 'normal'
5446 # $initiateMsg - Success message to use in all other auto-quit modes
5447 #
5448 # Return values
5449 # 'undef' on improper arguments or if there's an error
5450 # 1 otherwise
5451  
5452 my ($self, $session, $inputString, $standardCmd, $simpleMsg, $initiateMsg, $check) = @_;
5453  
5454 # Local variables
5455 my (
5456 $name, $initFailMsg, $result, $failMsg, $packageName, $rawScriptObj, $path, $taskObj,
5457 $missionObj, $scriptObj,
5458 );
5459  
5460 # Check for improper arguments
5461 if (
5462 ! defined $session || ! defined $inputString || ! defined $standardCmd
5463 || ! defined $simpleMsg || ! defined $initiateMsg || defined $check
5464 ) {
5465 return $axmud::CLIENT->writeImproper($self->_objClass . '->autoQuit', @_);
5466 }
5467  
5468 # Import one IV for convenience
5469 $name = $session->currentWorld->autoQuitObjName;
5470 # Standard failure message
5471 $initFailMsg = 'Could not initiate auto-quit sequence - ';
5472  
5473 # Mode 'world_cmd' - Send a sequence of world commands
5474 if (
5475 $session->currentWorld->autoQuitMode eq 'world_cmd'
5476 && $session->currentWorld->autoQuitCmdList
5477 ) {
5478 $result = $self->complete($session, $standardCmd, $initiateMsg);
5479  
5480 foreach my $cmd ($session->currentWorld->autoQuitCmdList) {
5481  
5482 $session->worldCmd($cmd);
5483 }
5484  
5485 return $result;
5486  
5487 # Mode 'task' - Run a task (the task is responsible for sending a 'quit' world command)
5488 } elsif ($session->currentWorld->autoQuitMode eq 'task' && $name) {
5489  
5490 # $self->findTaskPackageName recognises unique names of currently running tasks (e.g.
5491 # 'status_task_57'), so before we consult it, check that $name isn't already running
5492 if ($session->ivExists('currentTaskHash', $name)) {
5493  
5494 $failMsg
5495 = $initFailMsg . '\'' . $name . '\' isn\'t a valid task name or task label';
5496  
5497 } else {
5498  
5499 # Get the task's package name (e.g. 'Games::Axmud::Task::Status')
5500 $packageName = Games::Axmud::Generic::Cmd->findTaskPackageName($session, $name);
5501 if (! $packageName) {
5502  
5503 $failMsg = $initFailMsg . 'could not start the task \'' . $name . '\'';
5504  
5505 } else {
5506  
5507 # Create the task object
5508 $packageName->new($session, 'current');
5509 }
5510 }
5511  
5512 if ($failMsg) {
5513 return $self->error($session, $inputString, $failMsg);
5514 } else {
5515 return $self->complete($session, $standardCmd, $initiateMsg);
5516 }
5517  
5518 # Mode 'task_script' - Run an Axbasic script from within a task (the script is responsible
5519 # for sending a 'quit' world command)
5520 } elsif ($session->currentWorld->autoQuitMode eq 'task_script' && $name) {
5521  
5522 # We need to check that the file containing the script exists, because the Script task
5523 # won't pass us a convenient error return value. Create a dummy raw script to do it
5524 $rawScriptObj = Language::Axbasic::RawScript->new($session, $name);
5525 if (! $rawScriptObj) {
5526  
5527 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME . ' script \''
5528 . $name . '\'';
5529  
5530 } else {
5531  
5532 # Load the script into the raw script object
5533 $path = $axmud::DATA_DIR . '/scripts/' . $name . '.bas';
5534 if (! $rawScriptObj->loadFile($path)) {
5535  
5536 $failMsg = $initFailMsg . 'could not load the ' . $axmud::BASIC_NAME
5537 . ' script \'' . $name . '\'';
5538  
5539 } else {
5540  
5541 # Create the task object
5542 $taskObj = Games::Axmud::Task::Script->new($session, 'current');
5543 if (! $taskObj) {
5544  
5545 $failMsg = $initFailMsg . 'could not start a Script task running the'
5546 . ' ' . $axmud::BASIC_NAME . ' script \'' . $name . '\'';
5547  
5548 } else {
5549  
5550 # Tell it which script to execute
5551 $taskObj->ivPoke('scriptName', $name);
5552 }
5553 }
5554 }
5555  
5556 if ($failMsg) {
5557 return $self->error($session, $inputString, $failMsg);
5558 } else {
5559 return $self->complete($session, $standardCmd, $initiateMsg);
5560 }
5561  
5562 # Mode 'script' - Run an Axbasic script (the script is responsible for sending a 'quit'
5563 # world command)
5564 } elsif ($session->currentWorld->autoQuitMode eq 'script' && $name) {
5565  
5566 # Create the raw script object
5567 $rawScriptObj = Language::Axbasic::RawScript->new($session, $name);
5568 if (! $rawScriptObj) {
5569  
5570 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME . ' script \''
5571 . $name . '\'';
5572  
5573 } else {
5574  
5575 # Load the script into the raw script object
5576 $path = $axmud::DATA_DIR . '/scripts/' . $name . '.bas';
5577 if (! $rawScriptObj->loadFile($path)) {
5578  
5579 $failMsg = $initFailMsg . 'could not load the ' . $axmud::BASIC_NAME
5580 . ' script \'' . $name . '\'';
5581  
5582 } else {
5583  
5584 # Create a script object, which processes the raw script, removing extraneous
5585 # whitespace, empty lines, comments, etc
5586 $scriptObj = Language::Axbasic::Script->new($session, $rawScriptObj);
5587 if (! $scriptObj) {
5588  
5589 $failMsg = $initFailMsg . 'could not run the ' . $axmud::BASIC_NAME
5590 . ' script \'' . $name . '\'';
5591  
5592 } else {
5593  
5594 # Execute the script
5595 $scriptObj->implement();
5596 }
5597 }
5598 }
5599  
5600 if ($failMsg) {
5601 return $self->error($session, $inputString, $failMsg);
5602 } else {
5603 return $self->complete($session, $standardCmd, $initiateMsg);
5604 }
5605  
5606 # Mode 'mission' - Start a mission (the mission is responsible for sending a 'quit' world
5607 # command)
5608 } elsif ($session->currentWorld->autoQuitMode eq 'mission' && $name) {
5609  
5610 # If the mission exists...
5611 if (! $session->currentWorld->ivExists('missionHash', $name)) {
5612  
5613 $failMsg = $initFailMsg . 'the mission \'' . $name . '\' doesn\'t exist';
5614  
5615 } else {
5616  
5617 $missionObj = $session->currentWorld->ivShow('missionHash', $name);
5618  
5619 # If the world profile's ->loginSpecialList is set, make a local copy of the list
5620 $session->set_loginSpecialList($session->currentWorld->loginSpecialList);
5621  
5622 # Start the mission. The TRUE flag means to refrain from displaying confirmation
5623 # messages
5624 if (! $missionObj->startMission(TRUE)) {
5625  
5626 $failMsg = $initFailMsg . 'Could not start the mission \'' . $name . '\'';
5627  
5628 } else {
5629  
5630 # Automatically send the first group of commands (as if ';mission' had been
5631 # typed by the user
5632 $missionObj->continueMission($session);
5633 }
5634 }
5635  
5636 if ($failMsg) {
5637 return $self->error($session, $inputString, $failMsg);
5638 } else {
5639 return $self->complete($session, $standardCmd, $initiateMsg);
5640 }
5641  
5642 # Mode 0 - Send the standard 'quit' world command, as defined by the current
5643 # highest-priority command cage
5644 # Modes 1-5 (if ->autoQuitCmdList or ->autoQuitObjName are required, but not set)
5645 } else {
5646  
5647 # Send the 'quit' command for this world
5648 $session->sendModCmd('quit');
5649  
5650 return $self->complete($session, $standardCmd, $simpleMsg);
5651 }
5652 }
5653  
5654 sub sortAttributes {
5655  
5656 # Called by GA::Cmd::Read->do, Switch->do and Alert->do (and also PermRead->do,
5657 # PermSwitch->do, PermAlert->do
5658 # Returns a string containing a list of text-to-speech attributes, sorted by task
5659 #
5660 # Expected arguments
5661 # $iv - The GA::Client IV that stores the attributes to sort (e.g. ->ttsAttribHash)
5662 #
5663 # Return values
5664 # 'undef' on improper arguments
5665 # Otherwise returns the string
5666  
5667 my ($self, $iv, $check) = @_;
5668  
5669 # Local variables
5670 my (
5671 $string,
5672 %taskHash,
5673 );
5674  
5675 # Check for improper arguments
5676 if (! defined $iv || defined $check) {
5677  
5678 return $axmud::CLIENT->writeImproper($self->_objClass . '->sortAttributes', @_);
5679 }
5680  
5681 foreach my $attrib ($axmud::CLIENT->ivKeys($iv)) {
5682  
5683 my ($task, $listRef);
5684  
5685 $task = $axmud::CLIENT->ivShow($iv, $attrib);
5686  
5687 if (! exists $taskHash{$task}) {
5688  
5689 $taskHash{$task} = [$attrib];
5690  
5691 } else {
5692  
5693 $listRef = $taskHash{$task};
5694 push (@$listRef, $attrib);
5695 }
5696 }
5697  
5698 foreach my $task (sort {lc($a) cmp lc($b)} (keys %taskHash)) {
5699  
5700 my ($listRef, $prettyTask);
5701  
5702 $listRef = $taskHash{$task};
5703  
5704 # (Convert 'locator_task' to 'Locator task')
5705 $prettyTask = ucfirst($task);
5706 $prettyTask =~ s/\_/ /;
5707  
5708 $string .= $prettyTask . ': ' . join(', ', sort {lc($a) cmp lc($b)} (@$listRef)) . '. ';
5709 }
5710  
5711 return $string;
5712 }
5713  
5714 sub getKeypadHashes {
5715  
5716 # Called by GA::Cmd::Compass->do, PermCompass->do
5717 # Defines two hashes, one of keypad keycodes that the Compass task allows the user to
5718 # customise, and another of the keypad keycodes that the Compass task won't customise.
5719 # Returns the hashes as hash references
5720 #
5721 # Expected arguments
5722 # (none besides $self)
5723 #
5724 # Return values
5725 # 'undef' on improper arguments
5726 # Otherwise returns two hash references
5727  
5728 my ($self, $check) = @_;
5729  
5730 # Local variables
5731 my (%hash, %otherHash);
5732  
5733 # Check for improper arguments
5734 if (defined $check) {
5735  
5736 return $axmud::CLIENT->writeImproper($self->_objClass . '->getKeypadHashes', @_);
5737 }
5738  
5739 # Hash to convert all the <key>s that the Compass task allows us to customise
5740 %hash = (
5741 0 => 'kp_0',
5742 'zero' => 'kp_0',
5743 'kp_0' => 'kp_0',
5744  
5745 5 => 'kp_5',
5746 'five' => 'kp_5',
5747 'kp_5' => 'kp_5',
5748  
5749 '*' => 'kp_multiply',
5750 'times' => 'kp_multiply',
5751 'multiply' => 'kp_multiply',
5752 'kp_multiply' => 'kp_multiply',
5753  
5754 '/' => 'kp_divide',
5755 'slash' => 'kp_divide',
5756 'divide' => 'kp_divide',
5757 'kp_divide' => 'kp_divide',
5758  
5759 '.' => 'kp_full_stop',
5760 'dot' => 'kp_full_stop',
5761 'fullstop' => 'kp_full_stop',
5762 'period' => 'kp_full_stop',
5763 'kp_full_stop' => 'kp_full_stop',
5764  
5765 'enter' => 'kp_enter',
5766 'return' => 'kp_enter',
5767 'kp_enter' => 'kp_enter',
5768 );
5769  
5770 # Hash of other keypad <key>s that the Compass task doesn't allow us to customise
5771 %otherHash = (
5772 1 => '1',
5773 2 => '2',
5774 3 => '3',
5775 4 => '4',
5776 6 => '6',
5777 7 => '7',
5778 8 => '8',
5779 9 => '9',
5780  
5781 'one' => '1',
5782 'two' => '2',
5783 'three' => '3',
5784 'four' => '4',
5785 'six' => '6',
5786 'seven' => '7',
5787 'eight' => '8',
5788 'nine' => '9',
5789  
5790 'kp_1' => '1',
5791 'kp_2' => '2',
5792 'kp_3' => '3',
5793 'kp_4' => '4',
5794 'kp_6' => '6',
5795 'kp_7' => '7',
5796 'kp_8' => '8',
5797 'kp_9' => '9',
5798  
5799 '+' => 'add',
5800 'plus' => 'add',
5801 'add' => 'add',
5802 'kp_add' => 'add',
5803  
5804 '-' => 'subtract',
5805 'minus' => 'subtract',
5806 'subtract' => 'subtract',
5807 'kp_subtract' => 'subtract',
5808 );
5809  
5810 return (\%hash, \%otherHash);
5811 }
5812  
5813 sub updateCompass {
5814  
5815 # Called by GA::Cmd::PermCompass->do and WorldCompass->do
5816 # Applies changes to the IVs for a global initial task or the current world's initial task
5817 #
5818 # Expected arguments
5819 # $session, $inputString, $standardCmd
5820 # - Standard arguments to a command's ->do function
5821 # $argListRef - Reference to the list of arguments supplied to the client command
5822 # (unmodified). The calling function has already checked there is at
5823 # least one argument
5824 # $currentListRef - Reference to a list of current tasklist tasks (should contain 0 or 1
5825 # items)
5826 # $initListRef - Reference to a list of initial tasks (can contain any number of items,
5827 # including 0)
5828 #
5829 # Return values
5830 # 'undef' on improper arguments or failure
5831 # 1 on success
5832  
5833 my (
5834 $self, $session, $inputString, $standardCmd, $argListRef, $currentListRef, $initListRef,
5835 $check,
5836 ) = @_;
5837  
5838 # Local variables
5839 my (
5840 $hashRef, $otherHashRef, $count, $errorCount, $key, $keycode, $cmd,
5841 @args, @taskList, @initTaskList,
5842 %hash, %otherHash,
5843 );
5844  
5845 # Check for improper arguments
5846 if (
5847 ! defined $session || ! defined $inputString || ! defined $standardCmd
5848 || ! defined $argListRef || ! defined $currentListRef || ! defined $initListRef
5849 || defined $check
5850 ) {
5851 return $axmud::CLIENT->writeImproper(
5852 $self->_objClass . '->updateCompass',
5853 @_,
5854 );
5855 }
5856  
5857 # Dereference the args
5858 @args = @$argListRef;
5859 @taskList = @$currentListRef;
5860 @initTaskList = @$initListRef;
5861  
5862 # %hash to convert all the <key>s that the Compass task allows us to customise
5863 # %otherHash of other keypad <key>s that the Compass task doesn't allow us to customise
5864 ($hashRef, $otherHashRef) = $self->getKeypadHashes();
5865 %hash = %$hashRef;
5866 %otherHash = %$otherHashRef;
5867  
5868 # Count successes and errors, to show in confirmation messages
5869 $count = 0;
5870 $errorCount = 0;
5871  
5872 # ;pcm on
5873 # ;pcm -o
5874 if ($args[0] eq 'on' || $args[0] eq '-o') {
5875  
5876 # (For the benefit of visually-impaired users, ignore everything after the first
5877 # argument)
5878 foreach my $taskObj (@taskList) {
5879  
5880 if (! $taskObj->enable()) {
5881 $errorCount++;
5882 } else {
5883 $count++;
5884 }
5885 }
5886  
5887 foreach my $taskObj (@initTaskList) {
5888  
5889 $count++;
5890 $taskObj->set_enabledFlag(TRUE);
5891 }
5892  
5893 return $self->complete(
5894 $session, $standardCmd,
5895 'Compass tasks set to \'enabled\'. (Found tasks: ' . ($count + $errorCount)
5896 . ', errors: ' . $errorCount . ').',
5897 )
5898  
5899 # ;pcm off
5900 # ;pcm -f
5901 } elsif ($args[0] eq 'off' || $args[0] eq '-f') {
5902  
5903 foreach my $taskObj (@taskList) {
5904  
5905 if (! $taskObj->disable()) {
5906 $errorCount++;
5907 } else {
5908 $count++;
5909 }
5910 }
5911  
5912 foreach my $taskObj (@initTaskList) {
5913  
5914 $count++;
5915 $taskObj->set_enabledFlag(FALSE);
5916 }
5917  
5918 return $self->complete(
5919 $session, $standardCmd,
5920 'Compass tasks set to \'disabled\'. (Found tasks: ' . ($count + $errorCount)
5921 . ', errors: ' . $errorCount . ').',
5922 );
5923  
5924 # ;pcm <key> <command>
5925 # ;pcm <key>
5926 } elsif ($args[0]) {
5927  
5928 # Get the Axmud standard keycode
5929 $key = shift @args;
5930 if (! exists $hash{$key} && ! exists $otherHash{$key}) {
5931  
5932 return $self->error(
5933 $session, $inputString,
5934 'Unrecognised keypad key (try \';help compass\' for a list of recognised keys)',
5935 );
5936  
5937 } elsif (exists $otherHash{$key}) {
5938  
5939 return $self->error(
5940 $session, $inputString,
5941 'The Compass task doesn\'t allow us to customise the \'' . $otherHash{$key}
5942 . '\' key',
5943 );
5944  
5945 } else {
5946  
5947 $keycode = $hash{$key};
5948 }
5949  
5950 # Set the corresponding world <command> (if one was specified)
5951 if (@args) {
5952  
5953 $cmd = join (' ', @args);
5954 }
5955  
5956 # Update the task(s)
5957 foreach my $taskObj (@taskList, @initTaskList) {
5958  
5959 if (! $taskObj->set_key($keycode, $cmd)) {
5960 $errorCount++;
5961 } else {
5962 $count++;
5963 }
5964 }
5965  
5966 return $self->complete(
5967 $session, $standardCmd,
5968 'Set a world command for the keypad key \'' . $key . '\'. (Found tasks: '
5969 . ($count + $errorCount) . ', errors: ' . $errorCount . ').',
5970 );
5971 }
5972 }
5973  
5974 sub killLimitedTargets {
5975  
5976 # Called by GA::Cmd::Kill->do and Kkill->do
5977 # Attacks a list of targets limited to the given arguments, e.g. ('orc') or ('orcs',
5978 # 'troll', 'bears'), but doesn't attack players
5979 #
5980 # Expected arguments
5981 # $session - The calling function's GA::Session
5982 # $inputString - What the player actually typed (e.g. ';k orcs');
5983 # $standardCmd - The standard version of the command (i.e. 'kill')
5984 # $multipleFlag - Flag set to FALSE when called by ';kill' (e.g. attack a single orc),
5985 # set to TRUE when called by ';kkill' (e.g. attack all orcs at current
5986 # location)
5987 # @targetList - A list of target strings specified by the user, e.g. ('orcs', 'wolf')
5988 #
5989 # Return values
5990 # 'undef' on improper arguments or failure
5991 # 1 on success
5992  
5993 my ($self, $session, $inputString, $standardCmd, $multipleFlag, @targetList) = @_;
5994  
5995 # Local variables
5996 my @objList;
5997  
5998 # Check for improper arguments
5999 if (
6000 ! defined $session || ! defined $inputString || ! defined $standardCmd
6001 || ! defined $multipleFlag
6002 ) {
6003 return $axmud::CLIENT->writeImproper($self->_objClass . '->killLimitedTargets', @_);
6004 }
6005  
6006 # This command requires the Locator task to know the current location
6007 if (! $session->locatorTask) {
6008  
6009 return $self->error(
6010 $session, $inputString,
6011 'Cannot kill - Locator task isn\'t running',
6012 );
6013  
6014 } elsif (! $session->locatorTask->roomObj) {
6015  
6016 return $self->error(
6017 $session, $inputString,
6018 'Cannot kill - Locator task doesn\'t know the current location',
6019 );
6020 }
6021  
6022 if (! @targetList) {
6023  
6024 # Get the first target from the Locator's list of things in the current room
6025 @objList = $session->locatorTask->roomObj->tempObjList;
6026 if (! @objList) {
6027  
6028 return $self->complete(
6029 $session, $standardCmd,
6030 'Cannot kill - current location is empty',
6031 );
6032  
6033 } else {
6034  
6035 # Choose the first minion, sentient or creature in @objList
6036 OUTER: foreach my $obj (@objList) {
6037  
6038 if (
6039 $obj->aliveFlag
6040 && (
6041 ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6042 || $obj->category eq 'sentient'
6043 || $obj->category eq 'creature'
6044 )
6045 ) {
6046 push (@targetList, $obj->noun);
6047 last OUTER;
6048 }
6049 }
6050 }
6051  
6052 # If no suitable objects were found, don't attack
6053 if (! @targetList) {
6054  
6055 return $self->complete(
6056 $session, $standardCmd,
6057 'Cannot kill - no enemy minions, sentients or creatures at the current'
6058 . ' location',
6059 );
6060 }
6061 }
6062  
6063 # Attack the targets
6064 foreach my $target (@targetList) {
6065  
6066 $session->sendModCmd('kill', 'victim', $target);
6067 }
6068  
6069 if (scalar @targetList == 1) {
6070  
6071 return $self->complete($session, $standardCmd, 'Attacking 1 target');
6072  
6073 } else {
6074  
6075 return $self->complete(
6076 $session, $standardCmd,
6077 'Attacking ' . scalar @targetList . ' targets',
6078 );
6079 }
6080 }
6081  
6082 sub killUnlimitedTargets {
6083  
6084 # Called by GA::Cmd::KillAll->do and KillMall->do
6085 # Attacks all targets (or all non-player targets) at current location
6086 #
6087 # Expected arguments
6088 # $session - The calling function's GA::Session
6089 # $inputString - What the player actually typed (e.g. ';ka');
6090 # $standardCmd - The standard version of the command (i.e. 'killall')
6091 # $playerFlag - Set to TRUE if player targets should be attacked too; FALSE if only
6092 # non-player targets should be attacked
6093 #
6094 # Return values
6095 # 'undef' on improper arguments or failure
6096 # 1 on success
6097  
6098 my ($self, $session, $inputString, $standardCmd, $playerFlag, $check) = @_;
6099  
6100 # Local variables
6101 my (@objList, @targetList);
6102  
6103 # Check for improper arguments
6104 if (
6105 ! defined $session || ! defined $inputString || ! defined $standardCmd
6106 || ! defined $playerFlag || defined $check
6107 ) {
6108 return $axmud::CLIENT->writeImproper($self->_objClass . '->killUnlimitedTargets', @_);
6109 }
6110  
6111 # This command requires the Locator task to know the current location
6112 if (! $session->locatorTask) {
6113  
6114 return $self->error(
6115 $session, $inputString,
6116 'Cannot kill - Locator task isn\'t running',
6117 );
6118  
6119 } elsif (! $session->locatorTask->roomObj) {
6120  
6121 return $self->error(
6122 $session, $inputString,
6123 'Cannot kill - Locator task doesn\'t know the current location',
6124 );
6125 }
6126  
6127 # Get a list of attackable targets from the Locator's list of things in the current room
6128 @objList = $session->locatorTask->roomObj->tempObjList;
6129 if (! @objList) {
6130  
6131 return $self->complete(
6132 $session, $standardCmd,
6133 'Cannot kill - current location is empty',
6134 );
6135  
6136 } else {
6137  
6138 foreach my $obj (@objList) {
6139  
6140 if (
6141 $obj->aliveFlag
6142 && (
6143 ($playerFlag && $obj->category eq 'char')
6144 || ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6145 || $obj->category eq 'sentient'
6146 || $obj->category eq 'creature'
6147 )
6148 ) {
6149 push (@targetList, $obj->noun);
6150 }
6151 }
6152 }
6153  
6154 # Attack the targets
6155 foreach my $target (@targetList) {
6156  
6157 $session->sendModCmd('kill', 'victim', $target);
6158 }
6159  
6160 if (scalar @targetList == 1) {
6161  
6162 return $self->complete($session, $standardCmd, 'Attacking 1 target');
6163  
6164 } else {
6165  
6166 return $self->complete(
6167 $session, $standardCmd,
6168 'Attacking ' . scalar @targetList . ' targets',
6169 );
6170 }
6171 }
6172  
6173 sub interactLimitedTargets {
6174  
6175 # Called by GA::Cmd::Kill->do and Kkill->do
6176 # Attacks a list of targets limited to the given arguments, e.g. ('orc') or ('orcs',
6177 # 'troll', 'bears'), but doesn't attack players
6178 #
6179 # Expected arguments
6180 # $session - The calling function's GA::Session
6181 # $inputString - What the player actually typed (e.g. ';k orcs');
6182 # $standardCmd - The standard version of the command (i.e. 'kill')
6183 # $multipleFlag - Flag set to FALSE when called by ';interact' (e.g. attack a single
6184 # orc), set to TRUE when called by ';iinteract' (e.g. attack all orcs
6185 # at current location)
6186 # @targetList - A list of target strings specified by the user, e.g. ('orcs', 'wolf')
6187 #
6188 # Return values
6189 # 'undef' on improper arguments or failure
6190 # 1 on success
6191  
6192 my ($self, $session, $inputString, $standardCmd, $multipleFlag, @targetList) = @_;
6193  
6194 # Local variables
6195 my @objList;
6196  
6197 # Check for improper arguments
6198 if (
6199 ! defined $session || ! defined $inputString || ! defined $standardCmd
6200 || ! defined $multipleFlag
6201 ) {
6202 return $axmud::CLIENT->writeImproper($self->_objClass . '->interactLimitedTargets', @_);
6203 }
6204  
6205 # This command requires the Locator task to know the current location
6206 if (! $session->locatorTask) {
6207  
6208 return $self->error(
6209 $session, $inputString,
6210 'Cannot interact - Locator task isn\'t running',
6211 );
6212  
6213 } elsif (! $session->locatorTask->roomObj) {
6214  
6215 return $self->error(
6216 $session, $inputString,
6217 'Cannot interact - Locator task doesn\'t know the current location',
6218 );
6219 }
6220  
6221 if (! @targetList) {
6222  
6223 # Get the first target from the Locator's list of things in the current room
6224 @objList = $session->locatorTask->roomObj->tempObjList;
6225 if (! @objList) {
6226  
6227 return $self->complete(
6228 $session, $standardCmd,
6229 'Cannot interact - current location is empty',
6230 );
6231  
6232 } else {
6233  
6234 # Choose the first minion, sentient or creature in @objList
6235 OUTER: foreach my $obj (@objList) {
6236  
6237 if (
6238 $obj->aliveFlag
6239 && (
6240 ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6241 || $obj->category eq 'sentient'
6242 || $obj->category eq 'creature'
6243 )
6244 ) {
6245 push (@targetList, $obj->noun);
6246 last OUTER;
6247 }
6248 }
6249 }
6250  
6251 # If no suitable objects were found, don't attack
6252 if (! @targetList) {
6253  
6254 return $self->complete(
6255 $session, $standardCmd,
6256 'Cannot interact - no enemy minions, sentients or creatures at the current'
6257 . ' location',
6258 );
6259 }
6260 }
6261  
6262 # Attack the targets
6263 foreach my $target (@targetList) {
6264  
6265 $session->sendModCmd('interact', 'victim', $target);
6266 }
6267  
6268 if (scalar @targetList == 1) {
6269  
6270 return $self->complete($session, $standardCmd, 'Interacting with 1 target');
6271  
6272 } else {
6273  
6274 return $self->complete(
6275 $session, $standardCmd,
6276 'Interacting with ' . scalar @targetList . ' targets',
6277 );
6278 }
6279 }
6280  
6281 sub interactUnlimitedTargets {
6282  
6283 # Called by GA::Cmd::KillAll->do and KillMall->do
6284 # Attacks all targets (or all non-player targets) at current location
6285 #
6286 # Expected arguments
6287 # $session - The calling function's GA::Session
6288 # $inputString - What the player actually typed (e.g. ';ia');
6289 # $standardCmd - The standard version of the command (i.e. 'interactall')
6290 # $playerFlag - Set to TRUE if player targets should be attacked too; FALSE if only
6291 # non-player targets should be attacked
6292 #
6293 # Return values
6294 # 'undef' on improper arguments or failure
6295 # 1 on success
6296  
6297 my ($self, $session, $inputString, $standardCmd, $playerFlag, $check) = @_;
6298  
6299 # Local variables
6300 my (@objList, @targetList);
6301  
6302 # Check for improper arguments
6303 if (
6304 ! defined $session || ! defined $inputString || ! defined $standardCmd
6305 || ! defined $playerFlag || defined $check
6306 ) {
6307 return $axmud::CLIENT->writeImproper(
6308 $self->_objClass . '->interactUnlimitedTargets',
6309 @_,
6310 );
6311 }
6312  
6313 # This command requires the Locator task to know the current location
6314 if (! $session->locatorTask) {
6315  
6316 return $self->error(
6317 $session, $inputString,
6318 'Cannot kill - Locator task isn\'t running',
6319 );
6320  
6321 } elsif (! $session->locatorTask->roomObj) {
6322  
6323 return $self->error(
6324 $session, $inputString,
6325 'Cannot kill - Locator task doesn\'t know the current location',
6326 );
6327 }
6328  
6329 # Get a list of attackable targets from the Locator's list of things in the current room
6330 @objList = $session->locatorTask->roomObj->tempObjList;
6331 if (! @objList) {
6332  
6333 return $self->complete(
6334 $session, $standardCmd,
6335 'Cannot kill - current location is empty',
6336 );
6337  
6338 } else {
6339  
6340 foreach my $obj (@objList) {
6341  
6342 if (
6343 $obj->aliveFlag
6344 && (
6345 ($playerFlag && $obj->category eq 'char')
6346 || ($obj->category eq 'minion' && ! $obj->ownMinionFlag)
6347 || $obj->category eq 'sentient'
6348 || $obj->category eq 'creature'
6349 )
6350 ) {
6351 push (@targetList, $obj->noun);
6352 }
6353 }
6354 }
6355  
6356 # Attack the targets
6357 foreach my $target (@targetList) {
6358  
6359 $session->sendModCmd('interact', 'victim', $target);
6360 }
6361  
6362 if (scalar @targetList == 1) {
6363  
6364 return $self->complete($session, $standardCmd, 'Interacting 1 target');
6365  
6366 } else {
6367  
6368 return $self->complete(
6369 $session, $standardCmd,
6370 'Interacting with ' . scalar @targetList . ' targets',
6371 );
6372 }
6373 }
6374  
6375 # Extract switches
6376  
6377 sub extractProfileSwitches {
6378  
6379 # Called by $self->addInterface, ->modifyInterface, ->deleteInterface
6380 # Extracts the group 1 switch options for the commands ';addtrigger', ';modifytrigger' and
6381 # ';deletetrigger' (etc), namely -w, -r, -g, -c, -x <category>, -d <profile>
6382 #
6383 # Expected arguments
6384 # $session - The calling function's GA::Session
6385 # $inputString - what the user originally typed
6386 # $category - 'trigger', 'alias', 'macro', 'timer' or 'hook'
6387 # $action - what is to be done with the interface: 'add', 'modify' or 'delete'
6388 #
6389 # Optional arguments
6390 # @args - List of group 1 switch options arguments extracted from $inputString
6391 # (maybe be an empty list)
6392 #
6393 # Return values
6394 # Returns an empty list on improper arguments or on failure
6395 # Otherwise, returns a list in the form...
6396 # ($profCount, $profCategory, $profName, @args)
6397 # ...where $profCount is set to 0, if no profiles were found, and @args now contains fewer
6398 # (or the same arguments), depending on how many switch options were removed
6399  
6400 my ($self, $session, $inputString, $category, $action, @args) = @_;
6401  
6402 # Local variables
6403 my (
6404 $switch, $profCount, $profCategory, $profName, $tempCategory, $specificProf,
6405 $profObj,
6406 );
6407  
6408 # Check for improper arguments
6409 if (
6410 ! defined $session || ! defined $inputString || ! defined $category || ! defined $action
6411 ) {
6412 return $axmud::CLIENT->writeImproper(
6413 $self->_objClass . '->extractProfileSwitches',
6414 @_,
6415 );
6416 }
6417  
6418 # Extract group 1 switches
6419 $profCount = 0;
6420 ($switch, @args) = $self->extract('w', 0, @args);
6421 if (defined $switch) {
6422  
6423 $profCount++;
6424 $profCategory = 'world';
6425 $profName = $session->currentWorld->name;
6426 }
6427  
6428 ($switch, @args) = $self->extract('g', 0, @args);
6429 if (defined $switch) {
6430  
6431 if (! $session->currentGuild) {
6432  
6433 return $self->error(
6434 $session, $inputString,
6435 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6436 . ' guild - no current guild set',
6437 );
6438  
6439 } else {
6440  
6441 $profCount++;
6442 $profCategory = 'guild';
6443 $profName = $session->currentGuild->name;
6444 }
6445 }
6446  
6447 ($switch, @args) = $self->extract('r', 0, @args);
6448 if (defined $switch) {
6449  
6450 if (! $session->currentRace) {
6451  
6452 return $self->error(
6453 $session, $inputString,
6454 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6455 . ' race - no current race set',
6456 );
6457  
6458 } else {
6459  
6460 $profCount++;
6461 $profCategory = 'race';
6462 $profName = $session->currentRace->name;
6463 }
6464 }
6465  
6466 ($switch, @args) = $self->extract('c', 0, @args);
6467 if (defined $switch) {
6468  
6469 if (! $session->currentChar) {
6470  
6471 return $self->error(
6472 $session, $inputString,
6473 'Can\'t ' . $action . ' ' . $category . ' interface associated with current'
6474 . ' character - no current character set',
6475 );
6476  
6477 } else {
6478  
6479 $profCount++;
6480 $profCategory = 'char';
6481 $profName = $session->currentChar->name;
6482 }
6483 }
6484  
6485 ($switch, $tempCategory, @args) = $self->extract('x', 1, @args);
6486 if (defined $switch) {
6487  
6488 if (! $session->ivExists('templateHash', $profCategory)) {
6489  
6490 return $self->error(
6491 $session, $inputString,
6492 'Unrecognised custom profile category \'' . $profCategory . '\'',
6493 );
6494  
6495 } elsif (! $session->ivExists('currentProfHash', $profCategory)) {
6496  
6497 return $self->error(
6498 $session, $inputString,
6499 'Can\'t ' . $action . ' ' . $category . ' interface associated with '
6500 . 'current custom \'' . $profCategory . '\' profile - no '
6501 . 'current ' . $profCategory . ' profile set',
6502 );
6503  
6504 } else {
6505  
6506 $profObj = $session->ivShow('currentProfHash', $profCategory);
6507  
6508 $profCount++;
6509 $profCategory = $tempCategory;
6510 $profName = $profObj->name;
6511 }
6512 }
6513  
6514 ($switch, $specificProf, @args) = $self->extract('d', 1, @args);
6515 if (defined $switch) {
6516  
6517 if (! $session->ivExists('profHash', $specificProf)) {
6518  
6519 return $self->error(
6520 $session, $inputString,
6521 'Unrecognised profile \'' . $specificProf . '\'',
6522 );
6523  
6524 } else {
6525  
6526 $profObj = $session->ivShow('profHash', $specificProf);
6527  
6528 $profCount++;
6529 $profCategory = $profObj->category;
6530 $profName = $profObj->name;
6531 }
6532 }
6533  
6534 # Extraction complete
6535 return ($profCount, $profCategory, $profName, @args);
6536 }
6537  
6538 sub extractTaskSwitches {
6539  
6540 # Called by GA::Cmd::StartTask->do, AddInitTask->do and AddCustomTask->do
6541 # Also called by GA::Cmd::RunScriptTask->do
6542 # Extracts the switch options these commands have in common
6543 #
6544 # Expected arguments
6545 # $session - The calling function's GA::Session
6546 # $inputString - What the user actually typed (e.g. ';st status -i');
6547 # $standardCmd - The standard version of the user command, i.e. 'starttask'
6548 #
6549 # Return values
6550 # An empty list on improper arguments or on failure
6551 # Otherwise, returns a list of values in the form:
6552 # (TRUE, $groupCount, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
6553 # $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
6554 # $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag, @args)
6555 # The first argument, TRUE, is the flag to signal success of this function
6556 # The final argument, @args, contain any remaining arguments after the switch options
6557 # have been extracted
6558  
6559 my ($self, $session, $inputString, $standardCmd, @args) = @_;
6560  
6561 # Local variables
6562 my (
6563 $groupCount, $switch, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
6564 $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
6565 $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag, $string,
6566 @emptyList,
6567 );
6568  
6569 # Check for improper arguments
6570 if (! defined $session || ! defined $inputString || ! defined $standardCmd || ! @args) {
6571  
6572 $axmud::CLIENT->writeImproper($self->_objClass . '->extractTaskSwitches', @_);
6573 return @emptyList;
6574 }
6575  
6576 # Extract group 1 switches
6577 # -i - Start <task> immediately (default setting)
6578 # -e <other_task> - Wait for <other_task> to exist, before starting <task>
6579 # -n <other_task> - Wait for <other_task> to not exist, before starting <task>
6580 # -s <other_task> - Wait for <other_task> to start, then stop, before starting <task>
6581 # -t <minutes> - Start <task> <minutes> from now
6582 $groupCount = 0;
6583  
6584 ($switch, @args) = $self->extract('i', 0, @args);
6585 if (defined $switch) {
6586  
6587 $immediateFlag = TRUE;
6588 $groupCount++;
6589 }
6590  
6591 ($switch, $string, @args) = $self->extract('e', 1, @args);
6592 if (defined $switch) {
6593  
6594 $waitTaskExistFlag = TRUE;
6595 $otherTask = $string;
6596 $groupCount++;
6597 }
6598  
6599 ($switch, $string, @args) = $self->extract('n', 1, @args);
6600 if (defined $switch) {
6601  
6602 $waitTaskNoExistFlag = TRUE;
6603 $otherTask = $string;
6604 $groupCount++;
6605 }
6606  
6607 ($switch, $string, @args) = $self->extract('s', 1, @args);
6608 if (defined $switch) {
6609  
6610 $waitTaskStartStopFlag = TRUE;
6611 $otherTask = $string;
6612 $groupCount++;
6613 }
6614  
6615 ($switch, $string, @args) = $self->extract('t', 1, @args);
6616 if (defined $switch) {
6617  
6618 $waitMinutesFlag = TRUE;
6619 $minutes = $string;
6620 $groupCount++;
6621 }
6622  
6623 if ($groupCount > 1) {
6624  
6625 return $self->error(
6626 $session, $inputString,
6627 'Invalid switch arguments - switches -i/-e/-n/-s/-t can\'t be combined',
6628 );
6629 }
6630  
6631 # Extract group 2 switches
6632 # -d - Run <task> for an unlimited amount of time (default)
6633 # -f <minutes> - Run the task for <minutes>
6634 # -u <timer> - Run the task until the Axmud timer reaches <timer> (seconds since the
6635 # script began)
6636 $groupCount = 0;
6637 ($switch, @args) = $self->extract('d', 0, @args);
6638 if (defined $switch) {
6639  
6640 $unlimitedFlag = TRUE;
6641 $groupCount++;
6642 }
6643  
6644 ($switch, $runMinutes, @args) = $self->extract('f', 1, @args);
6645 if (defined $switch) {
6646  
6647 $runTaskForFlag = TRUE;
6648 $groupCount++;
6649 }
6650  
6651 ($switch, $timer, @args) = $self->extract('u', 1, @args);
6652 if (defined $switch) {
6653  
6654 $runTaskUntilFlag = TRUE;
6655 $groupCount++;
6656 }
6657  
6658 if ($groupCount > 1) {
6659  
6660 return $self->error(
6661 $session, $inputString,
6662 'Invalid switch arguments - switches -d/-f/-u can\'t be combined',
6663 );
6664 }
6665  
6666 # Extract group 3 switches
6667 # -w - Run the task without opening its own window (if it usually does)
6668 ($switch, @args) = $self->extract('w', 0, @args);
6669 if (defined $switch) {
6670  
6671 $noWindowFlag = TRUE;
6672 }
6673  
6674 # Return list of flags. The 1st argument is the flag to signal success
6675 return (
6676 TRUE,
6677 $groupCount, $otherTask, $minutes, $runMinutes, $timer, $immediateFlag,
6678 $waitTaskExistFlag, $waitTaskNoExistFlag, $waitTaskStartStopFlag, $waitMinutesFlag,
6679 $unlimitedFlag, $runTaskForFlag, $runTaskUntilFlag, $noWindowFlag,
6680 @args
6681 );
6682 }
6683  
6684 sub extractWinzoneSwitches {
6685  
6686 # Called by GA::Cmd::AddWinzone->do and ModifyWinzone->do
6687 # Extracts the switch options these commands have in common
6688 # Checks that each pattern found is valid, and that the compulsory switch options are
6689 # present
6690 #
6691 # Expected arguments
6692 # $session - The calling function's GA::Session
6693 # $inputString - What the user actually typed (e.g.
6694 # ';awz -p 10 10 -s 10 10 -n MyPackage');
6695 # $standardCmd - The standard version of the command, i.e. 'addwinzone'
6696 # @args - A list of arguments specified by the calling command,
6697 # e.g. ('-p', 10, 10, '-s', 10, 10, '-n', 'MyPackage')
6698 #
6699 # Return values
6700 # Returns 'undef' on improper arguments or on failure
6701 # Otherwise returns a list of arguments in the form
6702 # (
6703 # TRUE,
6704 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
6705 # $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
6706 # \%initHash, \%removeHash,
6707 # @args,
6708 # )
6709 # The first argument, TRUE, is the flag to signal success of this function
6710 # The final argument, @args, contain any remaining arguments after the switch options
6711 # have been extracted
6712  
6713 my ($self, $session, $inputString, $standardCmd, @args) = @_;
6714  
6715 # Local variables
6716 my (
6717 $switch, $exitFlag,
6718 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
6719 $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
6720 %initHash, %removeHash,
6721 );
6722  
6723 # Check for improper arguments
6724 if (! defined $session || ! defined $inputString || ! defined $standardCmd) {
6725  
6726 return $self->improper($session, $inputString);
6727 }
6728  
6729 # Extract compulsory switches (optional for ;modifywinzone)
6730 ($switch, $xPosBlocks, $yPosBlocks, @args) = $self->extract('-p', 2, @args);
6731 if (defined $switch) {
6732  
6733 $positionFlag = TRUE;
6734 }
6735  
6736 ($switch, $widthBlocks, $heightBlocks, @args) = $self->extract('-s', 2, @args);
6737 if (defined $switch) {
6738  
6739 $sizeFlag = TRUE;
6740 }
6741  
6742 ($switch, $packageName, @args) = $self->extract('-n', 1, @args);
6743 if (defined $switch) {
6744  
6745 $packageNameFlag = TRUE;
6746  
6747 if (! ($packageName =~ m/\:\:/)) {
6748  
6749 $packageName = 'Games::Axmud::Strip::' . $packageName;
6750 }
6751 }
6752  
6753 # Extract optional switches
6754 ($switch, $objName, @args) = $self->extract('-o', 1, @args);
6755 if (defined $switch) {
6756  
6757 $objNameFlag = TRUE;
6758 }
6759  
6760 do {
6761  
6762 my ($key, $value, $key2);
6763  
6764 $exitFlag = TRUE;
6765  
6766 ($switch, $key, $value, @args) = $self->extract('-i', 2, @args);
6767 if (defined $switch) {
6768  
6769 $exitFlag = FALSE;
6770 $initHash{$key} = $value;
6771 }
6772  
6773 ($switch, $key2, @args) = $self->extract('-r', 1, @args);
6774 if (defined $switch) {
6775  
6776 $exitFlag = FALSE;
6777 $removeHash{$key} = undef;
6778 }
6779  
6780 } until ($exitFlag);
6781  
6782 # Check compulsory switch options (optional for ;modifywinzone)
6783 if (
6784 $standardCmd eq 'addwinzone'
6785 && (
6786 ! defined $positionFlag || ! defined $sizeFlag || ! $packageNameFlag
6787 || ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $widthBlocks
6788 || ! defined $heightBlocks || ! defined $packageName
6789 )
6790 ) {
6791 return $self->error(
6792 $session, $inputString,
6793 'Can\'t add/modify a winzone: missing compulsory switch options',
6794 );
6795  
6796 } elsif (
6797 $standardCmd eq 'modifywinzone'
6798 && (
6799 (
6800 $positionFlag && (! defined $xPosBlocks || ! defined $yPosBlocks)
6801 ) || (
6802 $sizeFlag && (! defined $widthBlocks || ! defined $heightBlocks)
6803 ) || (
6804 $packageNameFlag && ! defined $packageName
6805 ) || %removeHash
6806 )
6807 ) {
6808 return $self->error(
6809 $session, $inputString,
6810 'Can\'t add/modify a winzone: incomplete optional switch options',
6811 );
6812  
6813 }
6814  
6815 # Return list of arguments. The 1st argument is the flag to signal success
6816 return (
6817 TRUE,
6818 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $packageName, $objName,
6819 $positionFlag, $sizeFlag, $packageNameFlag, $objNameFlag,
6820 \%initHash, \%removeHash,
6821 @args
6822 );
6823 }
6824  
6825 sub extractZoneModelSwitches {
6826  
6827 # Called by GA::Cmd::AddZoneModel->do and ModifyZoneModel->do
6828 # Extracts the switch options these commands have in common
6829 # Checks that each pattern found is valid, and that the compulsory switch options are
6830 # present
6831 #
6832 # Expected arguments
6833 # $session - The calling function's GA::Session
6834 # $inputString - What the user actually typed (e.g.
6835 # ';azl -p 10 10 -s 10 10');
6836 # $standardCmd - The standard version of the command, i.e. 'addzonemodel'
6837 # @args - A list of arguments specified by the calling command,
6838 # e.g. ('-p', 10, 10, '-s', 10, 10)
6839 #
6840 # Return values
6841 # Returns 'undef' on improper arguments or on failure
6842 # Otherwise returns a list of arguments in the form
6843 # (
6844 # TRUE,
6845 # $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner,
6846 # $orientation, $maxWindows, $maxVisibleWindows, $defaultWidthBlocks,
6847 # $defaultHeightBlocks, $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
6848 # $positionFlag, $sizeFlag, $singleLayerFlag, startCornerFlag,
6849 # $orientationFlag, $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag,
6850 # $defaultHeightFlag, $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag,
6851 # $gridWinmapFlag,
6852 # @args,
6853 # )
6854 # The first argument, TRUE, is the flag to signal success of this function
6855 # The final argument, @args, contain any remaining arguments after the switch options
6856 # have been extracted
6857  
6858 my ($self, $session, $inputString, $standardCmd, @args) = @_;
6859  
6860 # Local variables
6861 my (
6862 $switch, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner,
6863 $orientation, $maxWindows, $maxVisibleWindows, $defaultWidthBlocks,
6864 $defaultHeightBlocks, $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
6865 $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
6866 $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
6867 $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
6868 );
6869  
6870 # Check for improper arguments
6871 if (! defined $session || ! defined $inputString || ! defined $standardCmd) {
6872  
6873 return $self->improper($session, $inputString);
6874 }
6875  
6876 # Extract compulsory switches (optional for ;modifyzonemodel)
6877 ($switch, $xPosBlocks, $yPosBlocks, @args) = $self->extract('-p', 2, @args);
6878 if (defined $switch) {
6879  
6880 $positionFlag = TRUE;
6881 }
6882  
6883 ($switch, $widthBlocks, $heightBlocks, @args) = $self->extract('-s', 2, @args);
6884 if (defined $switch) {
6885  
6886 $sizeFlag = TRUE;
6887 }
6888  
6889 # Extract optional switches
6890 ($switch, @args) = $self->extract('-l', 0, @args);
6891 if (defined $switch) {
6892  
6893 $singleLayerFlag = TRUE;
6894 }
6895  
6896 ($switch, $startCorner, @args) = $self->extract('-c', 1, @args);
6897 if (defined $switch) {
6898  
6899 $startCornerFlag = TRUE;
6900 }
6901  
6902 ($switch, $orientation, @args) = $self->extract('-o', 1, @args);
6903 if (defined $switch) {
6904  
6905 $orientationFlag = TRUE;
6906 }
6907  
6908 ($switch, $maxWindows, @args) = $self->extract('-m', 1, @args);
6909 if (defined $switch) {
6910  
6911 $maxWindowFlag = TRUE;
6912 }
6913  
6914 ($switch, $maxVisibleWindows, @args) = $self->extract('-v', 1, @args);
6915 if (defined $switch) {
6916  
6917 $maxVisibleWindowFlag = TRUE;
6918 }
6919  
6920 ($switch, $defaultWidthBlocks, @args) = $self->extract('-w', 1, @args);
6921 if (defined $switch) {
6922  
6923 $defaultWidthFlag = TRUE;
6924 }
6925  
6926 ($switch, $defaultHeightBlocks, @args) = $self->extract('-h', 1, @args);
6927 if (defined $switch) {
6928  
6929 $defaultHeightFlag = TRUE;
6930 }
6931  
6932 ($switch, $ownerID, @args) = $self->extract('-i', 1, @args);
6933 if (defined $switch) {
6934  
6935 $ownerIDFlag = TRUE;
6936 }
6937  
6938 ($switch, $enabledWinmap, @args) = $self->extract('-a', 1, @args);
6939 if (defined $switch) {
6940  
6941 $enabledWinmapFlag = TRUE;
6942 }
6943  
6944 ($switch, $disabledWinmap, @args) = $self->extract('-d', 1, @args);
6945 if (defined $switch) {
6946  
6947 $disabledWinmapFlag = TRUE;
6948 }
6949  
6950 ($switch, $gridWinmap, @args) = $self->extract('-g', 1, @args);
6951 if (defined $switch) {
6952  
6953 $gridWinmapFlag = TRUE;
6954 }
6955  
6956 # Check compulsory switch options (optional for ;modifyzonemodel)
6957 if (
6958 $standardCmd eq 'addzonemodel'
6959 && (
6960 ! $positionFlag || ! $sizeFlag || ! defined $xPosBlocks || ! defined $yPosBlocks
6961 || ! defined $widthBlocks || ! defined $heightBlocks
6962 )
6963 ) {
6964 return $self->error(
6965 $session, $inputString,
6966 'Can\'t add/modify a zone model: missing compulsory switch options',
6967 );
6968  
6969 } elsif (
6970 $standardCmd eq 'modifyzonemodel'
6971 && (
6972 (
6973 $positionFlag && (! defined $xPosBlocks || ! defined $yPosBlocks)
6974 ) || (
6975 $sizeFlag && (! defined $widthBlocks || ! defined $heightBlocks)
6976 )
6977 )
6978 ) {
6979 return $self->error(
6980 $session, $inputString,
6981 'Can\'t add/modify a zone model: incomplete optional switch options',
6982 );
6983  
6984 # Check optional switch options
6985 } elsif (
6986  
6987 $startCornerFlag
6988 && (
6989 ! defined $startCorner
6990 || (
6991 $startCorner ne 'top_left' && $startCorner ne 'top_right'
6992 && $startCorner ne 'bottom_left' && $startCorner ne 'bottom_right'
6993 )
6994 )
6995 ) {
6996 return $self->error(
6997 $session, $inputString,
6998 'Can\'t add/modify a zone model: invalid start corner settings',
6999 );
7000  
7001 } elsif (
7002  
7003 $orientationFlag
7004 && (
7005 ! defined $orientation
7006 || (
7007 $orientation ne 'horizontal' && $orientation ne 'vertical'
7008 )
7009 )
7010 ) {
7011 return $self->error(
7012 $session, $inputString,
7013 'Can\'t add/modify a zone model: invalid orientation settings',
7014 );
7015  
7016 } elsif (defined $maxWindowFlag && (!($maxWindows =~ /\D/) || $maxWindows < 0)) {
7017  
7018 return $self->error(
7019 $session, $inputString,
7020 'Can\'t add/modify a zone model: invalid max window settings',
7021 );
7022  
7023 } elsif (
7024  
7025 $maxVisibleWindowFlag
7026 && (! ($maxVisibleWindows =~ /\D/))
7027 ) {
7028 return $self->error(
7029 $session, $inputString,
7030 'Can\'t add/modify a zone model: invalid max visible window settings',
7031 );
7032  
7033 } elsif (
7034  
7035 $defaultWidthFlag
7036 && (
7037 ! ($defaultWidthBlocks =~ /\D/)
7038 || $defaultWidthBlocks > 60
7039 )
7040 ) {
7041 return $self->error(
7042 $session, $inputString,
7043 'Can\'t add/modify a zone model: invalid default width settings',
7044 );
7045  
7046 } elsif (
7047 $defaultHeightFlag
7048 && (
7049 ! ($defaultHeightBlocks =~ /\D/)
7050 || $defaultHeightBlocks > 60
7051 )
7052 ) {
7053 return $self->error(
7054 $session, $inputString,
7055 'Can\'t add/modify a zone model: invalid default height settings',
7056 );
7057 }
7058  
7059 # Return list of arguments. The 1st argument is the flag to signal success
7060 return (
7061 TRUE,
7062 $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $startCorner, $orientation,
7063 $maxWindows, $maxVisibleWindows, $defaultWidthBlocks, $defaultHeightBlocks,
7064 $ownerID, $enabledWinmap, $disabledWinmap, $gridWinmap,
7065 $positionFlag, $sizeFlag, $singleLayerFlag, $startCornerFlag, $orientationFlag,
7066 $maxWindowFlag, $maxVisibleWindowFlag, $defaultWidthFlag, $defaultHeightFlag,
7067 $ownerIDFlag, $enabledWinmapFlag, $disabledWinmapFlag, $gridWinmapFlag,
7068 @args
7069 );
7070 }
7071  
7072 ##################
7073 # Accessors - set
7074  
7075 sub add_userCmd {
7076  
7077 my ($self, $cmd, $check) = @_;
7078  
7079 # Local variables
7080 my @list;
7081  
7082 # Check for improper arguments
7083 if (! defined $cmd || defined $check) {
7084  
7085 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_userCmd', @_);
7086 }
7087  
7088 @list = ($self->userCmdList, $cmd);
7089  
7090 # Sort in order of size
7091 @list = sort {
7092 if (length($a) == length($b)) {
7093 return (lc($a) cmp lc($b));
7094 } else {
7095 return length($a) <=> length($b);
7096 }
7097 } (@list);
7098  
7099 $self->ivPoke('userCmdList', @list);
7100  
7101 return 1;
7102 }
7103  
7104 sub del_userCmd {
7105  
7106 my ($self, $cmd, $check) = @_;
7107  
7108 # Local variables
7109 my @list;
7110  
7111 # Check for improper arguments
7112 if (! defined $cmd || defined $check) {
7113  
7114 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_userCmd', @_);
7115 }
7116  
7117 if ($cmd eq $self->standardCmd) {
7118  
7119 # Can't delete the corresponding user command
7120 return undef;
7121  
7122 } else {
7123  
7124 foreach my $item ($self->userCmdList) {
7125  
7126 if ($item ne $cmd) {
7127  
7128 push (@list, $item);
7129 }
7130 }
7131  
7132 $self->ivPoke('userCmdList', @list);
7133  
7134 return 1;
7135 }
7136 }
7137  
7138 sub reset_userCmd {
7139  
7140 my ($self, $check) = @_;
7141  
7142 # Local variables
7143 my @list;
7144  
7145 # Check for improper arguments
7146 if (defined $check) {
7147  
7148 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_userCmd', @_);
7149 }
7150  
7151 # Reset the list
7152 $self->ivPoke('usrCmdList', $self->defaultUserCmdList);
7153  
7154 return 1;
7155 }
7156  
7157 ##################
7158 # Accessors - get
7159  
7160 sub standardCmd
7161 { $_[0]->{standardCmd} }
7162  
7163 sub defaultUserCmdList
7164 { my $self = shift; return @{$self->{defaultUserCmdList}}; }
7165 sub userCmdList
7166 { my $self = shift; return @{$self->{userCmdList}}; }
7167  
7168 sub descrip
7169 { $_[0]->{descrip} }
7170 sub builtInFlag
7171 { $_[0]->{builtInFlag} }
7172 sub disconnectFlag
7173 { $_[0]->{disconnectFlag} }
7174 sub noBracketFlag
7175 { $_[0]->{noBracketFlag} }
7176 }
7177  
7178 { package Games::Axmud::Generic::ConfigWin;
7179  
7180 use strict;
7181 use warnings;
7182 use diagnostics;
7183  
7184 use Glib qw(TRUE FALSE);
7185  
7186 our @ISA = qw(
7187 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
7188 );
7189  
7190 ##################
7191 # Constructors
7192  
7193 sub new {
7194  
7195 # Called by GA::Generic::Win->createFreeWin
7196 # Creates a new instance of a 'config' window (any 'free' window object inheriting from this
7197 # object, namely 'edit' windows and 'pref' windows)
7198 #
7199 # Expected arguments
7200 # $number - Unique number for this window object
7201 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
7202 # should be created
7203 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
7204 # 'free' window object. When this window opens/closes, the owner is
7205 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
7206 # functions
7207 #
7208 # Optional arguments
7209 # $session - The GA::Session from which this function was called. 'undef' if the
7210 # calling function didn't specify a session and $owner's ->session IV
7211 # is also 'undef'
7212 # $title - A string to use as the window title. If 'undef', a generic title is
7213 # used
7214 # $editObj - The object to be edited in the window (for 'edit' windows only;
7215 # should be 'undef' for 'pref' windows)
7216 # $tempFlag - Flag set to TRUE if $editObj is either temporary, or has not yet been
7217 # added to any registry (usually because the user needs to name it
7218 # first). Set to FALSE (or 'undef') otherwise. Ignored if $editObj is
7219 # not specified
7220 # %configHash - Hash containing any number of key-value pairs needed for this
7221 # particular 'config' window; for example, for example,
7222 # GA::PrefWin::TaskStart uses it to specify a task name and type.
7223 # Set to an empty hash if not required
7224 # - This type of window object recognises these initialisation settings:
7225 #
7226 # ...
7227 #
7228 # Return values
7229 # 'undef' on improper arguments
7230 # Blessed reference to the newly-created object on success
7231  
7232 my (
7233 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
7234 %configHash,
7235 ) = @_;
7236  
7237 # Local variables
7238 my ($winType, $winName, $winHeight);
7239  
7240 # Check for improper arguments
7241 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
7242  
7243 return $axmud::CLIENT->writeImproper($class . '->new', @_);
7244 }
7245  
7246 # Set the values to use for some standard window IVs
7247 if ($editObj) {
7248  
7249 $winType = 'edit';
7250 $winName = 'edit';
7251 if (! defined $title) {
7252  
7253 $title = 'Edit window';
7254 }
7255  
7256 } else {
7257  
7258 $winType = 'pref';
7259 $winName = 'pref';
7260 if (! defined $title) {
7261  
7262 $title = 'Preference window';
7263 }
7264 }
7265  
7266 # For the benefit of MS Windows and its enormous buttons, increase the height of all
7267 # 'config' windows a little (this removes scrollbars in almost all tabs)
7268 $winHeight = $axmud::CLIENT->customFreeWinHeight;
7269 if (
7270 $^O eq 'MSWin32'
7271 && $axmud::CLIENT->customFreeWinHeight eq $axmud::CLIENT->constFreeWinHeight
7272 ) {
7273 $winHeight += 30;
7274 }
7275  
7276 # Setup
7277 my $self = {
7278 _objName => $winType . '_win_' . $number,
7279 _objClass => $class,
7280 _parentFile => undef, # No parent file object
7281 _parentWorld => undef, # No parent file object
7282 _privFlag => TRUE, # All IVs are private
7283  
7284 # Standard window object IVs
7285 # --------------------------
7286  
7287 # Unique number for this window object
7288 number => $number,
7289 # The window category - 'grid' or 'free'
7290 winCategory => 'free',
7291 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
7292 winType => $winType,
7293 # A name for the window (for 'config' windows, the same as the window type)
7294 winName => $winName,
7295 # The GA::Obj::Workspace object for the workspace in which this window is created
7296 workspaceObj => $workspaceObj,
7297 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
7298 # object. When this window opens/closes, the owner is informed via calls to its
7299 # ->add_childFreeWin / ->del_childFreeWin functions
7300 owner => $owner,
7301 # The GA::Session from which this function was called. 'undef' if the calling function
7302 # didn't specify a session and $owner's ->session IV is also 'undef'
7303 session => $session,
7304 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
7305 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
7306 # displayed in a 'dialogue' window)
7307 pseudoCmdMode => 'win_error',
7308  
7309 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
7310 # parent 'main' window's Gtk3::Window
7311 # The code should use this IV when it wants to do something to the window itself
7312 # (minimise it, make it active, etc)
7313 winWidget => undef,
7314 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
7315 # the parent GA::Table::PseudoWin table object
7316 # The code should use this IV when it wants to add, modify or remove widgets inside the
7317 # window itself
7318 winBox => undef,
7319 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
7320 # FALSE if not
7321 enabledFlag => FALSE,
7322 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
7323 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
7324 visibleFlag => TRUE,
7325 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
7326 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
7327 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
7328 childFreeWinHash => {},
7329 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
7330 # window is informed via a call to $self->del_childFreeWin
7331 # When the child is destroyed, this window might want to call some of its own functions
7332 # to update various widgets and/or IVs, in which case this window adds an entry to
7333 # this hash; a hash in the form
7334 # $childDestroyHash{unique_number} = list_reference
7335 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
7336 # reference to a list in groups of 2, in the form
7337 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
7338 childDestroyHash => {},
7339  
7340 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
7341 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
7342 # area)
7343 packingBox => undef, # Gtk3::VBox
7344  
7345 # Standard IVs for 'free' windows
7346  
7347 # The window's default size, in pixels
7348 widthPixels => $axmud::CLIENT->customFreeWinWidth,
7349 heightPixels => $winHeight,
7350 # Default border/item spacing sizes used in the window, in pixels
7351 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
7352 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
7353  
7354 # A string to use as the window title. If 'undef', a generic title is used
7355 title => $title,
7356 # Hash containing any number of key-value pairs needed for this particular 'config'
7357 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
7358 # name and type. Set to an empty hash if not required
7359 configHash => {%configHash},
7360  
7361 # Standard IVs for 'config' windows
7362  
7363 # Widgets
7364 notebook => undef, # Gtk3::Notebook
7365 hBox => undef, # Gtk3::HBox
7366 okButton => undef, # Gtk3::Button
7367 cancelButton => undef, # Gtk3::Button
7368 resetButton => undef, # Gtk3::Button
7369 saveButton => undef, # Gtk3::Button
7370  
7371 # The standard grid size for the notebook (any 'edit'/'pref' window can use a different
7372 # size, if it wants)
7373 gridSize => 12,
7374  
7375 # The object to be edited in the window (for 'edit' windows only; should be 'undef' for
7376 # 'pref' windows)
7377 editObj => $editObj,
7378 # Flag set to TRUE if $editObj is either temporary, or has not yet been added to any
7379 # registry (usually because the user needs to name it first). Set to FALSE
7380 # (or 'undef') otherwise. Ignored if $editObj is not specified
7381 tempFlag => $tempFlag,
7382 # Flag that can be set to TRUE (usually by $self->setupNotebook or ->expandNotebook) if
7383 # $editObj is a current object (e.g. if it is a current profile); set to FALSE at all
7384 # other times
7385 currentFlag => FALSE,
7386 # For 'edit' windows, a hash of IVs in $editObj that should be changed. If no changes
7387 # have been made in the 'edit' window, the hash is empty; otherwise the hash contains
7388 # the new values for each IV to be modified
7389 # Hash in the form:
7390 # ->editHash{iv_name} = scalar;
7391 # ->editHash{iv_name} = list_reference;
7392 # ->editHash{iv_name} = hash_reference;
7393 # For 'pref' windows, a hash of key-value pairs set by the window's widgets;
7394 # $self->enableButtons can access this hash to perform any necessary actions
7395 # ('pref' windows don't make a call to ->saveChanges)
7396 editHash => {},
7397 # Hash containing any number of key-value pairs needed for this particular
7398 # 'edit'/'pref' window; for example, GA::PrefWin::TaskStart uses it to specify a task
7399 # name and type. Set to an empty hash if not required
7400 editConfigHash => \%configHash,
7401 };
7402  
7403 # Bless the object into existence
7404 bless $self, $class;
7405  
7406 return $self;
7407 }
7408  
7409 ##################
7410 # Methods
7411  
7412 # Standard window object functions
7413  
7414 # sub winSetup {} # Inherited from GA::Generic::FreeWin
7415  
7416 sub winEnable {
7417  
7418 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
7419 # After the Gtk3::Window has been setup and moved into position, makes it visible
7420 #
7421 # Expected arguments
7422 # (none besides $self)
7423 #
7424 # Return values
7425 # 'undef' on improper arguments or if $self->editObj is the wrong type of object
7426 # 1 on success
7427  
7428 my ($self, $check) = @_;
7429  
7430 # Check for improper arguments
7431 if (defined $check) {
7432  
7433 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
7434 }
7435  
7436 # For 'edit' windows, check that $self->editObj is of the right type. For 'pref' windows,
7437 # $self->editObj is not set, so the check always succeeds
7438 if (! $self->checkEditObj()) {
7439  
7440 return undef;
7441 }
7442  
7443 # Make the window appear on the desktop
7444 $self->winShowAll($self->_objClass . '->winEnable');
7445 $self->ivPoke('enabledFlag', TRUE);
7446  
7447 return 1;
7448 }
7449  
7450 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
7451  
7452 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
7453  
7454 # sub winShowAll {} # Inherited from GA::Generic::Win
7455  
7456 sub drawWidgets {
7457  
7458 # Called by $self->winSetup
7459 # Sets up the 'edit'/'pref' window with its standard widgets
7460 #
7461 # Expected arguments
7462 # (none besides $self)
7463 #
7464 # Return values
7465 # 'undef' on improper arguments
7466 # 1 otherwise
7467  
7468 my ($self, $check) = @_;
7469  
7470 # Check for improper arguments
7471 if (defined $check) {
7472  
7473 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
7474 }
7475  
7476 # Create a packing box
7477 my $packingBox = Gtk3::VBox->new(FALSE, 0);
7478 $self->winBox->add($packingBox);
7479 $packingBox->set_border_width(0);
7480  
7481 # Add a notebook at the top
7482 my $notebook = Gtk3::Notebook->new();
7483 $packingBox->pack_start($notebook, TRUE, TRUE, 0);
7484 $notebook->set_scrollable(TRUE);
7485 $notebook->popup_enable();
7486  
7487 # Add a button strip at the bottom, in a horizontal packing box
7488 my $hBox = Gtk3::HBox->new(FALSE, 0);
7489 $packingBox->pack_end($hBox, FALSE, FALSE, $self->spacingPixels);
7490  
7491 # Create Reset/Save/Cancel/OK buttons
7492 my ($okButton, $cancelButton, $resetButton, $saveButton) = $self->enableButtons($hBox);
7493  
7494 # Update IVs
7495 $self->ivPoke('packingBox', $packingBox);
7496 $self->ivPoke('notebook', $notebook);
7497 $self->ivPoke('hBox', $hBox);
7498 $self->ivPoke('okButton', $okButton);
7499 $self->ivPoke('cancelButton', $cancelButton);
7500 $self->ivPoke('resetButton', $resetButton);
7501 $self->ivPoke('saveButton', $saveButton);
7502  
7503 # Set up the notebook with its tabs
7504 $self->setupNotebook();
7505  
7506 return 1;
7507 }
7508  
7509 # sub redrawWidgets {} # Inherited from GA::Generic::Win
7510  
7511 # ->signal_connects
7512  
7513 sub setDeleteEvent {
7514  
7515 # Called by $self->winSetup
7516 # Set up a ->signal_connect to watch out for the user manually closing the 'config' window
7517 #
7518 # Expected arguments
7519 # (none besides $self)
7520 #
7521 # Return values
7522 # 'undef' on improper arguments
7523 # 1 otherwise
7524  
7525 my ($self, $check) = @_;
7526  
7527 # Check for improper arguments
7528 if (defined $check) {
7529  
7530 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
7531 }
7532  
7533 $self->winBox->signal_connect('delete-event' => sub {
7534  
7535 # Prevent Gtk3 from taking action directly. Instead redirect the request to
7536 # $self->winDestroy
7537 return $self->winDestroy();
7538 });
7539  
7540 return 1;
7541 }
7542  
7543 # Other functions
7544  
7545 sub checkEditObj {
7546  
7547 # Called by $self->winEnable
7548 # For 'edit' windows, checks that the object stored in $self->editObj is the correct class
7549 # of object. For 'pref' windows, the check always succeeds (because 'pref' windows don't
7550 # have an ->editObj)
7551 #
7552 # Expected arguments
7553 # (none besides $self)
7554 #
7555 # Return values
7556 # 'undef' on improper arguments or if the check fails
7557 # 1 if the check succeeds
7558  
7559 my ($self, $check) = @_;
7560  
7561 # Check for improper arguments
7562 if (defined $check) {
7563  
7564 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEditObj', @_);
7565 }
7566  
7567 # (Everything inherits from Games::Axmud, so in this generic function the check always
7568 # succeeds)
7569 if ($self->editObj && ! $self->editObj->isa('Games::Axmud')) {
7570 return undef;
7571 } else {
7572 return 1;
7573 }
7574 }
7575  
7576 sub enableButtons {
7577  
7578 # Called by $self->drawWidgets
7579 # Creates the OK/Cancel/Save/Reset buttons at the bottom of the window
7580 # Individual 'edit'/'pref' windows almost always inherit the generic ->winEnable method,
7581 # but can use their own $self->enableButtons (rather than inherit this one) if they don't
7582 # need all four buttons
7583 #
7584 # Expected arguments
7585 # $hBox - The horizontal packing box in which the buttons live (not yet stored as
7586 # an IV)
7587 #
7588 # Return values
7589 # An empty list on improper arguments
7590 # Otherwise, a list containing the four Gtk::Button objects created
7591  
7592 my ($self, $hBox, $check) = @_;
7593  
7594 # Local variables
7595 my @emptyList;
7596  
7597 # Check for improper arguments
7598 if (! defined $hBox || defined $check) {
7599  
7600 $axmud::CLIENT->writeImproper($self->_objClass . '->enableButtons', @_);
7601 return @emptyList;
7602 }
7603  
7604 # Create the OK button, desensitised if $self->tempFlag is TRUE
7605 my $okButton = Gtk3::Button->new('OK');
7606 $hBox->pack_end($okButton, FALSE, FALSE, $self->borderPixels);
7607 $okButton->get_child->set_width_chars(10);
7608 $okButton->signal_connect('clicked' => sub {
7609  
7610 $self->buttonOK();
7611 });
7612 $okButton->set_tooltip_text('Accept changes');
7613 if ($self->tempFlag) {
7614  
7615 $okButton->set_state('insensitive');
7616 }
7617  
7618 # Create the Cancel button (never desensitised)
7619 my $cancelButton = Gtk3::Button->new('Cancel');
7620 $hBox->pack_end($cancelButton, FALSE, FALSE, $self->spacingPixels);
7621 $cancelButton->get_child->set_width_chars(10);
7622 $cancelButton->signal_connect('clicked' => sub {
7623  
7624 $self->buttonCancel();
7625 });
7626 $cancelButton->set_tooltip_text('Cancel changes');
7627  
7628 # Create the Reset button, desensitised if $self->tempFlag is TRUE
7629 my $resetButton = Gtk3::Button->new('Reset');
7630 $hBox->pack_start($resetButton, FALSE, FALSE, $self->borderPixels);
7631 $resetButton->get_child->set_width_chars(10);
7632 $resetButton->signal_connect('clicked' => sub {
7633  
7634 $self->buttonReset();
7635 });
7636 $resetButton->set_tooltip_text('Reset changes without closing the window');
7637 if ($self->tempFlag) {
7638  
7639 $resetButton->set_state('insensitive');
7640 }
7641  
7642 # Create the Save button, desensitised if $self->tempFlag is TRUE
7643 my $saveButton = Gtk3::Button->new('Save');
7644 $hBox->pack_start($saveButton, FALSE, FALSE, $self->borderPixels);
7645 $saveButton->get_child->set_width_chars(10);
7646 $saveButton->signal_connect('clicked' => sub {
7647  
7648 $self->buttonSave();
7649 });
7650 $saveButton->set_tooltip_text('Save changes without closing the window');
7651 if ($self->tempFlag) {
7652  
7653 $saveButton->set_state('insensitive');
7654 }
7655  
7656 return ($okButton, $cancelButton, $resetButton, $saveButton);
7657 }
7658  
7659 sub enableSingleButton {
7660  
7661 # Called by $self->enableButtons when only a single 'OK' button is required (rather than
7662 # the usual four)
7663 # Creates the OK button at the bottom of the window
7664 #
7665 # Expected arguments
7666 # $hBox - The horizontal packing box in which the buttons live
7667 #
7668 # Return values
7669 # An empty list on improper arguments
7670 # Otherwise, a list containing the Gtk::Button object created
7671  
7672 my ($self, $hBox, $check) = @_;
7673  
7674 # Local variables
7675 my @emptyList;
7676  
7677 # Check for improper arguments
7678 if (! defined $hBox || defined $check) {
7679  
7680 $axmud::CLIENT->writeImproper($self->_objClass . '->enableSingleButton', @_);
7681 return @emptyList;
7682 }
7683  
7684 # Create the OK button
7685 my $okButton = Gtk3::Button->new('OK');
7686 $hBox->pack_end($okButton, FALSE, FALSE, $self->borderPixels);
7687 $okButton->get_child->set_width_chars(10);
7688 $okButton->signal_connect('clicked' => sub {
7689  
7690 $self->buttonOK();
7691 });
7692 $okButton->set_tooltip_text('Close window');
7693  
7694 # This object doesn't edit anything, so we don't need Cancel/Reset/Edit buttons
7695 return ($okButton);
7696 }
7697  
7698 sub setupNotebook {
7699  
7700 # Called by $self->winEnable
7701 # Creates the first tab for the notebook. The remaining tabs are created by
7702 # $self->expandNotebook
7703 #
7704 # Expected arguments
7705 # (none besides $self)
7706 #
7707 # Return values
7708 # 'undef' on improper arguments
7709 # 1 otherwise
7710  
7711 my ($self, $check) = @_;
7712  
7713 # Check for improper arguments
7714 if (defined $check) {
7715  
7716 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupNotebook', @_);
7717 }
7718  
7719 # Tab setup, using the standard grid size
7720 my $grid = $self->addTab('_Name', $self->notebook);
7721  
7722 # Set up the rest of the tab
7723 $self->nameTab($grid);
7724  
7725 # Set up the remaining tabs
7726 $self->expandNotebook();
7727  
7728 # Tab complete
7729 return 1;
7730 }
7731  
7732 sub expandNotebook {
7733  
7734 # Called by $self->setupNotebook
7735 # Set up additional tabs for the notebook, depending on which type of object is being edited
7736 # Because this is the generic function, no additional tabs are actually set up here. This
7737 # generic function is usually only called for 'edit'/'pref' windows which have a single
7738 # tab (such as GA::EditWin::Interface::Active)
7739 #
7740 # Expected arguments
7741 # (none besides $self)
7742 #
7743 # Return values
7744 # 'undef' on improper arguments
7745 # 1 otherwise
7746  
7747 my ($self, $check) = @_;
7748  
7749 # Check for improper arguments
7750 if (defined $check) {
7751  
7752 return $axmud::CLIENT->writeImproper($self->_objClass . '->expandNotebook', @_);
7753 }
7754  
7755 # $self->additionalTab();
7756  
7757 return 1;
7758 }
7759  
7760 sub saveChanges {
7761  
7762 # Called by $self->buttonOK and $self->buttonSave (usually for 'edit' windows only, not
7763 # 'pref' windows)
7764 # Saves any changes made to data stored by the edit object
7765 #
7766 # Expected arguments
7767 # (none besides $self)
7768 #
7769 # Return values
7770 # 'undef' on improper arguments
7771 # 1 otherwise
7772  
7773 my ($self, $check) = @_;
7774  
7775 # Check for improper arguments
7776 if (defined $check) {
7777  
7778 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
7779 }
7780  
7781 if ($self->editHash) {
7782  
7783 # Store the changes the user has made
7784 foreach my $key ($self->ivKeys('editHash')) {
7785  
7786 $self->editObj->{$key} = $self->ivShow('editHash', $key);
7787 }
7788  
7789 # The changes can now be cleared
7790 $self->ivEmpty('editHash');
7791  
7792 # Mark the object's corresponding file object as needing to be saved, if it exists
7793 if ($self->editObj->_parentFile) {
7794  
7795 $self->editObj->doModify('saveChanges');
7796 }
7797  
7798 # Update the current session's object viewer window, if it is open
7799 if ($self->session->viewerWin) {
7800  
7801 $self->session->viewerWin->updateNotebook();
7802 }
7803 }
7804  
7805 return 1;
7806 }
7807  
7808 # Add widgets
7809  
7810 sub addTab {
7811  
7812 # Adds a tab to the notebook, creating a scroller and a grid, all with standardised sizes
7813 #
7814 # Expected arguments
7815 # $tabName - A mnemonic string, e.g. 'N_ame'
7816 # $notebook - The Gtk3::Notebook object to which this tab will be added
7817 #
7818 # Optional arguments
7819 # $columnSpaceWidth, $columnSpaceHeight
7820 # - The spacing between columns/rows, in pixels. If either of both is set to
7821 # 'undef', the default size is used ($self->spacingPixels)
7822 #
7823 # Return values
7824 # 'undef' on improper arguments
7825 # Otherwise returns the Gtk3::Grid created
7826  
7827 my ($self, $tabName, $notebook, $columnSpaceWidth, $columnSpaceHeight, $check) = @_;
7828  
7829 # Check for improper arguments
7830 if (! defined $tabName || ! defined $notebook || defined $check) {
7831  
7832 return $amid::MAIN->writeImproper($self->_objClass . '->addTab', @_);
7833 }
7834  
7835 # Set default sizes
7836 if (! defined $columnSpaceWidth) {
7837  
7838 $columnSpaceWidth = $self->spacingPixels;
7839 }
7840  
7841 if (! defined $columnSpaceHeight) {
7842  
7843 $columnSpaceHeight = $self->spacingPixels;
7844 }
7845  
7846 # Tab setup
7847 my $scroller = Gtk3::ScrolledWindow->new();
7848 $scroller->set_policy('automatic', 'automatic');
7849  
7850 my $tab = Gtk3::Label->new_with_mnemonic($tabName);
7851 $notebook->append_page($scroller, $tab);
7852  
7853 my $grid = Gtk3::Grid->new();
7854 $scroller->add_with_viewport($grid);
7855 $grid->set_border_width($self->spacingPixels);
7856 $grid->set_column_spacing($columnSpaceWidth);
7857 $grid->set_row_spacing($columnSpaceHeight);
7858  
7859 return $grid;
7860 }
7861  
7862 sub addInnerNotebookTab {
7863  
7864 # Adds a tab to the notebook containing an inner notebook, so that we get a second row of
7865 # tabs immediately beneath the first one
7866 #
7867 # Expected arguments
7868 # $tabName - A mnemonic string, e.g. 'N_ame'
7869 # $notebook - The Gtk3::Notebook object to which this tab will be added
7870 #
7871 # Return values
7872 # 'undef' on improper arguments
7873 # Otherwise returns the Gtk3::Notebook created
7874  
7875 my ($self, $tabName, $notebook, $check) = @_;
7876  
7877 # Check for improper arguments
7878 if (defined $check) {
7879  
7880 return $axmud::CLIENT->writeImproper($self->_objClass . '->addInnerNotebookTab', @_);
7881 }
7882  
7883 # Tab setup
7884 my $innerNotebook = Gtk3::Notebook->new();
7885 $innerNotebook->set_scrollable(TRUE);
7886 $innerNotebook->popup_enable();
7887  
7888 my $tab = Gtk3::Label->new_with_mnemonic($tabName);
7889 $notebook->append_page($innerNotebook, $tab);
7890  
7891 # Tab complete
7892 return $innerNotebook;
7893 }
7894  
7895 sub addLabel {
7896  
7897 # Adds a Gtk3::Label at the specified position in the tab's Gtk3::Grid
7898 #
7899 # Example calls:
7900 # my $label = $self->addLabel($grid, 'Some plain text',
7901 # 0, 6, 0, 1);
7902 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
7903 # 0, 6, 0, 1,
7904 # 0, 0.5);
7905 #
7906 # Expected arguments
7907 # $grid - The tab's Gtk3::Grid object
7908 # $text - The text to display (plain text or pango markup text)
7909 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
7910 # - The position of the label in the grid
7911 #
7912 # Optional arguments
7913 # $alignLeft, $alignRight
7914 # - Used in the call to ->set_alignment; two values in the range 0-1
7915 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
7916 #
7917 # Return values
7918 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
7919 # Otherwise the Gtk3::Label created
7920  
7921 my (
7922 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
7923 $alignRight, $check
7924 ) = @_;
7925  
7926 # Check for improper arguments
7927 if (
7928 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
7929 || ! defined $topAttach || ! defined $bottomAttach || defined $check
7930 ) {
7931 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
7932 }
7933  
7934 # Check that the position in the grid makes sense
7935 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
7936  
7937 return undef;
7938 }
7939  
7940 # Set default alignment, if none specified
7941 if (! defined $alignLeft) {
7942  
7943 $alignLeft = 0;
7944 }
7945  
7946 if (! defined $alignRight) {
7947  
7948 $alignRight = 0.5;
7949 }
7950  
7951 # Create the label
7952 my $label = Gtk3::Label->new();
7953 $label->set_markup($text);
7954  
7955 # Set its alignment
7956 $label->set_alignment($alignLeft, $alignRight);
7957  
7958 # Add the label to the grid
7959 $label->set_hexpand(TRUE);
7960 $label->set_vexpand(FALSE);
7961 $grid->attach(
7962 $label,
7963 $leftAttach,
7964 $topAttach,
7965 ($rightAttach - $leftAttach),
7966 ($bottomAttach - $topAttach),
7967 );
7968  
7969 return $label;
7970 }
7971  
7972 sub addLabelFrame {
7973  
7974 # Adds a Gtk3::Label within a Gtk3::Frame (giving the appearance of text in a box) at the
7975 # specified position in the tab's Gtk3::Grid
7976 #
7977 # Example calls:
7978 # my $label = $self->addLabel($grid, 'Some plain text',
7979 # 0, 6, 0, 1);
7980 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
7981 # 0, 6, 0, 1,
7982 # 0, 0.5);
7983 #
7984 # Expected arguments
7985 # $grid - The tab's Gtk3::Grid object
7986 # $text - The text to display (plain text or pango markup text)
7987 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
7988 # - The position of the label in the grid
7989 #
7990 # Optional arguments
7991 # $alignLeft, $alignRight
7992 # - Used in the call to ->set_alignment; two values in the range 0-1
7993 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
7994 #
7995 # Return values
7996 # An empty list of improper arguments or if the widget's position in the Gtk3::Grid is
7997 # invalid
7998 # Otherwise, a list in the form
7999 # (gtk_frame, gtk_label)
8000  
8001 my (
8002 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
8003 $alignRight, $check
8004 ) = @_;
8005  
8006 # Local variables
8007 my @emptyList;
8008  
8009 # Check for improper arguments
8010 if (
8011 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
8012 || ! defined $topAttach || ! defined $bottomAttach || defined $check
8013 ) {
8014 $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
8015 return @emptyList;
8016 }
8017  
8018 # Check that the position in the grid makes sense
8019 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8020  
8021 return @emptyList;
8022 }
8023  
8024 # Set default alignment, if none specified
8025 if (! defined $alignLeft) {
8026  
8027 $alignLeft = 0;
8028 }
8029  
8030 if (! defined $alignRight) {
8031  
8032 $alignRight = 0.5;
8033 }
8034  
8035 # Create the frame
8036 my $frame = Gtk3::Frame->new(undef);
8037 $frame->set_border_width($self->borderPixels);
8038  
8039 # Create the label
8040 my $label = Gtk3::Label->new();
8041 $frame->add($label);
8042 $label->set_markup($text);
8043  
8044 # Set its alignment
8045 $label->set_alignment($alignLeft, $alignRight);
8046  
8047 # Add the frame to the grid
8048 $frame->set_hexpand(TRUE);
8049 $frame->set_vexpand(FALSE);
8050 $grid->attach(
8051 $frame,
8052 $leftAttach,
8053 $topAttach,
8054 ($rightAttach - $leftAttach),
8055 ($bottomAttach - $topAttach),
8056 );
8057  
8058 return ($frame, $label);
8059 }
8060  
8061 sub addButton {
8062  
8063 # Adds a Gtk3::Button at the specified position in the tab's Gtk3::Grid
8064 #
8065 # Example calls:
8066 # my $button = $self->addButton($grid, 'button_name', 'tooltips', \&buttonClicked,
8067 # 0, 6, 0, 1);
8068 # my $button = $self->addButton($grid, 'button_name', 'tooltips', undef,
8069 # 0, 6, 0, 1);
8070 # my $button = $self->addButton($grid, 'button_name', '', \&buttonClicked,
8071 # 0, 6, 0, 1);
8072 #
8073 # The referenced function (if specified) receives an argument list in the form:
8074 # ($self, button_widget)
8075 #
8076 # Expected arguments
8077 # $grid - The tab's Gtk3::Grid object
8078 # $name - The name displayed on the button
8079 # $tooltips - Tooltips to use for the button; empty strings are not used
8080 # $funcRef - Reference to the function to call when the button is clicked. If 'undef',
8081 # it's up to the calling function to create a ->signal_connect method
8082 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8083 # - The position of the button in the grid
8084 #
8085 # Optional arguments
8086 # $flag - If set to TRUE, the button is marked with an image (namely
8087 # /icons/system/irreversible.png), which shows an action which can't
8088 # easily be reversed (e.g. by clicking on the main 'Cancel' button)
8089 #
8090 # Return values
8091 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8092 # Otherwise the Gtk3::Button created
8093  
8094 my (
8095 $self, $grid, $name, $tooltips, $funcRef, $leftAttach, $rightAttach, $topAttach,
8096 $bottomAttach, $flag, $check
8097 ) = @_;
8098  
8099 # Local variables
8100 my $current;
8101  
8102 # Check for improper arguments
8103 if (
8104 ! defined $grid || ! defined $name || ! defined $tooltips || ! defined $leftAttach
8105 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8106 || defined $check
8107 ) {
8108 return $axmud::CLIENT->writeImproper($self->_objClass . '->addButton', @_);
8109 }
8110  
8111 # Check that the position in the grid makes sense
8112 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8113  
8114 return undef;
8115 }
8116  
8117 # If $flag was specified, but GA::Client->irreversibleIconFlag is FALSE, we can't draw an
8118 # icon to show the irreversible action; instead, add an asterisk to the button label
8119 if ($flag && ! $axmud::CLIENT->irreversibleIconFlag) {
8120  
8121 $name = '(*) ' . $name;
8122 }
8123  
8124 # Create the button
8125 my $button = Gtk3::Button->new($name);
8126  
8127 # If a callback function was specified, use it
8128 if ($funcRef) {
8129  
8130 $button->signal_connect('clicked' => sub {
8131  
8132 &$funcRef($self, $button);
8133 });
8134 }
8135  
8136 # Use tooltips, if any were specified
8137 if ($tooltips) {
8138  
8139 $button->set_tooltip_text($tooltips);
8140 }
8141  
8142 # Use the 'irreversible' icon, if it was specified
8143 if ($flag && $axmud::CLIENT->irreversibleIconFlag) {
8144  
8145 my $image = Gtk3::Image->new_from_file(
8146 $axmud::SHARE_DIR . '/icons/system/irreversible.png',
8147 );
8148  
8149 $button->set_image($image);
8150 }
8151  
8152 # Add the button to the grid
8153 $button->set_hexpand(TRUE);
8154 $button->set_vexpand(FALSE);
8155 $grid->attach(
8156 $button,
8157 $leftAttach,
8158 $topAttach,
8159 ($rightAttach - $leftAttach),
8160 ($bottomAttach - $topAttach),
8161 );
8162  
8163 return $button;
8164 }
8165  
8166 sub addCheckButton {
8167  
8168 # Adds a Gtk3::CheckButton with an accompanying label at the specified position in the
8169 # window's Gtk3::Grid
8170 #
8171 # Example calls:
8172 # my $checkButton = $self->addCheckButton($grid, 'Click me', 'some_IV', TRUE,
8173 # 0, 6, 0, 1);
8174 # my $checkButton = $self->addCheckButton($grid, undef, 'some_IV', TRUE,
8175 # 0, 6, 0, 1);
8176 #
8177 # Expected arguments
8178 # $grid - The tab's Gtk3::Grid object
8179 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
8180 # no name is displayed
8181 # $iv - A string naming the IV set when the check button is toggled. If 'undef',
8182 # nothing happens when the user toggles the checkbutton; it's up to the
8183 # calling function to check the button's state
8184 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
8185 # TRUE if it should be 'normal'
8186 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8187 # - The position of the checkbutton in the grid
8188 #
8189 # Return values
8190 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8191 # Otherwise the Gtk3::CheckButton created
8192  
8193 my (
8194 $self, $grid, $name, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach,
8195 $bottomAttach, $check
8196 ) = @_;
8197  
8198 # Check for improper arguments
8199 if (
8200 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
8201 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8202 || defined $check
8203 ) {
8204 return $axmud::CLIENT->writeImproper($self->_objClass . '->addCheckButton', @_);
8205 }
8206  
8207 # Check that the position in the grid makes sense
8208 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8209  
8210 return undef;
8211 }
8212  
8213 # Create the checkbutton
8214 my $checkButton;
8215 if (defined $name && $name ne '') {
8216 $checkButton = Gtk3::CheckButton->new_with_label($name);
8217 } else {
8218 $checkButton = Gtk3::CheckButton->new();
8219 }
8220  
8221 if ($iv) {
8222  
8223 # Display the existing value of the IV
8224 $checkButton->set_active($self->editObj->$iv);
8225  
8226 $checkButton->signal_connect('toggled' => sub {
8227  
8228 $self->ivAdd('editHash', $iv, $checkButton->get_active());
8229 });
8230 }
8231  
8232 # Make the checkbutton insensitive, if $stateFlag is FALSE
8233 if (! $stateFlag) {
8234  
8235 $checkButton->set_state('insensitive');
8236 }
8237  
8238 # Add the checkbutton to the grid
8239 $checkButton->set_hexpand(TRUE);
8240 $checkButton->set_vexpand(FALSE);
8241 $grid->attach(
8242 $checkButton,
8243 $leftAttach,
8244 $topAttach,
8245 ($rightAttach - $leftAttach),
8246 ($bottomAttach - $topAttach),
8247 );
8248  
8249 return $checkButton;
8250 }
8251  
8252 sub addRadioButton {
8253  
8254 # Adds a Gtk3::RadioButton at the specified position in the tab's Gtk3::Grid
8255 #
8256 # Example calls:
8257 # my ($group, $button) = $self->addRadioButton(
8258 # $grid, undef, $name, 'some_IV', $value, TRUE,
8259 # 0, 6, 0, 1);
8260 # my ($group2, $button2) = $self->addRadioButton(
8261 # $grid, $group, $name, 'some_IV', $value, TRUE,
8262 # 0, 6, 0, 1, 0, 0.5);
8263 #
8264 # Expected arguments
8265 # $grid - The tab's Gtk3::Grid object
8266 # $group - Reference to the radio button group created, when the first button in the
8267 # group was added (if set to 'undef', this is the first button, and a
8268 # group will be created for it)
8269 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
8270 # no name is displayed
8271 # $iv - A string naming the IV set when the radio button is toggled. If 'undef',
8272 # nothing happens when the user toggles the radiobutton; it's up to the
8273 # calling function to check the button's state
8274 # $value - The value to which the IV is set, when the radio button is selected
8275 # (ignored if $iv is 'undef')
8276 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
8277 # TRUE if it should be 'normal'
8278 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8279 # - The position of the radiobutton in the grid
8280 #
8281 # Optional arguments
8282 # $alignLeft, $alignRight
8283 # - Used in the call to ->set_alignment; two values in the range 0-1
8284 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
8285 #
8286 # Return values
8287 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
8288 # invalid
8289 # Otherwise a list containing two elements: the radio button $group and the
8290 # Gtk3::RadioButton created
8291  
8292 my (
8293 $self, $grid, $group, $name, $iv, $value, $stateFlag, $leftAttach, $rightAttach,
8294 $topAttach, $bottomAttach, $alignLeft, $alignRight, $check
8295 ) = @_;
8296  
8297 # Local variables
8298 my @emptyList;
8299  
8300 # Check for improper arguments
8301 if (
8302 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
8303 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8304 || defined $check
8305 ) {
8306 $axmud::CLIENT->writeImproper($self->_objClass . '->addRadioButton', @_);
8307 return @emptyList;
8308 }
8309  
8310 # Check that the position in the grid makes sense
8311 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8312  
8313 return @emptyList;
8314 }
8315  
8316 # Set default alignment, if none specified
8317 if (! defined $alignLeft) {
8318  
8319 $alignLeft = 0;
8320 }
8321  
8322 if (! defined $alignRight) {
8323  
8324 $alignRight = 0.5;
8325 }
8326  
8327 # Create the radio button
8328 my $radioButton = Gtk3::RadioButton->new();
8329 # Add it to the existing group, if one was specified
8330 if (defined $group) {
8331  
8332 $radioButton->set_group($group);
8333 }
8334  
8335 if ($iv) {
8336  
8337 # If $value is the one currently stored in $self->editObj, mark this radio button
8338 # as active
8339 if (
8340 defined $value
8341 && defined $self->editObj->$iv
8342 && $value eq $self->editObj->$iv
8343 ) {
8344 $radioButton->set_active(TRUE);
8345 }
8346  
8347 $radioButton->signal_connect('toggled' => sub {
8348  
8349 # Set the IV only if this radiobutton has been selected
8350 if ($radioButton->get_active()) {
8351  
8352 $self->ivAdd('editHash', $iv, $value);
8353 }
8354 });
8355 }
8356  
8357 # Give the radio button a name, if one was specified
8358 if ($name) {
8359  
8360 $radioButton->set_label($name);
8361 }
8362  
8363 # Make the radio button insensitive, if $stateFlag is FALSE
8364 if (! $stateFlag) {
8365  
8366 $radioButton->set_state('insensitive');
8367 }
8368  
8369 # Set radio button's alignment
8370 $radioButton->set_alignment($alignLeft, $alignRight);
8371  
8372 # Add the radio button to the grid
8373 $radioButton->set_hexpand(FALSE);
8374 $radioButton->set_vexpand(FALSE);
8375 $grid->attach(
8376 $radioButton,
8377 $leftAttach,
8378 $topAttach,
8379 ($rightAttach - $leftAttach),
8380 ($bottomAttach - $topAttach),
8381 );
8382  
8383 return ($radioButton->get_group(), $radioButton);
8384 }
8385  
8386 sub addEntry {
8387  
8388 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid
8389 #
8390 # Example calls:
8391 # my $entry = $self->addEntry($grid, 'some_IV', TRUE,
8392 # 0, 6, 0, 1);
8393 # my $entry = $self->addEntry($grid, 'some_IV', FALSE,
8394 # 0, 6, 0, 1, 16, 16);
8395 # my $entry = $self->addEntry($grid, undef, TRUE,
8396 # 0, 6, 0, 1);
8397 #
8398 # Expected arguments
8399 # $grid - The tab's Gtk3::Grid object
8400 # $iv - A string naming the IV set when the user modifies the text in the entry
8401 # box. If 'undef', nothing happens when the user modifies the text; it's
8402 # up to the calling function to check the entry box's state
8403 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
8404 # if it should be 'normal'
8405 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8406 # - The position of the entry box in the grid
8407 #
8408 # Optional arguments
8409 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
8410 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
8411 #
8412 # Return values
8413 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8414 # Otherwise the Gtk3::Entry created
8415  
8416 my (
8417 $self, $grid, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
8418 $widthChars, $maxChars, $check
8419 ) = @_;
8420  
8421 # Check for improper arguments
8422 if (
8423 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
8424 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8425 || defined $check
8426 ) {
8427 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntry', @_);
8428 }
8429  
8430 # Check that the position in the grid makes sense
8431 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8432  
8433 return undef;
8434 }
8435  
8436 # Create the entry
8437 my $entry = Gtk3::Entry->new();
8438  
8439 # Display the existing value of the IV
8440 if (defined $iv && defined $self->editObj->$iv) {
8441  
8442 $entry->set_text($self->editObj->$iv);
8443 }
8444  
8445 # Set the width, if specified
8446 if (defined $widthChars) {
8447  
8448 $entry->set_width_chars($widthChars);
8449 }
8450  
8451 # Set the maximum number of characters, if specified
8452 if (defined $maxChars) {
8453  
8454 $entry->set_max_length($maxChars);
8455 }
8456  
8457 # Signal connect
8458 if (defined $iv) {
8459  
8460 $entry->signal_connect('changed' => sub {
8461  
8462 my $text = $entry->get_text();
8463  
8464 $self->ivAdd('editHash', $iv, $text);
8465 });
8466 }
8467  
8468 # Make the entry insensitive, if $stateFlag is FALSE
8469 if (! $stateFlag) {
8470  
8471 $entry->set_state('insensitive');
8472 }
8473  
8474 # Add the entry to the grid
8475 $entry->set_hexpand(TRUE);
8476 $entry->set_vexpand(FALSE);
8477 $grid->attach(
8478 $entry,
8479 $leftAttach,
8480 $topAttach,
8481 ($rightAttach - $leftAttach),
8482 ($bottomAttach - $topAttach),
8483 );
8484  
8485 return $entry;
8486 }
8487  
8488 sub addEntryWithButton {
8489  
8490 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry is
8491 # displayed alongside a button that simultaneously shows whether the IV's value is 'undef'
8492 # and allows the user to set the IV to 'undef'
8493 #
8494 # Example calls:
8495 # my $entry = $self->addEntryWithButton($grid, 'some_IV', TRUE,
8496 # 0, 6, 0, 1);
8497 # my $entry = $self->addEntryWithButton($grid, 'some_IV', FALSE,
8498 # 0, 6, 0, 1, 16, 16);
8499 #
8500 # Expected arguments
8501 # $grid - The tab's Gtk3::Grid object
8502 # $iv - A string naming the IV set when the user modifies the text in the entry
8503 # box. Unlike most of these functions, the $iv must be specified
8504 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
8505 # if it should be 'normal'
8506 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8507 # - The position of the entry in the grid
8508 #
8509 # Optional arguments
8510 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
8511 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
8512 #
8513 # Return values
8514 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8515 # Otherwise the Gtk3::Entry created
8516  
8517 my (
8518 $self, $grid, $iv, $stateFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
8519 $widthChars, $maxChars, $check
8520 ) = @_;
8521  
8522 # Check for improper arguments
8523 if (
8524 ! defined $grid || ! defined $iv || ! defined $stateFlag || ! defined $leftAttach
8525 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8526 || defined $check
8527 ) {
8528 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithButton', @_);
8529 }
8530  
8531 # Check that the position in the grid makes sense
8532 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8533  
8534 return undef;
8535 }
8536 # Call $self->addEntry to create the entry as normal, reserving one square in the grid for
8537 # the button (we don't pass $iv to $self->addEntry because we're going to create our own
8538 # ->signal_connect)
8539 my $entry = $self->addEntry(
8540 $grid, undef, $stateFlag, $leftAttach, ($rightAttach - 1), $topAttach, $bottomAttach,
8541 $widthChars, $maxChars,
8542 );
8543  
8544 # Set the contents of the entry
8545 if (defined $iv && defined $self->editObj->$iv) {
8546  
8547 $entry->set_text($self->editObj->$iv);
8548 }
8549  
8550 # Create a button
8551 my $button = Gtk3::Button->new();
8552  
8553 # Set the icon to display on the button, depending on whether the IV is set to 'undef',
8554 # or not
8555 my $image;
8556 if (defined $iv && defined $self->editObj->$iv) {
8557  
8558 # Use the Gtk3 'clear' icon - clicking on the button sets the IV to undef
8559 $image = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
8560 # Give the button a tooltip
8561 $button->set_tooltip_text('Click to set this IV to \'undef\'');
8562  
8563 } else {
8564  
8565 # Use the Gtk3 'remove' icon - IV is already 'undef'; clicking on the button does
8566 # nothing
8567 $image = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
8568 # Give the button a tooltip
8569 $button->set_tooltip_text('This IV is already set to \'undef\'');
8570 }
8571  
8572 $button->set_image($image);
8573  
8574 # Make the button clickable
8575 $button->signal_connect('clicked' => sub {
8576  
8577 # Empty the entry to remove any text entered into it
8578 $entry->set_text('');
8579  
8580 # Set the IV to undef
8581 $self->ivAdd('editHash', $iv, undef);
8582  
8583 # Change the button's image to mark this IV as being set to undef
8584 my $image2 = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
8585 $button->set_image($image2);
8586 # Give the button a new tooltip
8587 $button->set_tooltip_text('This IV is already set to \'undef\'');
8588 });
8589  
8590 # Respond when the user types something in the box
8591 $entry->signal_connect('changed' => sub {
8592  
8593 my $text = $entry->get_text();
8594 $self->ivAdd('editHash', $iv, $text);
8595  
8596 # Contents of the entry can't possibly be 'undef' any more
8597 my $image3 = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
8598 $button->set_image($image3);
8599 # Give the button a new tooltip
8600 $button->set_tooltip_text('Click to set this IV to \'undef\'');
8601 });
8602  
8603 # Add the button to the grid (the entry has already been added)
8604 $button->set_hexpand(FALSE);
8605 $button->set_vexpand(FALSE);
8606 $leftAttach = $rightAttach - 1;
8607 $grid->attach(
8608 $button,
8609 $leftAttach,
8610 $topAttach,
8611 ($rightAttach - $leftAttach),
8612 ($bottomAttach - $topAttach),
8613 );
8614  
8615 return $entry;
8616 }
8617  
8618 sub addEntryWithIcon {
8619  
8620 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry contains
8621 # a stock icon to show whether the current contents of the entry is permissible
8622 # The stock icons used are 'gtk-yes' (for an acceptable value) and 'gtk-no' (for a
8623 # forbidden value)
8624 #
8625 # Example calls:
8626 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'int', 0, 1000,
8627 # 0, 6, 0, 1);
8628 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'odd', 1, 1001,
8629 # 0, 6, 0, 1);
8630 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'even', 0, 1000,
8631 # 0, 6, 0, 1);
8632 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'float', 0, 1000000,
8633 # 0, 6, 0, 1);
8634 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'string', 3, 16,
8635 # 0, 6, 0, 1);
8636 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'regex', 1, undef,
8637 # 0, 6, 0, 1);
8638 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', \&checkFunction, undef, undef,
8639 # 0, 6, 0, 1);
8640 #
8641 # my $entry = $self->addEntryWithIcon($grid, 'some_IV', 'int', 0, 1000,
8642 # 0, 6, 0, 1, 16, 16);
8643 #
8644 # Expected arguments
8645 # $grid - The tab's Gtk3::Grid object
8646 # $iv - A string naming the IV set when the user modifies the text in the entry
8647 # box. If 'undef', nothing happens when the user modifies the text (except
8648 # that the icon is updated); it's up to the calling function to check the
8649 # entry box's state
8650 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
8651 # function
8652 # - If 'int', an integer is expected with the specified min/max values
8653 # - If 'odd', an odd-numbered integer with the specified min/max value is
8654 # expected. If the minimum value is less than 1, 1 is used instead
8655 # - If 'even', an even-numbered integer with the specified min/max value is
8656 # expected. If the minimum value is less than 0, 0 is used instead
8657 # - If 'float', a floating point number is expected with the specified min/max
8658 # values
8659 # - If 'string', a string is expected (which might be a number) with the
8660 # specified min/max length
8661 # - If 'regex', a valid regex is expected with the specified min/max length
8662 # - If a function reference, a function is called which should return 'undef'
8663 # or 1, depending on the value of the entry; the icon is set accordingly
8664 # $min, $max - The values described above (ignored when $mode is a function reference).
8665 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
8666 # maximum
8667 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8668 # - The position of the entry in the grid
8669 #
8670 # Optional arguments
8671 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
8672 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
8673 #
8674 # Return values
8675 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8676 # Otherwise the Gtk3::Entry created
8677  
8678 my (
8679 $self, $grid, $iv, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
8680 $bottomAttach, $widthChars, $maxChars, $check
8681 ) = @_;
8682  
8683 # Local variables
8684 my $msg;
8685  
8686 # Check for improper arguments
8687 if (
8688 ! defined $grid || ! defined $mode || ! defined $leftAttach || ! defined $rightAttach
8689 || ! defined $topAttach || ! defined $bottomAttach || defined $check
8690 ) {
8691 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithIcon', @_);
8692 }
8693  
8694 # Check that the position in the grid makes sense
8695 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8696  
8697 return undef;
8698 }
8699  
8700 # Check that the minimum/maximum values specified are valid and, if not, fix them
8701 if (defined $min && defined $max && $min > $max) {
8702  
8703 # Use no maximum value...
8704 $max = undef;
8705 # ...and show a warning, because this shouldn't happen
8706 if ($iv) {
8707 $msg = 'Minimum greater than maximum for IV \'' . $iv . '\'';
8708 } else {
8709 $msg = 'Minimum greater than maximum (min: ' . $min . ' max: ' . $max . ')';
8710 }
8711  
8712 $self->session->writeWarning(
8713 $msg,
8714 $self->_objClass . '->addEntryWithIcon',
8715 );
8716 }
8717  
8718 if ($mode eq 'odd' && defined $min && $min < 1) {
8719  
8720 # Lowest value of $min (if specified) is 1
8721 $min = 1;
8722  
8723 } elsif ($mode eq 'even' && defined $min && $min < 0) {
8724  
8725 # Lowest value of $min (if specified) is 0
8726 $min = 0;
8727 }
8728  
8729 # Create the entry
8730 my $entry = Gtk3::Entry->new();
8731  
8732 # Display the existing value of the IV
8733 if (defined $iv && defined $self->editObj->$iv) {
8734  
8735 $entry->set_text($self->editObj->$iv);
8736  
8737 if (! $self->checkEntry($self->editObj->$iv, $mode, $min, $max)) {
8738 $entry->set_icon_from_stock('secondary', 'gtk-no');
8739 } else {
8740 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8741 }
8742  
8743 } else {
8744  
8745 # We still need to set the icon for an empty box
8746 if ($mode eq 'string' || $mode eq 'regex') {
8747  
8748 # Empty strings/regexes might be acceptable
8749 if (! $self->checkEntry('', $mode, $min, $max)) {
8750 $entry->set_icon_from_stock('secondary', 'gtk-no');
8751 } else {
8752 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8753 }
8754  
8755 } else {
8756  
8757 # Box is empty, so any $self->checkEntry test will fail
8758 # When $mode is set to a function reference, we'll have to assume that an empty
8759 # entry box is not an acceptable value. If it is acceptable, you can call
8760 # $self->setEntryIcon immediately after calling this function
8761 $entry->set_icon_from_stock('secondary', 'gtk-no');
8762 }
8763 }
8764  
8765 # Customise the entry
8766 $entry->signal_connect('changed' => sub {
8767  
8768 my $value = $entry->get_text();
8769 # Check whether $value is a valid value, or not
8770 if (! $self->checkEntry($value, $mode, $min, $max)) {
8771  
8772 # Can't use this value
8773 if (defined $iv) {
8774  
8775 $self->ivDelete('editHash', $iv);
8776 }
8777  
8778 $entry->set_icon_from_stock('secondary', 'gtk-no');
8779  
8780 } else {
8781  
8782 # This is a valid value, so use it
8783 if (defined $iv) {
8784  
8785 $self->ivAdd('editHash', $iv, $value);
8786 }
8787  
8788 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8789 }
8790 });
8791  
8792 # Set the width, if specified
8793 if (defined $widthChars) {
8794  
8795 $entry->set_width_chars($widthChars);
8796 }
8797  
8798 # Set the maximum number of characters, if specified
8799 if (defined $maxChars) {
8800  
8801 $entry->set_max_length($maxChars);
8802 }
8803  
8804 # Add the entry to the grid
8805 $entry->set_hexpand(TRUE);
8806 $entry->set_vexpand(FALSE);
8807 $grid->attach(
8808 $entry,
8809 $leftAttach,
8810 $topAttach,
8811 ($rightAttach - $leftAttach),
8812 ($bottomAttach - $topAttach),
8813 );
8814  
8815 return $entry;
8816 }
8817  
8818 sub addEntryWithIconButton {
8819  
8820 # A combination of ->addEntryWithButton and ->addEntryWithIcon, using the same arguments
8821 # as ->addEntryWithIcon
8822 # An IV value of 'undef' counts as acceptable, in addition to the usual conditions
8823 #
8824 # Expected arguments
8825 # $grid - The tab's Gtk3::Grid object
8826 # $iv - A string naming the IV set when the user modifies the text in the entry
8827 # box. Unlike most of these functions, the $iv must be specified
8828 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
8829 # function
8830 # - If 'int', an integer is expected with the specified min/max values
8831 # - If 'odd', an odd-numbered integer with the specified min/max value is
8832 # expected. If the minimum value is less than 1, 1 is used instead
8833 # - If 'even', an even-numbered integer with the specified min/max value is
8834 # expected. If the minimum value is less than 0, 0 is used instead
8835 # - If 'float', a floating point number is expected with the specified min/max
8836 # values
8837 # - If 'string', a string is expected (which might be a number) with the
8838 # specified min/max length
8839 # - If 'regex', a valid regex is expected with the specified min/max length
8840 # - If a function reference, a function is called which should return 'undef'
8841 # or 1, depending on the value of the entry; the icon is set accordingly
8842 # $min, $max - The values described above (ignored when $mode is a function reference).
8843 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
8844 # maximum
8845 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8846 # - The position of the entry in the grid
8847 #
8848 # Optional arguments
8849 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
8850 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
8851 #
8852 # Return values
8853 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
8854 # Otherwise the Gtk3::Entry created
8855  
8856 my (
8857 $self, $grid, $iv, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
8858 $bottomAttach, $widthChars, $maxChars, $check
8859 ) = @_;
8860  
8861 # Local variables
8862 my $msg;
8863  
8864 # Check for improper arguments
8865 if (
8866 ! defined $grid || ! defined $iv || ! defined $mode || ! defined $leftAttach
8867 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
8868 || defined $check
8869 ) {
8870 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntryWithIconButton', @_);
8871 }
8872  
8873 # Check that the position in the grid makes sense
8874 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
8875  
8876 return undef;
8877 }
8878  
8879 # Call $self->addEntryWithIcon to create the entry as normal, reserving one square in the
8880 # grid for the button (we don't pass $iv to $self->addEntryWithIcon because we're going
8881 # to create our own ->signal_connect)
8882 my $entry = $self->addEntryWithIcon(
8883 $grid, undef, $mode, $min, $max, $leftAttach, ($rightAttach - 1), $topAttach,
8884 $bottomAttach, $widthChars, $maxChars,
8885 );
8886  
8887 # Set the contents of the entry
8888 if (defined $self->editObj->$iv) {
8889  
8890 $entry->set_text($self->editObj->$iv);
8891  
8892 } else {
8893  
8894 # An empty box represents 'undef', which is an acceptable value
8895 # We must set the icon manually, as calling $entry->set_text('') doesn't emit the
8896 # 'changed' signals which checks the validity of the value
8897 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8898 }
8899  
8900 # Create a button
8901 my $button = Gtk3::Button->new();
8902  
8903 # Set the icon to display on the button, depending on whether the IV is set to 'undef',
8904 # or not
8905 my $image;
8906 if (defined $iv && defined $self->editObj->$iv) {
8907  
8908 # Use the Gtk3 'clear' icon - clicking on the button sets the IV to undef
8909 $image = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
8910 # Give the button a tooltip
8911 $button->set_tooltip_text('Click to set this IV to \'undef\'');
8912  
8913 } else {
8914  
8915 # Use the Gtk3 'remove' icon - IV is already 'undef'; clicking on the button does
8916 # nothing
8917 $image = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
8918 # Give the button a tooltip
8919 $button->set_tooltip_text('This IV is already set to \'undef\'');
8920 }
8921  
8922 $button->set_image($image);
8923  
8924 # Make the button clickable
8925 $button->signal_connect('clicked' => sub {
8926  
8927 # Set the IV to undef
8928 $self->ivAdd('editHash', $iv, undef);
8929  
8930 # Empty the entry to remove any text entered into it, and update its icon
8931 $entry->set_text('');
8932 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8933  
8934 # Change the button's image to mark this IV as being set to undef
8935 my $image2 = Gtk3::Image->new_from_stock('gtk-remove', 'menu');
8936 $button->set_image($image2);
8937 # Give the button a new tooltip
8938 $button->set_tooltip_text('This IV is already set to \'undef\'');
8939 });
8940  
8941 # Respond when the user types something in the box
8942 $entry->signal_connect('changed' => sub {
8943  
8944 my $text = $entry->get_text();
8945 $self->ivAdd('editHash', $iv, $text);
8946  
8947 if ($self->checkEntry($text, $mode, $min, $max)) {
8948 $entry->set_icon_from_stock('secondary', 'gtk-yes');
8949 } else {
8950 $entry->set_icon_from_stock('secondary', 'gtk-no');
8951 }
8952  
8953 # Contents of the entry can't possibly be 'undef' any more
8954 my $image3 = Gtk3::Image->new_from_stock('gtk-clear', 'menu');
8955 $button->set_image($image3);
8956 # Give the button a new tooltip
8957 $button->set_tooltip_text('Click to set this IV to \'undef\'');
8958 });
8959  
8960 # Add the button to the grid (the entry has already been added)
8961 $button->set_hexpand(FALSE);
8962 $button->set_vexpand(FALSE);
8963 $leftAttach = $rightAttach - 1;
8964 $grid->attach(
8965 $button,
8966 $leftAttach,
8967 $topAttach,
8968 ($rightAttach - $leftAttach),
8969 ($bottomAttach - $topAttach),
8970 );
8971  
8972 return $entry;
8973 }
8974  
8975 sub addComboBox {
8976  
8977 # Adds a Gtk3::ComboBox at the specified position in the window's Gtk3::Grid
8978 #
8979 # Example calls:
8980 # my $comboBox = $self->addComboBox($grid, 'some_IV', \@comboList, 'some_title', TRUE,
8981 # 0, 6, 0, 1);
8982 # my $comboBox = $self->addComboBox($grid, 'some_IV', \@comboList, '', FALSE,
8983 # 0, 6, 0, 1);
8984 #
8985 # Expected arguments
8986 # $grid - The tab's Gtk3::Grid object
8987 # $iv - A string naming the IV set when the user chooses an item in the combo
8988 # box. If 'undef', nothing happens when the user chooses an item in
8989 # the box; it's up to the calling function to check the box's state
8990 # $listRef - Reference to a list with initial values (can be an empty list)
8991 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if an
8992 # empty string, the item at the top of the combobox list is the
8993 # current value of the IV
8994 # $noUndefFlag - If set to TRUE, the combo is populated only with the items in
8995 # $listRef. If set to FALSE (or 'undef'), the first item in the combo
8996 # is an empty value used to set the IV to 'undef'
8997 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
8998 # - The position of the combo box in the grid
8999 #
9000 # Optional arguments
9001 #
9002 # Return values
9003 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9004 # Otherwise the Gtk3::ComboBox created
9005  
9006 my (
9007 $self, $grid, $iv, $listRef, $title, $noUndefFlag, $leftAttach, $rightAttach,
9008 $topAttach, $bottomAttach, $check
9009 ) = @_;
9010  
9011 # Check for improper arguments
9012 if (
9013 ! defined $grid || ! defined $listRef || ! defined $title || ! defined $leftAttach
9014 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9015 || defined $check
9016 ) {
9017 return $axmud::CLIENT->writeImproper($self->_objClass . '->addComboBox', @_);
9018 }
9019  
9020 # Check that the position in the grid makes sense
9021 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9022  
9023 return undef;
9024 }
9025  
9026 # Create the combobox
9027 my $comboBox = Gtk3::ComboBoxText->new();
9028  
9029 # Populate the combobox
9030 if ($title) {
9031  
9032 # The first item in the combobox list is a title
9033 $comboBox->append_text($title);
9034 $comboBox->set_active(0);
9035  
9036 } elsif ($iv) {
9037  
9038 if ($noUndefFlag) {
9039  
9040 if (defined $self->editObj->$iv) {
9041  
9042 # The first item is the current value of the IV, if there is one
9043 $comboBox->append_text($self->editObj->$iv);
9044 # Make this the active item
9045 $comboBox->set_active(0);
9046 }
9047  
9048 } else {
9049  
9050 # The first item is an empty line, for setting the IV to 'undef'
9051 $comboBox->append_text('');
9052  
9053 if (defined $self->editObj->$iv) {
9054  
9055 # The second item is the current value of the IV, if there is one
9056 $comboBox->append_text($self->editObj->$iv);
9057 # Make this the active item
9058 $comboBox->set_active(1);
9059  
9060 } else {
9061  
9062 # Make the 'undef' option the active item
9063 $comboBox->set_active(0);
9064 }
9065 }
9066  
9067 } elsif (! $noUndefFlag) {
9068  
9069 # The first item is an empty line, for setting the IV to 'undef'
9070 $comboBox->append_text('');
9071 # Make the 'undef' option the active item
9072 $comboBox->set_active(0);
9073 }
9074  
9075 foreach my $item (@$listRef) {
9076  
9077 # Don't show the current value of the IV twice
9078 if (
9079 ! $iv
9080 || ! defined $self->editObj->$iv
9081 || $item ne $self->editObj->$iv
9082 ) {
9083 $comboBox->append_text($item);
9084 }
9085 }
9086  
9087 if (! $iv && $noUndefFlag) {
9088  
9089 # The active item hasn't been set yet
9090 $comboBox->set_active(0);
9091 }
9092  
9093 if ($iv) {
9094  
9095 $comboBox->signal_connect('changed' => sub {
9096  
9097 my $text = $comboBox->get_active_text();
9098  
9099 # If the user has selected the title, ignore it
9100 if (! $title || $text ne $title) {
9101  
9102 # If the user has selected the empty line at the top, set the IV to 'undef'
9103 if (! $text) {
9104  
9105 $self->ivAdd('editHash', $iv, undef);
9106  
9107 # Otherwise set the IV to the specified value
9108 } else {
9109  
9110 $self->ivAdd('editHash', $iv, $text);
9111 }
9112 }
9113 });
9114 }
9115  
9116 # Add the combobox to the grid
9117 $comboBox->set_hexpand(TRUE);
9118 $comboBox->set_vexpand(FALSE);
9119 $grid->attach(
9120 $comboBox,
9121 $leftAttach,
9122 $topAttach,
9123 ($rightAttach - $leftAttach),
9124 ($bottomAttach - $topAttach),
9125 );
9126  
9127 return $comboBox;
9128 }
9129  
9130 sub addTextView {
9131  
9132 # Adds a Gtk3::TextView at the specified position in the window's Gtk3::Grid
9133 #
9134 # Example calls:
9135 # my $textView = $self->addTextView($grid, 'some_IV', TRUE,
9136 # 0, 6, 0, 1);
9137 # my $textView = $self->addTextView($grid, 'some_IV', FALSE,
9138 # 0, 6, 0, 1,
9139 # TRUE, FALSE, TRUE,
9140 # -1, 120);
9141 #
9142 # Expected arguments
9143 # $grid - The tab's Gtk3::Grid object
9144 # $iv - A string naming the IV set when the user modifies the contents of the
9145 # textview. If 'undef', nothing happens when the user modifies the
9146 # contents; it's up to the calling function to check the textview's state
9147 # $editableFlag
9148 # - Flag set to TRUE if the textView should be editable, FALSE if it shouldn't
9149 # be editable
9150 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9151 # - The position of the textview in the grid
9152 #
9153 # Optional arguments
9154 # $listFlag - Flag set to TRUE if the contents of the textview should be treated as a
9155 # list, FALSE (or 'undef') if it should be treated as a single string
9156 # containing newline characters. Default value is TRUE (treat as a list)
9157 # $removeEmptyFlag
9158 # - Flag set to TRUE if empty lines should be removed when the IV is set,
9159 # FALSE (or 'undef') if they should be retained. Default value is TRUE
9160 # (remove lines)
9161 # $removeSpaceFlag
9162 # - Flag set to TRUE if lines should have leading/trailing whitespace removed
9163 # when the IV is set, FALSE (or 'undef') if not. Default value is TRUE
9164 # (remove leading/trailing whitespace)
9165 # $noScrollFlag
9166 # - Flag set to TRUE if word-wrap mode should be turned on, preventing a
9167 # horizontal scrollbar, FALSE (or 'undef') if the textview should scroll
9168 # in both dimensions. Default value is FALSE (scroll in both dimensions)
9169 # $width, $height
9170 # - The width and height (in pixels) of the frame containing the list. If
9171 # specified, values of -1 mean 'don't set this value'. The default values
9172 # are (-1, -1)
9173 #
9174 # Return values
9175 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9176 # Otherwise the Gtk3::TextView created (inside a Gtk::ScrolledWindow)
9177  
9178 my (
9179 $self, $grid, $iv, $editableFlag, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
9180 $listFlag, $removeEmptyFlag, $removeSpaceFlag, $noScrollFlag, $width, $height, $check
9181 ) = @_;
9182  
9183 # Check for improper arguments
9184 if (
9185 ! defined $grid || ! defined $editableFlag || ! defined $leftAttach
9186 || ! defined $rightAttach || ! defined $topAttach || defined $check
9187 ) {
9188 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTextView', @_);
9189 }
9190  
9191 # Check that the position in the grid makes sense
9192 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9193  
9194 return undef;
9195 }
9196  
9197 # Set defaults
9198 if (! defined $listFlag) {
9199  
9200 $listFlag = TRUE;
9201 }
9202  
9203 if (! defined $removeEmptyFlag) {
9204  
9205 $removeEmptyFlag = TRUE;
9206 }
9207  
9208 if (! defined $removeSpaceFlag) {
9209  
9210 $removeSpaceFlag = TRUE;
9211 }
9212  
9213 if (! defined $width) {
9214  
9215 $width = -1; # Let Gtk3 set the width
9216 }
9217  
9218 if (! defined $height) {
9219  
9220 $height = -1; # Let Gtk3 set the height
9221 }
9222  
9223 # Creating a containing Gtk3::Frame and Gtk3::ScrolledWindow
9224 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
9225 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
9226 $scroll->set_policy('automatic', 'automatic');
9227 $scroll->set_size_request($width, $height);
9228 # $scroll->set_border_width($self->spacingPixels);
9229  
9230 # Create a textview with default colours/fonts
9231 my $textView = Gtk3::TextView->new();
9232 $scroll->add($textView);
9233 my $buffer = Gtk3::TextBuffer->new();
9234 $textView->set_buffer($buffer);
9235 if ($noScrollFlag) {
9236  
9237 $textView->set_wrap_mode('word-char'); # Wrap words if possible, characters if not
9238 $textView->set_justification('left');
9239 }
9240  
9241 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
9242  
9243 if ($iv) {
9244  
9245 # Display the existing value of the IV (the call to $buffer->set_text requires a
9246 # defined value, so don't try to display 'undef')
9247 if ($self->editObj->$iv) {
9248  
9249 if ($listFlag) {
9250  
9251 # The call to ->ivPeek returns the contents of the IV as a flat list
9252 $buffer->set_text(join("\n", $self->editObj->ivPeek($iv)));
9253  
9254 } else {
9255  
9256 $buffer->set_text($self->editObj->$iv);
9257 }
9258 }
9259  
9260 $buffer->signal_connect('changed' => sub {
9261  
9262 my (
9263 $text,
9264 @list, @finalList,
9265 );
9266  
9267 $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
9268  
9269 if ($listFlag) {
9270  
9271 # Split the contents of the textview into a list of lines, separated by
9272 # newline characters
9273 @list = split("\n", $text);
9274 # Remove any empty lines and leading/trailing whitespace, if allowed
9275 foreach my $line (@list) {
9276  
9277 if ($line && $removeSpaceFlag) {
9278  
9279 $line =~ s/^\s+//; # Remove leading whitespace
9280 $line =~ s/\s+$//; # Remove trailing whitespace
9281 }
9282  
9283 if ($line || ! $removeEmptyFlag) {
9284  
9285 push (@finalList, $line);
9286 }
9287 }
9288  
9289 # Set the IV
9290 $self->ivAdd('editHash', $iv, \@finalList);
9291  
9292 } else {
9293  
9294 # Treat the contents of the IV as a single string
9295 $self->ivAdd('editHash', $iv, $text);
9296 }
9297 });
9298 }
9299  
9300 # Make the textview editable or not editable
9301 $textView->set_editable($editableFlag);
9302  
9303 # Add the textview to the grid
9304 $scroll->set_hexpand(TRUE);
9305 $scroll->set_vexpand(TRUE);
9306 $grid->attach(
9307 $scroll,
9308 $leftAttach,
9309 $topAttach,
9310 ($rightAttach - $leftAttach),
9311 ($bottomAttach - $topAttach),
9312 );
9313  
9314 return $textView;
9315 }
9316  
9317 sub addSimpleList {
9318  
9319 # Adds a GA::Obj::SimpleList at the specified position in the window's Gtk3::Grid
9320 #
9321 # Example calls:
9322 # my $slWidget = $self->addSimpleList($grid, 'some_IV', \@columnList,
9323 # 0, 6, 0, 1);
9324 #
9325 # Expected arguments
9326 # $grid - The tab's Gtk3::Grid object
9327 # $iv - The IV in $self->editObj containing the data being edited. If 'undef',
9328 # the list is not populated with data; it's up to the calling function
9329 # to do it
9330 # $columnListRef - Reference to a list of column headings and types, in the form
9331 # ('heading', 'column_type', 'heading', 'column_type'...)
9332 # - 'column_type' is one of the column types specified by
9333 # GA::Obj::SimpleList, e.g. 'scalar', 'int'
9334 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9335 # - The position of the simple list in the grid
9336 #
9337 # Optional arguments
9338 # $width, $height - The width and height (in pixels) of the scroller containing the list.
9339 # If specified, values of -1 mean 'don't set this value'. The default
9340 # values are (-1, -1)
9341 #
9342 # Return values
9343 # 'undef' on improper arguments
9344 # Otherwise the GA::Obj::SimpleList created
9345  
9346 my (
9347 $self, $grid, $iv, $columnListRef, $leftAttach, $rightAttach, $topAttach,
9348 $bottomAttach, $width, $height, $check,
9349 ) = @_;
9350  
9351 # Local variables
9352 my (
9353 $refType, $count,
9354 @columnList,
9355 );
9356  
9357 # Check for improper arguments
9358 if (
9359 ! defined $grid || ! defined $columnListRef || ! defined $leftAttach
9360 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9361 || defined $check
9362 ) {
9363 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleList', @_);
9364 }
9365  
9366 # Check that the position in the grid makes sense
9367 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9368  
9369 return undef;
9370 }
9371  
9372 # Set defaults
9373 if (! defined $width) {
9374  
9375 $width = -1; # Let Gtk3 set the width
9376 }
9377  
9378 if (! defined $height) {
9379  
9380 $height = -1; # Let Gtk3 set the height
9381 }
9382  
9383 # Dereference the list of columns
9384 @columnList = @$columnListRef;
9385  
9386 # Add a simple list
9387 my $frame = Gtk3::Frame->new(undef);
9388 $frame->set_border_width(0);
9389  
9390 my $scroller = Gtk3::ScrolledWindow->new();
9391 $frame->add($scroller);
9392 $scroller->set_shadow_type($axmud::CLIENT->constShadowType);
9393 $scroller->set_policy('automatic', 'automatic');
9394 $scroller->set_border_width(0);
9395 $scroller->set_size_request($width, $height);
9396  
9397 my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList);
9398 $scroller->add($slWidget);
9399  
9400 # No interactive searches required
9401 $slWidget->set_enable_search(FALSE);
9402  
9403 # Fill the columns with data
9404 if ($iv) {
9405  
9406 $refType = ref $self->editObj->{$iv};
9407  
9408 if ($refType eq 'HASH') {
9409  
9410 # Sort the hash by key, before adding it to the simple list
9411 $self->resetSortListData($slWidget, [$self->editObj->$iv]);
9412  
9413 } else {
9414  
9415 # Assume that the list/hash IV can be displayed in its current order
9416 $self->resetListData($slWidget, [$self->editObj->$iv], (scalar @columnList / 2));
9417 }
9418 }
9419  
9420 # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, so
9421 # that the user can't click them on and off
9422 $count = -1;
9423 do {
9424  
9425 my $title = shift @columnList;
9426 my $type = shift @columnList;
9427  
9428 $count++;
9429  
9430 if ($type eq 'bool') {
9431  
9432 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
9433 $cellRenderer->set(activatable => FALSE);
9434 }
9435  
9436 } until (! @columnList);
9437  
9438 # Add the simple list to the grid
9439 $frame->set_hexpand(TRUE);
9440 $frame->set_vexpand(TRUE);
9441 $grid->attach(
9442 $frame,
9443 $leftAttach,
9444 $topAttach,
9445 ($rightAttach - $leftAttach),
9446 ($bottomAttach - $topAttach),
9447 );
9448  
9449 return $slWidget;
9450 }
9451  
9452 sub addRegexButton {
9453  
9454 # Adds a Gtk3::Button at the specified position in the tab's Gtk3::Grid. The button, when
9455 # clicked, checks regexes in a list of IVs, and opens a dialogue window to display the
9456 # result
9457 #
9458 # Example calls:
9459 # my $button = $self->addRegexButton($grid, $listRef,
9460 # 0, 6, 0, 1);
9461 #
9462 # Expected arguments
9463 # $grid - The tab's Gtk3::Grid object
9464 # $listRef - Reference to a list in groups of 2, in the form (type, iv, type, iv...)
9465 # where 'type' is 'scalar' to test a pattern stored in a scalar IV, 'list'
9466 # to test the patterns stored in a list IV, 'keys' or 'values' to test
9467 # the patterns stored as keys/values in a hash IV, or 'both' to test the
9468 # patterns stored as keys and values in a hash IV. If the referenced list
9469 # is empty, no patterns are tested (and the button is desensitised). If
9470 # any 'type' is not recognised, patterns in the IV are not tested (but
9471 # other IVs are still tested)
9472 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9473 # - The position of the button in the grid
9474 #
9475 # Return values
9476 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9477 # Otherwise the Gtk3::Button created
9478  
9479 my (
9480 $self, $grid, $listRef, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $check,
9481 ) = @_;
9482  
9483 # Check for improper arguments
9484 if (
9485 ! defined $grid || ! defined $listRef || ! defined $leftAttach
9486 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9487 || defined $check
9488 ) {
9489 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRegexButton', @_);
9490 }
9491  
9492 # Check that the position in the grid makes sense
9493 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9494  
9495 return undef;
9496 }
9497  
9498 # Create the button
9499 my $button = Gtk3::Button->new('Check patterns');
9500 $button->set_tooltip_text(
9501 'Check that the patterns on this page are valid regular expressions',
9502 );
9503  
9504 if (! @$listRef) {
9505  
9506 # No IVs specified so no patterns to check
9507 $button->set_sensitive(FALSE);
9508  
9509 } else {
9510  
9511 # Respond to a mouse click on the button
9512 $button->signal_connect('clicked' => sub {
9513  
9514 my (
9515 $msg, $count,
9516 @list, @patternList, @errorList,
9517 );
9518  
9519 @list = @$listRef;
9520  
9521 do {
9522  
9523 my (
9524 $type, $iv, $value,
9525 @valueList,
9526 %valueHash,
9527 );
9528  
9529 $type = shift @list;
9530 $iv = shift @list;
9531  
9532 # Generate a list of patterns stored in the IV, but ignore any 'undef' values
9533 # and ignore any unrecognised $types
9534 if ($type eq 'scalar') {
9535  
9536 $value = $self->getEditHash_scalarIV($iv);
9537 if (defined $value) {
9538  
9539 push (@patternList, $value);
9540 }
9541  
9542 } elsif ($type eq 'list') {
9543  
9544 @valueList = $self->getEditHash_listIV($iv);
9545 foreach my $item (@valueList) {
9546  
9547 if (defined $item) {
9548  
9549 push (@patternList, $item);
9550 }
9551 }
9552  
9553 } elsif ($type eq 'keys' || $type eq 'values' || $type eq 'both') {
9554  
9555 %valueHash = $self->getEditHash_hashIV($iv);
9556  
9557 if ($type eq 'keys') {
9558  
9559 push (@patternList, keys %valueHash);
9560  
9561 } elsif ($type eq 'values') {
9562  
9563 foreach my $item (values %valueHash) {
9564  
9565 if (defined $item) {
9566  
9567 push (@patternList, $item);
9568 }
9569 }
9570  
9571 } else {
9572  
9573 foreach my $key (keys %valueHash) {
9574  
9575 my $item = $valueHash{$key};
9576  
9577 if (defined $item) {
9578 push (@patternList, $key, $item);
9579 } else {
9580 push (@patternList, $key);
9581 }
9582 }
9583 }
9584 }
9585  
9586 } until (! @list);
9587  
9588 if (! @patternList) {
9589  
9590 $self->showMsgDialogue(
9591 'Check patterns',
9592 'info',
9593 'There are no patterns on this page',
9594 'ok',
9595 );
9596  
9597 } else {
9598  
9599 # Check every pattern in turn. GA::Client->regexCheck returns 'undef' if the
9600 # regex is valid, or an error message if it's not valid
9601 foreach my $pattern (@patternList) {
9602  
9603 my $error = $axmud::CLIENT->regexCheck($pattern);
9604 if (defined $error) {
9605  
9606 push (@errorList, $pattern, $error);
9607 }
9608 }
9609  
9610 if (! @errorList) {
9611  
9612 $self->showMsgDialogue(
9613 'Check patterns',
9614 'info',
9615 'All patterns on this page are valid',
9616 'ok',
9617 );
9618  
9619 } else {
9620  
9621 $msg = 'Patterns checked: ' . (scalar @patternList) . ', errors: '
9622 . ((scalar @errorList) / 2);
9623  
9624 $count = 0;
9625 do {
9626  
9627 my ($pattern, $error);
9628  
9629 $pattern = shift @errorList;
9630 $error = shift @errorList;
9631 $count++;
9632  
9633 chomp $pattern;
9634 chomp $error;
9635  
9636 $msg .= "\n\n$pattern\n$error";
9637  
9638 # (Only show the first 2 errors - don't want a dialogue window as big as
9639 # the desktop)
9640 if ($count >= 2 && @errorList) {
9641  
9642 $msg .= "\n\n...";
9643 @errorList = ();
9644 }
9645  
9646 } until (! @errorList);
9647  
9648 $self->showMsgDialogue(
9649 'Check patterns',
9650 'error',
9651 $msg,
9652 'ok',
9653 undef,
9654 TRUE, # Preserve newline characters in $msg
9655 );
9656 }
9657 }
9658 });
9659 }
9660  
9661 # Add the button to the grid
9662 $button->set_hexpand(TRUE);
9663 $button->set_vexpand(FALSE);
9664 $grid->attach(
9665 $button,
9666 $leftAttach,
9667 $topAttach,
9668 ($rightAttach - $leftAttach),
9669 ($bottomAttach - $topAttach),
9670 );
9671  
9672 return $button;
9673 }
9674  
9675 # Add widgets - special functions for GA::EditWin::Generic::Interface and
9676 # GA::EditWin::Interface::Active
9677  
9678 sub useCheckButton {
9679  
9680 # Adapted from $self->addCheckButton
9681 # Adds a Gtk3::CheckButton with an accompnaying label at the specified position in the
9682 # window's Gtk3::Grid. Instead of setting an IV in $self->editHash, sets a key-value pair
9683 # in $self->attribHash
9684 #
9685 # Example calls:
9686 # my $checkButton = $self->useCheckButton($grid, 'Click me', 'some_attribute', TRUE,
9687 # 0, 6, 0, 1);
9688 # my $checkButton = $self->useCheckButton($grid, undef, 'some_attribute', TRUE,
9689 # 0, 6, 0, 1);
9690 #
9691 # Expected arguments
9692 # $grid - The tab's Gtk3::Grid object
9693 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
9694 # no name is displayed
9695 # $attrib - The name of the attribute set when the check button is toggled (matches
9696 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
9697 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
9698 # TRUE if it should be 'normal'
9699 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9700 # - The position of the checkbutton in the grid
9701 #
9702 # Optional arguments
9703 # $alignX, $alignY
9704 # - Used in the call to ->set_alignment; two values in the range 0-1
9705 # - If not specified, $alignX is set to 0, $alignY to 0.5
9706 #
9707 # Return values
9708 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9709 # Otherwise the Gtk3::CheckButton created
9710  
9711 my (
9712 $self, $grid, $name, $attrib, $stateFlag, $leftAttach, $rightAttach, $topAttach,
9713 $bottomAttach, $check
9714 ) = @_;
9715  
9716 # Check for improper arguments
9717 if (
9718 ! defined $grid || ! defined $attrib || ! defined $stateFlag || ! defined $leftAttach
9719 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9720 || defined $check
9721 ) {
9722 return $axmud::CLIENT->writeImproper($self->_objClass . '->useCheckButton', @_);
9723 }
9724  
9725 # Check that the position in the grid makes sense
9726 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9727  
9728 return undef;
9729 }
9730  
9731 # Create the checkbutton
9732 my $checkButton;
9733 if (defined $name && $name ne '') {
9734 $checkButton = Gtk3::CheckButton->new_with_label($name);
9735 } else {
9736 $checkButton = Gtk3::CheckButton->new();
9737 }
9738  
9739 $checkButton->set_active($self->editObj->ivShow('attribHash', $attrib));
9740 $checkButton->signal_connect('toggled' => sub {
9741  
9742 $self->ivAdd('attribHash', $attrib, $checkButton->get_active());
9743 });
9744  
9745 # Make the checkbutton insensitive, if $stateFlag is FALSE
9746 if (! $stateFlag) {
9747  
9748 $checkButton->set_state('insensitive');
9749 }
9750  
9751 # Add the checkbutton to the grid
9752 $checkButton->set_hexpand(TRUE);
9753 $checkButton->set_vexpand(FALSE);
9754 $grid->attach(
9755 $checkButton,
9756 $leftAttach,
9757 $topAttach,
9758 ($rightAttach - $leftAttach),
9759 ($bottomAttach - $topAttach),
9760 );
9761  
9762 return $checkButton;
9763 }
9764  
9765 sub useRadioButton {
9766  
9767 # Adapted from $self->addRadioButton
9768 # Adds a Gtk3::RadioButton at the specified position in the tab's Gtk3::Grid. Instead of
9769 # setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
9770 #
9771 # Example calls:
9772 # my ($group, $button) = $self->useRadioButton(
9773 # $grid, undef, $name, 'some_attribute', $value, TRUE,
9774 # 0, 6, 0, 1);
9775 # my ($group2, $button2) = $self->useRadioButton(
9776 # $grid, $group, $name, 'some_attribute', $value, TRUE,
9777 # 0, 6, 0, 1, 0, 0.5);
9778 #
9779 # Expected arguments
9780 # $grid - The tab's Gtk3::Grid object
9781 # $group - Reference to the radio button group created, when the first button in the
9782 # group was added (if set to 'undef', this is the first button, and a
9783 # group will be created for it)
9784 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
9785 # no name is displayed
9786 # $attrib - The name of the attribute set when the radio button is toggled (matches
9787 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
9788 # $value - The value to which the attribute is set, when the radio button is selected
9789 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
9790 # TRUE if it should be 'normal'
9791 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9792 # - The position of the radiobutton in the grid
9793 #
9794 # Optional arguments
9795 # $alignLeft, $alignRight
9796 # - Used in the call to ->set_alignment; two values in the range 0-1
9797 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
9798 #
9799 # Return values
9800 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
9801 # invalid
9802 # Otherwise a list containing two elements: the radio button $group and the
9803 # Gtk3::RadioButton created
9804  
9805 my (
9806 $self, $grid, $group, $name, $attrib, $value, $stateFlag, $leftAttach, $rightAttach,
9807 $topAttach, $bottomAttach, $alignLeft, $alignRight, $check
9808 ) = @_;
9809  
9810 # Local variables
9811 my @emptyList;
9812  
9813 # Check for improper arguments
9814 if (
9815 ! defined $grid || ! defined $attrib || ! defined $stateFlag || ! defined $leftAttach
9816 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9817 || defined $check
9818 ) {
9819 $axmud::CLIENT->writeImproper($self->_objClass . '->useRadioButton', @_);
9820 return @emptyList;
9821 }
9822  
9823 # Check that the position in the grid makes sense
9824 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9825  
9826 return @emptyList;
9827 }
9828  
9829 # Set default alignment, if none specified
9830 if (! defined $alignLeft) {
9831  
9832 $alignLeft = 0;
9833 }
9834  
9835 if (! defined $alignRight) {
9836  
9837 $alignRight = 0.5;
9838 }
9839  
9840 # Create the radio button
9841 my $radioButton = Gtk3::RadioButton->new();
9842 # Add it to the existing group, if one was specified
9843 if (defined $group) {
9844  
9845 $radioButton->set_group($group);
9846 }
9847  
9848 # If $value is the one currently stored in $self->editObj->attribHash, mark this radio
9849 # button as active
9850 if (defined $value && $value eq $self->editObj->ivShow('attribHash', $attrib)) {
9851  
9852 $radioButton->set_active(TRUE);
9853 }
9854  
9855 $radioButton->signal_connect('toggled' => sub {
9856  
9857 # Set the attribute only if this radiobutton has been selected
9858 if ($radioButton->get_active()) {
9859  
9860 $self->ivAdd('attribHash', $attrib, $value);
9861 }
9862 });
9863  
9864 # Give the radio button a name, if one was specified
9865 if ($name) {
9866  
9867 $radioButton->set_label($name);
9868 }
9869  
9870 # Make the radio button insensitive, if $stateFlag is FALSE
9871 if (! $stateFlag) {
9872  
9873 $radioButton->set_state('insensitive');
9874 }
9875  
9876 # Set radio button's alignment
9877 $radioButton->set_alignment($alignLeft, $alignRight);
9878  
9879 # Add the radio button to the grid
9880 $radioButton->set_hexpand(FALSE);
9881 $radioButton->set_vexpand(FALSE);
9882 $grid->attach(
9883 $radioButton,
9884 $leftAttach,
9885 $topAttach,
9886 ($rightAttach - $leftAttach),
9887 ($bottomAttach - $topAttach),
9888 );
9889  
9890 return ($radioButton->get_group(), $radioButton);
9891 }
9892  
9893 sub useEntryWithIcon {
9894  
9895 # Adapted from $self->addEntryWithIcon
9896 # Adds a Gtk3::Entry at the specified position in the tab's Gtk3::Grid. The entry contains
9897 # a stock icon to show whether the current contents of the entry is permissible
9898 # The stock icons used are 'gtk-yes' (for an acceptable value) and 'gtk-no' (for a
9899 # forbidden value)
9900 # Instead of setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
9901 #
9902 # Example calls:
9903 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'int', 0, 1000,
9904 # 0, 6, 0, 1);
9905 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'odd', 1, 1001,
9906 # 0, 6, 0, 1);
9907 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'even', 0, 1000,
9908 # 0, 6, 0, 1);
9909 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'float', 0, 1000000,
9910 # 0, 6, 0, 1);
9911 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'string', 3, 16,
9912 # 0, 6, 0, 1);
9913 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'regex', 1, undef,
9914 # 0, 6, 0, 1);
9915 # my $entry = $self->useEntryWithIcon(
9916 # $grid, 'some_attribute', \&checkFunction, undef, undef,
9917 # 0, 6, 0, 1);
9918 #
9919 # my $entry = $self->useEntryWithIcon($grid, 'some_attribute', 'int', 0, 1000,
9920 # 0, 6, 0, 1, 16, 16);
9921 #
9922 # Expected arguments
9923 # $grid - The tab's Gtk3::Grid object
9924 # $attrib - The name of the attribute set when the user modifies the text in the entry
9925 # box
9926 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
9927 # function
9928 # - If 'int', an integer is expected with the specified min/max values
9929 # - If 'odd', an odd-numbered integer with the specified min/max value is
9930 # expected. If the minimum value is less than 1, 1 is used instead
9931 # - If 'even', an even-numbered integer with the specified min/max value is
9932 # expected. If the minimum value is less than 0, 0 is used instead
9933 # - If 'float', a floating point number is expected with the specified min/max
9934 # values
9935 # - If 'string', a string is expected (which might be a number) with the
9936 # specified min/max length
9937 # - If 'regex', a valid regex is expected with the specified min/max length
9938 # - If a function reference, a function is called which should return 'undef'
9939 # or 1, depending on the value of the entry; the icon is set accordingly
9940 # $min, $max - The values described above (ignored when $mode is a function reference).
9941 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
9942 # maximum
9943 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
9944 # - The position of the entry in the grid
9945 #
9946 # Optional arguments
9947 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
9948 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
9949 #
9950 # Return values
9951 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
9952 # Otherwise the Gtk3::Entry created
9953  
9954 my (
9955 $self, $grid, $attrib, $mode, $min, $max, $leftAttach, $rightAttach, $topAttach,
9956 $bottomAttach, $widthChars, $maxChars, $check
9957 ) = @_;
9958  
9959 # Local variables
9960 my $current;
9961  
9962 # Check for improper arguments
9963 if (
9964 ! defined $grid || ! defined $attrib || ! defined $mode || ! defined $leftAttach
9965 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
9966 || defined $check
9967 ) {
9968 return $axmud::CLIENT->writeImproper($self->_objClass . '->useEntryWithIcon', @_);
9969 }
9970  
9971 # Check that the position in the grid makes sense
9972 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
9973  
9974 return undef;
9975 }
9976  
9977 # Check that the minimum/maximum values specified are valid and, if not, fix them
9978 if (defined $min && defined $max && $min > $max) {
9979  
9980 # Use no maximum value...
9981 $max = undef;
9982 # ...and show a warning, because this shouldn't happen
9983 $self->session->writeWarning(
9984 'Minimum greater than maximum for attribute \'' . $attrib . '\'',
9985 $self->_objClass . '->addEntryWithIcon',
9986 );
9987 }
9988  
9989 if ($mode eq 'odd' && defined $min && $min < 1) {
9990  
9991 # Lowest value of $min (if specified) is 1
9992 $min = 1;
9993  
9994 } elsif ($mode eq 'even' && defined $min && $min < 0) {
9995  
9996 # Lowest value of $min (if specified) is 0
9997 $min = 0;
9998 }
9999  
10000 # Create the entry
10001 my $entry = Gtk3::Entry->new();
10002  
10003 # Display the existing value of the attribute
10004 $current = $self->editObj->ivShow('attribHash', $attrib);
10005 if (defined $current) {
10006  
10007 $entry->set_text($current);
10008  
10009 if (! $self->checkEntry($current, $mode, $min, $max)) {
10010 $entry->set_icon_from_stock('secondary', 'gtk-no');
10011 } else {
10012 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10013 }
10014  
10015 } else {
10016  
10017 # We still need to set the icon for an empty box
10018 if ($mode eq 'string' || $mode eq 'regex') {
10019  
10020 # Empty strings/regexes might be acceptable
10021 if (! $self->checkEntry('', $mode, $min, $max)) {
10022 $entry->set_icon_from_stock('secondary', 'gtk-no');
10023 } else {
10024 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10025 }
10026  
10027 } else {
10028  
10029 # Box is empty, so any $self->checkEntry test will fail (for $mode
10030 # set to a function reference, we'll have to assume that)
10031 $entry->set_icon_from_stock('secondary', 'gtk-no');
10032 }
10033 }
10034  
10035 # Customise the entry
10036 $entry->signal_connect('changed' => sub {
10037  
10038 my $value = $entry->get_text();
10039 # Check whether $value is a valid value, or not
10040 if (! $self->checkEntry($value, $mode, $min, $max)) {
10041  
10042 # Can't use this value
10043 $self->ivDelete('attribHash', $attrib);
10044 $entry->set_icon_from_stock('secondary', 'gtk-no');
10045  
10046 } else {
10047  
10048 # This is a valid value, so use it
10049 $self->ivAdd('attribHash', $attrib, $value);
10050 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10051 }
10052 });
10053  
10054 # Set the width, if specified
10055 if (defined $widthChars) {
10056  
10057 $entry->set_width_chars($widthChars);
10058 }
10059  
10060 # Set the maximum number of characters, if specified
10061 if (defined $maxChars) {
10062  
10063 $entry->set_max_length($maxChars);
10064 }
10065  
10066 # Add the entry to the grid
10067 $entry->set_hexpand(TRUE);
10068 $entry->set_vexpand(FALSE);
10069 $grid->attach(
10070 $entry,
10071 $leftAttach,
10072 $topAttach,
10073 ($rightAttach - $leftAttach),
10074 ($bottomAttach - $topAttach),
10075 );
10076  
10077 return $entry;
10078 }
10079  
10080 sub useComboBox {
10081  
10082 # Adapted from $self->addComboBox
10083 # Adds a Gtk3::ComboBox at the specified position in the window's Gtk3::Grid. Instead of
10084 # setting an IV in $self->editHash, sets a key-value pair in $self->attribHash
10085 #
10086 # Example calls:
10087 # my $comboBox = $self->useComboBox($grid, 'some_attribute', \@comboList, 'some_title',
10088 # 0, 6, 0, 1);
10089 # my $comboBox = $self->useComboBox($grid, 'some_attribute', \@comboList, '',
10090 # 0, 6, 0, 1);
10091 #
10092 # Expected arguments
10093 # $grid - The tab's Gtk3::Grid object
10094 # $attrib - The name of the attribute set when the check button is toggled (matches
10095 # a key in $self->attribHash and GA::Interface::Trigger->attribHash)
10096 # $listRef - Reference to a list with initial values (can be an empty list)
10097 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if an
10098 # empty string, the item at the top of the combobox list is the current
10099 # value of the attribute
10100 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
10101 # - The position of the combo box in the grid
10102 #
10103 # Return values
10104 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
10105 # Otherwise the Gtk3::ComboBox created
10106  
10107 my (
10108 $self, $grid, $attrib, $listRef, $title, $leftAttach, $rightAttach, $topAttach,
10109 $bottomAttach, $check
10110 ) = @_;
10111  
10112 # Local variables
10113 my $current;
10114  
10115 # Check for improper arguments
10116 if (
10117 ! defined $grid || ! defined $attrib || ! defined $listRef || ! defined $title
10118 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
10119 || ! defined $bottomAttach || defined $check
10120 ) {
10121 return $axmud::CLIENT->writeImproper($self->_objClass . '->useComboBox', @_);
10122 }
10123  
10124 # Check that the position in the grid makes sense
10125 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
10126  
10127 return undef;
10128 }
10129  
10130 # Create the combobox
10131 my $comboBox = Gtk3::ComboBoxText->new();
10132  
10133 # Populate the combobox
10134 if ($title) {
10135  
10136 # The first item in the combobox list is a title
10137 $comboBox->append_text($title);
10138 $comboBox->set_active(0);
10139  
10140 } else {
10141  
10142 $current = $self->editObj->ivShow('attribHash', $attrib);
10143 if ($current) {
10144  
10145 # The first item is the current value of the IV, if there is one
10146 $comboBox->append_text($current);
10147 # Make this the active item
10148 $comboBox->set_active(0);
10149 }
10150 }
10151  
10152 foreach my $item (@$listRef) {
10153  
10154 # Don't show the current value of the IV twice
10155 if (! $current || $item ne $current) {
10156  
10157 $comboBox->append_text($item);
10158 }
10159 }
10160  
10161 $comboBox->signal_connect('changed' => sub {
10162  
10163 my $text = $comboBox->get_active_text();
10164  
10165 # If the user has selected the title, ignore it
10166 if (! $title || $text ne $title) {
10167  
10168 # If the user has selected the empty line at the top, set the attribute to an
10169 # empty string
10170 if (! $text) {
10171  
10172 $self->ivAdd('attribHash', $attrib, '');
10173  
10174 # Otherwise set the attribute to the specified value
10175 } else {
10176  
10177 $self->ivAdd('attribHash', $attrib, $text);
10178 }
10179 }
10180 });
10181  
10182 # Add the combobox to the grid
10183 $comboBox->set_hexpand(TRUE);
10184 $comboBox->set_vexpand(FALSE);
10185 $grid->attach(
10186 $comboBox,
10187 $leftAttach,
10188 $topAttach,
10189 ($rightAttach - $leftAttach),
10190 ($bottomAttach - $topAttach),
10191 );
10192  
10193 return $comboBox;
10194 }
10195  
10196 # Add widget support functions
10197  
10198 sub checkEntry {
10199  
10200 # Called by $self->addEntryWithIcon
10201 # Check whether the text entered in an entry box is a valid value for the IV, or not
10202 #
10203 # Expected arguments
10204 # $value - The value currently in the entry box
10205 # $mode - Set to 'int', 'odd', 'even', 'float', 'string' or a reference to a
10206 # function
10207 # - If 'int', an integer is expected with the specified min/max values
10208 # - If 'odd', an odd-numbered integer with the specified min/max value is
10209 # expected. If the minimum value is less than 1, 1 is used instead
10210 # - If 'even', an even-numbered integer with the specified min/max value is
10211 # expected. If the minimum value is less than 0, 0 is used instead
10212 # - If 'float', a floating point number is expected with the specified min/max
10213 # values
10214 # - If 'string', a string is expected (which might be a number) with the
10215 # specified min/max length
10216 # - If 'regex', a valid regex is expected with the specified min/max length
10217 # - If a function reference, a function is called which should return 'undef'
10218 # or 1, depending on the value of the entry; the icon is set accordingly
10219 # $min, $max - The values described above (ignored when $mode is a function reference).
10220 # If $min is 'undef', there is no minimum; if $max is 'undef', there is no
10221 # maximum
10222 #
10223 # Return values
10224 # 'undef' on improper arguments or if $value is an invalid value for the IV
10225 # 1 if $value is a valid value for the IV
10226  
10227 my ($self, $value, $mode, $min, $max, $check) = @_;
10228  
10229 # Local variables
10230 my $result;
10231  
10232 # Check for improper arguments
10233 if (! defined $value || ! defined $mode || defined $check) {
10234  
10235 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEntry', @_);
10236 }
10237  
10238 # 'int' mode
10239 if ($mode eq 'int') {
10240  
10241 if (
10242 ! defined $value
10243 || $value eq '' # Required for $entry->set_text('');
10244 || ! ($value =~ m/^\-?\d+$/)
10245 || (defined $min && $value < $min)
10246 || (defined $max && $value > $max)
10247 ) {
10248 # Invalid value
10249 return undef;
10250  
10251 } else {
10252  
10253 # Valid value
10254 return 1;
10255 }
10256  
10257 # 'odd' mode
10258 } elsif ($mode eq 'odd') {
10259  
10260 if (
10261 ! defined $value
10262 || $value eq '' # Required for $entry->set_text('');
10263 || ! ($value =~ m/^\-?\d+$/)
10264 || (defined $min && $value < $min)
10265 || (defined $max && $value > $max)
10266 || ! ($value % 2) # Number is even
10267 ) {
10268 # Invalid value
10269 return undef;
10270  
10271 } else {
10272  
10273 # Valid value
10274 return 1;
10275 }
10276  
10277 # 'even' mode
10278 } elsif ($mode eq 'even') {
10279  
10280 if (
10281 ! defined $value
10282 || $value eq '' # Required for $entry->set_text('');
10283 || ! ($value =~ m/^\-?\d+$/)
10284 || (defined $min && $value < $min)
10285 || (defined $max && $value > $max)
10286 || ! ($value % 2) # Number is even
10287 ) {
10288 # Invalid value
10289 return undef;
10290  
10291 } else {
10292  
10293 # Valid value
10294 return 1;
10295 }
10296  
10297 # 'float' mode
10298 } elsif ($mode eq 'float') {
10299  
10300 if (
10301 ! defined $value
10302 || $value eq '' # Required for $entry->set_text('');
10303 || ! ($value =~ /^[+-]?\d+\.?\d*$/)
10304 || (defined $min && $value < $min)
10305 || (defined $max && $value > $max)
10306 ) {
10307 # Invalid value
10308 return undef;
10309  
10310 } else {
10311  
10312 # Valid value
10313 return 1;
10314 }
10315  
10316 # 'string' mode
10317 } elsif ($mode eq 'string') {
10318  
10319 if (
10320 ! defined $value
10321 || (defined $min && length($value) < $min)
10322 || (defined $max && length($value) > $max)
10323 ) {
10324 # Invalid value
10325 return undef;
10326  
10327 } else {
10328  
10329 # Valid value
10330 return 1;
10331 }
10332  
10333  
10334 # 'regex' mode
10335 } elsif ($mode eq 'regex') {
10336  
10337 if (
10338 ! defined $value
10339 || (defined $min && length($value) < $min)
10340 || (defined $max && length($value) > $max)
10341 # ->regexCheck returns 'undef' for a valid regex, a string for an invalid one
10342 || $axmud::CLIENT->regexCheck($value)
10343 ) {
10344 # Invalid value
10345 return undef;
10346  
10347 } else {
10348  
10349 # Valid value
10350 return 1;
10351 }
10352  
10353 # $mode must be a function reference. Call the function so it can check $value and
10354 # return 'undef' or 1
10355 } else {
10356  
10357 return &$mode($self, $value);
10358 }
10359 }
10360  
10361 sub checkEntryIcon {
10362  
10363 # Called by the same function that called $self->addEntryWithIcon
10364 # When it's time to do something with the data entered, instead of having to call
10365 # $self->checkEntry for every entry box, we can just look at the icon
10366 # This function checks a list of Gtk3::Entry boxes and returns 1 if they are all showing the
10367 # 'gtk-ok' icon (meaning the values entered are acceptable)
10368 #
10369 # Expected arguments
10370 # @list - List of Gtk3::Entry boxes
10371 #
10372 # Return values
10373 # 'undef' on improper arguments, or if any of the entry boxes are using the 'gtk-no' icon
10374 # (meaning the value entered isn't acceptable) or if anything in @list is 'undef'
10375 # 1 if all the entry boxes are using the 'gtk-yes' icon (meaning the values entered are
10376 # all acceptable)
10377  
10378 my ($self, @list) = @_;
10379  
10380 # Check for improper arguments
10381 if (! @list) {
10382  
10383 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEntryIcon', @_);
10384 }
10385  
10386 foreach my $entry (@list) {
10387  
10388 # Check that the calling function didn't specify $entry4 when it meant to specify
10389 # $entry3
10390 if (! defined $entry) {
10391  
10392 return $self->writeError(
10393 'Undefined entry box',
10394 $self->_objClass . '->checkEntryIcon',
10395 );
10396  
10397 } elsif ($entry->get_icon_stock('secondary') ne 'gtk-yes') {
10398  
10399 return undef;
10400 }
10401 }
10402  
10403 # All values acceptable for this IV
10404 return 1;
10405 }
10406  
10407 sub setEntryIcon {
10408  
10409 # Called by the same function that called $self->addEntryWithIcon
10410 # If we need to manually change the entry's icon for some reason, this function can be
10411 # called
10412 # For example, if ->addEntryWithIcon is called with a function reference which sets the icon
10413 # every time the entry's text is changed, no IV is specified but we want an empty entry
10414 # box to be an acceptable value, this function can take care of it
10415 #
10416 # Expected arguments
10417 # $entry - The Gtk3::Entry whose icon should be modified
10418 # $flag - TRUE to use 'gtk-yes' (representing an acceptable value), FALSE to use
10419 # 'gtk-no' (representing an unacceptable value)
10420 #
10421 # Return values
10422 # 'undef' on improper arguments
10423 # 1 otherwise
10424  
10425 my ($self, $entry, $flag, $check) = @_;
10426  
10427 # Check for improper arguments
10428 if (! defined $entry || ! defined $flag || defined $check) {
10429  
10430 return $axmud::CLIENT->writeImproper($self->_objClass . '->setEntryIcon', @_);
10431 }
10432  
10433 if (! $flag) {
10434 $entry->set_icon_from_stock('secondary', 'gtk-no');
10435 } else {
10436 $entry->set_icon_from_stock('secondary', 'gtk-yes');
10437 }
10438  
10439 return 1;
10440 }
10441  
10442 sub resetEntryBoxes {
10443  
10444 # Empties the contents of any entry boxes appearing in a list of Gtk3 widgets, ignoring any
10445 # other widgets
10446 #
10447 # Expected arguments
10448 # (none besides $self)
10449 #
10450 # Optional arguments
10451 # @list - List of Gtk3 widgets (can be an empty list)
10452 #
10453 # Return values
10454 # 'undef' on improper arguments or if anything in @list is 'undef'
10455 # 1 otherwise
10456  
10457 my ($self, @list) = @_;
10458  
10459 # (No improper arguments to check)
10460  
10461 foreach my $widget (@list) {
10462  
10463 # Check that the calling function didn't specify $entry4 when it meant to specify
10464 # $entry3
10465 if (! defined $widget) {
10466  
10467 return $self->writeError(
10468 'Undefined widget',
10469 $self->_objClass . '->resetEntryBoxes',
10470 );
10471  
10472 } elsif ($widget->isa('Gtk3::Entry')) {
10473  
10474 $widget->set_text('');
10475 }
10476 }
10477  
10478 return 1;
10479 }
10480  
10481 sub addSimpleListButtons_listIV {
10482  
10483 # Adds four standard buttons used with GA::Obj::SimpleList widgets, when they're
10484 # displaying a list IV. The buttons are 'Add', 'Delete', 'Reset' and 'Clear'
10485 # NB The ->signal_connect method for the 'Add' button must be specified by the calling
10486 # function
10487 #
10488 # Example calls:
10489 # my $addButton = $self->addSimpleListButtons_listIV($grid, $slWidget, 'some_IV', 10);
10490 #
10491 # Expected arguments
10492 # $grid - The tab's Gtk3::Grid object
10493 # $slWidget - The GA::Obj::SimpleList object on which the buttons will act
10494 # $iv - The list IV in $self->editObj storing the data being edited
10495 # $rowNumber - On the current tab's grid, the row on which the buttons are put
10496 # $columns - The number of columns. For a straightforward list, 1, but many IVs
10497 # (particularly in profiles) have list IVs with data in groups of two,
10498 # three or more
10499 #
10500 # Optional arguments
10501 # @widgetList - List of Gtk3 widgets (entry boxes or combos) that are reset when the
10502 # 'Delete', 'Reset' and 'Clear' buttons are used. If the list is empty, no
10503 # widgets are reset
10504 #
10505 # Return values
10506 # 'undef' on improper arguments
10507 # Otherwise returns the Gtk::Button labelled 'Add', so the calling function can add a
10508 # ->signal_connect to it
10509  
10510 my ($self, $grid, $slWidget, $iv, $rowNumber, $columns, @widgetList) = @_;
10511  
10512 # Check for improper arguments
10513 if (
10514 ! defined $grid || ! defined $slWidget || ! defined $iv || ! defined $rowNumber
10515 || ! defined $columns
10516 ) {
10517 return $axmud::CLIENT->writeImproper(
10518 $self->_objClass . '->addSimpleListButtons_listIV',
10519 @_,
10520 );
10521 }
10522  
10523 # 'Add' button
10524 my $button = Gtk3::Button->new('Add');
10525 $button->set_tooltip_text('Add new value(s)');
10526 $grid->attach($button, 1, $rowNumber, 2, 1);
10527  
10528 # NB The signal_connect method for the 'Add' button must be specified by the callling
10529 # function. Here is some example code:
10530 #
10531 # $button->signal_connect('clicked' => sub {
10532 #
10533 # my ($pattern, $grpNum);
10534 #
10535 # $pattern = $entry->get_text();
10536 # $grpNum = $entry2->get_text();
10537 #
10538 # if ($self->checkEntryIcon($entry, $entry2)) {
10539 #
10540 # # Add new values to (the end of) the list IV
10541 # $self->addEditHash_listIV('myListIV',
10542 # undef, FALSE,
10543 # $pattern, $grpNum,
10544 # );
10545 #
10546 # # Refresh the simple list and reset entry boxes
10547 # $self->refreshList_listIV(
10548 # $slWidget,
10549 # scalar (@columnList / 2),
10550 # 'myListIV',
10551 # );
10552 #
10553 # $self->resetEntryBoxes($entry, $entry2);
10554 # }
10555 # });
10556  
10557 # 'Delete' button
10558 my $button2 = Gtk3::Button->new('Delete');
10559 $button2->signal_connect('clicked' => sub {
10560  
10561 # Get the selected row
10562 my ($index) = $slWidget->get_selected_indices();
10563 if (defined $index) {
10564  
10565 # Delete the value (or values) on this row
10566 $self->deleteEditHash_listIV($iv, ($index * $columns), $columns);
10567  
10568 # Refresh the simple list and reset entry boxes
10569 $self->refreshList_listIV($slWidget, $columns, $iv);
10570 $self->resetEntryBoxes(@widgetList);
10571 }
10572 });
10573 $button2->set_tooltip_text('Delete the selected value(s)');
10574 $grid->attach($button2, 6, $rowNumber, 2, 1);
10575  
10576 # 'Reset' button
10577 my $button3 = Gtk3::Button->new('Reset');
10578 $button3->signal_connect('clicked' => sub {
10579  
10580 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
10581 $self->ivDelete('editHash', $iv);
10582  
10583 # Refresh the simple list and reset entry boxes
10584 $self->refreshList_listIV($slWidget, $columns, $iv);
10585 $self->resetEntryBoxes(@widgetList);
10586 });
10587 $button3->set_tooltip_text('Reset the list');
10588 $grid->attach($button3, 8, $rowNumber, 2, 1);
10589  
10590 # 'Clear' button
10591 my $button4 = Gtk3::Button->new('Clear');
10592 $button4->signal_connect('clicked' => sub {
10593  
10594 # Add an empty list to $self->editHash
10595 $self->ivAdd('editHash', $iv, []);
10596  
10597 # Refresh the simple list and reset entry boxes
10598 $self->refreshList_listIV($slWidget, $columns, $iv);
10599 $self->resetEntryBoxes(@widgetList);
10600 });
10601 $button4->set_tooltip_text('Clear the list of values');
10602 $grid->attach($button4, 10, $rowNumber, 2, 1);
10603  
10604 return $button;
10605 }
10606  
10607 sub addSimpleListButtons_hashIV {
10608  
10609 # Adds four standard buttons used with GA::Obj::SimpleList widgets, when they're
10610 # displaying a hash IV. The buttons are 'Add', 'Delete', 'Reset' and 'Clear'
10611 # NB The ->signal_connect method for the 'Add' button must be specified by the calling
10612 # function
10613 #
10614 # Example calls:
10615 # my $addButton = $self->addSimpleListButton_hashIV($grid, $slWidget, 'someIV', 10);
10616 #
10617 # Expected arguments
10618 # $grid - The tab's Gtk3::Grid object
10619 # $slWidget - The GA::Obj::SimpleList object on which the buttons will act
10620 # $iv - The hash IV in $self->editObj storing the data being edited
10621 # $rowNumber - On the current tab's grid, the row on which the buttons are put
10622 #
10623 # Optional arguments
10624 # @widgetList - List of Gtk3 widgets (entry boxes or combos) that are reset when the
10625 # 'Delete', 'Reset' and 'Clear' buttons are used. If the list is empty, no
10626 # widgets are reset
10627 #
10628 # Return values
10629 # 'undef' on improper arguments
10630 # Otherwise the Gtk::Button labelled 'Add', so the calling function can add a
10631 # ->signal_connect to it
10632  
10633 my ($self, $grid, $slWidget, $iv, $rowNumber, @widgetList) = @_;
10634  
10635 # Check for improper arguments
10636 if (! defined $grid || ! defined $slWidget || ! defined $iv || ! defined $rowNumber) {
10637  
10638 return $axmud::CLIENT->writeImproper(
10639 $self->_objClass . '->addSimpleListButtons_hashIV',
10640 @_,
10641 );
10642 }
10643  
10644 # 'Add' button
10645 my $button = Gtk3::Button->new('Add');
10646 $button->set_tooltip_text('Add a new key/value pair');
10647 $grid->attach($button, 1, $rowNumber, 2, 1);
10648  
10649 # NB The signal_connect method for the 'Add' button must be specified by the callling
10650 # function. Here is some example code:
10651 # $button->signal_connect('clicked' => sub {
10652 #
10653 # my ($key, $value);
10654 #
10655 # $key = $entry->get_text();
10656 # $value = $entry2->get_text();
10657 #
10658 # if ($self->checkEntryIcon($entry, $entry2)) {
10659 #
10660 # # Add a new key-value pair
10661 # $self->modifyEditHash_hashIV('myHashIV', $key, $value);
10662 #
10663 # # Refresh the simple list and reset entry boxes
10664 # $self->refreshList_hashIV($slWidget, scalar (@columnList / 2), 'myHashIV');
10665 # $self->resetEntryBoxes($entry, $entry2);
10666 # }
10667 # });
10668  
10669 # 'Delete' button
10670 my $button2 = Gtk3::Button->new('Delete');
10671 $button2->signal_connect('clicked' => sub {
10672  
10673 my ($key) = $self->getSimpleListData($slWidget, 0);
10674 if (defined $key) {
10675  
10676 # Delete the key-value pair from the hash
10677 $self->modifyEditHash_hashIV($iv, $key, undef, TRUE);
10678  
10679 # Refresh the simple list and reset entry boxes
10680 $self->refreshList_hashIV($slWidget, 2, $iv);
10681 $self->resetEntryBoxes(@widgetList);
10682 }
10683 });
10684 $button2->set_tooltip_text('Delete the selected key/value pair');
10685 $grid->attach($button2, 6, $rowNumber, 2, 1);
10686  
10687 # 'Reset' button
10688 my $button3 = Gtk3::Button->new('Reset');
10689 $button3->signal_connect('clicked' => sub {
10690  
10691 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
10692 $self->ivDelete('editHash', $iv);
10693  
10694 # Refresh the simple list and reset entry boxes
10695 $self->refreshList_hashIV($slWidget, 2, $iv);
10696 $self->resetEntryBoxes(@widgetList);
10697 });
10698 $button3->set_tooltip_text('Reset the hash of key/value pairs');
10699 $grid->attach($button3, 8, $rowNumber, 2, 1);
10700  
10701 # 'Clear' button
10702 my $button4 = Gtk3::Button->new('Clear');
10703 $button4->signal_connect('clicked' => sub {
10704  
10705 # Add an empty hash to $self->editHash
10706 $self->ivAdd('editHash', $iv, {});
10707  
10708 # Refresh the simple list and reset entry boxes
10709 $self->refreshList_hashIV($slWidget, 2, $iv);
10710 $self->resetEntryBoxes(@widgetList);
10711 });
10712 $button4->set_tooltip_text('Clear the hash of key/value pairs');
10713 $grid->attach($button4, 10, $rowNumber, 2, 1);
10714  
10715 return $button;
10716 }
10717  
10718 sub refreshList_listIV {
10719  
10720 # Standard function for refreshing (or initialising) GA::Obj::SimpleList widgets when they
10721 # are displaying a list in two columns
10722 #
10723 # Expected arguments
10724 # $slWidget - The GA::Obj::SimpleList
10725 # $columns - The number of columns. Should be 2; this argument is retained for
10726 # consistency with other functions
10727 # $iv - The IV being displayed in the simple list
10728 #
10729 # Return values
10730 # 'undef' on improper arguments
10731 # 1 otherwise
10732  
10733 my ($self, $slWidget, $columns, $iv, $check) = @_;
10734  
10735 # Local variables
10736 my (
10737 $listRef, $row, $column,
10738 @ivList, @newList, @sortedList, @dataList,
10739 );
10740  
10741 # Check for improper arguments
10742 if (! defined $slWidget || ! defined $columns || ! defined $iv || defined $check) {
10743  
10744 return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshList_listIV', @_);
10745 }
10746  
10747 # Import the list being displayed
10748 if (defined $self->ivShow('editHash', $iv)) {
10749  
10750 # Use the current hash
10751 $listRef = $self->ivShow('editHash', $iv);
10752 @ivList = @$listRef;
10753  
10754 } else {
10755  
10756 # Use the original hash
10757 @ivList = $self->editObj->ivPeek($iv);
10758 }
10759  
10760 # Sort the list. If there is only one column, it's a straightforward sort; otherwise, we
10761 # have to convert @ivList into a two-dimensional list, in the form
10762 # $newList[row_number][column_number], and sort by columns
10763 if ($columns == 1) {
10764  
10765 # Straightforward sort
10766 @dataList = sort {lc($a) cmp lc($b)} (@ivList);
10767  
10768 } else {
10769  
10770 # Don't bother sorting, if there's only one row, if there are more than 2 columns or if
10771 # the IV name doesn't end in 'Hash'
10772 if (scalar @ivList > $columns && $columns == 2 && (substr($iv, -4) eq 'Hash')) {
10773  
10774 # Convert @ivList into a 2-dimensional list
10775 $row = -1;
10776 do {
10777  
10778 $row++;
10779 $newList[$row] = [splice (@ivList, 0, $columns)];
10780  
10781 } until (! @ivList);
10782  
10783 # Sort by the first column
10784 @sortedList = sort {lc($$a[0]) cmp lc($$b[0])} (@newList);
10785  
10786 # Flatten @newList into a 1-dimensional list, row by row
10787 foreach my $rowRef (@sortedList) {
10788  
10789 push (@dataList, @$rowRef);
10790 }
10791  
10792 } else {
10793  
10794 # Only one row, or too many columns to sort
10795 push (@dataList, @ivList);
10796 }
10797 }
10798  
10799 # Reset the simple list
10800 $self->resetListData($slWidget, [@dataList], $columns);
10801  
10802 return 1;
10803 }
10804  
10805 sub refreshList_hashIV {
10806  
10807 # Standard function for refreshing (or initialising) GA::Obj::SimpleList widgets, when
10808 # they're displaying a hash in two columns
10809 #
10810 # Expected arguments
10811 # $slWidget - The GA::Obj::SimpleList
10812 # $columns - The number of columns. Should be 2; this argument is retained for
10813 # consistency with other functions
10814 # $iv - The IV being displayed in the simple list
10815 #
10816 # Return values
10817 # 'undef' on improper arguments
10818 # 1 otherwise
10819  
10820 my ($self, $slWidget, $columns, $iv, $check) = @_;
10821  
10822 # Local variables
10823 my (
10824 $hashRef,
10825 @sortedList, @dataList,
10826 %ivHash,
10827 );
10828  
10829 # Check for improper arguments
10830 if (! defined $slWidget || ! defined $columns || ! defined $iv || defined $check) {
10831  
10832 return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshList_hashIV', @_);
10833 }
10834  
10835 # Import the hash being displayed
10836 if (defined $self->ivShow('editHash', $iv)) {
10837  
10838 # Use the current hash
10839 $hashRef = $self->ivShow('editHash', $iv);
10840 %ivHash = %$hashRef;
10841  
10842 } else {
10843  
10844 # Use the original hash
10845 %ivHash = $self->editObj->ivPeek($iv);
10846 }
10847  
10848 # Get a sorted list of keys, so they can be displayed in alphabetical order
10849 @sortedList = sort {lc($a) cmp lc($b)} (keys %ivHash);
10850  
10851 # Compile the simple list data
10852 foreach my $key (@sortedList) {
10853  
10854 push (@dataList, $key, $ivHash{$key});
10855 }
10856  
10857 # Reset the simple list
10858 $self->resetListData($slWidget, [@dataList], $columns);
10859  
10860 return 1;
10861 }
10862  
10863 sub resetComboBox {
10864  
10865 # Can be called by anything
10866 # Resets the contents of a combo box
10867 #
10868 # Expected arguments
10869 # $combo - The combo box to reset
10870 #
10871 # Optional arguments
10872 # @comboList - List of items to add to the combo box. If the list is empty, the combo
10873 # box is emptied
10874 #
10875 # Return values
10876 # 'undef' on improper arguments
10877 # 1 otherwise
10878  
10879 my ($self, $combo, @comboList) = @_;
10880  
10881 # Check for improper arguments
10882 if (! defined $combo) {
10883  
10884 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetComboBox', @_);
10885 }
10886  
10887 # Empty the combobox
10888 my $treeModel = $combo->get_model();
10889 $treeModel->clear();
10890  
10891 # Fill it with the new list of items
10892 if (@comboList) {
10893  
10894 foreach my $item (@comboList) {
10895  
10896 $combo->append_text($item);
10897 }
10898  
10899 $combo->set_active(0);
10900 }
10901  
10902 return 1;
10903 }
10904  
10905 # Data accessors
10906  
10907 sub getEditHash_scalarIV {
10908  
10909 # Can be called by anything
10910 # $self->editHash can contain scalar values, in the form
10911 # $hash{'name_of_iv'} = scalar_value
10912 # This function can be called to return the scalar value. However, if the IV hasn't yet been
10913 # added to $self->editHash, this function returns the contents of the IV in
10914 # $self->editObj, instead
10915 #
10916 # Expected arguments
10917 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
10918 #
10919 # Return values
10920 # 'undef' on improper arguments
10921 # Otherwise, returns a scalar value (may be 'undef')
10922  
10923 my ($self, $iv, $check) = @_;
10924  
10925 # Check for improper arguments
10926 if (! defined $iv || defined $check) {
10927  
10928 return $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_listIV', @_);
10929 }
10930  
10931 # Check the specified IV actually exists in $self->editHash
10932 if (! $self->ivExists('editHash', $iv)) {
10933  
10934 # It doesn't, so return the contents of the list IV, instead
10935 return $self->editObj->$iv;
10936  
10937 } else {
10938  
10939 return $self->ivShow('editHash', $iv);
10940 }
10941 }
10942  
10943 sub getEditHash_listIV {
10944  
10945 # Can be called by anything
10946 # $self->editHash can contain lists, in the form
10947 # $hash{'name_of_iv'} = reference_to_anonymous_list
10948 # This function can be called to return the contents of the dereferenced list. However, if
10949 # the IV hasn't yet been added to $self->editHash, this function returns the contents of
10950 # the IV in $self->editObj, instead
10951 #
10952 # Expected arguments
10953 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
10954 #
10955 # Return values
10956 # An empty list on improper arguments
10957 # Otherwise, returns a list of values (might be empty)
10958  
10959 my ($self, $iv, $check) = @_;
10960  
10961 # Local variables
10962 my (
10963 $listRef,
10964 @emptyList,
10965 );
10966  
10967 # Check for improper arguments
10968 if (! defined $iv || defined $check) {
10969  
10970 $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_listIV', @_);
10971 return @emptyList;
10972 }
10973  
10974 # Check the specified IV actually exists in $self->editHash
10975 if (! $self->ivExists('editHash', $iv)) {
10976  
10977 # It doesn't, so return the contents of the list IV, instead
10978 return $self->editObj->$iv;
10979  
10980 } else {
10981  
10982 $listRef = $self->ivShow('editHash', $iv);
10983 return @$listRef;
10984 }
10985 }
10986  
10987 sub getEditHash_hashIV {
10988  
10989 # Can be called by anything
10990 # $self->editHash can contain hashes, in the form
10991 # $hash{'name_of_iv'} = reference_to_anonymous_hash
10992 # This function can be called to return the contents of the dereferenced hash as a list.
10993 # However, if the IV hasn't yet been added to $self->editHash, this function returns the
10994 # contents of the IV in $self->editObj, instead
10995 #
10996 # Expected arguments
10997 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
10998 #
10999 # Return values
11000 # An empty list on improper arguments
11001 # Otherwise, returns a hash of values (as a flat list, which might be empty)
11002  
11003 my ($self, $iv, $check) = @_;
11004  
11005 # Local variables
11006 my (
11007 $hashRef,
11008 @list, @emptyList,
11009 %hash,
11010 );
11011  
11012 # Check for improper arguments
11013 if (! defined $iv || defined $check) {
11014  
11015 $axmud::CLIENT->writeImproper($self->_objClass . '->getEditHash_hashIV', @_);
11016 return @emptyList;
11017 }
11018  
11019 # Check the specified IV actually exists in $self->editHash
11020 if (! $self->ivExists('editHash', $iv)) {
11021  
11022 # It doesn't, so return the contents of the hash IV, instead
11023 return $self->editObj->$iv;
11024  
11025 } else {
11026  
11027 $hashRef = $self->ivShow('editHash', $iv);
11028 return %$hashRef;
11029 }
11030 }
11031  
11032 sub addEditHash_listIV {
11033  
11034 # Can be called by anything
11035 # Adds a value (or group of values) to a list IV, and saves the whole list IV
11036 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11037 # $self->editHash, the list is copied from $self->editObj, modified, then saved to
11038 # $self->editHash
11039 #
11040 # Expected arguments
11041 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11042 # $index - The index at which to insert the value (or group of values). If 0, the
11043 # value(s) are inserted at the the start of the list (equivalent to
11044 # 'unshift'). If 'undef', the value(s) are inserted at the end of the
11045 # list (equivalent to 'push')
11046 # $replaceFlag
11047 # - If set to TRUE, the value(s) at $index (and onwards) are replaced. If set
11048 # to FALSE, the value(s) are inserted at this point
11049 # @valueList - The value(s) to add to the list
11050 #
11051 # Return values
11052 # 'undef' on improper arguments
11053 # 1 otherwise
11054  
11055 my ($self, $iv, $index, $replaceFlag, @valueList) = @_;
11056  
11057 # Local variables
11058 my @ivList;
11059  
11060 # Check for improper arguments
11061 if (! defined $iv || ! defined $replaceFlag || ! @valueList) {
11062  
11063 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEditHash_listIV', @_);
11064 }
11065  
11066 # Import the list from $self->editHash if it's there, or the original list from
11067 # $self->editObj otherwise
11068 @ivList = $self->getEditHash_listIV($iv);
11069  
11070 if ($replaceFlag && defined $index) {
11071  
11072 # Replace existing values
11073 for (my $count = $index; $count < ($index + scalar @valueList); $count++) {
11074  
11075 $ivList[$count] = shift @valueList;
11076 }
11077  
11078 } elsif (! $replaceFlag && defined $index) {
11079  
11080 # Add value(s) at the insertion point
11081 splice(@ivList, $index, 0, @valueList);
11082  
11083 } else {
11084  
11085 # ($index not defined)
11086 # Add values to the end of the list
11087 push (@ivList, @valueList);
11088 }
11089  
11090 # Save the modified list
11091 $self->ivAdd('editHash', $iv, \@ivList);
11092  
11093 return 1;
11094 }
11095  
11096 sub deleteEditHash_listIV {
11097  
11098 # Can be called by anything
11099 # Deletes a value (or group of values) from a list IV, and saves the whole list IV
11100 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11101 # $self->editHash, the list is copied from $self->editObj, modified, then saved to
11102 # $self->editHash
11103 #
11104 # Expected arguments
11105 # $iv - The IV to be checked; a key in $self->editHash or an IV in $self->editObj
11106 # $index - The index at which to remove the value (or group of values). If 0, the
11107 # value(s) are deleted from the the start of the list (equivalent to 'shift').
11108 # If 'undef', the value(s) are deleted the end of the list (roughly equivalent
11109 # to 'pop').
11110 # $number - The number of values to delete (usually 1)
11111 #
11112 # Return values
11113 # 'undef' on improper arguments
11114 # 1 otherwise
11115  
11116 my ($self, $iv, $index, $number, $check) = @_;
11117  
11118 # Local variables
11119 my @ivList;
11120  
11121 # Check for improper arguments
11122 if (! defined $iv || ! defined $number || defined $check) {
11123  
11124 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteEditHash_listIV', @_);
11125 }
11126  
11127 # Import the list from $self->editHash if it's there, or the original list from
11128 # $self->editObj otherwise
11129 @ivList = $self->getEditHash_listIV($iv);
11130  
11131 if (defined $index) {
11132  
11133 splice(@ivList, $index, $number);
11134  
11135 } else {
11136  
11137 # Delete values from the end of a list
11138 splice(@ivList, ($index * -1), $number);
11139 }
11140  
11141 # Save the modified list
11142 $self->ivAdd('editHash', $iv, \@ivList);
11143  
11144 return 1;
11145 }
11146  
11147 sub modifyEditHash_hashIV {
11148  
11149 # Can be called by anything
11150 # Adds (or replaces) a single key-value pair in a hash IV, and saves the whole hash IV
11151 # If this IV hasn't been modified yet - i.e., if it is stored in $self->editObj but not in
11152 # $self->editHash, the hash is copied from $self->editObj, modified, then saved to
11153 # $self->editHash
11154 #
11155 # Expected arguments
11156 # $iv - The IV to be checked; a key in $self->editHash or an IV in
11157 # $self->editObj
11158 # $key, $value - The key/value pair to replace ($value can be 'undef')
11159 #
11160 # Optional arguments
11161 # $deleteFlag - If set to TRUE, the key-value pair is deleted from the hash ($value is
11162 # ignored, and should be set to 'undef')
11163 #
11164 # Return values
11165 # 'undef' on improper arguments
11166 # 1 otherwise
11167  
11168 my ($self, $iv, $key, $value, $deleteFlag, $check) = @_;
11169  
11170 # Local variables
11171 my %ivHash;
11172  
11173 # Check for improper arguments
11174 if (! defined $iv || ! defined $key || defined $check) {
11175  
11176 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyEditHash_hashIV', @_);
11177 }
11178  
11179 # Import the hash from $self->editHash if it's there, or the original hash from
11180 # $self->editObj otherwise
11181 if ($self->ivExists('editHash', $iv)) {
11182 %ivHash = $self->getEditHash_hashIV($iv);
11183 } else {
11184 %ivHash = $self->editObj->$iv;
11185 }
11186  
11187 if ($deleteFlag) {
11188  
11189 # Delete the key-value pair
11190 if (exists $ivHash{$key}) {
11191  
11192 delete $ivHash{$key};
11193 }
11194  
11195 } else {
11196  
11197 # Add the key-value pair
11198 $ivHash{$key} = $value;
11199 }
11200  
11201 # Save the modified hash
11202 $self->ivAdd('editHash', $iv, \%ivHash);
11203  
11204 return 1;
11205 }
11206  
11207 sub updateListDataWithKey {
11208  
11209 # Can be called by any tab function to update the data in a GA::Obj::SimpleList when it is
11210 # storing data in two columns representing the contents of a hash
11211 # The first column is the key, the second column its corresponding value
11212 # If the key already exists in the list, it is replaced; otherwise a new key-value pair is
11213 # added to the simple list
11214 # If the key is not defined or an empty string, it isn't added to the simple list
11215 #
11216 # Expected arguments
11217 # $slWidget - The GA::Obj::SimpleList to modify
11218 # $key - The key to add to the list, which will eventually be stored as a hash
11219 # $value - Its corresponding value
11220 #
11221 # Return values
11222 # 'undef' on improper arguments, or if $key is 'undef' or an empty string
11223 # 1 otherwise
11224  
11225 my ($self, $slWidget, $key, $value, $check) = @_;
11226  
11227 # Local variables
11228 my (
11229 @list,
11230 %hash,
11231 );
11232  
11233 # Check for improper arguments
11234 if (! defined $slWidget || defined $check) {
11235  
11236 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateListDataWithKey', @_);
11237 }
11238  
11239 # If $key is 'undef' or an empty string, do nothing
11240 if (! $key) {
11241  
11242 return undef;
11243 }
11244  
11245 # Convert the data stored in the GA::Obj::SimpleList into a hash
11246 %hash = $self->convertListDataToHash($slWidget);
11247  
11248 # Add the key-value pair
11249 $hash{$key} = $value;
11250  
11251 # Get a list of keys in the hash, so we can sort it alphabetically
11252 @list = sort {lc($a) cmp lc($b)} (keys %hash);
11253  
11254 # Reset the GA::Obj::SimpleList
11255 @{$slWidget->{data}} = ();
11256  
11257 foreach my $sortedKey (@list) {
11258  
11259 push (@{$slWidget->{data}}, [$sortedKey, $hash{$sortedKey}]);
11260 }
11261  
11262 return 1;
11263 }
11264  
11265 sub findKeyInListData {
11266  
11267 # Can be called by any tab function to check the data in a GA::Obj::SimpleList when it is
11268 # storing data in two columns representing the contents of a hash
11269 # The first column is the key, the second column its corresponding value
11270 # Checks whether the specified key exists in list's data
11271 #
11272 # Expected arguments
11273 # $slWidget - The GA::Obj::SimpleList to modify
11274 # $key - The key to add to the list's data
11275 #
11276 # Return values
11277 # undef on improper arguments, if $key is 'undef' or an empty string or if the key doesn't
11278 # exist in the list's data
11279 # 1 if the key would exist in the hash, if the list's data were converted to a hash right
11280 # now
11281  
11282 my ($self, $slWidget, $key, $check) = @_;
11283  
11284 # Local variables
11285 my (
11286 @list,
11287 %hash,
11288 );
11289  
11290 # Check for improper arguments
11291 if (! defined $slWidget || defined $check) {
11292  
11293 return $axmud::CLIENT->writeImproper($self->_objClass . '->findKeyInListData', @_);
11294 }
11295  
11296 # If $key is 'undef' or an empty string, do nothing
11297 if (! $key) {
11298  
11299 return undef;
11300 }
11301  
11302 # Convert the data stored in the GA::Obj::SimpleList into a hash
11303 %hash = $self->convertListDataToHash($slWidget);
11304  
11305 # See whether the key exists
11306 if (exists $hash{$key}) {
11307 return 1;
11308 } else {
11309 return undef;
11310 }
11311 }
11312  
11313 sub convertListDataToHash {
11314  
11315 # Can be called by any tab function to convert the data in a GA::Obj::SimpleList (in which
11316 # data is stored in two columns) into a hash
11317 #
11318 # Expected arguments
11319 # $slWidget - The GA::Obj::SimpleList to use
11320 #
11321 # Return values
11322 # An empty hash on improper arguments
11323 # Otherwise, returns the hash
11324  
11325 my ($self, $slWidget, $check) = @_;
11326  
11327 # Local variables
11328 my (
11329 @listRefList,
11330 %emptyHash, %hash,
11331 );
11332  
11333 # Check for improper arguments
11334 if (! defined $slWidget || defined $check) {
11335  
11336 $axmud::CLIENT->writeImproper($self->_objClass . '->convertListDataToHash', @_);
11337 return %emptyHash; # Returns an empty hash
11338 }
11339  
11340 @listRefList = @{$slWidget->{data}};
11341 foreach my $listRef (@listRefList) {
11342  
11343 $hash{$$listRef[0]} = $$listRef[1];
11344 }
11345  
11346 return %hash;
11347 }
11348  
11349 sub storeListData {
11350  
11351 # Can be called by any tab function to store the data in a GA::Obj::SimpleList in
11352 # $self->editHash
11353 #
11354 # Expected arguments
11355 # $slWidget - The GA::Obj::SimpleList to use
11356 # $iv - The name of the instance variable in $self->editHash where the list is
11357 # stored
11358 #
11359 # Return values
11360 # 'undef' on improper arguments
11361 # 1 otherwise
11362  
11363 my ($self, $slWidget, $iv, $check) = @_;
11364  
11365 # Local variables
11366 my (@storeList, @listOfRefs);
11367  
11368 # Check for improper arguments
11369 if (! defined $slWidget || ! defined $iv || defined $check) {
11370  
11371 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListData', @_);
11372 }
11373  
11374 @listOfRefs = @{$slWidget->{data}};
11375 foreach my $ref (@listOfRefs) {
11376  
11377 push (@storeList, @$ref);
11378 }
11379  
11380 $self->ivAdd('editHash', $iv, \@storeList);
11381  
11382 return 1;
11383 }
11384  
11385 sub storeListColumnInList {
11386  
11387 # Can be called by any tab function to store the data from a single column in a
11388 # GA::Obj::SimpleList as a list in $self->editHash
11389 #
11390 # Expected arguments
11391 # $slWidget - The GA::Obj::SimpleList to use
11392 # $iv - The name of the instance variable in $self->editHash in which the column's
11393 # data is stored
11394 # $column - The number of the chosen column
11395 #
11396 # Return values
11397 # 'undef' on improper arguments
11398 # 1 otherwise
11399  
11400 my ($self, $slWidget, $iv, $column, $check) = @_;
11401  
11402 # Local variables
11403 my (
11404 @listOfRefs, @dataList, @saveList,
11405 %storeHash,
11406 );
11407  
11408 # Check for improper arguments
11409 if (! defined $slWidget || ! defined $iv || ! defined $column || defined $check) {
11410  
11411 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListColumnInList', @_);
11412 }
11413  
11414 @listOfRefs = @{$slWidget->{data}};
11415 foreach my $ref (@listOfRefs) {
11416  
11417 @dataList = @$ref;
11418 push (@saveList, $dataList[$column]);
11419 }
11420  
11421 $self->ivAdd('editHash', $iv, \@saveList);
11422  
11423 return 1;
11424 }
11425  
11426 sub storeListDataInHash {
11427  
11428 # Can be called by any tab function to store the data in a GA::Obj::SimpleList in
11429 # $self->editHash
11430 # This is a companion function to $self->storeListData (which stores the data as a list);
11431 # this function stores the data as a hash
11432 #
11433 # Expected arguments
11434 # $slWidget - Reference to a GA::Obj::SimpleList
11435 # $iv - The name of the instance variable in $self->editHash where the hash is
11436 # stored
11437 #
11438 # Return values
11439 # 'undef' on improper arguments
11440 # 1 otherwise
11441  
11442 my ($self, $slWidget, $iv, $check) = @_;
11443  
11444 # Local variables
11445 my (
11446 @listOfRefs, @dataList,
11447 %storeHash,
11448 );
11449  
11450 # Check for improper arguments
11451 if (! defined $slWidget || ! defined $iv || defined $check) {
11452  
11453 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeListDataInHash', @_);
11454 }
11455  
11456 @listOfRefs = @{$slWidget->{data}};
11457 foreach my $ref (@listOfRefs) {
11458  
11459 @dataList = @$ref;
11460 $storeHash{$dataList[0]} = $dataList[1];
11461 }
11462  
11463 $self->ivAdd('editHash', $iv, \%storeHash);
11464  
11465 return 1;
11466 }
11467  
11468 # Standard tabs
11469  
11470 sub privateDataTab {
11471  
11472 # Standard private data tab - stores data in a single hash IV, such as the ->privateHash in
11473 # all profiles. The contents of the hash is displayed in a simple list. Each key's value
11474 # can itself be a scalar, list or hash, each of which can be edited from the tab
11475 # Currently used by the 'edit' windows for profiles, world model objects, exit model
11476 # objects and quests
11477 #
11478 # Expected arguments
11479 # $hashIV - The hash IV to be edited
11480 # $tabName - A name to display on the tab, with one letter highlighted as a keyboard
11481 # shortcut (e.g. '_Private')
11482 # $titleLabel - The main label to display at the top of the tab, e.g. 'Private data hash'
11483 # (displayed in bold)
11484 # $minorLabel - The label to display just below the main label (displayed in italics)
11485 #
11486 # Return values
11487 # 'undef' on improper arguments
11488 # 1 otherwise
11489  
11490 my ($self, $hashIV, $tabName, $titleLabel, $minorLabel, $check) = @_;
11491  
11492 # Local variables
11493 my (@columnList, @comboList);
11494  
11495 # Check for improper arguments
11496 if (
11497 ! defined $hashIV || ! defined $tabName || ! defined $titleLabel
11498 || ! defined $minorLabel || defined $check
11499 ) {
11500 return $axmud::CLIENT->writeImproper($self->_objClass . '->privateDataTab', @_);
11501 }
11502  
11503 # Tab setup
11504 my $grid = $self->addTab($tabName, $self->notebook);
11505  
11506 # Private settings hash
11507 $self->addLabel($grid, '<b>' . $titleLabel . '</b>',
11508 0, 12, 0, 1);
11509 $self->addLabel($grid, '<i>' . $minorLabel . '</i>',
11510 1, 12, 1, 2);
11511  
11512 # Add a simple list
11513 @columnList = (
11514 'Key', 'text',
11515 'Type', 'text',
11516 'Value(s)', 'text',
11517 );
11518  
11519 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
11520 1, 12, 2, 10);
11521  
11522 # Initialise the simple list
11523 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
11524  
11525 # Add an entry for adding new data to the private hash
11526 $self->addLabel($grid, 'Key',
11527 1, 3, 10, 11);
11528 # Show an icon for when something is entered; however the icon isn't checked (as would
11529 # normally happen)
11530 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
11531 3, 6, 10, 11);
11532  
11533 # The $key's corresponding value is either a scalar, a reference to a list or a reference to
11534 # a hash
11535 # Add three buttons to allow the user to add one of these three types of value
11536 my $button = $self->addButton($grid, 'Add scalar...', 'Add a scalar value', undef,
11537 6, 8, 10, 11);
11538 $button->signal_connect('clicked' => sub {
11539  
11540 my (
11541 $key,
11542 %ivHash,
11543 );
11544  
11545 $key = $entry->get_text();
11546  
11547 # Check the key hasn't already been created
11548 %ivHash = $self->getEditHash_hashIV($hashIV);
11549 if (! exists $ivHash{$key}) {
11550  
11551 # Prompt the user for a scalar value
11552 $self->promptScalar(
11553 $hashIV,
11554 $key, # Mode 2
11555 FALSE,
11556 undef,
11557 FALSE,
11558 'privateDataTab_refreshList',
11559 $slWidget,
11560 scalar (@columnList / 2),
11561 $hashIV,
11562 );
11563  
11564 # Reset the entry box
11565 $entry->set_text('');
11566 }
11567 });
11568  
11569 my $button2 = $self->addButton($grid, 'Add list...', 'Add a list value', undef,
11570 8, 10, 10, 11);
11571 $button2->signal_connect('clicked' => sub {
11572  
11573 my (
11574 $key,
11575 %ivHash,
11576 );
11577  
11578 $key = $entry->get_text();
11579  
11580 # Check the key hasn't already been created
11581 %ivHash = $self->getEditHash_hashIV($hashIV);
11582 if (! exists $ivHash{$key}) {
11583  
11584 # Prompt the user for a list value
11585 $self->promptList(
11586 $hashIV,
11587 $key, # Mode 2
11588 undef,
11589 FALSE,
11590 'privateDataTab_refreshList',
11591 $slWidget,
11592 scalar (@columnList / 2),
11593 $hashIV,
11594 );
11595  
11596 # Reset the entry box
11597 $entry->set_text('');
11598 }
11599 });
11600  
11601 my $button3 = $self->addButton($grid, 'Add hash...', 'Add a hash value', undef,
11602 10, 12, 10, 11);
11603 $button3->signal_connect('clicked' => sub {
11604  
11605 my (
11606 $key,
11607 %ivHash,
11608 );
11609  
11610 $key = $entry->get_text();
11611  
11612 # Check the key hasn't already been created
11613 %ivHash = $self->getEditHash_hashIV($hashIV);
11614 if (! exists $ivHash{$key}) {
11615  
11616 # Prompt the user for a hash value
11617 $self->promptHash(
11618 $hashIV,
11619 $key, # Mode 2
11620 undef,
11621 FALSE,
11622 'privateDataTab_refreshList',
11623 $slWidget,
11624 scalar (@columnList / 2),
11625 $hashIV,
11626 );
11627  
11628 # Reset the entry box
11629 $entry->set_text('');
11630 }
11631 });
11632  
11633 # Add the standard editing button
11634 my $button4 = Gtk3::Button->new('Edit');
11635 $button4->signal_connect('clicked' => sub {
11636  
11637 my (
11638 $key, $type,
11639 %ivHash,
11640 );
11641  
11642 ($key) = $self->getSimpleListData($slWidget, 0);
11643 %ivHash = $self->getEditHash_hashIV($hashIV);
11644 if (defined $key && exists $ivHash{$key}) {
11645  
11646 $type = ref $ivHash{$key};
11647  
11648 # Call ->promptScalar, ->promptList and ->promptHash
11649 if ($type eq 'ARRAY') {
11650  
11651 $self->promptList(
11652 $hashIV,
11653 $key, # Mode 2
11654 undef,
11655 FALSE,
11656 'privateDataTab_refreshList',
11657 $slWidget,
11658 scalar (@columnList / 2),
11659 $hashIV,
11660 );
11661  
11662 } elsif ($type eq 'HASH') {
11663  
11664 $self->promptHash(
11665 $hashIV,
11666 $key, # Mode 2
11667 undef,
11668 FALSE,
11669 'privateDataTab_refreshList',
11670 $slWidget,
11671 scalar (@columnList / 2),
11672 $hashIV,
11673 );
11674  
11675 } else {
11676  
11677 # Prompt the user for a scalar value
11678 $self->promptScalar(
11679 $hashIV,
11680 $key, # Mode 2
11681 FALSE,
11682 undef,
11683 FALSE,
11684 'privateDataTab_refreshList',
11685 $slWidget,
11686 scalar (@columnList / 2),
11687 $hashIV,
11688 );
11689 }
11690 }
11691 });
11692 $button4->set_tooltip_text('Edit the selected key');
11693 $grid->attach($button4, 1, 11, 3, 1);
11694  
11695 my $button5 = Gtk3::Button->new('Delete');
11696 $button5->signal_connect('clicked' => sub {
11697  
11698 my ($key) = $self->getSimpleListData($slWidget, 0);
11699 if (defined $key) {
11700  
11701 # Delete the key-value pair from the hash
11702 $self->modifyEditHash_hashIV($hashIV, $key, undef, TRUE);
11703  
11704 # Update the simple list
11705 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
11706 }
11707 });
11708 $button5->set_tooltip_text('Delete the selected key');
11709 $grid->attach($button5, 6, 11, 2, 1);
11710  
11711 my $button6 = Gtk3::Button->new('Reset');
11712 $button6->signal_connect('clicked' => sub {
11713  
11714 # Remove this IV from $self->editHash, so that the IV in $self->editObj takes over
11715 $self->ivDelete('editHash', $hashIV);
11716  
11717 # Update the simple list
11718 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
11719 });
11720 $button6->set_tooltip_text('Reset the list of keys');
11721 $grid->attach($button6, 8, 11, 2, 1);
11722  
11723 my $button7 = Gtk3::Button->new('Clear');
11724 $button7->signal_connect('clicked' => sub {
11725  
11726 # Add an empty hash to $self->editHash
11727 $self->ivAdd('editHash', $hashIV, {});
11728  
11729 # Update the simple list
11730 $self->privateDataTab_refreshList($slWidget, scalar (@columnList / 2), $hashIV);
11731 });
11732 $button7->set_tooltip_text('Clear the list of keys');
11733 $grid->attach($button7, 10, 11, 2, 1);
11734  
11735 # Tab complete
11736 return 1;
11737 }
11738  
11739 sub privateDataTab_refreshList {
11740  
11741 # Called by $self->privateDataTab to refresh the simple list
11742 #
11743 # Expected arguments
11744 # $slWidget - The GA::Obj::SimpleList
11745 # $columns - The number of columns
11746 # $hashIV - The hash IV being edited
11747 #
11748 # Return values
11749 # 'undef' on improper arguments
11750 # 1 otherwise
11751  
11752 my ($self, $slWidget, $columns, $hashIV, $check) = @_;
11753  
11754 # Local variables
11755 my (
11756 @dataList,
11757 %ivHash,
11758 );
11759  
11760 # Check for improper arguments
11761 if (! defined $slWidget || ! defined $columns || ! defined $hashIV || defined $check) {
11762  
11763 return $axmud::CLIENT->writeImproper(
11764 $self->_objClass . '->privateDataTab_refreshList',
11765 @_,
11766 );
11767 }
11768  
11769 # Import the IV (for convenience)
11770 %ivHash = $self->getEditHash_hashIV($hashIV);
11771  
11772 # Compile the simple list data
11773 foreach my $key (sort {lc($a) cmp lc($b)} (keys %ivHash)) {
11774  
11775 my (
11776 $value, $typeString, $valueString, $type,
11777 %hash,
11778 );
11779  
11780 $value = $ivHash{$key};
11781  
11782 if (! defined $value) {
11783  
11784 $typeString = 'scalar';
11785 $valueString = '<undef>';
11786  
11787 } else {
11788  
11789 $type = ref $value;
11790 if ($type eq 'ARRAY') {
11791  
11792 $typeString = 'list';
11793 foreach my $item (@$value) {
11794  
11795 if (! defined $valueString) {
11796 $valueString = $item;
11797 } else {
11798 $valueString .= ', ' . $item;
11799 }
11800 }
11801  
11802 } elsif ($type eq 'HASH') {
11803  
11804 $typeString = 'hash';
11805 foreach my $thisKey (sort {lc($a) cmp lc($b)} (keys %$value)) {
11806  
11807 my $thisValue = $$value{$thisKey};
11808 if (! defined $thisValue) {
11809  
11810 $thisValue = '<undef>';
11811 }
11812  
11813 if (! defined $valueString) {
11814 $valueString = $thisKey . ':' . $thisValue;
11815 } else {
11816 $valueString .= ', ' . $thisKey . ':' . $thisValue;
11817 }
11818 }
11819  
11820 } else {
11821  
11822 $typeString = 'scalar';
11823 $valueString = $value;
11824 }
11825 }
11826  
11827 push (@dataList,
11828 $key,
11829 $typeString,
11830 $valueString,
11831 );
11832 }
11833  
11834 # Reset the simple list
11835 $self->resetListData($slWidget, [@dataList], $columns);
11836  
11837 return 1;
11838 }
11839  
11840 # Shared tabs (shared by GA::EditWin::Profile::Char and GA::EditWin::Task)
11841  
11842 sub objects1Tab {
11843  
11844 # Objects1 tab
11845 #
11846 # Expected arguments
11847 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
11848 #
11849 # Return values
11850 # 'undef' on improper arguments
11851 # 1 otherwise
11852  
11853 my ($self, $innerNotebook, $check) = @_;
11854  
11855 # Local variables
11856 my (
11857 $page, $charObj,
11858 @columnList,
11859 %objHash,
11860 );
11861  
11862 # Check for improper arguments
11863 if (! defined $innerNotebook || defined $check) {
11864  
11865 return $axmud::CLIENT->writeImproper($self->_objClass . '->objects1Tab', @_);
11866 }
11867  
11868 # Tab setup. This tab is used in the task 'pref' window, and an identical copy used in the
11869 # character profile 'edit' window
11870 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
11871 $page = 'Page _3';
11872 } else {
11873 $page = 'Page _1';
11874 }
11875  
11876 my $grid = $self->addTab($page, $innerNotebook);
11877  
11878 # Decide which character profile we're using
11879 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
11880 $charObj = $self->session->currentChar;
11881 } else {
11882 $charObj = $self->editObj;
11883 }
11884  
11885 # Protected objects
11886 $self->addLabel($grid, '<b>Protected objects</b>',
11887 0, 12, 0, 1);
11888 $self->addLabel($grid,
11889 '<i>List of objects which enjoy semi-protection against being sold and dropped</i>',
11890 1, 12, 1, 2);
11891  
11892 # Add a simple list
11893 @columnList = (
11894 'Categories', 'text', # ->categoryList
11895 'Main noun', 'text', # ->noun
11896 'Other nouns', 'text', # ->otherNounList
11897 'Adjs', 'text', # ->adjList
11898 'Pseudo adjs', 'text', # ->pseudoAdjList
11899 'Unknowns', 'text', # ->unknownWordList
11900 );
11901  
11902 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
11903 1, 12, 2, 9);
11904  
11905 # Create a hash to link lines in the simple list to objects in the protected objects list,
11906 # in the form
11907 # $objHash{line_number} = blessed_reference_of_protected_object
11908 # Each time the simple list is refreshed, the hash is updated
11909 %objHash = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
11910  
11911 # Add buttons
11912 my $button = $self->addButton($grid,
11913 'Unprotect',
11914 'Delete the selected protected object',
11915 undef,
11916 1, 3, 9, 10,
11917 TRUE); # Irreversible
11918 $button->signal_connect('clicked' => sub {
11919  
11920 my ($index, $lineRef, $obj, $cmd, $match, $count);
11921  
11922 ($index) = $slWidget->get_selected_indices();
11923 if (defined $index) {
11924  
11925 $obj = $objHash{$index};
11926  
11927 if ($charObj) { # Check there is a current character profile
11928  
11929 # Find the object's position in the protected objects list maintained by the
11930 # character profile (which may possibly have changed, since the simple list
11931 # was last updated)
11932 $count = -1;
11933 foreach my $element ($charObj->protectObjList) {
11934  
11935 $count++;
11936  
11937 if ($element eq $obj) {
11938  
11939 $match = $count;
11940 }
11941 }
11942  
11943 if (defined $match) {
11944  
11945 # Unprotect the object. The ';unprotectobject' command lists objects
11946 # starting from 1, not 0 (so we must add 1 to $match)
11947 $self->session->pseudoCmd(
11948 'unprotectobject ' . ($match + 1),
11949 $self->pseudoCmdMode,
11950 );
11951  
11952 %objHash = $self->objects1Tab_refreshList(
11953 $slWidget,
11954 scalar (@columnList / 2),
11955 $charObj,
11956 );
11957 }
11958 }
11959 }
11960 });
11961  
11962 my $button2 = $self->addButton($grid, 'Edit...', 'Edit the protected object', undef,
11963 3, 5, 9, 10);
11964 $button2->signal_connect('clicked' => sub {
11965  
11966 my ($index, $obj, $childWinObj);
11967  
11968 ($index) = $slWidget->get_selected_indices();
11969 if (defined $index && exists $objHash{$index}) {
11970  
11971 $obj = $objHash{$index};
11972  
11973 # Open an 'edit' window for the protected object
11974 $childWinObj = $self->createFreeWin(
11975 'Games::Axmud::EditWin::Protect',
11976 $self,
11977 $self->session,
11978 'Edit protected object \'' . $obj->noun . '\'',
11979 $obj,
11980 FALSE, # Not temporary
11981 );
11982  
11983 if ($childWinObj) {
11984  
11985 # When the 'edit' window closes, update the simple list
11986 $self->add_childDestroy(
11987 $childWinObj,
11988 'objects1Tab_refreshList',
11989 [$slWidget, (scalar @columnList / 2), $charObj],
11990 );
11991 }
11992 }
11993 });
11994  
11995 my $button3 = $self->addButton($grid,
11996 'Dump list',
11997 'Display the list of protected objects in the \'main\' window',
11998 undef,
11999 8, 10, 9, 10);
12000 $button3->signal_connect('clicked' => sub {
12001  
12002 $self->session->pseudoCmd('listprotectobject', $self->pseudoCmdMode);
12003  
12004 %objHash
12005 = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12006 });
12007  
12008 my $button4 = $self->addButton($grid,
12009 'Refresh list',
12010 'Refresh the list of protected objects',
12011 undef,
12012 10, 12, 9, 10);
12013 $button4->signal_connect('clicked' => sub {
12014  
12015 # Refresh the simple list
12016 %objHash
12017 = $self->objects1Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12018  
12019 # If there is no current character profile (and we need one), the buttons (except for
12020 # the 'refresh list' button) must be insensitive
12021 if ($charObj) {
12022 $self->sensitiseWidgets($button, $button2);
12023 } else {
12024 $self->desensitiseWidgets($button, $button2);
12025 }
12026 });
12027  
12028 my $button5 = $self->addButton($grid,
12029 'Protect objects matching words:',
12030 'Protect objects matching this list of words',
12031 undef,
12032 1, 5, 10, 11,
12033 TRUE); # Irreversible
12034 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12035 5, 12, 10, 11);
12036 $button5->signal_connect('clicked' => sub {
12037  
12038 my $wordString = $entry->get_text();
12039  
12040 if ($self->checkEntryIcon($entry)) {
12041  
12042 # Protect objects matching these words
12043 $self->session->pseudoCmd(
12044 'protectobject ' . $wordString,
12045 $self->pseudoCmdMode,
12046 );
12047  
12048 # Refresh the simple list and reset the entry boxes
12049 %objHash = $self->objects1Tab_refreshList(
12050 $slWidget,
12051 scalar (@columnList / 2),
12052 $charObj,
12053 );
12054 $self->resetEntryBoxes($entry);
12055 }
12056 });
12057  
12058 my $button6 = $self->addButton($grid,
12059 'Monitor objects matching words:',
12060 'Monitor objects matching this list of words',
12061 undef,
12062 1, 5, 11, 12,
12063 TRUE); # Irreversible
12064 my $entry2 = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12065 5, 12, 11, 12);
12066 $button6->signal_connect('clicked' => sub {
12067  
12068 my $wordString = $entry2->get_text();
12069  
12070 if ($self->checkEntryIcon($entry2)) {
12071  
12072 # Monitor objects matching these words
12073 $self->session->pseudoCmd(
12074 'monitorobject ' . $wordString,
12075 $self->pseudoCmdMode,
12076 );
12077  
12078 # Refresh the simple list and reset the entry boxes
12079 %objHash = $self->objects1Tab_refreshList(
12080 $slWidget,
12081 scalar (@columnList / 2),
12082 $charObj,
12083 );
12084 $self->resetEntryBoxes($entry2);
12085 }
12086 });
12087  
12088 # Widgets can't be manipulated when this isn't a current profile (or a current task)
12089 if (! $self->currentFlag) {
12090  
12091 $button->set_sensitive(FALSE);
12092 $button2->set_sensitive(FALSE);
12093 $button3->set_sensitive(FALSE);
12094 $button4->set_sensitive(FALSE);
12095 $button5->set_sensitive(FALSE);
12096 $button6->set_sensitive(FALSE);
12097 $entry->set_sensitive(FALSE);
12098 $entry2->set_sensitive(FALSE);
12099 }
12100  
12101 # Tab complete
12102 return 1;
12103 }
12104  
12105 sub objects1Tab_refreshList {
12106  
12107 # Called by $self->objects1Tab to reset the GA::Obj::SimpleList
12108 #
12109 # Expected arguments
12110 # $slWidget - The GA::Obj::SimpleList
12111 # $columns - The number of columns in the list
12112 #
12113 # Optional arguments
12114 # $charObj - The character profile whose list of protected objects we're showing.
12115 # If set to 'undef', it's because there is no current character and,
12116 # because we need one, we therefore show an empty list
12117 #
12118 # Return values
12119 # An empty hash on improper arguments
12120 # Otherwise, a hash which links lines in the simple list to the objects it contains
12121 # - which replaces the hash %objHash in $self->objects1Tab
12122  
12123 my ($self, $slWidget, $columns, $charObj, $check) = @_;
12124  
12125 # Local variables
12126 my (
12127 $count,
12128 @objList, @dataList,
12129 %emptyHash, %objHash,
12130 );
12131  
12132 # Check for improper arguments
12133 if (! defined $slWidget || ! defined $columns || defined $check) {
12134  
12135 $axmud::CLIENT->writeImproper($self->_objClass . '->objects1Tab_refreshList', @_);
12136 return %emptyHash;
12137 }
12138  
12139 # Don't display anything if there is no specified character profile
12140 if (! $charObj) {
12141  
12142 $self->resetListData($slWidget, [], $columns);
12143  
12144 } else {
12145  
12146 # Import the list of protected objects
12147 @objList = $charObj->protectObjList;
12148  
12149 # Refresh the simple list, and create a new hash of objects linked to the line they
12150 # appear on
12151 $count = -1;
12152  
12153 # Compile the simple list data
12154 foreach my $obj (@objList) {
12155  
12156 $count++;
12157  
12158 push (@dataList,
12159 join(' ', $obj->categoryList),
12160 $obj->noun,
12161 join(' ', $obj->otherNounList),
12162 join(' ', $obj->adjList),
12163 join(' ', $obj->pseudoAdjList),
12164 join(' ', $obj->unknownWordList),
12165 );
12166  
12167 $objHash{$count} = $obj;
12168 }
12169  
12170 # Reset the simple list
12171 $self->resetListData($slWidget, [@dataList], $columns);
12172 }
12173  
12174 return %objHash;
12175 }
12176  
12177 sub objects2Tab {
12178  
12179 # Objects2 tab
12180 #
12181 # Expected arguments
12182 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
12183 #
12184 # Return values
12185 # 'undef' on improper arguments
12186 # 1 otherwise
12187  
12188 my ($self, $innerNotebook, $check) = @_;
12189  
12190 # Local variables
12191 my (
12192 $page, $charObj,
12193 @columnList,
12194 %objHash,
12195 );
12196  
12197 # Check for improper arguments
12198 if (! defined $innerNotebook || defined $check) {
12199  
12200 return $axmud::CLIENT->writeImproper($self->_objClass . '->objects2Tab', @_);
12201 }
12202  
12203 # Tab setup. This tab is used in the task 'pref' window, and an identical copy used in the
12204 # character profile 'edit' window
12205 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12206 $page = 'Page _4';
12207 } else {
12208 $page = 'Page _2';
12209 }
12210  
12211 my $grid = $self->addTab($page, $innerNotebook);
12212  
12213 # Decide which character profile we're using
12214 if ($self->_objClass eq 'Games::Axmud::EditWin::Task') {
12215 $charObj = $self->session->currentChar;
12216 } else {
12217 $charObj = $self->editObj;
12218 }
12219  
12220 # Monitored objects
12221 $self->addLabel($grid, '<b>Monitored objects</b>',
12222 0, 12, 0, 1);
12223 $self->addLabel($grid,
12224 '<i>List of objects whose condition is monitored by the Condition task</i>',
12225 1, 12, 1, 2);
12226  
12227 # Add a simple list
12228 @columnList = (
12229 'Categories', 'text', # ->categoryList
12230 'Main noun', 'text', # ->noun
12231 'Other nouns', 'text', # ->otherNounList
12232 'Adjs', 'text', # ->adjList
12233 'Pseudo adjs', 'text', # ->pseudoAdjList
12234 'Unknowns', 'text', # ->unknownWordList
12235 );
12236  
12237 my $slWidget = $self->addSimpleList($grid, undef, \@columnList,
12238 1, 12, 2, 9);
12239  
12240 # Create a hash to link lines in the simple list to objects in the monitored objects list,
12241 # in the form
12242 # $objHash{line_number} = blessed_reference_of_monitored_object
12243 # Each time the simple list is refreshed, the hash is updated
12244 %objHash = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12245  
12246 # Add buttons
12247 my $button = $self->addButton($grid,
12248 'Unmonitor',
12249 'Delete the selected monitored object',
12250 undef,
12251 1, 3, 9, 10,
12252 TRUE); # Irreversible
12253 $button->signal_connect('clicked' => sub {
12254  
12255 my ($index, $lineRef, $obj, $cmd, $match, $count);
12256  
12257 ($index) = $slWidget->get_selected_indices();
12258 if (defined $index) {
12259  
12260 $obj = $objHash{$index};
12261  
12262 if ($charObj) { # Check there is a current character profile
12263  
12264 # Find the object's position in the monitored objects list maintained by the
12265 # character profile (which may possibly have changed, since the simple list
12266 # was last updated)
12267 $count = -1;
12268 foreach my $element ($charObj->monitorObjList) {
12269  
12270 $count++;
12271  
12272 if ($element eq $obj) {
12273  
12274 $match = $count;
12275 }
12276 }
12277  
12278 if (defined $match) {
12279  
12280 # Unmonitor the object. The ';unmonitortobject' command lists objects
12281 # starting from 1, not 0 (so we must add 1 to $match)
12282 $self->session->pseudoCmd(
12283 'unmonitorobject ' . ($match + 1),
12284 $self->pseudoCmdMode,
12285 );
12286  
12287 %objHash = $self->objects2Tab_refreshList(
12288 $slWidget,
12289 scalar (@columnList / 2),
12290 $charObj,
12291 );
12292 }
12293 }
12294 }
12295 });
12296  
12297 my $button2 = $self->addButton($grid, 'Edit...', 'Edit the monitored object', undef,
12298 3, 5, 9, 10);
12299 $button2->signal_connect('clicked' => sub {
12300  
12301 my ($index, $obj, $childWinObj);
12302  
12303 ($index) = $slWidget->get_selected_indices();
12304 if (defined $index) {
12305  
12306 $obj = $objHash{$index};
12307  
12308 # Open an 'edit' window for the monitored object (the same 'edit' window is used for
12309 # both protected and monitored objects, at the moment)
12310 $childWinObj = $self->createFreeWin(
12311 'Games::Axmud::EditWin::Protect',
12312 $self,
12313 $self->session,
12314 'Edit monitored object \'' . $obj->noun . '\'',
12315 $obj,
12316 FALSE, # Not temporary
12317 );
12318  
12319 if ($childWinObj) {
12320  
12321 # When the 'edit' window closes, update the simple list
12322 $self->add_childDestroy(
12323 $childWinObj,
12324 'objects2Tab_refreshList',
12325 [$slWidget, (scalar @columnList / 2), $charObj],
12326 );
12327 }
12328 }
12329 });
12330  
12331 my $button3 = $self->addButton($grid,
12332 'Dump list',
12333 'Display the list of monitored objects in the \'main\' window',
12334 undef,
12335 8, 10, 9, 10);
12336 $button3->signal_connect('clicked' => sub {
12337  
12338 $self->session->pseudoCmd('listmonitorobject', $self->pseudoCmdMode);
12339  
12340 %objHash
12341 = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12342 });
12343  
12344 my $button4 = $self->addButton($grid,
12345 'Refresh list',
12346 'Refresh the list of monitored objects',
12347 undef,
12348 10, 12, 9, 10);
12349 $button4->signal_connect('clicked' => sub {
12350  
12351 # Refresh the simple list
12352 %objHash
12353 = $self->objects2Tab_refreshList($slWidget, scalar (@columnList / 2), $charObj);
12354  
12355 # If there is no current character profile (and we need one), the buttons (except for
12356 # the 'refresh list' button) must be insensitive
12357 if ($charObj) {
12358 $self->sensitiseWidgets($button, $button2);
12359 } else {
12360 $self->desensitiseWidgets($button, $button2);
12361 }
12362 });
12363  
12364 my $button5 = $self->addButton($grid,
12365 'Protect objects matching words:',
12366 'Protect objects matching this list of words',
12367 undef,
12368 1, 5, 10, 11,
12369 TRUE); # Irreversible
12370  
12371 my $entry = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12372 5, 12, 10, 11);
12373  
12374 $button5->signal_connect('clicked' => sub {
12375  
12376 my $wordString = $entry->get_text();
12377  
12378 if ($self->checkEntryIcon($entry)) {
12379  
12380 # Protect objects matching these words
12381 $self->session->pseudoCmd(
12382 'protectobject ' . $wordString,
12383 $self->pseudoCmdMode,
12384 );
12385  
12386 # Refresh the simple list and reset the entry boxes
12387 %objHash = $self->objects2Tab_refreshList(
12388 $slWidget,
12389 scalar(@columnList / 2),
12390 $charObj,
12391 );
12392  
12393 $self->resetEntryBoxes($entry);
12394 }
12395 });
12396  
12397 my $button6 = $self->addButton($grid,
12398 'Monitor objects matching words:',
12399 'Monitor objects matching this list of words',
12400 undef,
12401 1, 5, 11, 12,
12402 TRUE); # Irreversible
12403 my $entry2 = $self->addEntryWithIcon($grid, undef, 'string', 1, undef,
12404 5, 12, 11, 12);
12405 $button6->signal_connect('clicked' => sub {
12406  
12407 my $wordString = $entry2->get_text();
12408  
12409 if ($self->checkEntryIcon($entry2)) {
12410  
12411 # Monitor objects matching these words
12412 $self->session->pseudoCmd(
12413 'monitorobject ' . $wordString,
12414 $self->pseudoCmdMode,
12415 );
12416  
12417 # Refresh the simple list and reset the entry boxes
12418 %objHash = $self->objects2Tab_refreshList(
12419 $slWidget,
12420 scalar(@columnList / 2),
12421 $charObj,
12422 );
12423  
12424 $self->resetEntryBoxes($entry2);
12425 }
12426 });
12427  
12428 # Widgets can't be manipulated when this isn't a current profile (or a current task)
12429 if (! $self->currentFlag) {
12430  
12431 $button->set_sensitive(FALSE);
12432 $button2->set_sensitive(FALSE);
12433 $button3->set_sensitive(FALSE);
12434 $button4->set_sensitive(FALSE);
12435 $button5->set_sensitive(FALSE);
12436 $button6->set_sensitive(FALSE);
12437 $entry->set_sensitive(FALSE);
12438 $entry2->set_sensitive(FALSE);
12439 }
12440  
12441 # Tab complete
12442 return 1;
12443 }
12444  
12445 sub objects2Tab_refreshList {
12446  
12447 # Called by $self->objects2Tab to reset the GA::Obj::SimpleList
12448 #
12449 # Expected arguments
12450 # $slWidget - The GA::Obj::SimpleList
12451 # $columns - The number of columns in the list
12452 #
12453 # Optional arguments
12454 # $charObj - The character profile whose list of monitored objects we're showing.
12455 # If set to 'undef', it's because there is no current character and,
12456 # because we need one, we therefore show an empty list
12457 #
12458 # Return values
12459 # An empty hash on improper arguments
12460 # Otherwise, a hash which links lines in the simple list to the objects it contains
12461 # - which replaces the hash %objHash in $self->objects2Tab
12462  
12463 my ($self, $slWidget, $columns, $charObj, $check) = @_;
12464  
12465 # Local variables
12466 my (
12467 $count,
12468 @objList, @dataList,
12469 %emptyHash, %objHash,
12470 );
12471  
12472 # Check for improper arguments
12473 if (! defined $slWidget || ! defined $columns || defined $check) {
12474  
12475 $axmud::CLIENT->writeImproper($self->_objClass . '->objects2Tab_refreshList', @_);
12476 return %emptyHash;
12477 }
12478  
12479 # Don't display anything if there is no specified character profile
12480 if (! $charObj) {
12481  
12482 $self->resetListData($slWidget, [], $columns);
12483  
12484 } else {
12485  
12486 # Import the list of monitored objects
12487 @objList = $charObj->monitorObjList;
12488  
12489 # Refresh the simple list, and create a new hash of objects linked to the line they
12490 # appear on
12491 $count = -1;
12492  
12493 # Compile the simple list data
12494 foreach my $obj (@objList) {
12495  
12496 $count++;
12497 push (@dataList,
12498 join(' ', $obj->categoryList),
12499 $obj->noun,
12500 join(' ', $obj->otherNounList),
12501 join(' ', $obj->adjList),
12502 join(' ', $obj->pseudoAdjList),
12503 join(' ', $obj->unknownWordList),
12504 );
12505  
12506 $objHash{$count} = $obj;
12507 }
12508  
12509 # Reset the simple list
12510 $self->resetListData($slWidget, [@dataList], $columns);
12511 }
12512  
12513 return %objHash;
12514 }
12515  
12516 # Shared tabs (shared by GA::EditWin::Generic::ModelObj and GA::PrefWin::Search)
12517  
12518 sub openChildEditWin {
12519  
12520 # Opens an 'edit' window for a different world model object (e.g. after clicking the 'Edit'
12521 # button on one of the 'Family' tabs)
12522 #
12523 # Expected arguments
12524 # $number - The number of the world model object for which to open an 'edit' window
12525 #
12526 # Return values
12527 # 'undef' on improper arguments or if the model object doesn't seem to exist
12528 # 1 otherwise
12529  
12530 my ($self, $number, $check) = @_;
12531  
12532 # Local variables
12533 my $obj;
12534  
12535 # Check for improper arguments
12536 if (! defined $number || defined $check) {
12537  
12538 return $axmud::CLIENT->writeImproper($self->_objClass . '->openChildEditWin', @_);
12539 }
12540  
12541 # Check that the object really exists
12542 if (! $self->session->worldModelObj->ivExists('modelHash', $number)) {
12543  
12544 return undef;
12545  
12546 } else {
12547  
12548 $obj = $self->session->worldModelObj->ivShow('modelHash', $number);
12549 }
12550  
12551 # Open up an 'edit' window to edit the object
12552 $self->createFreeWin(
12553 'Games::Axmud::EditWin::ModelObj::' . ucfirst($obj->category),
12554 $self,
12555 $self->session,
12556 'Edit ' . $obj->category . ' model object #' . $obj->number,
12557 $obj,
12558 FALSE, # Not temporary,
12559 );
12560  
12561 return 1;
12562 }
12563  
12564 # Shared tabs (shared by GA::EditWin::Interface::Active and GA::EditWin::Interface::Trigger,
12565 # etc
12566  
12567 sub triggerAttributesTab {
12568  
12569 # TriggerAttributes tab
12570 #
12571 # Expected arguments
12572 # (none besides $self)
12573 #
12574 # Return values
12575 # 'undef' on improper arguments
12576 # 1 otherwise
12577  
12578 my ($self, $check) = @_;
12579  
12580 # Check for improper arguments
12581 if (defined $check) {
12582  
12583 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributesTab', @_);
12584 }
12585  
12586 # Tab setup
12587 # Create a notebook within the main one, so that we have two rows of tabs
12588 my $innerNotebook = $self->addInnerNotebookTab('_Attributes', $self->notebook);
12589  
12590 # Add tabs to the inner notebook
12591 $self->triggerAttributes1Tab($innerNotebook);
12592 $self->triggerAttributes2Tab($innerNotebook);
12593  
12594 return 1;
12595 }
12596  
12597 sub triggerAttributes1Tab {
12598  
12599 # TriggerAttributes1Tab tab
12600 #
12601 # Expected arguments
12602 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
12603 #
12604 # Return values
12605 # 'undef' on improper arguments
12606 # 1 otherwise
12607  
12608 my ($self, $innerNotebook, $check) = @_;
12609  
12610 # Check for improper arguments
12611 if (! defined $innerNotebook || defined $check) {
12612  
12613 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributes1Tab', @_);
12614 }
12615  
12616 # Tab setup
12617 my $grid = $self->addTab('Page _1', $innerNotebook);
12618  
12619 # Trigger attributes
12620 $self->addLabel($grid, '<b>Trigger attributes</b>',
12621 0, 12, 0, 1);
12622  
12623 # Left column
12624 $self->useCheckButton(
12625 $grid,
12626 'Ignore the trigger response (e.g. just apply a style)',
12627 'ignore_response',
12628 TRUE,
12629 1, 6, 1, 2);
12630 $self->useCheckButton($grid, 'Ignore case', 'ignore_case', TRUE,
12631 1, 6, 2, 3);
12632 $self->useCheckButton($grid, 'Keep checking triggers after a match', 'keep_checking', TRUE,
12633 1, 6, 3, 4);
12634 $self->useCheckButton($grid, 'Splitter trigger', 'splitter', TRUE,
12635 1, 6, 4, 5);
12636 $self->useCheckButton(
12637 $grid, 'Split after matching pattern, not before', 'split_after', TRUE,
12638 1, 6, 5, 6);
12639 $self->useCheckButton(
12640 $grid, 'Split line multiple times, if multiple matches', 'keep_splitting', TRUE,
12641 1, 6, 6, 7);
12642 $self->useCheckButton($grid, 'Rewriter trigger', 'rewriter', TRUE,
12643 1, 6, 7, 8);
12644 $self->useCheckButton($grid, 'Rewrite every matching part of line', 'rewrite_global', TRUE,
12645 1, 6, 8, 9);
12646  
12647 # Right column
12648 my $checkButton = $self->useCheckButton(
12649 $grid, 'Only fire in session\'s default pane', 'default_pane', TRUE,
12650 7, 12, 1, 2);
12651 $self->addLabel($grid, 'Fire in named pane',
12652 7, 9, 2, 3);
12653 my $entry = $self->addEntry($grid, undef, TRUE,
12654 9, 12, 2, 3,
12655 8, 8);
12656 $entry->set_text($self->editObj->ivShow('attribHash', 'pane_name'));
12657 if ($entry->get_text()) {
12658  
12659 $checkButton->set_sensitive(FALSE);
12660 }
12661  
12662 $entry->signal_connect('changed' => sub {
12663  
12664 my $text = $entry->get_text();
12665  
12666 # If the user has emptied the entry box, set the attribute to an empty string
12667 if (! $text) {
12668  
12669 $self->ivAdd('attribHash', 'pane_name', '');
12670 $checkButton->set_sensitive(TRUE);
12671  
12672 # Otherwise set the attribute to the specified value
12673 } else {
12674  
12675 $self->ivAdd('attribHash', 'pane_name', $text);
12676 $checkButton->set_active(FALSE);
12677 $checkButton->set_sensitive(FALSE);
12678 }
12679 });
12680  
12681 $self->useCheckButton($grid, 'Require a prompt to fire', 'need_prompt', TRUE,
12682 7, 12, 3, 4);
12683 $self->useCheckButton($grid, 'Require a login to fire', 'need_login', TRUE,
12684 7, 12, 4, 5);
12685 $self->useCheckButton($grid, 'Omit (gag) from output', 'gag', TRUE,
12686 7, 12, 5, 6);
12687 $self->useCheckButton($grid, 'Omit (gag) from logfile', 'gag_log', TRUE,
12688 7, 12, 6, 7);
12689 $self->useCheckButton($grid, 'Temporary trigger', 'temporary', TRUE,
12690 7, 12, 7, 8);
12691 $self->addLabel($grid, 'Cooldown (in seconds)',
12692 7, 9, 8, 9);
12693 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
12694 9, 12, 8, 9,
12695 8, 8);
12696  
12697 # Tab complete
12698 return 1;
12699 }
12700  
12701 sub triggerAttributes2Tab {
12702  
12703 # TriggerAttributes2Tab tab
12704 #
12705 # Expected arguments
12706 # $innerNotebook - The Gtk3::Notebook object inside $self->notebook
12707 #
12708 # Return values
12709 # 'undef' on improper arguments
12710 # 1 otherwise
12711  
12712 my ($self, $innerNotebook, $check) = @_;
12713  
12714 # Local variables
12715 my (@grpNumList, @comboList, @comboList2);
12716  
12717 # Check for improper arguments
12718 if (! defined $innerNotebook || defined $check) {
12719  
12720 return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerAttributes2Tab', @_);
12721 }
12722  
12723 # Tab setup
12724 my $grid = $self->addTab('Page _2', $innerNotebook);
12725  
12726 # (Need just a little extra space to make everything fit)
12727 $grid->set_column_spacing($self->spacingPixels - 1);
12728 $grid->set_row_spacing($self->spacingPixels - 1);
12729  
12730 # Trigger styles
12731 $self->addLabel($grid, '<b>Trigger attributes (cont.)</b>',
12732 0, 12, 0, 1);
12733  
12734 # Top left
12735 my ($group, $radioButton) = $self->useRadioButton(
12736 $grid, undef,
12737 'Mode 0', # Radio button name
12738 'style_mode', # Attribute to set
12739 0, # Attribute set to this value when toggled
12740 TRUE, # Sensitive widget
12741 1, 2, 1, 2);
12742 $self->addLabel($grid, 'Don\'t apply styles',
12743 2, 5, 1, 2);
12744  
12745 ($group, $radioButton) = $self->useRadioButton(
12746 $grid, $group, 'Mode -1', 'style_mode', -1, TRUE,
12747 1, 2, 2, 3);
12748 $self->addLabel($grid, 'Apply style to whole line',
12749 2, 5, 2, 3);
12750  
12751 # Top right
12752 ($group, $radioButton) = $self->useRadioButton(
12753 $grid, $group, 'Mode -2', 'style_mode', -2, TRUE,
12754 5, 7, 1, 2);
12755 $self->addLabel($grid, 'Apply style to matched text',
12756 7, 10, 1, 2);
12757  
12758 my ($group2, $radioButton2) = $self->useRadioButton(
12759 $grid, $group,
12760 'Mode n',
12761 'style_mode',
12762 -3, # Non-standard value; set to correct value by $self->saveChanges
12763 TRUE,
12764 5, 7, 2, 3);
12765 $self->addLabel($grid, 'Apply style to matched substring #:',
12766 7, 10, 2, 3);
12767 @grpNumList = (1, 2, 3, 4, 5, 6, 7, 8, 9);
12768 my $combo = $self->useComboBox(
12769 $grid,
12770 '_substr_num',
12771 \@grpNumList,
12772 'Select:',
12773 10, 12, 2, 3);
12774  
12775 if (
12776 $self->editObj->ivShow('attribHash', 'style_mode')
12777 && $self->editObj->ivShow('attribHash', 'style_mode') > 0
12778 ) {
12779 # Style mode is 1 or more, which corresponds to the radio button on the top-right
12780 $radioButton2->set_active(TRUE);
12781 $combo->set_active($self->editObj->ivShow('attribHash', 'style_mode'));
12782 }
12783  
12784 # Bottom left
12785 $self->addLabel($grid, '<u>Trigger style to apply:</u>',
12786 1, 12, 3, 4);
12787  
12788 $self->triggerAttributesTab_addRadioButtons($grid, 'Italics:', 'style_italics', 4);
12789 $self->triggerAttributesTab_addRadioButtons($grid, 'Underline:', 'style_underline', 5);
12790 $self->triggerAttributesTab_addRadioButtons($grid, 'Slow blink:', 'style_blink_slow', 6);
12791 $self->triggerAttributesTab_addRadioButtons($grid, 'Fast blink:', 'style_blink_fast', 7);
12792 $self->triggerAttributesTab_addRadioButtons($grid, 'Strike-through:', 'style_strike', 8);
12793 $self->triggerAttributesTab_addRadioButtons($grid, 'Link:', 'style_link', 9);
12794  
12795 # Bottom right
12796 push (@comboList, '');
12797 push (@comboList2, '');
12798 foreach my $tag ($axmud::CLIENT->constColourTagList) {
12799  
12800 push (@comboList, $tag);
12801 push (@comboList2, 'ul_' . $tag);
12802 }
12803  
12804 foreach my $tag ($axmud::CLIENT->constBoldColourTagList) {
12805  
12806 push (@comboList, $tag);
12807 push (@comboList2, 'UL_' . $tag);
12808 }
12809  
12810 $self->triggerAttributesTab_setColours(
12811 $grid,
12812 'Text colour',
12813 'style_text',
12814 \@comboList,
12815 3,
12816 );
12817  
12818 $self->triggerAttributesTab_setColours(
12819 $grid,
12820 'Underlay colour',
12821 'style_underlay',
12822 \@comboList2,
12823 7,
12824 );
12825  
12826 # Tab complete
12827 return 1;
12828 }
12829  
12830 sub triggerAttributesTab_addRadioButtons {
12831  
12832 # Called by $self->triggerAttributes2Tab to add radio buttons for setting an attribute
12833 #
12834 # Expected arguments
12835 # $grid - The Gtk3::Grid
12836 # $labelText - The label text to use (e.g. 'Italics')
12837 # $attrib - The attibute to set (e.g. 'style_italics')
12838 # $row - The Gtk3::Grid row on which the radio buttons are drawn
12839 #
12840 # Return values
12841 # 'undef' on improper arguments
12842 # 1 otherwise
12843  
12844 my ($self, $grid, $labelText, $attrib, $row, $check) = @_;
12845  
12846 # Check for improper arguments
12847 if (
12848 ! defined $grid || ! defined $labelText || ! defined $attrib || ! defined $row
12849 || defined $check
12850 ) {
12851 return $axmud::CLIENT->writeImproper(
12852 $self->_objClass . '->triggerAttributesTab_addRadioButtons',
12853 @_,
12854 );
12855 }
12856  
12857 $self->addLabel($grid, $labelText,
12858 1, 2, $row, ($row + 1));
12859 my ($group, $radioButton) = $self->useRadioButton(
12860 $grid, undef,
12861 'Do not change', # Radio button name
12862 $attrib, # Attribute to set
12863 0, # Attribute set to this value when toggled
12864 TRUE, # Sensitive widget
12865 2, 4, $row, ($row + 1));
12866  
12867 ($group, $radioButton) = $self->useRadioButton(
12868 $grid, $group, 'Yes', $attrib, 1, TRUE,
12869 4, 5, $row, ($row + 1));
12870  
12871 ($group, $radioButton) = $self->useRadioButton(
12872 $grid, $group, 'No', $attrib, 2, TRUE,
12873 5, 6, $row, ($row + 1));
12874  
12875 return 1;
12876 }
12877  
12878 sub triggerAttributesTab_setColours {
12879  
12880 # Called by $self->triggerAttributes2Tab to add radio buttons for setting a colour attribute
12881 #
12882 # Expected arguments
12883 # $grid - The Gtk3::Grid
12884 # $labelText - The label text to use (e.g. 'Text colour')
12885 # $attrib - The attibute to set (e.g. 'style_text')
12886 # $comboListRef - Reference to a list of standard colour tags to display in a combobox
12887 # $row - The Gtk3::Grid row on which the radio buttons are drawn
12888 #
12889 # Return values
12890 # 'undef' on improper arguments
12891 # 1 otherwise
12892  
12893 my ($self, $grid, $labelText, $attrib, $comboListRef, $row, $check) = @_;
12894  
12895 # Check for improper arguments
12896 if (
12897 ! defined $grid || ! defined $labelText || ! defined $attrib || ! defined $row
12898 || defined $check
12899 ) {
12900 return $axmud::CLIENT->writeImproper(
12901 $self->_objClass . '->triggerAttributesTab_setColours',
12902 @_,
12903 );
12904 }
12905  
12906 $self->addLabel($grid, $labelText,
12907 7, 9, $row, ($row + 1));
12908 my $entry = $self->addEntry($grid, undef, FALSE,
12909 9, 12, $row, ($row + 1));
12910 $entry->set_text($self->editObj->ivShow('attribHash', $attrib));
12911  
12912 my $comboBox = $self->addComboBox($grid, undef, $comboListRef, '',
12913 TRUE, # No 'undef' value used
12914 7, 10, ($row + 1), ($row + 2));
12915  
12916 my $button = $self->addButton(
12917 $grid,
12918 'Set',
12919 'Set this standard colour tag as the ' . lc($labelText),
12920 undef,
12921 10, 12, ($row + 1), ($row + 2));
12922 $button->signal_connect('clicked' => sub {
12923  
12924 my $text = $comboBox->get_active_text();
12925  
12926 # If the user has selected the empty line at the top, set the attribute to an empty
12927 # string
12928 if (! $text) {
12929  
12930 $self->ivAdd('attribHash', $attrib, '');
12931  
12932 # Otherwise set the attribute to the specified value
12933 } else {
12934  
12935 $self->ivAdd('attribHash', $attrib, $text);
12936 $comboBox->set_active(0);
12937 }
12938  
12939 $entry->set_text($self->ivShow('attribHash', $attrib));
12940 });
12941  
12942 $self->addLabel($grid, 'xterm tag',
12943 7, 8, ($row + 2), ($row + 3));
12944 my $entry2 = $self->addEntryWithIcon($grid, undef, \&triggerAttributesTab_checkXTerm, 0, 0,
12945 8, 10, ($row + 2), ($row + 3));
12946 $entry2->set_icon_from_stock('secondary', 'gtk-yes'); # (Empty box is valid)
12947 my $button2 = $self->addButton(
12948 $grid,
12949 'Set',
12950 'Set this xterm tag as the ' . lc($labelText),
12951 undef,
12952 10, 12, ($row + 2), ($row + 3));
12953 $button2->signal_connect('clicked' => sub {
12954  
12955 my $text;
12956  
12957 if ($self->checkEntryIcon($entry2)) {
12958  
12959 $text = $entry2->get_text();
12960  
12961 # If the user has emptied the entry box, set the attribute to an empty string
12962 if (! $text) {
12963  
12964 $self->ivAdd('attribHash', $attrib, '');
12965  
12966 # Otherwise set the attribute to the specified value
12967 } else {
12968  
12969 $self->ivAdd('attribHash', $attrib, $text);
12970 }
12971  
12972 $entry->set_text($self->ivShow('attribHash', $attrib));
12973 $entry2->set_text('');
12974 }
12975 });
12976  
12977 $self->addLabel($grid, 'RGB tag',
12978 7, 8, ($row + 3), ($row + 4));
12979 my $entry3 = $self->addEntryWithIcon($grid, undef, \&triggerAttributesTab_checkRGB, 0, 0,
12980 8, 10, ($row + 3), ($row + 4));
12981 $entry3->set_icon_from_stock('secondary', 'gtk-yes'); # (Empty box is valid)
12982 my $button3 = $self->addButton(
12983 $grid,
12984 'Set',
12985 'Set this RGB tag as the ' . lc($labelText),
12986 undef,
12987 10, 12, ($row + 3), ($row + 4));
12988 $button3->signal_connect('clicked' => sub {
12989  
12990 my $text;
12991  
12992 if ($self->checkEntryIcon($entry3)) {
12993  
12994 $text = $entry3->get_text();
12995  
12996 # If the user has emptied the entry box, set the attribute to an empty string
12997 if (! $text) {
12998  
12999 $self->ivAdd('attribHash', $attrib, '');
13000  
13001 # Otherwise set the attribute to the specified value
13002 } else {
13003  
13004 $self->ivAdd('attribHash', $attrib, $text);
13005 }
13006  
13007 $entry->set_text($self->ivShow('attribHash', $attrib));
13008 $entry3->set_text('');
13009 }
13010 });
13011  
13012 return 1;
13013 }
13014  
13015 sub triggerAttributesTab_checkXTerm {
13016  
13017 # Called by $self->triggerAttributes2Tab to check the text in the Gtk3::Entry
13018 #
13019 # Expected arguments
13020 # $text - The contents of the Gtk3::Entry
13021 #
13022 # Return values
13023 # 'undef' on improper arguments or if $text is invalid
13024 # 1 if $text is valid
13025  
13026 my ($self, $text, $check) = @_;
13027  
13028 # Check for improper arguments
13029 if (! defined $text || defined $check) {
13030  
13031 return $axmud::CLIENT->writeImproper(
13032 $self->_objClass . '->triggerAttributesTab_checkXTerm',
13033 @_,
13034 );
13035 }
13036  
13037 # $text can be an xterm colour tag (in the range 'x0' to 'x255', or 'ux0' to 'ux255'; xterm
13038 # tags are case-insensitive
13039 # An empty entry box is also a valid value
13040 if (! $text) {
13041  
13042 return 1;
13043  
13044 } elsif ($text =~ m/^u?x([0-9]+)$/i) {
13045  
13046 # (Don't permit 'x000005', but do permit 'x005' or 'x5')
13047 if ($1 >= 0 && $1 <= 255 && length ($1) <= 3) {
13048 return 1;
13049 } else {
13050 return undef;
13051 }
13052  
13053 } else {
13054  
13055 return undef;
13056 }
13057 }
13058  
13059 sub triggerAttributesTab_checkRGB {
13060  
13061 # Called by $self->triggerAttributes2Tab to check the text in the Gtk3::Entry
13062 #
13063 # Expected arguments
13064 # $text - The contents of the Gtk3::Entry
13065 #
13066 # Return values
13067 # 'undef' on improper arguments or if $text is invalid
13068 # 1 if $text is valid
13069  
13070 my ($self, $text, $check) = @_;
13071  
13072 # Check for improper arguments
13073 if (! defined $text || defined $check) {
13074  
13075 return $axmud::CLIENT->writeImproper(
13076 $self->_objClass . '->triggerAttributesTab_checkRGB',
13077 @_,
13078 );
13079 }
13080  
13081 # $text can be an RGB colour tag (in the form '#xxxxxx' or '#uxxxxxx' where x is any
13082 # character in the range A-F, a-f, 0-9; RGB tags are case-insensitive
13083 # An empty entry box is also a valid value
13084 if (! $text) {
13085  
13086 return 1;
13087  
13088 } elsif ($text =~ m/^u?\#[A-F0-9]{6}$/i) {
13089  
13090 return 1;
13091  
13092 } else {
13093  
13094 return undef;
13095 }
13096 }
13097  
13098 sub aliasAttributesTab {
13099  
13100 # AliasAttributes tab
13101 #
13102 # Expected arguments
13103 # (none besides $self)
13104 #
13105 # Return values
13106 # 'undef' on improper arguments
13107 # 1 otherwise
13108  
13109 my ($self, $check) = @_;
13110  
13111 # Check for improper arguments
13112 if (defined $check) {
13113  
13114 return $axmud::CLIENT->writeImproper($self->_objClass . '->aliasAttributesTab', @_);
13115 }
13116  
13117 # Tab setup
13118 my $grid = $self->addTab('_Attributes', $self->notebook);
13119  
13120 # Alias attributes
13121 $self->addLabel($grid, '<b>Alias attributes</b>',
13122 0, 12, 0, 1);
13123  
13124 # Left column
13125 $self->useCheckButton($grid, 'Ignore case', 'ignore_case', TRUE,
13126 1, 6, 1, 2);
13127 $self->useCheckButton($grid, 'Keep checking aliases after a match', 'keep_checking', TRUE,
13128 1, 6, 2, 3);
13129  
13130 # Right column
13131 $self->useCheckButton($grid, 'Temporary alias', 'temporary', TRUE,
13132 7, 12, 1, 2);
13133 $self->addLabel($grid, 'Cooldown (in seconds)',
13134 7, 9, 2, 3);
13135 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13136 9, 12, 2, 3,
13137 8, 8);
13138  
13139 # Tab complete
13140 return 1;
13141 }
13142  
13143 sub macroAttributesTab {
13144  
13145 # MacroAttributes tab
13146 #
13147 # Expected arguments
13148 # (none besides $self)
13149 #
13150 # Return values
13151 # 'undef' on improper arguments
13152 # 1 otherwise
13153  
13154 my ($self, $check) = @_;
13155  
13156 # Check for improper arguments
13157 if (defined $check) {
13158  
13159 return $axmud::CLIENT->writeImproper($self->_objClass . '->macroAttributesTab', @_);
13160 }
13161  
13162 # Tab setup
13163 my $grid = $self->addTab('_Attributes', $self->notebook);
13164  
13165 # Macro attributes
13166 $self->addLabel($grid, '<b>Macro attributes</b>',
13167 0, 12, 0, 1);
13168  
13169 # Left column
13170 $self->useCheckButton($grid, 'Temporary macro', 'temporary', TRUE,
13171 1, 6, 1, 2);
13172  
13173 # Right column
13174 $self->addLabel($grid, 'Cooldown (in seconds)',
13175 7, 9, 1, 2);
13176 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13177 9, 12, 1, 2,
13178 8, 8);
13179  
13180 # Tab complete
13181 return 1;
13182 }
13183  
13184 sub timerAttributesTab {
13185  
13186 # TimerAttributes tab
13187 #
13188 # Expected arguments
13189 # (none besides $self)
13190 #
13191 # Return values
13192 # 'undef' on improper arguments
13193 # 1 otherwise
13194  
13195 my ($self, $check) = @_;
13196  
13197 # Check for improper arguments
13198 if (defined $check) {
13199  
13200 return $axmud::CLIENT->writeImproper($self->_objClass . '->timerAttributesTab', @_);
13201 }
13202  
13203 # Tab setup
13204 my $grid = $self->addTab('_Timers', $self->notebook);
13205  
13206 # Timer attributes
13207 $self->addLabel($grid, '<b>Timer attributes</b>',
13208 0, 12, 0, 1);
13209  
13210 # Left column
13211 $self->addLabel($grid, 'Repeat count (-1 unlimited)',
13212 1, 4, 1, 2);
13213 $self->useEntryWithIcon($grid, 'count', 'int', -1, undef,
13214 4, 6, 1, 2);
13215 $self->addLabel($grid, 'Initial delay (0 for no delay)',
13216 1, 4, 2, 3);
13217 $self->useEntryWithIcon($grid, 'initial_delay', 'float', 0, undef,
13218 4, 6, 2, 3);
13219 $self->useCheckButton($grid, 'Random delays', 'random_delay', TRUE,
13220 1, 6, 3, 4);
13221  
13222 # Right column
13223 $self->addLabel($grid, 'Minimum random delay',
13224 7, 10, 1, 2);
13225 $self->useEntryWithIcon($grid, 'random_min', 'float', 0, undef,
13226 10, 12, 1, 2);
13227 $self->useCheckButton($grid, 'Start after login', 'wait_login', TRUE,
13228 7, 12, 2, 3);
13229 $self->useCheckButton($grid, 'Temporary timer', 'temporary', TRUE,
13230 7, 12, 3, 4);
13231  
13232 # Tab complete
13233 return 1;
13234 }
13235  
13236 sub hookAttributesTab {
13237  
13238 # HookAttributes tab
13239 #
13240 # Expected arguments
13241 # (none besides $self)
13242 #
13243 # Return values
13244 # 'undef' on improper arguments
13245 # 1 otherwise
13246  
13247 my ($self, $check) = @_;
13248  
13249 # Check for improper arguments
13250 if (defined $check) {
13251  
13252 return $axmud::CLIENT->writeImproper($self->_objClass . '->hookAttributesTab', @_);
13253 }
13254  
13255 # Tab setup
13256 my $grid = $self->addTab('_Attributes', $self->notebook);
13257  
13258 # Hook attributes
13259 $self->addLabel($grid, '<b>Hook attributes</b>',
13260 0, 12, 0, 1);
13261  
13262 # Left column
13263 $self->useCheckButton($grid, 'Temporary hook', 'temporary', TRUE,
13264 1, 6, 1, 2);
13265  
13266 # Right column
13267 $self->addLabel($grid, 'Cooldown (in seconds)',
13268 7, 9, 1, 2);
13269 $self->useEntryWithIcon($grid, 'cooldown', 'float', 0, undef,
13270 9, 12, 1, 2,
13271 8, 8);
13272  
13273 # Tab complete
13274 return 1;
13275 }
13276  
13277 # 'dialogue' windows for simple scalars, lists and hashes
13278  
13279 sub promptScalar {
13280  
13281 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a scalar value
13282 # If the user supplies a value, sets the IV then closes the window
13283 #
13284 # Operates in two modes
13285 # Mode 1 - the supplied IV is a scalar, i.e.
13286 # $self->editObj->$iv = 'some_scalar_value'
13287 # $self->editHash->$iv = 'some_scalar_value'
13288 # - the value supplied by the user is saved in place of 'some_scalar_value'
13289 #
13290 # Mode 2 - the supplied IV is a hash, i.e.
13291 # $self->editObj->$iv = {some_hash}
13292 # $self->editHash->$iv = {some_hash}
13293 # - the calling function also supplies a key in {some_hash}
13294 # - the value supplied by the user is saved as the key's corresponding value
13295 #
13296 # Expected arguments
13297 # $iv - The IV to set in $self->editHash
13298 #
13299 # Optional arguments
13300 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
13301 # $deRefFlag
13302 # - In mode 1, 'undef'; in mode 2, TRUE if the key's corresponding value in
13303 # {some_hash} is stored as a scalar reference (only cage masks do this); FALSE
13304 # (or 'undef') if it's stored as a simple scalar
13305 # $slWidget
13306 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleList in which the
13307 # IV's data is being displayed (if specified, the simple list is updated when
13308 # this window is closed)
13309 # $readOnlyFlag
13310 # - If set to TRUE, the scalar is read-only (so can't be edited); otherwise set
13311 # to FALSE (or 'undef')
13312 # $callFunc
13313 # - If specified, $self->$funcName is called when the IV is updated instead of the
13314 # usual call to $self->updateListDataWithKey (useful if we don't want the
13315 # simple list sorted alphabetically, as normally happens); otherwise set to
13316 # 'undef'
13317 # @callFuncArgs
13318 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
13319 # list
13320 #
13321 # Return values
13322 # 'undef' on improper arguments
13323 # 1 otherwise
13324  
13325 my ($self, $iv, $key, $deRefFlag, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
13326  
13327 # Local variables
13328 my (
13329 $title, $labelText, $outerHashRef, $value, $response,
13330 %outerHash,
13331 );
13332  
13333 # Check for improper arguments
13334 if (! defined $iv) {
13335  
13336 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptScalar', @_);
13337 }
13338  
13339 # Set the window title
13340 if ($readOnlyFlag) {
13341 $title = 'View Scalar';
13342 } else {
13343 $title = 'Edit Scalar';
13344 }
13345  
13346 # Show the 'dialogue' window
13347 my $dialogueWin;
13348 if (! $readOnlyFlag) {
13349  
13350 $dialogueWin = Gtk3::Dialog->new(
13351 $title,
13352 $self->winWidget,
13353 [qw/modal destroy-with-parent/],
13354 'gtk-cancel' => 'reject',
13355 'gtk-ok' => 'accept',
13356 );
13357  
13358 } else {
13359  
13360 $dialogueWin = Gtk3::Dialog->new(
13361 $title,
13362 $self->winWidget,
13363 [qw/modal destroy-with-parent/],
13364 'gtk-ok' => 'accept',
13365 );
13366 }
13367  
13368 $dialogueWin->set_position('center-always');
13369 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
13370  
13371 $dialogueWin->signal_connect('delete-event' => sub {
13372  
13373 $dialogueWin->destroy();
13374 $self->restoreFocus();
13375  
13376 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
13377 # the window is visibly closed)
13378 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
13379 });
13380  
13381 # Add widgets to the 'dialogue' window
13382 my $vBox = $dialogueWin->get_content_area();
13383 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
13384 # Gtk3::VBox on the right, into which we put everything
13385 my $vBox2 = $self->addDialogueIcon($vBox);
13386  
13387 # Create a label, which will shortly show which IV is being edited (a second label,
13388 # $undefLabel, is sometimes used immediately below it)
13389 my $label = Gtk3::Label->new();
13390 $label->set_alignment(0, 0.5);
13391  
13392 # Create an entry, in which the user supplies a new value
13393 my $entry = Gtk3::Entry->new;
13394 if ($readOnlyFlag) {
13395  
13396 $entry->set_state('insensitive');
13397 }
13398  
13399 # Set the contents of the entry box, and prepare the label text
13400 if (! defined $key) {
13401  
13402 # Mode 1 - edit the value of $self->editObj->$iv or $self->editHash->$iv
13403 $labelText = 'Value of IV \'' . $iv . '\'';
13404  
13405 # If the IV hasn't yet been edited, use the original value
13406 if (! $self->ivExists('editHash', $iv)) {
13407  
13408 if (defined $self->editObj->{$iv}) {
13409  
13410 # Put the current value in the entry box
13411 $entry->set_text($self->editObj->{$iv});
13412  
13413 } else {
13414  
13415 # Add more text to the label, to show that the value is 'undef'
13416 $labelText .= ' <i>(currently \'undef\')</i>';
13417 }
13418  
13419 # If the IV has been edited, use the edited value
13420 } else {
13421  
13422 # Use an edited value
13423 if (defined $self->ivShow('editHash', $iv)) {
13424  
13425 $entry->set_text($self->ivShow('editHash', $iv));
13426  
13427 } else {
13428  
13429 # Add more text to the label, to show that the value is 'undef'
13430 $labelText .= ' <i>(currently \'undef\')</i>';
13431 }
13432 }
13433  
13434 } else {
13435  
13436 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
13437 # stored as $self->editObj->$iv or $self->editHash->$iv
13438 $labelText = 'Value of key \'' . $key . '\' stored in IV \'' . $iv . '\'';
13439  
13440 # Get a copy of the hash being edited
13441 if (! $self->ivExists('editHash', $iv)) {
13442  
13443 %outerHash = $self->editObj->$iv;
13444  
13445 # If the IV has been edited, use the edited hash
13446 } else {
13447  
13448 $outerHashRef = $self->ivShow('editHash', $iv);
13449 %outerHash = %$outerHashRef;
13450 }
13451  
13452 if (exists $outerHash{$key}) {
13453  
13454 if (defined $outerHash{$key}) {
13455  
13456 # Put the current value of the key-value pair in the entry box
13457 $value = $outerHash{$key};
13458 if ($deRefFlag) {
13459  
13460 # Cage masks: $value is a scalar reference
13461 $entry->set_text($$value);
13462  
13463 } else {
13464  
13465 # Everything else: $value is a normal scalar
13466 $entry->set_text($value);
13467 }
13468  
13469 } else {
13470  
13471 # Add more text to the label, to show that the value is 'undef'
13472 $labelText .= ' <i>(currently \'undef\')</i>';
13473 }
13474 }
13475 }
13476  
13477 # Set the label text
13478 $label->set_markup($labelText);
13479  
13480 # Pack the label and entry box
13481 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
13482 $vBox2->pack_start($entry, TRUE, TRUE, $self->spacingPixels);
13483  
13484 # Optionally add a button strip in the lower area, containing a single button
13485 if (! $readOnlyFlag) {
13486  
13487 my $hBox = Gtk3::HBox->new(FALSE, 0);
13488 $vBox2->pack_start($hBox, TRUE, TRUE, $self->spacingPixels);
13489  
13490 # Create the 'use undef' button
13491 my $button3 = Gtk3::Button->new('Use \'undef\' value');
13492 $hBox->pack_end($button3, FALSE, FALSE, $self->spacingPixels);
13493  
13494 $button3->signal_connect('clicked' => sub {
13495  
13496 # Store an 'undef' scalar value
13497  
13498 # Mode 1 - edit the scalar stored in $self->editObj->$iv or $self->editHash->$iv
13499 if (! defined $key) {
13500  
13501 $self->ivAdd('editHash', $iv, undef);
13502  
13503 # Update the simple list displayed in the parent window, if a list was specified
13504 if ($slWidget) {
13505  
13506 $self->updateListDataWithKey($slWidget, $iv, undef);
13507 }
13508  
13509 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
13510 # stored as $self->editObj->$iv or $self->editHash->$iv
13511 } else {
13512  
13513 # Update the hash stored in the IV with a new key-value pair. The key is $key,
13514 # the corresponding value is the new scalar
13515 $outerHash{$key} = undef;
13516  
13517 # Store the modified outer hash as the IV
13518 $self->ivAdd('editHash', $iv, \%outerHash);
13519  
13520 # Update the simple list displayed in the parent window, if a list was specified
13521 if ($slWidget) {
13522  
13523 $self->updateListDataWithKey($slWidget, $key, undef);
13524 }
13525 }
13526  
13527 # Call a function to re-display the simple list in the parent window, if a function
13528 # was specified
13529 if ($callFunc) {
13530  
13531 $self->$callFunc(@callFuncArgs);
13532 }
13533  
13534 # Close the window and return success value
13535 $dialogueWin->destroy();
13536 $self->restoreFocus();
13537  
13538 # (In case TTS is being used and another 'dialogue' window is about to open, make
13539 # sure the window is visibly closed)
13540 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
13541  
13542 return 1;
13543 });
13544 }
13545  
13546 # Widget drawing complete
13547 $vBox->show_all();
13548  
13549 # Get the response
13550 $response = $dialogueWin->run();
13551 if ($response eq 'accept') {
13552  
13553 my $scalar;
13554  
13555 # Don't save anything for read-only values
13556 if (! $readOnlyFlag) {
13557  
13558 $scalar = $entry->get_text();
13559  
13560 # Mode 1 - edit the value stored in of $self->editObj->$iv or $self->editHash->$iv
13561 if (! defined $key) {
13562  
13563 # Store the edited scalar
13564 $self->ivAdd('editHash', $iv, $scalar);
13565  
13566 # Update the simple list displayed in the parent window, if a list was specified
13567 if ($slWidget) {
13568  
13569 $self->updateListDataWithKey($slWidget, $iv, $scalar);
13570 }
13571  
13572 # Mode 2 - edit the scalar stored in a key-value pair; the pair is in the hash
13573 # stored as $self->editObj->$iv or $self->editHash->$iv
13574 } else {
13575  
13576 # Update the hash stored in the IV with a new key-value pair. The key is $key,
13577 # the corresponding value is the new scalar
13578 if ($deRefFlag) {
13579  
13580 # Cage masks: $value is a scalar reference
13581 $value = \$scalar;
13582  
13583 } else {
13584  
13585 # Everything else: $value is a normal scalar
13586 $value = $scalar;
13587 }
13588  
13589 $outerHash{$key} = $value;
13590  
13591 # Store the modified outer hash as the IV
13592 $self->ivAdd('editHash', $iv, \%outerHash);
13593  
13594 # Update the simple list displayed in the parent window, if a list was specified
13595 if ($slWidget) {
13596  
13597 $self->updateListDataWithKey($slWidget, $key, $value);
13598 }
13599 }
13600  
13601 # Call a function to re-display the simple list in the parent window, if a function
13602 # was specified
13603 if ($callFunc) {
13604  
13605 $self->$callFunc(@callFuncArgs);
13606 }
13607 }
13608 }
13609  
13610 # Destroy the window
13611 $dialogueWin->destroy();
13612 $self->restoreFocus();
13613  
13614 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
13615 # window is visibly closed)
13616 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptScalar');
13617  
13618 # Operation complete
13619 return 1;
13620 }
13621  
13622 sub promptList {
13623  
13624 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a list of values
13625 # If the user supplies any values, sets the IV then closes the window
13626 #
13627 # Operates in two modes
13628 # Mode 1 - the supplied IV is a list, i.e.
13629 # $self->editObj->$iv = [some_list]
13630 # $self->editHash->$iv = [some_list]
13631 # - the values supplied by the user are saved in place of [some_list]
13632 #
13633 # Mode 2 - the supplied IV is a hash, i.e.
13634 # $self->editObj->$iv = {some_hash}
13635 # $self->editHash->$iv = {some_hash}
13636 # - the calling function also supplies a key in {some_hash}
13637 # - a reference to the list supplied by the user is saved as the key's
13638 # corresponding value
13639 #
13640 # Expected arguments
13641 # $iv - The IV to set in $self->editHash
13642 #
13643 # Optional arguments
13644 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
13645 # $slWidget
13646 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleList in which the
13647 # IV's data is being displayed (if specified, the simple list is updated when
13648 # this window is closed)
13649 # $readOnlyFlag
13650 # - If set to TRUE, the list is read-only (so can't be edited); otherwise set
13651 # to FALSE (or 'undef')
13652 # $callFunc
13653 # - If specified, $self->$funcName is called when the IV is updated instead of the
13654 # usual call to $self->updateListDataWithKey (useful if we don't want the
13655 # simple list sorted alphabetically, as normally happens); otherwise set to
13656 # 'undef'
13657 # @callFuncArgs
13658 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
13659 # list
13660 #
13661 # Return values
13662 # 'undef' on improper arguments
13663 # 1 otherwise
13664  
13665 my ($self, $iv, $key, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
13666  
13667 # Local variables
13668 my (
13669 $title, $replaceListRef, $outerHashRef, $response,
13670 %outerHash,
13671 );
13672  
13673 # Check for improper arguments
13674 if (! defined $iv) {
13675  
13676 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptList', @_);
13677 }
13678  
13679 # Set the window title
13680 if ($readOnlyFlag) {
13681 $title = 'View List';
13682 } else {
13683 $title = 'Edit List';
13684 }
13685  
13686 # Show the 'dialogue' window
13687 my $dialogueWin;
13688 if (! $readOnlyFlag) {
13689  
13690 $dialogueWin = Gtk3::Dialog->new(
13691 $title,
13692 $self->winWidget,
13693 [qw/modal destroy-with-parent/],
13694 'gtk-cancel' => 'reject',
13695 'gtk-ok' => 'accept',
13696 );
13697  
13698 } else {
13699  
13700 $dialogueWin = Gtk3::Dialog->new(
13701 $title,
13702 $self->winWidget,
13703 [qw/modal destroy-with-parent/],
13704 'gtk-ok' => 'accept',
13705 );
13706 }
13707  
13708 $dialogueWin->set_position('center-always');
13709 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
13710  
13711 $dialogueWin->signal_connect('delete-event' => sub {
13712  
13713 $dialogueWin->destroy();
13714 $self->restoreFocus();
13715  
13716 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
13717 # the window is visibly closed)
13718 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptList');
13719 });
13720  
13721 # Add widgets to the 'dialogue' window
13722 my $vBox = $dialogueWin->get_content_area();
13723 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
13724 # Gtk3::VBox on the right, into which we put everything
13725 my $vBox2 = $self->addDialogueIcon($vBox);
13726  
13727 # Create a label, which will shortly show which IV is being edited
13728 my $label = Gtk3::Label->new();
13729 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
13730 $label->set_alignment(0, 0.5);
13731  
13732 # Create a textview, in which the user supplies a list of values
13733 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
13734 $vBox2->pack_start($scroll, TRUE, TRUE, $self->spacingPixels);
13735 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
13736 $scroll->set_policy('automatic', 'automatic');
13737 $scroll->set_size_request(200, 150); # Minimum size
13738 $scroll->set_border_width($self->spacingPixels);
13739  
13740 # Create a textview with default colours/fonts
13741 my $textView = Gtk3::TextView->new();
13742 $scroll->add($textView);
13743  
13744 my $buffer = Gtk3::TextBuffer->new();
13745 $textView->set_buffer($buffer);
13746  
13747 if ($readOnlyFlag) {
13748 $textView->set_editable(FALSE);
13749 } else {
13750 $textView->set_editable(TRUE);
13751 }
13752  
13753 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
13754  
13755 # Set the contents of the label and the textview
13756 if (! defined $key) {
13757  
13758 # Mode 1 - edit the list stored in $self->editObj->$iv or $self->editHash->$iv
13759 $label->set_markup('List stored in IV \'' . $iv . '\'');
13760  
13761 # If the IV hasn't yet been edited, use the original stored list
13762 if (! $self->ivExists('editHash', $iv)) {
13763  
13764 $replaceListRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
13765 $buffer->set_text(join("\n", @$replaceListRef));
13766  
13767 # If the IV has been edited, use the edited list
13768 } else {
13769  
13770 $replaceListRef = $self->ivShow('editHash', $iv);
13771 $buffer->set_text(join("\n", @$replaceListRef));
13772 }
13773  
13774 } else {
13775  
13776 # Mode 2 - edit the list stored in a key-value pair; the pair is in the hash
13777 # stored as $self->editObj->$iv or $self->editHash->$iv
13778 $label->set_markup('List stored in key \'' . $key . '\' in IV \'' . $iv . '\'');
13779  
13780 # Get a copy of the hash being edited
13781 if (! $self->ivExists('editHash', $iv)) {
13782  
13783 $outerHashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
13784 %outerHash = %$outerHashRef;
13785  
13786 } else {
13787  
13788 $outerHashRef = $self->ivShow('editHash', $iv);
13789 %outerHash = %$outerHashRef;
13790 }
13791  
13792 # Put the current contents of the list in the textview
13793 if (exists $outerHash{$key} && defined $outerHash{$key}) {
13794  
13795 $replaceListRef = $outerHash{$key};
13796 $buffer->set_text(join("\n", @$replaceListRef));
13797 }
13798 }
13799  
13800 # Widget drawing complete
13801 $vBox->show_all();
13802  
13803 # Get the response
13804 $response = $dialogueWin->run();
13805 if ($response eq 'accept') {
13806  
13807 my (
13808 $text,
13809 @dataList,
13810 );
13811  
13812 # Don't save anything for read-only values
13813 if (! $readOnlyFlag) {
13814  
13815 $text = $axmud::CLIENT->desktopObj->bufferGetText($buffer);
13816  
13817 # Split the contents of the textview into a list of lines, separated by
13818 # newline characters
13819 @dataList = split("\n", $text);
13820  
13821 # Mode 1 - edit the list stored in of $self->editObj->$iv or $self->editHash->$iv
13822 if (! defined $key) {
13823  
13824 # Store the list we've been editing
13825 $self->ivAdd('editHash', $iv, \@dataList);
13826  
13827 # Update the simple list displayed in the parent window, if a list was specified
13828 if ($slWidget) {
13829  
13830 $self->updateListDataWithKey($slWidget, $iv, \@dataList);
13831 }
13832  
13833 # Mode 2 - edit the list stored in a key-value pair; the pair is in the hash
13834 # stored as $self->editObj->$iv or $self->editHash->$iv
13835 } else {
13836  
13837 # Update the hash stored in the IV with a new key-value pair. The key is
13838 # $key, the corresponding value is a reference to the list we've
13839 # been editing, @dataList
13840 $outerHash{$key} = \@dataList;
13841  
13842 # Store the modified outer hash as the IV
13843 $self->ivAdd('editHash', $iv, \%outerHash);
13844  
13845 # Update the simple list displayed in the parent window, if a list was specified
13846 if ($slWidget) {
13847  
13848 $self->updateListDataWithKey($slWidget, $key, \@dataList);
13849 }
13850 }
13851  
13852 # Call a function to re-display the simple list in the parent window, if a function
13853 # was specified
13854 if ($callFunc) {
13855  
13856 $self->$callFunc(@callFuncArgs);
13857 }
13858 }
13859 }
13860  
13861 # Destroy the window
13862 $dialogueWin->destroy();
13863 $self->restoreFocus();
13864  
13865 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
13866 # window is visibly closed)
13867 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptList');
13868  
13869 # Operation complete
13870 return 1;
13871 }
13872  
13873 sub promptHash {
13874  
13875 # Creates a 'dialogue' window to prompt the user to view, enter (or edit) a hash of
13876 # key-value pairs
13877 # If the user supplies any pairs, sets the IV then closes the window
13878 #
13879 # Operates in two modes
13880 # Mode 1 - the supplied IV is a hash, i.e.
13881 # $self->editObj->$iv = {some_hash}
13882 # $self->editHash->$iv = {some_hash}
13883 # - the key-value pairs supplied by the user are saved in place of {some_hash}
13884 #
13885 # Mode 2 - the supplied IV is a hash, i.e.
13886 # $self->editObj->$iv = {some_hash}
13887 # $self->editHash->$iv = {some_hash}
13888 # - the calling function also supplies a key in {some_hash}
13889 # - a reference to the hash supplied by the user is saved as the key's
13890 # corresponding value
13891 #
13892 # Expected arguments
13893 # $iv - The IV to set in $self->editObj
13894 #
13895 # Optional arguments
13896 # $key - In mode 1, 'undef'; in mode 2, a key in {some_hash}
13897 # $slWidget
13898 # - In mode 1, 'undef'; in mode 2, 'undef' or the GA::Obj::SimpleListin which the
13899 # IV's data is being displayed (if specified, the simple list is updated when
13900 # this window is closed)
13901 # $readOnlyFlag
13902 # - If set to TRUE, the scalar is read-only (so can't be edited); otherwise set to
13903 # FALSE (or 'undef')
13904 # $callFunc
13905 # - If specified, $self->$funcName is called when the IV is updated instead of the
13906 # usual call to $self->updateListDataWithKey (useful if we don't want the
13907 # simple list sorted alphabetically, as normally happens); otherwise set to
13908 # 'undef'
13909 # @callFuncArgs
13910 # - Optional list of args to be passed if $callFunc is called; otherwise an empty
13911 # list
13912 #
13913 # Return values
13914 # 'undef' on improper arguments
13915 # 1 otherwise
13916  
13917 my ($self, $iv, $key, $slWidget, $readOnlyFlag, $callFunc, @callFuncArgs) = @_;
13918  
13919 # Local variables
13920 my (
13921 $title, $response, $outerHashRef,
13922 %outerHash, %replaceHash, %innerHash,
13923 );
13924  
13925 # Check for improper arguments
13926 if (! defined $iv) {
13927  
13928 return $axmud::CLIENT->writeImproper($self->_objClass . '->promptHash', @_);
13929 }
13930  
13931 # Set the window title
13932 if ($readOnlyFlag) {
13933 $title = 'View Hash';
13934 } else {
13935 $title = 'Edit Hash';
13936 }
13937  
13938 # Show the 'dialogue' window
13939 my $dialogueWin;
13940 if (! $readOnlyFlag) {
13941  
13942 $dialogueWin = Gtk3::Dialog->new(
13943 $title,
13944 $self->winWidget,
13945 [qw/modal destroy-with-parent/],
13946 'gtk-cancel' => 'reject',
13947 'gtk-ok' => 'accept',
13948 );
13949  
13950 } else {
13951  
13952 $dialogueWin = Gtk3::Dialog->new(
13953 $title,
13954 $self->winWidget,
13955 [qw/modal destroy-with-parent/],
13956 'gtk-ok' => 'accept',
13957 );
13958 }
13959  
13960 $dialogueWin->set_position('center-always');
13961 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
13962  
13963 $dialogueWin->signal_connect('delete-event' => sub {
13964  
13965 $dialogueWin->destroy();
13966 $self->restoreFocus();
13967  
13968 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
13969 # the window is visibly closed)
13970 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptHash');
13971 });
13972  
13973 # Add widgets to the 'dialogue' window
13974 my $vBox = $dialogueWin->get_content_area();
13975 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
13976 # Gtk3::VBox on the right, into which we put everything
13977 my $vBox2 = $self->addDialogueIcon($vBox);
13978  
13979 # Create a label, which will shortly show which IV is being edited
13980 my $label = Gtk3::Label->new();
13981 $vBox2->pack_start($label, TRUE, TRUE, $self->spacingPixels);
13982 $label->set_alignment(0, 0.5);
13983  
13984 # Create a scroller
13985 my $scroller = Gtk3::ScrolledWindow->new;
13986 $vBox2->pack_start($scroller, TRUE, TRUE, $self->spacingPixels);
13987 $scroller->set_policy('automatic', 'automatic');
13988 $scroller->set_size_request(200, 150); # Minimum size
13989  
13990 # Create a simple list with two columns representing a hash, for which the user
13991 # supplies key-value pairs
13992 my $slWidget2 = Games::Axmud::Obj::SimpleList->new(
13993 # Give the first column a minimum width; don't want the columns moving around too
13994 # much when the user enter new key-value pairs
13995 'Key ' => 'text',
13996 'Value' => 'text',
13997 );
13998 $scroller->add($slWidget2);
13999  
14000 # Set the contents of the label and the simple list. We don't want to overwrite the hash
14001 # until the user clicks the 'ok' button, so we'll edit a copy of the hash
14002 if (! defined $key) {
14003  
14004 # Mode 1 - edit the hash stored in $self->editObj->$iv or $self->editHash->$iv
14005 $label->set_markup('Hash stored in IV \'' . $iv . '\'');
14006 %outerHash = $self->promptHash_displayDataMode1($slWidget2, $iv);
14007 # Edit a copy, so that we can revert to the original copy if we want to
14008 %replaceHash = %outerHash;
14009  
14010 } else {
14011  
14012 # Mode 2 - edit the hash stored in a key-value pair; the pair is in the hash
14013 # stored as $self->editObj->$iv or $self->editHash->$iv
14014 $label->set_markup('Hash stored in key \'' . $key . "\'\nin IV \'" . $iv . "\'");
14015 %innerHash = $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14016 # Edit a copy, so that we can revert to the original copy if we want to
14017 %replaceHash = %innerHash;
14018 }
14019  
14020 # If the hash is editable, we have a lot more widgets to add
14021 if (! $readOnlyFlag) {
14022  
14023 # Add a grid containing entry boxes for new key-value pairs. The grid ensures that
14024 # the two entry boxes are aligned with each other
14025 my $grid = Gtk3::Grid->new();
14026 $vBox2->pack_start($grid, TRUE, TRUE, $self->spacingPixels);
14027  
14028 my $label2 = Gtk3::Label->new();
14029 $label2->set_alignment(0, 0.5);
14030 $label2->set_markup('Key');
14031 $label2->set_hexpand(TRUE);
14032 $grid->attach($label2, 0, 0, 1, 1);
14033  
14034 my $entry = Gtk3::Entry->new();
14035 $entry->set_hexpand(TRUE);
14036 $grid->attach($entry, 1, 0, 1, 1);
14037  
14038 my $label3 = Gtk3::Label->new();
14039 $label3->set_alignment(0, 0.5);
14040 $label3->set_markup('Value');
14041 $label3->set_hexpand(TRUE);
14042 $grid->attach($label3, 0, 1, 1, 1);
14043  
14044 my $entry2 = Gtk3::Entry->new();
14045 $entry2->set_hexpand(TRUE);
14046 $grid->attach($entry2, 1, 1, 1, 1);
14047  
14048 # Add a button strip containing editing buttons
14049 my $hBox = Gtk3::HBox->new(FALSE, 0);
14050 $vBox2->pack_start($hBox, TRUE, TRUE, $self->spacingPixels);
14051  
14052 # 'Add' button
14053 my $button = Gtk3::Button->new('Add');
14054 $hBox->pack_start($button, FALSE, FALSE, $self->spacingPixels);
14055 $button->set_tooltip_text('Add a key-value pair');
14056 $button->signal_connect('clicked' => sub {
14057  
14058 my ($thisKey, $thisValue);
14059  
14060 $thisKey = $entry->get_text();
14061 $thisValue = $entry2->get_text();
14062  
14063 # Update the hash we're editing...
14064 $replaceHash{$thisKey} = $thisValue;
14065 # ...and update the displayed simple list
14066 $self->updateListDataWithKey($slWidget2, $thisKey, $thisValue);
14067  
14068 # Empty the entry boxes
14069 $self->resetEntryBoxes($entry, $entry2);
14070 });
14071  
14072 # 'Undef' button
14073 my $button2 = Gtk3::Button->new('Add with \'undef\' value');
14074 $hBox->pack_start($button2, FALSE, FALSE, $self->spacingPixels);
14075 $button2->set_tooltip_text('Add a key-value pair, with the value set to \'undef\'');
14076 $button2->signal_connect('clicked' => sub {
14077  
14078 my $thisKey = $entry->get_text();
14079  
14080 # Update the hash we're editing...
14081 $replaceHash{$thisKey} = undef;
14082 # ...and update the displayed simple list
14083 $self->updateListDataWithKey($slWidget2, $thisKey, undef);
14084  
14085 # Empty the entry boxes
14086 $self->resetEntryBoxes($entry, $entry2);
14087 });
14088  
14089 # Add a second button strip containing editing buttons
14090 my $hBox2 = Gtk3::HBox->new(FALSE, 0);
14091 $vBox2->pack_start($hBox2, TRUE, TRUE, $self->spacingPixels);
14092  
14093 # 'Delete' button
14094 my $button3 = Gtk3::Button->new('Delete');
14095 $hBox2->pack_start($button3, FALSE, FALSE, $self->spacingPixels);
14096 $button3->set_tooltip_text('Delete the selected key-value pair');
14097 $button3->signal_connect('clicked' => sub {
14098  
14099 my (
14100 $thisKey,
14101 @selectList,
14102 );
14103  
14104 # Update the hash we're editing...
14105 ($thisKey) = $self->getSimpleListData($slWidget2, 0, 1);
14106 if (defined $thisKey) {
14107  
14108  
14109 delete $replaceHash{$thisKey};
14110 # ...and update the displayed simple list
14111 @selectList = $slWidget2->get_selected_indices();
14112 splice(@{$slWidget2->{data}}, $selectList[0], 1);
14113 }
14114 });
14115  
14116 # 'Reset' button
14117 my $button4 = Gtk3::Button->new('Reset');
14118 $hBox2->pack_start($button4, FALSE, FALSE, $self->spacingPixels);
14119 $button4->set_tooltip_text('Undo changes to the hash');
14120 $button4->signal_connect('clicked' => sub {
14121  
14122 # Update the hash we're editing...
14123 if (! defined $key) {
14124  
14125 # Mode 1
14126 $self->promptHash_displayDataMode1($slWidget2, $iv);
14127 %replaceHash = %outerHash;
14128  
14129 } else {
14130  
14131 # Mode 2
14132 $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14133 %replaceHash = %innerHash;
14134 }
14135  
14136 # ...and update the displayed simple list
14137 @{$slWidget2->{data}} = ();
14138  
14139 if (! defined $key) {
14140 $self->promptHash_displayDataMode1($slWidget2, $iv);
14141 } else {
14142 $self->promptHash_displayDataMode2($slWidget2, $iv, $key);
14143 }
14144 });
14145  
14146 # 'Clear' button
14147 my $button5 = Gtk3::Button->new('Clear');
14148 $hBox2->pack_start($button5, FALSE, FALSE, $self->spacingPixels);
14149 $button5->set_tooltip_text('Clear the hash');
14150 $button5->signal_connect('clicked' => sub {
14151  
14152 # Update the hash we're editing...
14153 %replaceHash = ();
14154 # ...and update the displayed simple list
14155 @{$slWidget2->{data}} = ();
14156 });
14157 }
14158  
14159 # Widget drawing complete
14160 $vBox->show_all();
14161  
14162 # Get the response
14163 $response = $dialogueWin->run();
14164 if ($response eq 'accept') {
14165  
14166 # Don't save anything for read-only values
14167 if (! $readOnlyFlag) {
14168  
14169 # Mode 1 - edit the hash stored in $self->editObj->$iv or $self->editHash->$iv
14170 if (! defined $key) {
14171  
14172 # Store the hash we've been editing
14173 $self->ivAdd('editHash', $iv, \%replaceHash);
14174  
14175 # Update the simple list displayed in the parent window, if a list was specified
14176 if ($slWidget) {
14177  
14178 $self->updateListDataWithKey($slWidget, $iv, \%replaceHash);
14179 }
14180  
14181 # Mode 2 - edit the hash stored in a key-value pair; the pair is in the hash stored
14182 # as $self->editObj->$iv or $self->editHash->$iv
14183 } else {
14184  
14185 # Get a copy of the hash stored in the IV
14186 if (! $self->ivExists('editHash', $iv)) {
14187  
14188 %outerHash = $self->editObj->$iv;
14189  
14190 # If the IV has been edited, use the edited hash
14191 } else {
14192  
14193 $outerHashRef = $self->ivShow('editHash', $iv);
14194 %outerHash = %$outerHashRef;
14195 }
14196  
14197 # Now update that hash with a new key-value pair. The key is $key, the
14198 # corresponding value is a reference to the hash we've been editing,
14199 # %replaceHash
14200 $outerHash{$key} = \%replaceHash;
14201  
14202 # Store the modified outer hash as the IV
14203 $self->ivAdd('editHash', $iv, \%outerHash);
14204  
14205 # Update the displayed list, if one was specified
14206 if ($slWidget) {
14207  
14208 $self->updateListDataWithKey($slWidget, $key, \%replaceHash);
14209 }
14210 }
14211  
14212 # Call a function to re-display the simple list, if one was specified
14213 if ($callFunc) {
14214  
14215 $self->$callFunc(@callFuncArgs);
14216 }
14217 }
14218 }
14219  
14220 # Destroy the window
14221 $dialogueWin->destroy();
14222 $self->restoreFocus();
14223  
14224 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
14225 # window is visibly closed)
14226 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->promptHash');
14227  
14228 # Operation complete
14229 return 1;
14230 }
14231  
14232 sub promptHash_displayDataMode1 {
14233  
14234 # Called by $self->promptHash when we want to edit a hash IV in $self->editObj or
14235 # $self->editHash
14236 # The calling function had created a GA::Obj::SimpleList; this function's job is to fill
14237 # it with data
14238 #
14239 # Expected arguments
14240 # $slWidget - The GA::Obj::SimpleList where the IV's data is displayed
14241 # $iv - The IV being edited
14242 #
14243 # Return values
14244 # An empty hash on improper arguments
14245 # Otherwise returns a copy of the hash being edited
14246  
14247 my ($self, $slWidget, $iv, $check) = @_;
14248  
14249 # Local variables
14250 my (
14251 $hashRef,
14252 %emptyHash, %dataHash,
14253 );
14254  
14255 # Check for improper arguments
14256 if (! defined $slWidget || ! defined $iv || defined $check) {
14257  
14258 $axmud::CLIENT->writeImproper(
14259 $self->_objClass . '->promptHash_displayDataMode1',
14260 @_,
14261 );
14262  
14263 return %emptyHash;
14264 }
14265  
14266 # If the IV hasn't yet been edited, use the original stored hash
14267 if (! $self->ivExists('editHash', $iv)) {
14268  
14269 $hashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
14270 %dataHash = %$hashRef;
14271  
14272 # If the IV has been edited, use the edited hash
14273 } else {
14274  
14275 $hashRef = $self->ivShow('editHash', $iv);
14276 %dataHash = %$hashRef;
14277 }
14278  
14279 # Update the GA::Obj::SimpleList (which currently stores no data)
14280 foreach my $key (sort {lc($a) cmp lc($b)} (keys %dataHash)) {
14281  
14282 push (
14283 @{$slWidget->{data}},
14284 [$key, $dataHash{$key}],
14285 );
14286 }
14287  
14288 return %dataHash;
14289 }
14290  
14291 sub promptHash_displayDataMode2 {
14292  
14293 # Called by $self->promptHash when we want to edit a hash, stored as a reference in an IV of
14294 # $self->editObj or $self->editHash
14295 #
14296 # i.e. SomeObject->{myHash} = {
14297 # iv1 => value,
14298 # iv2 => value,
14299 # iv3 => hash_reference_to_edit,
14300 # }
14301 #
14302 # The calling function had created a GA::Obj::SimpleList to display
14303 # hash_reference_to_edit; this function's job is to fill it with data
14304 #
14305 # Expected arguments
14306 # $slWidget - The GA::Obj::SimpleList where the IV's data is displayed
14307 # $iv - The IV being edited ('myHash' in the example above)
14308 # $key - The IV is a hash. $key is a key in that hash; $key's corresponding value
14309 # is the reference to the hash which we display in the simple list ('iv3'
14310 # in the example above)
14311 #
14312 # Return values
14313 # An empty hash on improper arguments
14314 # Otherwise returns a copy of the hash being edited
14315  
14316 my ($self, $slWidget, $iv, $key, $check) = @_;
14317  
14318 # Local variables
14319 my (
14320 $hashRef, $dataHashRef,
14321 %emptyHash, %hash, %dataHash,
14322 );
14323  
14324 # Check for improper arguments
14325 if (! defined $slWidget || ! defined $iv || ! defined $key || defined $check) {
14326  
14327 $axmud::CLIENT->writeImproper(
14328 $self->_objClass . '->promptHash_displayDataMode2',
14329 @_,
14330 );
14331  
14332 return %emptyHash;
14333 }
14334  
14335 # If the IV hasn't yet been edited, use the original stored hash
14336 if (! $self->ivExists('editHash', $iv)) {
14337  
14338 $hashRef = $self->editObj->{$iv}; # (Profile templates have no accessors)
14339 %hash = %$hashRef;
14340  
14341 # If the IV has been edited, use the edited hash
14342 } else {
14343  
14344 $hashRef = $self->ivShow('editHash', $iv);
14345 %hash = %$hashRef;
14346 }
14347  
14348 # Update the GA::Obj::SimpleList (which currently stores no data)
14349 if (exists $hash{$key} && defined $hash{$key}) {
14350  
14351 $dataHashRef = $hash{$key};
14352 %dataHash = %$dataHashRef;
14353  
14354 foreach my $key (sort {lc($a) cmp lc($b)} (keys %dataHash)) {
14355  
14356 push (
14357 @{$slWidget->{data}},
14358 [$key, $dataHash{$key}],
14359 );
14360 }
14361 }
14362  
14363 return %dataHash;
14364 }
14365  
14366 # General support functions
14367  
14368 sub sensitiseWidgets {
14369  
14370 # Sensitises a list of Gtk3 widgets
14371 #
14372 # Expected arguments
14373 # @list - The list of widgets to sensitise
14374 #
14375 # Return values
14376 # 'undef' on improper arguments
14377 # 1 otherwise
14378  
14379 my ($self, @list) = @_;
14380  
14381 # Check for improper arguments
14382 if (! @list) {
14383  
14384 return $axmud::CLIENT->writeImproper($self->_objClass . '->sensitiseWidgets', @_);
14385 }
14386  
14387 foreach my $widget (@list) {
14388  
14389 $widget->set_sensitive(TRUE);
14390 }
14391  
14392 return 1;
14393 }
14394  
14395 sub desensitiseWidgets {
14396  
14397 # Desensitises a list of Gtk3 widgets
14398 #
14399 # Expected arguments
14400 # @list - The list of widgets to desensitise
14401 #
14402 # Return values
14403 # 'undef' on improper arguments
14404 # 1 otherwise
14405  
14406 my ($self, @list) = @_;
14407  
14408 # Check for improper arguments
14409 if (! @list) {
14410  
14411 return $axmud::CLIENT->writeImproper($self->_objClass . '->desensitiseWidgets', @_);
14412 }
14413  
14414 foreach my $widget (@list) {
14415  
14416 $widget->set_sensitive(FALSE);
14417 }
14418  
14419 return 1;
14420 }
14421  
14422 # Standard callbacks
14423  
14424 sub buttonCancel {
14425  
14426 # 'Cancel' button callback
14427 #
14428 # Expected arguments
14429 # (none besides $self)
14430 #
14431 # Return values
14432 # 'undef' on improper arguments
14433 # 1 otherwise
14434  
14435 my ($self, $check) = @_;
14436  
14437 # Check for improper arguments
14438 if (defined $check) {
14439  
14440 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonCancel', @_);
14441 }
14442  
14443 # Close the window
14444 $self->winDestroy();
14445  
14446 return 1;
14447 }
14448  
14449 sub buttonOK {
14450  
14451 # 'OK' button callback
14452 #
14453 # Expected arguments
14454 # (none besides $self)
14455 #
14456 # Return values
14457 # 'undef' on improper arguments
14458 # 1 otherwise
14459  
14460 my ($self, $check) = @_;
14461  
14462 # Check for improper arguments
14463 if (defined $check) {
14464  
14465 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonOK', @_);
14466 }
14467  
14468 # Save changes
14469 $self->saveChanges();
14470  
14471 # Close the window
14472 $self->winDestroy();
14473  
14474 return 1;
14475 }
14476  
14477 sub buttonReset {
14478  
14479 # 'Reset' button callback
14480 #
14481 # Expected arguments
14482 # (none besides $self)
14483 #
14484 # Return values
14485 # 'undef' on improper arguments
14486 # 1 otherwise
14487  
14488 my ($self, $check) = @_;
14489  
14490 # Local variables
14491 my $number;
14492  
14493 # Check for improper arguments
14494 if (defined $check) {
14495  
14496 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonReset', @_);
14497 }
14498  
14499 # Remove all the existing tabs from the notebook
14500 $number = $self->notebook->get_n_pages();
14501 if ($number) {
14502  
14503 for (my $count = 0; $count < $number; $count++) {
14504  
14505 $self->notebook->remove_page(0);
14506 }
14507 }
14508  
14509 # Empty $self->editHash, destroying all the changes
14510 $self->ivEmpty('editHash');
14511  
14512 # Re-draw all the tabs
14513 $self->setupNotebook();
14514 # Render the changes
14515 $self->winShowAll($self->_objClass . '->buttonReset');
14516  
14517 return 1;
14518 }
14519  
14520 sub buttonSave {
14521  
14522 # 'Save' button callback
14523 #
14524 # Expected arguments
14525 # (none besides $self)
14526 #
14527 # Return values
14528 # 'undef' on improper arguments
14529 # 1 otherwise
14530  
14531 my ($self, $check) = @_;
14532  
14533 # Local variables
14534 my $number;
14535  
14536 # Check for improper arguments
14537 if (defined $check) {
14538  
14539 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonSave', @_);
14540 }
14541  
14542 # Save changes
14543 $self->saveChanges();
14544  
14545 # Reset the hash of functions to call when a child window is closed, ready for it to be
14546 # refilled
14547 $self->ivEmpty('childDestroyHash');
14548  
14549 # Remove all the tabs
14550 $number = $self->notebook->get_n_pages();
14551 if ($number) {
14552  
14553 for (my $count = 0; $count < $number; $count++) {
14554  
14555 $self->notebook->remove_page(0);
14556 }
14557 }
14558  
14559 # Re-draw all the tabs
14560 $self->setupNotebook();
14561 # Render the changes
14562 $self->winShowAll($self->_objClass . '->buttonSave');
14563  
14564 return 1;
14565 }
14566  
14567 ##################
14568 # Accessors - set
14569  
14570 ##################
14571 # Accessors - get
14572  
14573 sub notebook
14574 { $_[0]->{notebook} }
14575 sub hBox
14576 { $_[0]->{hBox} }
14577 sub okButton
14578 { $_[0]->{okButton} }
14579 sub cancelButton
14580 { $_[0]->{cancelButton} }
14581 sub resetButton
14582 { $_[0]->{resetButton} }
14583 sub saveButton
14584 { $_[0]->{saveButton} }
14585  
14586 sub gridSize
14587 { $_[0]->{gridSize} }
14588  
14589 sub editObj
14590 { $_[0]->{editObj} }
14591 sub tempFlag
14592 { $_[0]->{tempFlag} }
14593 sub currentFlag
14594 { $_[0]->{currentFlag} }
14595 sub editHash
14596 { my $self = shift; return %{$self->{editHash}}; }
14597 sub editConfigHash
14598 { my $self = shift; return %{$self->{editConfigHash}}; }
14599 }
14600  
14601 { package Games::Axmud::Generic::EditWin;
14602  
14603 use strict;
14604 use warnings;
14605 use diagnostics;
14606  
14607 use Glib qw(TRUE FALSE);
14608  
14609 our @ISA = qw(
14610 Games::Axmud::Generic::ConfigWin Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win
14611 Games::Axmud
14612 );
14613  
14614 ##################
14615 # Constructors
14616  
14617 # sub new {} # Inherited from GA::Generic::ConfigWin
14618  
14619 ##################
14620 # Methods
14621  
14622 # Standard window object functions
14623  
14624 # sub winSetup {} # Inherited from GA::Generic::ConfigWin
14625  
14626 # sub winEnable {} # Inherited from GA::Generic::ConfigWin
14627  
14628 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
14629  
14630 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
14631  
14632 # sub winShowAll {} # Inherited from GA::Generic::Win
14633  
14634 # sub drawWidgets {} # Inherited from GA::Generic::ConfigWin
14635  
14636 # sub redrawWidgets {} # Inherited from GA::Generic::Win
14637  
14638 # ->signal_connects
14639  
14640 # Other functions
14641  
14642 ##################
14643 # Accessors - set
14644  
14645 ##################
14646 # Accessors - get
14647 }
14648  
14649 { package Games::Axmud::Generic::FixedWin;
14650  
14651 use strict;
14652 use warnings;
14653 use diagnostics;
14654  
14655 use Glib qw(TRUE FALSE);
14656  
14657 our @ISA = qw(
14658 Games::Axmud::Generic::GridWin Games::Axmud::Generic::Win Games::Axmud
14659 );
14660  
14661 ##################
14662 # Constructors
14663  
14664 sub new {
14665  
14666 # Called by GA::Obj::Workspace->createGridWin and ->createSimpleGridWin
14667 # Generic function to create a 'fixed' window
14668 #
14669 # Expected arguments
14670 # $number - Unique number for this window object
14671 # $winType - The window type, must be 'fixed'
14672 # $winName - The window name, must be 'fixed'
14673 # $workspaceObj
14674 # - The GA::Obj::Workspace object for the workspace in which this window is
14675 # created
14676 #
14677 # Optional arguments
14678 # $owner - The owner, if known ('undef' if not). Typically it's a GA::Session or a
14679 # task (inheriting from GA::Generic::Task); could also be GA::Client.
14680 # It should not be another window object
14681 # (inheriting from GA::Generic::Win). The owner should have its own
14682 # ->del_winObj function which is called when $self->winDestroy is
14683 # called
14684 # $session - The owner's session. If $owner is a GA::Session, that session. If
14685 # it's something else (like a task), the task's session. If $owner is
14686 # 'undef', so is $session
14687 # $workspaceGridObj
14688 # - The GA::Obj::WorkspaceGrid object into whose grid this window has been
14689 # placed. 'undef' in $workspaceObj->gridEnableFlag = FALSE
14690 # $areaObj - The GA::Obj::Area (a region of a workspace grid zone) which handles this
14691 # window. 'undef' in $workspaceObj->gridEnableFlag = FALSE
14692 # $winmap - Ignored if set
14693 #
14694 # Return values
14695 # 'undef' on improper arguments
14696 # Blessed reference to the newly-created object on success
14697  
14698 my (
14699 $class, $number, $winType, $winName, $workspaceObj, $owner, $session, $workspaceGridObj,
14700 $areaObj, $winmap, $check,
14701 ) = @_;
14702  
14703 # Check for improper arguments
14704 if (
14705 ! defined $class || ! defined $number || ! defined $winType || ! defined $winName
14706 || ! defined $workspaceObj || defined $check
14707 ) {
14708 return $axmud::CLIENT->writeImproper($class . '->new', @_);
14709 }
14710  
14711 # Check that the $winType is valid
14712 if ($winType ne 'fixed') {
14713  
14714 return $axmud::CLIENT->writeError(
14715 'Internal window error: invalid \'fixed\' window type \'' . $winType . '\'',
14716 $class . '->new',
14717 );
14718 }
14719  
14720 # Setup
14721 my $self = {
14722 _objName => 'fixed_win_' . $number,
14723 _objClass => $class,
14724 _parentFile => undef, # No parent file object
14725 _parentWorld => undef, # No parent file object
14726 _privFlag => TRUE, # All IVs are private
14727  
14728 # Standard window object IVs
14729 # --------------------------
14730  
14731 # Unique number for this window object
14732 number => $number,
14733 # The window category - 'grid' or 'free'
14734 winCategory => 'grid',
14735 # The window type, must be 'fixed'
14736 winType => $winType,
14737 # The window name, must be 'fixed'
14738 winName => $winName,
14739 # The GA::Obj::Workspace object for the workspace in which this window is created
14740 workspaceObj => $workspaceObj,
14741 # The owner, if known ('undef' if not). Typically it's a GA::Session or a task
14742 # (inheriting from GA::Generic::Task); could also be GA::Client. It should not be
14743 # another window object (inheriting from GA::Generic::Win). The owner must have its
14744 # own ->del_winObj function which is called when $self->winDestroy is called
14745 owner => $owner,
14746 # The owner's session ('undef' if not). If ->owner is a GA::Session, that session. If
14747 # it's something else (like a task), the task's sesssion. If ->owner is 'undef', so is
14748 # ->session
14749 session => $session,
14750 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
14751 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
14752 # displayed in a 'dialogue' window)
14753 pseudoCmdMode => 'win_error',
14754  
14755 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
14756 # parent 'main' window's Gtk3::Window
14757 # The code should use this IV when it wants to do something to the window itself
14758 # (minimise it, make it active, etc)
14759 winWidget => undef,
14760 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
14761 # the parent GA::Table::PseudoWin table object
14762 # The code should use this IV when it wants to add, modify or remove widgets inside the
14763 # window itself
14764 winBox => undef,
14765 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
14766 # FALSE if not
14767 enabledFlag => FALSE,
14768 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
14769 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
14770 visibleFlag => TRUE,
14771 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
14772 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
14773 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
14774 childFreeWinHash => {},
14775 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
14776 # window is informed via a call to $self->del_childFreeWin
14777 # When the child is destroyed, this window might want to call some of its own functions
14778 # to update various widgets and/or IVs, in which case this window adds an entry to
14779 # this hash; a hash in the form
14780 # $childDestroyHash{unique_number} = list_reference
14781 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
14782 # reference to a list in groups of 2, in the form
14783 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
14784 childDestroyHash => {},
14785  
14786 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
14787 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
14788 # area)
14789 packingBox => undef,
14790  
14791 # Standard IVs for 'grid' windows
14792  
14793 # The GA::Obj::WorkspaceGrid object into whose grid this window has been placed. 'undef'
14794 # in $workspaceObj->gridEnableFlag = FALSE
14795 workspaceGridObj => $workspaceGridObj,
14796 # The GA::Obj::Area object for this window. An area object is a part of a zone's
14797 # internal grid, handling a single window (this one). Set to 'undef' in
14798 # $workspaceObj->gridEnableFlag = FALSE
14799 areaObj => $areaObj,
14800 # For pseudo-windows (in which a window object is created, but its widgets are drawn
14801 # inside a GA::Table::PseudoWin table object), the table object created. 'undef' if
14802 # this window object is a real 'grid' window
14803 pseudoWinTableObj => undef,
14804 # The name of the GA::Obj::Winmap object (not used for 'map' windows)
14805 winmap => undef,
14806  
14807 # Standard IVs for 'fixed' windows
14808 # ...
14809 };
14810  
14811 # Bless the object into existence
14812 bless $self, $class;
14813  
14814 return $self;
14815 }
14816  
14817 ##################
14818 # Methods
14819  
14820 # Standard window object functions
14821  
14822 # sub winSetup {} # Inherited from GA::Generic::GridWin
14823  
14824 # sub winEnable {} # Inherited from GA::Generic::GridWin
14825  
14826 # sub winDisengage {} # Defined in window objects which inherit this one
14827  
14828 # sub winDestroy {} # Defined in window objects which inherit this one
14829  
14830 # sub winShowAll {} # Inherited from GA::Generic::Win
14831  
14832 # sub drawWidgets {} # Inherited from GA::Generic::Win
14833  
14834 # sub redrawWidgets {} # Inherited from GA::Generic::Win
14835  
14836 # ->signal_connects
14837  
14838 # Other functions
14839  
14840 ##################
14841 # Accessors - set
14842  
14843 ##################
14844 # Accessors - get
14845 }
14846  
14847 { package Games::Axmud::Generic::FreeWin;
14848  
14849 use strict;
14850 use warnings;
14851 use diagnostics;
14852  
14853 use Glib qw(TRUE FALSE);
14854  
14855 our @ISA = qw(Games::Axmud::Generic::Win Games::Axmud);
14856  
14857 ##################
14858 # Constructors
14859  
14860 # sub new {} # Defined in window objects which inherit this one
14861  
14862 ##################
14863 # Methods
14864  
14865 # Standard window object functions
14866  
14867 sub winSetup {
14868  
14869 # Called by GA::Generic::Win->createFreeWin, after the call to $self->new
14870 # Creates the Gtk3::Window itself
14871 #
14872 # Expected arguments
14873 # (none besides $self)
14874 #
14875 # Return values
14876 # 'undef' on improper arguments or if the window can't be opened
14877 # 1 on success
14878  
14879 my ($self, $check) = @_;
14880  
14881 # Local variables
14882 my $iv;
14883  
14884 # Check for improper arguments
14885 if (defined $check) {
14886  
14887 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
14888 }
14889  
14890 # Create the Gtk3::Window
14891 my $winWidget = Gtk3::Window->new('toplevel');
14892 if (! $winWidget) {
14893  
14894 return undef;
14895  
14896 } else {
14897  
14898 # Store the IV now, as subsequent code needs it
14899 $self->ivPoke('winWidget', $winWidget);
14900 $self->ivPoke('winBox', $winWidget);
14901 }
14902  
14903 # Set up ->signal_connects
14904 $self->setDeleteEvent(); # 'delete-event'
14905  
14906 # Set the window title
14907 $winWidget->set_title($self->title);
14908  
14909 # Set the window's default size and position
14910 $winWidget->set_default_size($self->widthPixels, $self->heightPixels);
14911 $winWidget->set_border_width($self->borderPixels);
14912 $winWidget->set_position('center');
14913  
14914 # Set the icon list for this window
14915 $iv = $self->winType . 'WinIconList';
14916 $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv});
14917  
14918 # Draw the widgets used by this window
14919 if (! $self->drawWidgets()) {
14920  
14921 return undef;
14922 }
14923  
14924 # The calling function can now call $self->winEnable to make the window visible
14925 return 1;
14926 }
14927  
14928 sub winEnable {
14929  
14930 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
14931 # After the Gtk3::Window has been setup and moved into position, makes it visible
14932 #
14933 # Expected arguments
14934 # (none besides $self)
14935 #
14936 # Return values
14937 # 'undef' on improper arguments
14938 # 1 on success
14939  
14940 my ($self, $check) = @_;
14941  
14942 # Check for improper arguments
14943 if (defined $check) {
14944  
14945 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
14946 }
14947  
14948 # Make the window appear on the desktop
14949 $self->winShowAll($self->_objClass . '->winEnable');
14950 $self->ivPoke('enabledFlag', TRUE);
14951  
14952 return 1;
14953 }
14954  
14955 sub winDisengage {
14956  
14957 # Should not be called, in general (provides compatibility with other types of windows,
14958 # whose window objects can be destroyed without closing the windows themselves)
14959 # If called, this function just calls $self->winDestroy and returns the result
14960 #
14961 # Expected arguments
14962 # (none besides $self)
14963 #
14964 # Return values
14965 # 'undef' on improper arguments or if the window can't be disengaged
14966 # 1 on success
14967  
14968 my ($self, $check) = @_;
14969  
14970 # Check for improper arguments
14971 if (defined $check) {
14972  
14973 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDisengage', @_);
14974 }
14975  
14976 return $self->winDestroy();
14977 }
14978  
14979 sub winDestroy {
14980  
14981 # Can be called by anything
14982 # Updates IVs
14983 #
14984 # Expected arguments
14985 # (none besides $self)
14986 #
14987 # Return values
14988 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
14989 # been destroyed
14990 # 1 on success
14991  
14992 my ($self, $check) = @_;
14993  
14994 # Check for improper arguments
14995 if (defined $check) {
14996  
14997 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
14998 }
14999  
15000 if (! $self->winBox) {
15001  
15002 # Window already destroyed in a previous call to this function
15003 return undef;
15004 }
15005  
15006 # Close any 'free' windows for which this window is a parent
15007 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
15008  
15009 $winObj->winDestroy();
15010 }
15011  
15012 # Destroy the Gtk3::Window
15013 eval { $self->winBox->destroy(); };
15014 if ($@) {
15015  
15016 # Window can't be destroyed
15017 return undef;
15018  
15019 } else {
15020  
15021 $self->ivUndef('winWidget');
15022 $self->ivUndef('winBox');
15023 }
15024  
15025 # Inform the owner and the desktop object of this 'free' window's demise
15026 $axmud::CLIENT->desktopObj->del_freeWin($self);
15027 if ($self->owner) {
15028  
15029 $self->owner->del_childFreeWin($self);
15030 }
15031  
15032 return 1;
15033 }
15034  
15035 # sub winShowAll {} # Inherited from GA::Generic::Win
15036  
15037 # sub drawWidgets {} # Inherited from GA::Generic::Win
15038  
15039 # sub redrawWidgets {} # Inherited from GA::Generic::Win
15040  
15041 # ->signal_connects
15042  
15043 sub setDeleteEvent {
15044  
15045 # Called by $self->winSetup
15046 # Set up a ->signal_connect to watch out for the user manually closing the 'free' window
15047 #
15048 # Expected arguments
15049 # (none besides $self)
15050 #
15051 # Return values
15052 # 'undef' on improper arguments
15053 # 1 otherwise
15054  
15055 my ($self, $check) = @_;
15056  
15057 # Check for improper arguments
15058 if (defined $check) {
15059  
15060 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
15061 }
15062  
15063 $self->winBox->signal_connect('delete-event' => sub {
15064  
15065 # Prevent Gtk3 from taking action directly. Instead redirect the request to
15066 # $self->winDestroy
15067 return $self->winDestroy();
15068 });
15069  
15070 return 1;
15071 }
15072  
15073 # Other functions
15074  
15075 ##################
15076 # Accessors - set
15077  
15078 ##################
15079 # Accessors - get
15080  
15081 sub widthPixels
15082 { $_[0]->{widthPixels} }
15083 sub heightPixels
15084 { $_[0]->{heightPixels} }
15085 sub borderPixels
15086 { $_[0]->{borderPixels} }
15087 sub spacingPixels
15088 { $_[0]->{spacingPixels} }
15089  
15090 sub title
15091 { $_[0]->{title} }
15092 sub configHash
15093 { my $self = shift; return %{$self->{configHash}}; }
15094 sub packingBox
15095 { $_[0]->{packingBox} }
15096 }
15097  
15098 { package Games::Axmud::Generic::GridWin;
15099  
15100 use strict;
15101 use warnings;
15102 use diagnostics;
15103  
15104 use Glib qw(TRUE FALSE);
15105  
15106 our @ISA = qw(Games::Axmud::Generic::Win Games::Axmud);
15107  
15108 ##################
15109 # Constructors
15110  
15111 # sub new {} # Defined in window objects which inherit this one
15112  
15113 ##################
15114 # Methods
15115  
15116 # Standard window object functions
15117  
15118 sub winSetup {
15119  
15120 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
15121 # This generic function merely creates a Gtk3::Window
15122 # Your own window object code should either create a function based on
15123 # GA::Win::Internal->winSetup, or your code should inherit that function directly
15124 #
15125 # Expected arguments
15126 # (none besides $self)
15127 #
15128 # Optional arguments
15129 # $title - The window title or 'undef'. Ignored in this generic function
15130 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
15131 # created (can be used to set up further ->signal_connects, if this
15132 # window needs them)
15133 #
15134 # Return values
15135 # 'undef' on improper arguments or if the window can't be opened
15136 # 1 on success
15137  
15138 my ($self, $title, $listRef, $check) = @_;
15139  
15140 # Local variables
15141 my $iv;
15142  
15143 # Check for improper arguments
15144 if (defined $check) {
15145  
15146 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
15147 }
15148  
15149 # Don't create a new window, if it already exists
15150 if ($self->enabledFlag) {
15151  
15152 return undef;
15153 }
15154  
15155 # Create the Gtk3::Window
15156 my $winWidget = Gtk3::Window->new('toplevel');
15157 if (! $winWidget) {
15158  
15159 return undef;
15160  
15161 } else {
15162  
15163 # Store the IV now, as everything needs it
15164 $self->ivPoke('winWidget', $winWidget);
15165 $self->ivPoke('winBox', $winWidget);
15166 }
15167  
15168 # Set up ->signal_connects specified by the calling function, if any
15169 if ($listRef) {
15170  
15171 foreach my $func (@$listRef) {
15172  
15173 $self->$func();
15174 }
15175 }
15176  
15177 # Set the icon list for this window
15178 $iv = $self->winType . 'WinIconList';
15179 $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv});
15180  
15181 # Draw the widgets used by this window
15182 if (! $self->drawWidgets($winWidget)) {
15183  
15184 return undef;
15185 }
15186  
15187 # The calling function can now move the window into position, before calling
15188 # $self->winEnable to make it visible, and to set up any more ->signal_connects()
15189 return 1;
15190 }
15191  
15192 sub winEnable {
15193  
15194 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
15195 # This generic function merely makes the Gtk3::Window visible
15196 # Your own window object code should either create a function based on
15197 # GA::Win::Internal->winEnable, or your code should inherit that function directly
15198 #
15199 # Expected arguments
15200 # (none besides $self)
15201 #
15202 # Optional arguments
15203 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
15204 # created (can be used to set up further ->signal_connects, if this
15205 # window needs them)
15206 #
15207 # Return values
15208 # 'undef' on improper arguments
15209 # 1 on success
15210  
15211 my ($self, $title, $listRef, $check) = @_;
15212  
15213 # Check for improper arguments
15214 if (defined $check) {
15215  
15216 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
15217 }
15218  
15219 # Make the window appear on the desktop
15220 $self->winShowAll($self->_objClass . '->winEnable');
15221 $self->ivPoke('enabledFlag', TRUE);
15222  
15223 # For windows about to be placed on a grid, briefly minimise the window so it doesn't
15224 # appear in the centre of the desktop before being moved to its correct workspace, size
15225 # and position
15226 if ($self->workspaceGridObj && $self->winWidget eq $self->winBox) {
15227  
15228 $self->minimise();
15229 }
15230  
15231 # Set up ->signal_connects specified by the calling function, if any
15232 if ($listRef) {
15233  
15234 foreach my $func (@$listRef) {
15235  
15236 $self->$func();
15237 }
15238 }
15239  
15240 return 1;
15241 }
15242  
15243 # sub winDisengage {} # Defined in window objects which inherit this one
15244  
15245 # sub winDestroy {} # Defined in window objects which inherit this one
15246  
15247 # sub winShowAll {} # Inherited from GA::Win::Generic
15248  
15249 # sub drawWidgets {} # Inherited from GA::Win::Generic
15250  
15251 # sub redrawWidgets {} # Inherited from GA::Win::Generic
15252  
15253 # ->signal_connects
15254  
15255 sub setDeleteEvent {
15256  
15257 # Called by GA::Obj::Workspace->createGridWin (for 'external' windows only)
15258 # Called by $self->winSetup (for other 'grid' windows)
15259 # This generic function doesn't actually create any ->signal_connects
15260 #
15261 # Expected arguments
15262 # (none besides $self)
15263 #
15264 # Return values
15265 # 'undef' on improper arguments
15266 # 1 otherwise
15267  
15268 my ($self, $check) = @_;
15269  
15270 # Check for improper arguments
15271 if (defined $check) {
15272  
15273 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
15274 }
15275  
15276 # (Do nothing)
15277  
15278 return 1;
15279 }
15280  
15281 sub setKeyPressEvent {
15282  
15283 # Called by $self->winSetup
15284 # This generic function doesn't actually create any ->signal_connects
15285 #
15286 # Expected arguments
15287 # (none besides $self)
15288 #
15289 # Return values
15290 # 'undef' on improper arguments
15291 # 1 otherwise
15292  
15293 my ($self, $check) = @_;
15294  
15295 # Check for improper arguments
15296 if (defined $check) {
15297  
15298 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyPressEvent', @_);
15299 }
15300  
15301 # (Do nothing)
15302  
15303 return 1;
15304 }
15305  
15306 sub setKeyReleaseEvent {
15307  
15308 # Called by $self->winSetup
15309 # This generic function doesn't actually create any ->signal_connects
15310 #
15311 # Expected arguments
15312 # (none besides $self)
15313 #
15314 # Return values
15315 # 'undef' on improper arguments
15316 # 1 otherwise
15317  
15318 my ($self, $check) = @_;
15319  
15320 # Check for improper arguments
15321 if (defined $check) {
15322  
15323 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyReleaseEvent', @_);
15324 }
15325  
15326 # (Do nothing)
15327  
15328 return 1;
15329 }
15330  
15331 sub setConfigureEvent {
15332  
15333 # Called by $self->winEnable
15334 # This generic function doesn't actually create any ->signal_connects
15335 #
15336 # Expected arguments
15337 # (none besides $self)
15338 #
15339 # Return values
15340 # 'undef' on improper arguments
15341 # 1 otherwise
15342  
15343 my ($self, $check) = @_;
15344  
15345 # Check for improper arguments
15346 if (defined $check) {
15347  
15348 return $axmud::CLIENT->writeImproper($self->_objClass . '->setConfigureEvent', @_);
15349 }
15350  
15351 # (Do nothing)
15352  
15353 return 1;
15354 }
15355  
15356 sub setWindowStateEvent {
15357  
15358 # Called by $self->winEnable
15359 # This generic function doesn't actually create any ->signal_connects
15360 #
15361 # Expected arguments
15362 # (none besides $self)
15363 #
15364 # Return values
15365 # 'undef' on improper arguments
15366 # 1 otherwise
15367  
15368 my ($self, $check) = @_;
15369  
15370 # Check for improper arguments
15371 if (defined $check) {
15372  
15373 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowStateEvent', @_);
15374 }
15375  
15376 # (Do nothing)
15377  
15378 return 1;
15379 }
15380  
15381 sub setWindowClosedEvent {
15382  
15383 # Called by GA::Obj::Workspace->createGridWin (for 'external' windows only)
15384 # This generic function doesn't actually create any ->signal_connects
15385 #
15386 # Expected arguments
15387 # (none besides $self)
15388 #
15389 # Return values
15390 # 'undef' on improper arguments
15391 # 1 otherwise
15392  
15393 my ($self, $check) = @_;
15394  
15395 # Check for improper arguments
15396 if (defined $check) {
15397  
15398 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowClosedEvent', @_);
15399 }
15400  
15401 # (Do nothing)
15402  
15403 return 1;
15404 }
15405  
15406 # Other functions
15407  
15408 ##################
15409 # Accessors - set
15410  
15411 sub set_areaObj {
15412  
15413 my ($self, $areaObj, $check) = @_;
15414  
15415 # Check for improper arguments
15416 if (defined $check) {
15417  
15418 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_areaObj', @_);
15419 }
15420  
15421 $self->ivPoke('areaObj', $areaObj);
15422  
15423 return 1;
15424 }
15425  
15426 sub set_workspaceGridObj {
15427  
15428 my ($self, $workspaceGridObj, $check) = @_;
15429  
15430 # Check for improper arguments
15431 if (defined $check) {
15432  
15433 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceGridObj', @_);
15434 }
15435  
15436 $self->ivPoke('workspaceGridObj', $workspaceGridObj);
15437  
15438 return 1;
15439 }
15440  
15441 ##################
15442 # Accessors - get
15443  
15444 sub workspaceGridObj
15445 { $_[0]->{workspaceGridObj} }
15446 sub areaObj
15447 { $_[0]->{areaObj} }
15448 sub pseudoWinTableObj
15449 { $_[0]->{pseudoWinTableObj} }
15450 sub winmap
15451 { $_[0]->{winmap} }
15452 }
15453  
15454 { package Games::Axmud::Generic::Interface;
15455  
15456 use strict;
15457 use warnings;
15458 use diagnostics;
15459  
15460 use Glib qw(TRUE FALSE);
15461  
15462 our @ISA = qw(Games::Axmud);
15463  
15464 ##################
15465 # Constructors
15466  
15467 ##################
15468 # Methods
15469  
15470 sub modifyAttribs {
15471  
15472 # Called by GA::Generic::Cmd->modifyInterface (caused by ';modifytrigger', etc)
15473 # Modifies this object's IVs (the calling function modifies attributes on the corresponding
15474 # inactive interface)
15475 #
15476 # Expected arguments
15477 # $session - The calling function's GA::Session
15478 # %attribHash - A hash of attributes, in the form
15479 # (attribute, value, attribute, value...)
15480 # - The keys can match any of the keys in $self->attribHash, or the
15481 # standard attributes 'name', 'stimulus', 'response', 'enabled'
15482 #
15483 # Return values
15484 # 'undef' on improper arguments or if any of the keys in %attribHash are unrecognised
15485 # attributes
15486 # 1 otherwise
15487  
15488 my ($self, $session, %attribHash) = @_;
15489  
15490 # Local variables
15491 my $modelObj;
15492  
15493 # Check for improper arguments
15494 if (! defined $session) {
15495  
15496 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyAttribs', @_);
15497 }
15498  
15499 # If an empty hash was supplied, then of course we do nothing (but still show 1 for success)
15500 if (! %attribHash) {
15501  
15502 return 1;
15503 }
15504  
15505 # Get the corresponding interface model object
15506 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $self->category);
15507  
15508 # Check that every key in %attribHash is valid, before we start modifying any values
15509 foreach my $attrib (keys %attribHash) {
15510  
15511 my ($type, $value);
15512  
15513 if (
15514 $attrib ne 'name' && $attrib ne 'stimulus' && $attrib ne 'response'
15515 && $attrib ne 'enabled'
15516 && ! $self->ivExists('attribHash', $attrib)
15517 ) {
15518 return $self->writeError(
15519 'Unrecognised attribute \'' . $attrib . '\' for interface category \''
15520 . $self->category . '\'',
15521 $self->_objClass . '->modifyAttribs',
15522 );
15523 }
15524  
15525 # Check the value is valid
15526 $type = $modelObj->ivShow('attribTypeHash', $attrib);
15527 $value = $self->checkAttribValue($session, $attrib, $attribHash{$attrib}, $type);
15528 if (! defined $value) {
15529  
15530 # Error message already displayed
15531 return undef;
15532  
15533 } else {
15534  
15535 # ->checkAttribValue modifies some $values (e.g. converts booleans to TRUE or FALSE)
15536 $attribHash{$attrib} = $value;
15537 }
15538 }
15539  
15540 # Modify stored attributes
15541 foreach my $key (keys %attribHash) {
15542  
15543 my $value = $attribHash{$key};
15544  
15545 # Standard attributes
15546 if ($key eq 'name') {
15547  
15548 $self->ivPoke('name', $value);
15549  
15550 } elsif ($key eq 'stimulus') {
15551  
15552 $self->ivPoke('stimulus', $value);
15553  
15554 } elsif ($key eq 'response') {
15555  
15556 $self->ivPoke('response', $value);
15557  
15558 } elsif ($key eq 'enabled') {
15559  
15560 if ($value) {
15561 $self->ivPoke('enabledFlag', TRUE);
15562 } else {
15563 $self->ivPoke('enabledFlag', FALSE);
15564 }
15565  
15566 # Category-dependent attributes
15567 } else {
15568  
15569 $self->ivAdd('attribHash', $key, $value);
15570 }
15571 }
15572  
15573 return 1;
15574 }
15575  
15576 sub checkAttribValue {
15577  
15578 # Called by GA::Generic::Interface->set_attribHash
15579 # Called by GA::Interface::Active->modifyAttributes
15580 # Called by GA::Generic::Cmd->addInterface
15581 #
15582 # Given an interface attribute, its corresponding value and the attribute type, checks that
15583 # the value is valid. Also modifies the value in some circumstances (e.g. for the
15584 # 'boolean' type, converts it to TRUE or FALSE)
15585 #
15586 # Expected arguments
15587 # $session - The calling function's GA::Session
15588 # $attrib - The name of the attribute
15589 # $value - The corresponding value
15590 # $type - The attribute type, one of 'boolean', 'colour', 'hook_event',
15591 # 'instruction', 'interval', 'keycode', 'mode', 'number', 'pattern',
15592 # 'repeat_count', 'string', 'style', 'substitution' or 'underlay'
15593 #
15594 # Return values
15595 # 'undef' on improper arguments, if $value isn't valid or if $type is unrecognised
15596 # Otherwise, returns $value (possibly after being modified)
15597  
15598 my ($self, $session, $attrib, $value, $type, $check) = @_;
15599  
15600 # Local variables
15601 my ($char, $modelObj);
15602  
15603 # Check for improper arguments
15604 if (
15605 ! defined $session || ! defined $attrib || ! defined $value || ! defined $type
15606 || defined $check
15607 ) {
15608 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkAttribValue', @_);
15609 }
15610  
15611 if ($type eq 'boolean') {
15612  
15613 # Convert $value to TRUE of FALSE
15614 $char = substr ($value, 0, 1);
15615  
15616 if (
15617 ! $value # zero (or an empty string)
15618 || $char eq 'f' || $char eq 'F' # any word beginning with 'f'/'F'
15619 ) {
15620 return FALSE;
15621  
15622 } elsif (
15623 $value eq '1' # one
15624 || $char eq 't' || $char eq 'T' # any word beginning with 't'/'T'
15625 ) {
15626 return TRUE;
15627  
15628 } else {
15629  
15630 return $session->writeWarning(
15631 'Invalid attribute value for \'' . $attrib . '\' (not a TRUE/FALSE value)',
15632 $self->_objClass . '->checkAttribValue',
15633 );
15634 }
15635  
15636 } elsif ($type eq 'colour' || $type eq 'underlay') {
15637  
15638 # Must check it's a valid Axmud colour tag (standard, xterm or RGB), or an empty string
15639 if ($value eq '') {
15640  
15641 # $value is valid
15642 return $value;
15643  
15644 } elsif ($value eq '0') {
15645  
15646 # ;addtrigger and ;modifytrigger use 0 in place of an empty string
15647 return '';
15648  
15649 } else {
15650  
15651 if ($type eq 'colour' && ! $axmud::CLIENT->checkTextTags($value)) {
15652  
15653 return $session->writeWarning(
15654 'Invalid attribute value for \'' . $attrib . '\' (not a valid standard or'
15655 . ' xterm text colour tag)',
15656 $self->_objClass . '->checkAttribValue',
15657 );
15658  
15659 } elsif (
15660 $type eq 'underlay'
15661 && ! $axmud::CLIENT->checkUnderlayTags($value)
15662 ) {
15663 return $session->writeWarning(
15664 'Invalid attribute value for \'' . $attrib . '\' (not a valid standard or'
15665 . ' xterm underlay colour tag)',
15666 $self->_objClass . '->checkAttribValue',
15667 );
15668  
15669 } else {
15670  
15671 # $value is valid
15672 return $value;
15673 }
15674 }
15675  
15676 } elsif ($type eq 'hook_event') {
15677  
15678 # Must check it's a valid hook event. Get the hook interface model
15679 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', 'hook');
15680 # Check the hook event exists in the hash or, if not, check that it's a valid name for
15681 # a custom hook event
15682 if (
15683 ! $modelObj->ivExists('hookEventHash', $value)
15684 && ! ($value =~ m/^\_[A-Za-z0-9]/)
15685 ) {
15686 return $session->writeWarning(
15687 'Invalid attribute value for \'' . $attrib . '\' (not a valid hook event)',
15688 $self->_objClass . '->checkAttribValue',
15689 );
15690  
15691 } else {
15692  
15693 # $value is valid
15694 return $value;
15695 }
15696  
15697 } elsif ($type eq 'interval') {
15698  
15699 # CHeck the value. Valid values are
15700 # - A positive number
15701 # - A 24-hour clock time, in the form HH::MM (00:00-23:59)
15702 # - A clock time in the form 99:MM (99:00-99:59), for timers that fire once every hour
15703 # at MM minutes past the hour
15704 if (
15705 ( ! $axmud::CLIENT->floatCheck($value, 0) || $value == 0)
15706 && ! ($value =~ m/^([01]?[0-9]|2[0-3])\:[0-5][0-9]$/)
15707 && ! ($value =~ m/^99\:[0-5][0-9]$/)
15708 ) {
15709 return $session->writeWarning(
15710 'Invalid attribute value for \'' . $attrib . '\' (not an interval above 0, a'
15711 . ' 24-hour clock time in the form HH:MM, or an hourly timer in the form'
15712 . ' 99:MM)',
15713 $self->_objClass . '->checkAttribValue',
15714 );
15715  
15716 } else {
15717  
15718 # $value is valid
15719 return $value;
15720 }
15721  
15722 } elsif ($type eq 'keycode') {
15723  
15724 my ($modValue, $shiftFlag);
15725  
15726 # Remove modifiers, so we can accept 'f1', 'ctrl f1', 'alt f1', 'shift alt f1', etc
15727 # (but we don't accept either 'shift f1' or 'alt-gr f1')
15728 # For keypresses that aren't Axmud standard keycodes (like the letter 'a', for example),
15729 # we accept 'ctrl a', etc but we don't accept 'a' (so that the user can type normally)
15730 $modValue = $value;
15731 if ($modValue =~ s/(shift\s+|alt_gr\s+)//g) {
15732  
15733 $shiftFlag = TRUE;
15734 }
15735  
15736 if (
15737 $modValue =~ s/(alt\s+|ctrl\s+)//g
15738 && (
15739 $axmud::CLIENT->ivExists('constKeycodeHash', $modValue)
15740 || length ($modValue) == 1
15741 )
15742 ) {
15743 # value is $valid
15744 return $value;
15745  
15746 # Otherwise just check it's a valid standard keycode
15747 } elsif ($shiftFlag || ! $axmud::CLIENT->ivExists('constKeycodeHash', $modValue)) {
15748  
15749 return $session->writeWarning(
15750 'Invalid attribute value for \'' . $attrib . '\' (not ' . $axmud::NAME_ARTICLE
15751 . ' standard keycode)',
15752 $self->_objClass . '->checkAttribValue',
15753 );
15754  
15755 } else {
15756  
15757 # $value is valid
15758 return $value;
15759 }
15760  
15761 } elsif ($type eq 'mode') {
15762  
15763 # Must check it's a valid trigger style mode: -2, -1, 0 or a positive integer
15764 if (! $axmud::CLIENT->intCheck($value, -2)) {
15765  
15766 return $session->writeWarning(
15767 'Invalid attribute value for \'' . $attrib . '\' (not a trigger style mode)',
15768 $self->_objClass . '->checkAttribValue',
15769 );
15770  
15771 } else {
15772  
15773 # $value is valid
15774 return $value;
15775 }
15776  
15777 } elsif ($type eq 'number') {
15778  
15779 # Check it's a positive number or 0
15780 if (! $axmud::CLIENT->floatCheck($value, 0)) {
15781  
15782 return $session->writeWarning(
15783 'Invalid attribute value for \'' . $attrib . '\' (not a number, 0 or above)',
15784 $self->_objClass . '->checkAttribValue',
15785 );
15786  
15787 } else {
15788  
15789 # $value is valid
15790 return $value;
15791 }
15792  
15793 } elsif ($type eq 'repeat_count') {
15794  
15795 # Check it's a real positive integer, or the value -1
15796 if (! $axmud::CLIENT->intCheck($value, -1) || $value == 0) {
15797  
15798 return $session->writeWarning(
15799 'Invalid attribute value for \'' . $attrib . '\' (not a repeat count)',
15800 $self->_objClass . '->checkAttribValue',
15801 );
15802  
15803 } else {
15804  
15805 # $value is valid
15806 return $value;
15807 }
15808  
15809 } elsif ($type eq 'style') {
15810  
15811 # Must check it's a valid trigger style: 0, 1 or 2
15812 if ($value ne '0' && $value ne '1' && $value ne '2') {
15813  
15814 return $session->writeWarning(
15815 'Invalid attribute value for \'' . $attrib . '\' (not a trigger style)',
15816 $self->_objClass . '->checkAttribValue',
15817 );
15818  
15819 } else {
15820  
15821 # $value is valid
15822 return $value;
15823 }
15824  
15825 } elsif ($type eq 'pattern') {
15826  
15827 # Check it's a valid regex
15828 if (defined $axmud::CLIENT->regexCheck($value)) {
15829  
15830 return $session->writeWarning(
15831 'Invalid attribute value for \'' . $attrib . '\' (not a valid pattern/regular'
15832 . ' expression)',
15833 $self->_objClass . '->checkAttribValue',
15834 );
15835  
15836 } else {
15837  
15838 # $value is valid
15839 return $value;
15840 }
15841  
15842 } elsif ($type eq 'instruction' || $type eq 'string' || $type eq 'substitution') {
15843  
15844 # All values of $value are valid
15845 return $value;
15846  
15847 } else {
15848  
15849 # Unrecognised $type
15850 return $session->writeWarning(
15851 'Invalid attribute type \'' . $type . '\'',
15852 $self->_objClass . '->checkAttribValue',
15853 );
15854 }
15855 }
15856  
15857 ##################
15858 # Accessors - set
15859  
15860 sub set_attribHash {
15861  
15862 # Called by GA::Generic::Cmd->addInterface
15863 #
15864 # Expected arguments
15865 # $session - The calling function's GA::Session
15866 #
15867 # Return values
15868 # 'undef' on improper arguments
15869 # 1 otherwise
15870  
15871 my ($self, $session, @list) = @_;
15872  
15873 # Local variables
15874 my (
15875 $modelObj,
15876 %attribHash,
15877 );
15878  
15879 # Check for improper arguments
15880 if (! defined $session || ! @list) {
15881  
15882 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_attribHash', @_);
15883 }
15884  
15885 # Get the corresponding interface model object
15886 $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $self->category);
15887  
15888 # @list is in the form (attribute, value, attribute, value...)
15889 do {
15890  
15891 my ($attrib, $value, $type, $checkValue);
15892  
15893 $attrib = shift @list;
15894 $value = shift @list;
15895  
15896 # Check that the attribute exists for this category of interface
15897 if ($modelObj->ivExists('attribTypeHash', $attrib)) {
15898  
15899 # It exists. Check that $value is the right kind of value
15900 $type = $modelObj->ivShow('attribTypeHash', $attrib);
15901 $checkValue = $self->checkAttribValue($session, $attrib, $value, $type);
15902 if (! defined $checkValue) {
15903  
15904 # Error message already displayed
15905 return undef;
15906  
15907 } else {
15908  
15909 # The value may have been modified (e.g. 1 becomes TRUE)
15910 $attribHash{$attrib} = $checkValue;
15911 }
15912 }
15913  
15914 } until (! @list);
15915  
15916 # Add key-value pairs to $self->attribHash, one at a time
15917 foreach my $key (keys %attribHash) {
15918  
15919 $self->ivAdd('attribHash', $key, $attribHash{$key});
15920 }
15921  
15922 return 1;
15923 }
15924  
15925 sub set_beforeAfterHashes {
15926  
15927 # Called by GA::Generic::Cmd->addInterface, ->modifyInterface
15928 #
15929 # Expected arguments
15930 # $session - The calling function's GA::Session
15931 # $beforeHashRef - Reference to a hash, whose key-value pairs should be added to
15932 # $self->beforeHash
15933 # $afterHashRef - Reference to a hash, whose key-value pairs should be added to
15934 # $self->afterHash
15935 #
15936 # Optional arguments (when called by ->modifyInterface)
15937 # $beforeRemoveHashRef - Reference to a hash, whose key-value pairs should be added to
15938 # $self->beforeHash
15939 # $afterRemoveHashRef - Reference to a hash, whose key-value pairs should be added to
15940 # $self->afterHash
15941 #
15942 # Return values
15943 # 'undef' on improper arguments
15944 # 1 otherwise
15945  
15946 my (
15947 $self, $session, $beforeHashRef, $afterHashRef,
15948 $beforeRemoveHashRef, $afterRemoveHashRef,
15949 $check,
15950 ) = @_;
15951  
15952 # Check for improper arguments
15953 if (
15954 ! defined $session || ! defined $beforeHashRef || ! defined $afterHashRef
15955 || defined $check
15956 ) {
15957 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_beforeAfterHashes', @_);
15958 }
15959  
15960 foreach my $name (keys %$beforeHashRef) {
15961  
15962 $self->ivAdd('beforeHash', $name, undef);
15963 }
15964  
15965 foreach my $name (keys %$afterHashRef) {
15966  
15967 $self->ivAdd('afterHash', $name, undef);
15968 }
15969  
15970 if ($beforeRemoveHashRef) {
15971  
15972 foreach my $name (keys %$beforeRemoveHashRef) {
15973  
15974 if ($self->ivExists('beforeHash', $name)) {
15975  
15976 $self->ivDelete('beforeHash', $name);
15977 }
15978 }
15979 }
15980  
15981 if ($afterRemoveHashRef) {
15982  
15983 foreach my $name (keys %$afterRemoveHashRef) {
15984  
15985 if ($self->ivExists('afterHash', $name)) {
15986  
15987 $self->ivDelete('afterHash', $name);
15988 }
15989 }
15990 }
15991  
15992 return 1;
15993 }
15994  
15995 ##################
15996 # Accessors - get
15997 }
15998  
15999 { package Games::Axmud::Generic::InterfaceCage;
16000  
16001 use strict;
16002 use warnings;
16003 use diagnostics;
16004  
16005 use Glib qw(TRUE FALSE);
16006  
16007 our @ISA = qw(Games::Axmud::Generic::Cage Games::Axmud);
16008  
16009 ##################
16010 # Constructors
16011  
16012 sub new {
16013  
16014 # Inherited by GA::Cage::Trigger->new, etc
16015 # Creates a new instance of a trigger, alias, macro, timer or hook cage
16016 #
16017 # Expected arguments
16018 # $session - The calling function's GA::Session (not stored as an IV)
16019 # $profName - The parent profile's name (e.g. matches the object's ->name)
16020 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
16021 #
16022 # Return values
16023 # 'undef' on improper arguments or if the cage already seems to exist
16024 # Blessed reference to the newly-created object on success
16025  
16026 my ($class, $session, $profName, $profCategory, $check) = @_;
16027  
16028 # Local variables
16029 my (
16030 $cageType, $name,
16031 @typeList,
16032 );
16033  
16034 # Check for improper arguments
16035 if (
16036 ! defined $session || ! defined $profName || ! defined $profCategory
16037 || defined $check
16038 ) {
16039 return $axmud::CLIENT->writeImproper($class . '->new', @_);
16040 }
16041  
16042 # Is this a trigger, alias, macro, timer or hook cage?
16043 @typeList = ('Trigger', 'Alias', 'Macro', 'Timer', 'Hook');
16044 OUTER: foreach my $item (@typeList) {
16045  
16046 if (index ($class, $item) > -1) {
16047  
16048 $cageType = lc($item);
16049 last OUTER;
16050 }
16051 }
16052  
16053 # Compose the cage's unique name
16054 $name = $cageType . '_' . $profCategory . '_' . $profName;
16055  
16056 # Check that $name is valid and not already in use by another profile
16057 if (! $axmud::CLIENT->nameCheck($name, 42)) {
16058  
16059 return $session->writeError(
16060 'Registry naming error: invalid name \'' . $name . '\'',
16061 $class . '->new',
16062 );
16063  
16064 } elsif ($session->ivExists('cageHash', $name)) {
16065  
16066 return $session->writeError(
16067 'Registry naming error: cage \'' . $name . '\' already exists',
16068 $class . '->new',
16069 );
16070 }
16071  
16072 # Setup
16073 my $self = {
16074 _objName => $name,
16075 _objClass => $class,
16076 _parentFile => 'otherprof',
16077 _parentWorld => $session->currentWorld->name,
16078 _privFlag => FALSE, # All IVs are public
16079  
16080 # Standard cage IVs
16081 # -----------------
16082  
16083 name => $name,
16084 cageType => $cageType,
16085 standardFlag => TRUE, # This is a built-in Axmud cage
16086 profName => $profName,
16087 profCategory => $profCategory,
16088  
16089 # Interface cage IVs
16090 # ------------------
16091  
16092 # Hash of interfaces in the form
16093 # $interfaceHash{interface_name} = blessed_reference_to_interface_object
16094 interfaceHash => {},
16095 };
16096  
16097 # Bless the object into existence
16098 bless $self, $class;
16099 return $self;
16100 }
16101  
16102 sub clone {
16103  
16104 # Creates a clone of an trigger, alias, macro, timer or hook cage
16105 #
16106 # Expected arguments
16107 # $session - The calling function's GA::Session (not stored as an IV)
16108 # $profName - The parent profile's name (e.g. matches the object's ->name)
16109 # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc)
16110 #
16111 # Return values
16112 # 'undef' on improper arguments or if the cage already seems to exist
16113 # Blessed reference to the newly-created object on success
16114  
16115 my ($self, $session, $profName, $profCategory, $check) = @_;
16116  
16117 # Local variables
16118 my (
16119 $name,
16120 %hash, %cloneHash,
16121 );
16122  
16123 # Check for improper arguments
16124 if (
16125 ! defined $session || ! defined $profName || ! defined $profCategory
16126 || defined $check
16127 ) {
16128 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
16129 }
16130  
16131 # Compose the cage's unique name
16132 $name = $self->cageType . '_' . $profCategory . '_' . $profName;
16133  
16134 # Check that $name is valid and not already in use by another profile
16135 if (! $axmud::CLIENT->nameCheck($name, 42)) {
16136  
16137 return $axmud::CLIENT->writeError(
16138 'Registry naming error: invalid name \'' . $name . '\'',
16139 $self->_objClass . '->clone',
16140 );
16141  
16142 } elsif ($session->ivExists('cageHash', $name)) {
16143  
16144 return $axmud::CLIENT->writeError(
16145 'Registry naming error: cage \'' . $name . '\' already exists',
16146 $self->_objClass . '->clone',
16147 );
16148 }
16149  
16150 # Setup
16151 my $clone = {
16152 _objName => $name,
16153 _objClass => $self->_objClass,
16154 _parentFile => 'otherprof',
16155 _parentWorld => undef,
16156 _privFlag => FALSE, # All IVs are public
16157  
16158 # Standard cage IVs
16159 # -----------------
16160  
16161 name => $name,
16162 cageType => $self->cageType,
16163 standardFlag => TRUE, # This is a built-in Axmud cage
16164 profName => $profName,
16165 profCategory => $profCategory,
16166  
16167 # Command cage IVs
16168 # ----------------
16169  
16170 interfaceHash => {$self->interfaceHash}, # Set below
16171 };
16172  
16173 # Bless the cloned object into existence
16174 bless $clone, $self->_objClass;
16175  
16176 # $self->interfaceHash contains a collection of blessed references to trigger/alias/macro/
16177 # timer/hook objects, each of which must be cloned, too
16178 %hash = $self->interfaceHash;
16179 if (%hash) {
16180  
16181 foreach my $interfaceName (keys %hash) {
16182  
16183 my ($interfaceObj, $newObj);
16184  
16185 $interfaceObj = $hash{$interfaceName};
16186 $newObj = $interfaceObj->clone($profName);
16187 if (! $newObj) {
16188  
16189 $session->writeWarning(
16190 'Error cloning the ' . $self->cageType . ' interface object while cloning'
16191 . ' the ' . $self->cageType . ' cage for the profile \'' . $profName . '\'',
16192 $self->_objClass . '->clone',
16193 );
16194  
16195 } else {
16196  
16197 $cloneHash{$newObj->name} = $newObj;
16198 }
16199 }
16200  
16201 if (%cloneHash) {
16202  
16203 # Set this object's IV
16204 $clone->{interfaceHash} = \%cloneHash;
16205 }
16206 }
16207  
16208 return $clone;
16209 }
16210  
16211 ##################
16212 # Methods
16213  
16214 ##################
16215 # Accessors - set
16216  
16217 ##################
16218 # Accessors - get
16219  
16220 # NB These methods set/return the cage's ACTUAL interface hash. To get/set values from this hash
16221 # AND/OR its inferiors, use the generic cage's ->ivXXX functions
16222 sub interfaceHash
16223 { my $self = shift; return %{$self->{interfaceHash}}; }
16224 }
16225  
16226 { package Games::Axmud::Generic::InterfaceModel;
16227  
16228 use strict;
16229 use warnings;
16230 use diagnostics;
16231  
16232 use Glib qw(TRUE FALSE);
16233  
16234 our @ISA = qw(Games::Axmud);
16235  
16236 ##################
16237 # Constructors
16238  
16239 ##################
16240 # Methods
16241  
16242 ##################
16243 # Accessors - set
16244  
16245 ##################
16246 # Accessors - get
16247  
16248 sub category
16249 { $_[0]->{category} }
16250  
16251 sub stimulusName
16252 { $_[0]->{stimulusName} }
16253 sub responseName
16254 { $_[0]->{responseName} }
16255  
16256 sub optionalAttribHash
16257 { my $self = shift; return %{$self->{optionalAttribHash}}; }
16258 sub attribTypeHash
16259 { my $self = shift; return %{$self->{attribTypeHash}}; }
16260 sub compulsorySwitchHash
16261 { my $self = shift; return %{$self->{compulsorySwitchHash}}; }
16262 sub optionalSwitchHash
16263 { my $self = shift; return %{$self->{optionalSwitchHash}}; }
16264 }
16265  
16266 { package Games::Axmud::Generic::MapWin;
16267  
16268 use strict;
16269 use warnings;
16270 use diagnostics;
16271  
16272 use Glib qw(TRUE FALSE);
16273  
16274 our @ISA = qw(
16275 Games::Axmud::Generic::GridWin Games::Axmud::Generic::Win Games::Axmud
16276 );
16277  
16278 ##################
16279 # Constructors
16280  
16281 # sub new {} # Defined in window objects which inherit this one
16282  
16283 ##################
16284 # Methods
16285  
16286 # Standard window object functions
16287  
16288 # sub winSetup {} # Inherited from GA::Generic::GridWin
16289  
16290 # sub winEnable {} # Inherited from GA::Generic::GridWin
16291  
16292 # sub winDisengage {} # Defined in window objects which inherit this one
16293  
16294 # sub winDestroy {} # Defined in window objects which inherit this one
16295  
16296 # sub winShowAll {} # Inherited from GA::Generic::Win
16297  
16298 # sub drawWidgets {} # Inherited from GA::Generic::Win
16299  
16300 # sub redrawWidgets {} # Inherited from GA::Generic::Win
16301  
16302 # Standard 'map' window object functions
16303  
16304 # sub winReset {} # Defined in window objects which inherit this one
16305  
16306 # sub winUpdate {} # Defined in window objects which inherit this one
16307  
16308 # ->signal_connects
16309  
16310 # Other functions
16311  
16312 ##################
16313 # Accessors - set
16314  
16315 ##################
16316 # Accessors - get
16317 }
16318  
16319 { package Games::Axmud::Generic::Mcp;
16320  
16321 use strict;
16322 use warnings;
16323 use diagnostics;
16324  
16325 use Glib qw(TRUE FALSE);
16326  
16327 our @ISA = qw(Games::Axmud);
16328  
16329 ##################
16330 # Constructors
16331  
16332 sub new {
16333  
16334 # Called by GA::Client->createSupportedMcpPackages and ->addPluginMcpPackages to create an
16335 # MCP package object, which handles one or more MCP messages
16336 #
16337 # Objects that inherit from this one should include at least their own ->msg function (but
16338 # should use the inherited version of all other functions in this generic object,
16339 # including ->new and ->clone)
16340 #
16341 # Expected arguments
16342 # $name - The name of the GCP package, e.g. 'mcp-negotiate-can'. Must conform to
16343 # MCP's package name rules (see the MCP spec for more information)
16344 #
16345 # Optional aguments
16346 # $minVersion - The minimum package version supported (e.g. 1.0, 2.0 etc). If not
16347 # specified or not a valid number (any decimal number greater than 0),
16348 # 1.0 is used
16349 # $maxVersion - The maximum package version supported (e.g. 1.0, 2.0 etc). If not
16350 # specified or not a valid number (any decimal number greater than 0),
16351 # 1.0 is used
16352 # $plugin - For MCP packages defined by a plugin, the plugin's main package
16353 # (declared in the file header). For Axmud-supported MCP packages,
16354 # should be 'undef'
16355 # @supplantList - An optional list of MCP package names for which Axmud should prefer to
16356 # use this MCP package, if the world supports both. Standard MCP
16357 # packages like 'mcp-negotiate' cannot be supplanted (specifically,
16358 # any package whose name begins 'mcp-' cannot be supplanted; the name
16359 # is ignored if present in this list)
16360 #
16361 # Return values
16362 # 'undef' on improper arguments
16363 # Blessed reference to the newly-created object on success
16364  
16365 my ($class, $name, $minVersion, $maxVersion, $plugin, @supplantList) = @_;
16366  
16367 # Local variables
16368 my (
16369 @modList,
16370 %checkHash,
16371 );
16372  
16373 # Check for improper arguments
16374 if (! defined $class || ! defined $name) {
16375  
16376 return $axmud::CLIENT->writeImproper($class . '->new', @_);
16377 }
16378  
16379 # Set the minimum/maximum versions, if not specified or if invalid values specified
16380 if (
16381 ! defined $minVersion
16382 || $minVersion eq '0'
16383 || ! $axmud::CLIENT->floatCheck($minVersion, 0)
16384 ) {
16385 $minVersion = '1.0';
16386 }
16387  
16388 if (
16389 ! defined $maxVersion
16390 || $maxVersion eq '0'
16391 || ! $axmud::CLIENT->floatCheck($maxVersion, 0)
16392 ) {
16393 $maxVersion = '1.0';
16394 }
16395  
16396 # Remove any 'official' packages (and any duplicate package names)from @supplantList
16397 foreach my $item (@supplantList) {
16398  
16399 if (! exists $checkHash{$item} && substr($item, 0, 4) ne 'mcp-') {
16400  
16401 push (@modList, $item);
16402 $checkHash{$item} = undef;
16403 }
16404 }
16405  
16406 # Setup
16407 my $self = {
16408 _objName => $name,
16409 _objClass => $class,
16410 _parentFile => undef,
16411 _parentWorld => undef,
16412 _privFlag => TRUE, # All IVs are private
16413  
16414 # IVs
16415 # ---
16416  
16417 # The name of the GCP package, e.g. 'mcp-negotiate-can'. Must conform to MCP's package
16418 # name rules (see the MCP spec for more information)
16419 name => $name,
16420 # For MCP packages defined by a plugin, the plugin's main package (declared in the file
16421 # header). For Axmud-supported MCP packages, should be 'undef'
16422 plugin => $plugin,
16423 # An optional list of MCP package names for which Axmud should prefer to use this MCP
16424 # package, if the world supports both
16425 supplantList => [@modList],
16426  
16427 # The minimum package version supported (e.g. 1.0, 2.0 etc)
16428 minVersion => $minVersion,
16429 # The maximum package version supported (e.g. 1.0, 2.0 etc)
16430 maxVersion => $maxVersion,
16431 # The highest version that's supported by both the server and client (set by
16432 # a call to $self->set_useVersion from GA::Session->detectMCP or
16433 # ->processMcpMsg)
16434 useVersion => undef,
16435  
16436 # Any values which particular kinds of MCP package need to store, can be stored in this
16437 # hash
16438 dataHash => {},
16439 };
16440  
16441 # Bless the object into existence
16442 bless $self, $class;
16443 return $self;
16444 }
16445  
16446 sub clone {
16447  
16448 # Called by GA::Session->detectMCP to clone an MCP package object stored in
16449 # GA::Client->mcpPackageHash (with default settings, and whose code is never executed)
16450 # into an MCP package object stored in GA::Session->mcpPackageHash (with custom settings,
16451 # and whose code can be executed when MCP messages are received)
16452 #
16453 # Expected arguments
16454 # $session - The GA::Session which will store the cloned MCP package object
16455 #
16456 # Return values
16457 # 'undef' on improper arguments
16458 # Blessed reference to the newly-created object on success
16459  
16460 my ($self, $session, $check) = @_;
16461  
16462 # Check for improper arguments
16463 if (! defined $session || defined $check) {
16464  
16465 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
16466 }
16467  
16468 # Setup
16469 my $clone = {
16470 _objName => $self->_objName,
16471 _objClass => $self->_objClass,
16472 _parentFile => undef,
16473 _parentWorld => $session->currentWorld->name,
16474 _privFlag => TRUE, # All IVs are private
16475  
16476 name => $self->name,
16477 plugin => $self->plugin,
16478 supplantList => [$self->supplantList],
16479 minVersion => $self->minVersion,
16480 maxVersion => $self->maxVersion,
16481 useVersion => undef,
16482  
16483 dataHash => {},
16484 };
16485  
16486 # Bless the cloned object into existence
16487 bless $clone, $self->_objClass;
16488 return $clone;
16489 }
16490  
16491 ##################
16492 # Methods
16493  
16494 sub msg {
16495  
16496 # Called by GA::Session->processMcpMsg
16497 # This generic function does nothing, except to check that the message belongs to this
16498 # package
16499 #
16500 # Expected arguments
16501 # $session - The calling GA::Session
16502 # $msg - The MCP message name, e.g. 'mcp-negotiate-can'
16503 #
16504 # Optional arguments
16505 # %hash - A hash of key-value pairs which accompany the MCP message (may be an
16506 # empty hash)
16507 #
16508 # Return values
16509 # 'undef' on improper arguments or if there's an error processing the message
16510 # 1 if the message is processed successfully
16511  
16512 my ($self, $session, $msg, %hash) = @_;
16513  
16514 # Local variables
16515 my $name;
16516  
16517 # Check for improper arguments
16518 if (! defined $session || ! defined $msg) {
16519  
16520 return $axmud::CLIENT->writeImproper($self->_objClass . '->msg', @_);
16521 }
16522  
16523 # Check that the MCP message actually belongs to this package
16524 $name = $self->name;
16525 if (! ($msg =~ m/^$name\-/)) {
16526  
16527 return undef;
16528 }
16529  
16530 # (Add your own code here)
16531  
16532 return 1;
16533 }
16534  
16535 ##################
16536 # Accessors - set
16537  
16538 sub add_scalar {
16539  
16540 # Can be called by anything to add a key-value pair to $self->dataHash, using a scalar value
16541 # (which can be 'undef')
16542 # The scalar value is stored as a scalar value and can be retrieved with a call to
16543 # $self->get_scalar()
16544  
16545 my ($self, $key, $scalar, $check) = @_;
16546  
16547 # Check for improper arguments
16548 if (! defined $key || defined $check) {
16549  
16550 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_scalar', @_);
16551 }
16552  
16553 $self->ivPoke('dataHash', $key, $scalar);
16554  
16555 return 1;
16556 }
16557  
16558 sub get_scalar {
16559  
16560 my ($self, $key, $check) = @_;
16561  
16562 # Check for improper arguments
16563 if (! defined $key || defined $check) {
16564  
16565 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_scalar', @_);
16566 }
16567  
16568 return $self->ivShow('dataHash', $key);
16569 }
16570  
16571 sub add_list {
16572  
16573 # Can be called by anything to add a key-value pair to $self->dataHash, using a list value
16574 # (which can be an empty list)
16575 # The list value is stored as a list reference and can be retrieved with a call to
16576 # $self->get_list()
16577  
16578 my ($self, $key, @list) = @_;
16579  
16580 # Check for improper arguments
16581 if (! defined $key) {
16582  
16583 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_list', @_);
16584 }
16585  
16586 $self->ivPoke('dataHash', $key, \@list);
16587  
16588 return 1;
16589 }
16590  
16591 sub get_list {
16592  
16593 my ($self, $key, $check) = @_;
16594  
16595 # Local variables
16596 my $listRef;
16597  
16598 # Check for improper arguments
16599 if (! defined $key || defined $check) {
16600  
16601 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_list', @_);
16602 }
16603  
16604 $listRef = $self->ivShow('dataHash', $key);
16605 if (ref $listRef eq 'ARRAY') {
16606  
16607 return @$listRef;
16608  
16609 } else {
16610  
16611 # Emergency failsafe - return the reference itself
16612 return $listRef;
16613 }
16614 }
16615  
16616 sub add_hash {
16617  
16618 # Can be called by anything to add a key-value pair to $self->dataHash, using a hash value
16619 # (which can be empty hash)
16620 # The hash value is stored as a hash reference (and can be retrieved with a call to
16621 # $self->get_hash()
16622  
16623 my ($self, $key, %hash) = @_;
16624  
16625 # Check for improper arguments
16626 if (! defined $key) {
16627  
16628 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_hash', @_);
16629 }
16630  
16631 $self->ivPoke('dataHash', $key, \%hash);
16632  
16633 return 1;
16634 }
16635  
16636 sub get_hash {
16637  
16638 my ($self, $key, $check) = @_;
16639  
16640 # Local variables
16641 my $hashRef;
16642  
16643 # Check for improper arguments
16644 if (! defined $key || defined $check) {
16645  
16646 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_hash', @_);
16647 }
16648  
16649 $hashRef = $self->ivShow('dataHash', $key);
16650 if (ref $hashRef eq 'HASH') {
16651  
16652 return %$hashRef;
16653  
16654 } else {
16655  
16656 # Emergency failsafe - return the reference itself
16657 return $hashRef;
16658 }
16659 }
16660  
16661 sub del_key {
16662  
16663 my ($self, $key, $check) = @_;
16664  
16665 # Check for improper arguments
16666 if (! defined $key || defined $check) {
16667  
16668 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_key', @_);
16669 }
16670  
16671 $self->ivDelete('dataHash', $key);
16672  
16673 return 1;
16674 }
16675  
16676 sub set_useVersion {
16677  
16678 my ($self, $version, $check) = @_;
16679  
16680 # Check for improper arguments
16681 if (! defined $version || defined $check) {
16682  
16683 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_useVersion', @_);
16684 }
16685  
16686 $self->ivPoke('useVersion', $version);
16687  
16688 return 1;
16689 }
16690  
16691 ##################
16692 # Accessors - get
16693  
16694 sub name
16695 { $_[0]->{name} }
16696 sub plugin
16697 { $_[0]->{plugin} }
16698 sub supplantList
16699 { my $self = shift; return @{$self->{supplantList}}; }
16700  
16701 sub minVersion
16702 { $_[0]->{minVersion} }
16703 sub maxVersion
16704 { $_[0]->{maxVersion} }
16705 sub useVersion
16706 { $_[0]->{useVersion} }
16707  
16708 sub dataHash
16709 { my $self = shift; return %{$self->{dataHash}}; }
16710 }
16711  
16712 { package Games::Axmud::Generic::ModelObj;
16713  
16714 use strict;
16715 use warnings;
16716 use diagnostics;
16717  
16718 use Glib qw(TRUE FALSE);
16719  
16720 our @ISA = qw(Games::Axmud);
16721  
16722 ##################
16723 # Constructors
16724  
16725 sub new {
16726  
16727 # Prepare a new instance of the generic model object (which is never blessed into existence)
16728 # NB Room model objects do inherit from this object, but don't call this function; they
16729 # initialise all of their own IVs
16730 # NB Exit model objects don't inherit from this object
16731 #
16732 # Expected arguments
16733 # $session - The parent GA::Session (not stored as an IV)
16734 # $name - A name for the object. For room objects, this is the same as the room's
16735 # brief description. For regions, ->name is the only place $name is
16736 # stored. For everything else, ->noun is also set to ->name
16737 # - (NB If $name is longer than 32 characters, it is shortened)
16738 # $category - 'region', 'room', 'weapon', 'armour', 'garment', 'char', 'minion',
16739 # 'sentient', 'creature', 'portable', 'decoration' or 'custom' (but room
16740 # model objects don't call this function)
16741 #
16742 # Return values
16743 # 'undef' on improper arguments
16744 # Otherwise returns $self, a hash that will be blessed into existence by the inheriting
16745 # object
16746  
16747 my ($class, $session, $name, $category, $check) = @_;
16748  
16749 # Check for improper arguments
16750 if (
16751 ! defined $class || ! defined $session || ! defined $name || ! defined $category
16752 || defined $check
16753 ) {
16754 return $axmud::CLIENT->writeImproper($class . '->new', @_);
16755 }
16756  
16757 # Check that $category is valid
16758 if (! $axmud::CLIENT->ivExists('constModelTypeHash', $category)) {
16759  
16760 return $axmud::CLIENT->writeError(
16761 'Invalid model object category \'' . $category . '\'',
16762 $class . '->new',
16763 );
16764 }
16765  
16766 # If $name is longer than 32 characters, shorten it (and add an ellipsis)
16767 if (length ($name) > 32) {
16768  
16769 $name = substr($name, 0, 29) . '...';
16770 }
16771  
16772 # Setup
16773 my $self = {
16774 _objName => $name,
16775 _objClass => $class,
16776 _parentFile => undef, # Set by the calling function
16777 _parentWorld => undef, # Set by the calling function
16778 _privFlag => FALSE, # All IVs are public
16779  
16780 # NB If any of these IVs are changed, GA::Generic::ModelObj->convertCategory must be
16781 # changed, too
16782  
16783 # Group 1 IVs (all objects)
16784 # -------------------------
16785  
16786 # The object's actual name, e.g. 'orc' (can include spaces)
16787 name => $name,
16788 # What kind of object this is ('char', 'portable', 'custom' etc)
16789 category => $category,
16790 # Flag set to TRUE if this object is in $session's world model (in which case, the
16791 # object is a 'model object')
16792 # Flag set to FALSE if this object is not in $session's world model (in which case, the
16793 # object is a 'non-model object')
16794 # All objects which call this function have their ->modelFlag set to FALSE, initially
16795 modelFlag => FALSE,
16796 # For model objects, a unique number ('undef' for non-model objects)
16797 number => undef,
16798 # Number of the model object of the room where this object is found, the shop where this
16799 # object is bought, the NPC from which this object is liberated, or the region in
16800 # which this object wanders ('undef' for non-model objects, or if there is nothing
16801 # resembling a parent)
16802 parent => undef,
16803 # Hash of numbers of model objects for which this is the ->parent. Hash in the form
16804 # $childHash{number} = 'undef'
16805 childHash => {},
16806  
16807 # These variables are the same for each kind of object (the same for all weapons, the
16808 # same for all decorations, etc)
16809  
16810 # Flag set to FALSE if this object is an abstract concept ('region' and 'room', possibly
16811 # 'custom'), TRUE if this object is a concrete thing (everything else, possibly
16812 # including 'custom')
16813 concreteFlag => FALSE,
16814 # Flag set to TRUE if this object is alive, FALSE if not
16815 aliveFlag => FALSE,
16816 # Flag set to TRUE if this object is sentient (capable of speech, in theory), FALSE if
16817 # not
16818 sentientFlag => FALSE,
16819 # Flag set to TRUE if the object can be carried (in theory), FALSE if not
16820 portableFlag => FALSE,
16821 # Flag set to TRUE if the object can be bought and sold (in theory), FALSE if not
16822 saleableFlag => FALSE,
16823  
16824 # Private properties for this object, in a customisable hash
16825 privateHash => {},
16826  
16827 # If the world's source code is available on the user's computer (i.e. the world model
16828 # object's ->mudlibPath IV is set), and if the file matching this object is known,
16829 # the path to that file (relative to the directory stored in ->mudLibPath)
16830 sourceCodePath => undef,
16831 # Notes on this object, if the user wants to add them. Each value in the list is a
16832 # separate line for display
16833 notesList => [],
16834 };
16835  
16836 # Group 2 IVs (all objects except 'region' and 'room')
16837 # ----------------------------------------------------
16838  
16839 if ($category ne 'region' && $category ne 'room') {
16840  
16841 # A word string most likely to be the main noun (usually a single word, e.g. 'sword')
16842 $self->{noun} = undef,
16843 # A possible description of the object. For example, with 'a huge hairy orc', possible
16844 # noun tags include 'orc', 'hairy orc', 'huge hairy orc' and 'huge hairy orc'
16845 # Is set as required; the default setting is the same as $self->noun
16846 $self->{nounTag} = undef,
16847 # List of other words which are known to be nouns for this object
16848 $self->{otherNounList} = [],
16849 # List of other words which are known to be adjectives describing this object
16850 $self->{adjList} = [],
16851 # List of pseudo-adjectives (single words like 'suspicious' reduced from a longer string
16852 # like 'slightly suspicious-looking') describing this object
16853 $self->{pseudoAdjList} = [],
16854 # List of root adjectives describing this object (for languages that use declined
16855 # adjectives; English isn't one of them)
16856 $self->{rootAdjList} = [],
16857 # Words describing the object which aren't known nouns or adjectives
16858 $self->{unknownWordList} = [],
16859 # A number representing how many there of this object there are; usually set to 1
16860 $self->{multiple} = 1,
16861 # How the object appears in verbose room descriptions, minus any initial articles
16862 $self->{baseString} = undef,
16863 # Description for the object, if known (e.g. 'A magnificent gleaming sword, perfect for
16864 # chopping up trolls')
16865 $self->{descrip} = undef,
16866  
16867 # Two IVs for non-model objects used with the Inventory task (set to 'undef' when used
16868 # by anything else)
16869  
16870 # If this object is contained in another one, the model number of the container
16871 $self->{container} = undef,
16872 # How this object is possessed ('wield', 'hold', 'wear', 'carry', 'sack', 'misc')
16873 $self->{inventoryType} = undef,
16874 }
16875  
16876 # Group 3 IVs ('character', 'minion', 'sentient', 'creature' and optionally 'custom')
16877 # -----------------------------------------------------------------------------------
16878  
16879 # (Group 3 IVs are for available for use in any code you write to handle attacks)
16880 if (
16881 $category eq 'character' || $category eq 'minion' || $category eq 'sentient'
16882 || $category eq 'creature' || $category eq 'custom'
16883 ) {
16884 # The current status of the fight with this object:
16885 # 'waiting' - the fight hasn't started yet (but will soon)
16886 # 'alive' - the target is alive
16887 # 'kill' - the target is dead
16888 # 'flee' - the target has run away in a direction that can be followed
16889 # 'escape' - the target has run away, and can't be pursued for some reason
16890 # The current status of the interaction with this object:
16891 # 'waiting' - the interaction hasn't started yet (but will soon)
16892 # 'interact' - the target is interacting (and alive)
16893 # 'finish' - the interaction has finished
16894 # 'flee' - the target has run away in a direction that can be followed
16895 # 'escape' - the target has run away, and can't be pursued for some reason
16896 $self->{targetStatus} = undef;
16897 # What kind of attack this attack: 'fight' for a fight, and 'interaction' for an
16898 # interaction
16899 $self->{targetType} = undef;
16900 # For targets who move after a fight starts. The path from the original location to the
16901 # target's presumed current location, e.g. 'n;nw;w'
16902 $self->{targetPath} = undef;
16903 # For targets who move after a fight starts. The target's presumed location in the
16904 # world (the world model number of a room). Set to 'undef' if unknown
16905 $self->{targetRoomNum} = undef;
16906  
16907 # Is the object listed separately when the user types a look/glance command, or is it
16908 # only apparent that the object exists from a description of something else? (Group 4
16909 # IV for inanimate objects)
16910 # Flag set to TRUE if the object is listed separately, FALSE if not
16911 $self->{explicitFlag} = TRUE;
16912  
16913 # Flag that can be set to TRUE, if your code needs to remember which objects in a room
16914 # have been attacked
16915 $self->{alreadyAttackedFlag}
16916 = FALSE;
16917 }
16918  
16919 # Group 4 IVs ('weapon', 'armour', 'garment', 'portable', 'decoration', optionally 'custom')
16920 # ------------------------------------------------------------------------------------------
16921  
16922 if (
16923 $category eq 'weapon' || $category eq 'armour' || $category eq 'garment'
16924 || $category eq 'portable' || $category eq 'decoration' || $category eq 'custom'
16925 ) {
16926 # Is the object listed separately when the user types a look/glance command, or is it
16927 # only apparent that the object exists from a description of something else? (Group 3
16928 # IV for living beings)
16929 # Flag set to TRUE if the object is listed separately, FALSE if not
16930 $self->{explicitFlag} = TRUE;
16931  
16932 # Object's weight (if known)
16933 $self->{weight} = undef;
16934 # Character's stat bonuses or penalties when using this object
16935 $self->{bonusHash} = {};
16936  
16937 # Condition of the object (a number in the range 0-100; 'undef' if unknown, or if not
16938 # used in this world)
16939 $self->{condition} = undef;
16940 # The Condition task uses this flag to help it set an object's current condition
16941 $self->{conditionChangeFlag}
16942 = FALSE;
16943 # Flag set to TRUE if this object is fixable/repairable), FALSE if not (or if unknown)
16944 $self->{fixableFlag} = FALSE;
16945  
16946 # Flag set to TRUE if sellable, FALSE if not (or if unknown). This flag tells you
16947 # whether this particular object can be sold; $self->saleableFlag, a group 1 IV, tells
16948 # you whether objects of this ->category can be sold, or not)
16949 $self->{sellableFlag} = FALSE;
16950 # The highest value of the object that's been noticed when buying it ('undef' if value
16951 # unknown)
16952 $self->{buyValue} = undef;
16953 # The highest value of the object that's been noticed when selling it ('undef' if value
16954 # unknown)
16955 $self->{sellValue} = undef;
16956  
16957 # Flag set to TRUE if this object can only be used by certain guilds, races or indeed
16958 # characters
16959 $self->{exclusiveFlag} = FALSE;
16960 # A hash of guilds, races, named chars etc allowed to use this object. Hash in the form
16961 # ->exclusionHash{profile_name) = undef
16962 $self->{exclusiveHash} = {};
16963 }
16964  
16965 # The generic model object is never actually blessed into existence
16966 return $self;
16967 }
16968  
16969 ##################
16970 # Methods
16971  
16972 ##################
16973 # Accessors - set
16974  
16975 ##################
16976 # Accessors - get
16977  
16978 # Group 1 IVs (all objects)
16979 sub name
16980 { $_[0]->{name} }
16981 sub category
16982 { $_[0]->{category} }
16983 sub modelFlag
16984 { $_[0]->{modelFlag} }
16985 sub number
16986 { $_[0]->{number} }
16987 sub parent
16988 { $_[0]->{parent} }
16989 sub childHash
16990 { my $self = shift; return %{$self->{childHash}}; }
16991  
16992 sub concreteFlag
16993 { $_[0]->{concreteFlag} }
16994 sub aliveFlag
16995 { $_[0]->{aliveFlag} }
16996 sub sentientFlag
16997 { $_[0]->{sentientFlag} }
16998 sub portableFlag
16999 { $_[0]->{portableFlag} }
17000 sub saleableFlag
17001 { $_[0]->{saleableFlag} }
17002  
17003 sub privateHash
17004 { my $self = shift; return %{$self->{privateHash}}; }
17005  
17006 sub sourceCodePath
17007 { $_[0]->{sourceCodePath} }
17008 sub notesList
17009 { my $self = shift; return @{$self->{notesList}}; }
17010  
17011 # Group 2 IVs (all objects except 'region' and 'room')
17012 sub noun
17013 { $_[0]->{noun} }
17014 sub nounTag
17015 { $_[0]->{nounTag} }
17016 sub otherNounList
17017 { my $self = shift; return @{$self->{otherNounList}}; }
17018 sub adjList
17019 { my $self = shift; return @{$self->{adjList}}; }
17020 sub pseudoAdjList
17021 { my $self = shift; return @{$self->{pseudoAdjList}}; }
17022 sub rootAdjList
17023 { my $self = shift; return @{$self->{rootAdjList}}; }
17024 sub unknownWordList
17025 { my $self = shift; return @{$self->{unknownWordList}}; }
17026 sub multiple
17027 { $_[0]->{multiple} }
17028 sub baseString
17029 { $_[0]->{baseString} }
17030 sub descrip
17031 { $_[0]->{descrip} }
17032  
17033 sub container
17034 { $_[0]->{container} }
17035 sub inventoryType
17036 { $_[0]->{inventoryType} }
17037  
17038 # Group 3 IVs ('character', 'minion', 'sentient', 'creature' and optionally 'custom')
17039 sub targetStatus
17040 { $_[0]->{targetStatus} }
17041 sub targetType
17042 { $_[0]->{targetType} }
17043 sub targetPath
17044 { $_[0]->{targetPath} }
17045 sub targetRoomNum
17046 { $_[0]->{targetRoomNum} }
17047  
17048 sub explicitFlag
17049 { $_[0]->{explicitFlag} } # Also a group 4 IV
17050  
17051 sub alreadyAttackedFlag
17052 { $_[0]->{alreadyAttackedFlag} }
17053  
17054 # Group 4 IVs ('weapon', 'armour', 'garment', 'portable', 'decoration', optionally 'custom')
17055 # sub explicitFlag
17056 # { $_[0]->{explicitFlag} } # Also a group 3 IV
17057 sub weight
17058 { $_[0]->{weight} }
17059 sub bonusHash
17060 { my $self = shift; return %{$self->{bonusHash}}; }
17061  
17062 sub condition
17063 { $_[0]->{condition} }
17064 sub conditionChangeFlag
17065 { $_[0]->{conditionChangeFlag} }
17066 sub fixableFlag
17067 { $_[0]->{fixableFlag} }
17068  
17069 sub sellableFlag
17070 { $_[0]->{sellableFlag} }
17071 sub buyValue
17072 { $_[0]->{buyValue} }
17073 sub sellValue
17074 { $_[0]->{sellValue} }
17075  
17076 sub exclusiveFlag
17077 { $_[0]->{exclusiveFlag} }
17078 sub exclusiveHash
17079 { my $self = shift; return %{$self->{exclusiveHash}}; }
17080 }
17081  
17082 { package Games::Axmud::Generic::OtherWin;
17083  
17084 use strict;
17085 use warnings;
17086 use diagnostics;
17087  
17088 use Glib qw(TRUE FALSE);
17089  
17090 our @ISA = qw(
17091 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
17092 );
17093  
17094 ##################
17095 # Constructors
17096  
17097 sub new {
17098  
17099 # Called by GA::Generic::Win->createFreeWin
17100 # Creates a new instance of an 'other' window (most window objects inheriting from this
17101 # generic object share the same ->new function, with only standard IVs)
17102 #
17103 # Expected arguments
17104 # $number - Unique number for this window object
17105 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
17106 # should be created
17107 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
17108 # 'free' window object. When this window opens/closes, the owner is
17109 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
17110 # functions
17111 #
17112 # Optional arguments
17113 # $session - The GA::Session from which this function was called. 'undef' if the
17114 # calling function didn't specify a session and $owner's ->session IV
17115 # is also 'undef'
17116 # $title - Ignored if set (all 'other' windows define their own title)
17117 # $editObj - Ignored if set
17118 # $tempFlag - Ignored if set
17119 # %configHash - Hash containing any number of key-value pairs needed for this
17120 # particular 'other' window; set to an empty hash if not required
17121 # - This type of window object recognises these initialisation settings:
17122 #
17123 # ...
17124 #
17125 # Return values
17126 # 'undef' on improper arguments
17127 # Blessed reference to the newly-created object on success
17128  
17129 my (
17130 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
17131 %configHash,
17132 ) = @_;
17133  
17134 # Check for improper arguments
17135 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
17136  
17137 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17138 }
17139  
17140 # Setup
17141 my $self = {
17142 _objName => 'other_win_' . $number,
17143 _objClass => $class,
17144 _parentFile => undef, # No parent file object
17145 _parentWorld => undef, # No parent file object
17146 _privFlag => TRUE, # All IVs are private
17147  
17148 # Standard window object IVs
17149 # --------------------------
17150  
17151 # Unique number for this window object
17152 number => $number,
17153 # The window category - 'grid' or 'free'
17154 winCategory => 'free',
17155 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
17156 winType => 'other',
17157 # A name for the window (can be unique to this type of window object, or can be the
17158 # same as ->winType)
17159 winName => 'other',
17160 # The GA::Obj::Workspace object for the workspace in which this window is created
17161 workspaceObj => $workspaceObj,
17162 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
17163 # object. When this window opens/closes, the owner is informed via calls to its
17164 # ->add_childFreeWin / ->del_childFreeWin functions
17165 owner => $owner,
17166 # The GA::Session from which this function was called. 'undef' if the calling function
17167 # didn't specify a session and $owner's ->session IV is also 'undef'
17168 session => $session,
17169 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
17170 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
17171 # displayed in a 'dialogue' window)
17172 pseudoCmdMode => 'win_error',
17173  
17174 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
17175 # parent 'main' window's Gtk3::Window
17176 # The code should use this IV when it wants to do something to the window itself
17177 # (minimise it, make it active, etc)
17178 winWidget => undef,
17179 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
17180 # the parent GA::Table::PseudoWin table object
17181 # The code should use this IV when it wants to add, modify or remove widgets inside the
17182 # window itself
17183 winBox => undef,
17184 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
17185 # FALSE if not
17186 enabledFlag => FALSE,
17187 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
17188 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
17189 visibleFlag => TRUE,
17190 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
17191 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
17192 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
17193 childFreeWinHash => {},
17194 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
17195 # window is informed via a call to $self->del_childFreeWin
17196 # When the child is destroyed, this window might want to call some of its own functions
17197 # to update various widgets and/or IVs, in which case this window adds an entry to
17198 # this hash; a hash in the form
17199 # $childDestroyHash{unique_number} = list_reference
17200 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
17201 # reference to a list in groups of 2, in the form
17202 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
17203 childDestroyHash => {},
17204  
17205 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
17206 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
17207 # area)
17208 packingBox => undef,
17209  
17210 # Standard IVs for 'free' windows
17211  
17212 # The window's default size, in pixels
17213 widthPixels => $axmud::CLIENT->customFreeWinWidth,
17214 heightPixels => $axmud::CLIENT->customFreeWinHeight,
17215 # Default border/item spacing sizes used in the window, in pixels
17216 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
17217 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
17218  
17219 # A string to use as the window title
17220 title => $axmud::SCRIPT . ' window',
17221 # Hash containing any number of key-value pairs needed for this particular 'config'
17222 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
17223 # name and type. Set to an empty hash if not required
17224 configHash => {%configHash},
17225 };
17226  
17227 # Bless the object into existence
17228 bless $self, $class;
17229  
17230 return $self;
17231 }
17232  
17233 # Standard window object functions
17234  
17235 # sub winSetup {} # Inherited from GA::Generic::FreeWin
17236  
17237 # sub winEnable {} # Inherited from GA::Generic::FreeWin
17238  
17239 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
17240  
17241 # sub winDestroy {} # Inherited from GA::Generic::FreeWin
17242  
17243 # sub winShowAll {} # Inherited from GA::Generic::Win
17244  
17245 # sub drawWidgets {} # Inherited from GA::Generic::Win
17246  
17247 # sub redrawWidgets {} # Inherited from GA::Generic::Win
17248  
17249 # ->signal_connects
17250  
17251 # Other functions
17252  
17253 ##################
17254 # Methods
17255  
17256 ##################
17257 # Accessors - set
17258  
17259 ##################
17260 # Accessors - get
17261 }
17262  
17263 { package Games::Axmud::Generic::Plugin::Cmd;
17264  
17265 # NB Plugin client commands can have the same name as existing client commands. When the
17266 # plugin is loaded, the existing command is replaced for as long as the plugin is enabled.
17267  
17268 use strict;
17269 use warnings;
17270 use diagnostics;
17271  
17272 use Glib qw(TRUE FALSE);
17273  
17274 our @ISA = qw(Games::Axmud::Generic::Cmd Games::Axmud);
17275  
17276 ##################
17277 # Constructors
17278  
17279 ##################
17280 # Methods
17281  
17282 ##################
17283 # Accessors - set
17284  
17285 ##################
17286 # Accessors - get
17287 }
17288  
17289 { package Games::Axmud::Generic::Profile;
17290  
17291 use strict;
17292 use warnings;
17293 use diagnostics;
17294  
17295 use Glib qw(TRUE FALSE);
17296  
17297 our @ISA = qw(Games::Axmud);
17298  
17299 ##################
17300 # Constructors
17301  
17302 ##################
17303 # Methods
17304  
17305 sub cloneInitTaskList {
17306  
17307 # Called by $self->clone immediately after cloning this profile from another
17308 # Clones task objects in the original profile's initial tasklist
17309 #
17310 # Expected arguments
17311 # $original - The original profile object, from which this object was cloned
17312 #
17313 # Return values
17314 # 'undef' on improper arguments
17315 # 1 otherwise
17316  
17317 my ($self, $original, $check) = @_;
17318  
17319 # Local variables
17320 my (
17321 @taskList,
17322 %taskHash,
17323 );
17324  
17325 # Check for improper arguments
17326 if (! defined $original || defined $check) {
17327  
17328 return $axmud::CLIENT->writeImproper($self->_objClass . '->new', @_);
17329 }
17330  
17331 # Import the original profile's initial tasklist
17332 foreach my $name ($original->initTaskOrderList) {
17333  
17334 my ($oldObj, $newObj);
17335  
17336 $oldObj = $original->ivShow('initTaskHash', $name);
17337 $newObj = $oldObj->clone('initial', $self->name, $self->category);
17338 if ($newObj) {
17339  
17340 push (@taskList, $newObj);
17341 $taskHash{$newObj->uniqueName} = $newObj;
17342 }
17343 }
17344  
17345 # Update IVs
17346 if (@taskList) {
17347  
17348 $self->ivPoke('initTaskHash', %taskHash);
17349 $self->ivPoke('initTaskOrderList', @taskList);
17350 }
17351  
17352 return 1;
17353 }
17354  
17355 ##################
17356 # Accessors - set
17357  
17358 ##################
17359 # Accessors - get
17360  
17361 sub name
17362 { $_[0]->{name} }
17363 sub category
17364 { $_[0]->{category} }
17365 sub parentWorld
17366 { $_[0]->{parentWorld} }
17367  
17368 sub initTaskHash
17369 { my $self = shift; return %{$self->{initTaskHash}}; }
17370 sub initTaskOrderList
17371 { my $self = shift; return @{$self->{initTaskOrderList}}; }
17372 sub initTaskTotal
17373 { $_[0]->{initTaskTotal} }
17374 sub initScriptHash
17375 { my $self = shift; return %{$self->{initScriptHash}}; }
17376 sub initScriptOrderList
17377 { my $self = shift; return @{$self->{initScriptOrderList}}; }
17378 sub initMission
17379 { $_[0]->{initMission} }
17380 sub initCmdList
17381 { my $self = shift; return @{$self->{initCmdList}}; }
17382  
17383 sub setupCompleteFlag
17384 { $_[0]->{setupCompleteFlag} }
17385 sub notepadList
17386 { my $self = shift; return @{$self->{notepadList}}; }
17387 sub privateHash
17388 { my $self = shift; return %{$self->{privateHash}}; }
17389 }
17390  
17391 { package Games::Axmud::Generic::Strip;
17392  
17393 use strict;
17394 use warnings;
17395 use diagnostics;
17396  
17397 use Glib qw(TRUE FALSE);
17398  
17399 our @ISA = qw(Games::Axmud);
17400  
17401 ##################
17402 # Constructors
17403  
17404 sub new {
17405  
17406 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
17407 # Generic function to create this strip object (most objects inheriting from this one will
17408 # use their own ->new function)
17409 #
17410 # Expected arguments
17411 # $number - The strip object's number within the parent window (matches
17412 # GA::Win::Internal->stripCount, or -1 for a temporary strip object
17413 # created to access its default IVs)
17414 # $winObj - The parent window object (GA::Win::Internal). 'temp' for temporary strip
17415 # objects
17416 #
17417 # Optional arguments
17418 # %initHash - A hash containing arbitrary data to use as the strip object's
17419 # initialisation settings. The strip object should use default
17420 # initialisation settings unless it can succesfully interpret one or more
17421 # of the key-value pairs in the hash, if there are any
17422 # - This type of strip object recognises these initialisation settings:
17423 #
17424 # 'some_string' - 'some_value'
17425 # 'some_string_2' - 'some_value'
17426 # ... - ...
17427 #
17428 # Return values
17429 # 'undef' on improper arguments
17430 # Blessed reference to the newly-created object on success
17431  
17432 my ($class, $number, $winObj, %initHash) = @_;
17433  
17434 # Local variables
17435 my %modHash;
17436  
17437 # Check for improper arguments
17438 if (! defined $class || ! defined $number || ! defined $winObj) {
17439  
17440 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17441 }
17442  
17443 # # Default initialisation settings
17444 # %modHash = (
17445 # 'some_string' => 'some_value',
17446 # 'some_string_2' => 'some_value',
17447 # );
17448 #
17449 # # Interpret the initialisation settings in %initHash, if any
17450 # foreach my $key (keys %modHash) {
17451 #
17452 # if (exists $initHash{$key}) {
17453 #
17454 # if ($key eq 'some_flag_set_to_TRUE_or_FALSE') {
17455 #
17456 # if ($initHash{$key}) {
17457 # $modHash{$key} = TRUE;
17458 # } else {
17459 # $modHash{$key} = FALSE;
17460 # }
17461 #
17462 # } else {
17463 #
17464 # $modHash{$key} = $initHash{$key};
17465 # }
17466 # }
17467 # }
17468  
17469 # Setup
17470 my $self = {
17471 _objName => 'strip_' . $number,
17472 _objClass => $class,
17473 _parentFile => undef, # No parent file object
17474 _parentWorld => undef, # No parent file object
17475 _privFlag => TRUE, # All IVs are private
17476  
17477 # Standard strip object IVs
17478 # -------------------------
17479  
17480 # The strip object's number within the parent window (matches
17481 # GA::Win::Internal->stripCount, or -1 for a temporary strip object created to access
17482 # its default IVs)
17483 number => $number,
17484 # The type of strip object (custom strip objects should use a ->type starting with
17485 # 'custom_' to avoid clashing with future built-in strip objects)
17486 type => 'generic',
17487 # The parent window object (GA::Win::Internal). 'temp' for temporary strip objects
17488 winObj => $winObj,
17489  
17490 # Flag set to TRUE if the strip object is visible (has actually drawn widgets in the
17491 # window), set to FALSE if it is not visible (has drawn no widgets in the window, but
17492 # still exists in GA::Win::Internal->stripHash, etc)
17493 # The flag might be set to FALSE in strip objects like GA::Strip::GaugeBox, which
17494 # might have gauges to draw, or not, depending on current conditions. (Most strip
17495 # objects have this flag set to TRUE all the time)
17496 # If FALSE, GA::Win::Internal->drawWidgets and ->addStripObj don't draw any widgets when
17497 # called by this object's functions
17498 # NB Strip objects are created with this flag set to TRUE or FALSE, but once created,
17499 # the flag's value shouldn't be modified by anything other than
17500 # GA::Win::Internal->hideStripObj and ->revealStripObj (which in turn call
17501 # $self->set_visibleFlag)
17502 visibleFlag => TRUE,
17503 # Flag set to TRUE is the strip object should be given its share of any extra space
17504 # within the packing box (the extra space is divided equally between all children of
17505 # the box whose ->expandFlag is TRUE)
17506 expandFlag => FALSE,
17507 # Flag set to TRUE if any space given to the strip object by the 'expand' option is
17508 # actually allocated within the strip object, FALSE if it is used as padding outside
17509 # it (on both sides)
17510 fillFlag => FALSE,
17511 # Flag set to TRUE if the strip object should be packed into its window with a small
17512 # gap between strip objects to either side; FALSE if not (can be set to FALSE if the
17513 # the strip object's widgets are drawn in a way, such that a gap is not necessary,
17514 # for example in the toolbar strip object)
17515 spacingFlag => TRUE,
17516 # Flag set to TRUE if only one instance of this strip object should be added to the
17517 # parent window, set to FALSE if any number of instances can be added
17518 jealousyFlag => TRUE,
17519 # Flag set to TRUE if this strip object can be added when $axmud::BLIND_MODE_FLAG is
17520 # TRUE, FALSE if it can't be added (because it's not useful for visually-impaired
17521 # users)
17522 blindFlag => FALSE,
17523 # Flag set to TRUE if the main container widget, stored in $self->packingBox, should be
17524 # allowed to accept the focus, FALSE if not. The restriction is applied during the
17525 # call to GA::Win::Internal->drawWidgets and ->addStripObj. Even if FALSE, widgets in
17526 # the container widget can be set to accept the focus (e.g. the Gtk3::Entry in
17527 # GA::Strip::MenuBar)
17528 allowFocusFlag => FALSE,
17529  
17530 # Initialisation settings stored as a hash (see the comments above)
17531 initHash => \%modHash,
17532 # Reference to a function to call when some widget is used. This IV is set only when
17533 # required by this type of strip object. It can be set by a call to
17534 # $self->set_func() or by some setting in $self->initHash, which is applied in the
17535 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
17536 # generic object function Games::Axmud->getMethodRef()
17537 funcRef => undef,
17538 # A value passed to ->funcRef when it is called which identifies this strip object and
17539 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
17540 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
17541 # to $self->objEnable()
17542 funcID => undef,
17543  
17544 # The container widget for this strip object (usually a Gtk3::HBox or Gtk3::VBox). This
17545 # widget is the one added to the window's main Gtk3::HBox or Gtk3::VBox
17546 packingBox => undef,
17547  
17548 # Other IVs
17549 # ---------
17550  
17551 # Widgets
17552 # button => undef, # Gtk3::Button
17553  
17554 # Everything else
17555  
17556 # ...
17557 };
17558  
17559 # Bless the object into existence
17560 bless $self, $class;
17561  
17562 return $self;
17563 }
17564  
17565 ##################
17566 # Methods
17567  
17568 # Standard strip object functions
17569  
17570 sub objEnable {
17571  
17572 # Called by GA::Win::Internal->drawWidgets or ->addStripObj
17573 # Generic function for setting up the strip object's widgets (which isn't actually called by
17574 # anything)
17575 # Copy this function into your own strip object code and add your own widgets
17576 #
17577 # Expected arguments
17578 # $winmapObj - The winmap object (GA::Obj::Winmap) that specifies the layout of the
17579 # parent window
17580 #
17581 # Return values
17582 # 'undef' on improper arguments
17583 # 1 on success
17584  
17585 my ($self, $winmapObj, $check) = @_;
17586  
17587 # Check for improper arguments
17588 if (! defined $winmapObj || defined $check) {
17589  
17590 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
17591 }
17592  
17593 # Create a Gtk3::VBox (or a Gtk3::HBox) to contain one or more Gtk3 widgets
17594 my $packingBox = Gtk3::VBox->new(FALSE, 0);
17595 $packingBox->set_border_width(0);
17596  
17597 # Add a widget
17598 # my $button = Gtk3::Button->new($name);
17599 # $packingBox->pack_start($button, FALSE, FALSE, 0);
17600  
17601 # Update IVs
17602 $self->ivPoke('packingBox', $packingBox);
17603 # $self->ivPoke('button', $button); # Optional
17604  
17605 return 1;
17606 }
17607  
17608 sub objDestroy {
17609  
17610 # Called by GA::Win::Internal->removeStripObj, just before the strip is removed from its
17611 # parent window, and also by ->winDestroy and ->resetWinmap, to give this object a chance
17612 # to do any necessary tidying up
17613 # Generic function that can be inherited by any strip object that doesn't need to do any
17614 # tidying up
17615 #
17616 # Expected arguments
17617 # (none besides $self)
17618 #
17619 # Return values
17620 # 'undef' on improper arguments
17621 # 1 otherwise
17622  
17623 my ($self, $check) = @_;
17624  
17625 # Check for improper arguments
17626 if (defined $check) {
17627  
17628 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
17629 }
17630  
17631 # (No tidying up required for this type of strip object)
17632  
17633 return 1;
17634 }
17635  
17636 sub setWidgetsIfSession {
17637  
17638 # Called by GA::Win::Internal->setWidgetsIfSession
17639 # Allows this strip object to sensitise or desensitise its widgets, depending on whether
17640 # the parent window has a ->visibleSession at the moment
17641 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
17642 # argument will be FALSE)
17643 #
17644 # Expected arguments
17645 # $flag - TRUE if the parent window has a visible session, FALSE if not
17646 #
17647 # Return values
17648 # 'undef' on improper arguments
17649 # 1 otherwise
17650  
17651 my ($self, $flag, $check) = @_;
17652  
17653 # Check for improper arguments
17654 if (! defined $flag || defined $check) {
17655  
17656 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
17657 }
17658  
17659 # (nothing to do for this strip object)
17660  
17661 return 1;
17662 }
17663  
17664 sub setWidgetsChangeSession {
17665  
17666 # Called by GA::Win::Internal->setWidgetsChangeSession
17667 # Allows this strip object to update its widgets whenever the visible session in any 'main'
17668 # window changes
17669 #
17670 # Expected arguments
17671 # (none besides $self)
17672 #
17673 # Return values
17674 # 'undef' on improper arguments
17675 # 1 otherwise
17676  
17677 my ($self, $check) = @_;
17678  
17679 # Check for improper arguments
17680 if (defined $check) {
17681  
17682 return $axmud::CLIENT->writeImproper(
17683 $self->_objClass . '->setWidgetsChangeSession',
17684 @_,
17685 );
17686 }
17687  
17688 # (nothing to do for this strip object)
17689  
17690 return 1;
17691 }
17692  
17693 # ->signal_connects
17694  
17695 # Other functions
17696  
17697 ##################
17698 # Accessors - set
17699  
17700 sub notify_addStripObj {
17701  
17702 # Called by GA::Win::Internal->drawWidgets and ->addStripObj whenever a strip object is
17703 # added to the window
17704  
17705 my ($self, $stripObj, $check) = @_;
17706  
17707 # Check for improper arguments
17708 if (! defined $stripObj || defined $check) {
17709  
17710 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addStripObj', @_);
17711 }
17712  
17713 # (This generic function does nothing with the notification)
17714  
17715 return 1;
17716 }
17717  
17718 sub notify_removeStripObj {
17719  
17720 # Called by GA::Win::Internal->removeStripObj whenever a strip object is removed from the
17721 # window
17722  
17723 my ($self, $stripObj, $check) = @_;
17724  
17725 # Check for improper arguments
17726 if (! defined $stripObj || defined $check) {
17727  
17728 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeStripObj', @_);
17729 }
17730  
17731 # (This generic function does nothing with the notification)
17732  
17733 return 1;
17734 }
17735  
17736 sub notify_addTableObj {
17737  
17738 # Called by GA::Strip::Table->addTableObj whenever a table object is added to the window's
17739 # Gtk3::Grid
17740  
17741 my ($self, $tableObj, $check) = @_;
17742  
17743 # Check for improper arguments
17744 if (! defined $tableObj || defined $check) {
17745  
17746 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addTableObj', @_);
17747 }
17748  
17749 # (This generic function does nothing with the notification)
17750  
17751 return 1;
17752 }
17753  
17754 sub notify_removeTableObj {
17755  
17756 # Called by GA::Strip::Table->removeTableObj whenever a table object is removed from the
17757 # window's Gtk3::Grid
17758  
17759 my ($self, $tableObj, $check) = @_;
17760  
17761 # Check for improper arguments
17762 if (! defined $tableObj || defined $check) {
17763  
17764 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeTableObj', @_);
17765 }
17766  
17767 # (This generic function does nothing with the notification)
17768  
17769 return 1;
17770 }
17771  
17772 sub set_func {
17773  
17774 my ($self, $funcRef, $check) = @_;
17775  
17776 # Check for improper arguments
17777 if (defined $check) {
17778  
17779 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_func', @_);
17780 }
17781  
17782 $self->ivPoke('funcRef', $funcRef);
17783  
17784 return 1;
17785 }
17786  
17787 sub set_id {
17788  
17789 my ($self, $funcID, $check) = @_;
17790  
17791 # Check for improper arguments
17792 if (defined $check) {
17793  
17794 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_id', @_);
17795 }
17796  
17797 $self->ivPoke('funcID', $funcID);
17798  
17799 return 1;
17800 }
17801  
17802 sub set_visibleFlag {
17803  
17804 # Should only be called by GA::Win::Internal->hideStripObj and ->revealStripObj
17805  
17806 my ($self, $flag, $check) = @_;
17807  
17808 # Check for improper arguments
17809 if (! defined $flag || defined $check) {
17810  
17811 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_visibleFlag', @_);
17812 }
17813  
17814 if (! $flag) {
17815 $self->ivPoke('visibleFlag', FALSE);
17816 } else {
17817 $self->ivPoke('visibleFlag', TRUE);
17818 }
17819  
17820 return 1;
17821 }
17822  
17823 ##################
17824 # Accessors - get
17825  
17826 sub number
17827 { $_[0]->{number} }
17828 sub type
17829 { $_[0]->{type} }
17830 sub winObj
17831 { $_[0]->{winObj} }
17832  
17833 sub visibleFlag
17834 { $_[0]->{visibleFlag} }
17835 sub expandFlag
17836 { $_[0]->{expandFlag} }
17837 sub fillFlag
17838 { $_[0]->{fillFlag} }
17839 sub spacingFlag
17840 { $_[0]->{spacingFlag} }
17841 sub jealousyFlag
17842 { $_[0]->{jealousyFlag} }
17843 sub blindFlag
17844 { $_[0]->{blindFlag} }
17845 sub allowFocusFlag
17846 { $_[0]->{allowFocusFlag} }
17847  
17848 sub initHash
17849 { my $self = shift; return %{$self->{initHash}}; }
17850 sub funcRef
17851 { $_[0]->{funcRef} }
17852 sub funcID
17853 { $_[0]->{funcID} }
17854  
17855 sub packingBox
17856 { $_[0]->{packingBox} }
17857 }
17858  
17859 { package Games::Axmud::Generic::Table;
17860  
17861 use strict;
17862 use warnings;
17863 use diagnostics;
17864  
17865 use Glib qw(TRUE FALSE);
17866  
17867 our @ISA = qw(Games::Axmud);
17868  
17869 ##################
17870 # Constructors
17871  
17872 sub new {
17873  
17874 # Called by GA::Strip::Table->addTableObj
17875 # Generic function for creating table objects (which isn't actually called by anything)
17876 # Copy this function into your own table object code and add your own IVs to $self = {}
17877 #
17878 # Expected arguments
17879 # $number - The table object's number within the parent strip object (matches
17880 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
17881 # created to access its default IVs)
17882 # $name - A name for the table object. Can be any string or, if no name was
17883 # specified in the call to the calling function, $name is the same as
17884 # $number. (No part of the code checks that table object names are unique;
17885 # if two or more table objects share the same ->name, usually the one with
17886 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
17887 # chars)
17888 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary strip
17889 # objects
17890 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
17891 # parent strip object's Gtk3::Grid for use exclusively by this table
17892 # object. 'temp' for temporary strip objects
17893 #
17894 # Optional arguments
17895 # %initHash - A hash containing arbitrary data to use as the table object's
17896 # initialisation settings. The table object should use default
17897 # initialisation settings unless it can succesfully interpret one or more
17898 # of the key-value pairs in the hash, if there are any
17899 # - This type of table object recognises these initialisation settings:
17900 #
17901 # 'some_string' - 'some_value'
17902 # 'some_string_2' - 'some_value'
17903 # ... - ...
17904 #
17905 # Return values
17906 # 'undef' on improper arguments
17907 # Blessed reference to the newly-created object on success
17908  
17909 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
17910  
17911 # Local variables
17912 my %modHash;
17913  
17914 # Check for improper arguments
17915 if (
17916 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
17917 || ! defined $zoneObj
17918 ) {
17919 return $axmud::CLIENT->writeImproper($class . '->new', @_);
17920 }
17921  
17922 # # Default initialisation settings
17923 # %modHash = (
17924 # 'some_string' => 'some_value',
17925 # 'some_string_2' => 'some_value',
17926 # );
17927 #
17928 # # Interpret the initialisation settings in %initHash, if any
17929 # foreach my $key (keys %modHash) {
17930 #
17931 # if (exists $initHash{$key}) {
17932 #
17933 # if ($key eq 'some_flag_set_to_TRUE_or_FALSE') {
17934 #
17935 # if ($initHash{$key}) {
17936 # $modHash{$key} = TRUE;
17937 # } else {
17938 # $modHash{$key} = FALSE;
17939 # }
17940 #
17941 # } else {
17942 #
17943 # $modHash{$key} = $initHash{$key};
17944 # }
17945 # }
17946 # }
17947  
17948 # Setup
17949 my $self = {
17950 _objName => 'table_obj_' . $number,
17951 _objClass => $class,
17952 _parentFile => undef, # No parent file object
17953 _parentWorld => undef, # No parent file object
17954 _privFlag => TRUE, # All IVs are private
17955  
17956 # Standard table object IVs
17957 # -------------------------
17958  
17959 # The table object's number within the parent strip object (matches
17960 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
17961 # access its default IVs)
17962 number => $number,
17963 # A name for the table object. Can be any string or, if no name was specified in the
17964 # call to the calling function, $name is the same as $number. (No part of the code
17965 # checks that table object names are unique; if two or more table objects share the
17966 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
17967 # table objects. Max 16 chars)
17968 name => $name,
17969 # The type of table object (custom table objects should use a ->type starting with
17970 # 'custom_' to avoid clashing with future built-in table objects)
17971 type => 'generic',
17972 # The parent strip object (GA::Strip::Table)
17973 stripObj => $stripObj,
17974 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
17975 # temporary table objects
17976 winObj => $stripObj->winObj,
17977 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
17978 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
17979 # table objects
17980 zoneObj => $zoneObj,
17981  
17982 # Flag set to TRUE if this table object can be deleted from the Gtk3::Grid, once it is
17983 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
17984 # when a connection to a world terminates)
17985 allowRemoveFlag => TRUE,
17986 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
17987 # created. Set to FALSE if it can't be resized
17988 allowResizeFlag => TRUE,
17989 # Initialisation settings stored as a hash (see the comments above)
17990 initHash => \%modHash,
17991 # Reference to a function to call when some widget is used. This IV is set only when
17992 # required by this type of table object. It can be set by a call to
17993 # $self->set_func() or by some setting in $self->initHash, which is applied in the
17994 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
17995 # generic object function Games::Axmud->getMethodRef()
17996 funcRef => undef,
17997 # A value passed to ->funcRef when it is called which identifies this table object and
17998 # its widget(s). Can be any value except 'undef'. It can be set by a call to
17999 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
18000 # to $self->objEnable()
18001 funcID => '',
18002  
18003 # The container widget(s) for this table object
18004 # If a frame title is not required, both IVs are set to the same container widget
18005 # (usually a Gtk3::HBox or Gtk3::VBox)
18006 # If a frame title is required, ->packingBox is set to a Gtk3::Frame, ->packingBox2 is
18007 # set to a different container widget (a Gtk3::HBox, etc). ->packingBox is packed into
18008 # the parent strip object's Gtk3::Grid. ->packingBox2 contains all the other widgets
18009 # for this table object. ->packingBox2 is packed inside ->packingBox
18010 packingBox => undef, # Gtk3::HBox (etc) or Gtk3::Frame
18011 packingBox2 => undef, # Gtk3::HBox (etc)
18012  
18013 # Other IVs
18014 # ---------
18015  
18016 # Widgets
18017 # button => undef, # Gtk3::Button
18018  
18019 # Everything else
18020  
18021 # ...
18022 };
18023  
18024 # Bless the object into existence
18025 bless $self, $class;
18026  
18027 return $self;
18028 }
18029  
18030 ##################
18031 # Methods
18032  
18033 # Standard table object functions
18034  
18035 sub objEnable {
18036  
18037 # Called by GA::Strip::Table->addTableObj
18038 # Generic function for setting up the table object's widgets (which isn't actually called by
18039 # anything)
18040 # Copy this function into your own table object code and add your own widgets
18041 #
18042 # Expected arguments
18043 # (none besides $self)
18044 #
18045 # Return values
18046 # 'undef' on improper arguments
18047 # 1 on success
18048  
18049 my ($self, $check) = @_;
18050  
18051 # Check for improper arguments
18052 if (defined $check) {
18053  
18054 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
18055 }
18056  
18057 # Create a packing box; it is this object which is placed onto the Gtk3::Grid
18058 my $packingBox = Gtk3::VBox->new(FALSE, 0);
18059 $packingBox->set_border_width(0);
18060  
18061 # Add a widget
18062 # my $button = Gtk3::Button->new($name);
18063 # $packingBox->pack_start($button, FALSE, FALSE, 0);
18064  
18065 # Update IVs
18066 $self->ivPoke('packingBox', $packingBox); # Compulsory
18067 # $self->ivPoke('button', $button); # Optional
18068  
18069 return 1;
18070 }
18071  
18072 sub objDestroy {
18073  
18074 # Called by GA::Strip::Table->objDestroy, just before that strip is removed from its
18075 # parent window, to give this object a chance to do any necessary tidying up
18076 # Generic function that can be inherited by any table object that doesn't need to do any
18077 # tidying up
18078 #
18079 # Expected arguments
18080 # (none besides $self)
18081 #
18082 # Return values
18083 # 'undef' on improper arguments
18084 # 1 otherwise
18085  
18086 my ($self, $check) = @_;
18087  
18088 # Check for improper arguments
18089 if (defined $check) {
18090  
18091 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
18092 }
18093  
18094 # (No tidying up required for this type of table object)
18095  
18096 return 1;
18097 }
18098  
18099 sub setWidgetsIfSession {
18100  
18101 # Called by GA::Strip::Table->setWidgetsIfSession
18102 # Allows this table object to sensitise or desensitise its widgets, depending on whether
18103 # the parent window has a ->visibleSession at the moment
18104 # (NB Only 'main' windows have a ->visibleSession; for other 'grid' windows, the flag
18105 # argument will be FALSE)
18106 #
18107 # Expected arguments
18108 # $flag - TRUE if the parent window has a visible session, FALSE if not
18109 #
18110 # Return values
18111 # 'undef' on improper arguments
18112 # 1 otherwise
18113  
18114 my ($self, $flag, $check) = @_;
18115  
18116 # Check for improper arguments
18117 if (! defined $flag || defined $check) {
18118  
18119 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
18120 }
18121  
18122 # (nothing to do for this table object)
18123  
18124 return 1;
18125 }
18126  
18127 sub setWidgetsChangeSession {
18128  
18129 # Called by GA::Strip::Table->setWidgetsChangeSession
18130 # Allows this table object to update its widgets whenever the visible session in any 'main'
18131 # window changes
18132 #
18133 # Expected arguments
18134 # (none besides $self)
18135 #
18136 # Return values
18137 # 'undef' on improper arguments
18138 # 1 otherwise
18139  
18140 my ($self, $check) = @_;
18141  
18142 # Check for improper arguments
18143 if (defined $check) {
18144  
18145 return $axmud::CLIENT->writeImproper(
18146 $self->_objClass . '->setWidgetsChangeSession',
18147 @_,
18148 );
18149 }
18150  
18151 # (nothing to do for this table object)
18152  
18153 return 1;
18154 }
18155  
18156 sub setWidgetsOnResize {
18157  
18158 # Called by GA::Strip::Table->resizeTableObj
18159 # Allows this table object to update its widgets whenever the table object is resized on its
18160 # Gtk3::Grid
18161 #
18162 # Expected arguments
18163 # $left, $right, $top, $bottom
18164 # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom)
18165 # corners of the table object on the table after the resize
18166 #
18167 # Return values
18168 # 'undef' on improper arguments
18169 # 1 otherwise
18170  
18171 my ($self, $left, $right, $top, $bottom, $check) = @_;
18172  
18173 # Check for improper arguments
18174 if (
18175 ! defined $left || ! defined $right || ! defined $top || ! defined $bottom
18176 || defined $check
18177 ) {
18178 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsOnResize', @_);
18179 }
18180  
18181 # (nothing to do for this table object)
18182  
18183 return 1;
18184 }
18185  
18186 # ->signal_connects
18187  
18188 # Other functions
18189  
18190 sub setupPackingBoxes {
18191  
18192 # Called by $self->objEnable
18193 # If a frame title is required, we need two packing boxes, rather than the usual one. The
18194 # Gtk3::Frame (stored in $self->packingBox) is added to the parent strip object's
18195 # Gtk3::Grid, but this object's widgets are packed into the usual container widget
18196 # (stored in $self->packingBox2)
18197 # If a frame title is not required, $self->packingBox and ->packingBox2 refer to the same
18198 # widget - the one passed to this function as an argument
18199 #
18200 # Expected arguments
18201 # $container - The container widget created by the calling function (usually a
18202 # Gtk3::HBox or Gtk3::VBox)
18203 #
18204 # Return values
18205 # An empty list on improper arguments
18206 # Otherwise, returns a list in the form
18207 # (packingBox, packingBox2)
18208  
18209 my ($self, $container, $check) = @_;
18210  
18211 # Local variables
18212 my (
18213 $packingBox, $packingBox2,
18214 @emptyList,
18215 );
18216  
18217 # Check for improper arguments
18218 if (! defined $container || defined $check) {
18219  
18220 $axmud::CLIENT->writeImproper($self->_objClass . '->setupPackingBoxes', @_);
18221 return @emptyList;
18222 }
18223  
18224 if ($self->ivShow('initHash', 'frame_title')) {
18225  
18226 $packingBox = Gtk3::Frame->new($self->ivShow('initHash', 'frame_title'));
18227 $packingBox->set_border_width(0);
18228  
18229 $packingBox2 = $container;
18230 $packingBox->add($packingBox2);
18231  
18232 } else {
18233  
18234 $packingBox = $packingBox2 = $container;
18235 }
18236  
18237 return ($packingBox, $packingBox2);
18238 }
18239  
18240 sub testFlag {
18241  
18242 # Can be called by anything
18243 # Convert any boolean value into a literal Glib TRUE or FALSE. If no value is specified,
18244 # uses the specified default value. If neither a value nor a default value are
18245 # specified, returns FALSE
18246 #
18247 # Expected arguments
18248 # (none besides $self)
18249 #
18250 # Optional arguments
18251 # $flag - Any boolean value; 'undef' is treated as FALSE
18252 # $defaultFlag - The default value to use, should be either a literal Glib TRUE or
18253 # FALSE, or 'undef'
18254 #
18255 # Return values
18256 # TRUE or FALSE
18257  
18258 my ($self, $flag, $defaultFlag, $check) = @_;
18259  
18260 # Check for improper arguments
18261 if (defined $check) {
18262  
18263 $axmud::CLIENT->writeImproper($self->_objClass . '->testFlag', @_);
18264 return FALSE;
18265 }
18266  
18267 if (! defined $flag) {
18268  
18269 $flag = $defaultFlag;
18270 }
18271  
18272 if (! $flag) {
18273 return FALSE;
18274 } else {
18275 return TRUE;
18276 }
18277 }
18278  
18279 sub testJustify {
18280  
18281 # Can be called by anything
18282 # Converts a value into a Gtk3::Justification. The specified value is case-insensitive.
18283 # If no value is specified, converts the specified default value. If neither a value
18284 # nor a default value are specified, returns 'GTK_JUSTIFY_LEFT'. If the value (or default
18285 # value, if required) is not valid, returns 'GTK_JUSTIFY_LEFT'
18286 #
18287 # The conversion table is:
18288 # 'left', 'GTK_JUSTIFY_LEFT' > 'GTK_JUSTIFY_LEFT'
18289 # 'right', 'GTK_JUSTIFY_RIGHT' > 'GTK_JUSTIFY_RIGHT'
18290 # 'centre', 'center', 'GTK_JUSTIFY_CENTER' > 'GTK_JUSTIFY_CENTER'
18291 # 'fill', 'GTK_JUSTIFY_FILL' > 'GTK_JUSTIFY_FILL'
18292 # <invalid value> > 'GTK_JUSTIFY_LEFT'
18293 #
18294 # Expected arguments
18295 # (none besides $self)
18296 #
18297 # Optional arguments
18298 # $value - One of the values described above, or 'undef'
18299 # $defaultValue - The default value to use, should be either a Gtk3::Justification or
18300 # 'undef'
18301 #
18302 # Return values
18303 # 'undef' on improper arguments
18304 # Otherwise returns a Gtk3::Justification
18305  
18306 my ($self, $value, $defaultValue, $check) = @_;
18307  
18308 # Check for improper arguments
18309 if (defined $check) {
18310  
18311 return $axmud::CLIENT->writeImproper($self->_objClass . '->testJustify', @_);
18312 }
18313  
18314 if (! defined $value) {
18315  
18316 if (! defined $defaultValue) {
18317 return 'GTK_JUSTIFY_LEFT';
18318 } else {
18319 $value = $defaultValue;
18320 }
18321 }
18322  
18323 $value = lc($value);
18324  
18325 if ($value eq 'left' || $value eq 'gtk_justify_left') {
18326 return 'GTK_JUSTIFY_LEFT';
18327 } elsif ($value eq 'right' || $value eq 'gtk_justify_right') {
18328 return 'GTK_JUSTIFY_RIGHT';
18329 } elsif ($value eq 'centre' || $value eq 'center' || $value eq 'gtk_justify_center') {
18330 return 'GTK_JUSTIFY_CENTER';
18331 } elsif ($value eq 'fill' || $value eq 'gtk_justify_fill') {
18332 return 'GTK_JUSTIFY_FILL';
18333 } else {
18334 return 'GTK_JUSTIFY_LEFT';
18335 }
18336 }
18337  
18338 sub testAlign {
18339  
18340 # Can be called by anything
18341 # Converts a value into an alignment used by several Gtk3 widgets, a fractional value in the
18342 # range 0-1. If no value is specified, converts the specified default value. If neither a
18343 # value nor a default value are specified, returns 0. If the value (or default value, if
18344 # required) is not valid, returns 0
18345 #
18346 # Expected arguments
18347 # (none besides $self)
18348 #
18349 # Optional arguments
18350 # $value - One of the values described above, or 'undef'
18351 # $defaultVAlue - The default value to use, should be a fractional number in the range
18352 # 0-1 or 'undef'
18353 #
18354 # Return values
18355 # 'undef' on improper arguments
18356 # Otherwise returns a value in the range 0-1
18357  
18358 my ($self, $value, $defaultValue, $check) = @_;
18359  
18360 # Check for improper arguments
18361 if (defined $check) {
18362  
18363 return $axmud::CLIENT->writeImproper($self->_objClass . '->testJustify', @_);
18364 }
18365  
18366 if (! defined $value) {
18367  
18368 if (! defined $defaultValue) {
18369 return 0;
18370 } else {
18371 $value = $defaultValue;
18372 }
18373 }
18374  
18375 if (! $axmud::CLIENT->floatCheck($value, 0, 1)) {
18376 return 0;
18377 } else {
18378 return $value;
18379 }
18380 }
18381  
18382 sub testStock {
18383  
18384 # Can be called by anything
18385 # Checks a Gtk3::Stock like 'gtk-yes' or 'gtk-save' (case-insensitive). If it's valid,
18386 # returns it (converted to all lower-case); if it's not valid, returns 'undef'. If no
18387 # Gtk3::Stock is specified, returns 'undef'
18388 #
18389 # Expected arguments
18390 # (none besides $self)
18391 #
18392 # Optional arguments
18393 # $stock - A Gtk3::Stock, or 'undef'
18394 #
18395 # Return values
18396 # 'undef' on improper arguments, if $stock is invalid or if $stock is 'undef'
18397 # Otherwise returns a Gtk3::Stock
18398  
18399 my ($self, $stock, $check) = @_;
18400  
18401 # Local variables
18402 my @list;
18403  
18404 # Check for improper arguments
18405 if (defined $check) {
18406  
18407 return $axmud::CLIENT->writeImproper($self->_objClass . '->testStock', @_);
18408 }
18409  
18410 if (! defined $stock) {
18411  
18412 return undef;
18413 }
18414  
18415 @list = Gtk3::Stock->list_ids();
18416 foreach my $item (@list) {
18417  
18418 if (lc($stock) eq $item) {
18419  
18420 return $item;
18421 }
18422 }
18423  
18424 return undef;
18425 }
18426  
18427 sub testInt {
18428  
18429 # Can be called by anything
18430 # Checks that a value is an integer. Optionally checks that the value is some minimum
18431 # value. If the check succeeds, returns the value. If the check fails or no value is
18432 # specified, returns a default value (but returns 'undef' if no default value is
18433 # specified)
18434 #
18435 # Expected arguments
18436 # (none besides $self)
18437 #
18438 # Optional arguments
18439 # $value - A value to check, or 'undef'
18440 # $minValue - The minimum value, or 'undef'
18441 # $defaultValue - The default value, or 'undef'
18442 #
18443 # Return values
18444 # 'undef' on improper arguments or if the check fails and no default value is specified
18445 # Otherwise returns an integer value
18446  
18447 my ($self, $value, $minValue, $defaultValue, $check) = @_;
18448  
18449 # Check for improper arguments
18450 if (defined $check) {
18451  
18452 return $axmud::CLIENT->writeImproper($self->_objClass . '->testInt', @_);
18453 }
18454  
18455 if (
18456 ! defined $value
18457 || ! $axmud::CLIENT->intCheck($value)
18458 || (defined $minValue && $value < $minValue)
18459 ) {
18460 return $defaultValue;
18461  
18462 } else {
18463  
18464 return $value;
18465 }
18466 }
18467  
18468 sub testIconValue {
18469  
18470 # Can be called by anything, but probably called by GA::Table::Entry->objEnable to set the
18471 # Gtk3::Entry icon
18472 # Checks whether some value is an acceptable value, given a specified value type, value
18473 # minimum and/or value maximum
18474 #
18475 # Expected arguments
18476 # (none besides $self)
18477 #
18478 # Optional arguments
18479 # $value - A value to check. If 'undef', no check is carried out
18480 # $type - Set to 'int' (to be acceptable, the value must be an integer), 'odd' (the
18481 # value must be an odd-numbered integer), 'even' (the value must be an
18482 # even-numbered integer), 'float' (the value must be an integer or
18483 # floating point number), 'string' (the value can be anything, even an
18484 # empty string). If 'undef', no check is carried out
18485 # $min, $max - For 'int'/'float', the minimum/maximum values that are acceptable. For
18486 # 'odd'/'even', the minimum/maximum values that are acceptable. For
18487 # 'string', the minimum/maximum length of the string. If either or both
18488 # values are 'undef', then no minimumx and/or maximum applies. This
18489 # function assumes the calling function has checked that $min and $max
18490 # are sane values
18491 #
18492 # Return values
18493 # 'undef' on improper arguments, if $value and/or $type were not specified, if $type was
18494 # not recognised or if the $value is not acceptable
18495 # 1 if $value is acceptable
18496  
18497 my ($self, $value, $type, $min, $max, $check) = @_;
18498  
18499 # Check for improper arguments
18500 if (defined $check) {
18501  
18502 return $axmud::CLIENT->writeImproper($self->_objClass . '->testIconValue', @_);
18503 }
18504  
18505 # Some combinations of argument can't be checked
18506 if (
18507 ! defined $value
18508 || ! defined $type
18509 || (
18510 $type ne 'int' && $type ne 'float' && $type ne 'odd' && $type ne 'even'
18511 && $type ne 'string'
18512 )
18513 ) {
18514 return undef;
18515 }
18516  
18517 # Perform the check
18518 if ($type eq 'int') {
18519  
18520 if (
18521 ! $axmud::CLIENT->intCheck($value)
18522 || (defined $min && $value < $min)
18523 || (defined $max && $value > $max)
18524 ) {
18525 # Invalid value
18526 return undef;
18527  
18528 } else {
18529  
18530 # Valid value
18531 return 1;
18532 }
18533  
18534 } elsif ($type eq 'odd') {
18535  
18536 if (
18537 ! $axmud::CLIENT->intCheck($value)
18538 || (defined $min && $value < $min)
18539 || (defined $max && $value > $max)
18540 # Number is even
18541 || ! ($value % 2)
18542 ) {
18543 # Invalid value
18544 return undef;
18545  
18546 } else {
18547  
18548 # Valid value
18549 return 1;
18550 }
18551  
18552 } elsif ($type eq 'even') {
18553  
18554 if (
18555 ! $axmud::CLIENT->intCheck($value)
18556 || (defined $min && $value < $min)
18557 || (defined $max && $value > $max)
18558 # Number is odd
18559 || ($value % 2)
18560 ) {
18561 # Invalid value
18562 return undef;
18563  
18564 } else {
18565  
18566 # Valid value
18567 return 1;
18568 }
18569  
18570 } elsif ($type eq 'float') {
18571  
18572 if (
18573 ! $axmud::CLIENT->floatCheck($value)
18574 || (defined $min && $value < $min)
18575 || (defined $max && $value > $max)
18576 ) {
18577 # Invalid value
18578 return undef;
18579  
18580 } else {
18581  
18582 # Valid value
18583 return 1;
18584 }
18585  
18586 } elsif ($type eq 'string') {
18587  
18588 if (
18589 (defined $min && length($value) < $min)
18590 || (defined $max && length($value) > $max)
18591 ) {
18592 # Invalid value
18593 return undef;
18594  
18595 } else {
18596  
18597 # Valid value
18598 return 1;
18599 }
18600 }
18601 }
18602  
18603 ##################
18604 # Accessors - set
18605  
18606 sub notify_addTableObj {
18607  
18608 # Called by GA::Strip::Table->addTableObj whenever a table object is added to the window's
18609 # Gtk3::Grid
18610  
18611 my ($self, $tableObj, $check) = @_;
18612  
18613 # Check for improper arguments
18614 if (! defined $tableObj || defined $check) {
18615  
18616 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_addTableObj', @_);
18617 }
18618  
18619 # (This generic function does nothing with the notification)
18620  
18621 return 1;
18622 }
18623  
18624 sub notify_removeTableObj {
18625  
18626 # Called by GA::Strip::Table->removeTableObj whenever a table object is removed from the
18627 # window's Gtk3::Grid
18628  
18629 my ($self, $tableObj, $check) = @_;
18630  
18631 # Check for improper arguments
18632 if (! defined $tableObj || defined $check) {
18633  
18634 return $axmud::CLIENT->writeImproper($self->_objClass . '->notify_removeTableObj', @_);
18635 }
18636  
18637 # (This generic function does nothing with the notification)
18638  
18639 return 1;
18640 }
18641  
18642 sub set_allowRemoveFlag {
18643  
18644 # Must only be called by the code which created the table object
18645  
18646 my ($self, $flag, $check) = @_;
18647  
18648 # Check for improper arguments
18649 if (! defined $flag || defined $check) {
18650  
18651 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowRemoveFlag', @_);
18652 }
18653  
18654 if ($flag) {
18655 $self->ivPoke('allowRemoveFlag', TRUE);
18656 } else {
18657 $self->ivPoke('allowRemoveFlag', FALSE);
18658 }
18659  
18660 return 1;
18661 }
18662  
18663 sub set_allowResizeFlag {
18664  
18665 # Must only be called by the code which created the table object
18666  
18667 my ($self, $flag, $check) = @_;
18668  
18669 # Check for improper arguments
18670 if (! defined $flag || defined $check) {
18671  
18672 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowResizeFlag', @_);
18673 }
18674  
18675 if ($flag) {
18676 $self->ivPoke('allowResizeFlag', TRUE);
18677 } else {
18678 $self->ivPoke('allowResizeFlag', FALSE);
18679 }
18680  
18681 return 1;
18682 }
18683  
18684 sub set_func {
18685  
18686 my ($self, $funcRef, $check) = @_;
18687  
18688 # Check for improper arguments
18689 if (defined $check) {
18690  
18691 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_func', @_);
18692 }
18693  
18694 $self->ivPoke('funcRef', $funcRef);
18695  
18696 return 1;
18697 }
18698  
18699 sub set_frameTitle {
18700  
18701 my ($self, $text, $check) = @_;
18702  
18703 # Check for improper arguments
18704 if (defined $check) {
18705  
18706 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_frameTitle', @_);
18707 }
18708  
18709 if (! defined $text) {
18710  
18711 $text = '';
18712 }
18713  
18714 if ($self->packingBox->isa('Gtk3::Frame')) {
18715  
18716 $self->packingBox->set_label($text);
18717 }
18718  
18719 return 1;
18720 }
18721  
18722 sub set_id {
18723  
18724 my ($self, $funcID, $check) = @_;
18725  
18726 # Check for improper arguments
18727 if (defined $check) {
18728  
18729 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_id', @_);
18730 }
18731  
18732 $self->ivPoke('funcID', $funcID);
18733  
18734 return 1;
18735 }
18736  
18737 sub set_zoneObj {
18738  
18739 my ($self, $zoneObj, $check) = @_;
18740  
18741 # Check for improper arguments
18742 if (defined $check) {
18743  
18744 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_zoneObj', @_);
18745 }
18746  
18747 $self->ivPoke('zoneObj', $zoneObj);
18748  
18749 return 1;
18750 }
18751  
18752 ##################
18753 # Accessors - get
18754  
18755 sub number
18756 { $_[0]->{number} }
18757 sub name
18758 { $_[0]->{name} }
18759 sub type
18760 { $_[0]->{type} }
18761 sub stripObj
18762 { $_[0]->{stripObj} }
18763 sub winObj
18764 { $_[0]->{winObj} }
18765 sub zoneObj
18766 { $_[0]->{zoneObj} }
18767  
18768 sub allowRemoveFlag
18769 { $_[0]->{allowRemoveFlag} }
18770 sub allowResizeFlag
18771 { $_[0]->{allowResizeFlag} }
18772 sub initHash
18773 { my $self = shift; return %{$self->{initHash}}; }
18774 sub funcRef
18775 { $_[0]->{funcRef} }
18776 sub funcID
18777 { $_[0]->{funcID} }
18778  
18779 sub packingBox
18780 { $_[0]->{packingBox} }
18781 sub packingBox2
18782 { $_[0]->{packingBox2} }
18783 }
18784  
18785 { package Games::Axmud::Generic::Task;
18786  
18787 use strict;
18788 use warnings;
18789 use diagnostics;
18790  
18791 use Glib qw(TRUE FALSE);
18792  
18793 our @ISA = qw(Games::Axmud);
18794  
18795 ##################
18796 # Constructors
18797  
18798 sub new {
18799  
18800 # Prepare a new instance of the generic task (although the generic task is never actually
18801 # blessed into existence)
18802 #
18803 # Expected arguments
18804 # $session - The parent GA::Session (not set as an IV by this function - set by
18805 # $self->updateTaskLists for current tasks)
18806 #
18807 # Optional arguments
18808 # $taskType - Which tasklist this task is being created into - 'current' for the current
18809 # tasklist (tasks which are actually running now), 'initial' (tasks which
18810 # should be run when the user connects to the world), 'custom' (tasks with
18811 # customised initial parameters, which are run when the user demands). If
18812 # set to 'undef', this is a temporary task, created in order to access the
18813 # default values stored in IVs, that will not be added to any tasklist
18814 # $profName - ($taskType = 'current') name of the profile from whose initial tasklist
18815 # this task was created ('undef' if none)
18816 # - ($taskType = 'initial') name of the profile in whose initial tasklist
18817 # this task will be. If 'undef', the global initial tasklist is used
18818 # - ($taskType = 'custom') 'undef'
18819 # $profCategory
18820 # - ($taskType = 'current', 'initial') which category the profile falls undef
18821 # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile)
18822 # - ($taskType = 'custom') 'undef'
18823 # $customName
18824 # - ($taskType = 'current', 'initial') 'undef'
18825 # - ($taskType = 'custom') the custom task name, matching a key in
18826 # GA::Session->customTaskHash
18827 #
18828 # Return values
18829 # 'undef' on improper arguments
18830 # Otherwise returns $self, a hash that will be blessed into existence by the inheriting
18831 # object
18832  
18833 my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_;
18834  
18835 # Check for improper arguments
18836 if (! defined $class || ! defined $session || defined $check) {
18837  
18838 return $axmud::CLIENT->writeImproper($class . '->new', @_);
18839 }
18840  
18841 # For 'initial' tasks, check that the profile $profName exists (for 'current' tasks, if
18842 # $profName is defined, we can safely assume that it already exists)
18843 if (
18844 $taskType
18845 && $taskType eq 'initial'
18846 && defined $profName
18847 && ! $session->ivExists('profHash', $profName)
18848 ) {
18849 return $axmud::CLIENT->writeError(
18850 'Can\'t create new initial task because profile ' . $profName . ' doesn\'t exist',
18851 $class . '->new',
18852 );
18853 }
18854  
18855 # Setup
18856 my $self = {
18857 _objName => 'generic_task',
18858 _objClass => $class,
18859 # Parent file object IVs set by ->setParentFileObj
18860 _parentFile => undef,
18861 _parentWorld => undef,
18862 _privFlag => TRUE, # All IVs are private
18863  
18864 # Perl object components
18865 # ----------------------
18866  
18867 # The parent GA::Session object (for current tasks) - set by $self->updateTaskLists
18868 session => undef,
18869  
18870 # Task settings
18871 # -------------
18872  
18873 # The generic task has 'task settings' (IVs which are used with every kind of task), but
18874 # no 'task parameters' (IVs which are unique to each kind of task)
18875  
18876 # What type of task this is, e.g. 'locator_task', 'attack_bot_task' etc (max 16
18877 # characters, A-Z, a-z, underline, numbers (not on first char), non-Latin alphabets
18878 # acceptable)
18879 name => 'generic_task',
18880  
18881 # Capitalised form of $self->name, used for (e.g.) task window titles (max 32 chars)
18882 prettyName => 'Generic Task',
18883 # Each instance of the generic task is given a unique name, just before being blessed
18884 # into existence (based on ->name, so assumed to be no more than 24 characters)
18885 uniqueName => undef,
18886 # Very short name (probably just two letters) for display in the Status task's
18887 # own window
18888 shortName => 'Gn',
18889 # For custom tasks, the custom task name (matches a key in GA::Client->customTaskHash,
18890 # max 16 chars); set to 'undef' for current and initial tasks
18891 customName => $customName,
18892  
18893 # What category of task, 'process' or 'activity'
18894 category => 'process',
18895 # Description of the task (any length permitted)
18896 descrip => 'A generic task',
18897 # 'current', 'initial' or 'custom' (or 'undef' for a temporary task)
18898 taskType => $taskType,
18899 # ($taskType = 'current') name of the profile from whose initial tasklist this task was
18900 # created ('undef' if none)
18901 # ($taskType = 'initial') name of the profile in whose initial tasklisk this task will
18902 # be
18903 # ($taskType = 'custom') 'undef'
18904 profName => $profName,
18905 # ($taskType = 'initial') the category of the profile with which this initial task is
18906 # associated ('world', 'race', 'guild', 'char', etc)
18907 # ($taskType = 'current', 'initial') which category the profile falls under (i.e.
18908 # 'world', 'race', 'char', etc, or 'undef' if no profile)
18909 # ($taskType = 'custom') 'undef'
18910 profCategory => $profCategory,
18911 # A reference to the GA::Session IV for this task, if there is one (e.g.
18912 # GA::Session->locatorTask for the current Locator task). We need it so that, if the
18913 # task is destroyed with the ';killtask' command, that IV can be set to 'undef'
18914 # Set for all built-in tasks that have their ->jealousyFlag set to TRUE; at the
18915 # moment, that's all built-in tasks except the Frame and Script tasks. In addition,
18916 # only the lead (first) Chat task has its ->shortCutIV set
18917 # For private tasks, usually set to 'undef'; however, if you write a replacement for
18918 # (say) the built-in Attack task, it's possible to set this IV to 'attackTask' - in
18919 # which case, when your private task is running and other parts of the Axmud code
18920 # consult the current Attack task, they'll consult your private task instead
18921 shortCutIV => undef,
18922  
18923 # Whether multiple instances of this bot can run concurrently
18924 # FALSE - any number of concurrent instances can run
18925 # TRUE - only one instance can run
18926 # (Activity tasks are almost always jealous. Process tasks are often jealous.)
18927 jealousyFlag => TRUE,
18928 # Whether this task requires the Locator task to be running
18929 # FALSE - this task doesn't need the Locator task
18930 # TRUE - this task can't run without the Locator task (and will shut down if the
18931 # Locator task shuts down)
18932 requireLocatorFlag => TRUE,
18933 # Whether the task should reset itself, if any of the current profiles are changed
18934 # (because many tasks depend on data in current profiles; if they suddenly change,
18935 # the tasks will at best be relying on obsolete data, and at worst could corrupt the
18936 # new current profiles)
18937 # FALSE - this task doesn't care if any of the current profiles are changed
18938 # TRUE - this task must reset itself if any of the current profiles are changed
18939 profSensitivityFlag => TRUE,
18940 # Whether this task can be stored as an initial/custom task
18941 # FALSE - this task isn't storable (can't be started with ';starttask' under normal
18942 # circumstances - e.g. the Advance task, which should be started with
18943 # ';advance', and the Chat task, which should be started with ';listen')
18944 # TRUE - this task is storable (can be used as an initial/custom task)
18945 storableFlag => TRUE,
18946  
18947 # When the task will start/started - matches GA::Session->sessionTime (in seconds)
18948 # [ ->status = 'wait_init' ] the time at which to start
18949 # [ ->status = 'running', 'paused'] the time the task actually started
18950 startTime => 0,
18951 # The next time the task's status should be checked - matches
18952 # GA::Session->sessionTime (in seconds)
18953 # [ Status = 'wait_task_*] the next time to check (usually after 60 seconds)
18954 # [ Status = 'paused'] the time to unpause
18955 checkTime => 0,
18956 # How the task should stop running
18957 # 'unlimited' run indefinitely, using the task's code to decide when to shut down
18958 # 'run_for' run for some time after the task has become active
18959 # 'run_until' run until a certain time
18960 endStatus => 'unlimited',
18961 # When the task should stop running (default value is 0 for 'run forever')
18962 # [ ->status = 'wait_* ][ ->endStatus = 'run_for' ]
18963 # - run for this many minutes
18964 # [ ->status = 'wait_* ][ ->endStatus = 'run_until' ]
18965 # - run until this system time (matches GA::Session->sessionTime, in seconds)
18966 # [ ->status = 'running', 'paused' ][ ->endStatus = 'run_*' ]
18967 # - stop at this system time (matches GA::Session->sessionTime, in seconds)
18968 # [ ->status = 'finished' ]
18969 # - the system time at which the task actually finished (not the time it's due to
18970 # finish) (matches GA::Session->sessionTime, in seconds)
18971 endTime => 0,
18972 # Wait for another task to do something
18973 # [ ->status = 'wait_task_*' ]
18974 # - the task for which to wait - can match either Task->name or Task->uniqueName
18975 waitForTask => undef,
18976 # How often the task loop should call this task, in seconds (e.g. 1, call once a second,
18977 # 0.2, call five times a second)
18978 # If 0, the task is called once per task loop. The task will never be called more
18979 # than once per task loop, so if this IV is set to 0.1 and the task loop is running
18980 # once a second, this task will still only be called once a second
18981 # Set to 0 for all activity tasks
18982 delayTime => 0,
18983  
18984 # Set to TRUE if the task should shut down gracefully, FALSE otherwise
18985 shutdownFlag => FALSE,
18986 # Flag set to TRUE if the task has ever been reset, FALSE if it's never been reset (so
18987 # that functions like $self->doFirstStage and ->doInit don't, for example, try to add
18988 # widgets to a task window that was created by the pre-reset task, and therefore
18989 # already contains widgets)
18990 hasResetFlag => FALSE,
18991 # The task's status
18992 # 'no_exist' task doesn't exist
18993 # 'wait_init' waiting to initialise
18994 # 'wait_task_exist' waiting for a task to exist, before initialising
18995 # 'wait_task_no_exist' waiting for a task to not exist, before initialising
18996 # 'wait_task_start_stop' waiting for a task to exist, and then finish, before
18997 # initialising
18998 # 'running' task is active
18999 # 'paused' task is paused
19000 # 'finished' task is finished
19001 # 'reset' task must be reset
19002 status => 'no_exist',
19003 # The task's resumption status
19004 # [->status = 'paused']
19005 # - when the task resumes, what its status should be (default is 'running')
19006 resumeStatus => undef,
19007 # For some tasks it's useful to have a functionality of running in an 'active' mode
19008 # (actively doing things) or in a 'disactivated' mode (waiting for something to
19009 # happen). This IV provides that functionality.
19010 # If the task is 'active' (or if the functionality isn't needed), the flag is set to
19011 # TRUE, if the task is 'disactivated', the variable is set to FALSE. Tasks that don't
19012 # need to distinguish between 'active' and 'disactivated' should have this flag set
19013 # to TRUE.
19014 activeFlag => TRUE,
19015 # The task stage (which chunk of the task should be performed on the next task loop).
19016 # Should be a number; integers are preferred, but if you use decimals like 1.1 or 1.2,
19017 # don't make the stage longer than 5 characters (i.e. don't use 1.1510)
19018 # [ ->category = 'process']
19019 # - set to 0 until task starts, thereafter any value (usually a number)
19020 # [ ->category = 'activity']
19021 # - always set to 0 (and should be ignored by the task code)
19022 stage => 0,
19023  
19024 # Task windows can take one of three forms: a 'grid' window (separate from the session's
19025 # 'main' window), or a table object inside the session's 'main' window,
19026 # GA::Table::Pane or GA::Table::PseudoWin
19027 # GA::Table::Pane creates a simple pane object inside the session's 'main' window.
19028 # This task interacts with the pane object and its textview(s) mostly by accessing
19029 # $self->defaultTabObj IVs
19030 # GA::Table::PseudoWin creates a pseudo-window - a window object inheriting from
19031 # GA::Generic::GridWin, but which does not open a separate window; instead, the
19032 # pseudo-window's widgets are drawn inside the table object
19033 #
19034 # There are no built-in tasks which use more than one task window. If you write your own
19035 # tasks, the code is free to open additional task windows, and to store those task
19036 # windows in its own IVs
19037 #
19038 # Is the task allowed to open task windows at all?
19039 allowWinFlag => FALSE,
19040 # Is the task required to have a task window open? (TRUE - the task can't run if a task
19041 # window can't be opened and must halt if the window is closed, FALSE - the task can
19042 # run without a task window)
19043 # (Ignored if ->allowWinFlag is FALSE)
19044 requireWinFlag => FALSE,
19045 # Should the task open a task window when it starts? (Ignored if ->allowWinFlag or
19046 # ->requireWinFlag are FALSE)
19047 startWithWinFlag => FALSE,
19048 #
19049 # The comments for the remaining IVs assume the task opens only one task window (if any)
19050 #
19051 # What kind of task window this task prefers to open (see the comments just above) - an
19052 # ordered list of strings, containing any of the following:
19053 # 'grid' - open a 'grid' window
19054 # 'pane' - open a pane object inside the session's 'main' window
19055 # 'entry' - open a pane object using an entry box inside the session's 'main'
19056 # window
19057 # 'pseudo' - opens a pseudo-window inside the session's 'main' window
19058 # When $self->openWin is called, it will act on each item on the list, from first to
19059 # last, until it succeeds in opening a task window (that is to say, if the first item
19060 # is 'win' and the code successfully opens a 'grid' window, it ignores the rest of the
19061 # list)
19062 # If it's an empty list, then of course no task window is opened
19063 winPreferList => [],
19064 # For 'grid' and 'pseudo', the blessed reference of the window object
19065 # (GA::Win::Internal), if one is open; set to 'undef' otherwise
19066 winObj => undef,
19067 # For 'pane', 'entry' and 'pseudo', the blessed reference of the table object inside the
19068 # session's 'main' window; set to 'undef' otherwise
19069 # NB For 'pseudo', both ->winObj and ->tableObj are set
19070 tableObj => undef,
19071 # For all task window types, flag set to TRUE if there is a task window open (i.e.
19072 # either ->winObj or ->tableObj are set), set to FALSE if there is no task window open
19073 # (both ->winObj and ->tableObj are not set)
19074 taskWinFlag => FALSE,
19075 # For all task window types, flag set to TRUE if there is a task window open that's
19076 # using an entry box; set to FALSE otherwise
19077 taskWinEntryFlag => FALSE,
19078 # For 'grid' and 'pseudo', the winmap to use in the window object, if one is open
19079 # (matches a key in GA::Client->winmapHash). If set to 'undef' and a window object is
19080 # created, the 'basic_empty' winmap is used
19081 winmap => undef,
19082 # For all task window types, when the client command ';opentaskwindow' is used to open a
19083 # task window some time after the task has started, a function within the task to call
19084 # which fills the window with strip objects and table objects, or which initialises
19085 # the contents of a pane object, or anything else required (e.g. 'createWidgets',
19086 # which would call $self->createWidgets() - a literal function name, not a reference
19087 # to a function)
19088 # If 'undef', no function is called
19089 winUpdateFunc => undef,
19090 # For all task window types, if the task has created a task window that includes a pane
19091 # object, the tab object (GA::Obj::Tab) corresponding to the first tab in that pane
19092 # object (otherwise set to 'undef')
19093 # Set automatically if the winmap specified by $self->winmap contains a pane object; can
19094 # be set manually otherwise
19095 defaultTabObj => undef,
19096 # For any task window using a pane object, which kind of tab to add to the pane when the
19097 # task window opens - 'simple' to create a simple tab (one with no label), 'multi' to
19098 # create a tab with a label, and 'empty' to create no tabs at first, leaving an empty
19099 # an empty pane
19100 # For task windows that don't use a pane object, this IV is ignored, so the value should
19101 # remain set to 'undef'
19102 # If set to 'multi' or 'empty', simple tabs are never added; the first tab is always a
19103 # normal tab
19104 tabMode => undef,
19105 # For any task window using a pane object, flag set to TRUE if that pane object uses a
19106 # monochrome colour scheme (a specified background colour with a suitable text
19107 # colour), which is set by the task itself (for example, the Status task changes
19108 # colour when the current' characters hit points change)
19109 # Flag set to FALSE if the default colour scheme for 'custom' windows should apply (or
19110 # if there is no pane object at all)
19111 monochromeFlag => FALSE,
19112 # For any task using a pane object, the colour scheme applied is specified thus:
19113 # 1. If the following IV is set, that colour scheme is applied
19114 # 2. Otherwise, if a colour scheme exists with the same name as the task (matching
19115 # $self->name, e.g. 'locator_task', or that name with the '_task' removed, e.g.
19116 # 'locator'), then that colour scheme is applied
19117 # 3. Otherwise, the colour scheme applied is the same as the window's ->winType (for
19118 # all task windows, 'custom')
19119 colourScheme => undef,
19120 # For any task window using a pane object, flag set to TRUE if that pane objecct's
19121 # vertical scroll bar, if any, should remain at the top, leaving the first lines in
19122 # view; set FALSE if it should scroll to the bottom (as normal)
19123 noScrollFlag => FALSE,
19124  
19125 # Flag set to TRUE if this task is capable of doing text-to-speech (TTS), FALSE
19126 # otherwise
19127 ttsFlag => FALSE,
19128 # For tasks that can do TTS, the name of the TTS configuration object to use. If set to
19129 # 'undef', the default configuration for tasks is used
19130 ttsConfig => undef,
19131 # TTS attributes and flag attributes.
19132 # The user can use the client commands ';read', ';switch' and ';alert' to interact with
19133 # individual tasks to customise the way they use TTS
19134 # ';read' is used with TTS attributes, which typically get the task to read out
19135 # information (e.g. the Status task can read out current health points).
19136 # ';switch' is used with TTS flag attributes, which typically tell the task to
19137 # automatically read out information (e.g. the Locator task can be told to read out
19138 # room titles automatically, as they are received; or not)
19139 # ';alert' is used with TTS alert attributes, which typically read out a message when
19140 # some statistic reaches a certain level (e.g. the Status task can be told to read
19141 # out an alert when health points fall below or recover to a certain percentage)
19142 # A hash of all attributes used by built-in tasks is stored in
19143 # GA::Client->constTtsAttribHash, ->constTtsFlagAttribHash and
19144 # ->constTtsAlertAttribHash
19145 # Each GA::Session stores a custom list of attributes, initially set to the same
19146 # values, but modified as any user-written tasks start/stop. If a user-written task
19147 # wants to use an attribute like 'title', the ';read', ';switch' and ';alert' commands
19148 # work with the user-written task, rather than the built-in one. (When the user-
19149 # written task halts, the built-in task's attributes are restored)
19150 # A hash of all TTS (normal) attributes used by this task, in the form
19151 # $ttsAttribHash{attribute} = optional_value_or_undef
19152 # ...where 'attribute' is a string unique to this hash, preferably a single word in all
19153 # lower-case letters
19154 # When the ';read' command calls this task's ->ttsReadAttrib() function, that function
19155 # decides how to respond. If it wants to store a value in this hash, it can do so. If
19156 # it stores a value, it might be a value specified by the ';read' command, or not.
19157 # Otherwise the attribute's corresponding value is 'undef'. The hash should only be
19158 # modified by calls to ->ttsReadAttrib()
19159 ttsAttribHash => {},
19160 # A hash of all TTS flag attributes used by this task, in the form
19161 # $ttsFlagAttribHash{flag_attribute} = TRUE_or_FALSE_value
19162 # ...where 'flag_attribute' is a string unique to this hash, preferably a single word in
19163 # all lower-case letters
19164 # When the ';switch' command calls this task's ->ttsSwitchFlagAttrib() function, that
19165 # function decides how to respond. Almost always, the TRUE or FALSE value stored in
19166 # this hash is toggled, but that's not compulsory. The hash should only be modified
19167 # by calls to ->ttsSwitchFlagAttrib()
19168 ttsFlagAttribHash => {},
19169 # A hash of all TTS alert attributes used by this task, in the form
19170 # $ttsAlertAttribHash{alert_attribute} = optional_value_or_undef
19171 # ...where 'alert_attribute' is a string unique to this hash, preferably a single word
19172 # in all lower-case letters
19173 # When the ';alert' command calls this task's ->ttsSetAlertAttrib() function, that
19174 # function decides how to respond. If it wants to store a value in this hash, it can
19175 # do so. If it stores a value, it might be a value specified by the ';alert' command,
19176 # or not. Otherwise the attribute's corresponding value is 'undef'. The hash should
19177 # only be modified by calls to ->ttsSetAlertAttrib()
19178 ttsAlertAttribHash => {},
19179 };
19180  
19181 # The generic task is never actually blessed into existence
19182 return $self;
19183 }
19184  
19185 sub clone {
19186  
19187 # Create a clone of an existing task
19188 # Usually used upon connection to a world, when every task in the initial tasklists must
19189 # be cloned into a new object, representing a task in the current tasklist
19190 # (Also used when cloning a profile object, since all the tasks in its initial tasklist must
19191 # also be cloned)
19192 #
19193 # Expected arguments
19194 # $session - The parent GA::Session (not stored as an IV)
19195 # $taskType - Which tasklist this task is being created into - 'current' for the current
19196 # tasklist (tasks which are actually running now), 'initial' (tasks which
19197 # should be run when the user connects to the world). Custom tasks aren't
19198 # cloned (at the moment)
19199 #
19200 # Optional arguments
19201 # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the
19202 # existing task is stored
19203 # $profCategory
19204 # - ($taskType = 'initial') which category the profile falls under (i.e.
19205 # 'world', 'race', 'char', etc)
19206 #
19207 # Return values
19208 # 'undef' on improper arguments or if the task can't be cloned
19209 # Blessed reference to the newly-created object on success
19210  
19211 my ($self, $session, $taskType, $profName, $profCategory, $check) = @_;
19212  
19213 # Check for improper arguments
19214 if (
19215 ! defined $session || ! defined $taskType || defined $check
19216 || ($taskType ne 'current' && $taskType ne 'initial')
19217 || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory))
19218 ) {
19219 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
19220 }
19221  
19222 # For initial tasks, check that $profName exists
19223 if (
19224 $taskType eq 'initial'
19225 && defined $profName
19226 && ! $session->ivExists('profHash', $profName)
19227 ) {
19228 return $axmud::CLIENT->writeError(
19229 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist',
19230 $self->_objClass . '->clone',
19231 );
19232 }
19233  
19234 # Check that the task doesn't belong to a disabled plugin (in which case, it can't be
19235 # cloned)
19236 if (! $self->checkPlugins()) {
19237  
19238 return undef;
19239 }
19240  
19241 # Create the new task, using default settings and parameters
19242 my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory);
19243  
19244 # Most of the cloned task's settings have default values, but a few are copied from the
19245 # original
19246 $self->cloneTaskSettings($clone);
19247  
19248 # Give the new (cloned) task the same initial parameters as the original one
19249 # (no parameters to preserve)
19250  
19251 # Cloning complete
19252 return $clone;
19253 }
19254  
19255 ##################
19256 # Methods
19257  
19258 # Constructor support functions
19259  
19260 sub cloneTaskSettings {
19261  
19262 # Called by $self->clone (and nothing else)
19263 # Most task settings are not copied from the original task to a clone (most of the clone's
19264 # task settings continue to have default values), however there are a few task settings
19265 # which must be copied from the clone. This function handles it.
19266 #
19267 # Expected arguments
19268 # $self - The original task
19269 # $clone - The cloned task
19270 #
19271 # Return values
19272 # 'undef' on improper arguments
19273 # 1 on success
19274  
19275 my ($self, $clone, $check) = @_;
19276  
19277 # Check for improper arguments
19278 if (! defined $clone || defined $check) {
19279  
19280 return $axmud::CLIENT->writeImproper($self->_objClass . '->cloneTaskSettings', @_);
19281 }
19282  
19283 $clone->{_objName} = $self->{_objName};
19284 # ->_parentFile / ->_parentWorld has already been set (by ->updateTaskLists)
19285 $clone->{_objClass} = $self->{_objClass};
19286 $clone->{_privFlag} = TRUE, # All IVs are private
19287  
19288 # Text-to-speech (TTS) task settings must be copied from the original, so that settings in
19289 # tasks stored in the global initial tasklist are transferred to a current task, when it
19290 # starts
19291 $clone->{ttsFlag} = $self->ttsFlag;
19292 $clone->{ttsConfig} = $self->ttsConfig;
19293 $clone->{ttsAttribHash} = {$self->ttsAttribHash};
19294 $clone->{ttsFlagAttribHash} = {$self->ttsFlagAttribHash};
19295 $clone->{ttsAlertAttribHash} = {$self->ttsAlertAttribHash};
19296 # Same applies to the IV that sets whether a window is opened, when the task starts (for the
19297 # benefit of tasks which can do either)
19298 $clone->{startWithWinFlag} = $self->startWithWinFlag;
19299 # Same applies to the preferred colour scheme
19300 $clone->{colourScheme} = $self->colourScheme;
19301  
19302 return 1;
19303 }
19304  
19305 sub preserve {
19306  
19307 # Called by $self->main whenever this task is reset, in order to preserve some if its task
19308 # parameters (but not necessarily all of them)
19309 #
19310 # Expected arguments
19311 # $newTask - The new task which has been created, to which some of this task's instance
19312 # variables might have to be transferred
19313 #
19314 # Return values
19315 # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current
19316 # tasklist
19317 # 1 on success
19318  
19319 my ($self, $newTask, $check) = @_;
19320  
19321 # Check for improper arguments
19322 if (! defined $newTask || defined $check) {
19323  
19324 return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_);
19325 }
19326  
19327 # Check the task is in the current tasklist
19328 if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) {
19329  
19330 return $self->writeWarning(
19331 '\'' . $self->uniqueName . '\' task missing from the current tasklist',
19332 $self->_objClass . '->preserve',
19333 );
19334 }
19335  
19336 # Preserve some task parameters (the others are left with their default settings, some of
19337 # which will be re-initialised in stage 2)
19338  
19339 # (no parameters to preserve)
19340  
19341 return 1;
19342 }
19343  
19344 sub checkPlugins {
19345  
19346 # Called by a task's ->new function (but not by the generic task itself))
19347 # Checks that this task wasn't created by a plugin which is currently disabled, or not
19348 # loaded (in which case, the task can't be added to a current, initial or custom tasklist)
19349 #
19350 # Expected arguments
19351 # (none besides $self)
19352 #
19353 # Return values
19354 # 'undef' on improper arguments or if this task was created by a plugin which is
19355 # currently disabled, or not loaded
19356 # 1 otherwise
19357  
19358 my ($self, $check) = @_;
19359  
19360 # Local variables
19361 my ($plugin, $pluginObj);
19362  
19363 # Check for improper arguments
19364 if (defined $check) {
19365  
19366 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPlugins', @_);
19367 }
19368  
19369 # Was this task created by a plugin?
19370 if ($axmud::CLIENT->ivExists('pluginTaskHash', $self->name)) {
19371  
19372 $plugin = $axmud::CLIENT->ivShow('pluginTaskHash', $self->name);
19373 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $plugin);
19374  
19375 if (! $pluginObj) {
19376  
19377 # This task can't be added to a current, initial or custom tasklist
19378 return $self->error(
19379 'The \'' . $self->name . '\' task was created by a plugin which has not been'
19380 . ' loaded',
19381 );
19382  
19383 } elsif (! $pluginObj->enabledFlag) {
19384  
19385 return $self->error(
19386 'The \'' . $self->name . '\' task was created by a plugin which has been'
19387 . ' disabled',
19388 );
19389 }
19390 }
19391  
19392 # Otherwise, the task can be added to a current, initial or custom tasklist
19393 return 1;
19394 }
19395  
19396 sub setParentFileObj {
19397  
19398 # Called by a task's ->new function (but not by the generic task itself))
19399 # Sets the standard IVs ->_parentFile and ->_parentWorld, if required
19400 #
19401 # Expected arguments
19402 # $session - The calling function's GA::Session
19403 # $taskType - Which tasklist this task is being created into - 'current', 'initial'
19404 # or 'custom'
19405 #
19406 # Optional arguments
19407 # $profName - Name of the profile in whose initial tasklist this task will be (or
19408 # 'undef')
19409 # $profCategory - That profile's category (or 'undef')
19410 #
19411 # Return values
19412 # 'undef' on improper arguments
19413 # 1 otherwise
19414  
19415 my ($self, $session, $taskType, $profName, $profCategory, $check) = @_;
19416  
19417 # Check for improper arguments
19418 if (! defined $session || ! defined $taskType || defined $check) {
19419  
19420 return $axmud::CLIENT->writeImproper($self->_objClass . '->setParentFileObj', @_);
19421 }
19422  
19423 # Initial task in a profile's initial tasklist
19424 if ($taskType eq 'initial' && defined $profName) {
19425  
19426 if ($profCategory eq 'world') {
19427  
19428 $self->{_parentFile} = $profName;
19429  
19430 } else {
19431  
19432 $self->{_parentFile} = 'otherprof';
19433 $self->{_parentWorld} = $session->currentWorld->name;
19434 }
19435  
19436 # Task in the global initial/custom tasklists
19437 } elsif ($taskType eq 'initial' || $taskType eq 'custom') {
19438  
19439 $self->{_parentFile} = 'tasks';
19440 }
19441  
19442 return 1;
19443 }
19444  
19445 sub updateTaskLists {
19446  
19447 # Called by a task's ->new function (but not by the generic task itself))
19448 # Also called by GA::Obj::File->extractData when importing an initial/custom task
19449 #
19450 # Updates the current, global initial, custom or profile initial tasklists with the newly-
19451 # created task, as appropriate. Also sets $self->uniqueName
19452 # NB We use $self->{...} to set the value of IVs, rather than $self->ivPoke(...), to avoid
19453 # setting the ->modifyFlag IV of parent GA::Obj::File (stored in $self->_parentFile)
19454 #
19455 # Expected arguments
19456 # $session - The calling function's GA::Session (set as an IV for current tasks only)
19457 #
19458 # Return values
19459 # 'undef' on improper arguments or if we try to add a non-storable task to an initial or
19460 # custom tasklist
19461 # 1 otherwise
19462  
19463 my ($self, $session, $check) = @_;
19464  
19465 # Local variables
19466 my $profile;
19467  
19468 # Check for improper arguments
19469 if (! defined $session || defined $check) {
19470  
19471 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateTaskLists', @_);
19472 }
19473  
19474 if ($self->taskType eq 'current') {
19475  
19476 # Give task a unique name within the current tasklist
19477 $self->{uniqueName} = $self->{name} . '_' . $axmud::CLIENT->inc_taskTotal();
19478 # Set the session to which this current task will belong
19479 $self->{session} = $session;
19480 # Create an entry in the session's current tasklist
19481 $session->add_task($self);
19482  
19483 } else {
19484  
19485 # If ->storableFlag is not set, the task can't be added to any initial/custom tasklist
19486 if (! $self->storableFlag) {
19487  
19488 return $self->writeError(
19489 '\'' . $self->prettyName . '\' task cannot be added as an initial/custom task',
19490 $self->_objClass . '->updateTaskLists',
19491 );
19492  
19493 } elsif ($self->taskType eq 'initial') {
19494  
19495 if (! defined $self->profName) {
19496  
19497 # Give task a unique name within the global initial tasklist
19498 $self->{uniqueName}
19499 = $self->{name} . '_' . $axmud::CLIENT->inc_initTaskTotal();
19500 # Create an entry in the global initial tasklist
19501 $axmud::CLIENT->add_initTask($self);
19502  
19503 } else {
19504  
19505 # Give task a unique name within the associated profile's initial tasklist
19506 $profile = $session->ivShow('profHash', $self->profName);
19507 $self->{uniqueName}
19508 = $self->{name} . '_' . $profile->ivIncrement('initTaskTotal');
19509  
19510 # Inform the associated profile it has acquired a new initial task
19511 $profile->ivAdd('initTaskHash', $self->uniqueName, $self);
19512 $profile->ivPush('initTaskOrderList', $self->uniqueName);
19513 }
19514  
19515 } elsif ($self->taskType eq 'custom') {
19516  
19517 # Create an entry in the custom tasklist registry (the ->uniqueName IV isn't set;
19518 # the task already has a ->customName)
19519 $axmud::CLIENT->add_customTask($self);
19520 }
19521  
19522 # The parent file object should be marked as having had its data modified
19523 $session->setModifyFlag(
19524 $self->_parentFile,
19525 TRUE,
19526 $self->_objClass . '->updateTaskLists',
19527 );
19528 }
19529  
19530 return 1;
19531 }
19532  
19533 # Code for 'process' tasks
19534  
19535 sub main {
19536  
19537 # All process tasks must have their own main() function which resembles this generic one
19538 # $self->main() is called by GA::Session->taskLoop() every time the task loop spins
19539 #
19540 # Activity tasks should not have a main() function. They inherit their main() function from
19541 # this generic task, and an error is displayed if anything tries to call it
19542 #
19543 # Expected arguments
19544 # (none besides $self)
19545 #
19546 # Return values
19547 # 'undef' on improper arguments, if there is an error, if the task is shutting down or if
19548 # the task is reset
19549 # Otherwise, we normally return the new value of $self->stage
19550  
19551 my ($self, $check) = @_;
19552  
19553 # Local variables
19554 my $newTaskObj;
19555  
19556 # Check for improper arguments
19557 if (defined $check) {
19558  
19559 return $axmud::CLIENT->writeImproper($self->_objClass . '->main', @_);
19560 }
19561  
19562 if ($self->category eq 'activity') {
19563  
19564 # Issue a warning - activity tasks should not have their own main function, and it
19565 # should not be called
19566 return $self->writeError(
19567 '\'' . $self->uniqueName . '\' task is an activity task, but its ->main() function'
19568 . ' was called',
19569 $self->_objClass . '->main',
19570 );
19571  
19572 } elsif ($self->shutdownFlag) {
19573  
19574 # There are two ways to stop a task - by setting its status to 'finished' (in which case
19575 # it stops immediately), or by setting its ->shutdownFlag to TRUE
19576 # Task is shutting down. Close the task window, if it is open
19577 if ($self->taskWinFlag) {
19578  
19579 $self->closeWin();
19580 }
19581  
19582 # For built-in jealous tasks, inform the GA::Session that a built-in task has stopped
19583 # running
19584 if ($self->shortCutIV) {
19585  
19586 $self->session->del_standardTask($self);
19587 }
19588  
19589 # If the Status task is running, tell it to update its display of active tasks (unless
19590 # this task is the Status task, of course)
19591 if ($self->name ne 'status_task') {
19592  
19593 $self->session->update_statusTask();
19594 }
19595  
19596 # Execute any other code (each task can define their own ->doShutdown() function)
19597 $self->doShutdown();
19598  
19599 # This task can stop immediately
19600 $self->ivPoke('status', 'finished');
19601 return undef;
19602  
19603 } elsif ($self->status eq 'reset') {
19604  
19605 # The task is resetting
19606 # Create a new copy of this task, preserving some of its task parameters, but setting
19607 # other task parameters to their default states
19608 $newTaskObj = $self->_objClass->new($self->session, 'current');
19609 if (! $newTaskObj) {
19610  
19611 # Reset failed; halt this task instead
19612 $self->ivPoke('status', 'finished');
19613  
19614 return $self->writeError(
19615 'Failed to reset \'' . $self->uniqueName . '\' task - halting task instead',
19616 $self->_objClass . '->main',
19617 );
19618 }
19619  
19620 # Also preserve a few task settings. The new task has the same ->endStatus, ->endTime
19621 # and TTS settings as this one
19622 $newTaskObj->set_endStatus($self->endStatus);
19623 $newTaskObj->set_endTime($self->endTime);
19624 $newTaskObj->set_hasResetFlag(TRUE);
19625 $newTaskObj->set_ttsConfig($self->ttsConfig);
19626 $newTaskObj->set_ttsHash($self);
19627 # New task should be 'running', and start at stage 2 on the next task loop
19628 $newTaskObj->set_status('running');
19629 $newTaskObj->set_stage(2);
19630  
19631 # Copy some of this task's parameters to the new task
19632 $self->preserve($newTaskObj);
19633  
19634 # For built-in jealous tasks, inform the GA::Session that an old built-in task has
19635 # stopped running, and that a new one has started running
19636 if ($self->shortCutIV) {
19637  
19638 $self->session->del_standardTask($self);
19639 }
19640  
19641 if ($newTaskObj->shortCutIV) {
19642  
19643 $self->session->add_standardTask($newTaskObj);
19644 }
19645  
19646 # If the Status task is running, tell it to update its display of active tasks (unless
19647 # this task is the Status task, of course)
19648 if ($self->name ne 'status_task') {
19649  
19650 $self->session->update_statusTask();
19651 }
19652  
19653 # If there is a task window open, transfer it to the new task
19654 $self->transferWin($newTaskObj);
19655  
19656 # Execute any other code (each task can define their own ->doReset() function)
19657 $self->doReset($newTaskObj);
19658  
19659 # This task must stop immediately, to be replaced by $newTaskObj on the next task loop
19660 $self->ivPoke('status', 'finished');
19661 return undef;
19662  
19663 } elsif ($self->stage == 1) {
19664  
19665 # Create a new task window (if possible)
19666 if (
19667 ! $self->taskWinFlag
19668 && $self->allowWinFlag
19669 && ($self->requireWinFlag || $self->startWithWinFlag)
19670 ) {
19671 # Create a new task window
19672 if (! $self->openWin($self->winmap) && $self->requireWinFlag) {
19673  
19674 # The window was not opened, but the task requires a window in order to run, so
19675 # it must be halted
19676 $self->writeWarning(
19677 '\'' . $self->uniqueName . '\' task couldn\'t open its own window'
19678 . ' - aborting task',
19679 $self->_objClass . '->main',
19680 );
19681  
19682 $self->ivPoke('status', 'finished');
19683 return undef;
19684 }
19685 }
19686  
19687 # Set the global variable to tell any interested parties that this built-in task is
19688 # running
19689 $self->session->add_standardTask($self);
19690 # If the Status task is running, tell it to update its display of active tasks (unless
19691 # this task is the Status task, of course)
19692 if ($self->name ne 'status_task') {
19693  
19694 $self->session->update_statusTask();
19695 }
19696  
19697 # Execute any other code (each task can define their own ->doFirstStage() function)
19698 $self->doFirstStage();
19699  
19700 return $self->ivPoke('stage', 2);
19701  
19702 } else {
19703  
19704 # Process stages 2+
19705 return $self->doStage();
19706 }
19707 }
19708  
19709 sub doFirstStage {
19710  
19711 # Called by $self->main, just before the task completes the first stage ($self->stage)
19712 # This function does nothing, so tasks that need to do something special during the first
19713 # stage should have their own ->doFirstStage function
19714 #
19715 # Expected arguments
19716 # (none besides $self)
19717 #
19718 # Return values
19719 # 'undef' on improper arguments
19720 # 1 otherwise
19721  
19722 my ($self, $check) = @_;
19723  
19724 # Check for improper arguments
19725 if (defined $check) {
19726  
19727 return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_);
19728 }
19729  
19730 # (This generic ->doFirstStage function does nothing)
19731  
19732 return 1;
19733 }
19734  
19735 sub doStage {
19736  
19737 # Called by $self->main to process all stages (except stage 1)
19738 #
19739 # Expected arguments
19740 # (none besides $self)
19741 #
19742 # Return values
19743 # 'undef' on improper arguments or if this function sets that task's ->status IV to
19744 # 'finished' or sets its ->shutdownFlag to TRUE
19745 # Otherwise, we normally return the new value of $self->stage
19746  
19747 my ($self, $check) = @_;
19748  
19749 # Check for improper arguments
19750 if (defined $check) {
19751  
19752 return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_);
19753 }
19754  
19755 if ($self->stage == 2) {
19756  
19757 # (This generic ->doFirstStage function does nothing at stage 2, which repeats
19758 # indefinitely)
19759 return $self->ivPoke('stage', 2);
19760  
19761 } else {
19762  
19763 # The task stage has somehow been set to an invalid value
19764 return $self->invalidStage();
19765 }
19766 }
19767  
19768 sub invalidStage {
19769  
19770 # Called by $self->doStage when $self->stage has been set to an unrecognised value
19771 #
19772 # Expected arguments
19773 # (none besides $self)
19774 #
19775 # Return values
19776 # 'undef'
19777  
19778 my ($self, $check) = @_;
19779  
19780 # Check for improper arguments
19781 if (defined $check) {
19782  
19783 return $axmud::CLIENT->writeImproper($self->_objClass . '->invalidStage', @_);
19784 }
19785  
19786 # If $self->stage has been set to an unrecognised value, we can't continue
19787 $self->ivPoke('status', 'finished');
19788  
19789 return $self->writeError(
19790 '\'' . $self->uniqueName . '\' task : undefined task stage \'' . $self->stage . '\'',
19791 $self->_objClass . '->invalidStage',
19792 );
19793 }
19794  
19795 # Code for 'activity' tasks
19796  
19797 sub init {
19798  
19799 # All activity tasks must have their own init() function which resembles this generic one
19800 # $self->init() is called by GA::Session->taskLoop() once, when the task is added to the
19801 # current tasklist
19802 #
19803 # Process tasks should not have an init() function. They inherit their init() function from
19804 # this generic task, and an error is displayed if anything tries to call it
19805 #
19806 # Expected arguments
19807 # (none besides $self)
19808 #
19809 # Return values
19810 # 'undef' on improper arguments, if there is an error, if the task is shutting down or if
19811 # the task is reset
19812 # 1 otherwise
19813  
19814 my ($self, $check) = @_;
19815  
19816 # Local variables
19817 # ...
19818  
19819 # Check for improper arguments
19820 if (defined $check) {
19821  
19822 return $axmud::CLIENT->writeImproper($self->_objClass . '->init', @_);
19823 }
19824  
19825 if ($self->category eq 'process') {
19826  
19827 # Issue a warning - process tasks should not have their own init function, and it should
19828 # not be called
19829 return $self->writeError(
19830 '\'' . $self->uniqueName . '\' task is a process task, but its ->init() function'
19831 . ' was called',
19832 $self->_objClass . '->init',
19833 );
19834 }
19835  
19836 # Create a new task window (if possible)
19837 if (
19838 ! $self->taskWinFlag
19839 && $self->allowWinFlag
19840 && ($self->requireWinFlag || $self->startWithWinFlag)
19841 ) {
19842 # Create a new task window
19843 if (! $self->openWin($self->winmap) && $self->requireWinFlag) {
19844  
19845 # The window was not opened, but the task requires a window in order to run, so it
19846 # must be halted
19847 $self->writeWarning(
19848 '\'' . $self->uniqueName . '\' task couldn\'t open its own window'
19849 . ' - aborting task',
19850 $self->_objClass . '->main',
19851 );
19852  
19853 $self->ivPoke('status', 'finished');
19854 return undef;
19855 }
19856 }
19857  
19858 # For built-in jealous tasks, inform the GA::Session that a built-in task has started
19859 # running
19860 if ($self->shortCutIV) {
19861  
19862 $self->session->add_standardTask($self);
19863 }
19864  
19865 # If the Status task is running, tell it to update its display of active tasks (unless
19866 # this task is the Status task, of course)
19867 if ($self->name ne 'status_task') {
19868  
19869 $self->session->update_statusTask();
19870 }
19871  
19872 # Execute any other code (each task can define their own ->doInit() function)
19873 $self->doInit();
19874  
19875 # Setup complete
19876 return 1;
19877 }
19878  
19879 sub doInit {
19880  
19881 # Called by $self->init, just before the task completes its setup ($self->init)
19882 # This function does nothing, so tasks that need to do something special during a reset
19883 # should have their own ->doInit function
19884 # NB If this function modifies the task window - for example, if it should add table objects
19885 # to the window - the function should first check $self->hasResetFlag, and refrain from
19886 # creating new table objects for a window that already contains them (some example code
19887 # appears below)
19888 #
19889 # Expected arguments
19890 # (none besides $self)
19891 #
19892 # Return values
19893 # 'undef' on improper arguments
19894 # 1 otherwise
19895  
19896 my ($self, $check) = @_;
19897  
19898 # Check for improper arguments
19899 if (defined $check) {
19900  
19901 return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_);
19902 }
19903  
19904 # (This generic ->doInit function does nothing)
19905  
19906 # If the task creates a window with various table objects, it might be easier to remove
19907 # them all, rather than writing code to update them all when the task resets. You can use
19908 # this example code in that case
19909 # if ($self->hasResetFlag) {
19910 #
19911 # if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) {
19912 #
19913 # # Operation failed; task must close
19914 # $self->ivPoke('shutdownFlag', TRUE);
19915 # return 1;
19916 # }
19917 # }
19918  
19919 return 1;
19920 }
19921  
19922 sub shutdown {
19923  
19924 # All activity tasks must have their own shutdown() function to allow the task to shut down
19925 # gracefully
19926 # $self->shutdown is called by GA::Session->taskLoop() once, when its ->shutdownFlag is
19927 # set to TRUE
19928 # Also called by GA::Session->stop, should the session have to stop suddenly (makes sure
19929 # any task windows are closed)
19930 #
19931 # Expected arguments
19932 # (none besides $self)
19933 #
19934 # Return values
19935 # 'undef' on improper arguments
19936 # 1 otherwise
19937  
19938 my ($self, $check) = @_;
19939  
19940 # Check for improper arguments
19941 if (defined $check) {
19942  
19943 return $axmud::CLIENT->writeImproper($self->_objClass . '->shutdown', @_);
19944 }
19945  
19946 # Task is shutting down. Close the task window, if it is open
19947 if ($self->taskWinFlag) {
19948  
19949 $self->closeWin();
19950 }
19951  
19952 # For built-in jealous tasks, inform the GA::Session that a built-in task has stopped
19953 # running
19954 if ($self->shortCutIV) {
19955  
19956 $self->session->del_standardTask($self);
19957 }
19958  
19959 # If the Status task is running, tell it to update its display of active tasks (unless this
19960 # task is the Status task, of course)
19961 if ($self->name ne 'status_task') {
19962  
19963 $self->session->update_statusTask();
19964 }
19965  
19966 # Execute any other code (each task can define their own ->doShutdown() function)
19967 $self->doShutdown();
19968  
19969 # Task can stop immediately
19970 $self->ivPoke('status', 'finished');
19971 return undef;
19972 }
19973  
19974 sub reset {
19975  
19976 # All activity tasks must have their own reset() function to allow the task to reset
19977 # properly
19978 # $self->reset is called by GA::Session->taskLoop() once, when its ->status is set to
19979 # 'reset'
19980 #
19981 # Expected arguments
19982 # (none besides $self)
19983 #
19984 # Return values
19985 # 'undef'
19986  
19987 my ($self, $check) = @_;
19988  
19989 # Local variables
19990 my $newTaskObj;
19991  
19992 # Check for improper arguments
19993 if (defined $check) {
19994  
19995 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset', @_);
19996 }
19997  
19998 # The task is resetting
19999 # Create a new copy of this task, preserving some of its task parameters, but setting other
20000 # task parameters to their default states
20001 $newTaskObj = $self->_objClass->new($self->session, 'current');
20002 if (! $newTaskObj) {
20003  
20004 # Reset failed; halt this task instead
20005 $self->ivPoke('status', 'finished');
20006  
20007 return $self->writeError(
20008 'Failed to reset \'' . $self->uniqueName . '\' task - halting task instead',
20009 $self->_objClass . '->reset',
20010 );
20011 }
20012  
20013 # Also preserve a few task settings. The new task has the same ->endStatus, ->endTime and
20014 # TTS settings as this one
20015 $newTaskObj->set_endStatus($self->endStatus);
20016 $newTaskObj->set_endTime($self->endTime);
20017 $newTaskObj->set_hasResetFlag(TRUE);
20018 $newTaskObj->set_ttsConfig($self->ttsConfig);
20019 $newTaskObj->set_ttsHash($self);
20020 # New task's status should be left as 'wait_init', so that its ->init function will be
20021 # called on the next task loop
20022 $newTaskObj->set_status('wait_init');
20023  
20024 # Copy some of this task's parameters to the new task
20025 $self->preserve($newTaskObj);
20026  
20027 # For built-in jealous tasks, inform the GA::Session that an old built-in task has stopped
20028 # running, and that a new one has started running
20029 if ($self->shortCutIV) {
20030  
20031 $self->session->del_standardTask($self);
20032 }
20033  
20034 if ($newTaskObj->shortCutIV) {
20035  
20036 $self->session->add_standardTask($newTaskObj);
20037 }
20038  
20039 # If the Status task is running, tell it to update its display of active tasks (unless this
20040 # task is the Status task, of course)
20041 if ($self->name ne 'status_task') {
20042  
20043 $self->session->update_statusTask();
20044 }
20045  
20046 # If there is a task window open, transfer it to the new task
20047 $self->transferWin($newTaskObj);
20048  
20049 # Execute any other code (each task can define their own ->doReset() function)
20050 $self->doReset($newTaskObj);
20051  
20052 # This task must stop immediately, to be replaced by $newTaskObj on the next task loop
20053 $self->ivPoke('status', 'finished');
20054 return undef;
20055 }
20056  
20057 # Code for both 'process' and 'activity' functions
20058  
20059 sub doShutdown {
20060  
20061 # Called just before the task completes a shutdown
20062 # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown
20063 #
20064 # This function does nothing, so tasks that need to do something special during a shutdown
20065 # should have their own ->doShutdown function
20066 #
20067 # Expected arguments
20068 # (none besides $self)
20069 #
20070 # Return values
20071 # 'undef' on improper arguments
20072 # 1 otherwise
20073  
20074 my ($self, $check) = @_;
20075  
20076 # Check for improper arguments
20077 if (defined $check) {
20078  
20079 return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_);
20080 }
20081  
20082 # (This generic ->doShutdown function does nothing)
20083  
20084 return 1;
20085 }
20086  
20087 sub doReset {
20088  
20089 # Called just before the task completes a reset
20090 # For process tasks, called by $self->main. For activity tasks, called by $self->reset
20091 #
20092 # This function does nothing, so tasks that need to do something special during a reset
20093 # should have their own ->doReset function
20094 #
20095 # Expected arguments
20096 # $newTaskObj - The replacement task object
20097 #
20098 # Return values
20099 # 'undef' on improper arguments
20100 # 1 otherwise
20101  
20102 my ($self, $newTaskObj, $check) = @_;
20103  
20104 # Check for improper arguments
20105 if (! defined $newTaskObj || defined $check) {
20106  
20107 return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_);
20108 }
20109  
20110 # (This generic ->doReset function does nothing)
20111  
20112 return 1;
20113 }
20114  
20115 # Task window functions
20116  
20117 sub toggleWin {
20118  
20119 # Called by GA::Cmd::OpenTaskWindow->do and CloseTaskWindow->do
20120 # Decides what to do if the user tries to open or close a task window for this task
20121 # Should usually display a message informing the user of what it decided to do
20122 #
20123 # Expected arguments
20124 # (none besides $self)
20125 #
20126 # Return values
20127 # 'undef' on improper arguments or if the task isn't able to open a task window
20128 # 1 if the window is opened/closed
20129  
20130 my ($self, $check) = @_;
20131  
20132 # Local variables
20133 my $func;
20134  
20135 # Check for improper arguments
20136 if (defined $check) {
20137  
20138 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleWin', @_);
20139 }
20140  
20141 if (! $self->allowWinFlag) {
20142  
20143 # This task isn't allowed to open a window
20144 return $self->writeError(
20145 'Windows not available for this task',
20146 $self->_objClass . '->toggleWin',
20147 );
20148  
20149 } elsif ($self->taskWinFlag) {
20150  
20151 # A window is open, so close it
20152 $self->closeWin();
20153  
20154 if ($self->requireWinFlag) {
20155  
20156 # The task should shut down when its window is closed
20157 $self->ivPoke('shutdownFlag', TRUE);
20158 $self->writeText(
20159 'Window for \'' . $self->prettyName . '\' task closed (task will also halt)',
20160 );
20161  
20162 } else {
20163  
20164 # The task can continue without a window
20165 $self->writeText(
20166 'Window for \'' . $self->prettyName . '\' task closed',
20167 );
20168 }
20169  
20170 # Window closing complete
20171 return 1;
20172  
20173 } else {
20174  
20175 # A window is not currently open, so open it
20176 $self->openWin($self->winmap);
20177  
20178 if (! $self->taskWinFlag) {
20179  
20180 if ($self->requireWinFlag) {
20181  
20182 # The task cannot run without a window
20183 $self->ivPoke('shutdownFlag', TRUE);
20184 $self->writeText(
20185 'Window for \'' . $self->prettyName . '\' task could not be opened (task'
20186 . ' will be halted)',
20187 );
20188  
20189 } else {
20190  
20191 # The task can continue without a window
20192 $self->writeText(
20193 'Window for \'' . $self->prettyName . '\' task could not be opened',
20194 );
20195 }
20196  
20197 } else {
20198  
20199 $self->writeText(
20200 'Window for \'' . $self->prettyName . '\' task opened',
20201 );
20202  
20203 # If the task defines a function to call, in order to set up the window after being
20204 # opened, call the function now
20205 $func = $self->winUpdateFunc;
20206 if ($func) {
20207  
20208 $self->$func();
20209 }
20210 }
20211  
20212 # Window opening complete
20213 return 1;
20214 }
20215 }
20216  
20217 sub openWin {
20218  
20219 # Called by the task's ->main method or by its ->toggleWin method, or by any other code
20220 # Tries to open each type of task window in $self->winPreferList, halting at the first
20221 # successful attempt (or when all attempts fail)
20222 #
20223 # Expected arguments
20224 # (none besides self)
20225 #
20226 # Optional arguments
20227 # $winmap - The winmap to use in a 'grid' window or a pseudo-window (matches a key in
20228 # GA::Client->winmapHash). If 'undef', $self->winmap is used
20229 # @preferList - The types of task window to try to open. If not an empty list, this list
20230 # is used rather than $self->winPreferList
20231 #
20232 # Return values
20233 # 'undef' on improper arguments, if $winmap doesn't exist (when specified, checked even if
20234 # a 'grid' window isn't opened) or if a task window is not opened
20235 # 1 if a window is opened
20236  
20237 my ($self, $winmap, @preferList) = @_;
20238  
20239 # Local variables
20240 my ($winmapObj, $result);
20241  
20242 # (No improper arguments to check)
20243  
20244 # Don't open a task window if it's not allowed, or if there's already one open
20245 # Additionally, in Axmud 'blind' mode, don't open a task window unless it's required (the
20246 # task won't run without a window)
20247 if (
20248 ! $self->allowWinFlag
20249 || ! $self->winPreferList
20250 || $self->taskWinFlag
20251 || ($axmud::BLIND_MODE_FLAG && ! $self->requireWinFlag)
20252 ) {
20253 return undef;
20254 }
20255  
20256 # If $winmap wasn't specified, use the winmap specified by the IV or a default winmap, if
20257 # necessary
20258 if (! $winmap) {
20259  
20260 if ($self->winmap) {
20261 $winmap = $self->winmap;
20262 } else {
20263 $winmap = 'basic_empty';
20264 }
20265 }
20266  
20267 # Check the winmap exists
20268 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $winmap);
20269 if (! $winmapObj) {
20270  
20271 return undef;
20272 }
20273  
20274 # Open a task window, giving up after the first successful attempt
20275 if (! @preferList) {
20276  
20277 @preferList = $self->winPreferList;
20278 }
20279  
20280 OUTER: foreach my $item (@preferList) {
20281  
20282 if ($item eq 'grid') {
20283 $result = $self->openGridWin($winmapObj);
20284 } elsif ($item eq 'pane') {
20285 $result = $self->openPaneWin($winmapObj, FALSE);
20286 } elsif ($item eq 'entry') {
20287 $result = $self->openPaneWin($winmapObj, TRUE);
20288 } elsif ($item eq 'pseudo') {
20289 $result = $self->openPseudoWin($winmapObj);
20290 }
20291  
20292 if ($result) {
20293  
20294 last OUTER;
20295 }
20296 }
20297  
20298 return $result;
20299 }
20300  
20301 sub openGridWin {
20302  
20303 # Called by the $self->openWin (only)
20304 # Tries to open a task window as a 'grid' window (in response to 'grid' in
20305 # $self->winPreferList)
20306 #
20307 # Expected arguments
20308 # $winmapObj - The winmap object to use in the task window (matches a value in
20309 # GA::Client->winmapHash)
20310 #
20311 # Return values
20312 # 'undef' on improper arguments or if a 'grid' window is not opened
20313 # 1 if a 'grid' window is opened
20314  
20315 my ($self, $winmapObj, $check) = @_;
20316  
20317 # Local variables
20318 my (
20319 $winObj,
20320 @workspaceList,
20321 );
20322  
20323 # Check for improper arguments
20324 if (! defined $winmapObj || defined $check) {
20325  
20326 return $axmud::CLIENT->writeImproper($self->_objClass . '->openGridWin', @_);
20327 }
20328  
20329 # Compile a list of workspaces, with the workspace containing the parent session's 'main'
20330 # window first
20331 @workspaceList
20332 = $axmud::CLIENT->desktopObj->listWorkspaces($self->session->mainWin->workspaceObj);
20333  
20334 OUTER: foreach my $workspaceObj (@workspaceList) {
20335  
20336 $winObj = $workspaceObj->createGridWin(
20337 'custom', # All task windows are 'custom' windows
20338 $self->name, # Window name is the same as the task name
20339 $self->prettyName, # Window title
20340 $winmapObj->name,
20341 'Games::Axmud::Win::Internal',
20342 # Package name
20343 undef, # No windows exists yet
20344 undef, # Ditto
20345 $self, # Owner
20346 $self->session,
20347 $workspaceObj->findWorkspaceGrid($self->session),
20348 # Session's workspace grid object
20349 );
20350  
20351 if ($winObj) {
20352  
20353 last OUTER;
20354 }
20355 }
20356  
20357 if (! $winObj) {
20358  
20359 # Window not opened
20360 return undef;
20361  
20362 } else {
20363  
20364 # Window created and enabled
20365 $self->ivPoke('winObj', $winObj);
20366 $self->ivPoke('taskWinFlag', TRUE);
20367 # Set its title
20368 $self->setTaskWinTitle();
20369  
20370 # In Axmud 'blind' mode, make sure the session's 'main' window is not obscured by the
20371 # newly-opened task window
20372 if ($axmud::BLIND_MODE_FLAG) {
20373  
20374 $self->session->mainWin->restoreFocus();
20375 }
20376 }
20377  
20378 # Add a tab, if required. The TRUE argument indicates window setup
20379 $self->addTab(undef, TRUE);
20380 # Set up the entry box, if present
20381 $self->setupEntry();
20382  
20383 return 1;
20384 }
20385  
20386 sub openPaneWin {
20387  
20388 # Called by the $self->openWin (only)
20389 # Tries to open a task window as a pane object (GA::Table::Pane) inside the session's 'main'
20390 # window (in response to 'pane' or 'entry' in $self->winPreferList)
20391 #
20392 # Expected arguments
20393 # $winmapObj - The winmap object that would be used if a 'grid' window were opened
20394 # instead. This function sometimes uses it to work out with the pane
20395 # object should have an entry box, or not; in that situation, it chooses
20396 # no entry box if this value is 'undef'
20397 #
20398 # Optional arguments
20399 # $entryFlag - TRUE if the pane object should have its own entry box, FALSE (or 'undef')
20400 # if not
20401 #
20402 # Return values
20403 # 'undef' on improper arguments or if a pane object is not created
20404 # 1 if a pane object is created
20405  
20406 my ($self, $winmapObj, $entryFlag, $check) = @_;
20407  
20408 # Local variables
20409 my ($stripObj, $entryFunc, $left, $right, $top, $bottom, $tableObj, $tabObj);
20410  
20411 # Check for improper arguments
20412 if (! defined $winmapObj || defined $check) {
20413  
20414 return $axmud::CLIENT->writeImproper($self->_objClass . '->openPaneWin', @_);
20415 }
20416  
20417 # Tasks can't create pane objects inside 'main' windows if it's a 'main' window shared
20418 # between sessions
20419 if ($axmud::CLIENT->shareMainWinFlag) {
20420  
20421 return undef;
20422 }
20423  
20424 # If there's an entry box, set the callback function
20425 if ($entryFlag) {
20426  
20427 $entryFunc = $self->getMethodRef('entryCallback');
20428 }
20429  
20430 # Ask the session's 'main' window for the size and position of another table object, using
20431 # the winmap's default winzone size, and check whether space exists for another table
20432 # object
20433 $stripObj = $self->session->mainWin->tableStripObj;
20434 ($left, $right, $top, $bottom) = $stripObj->findPosn();
20435 if (! defined $left) {
20436  
20437 # No room for another table object
20438 return undef;
20439 }
20440  
20441 # Create a pane object at the specified size and position
20442 $tableObj = $stripObj->addTableObj(
20443 'Games::Axmud::Table::Pane',
20444 $left,
20445 $right,
20446 $top,
20447 $bottom,
20448 undef, # No ->objName
20449 # ->initHash
20450 'frame_title' => $self->prettyName,
20451 'entry_flag' => $entryFlag,
20452 'func' => $entryFunc,
20453 'id' => $self->uniqueName,
20454 'new_line' => 'before',
20455 );
20456  
20457 if (! $tableObj) {
20458  
20459 return undef;
20460 }
20461  
20462 # Pane object created and enabled
20463 $self->ivPoke('tableObj', $tableObj);
20464 $self->ivPoke('taskWinFlag', TRUE);
20465 $self->ivPoke('taskWinEntryFlag', $entryFlag);
20466  
20467 # Add a tab, if required. The TRUE argument indicates window setup
20468 $self->addTab(undef, TRUE);
20469  
20470 # Operatin complete
20471 return 1;
20472 }
20473  
20474 sub openPseudoWin {
20475  
20476 # Called by the $self->openWin (only)
20477 # Tries to open a task window as a pseudo-window inside the session's 'main' window, the
20478 # pseudo-window being handled by the table object GA::Table::PseudoWin (in response to
20479 # 'pseudo' in $self->winPreferList)
20480 #
20481 # Expected arguments
20482 # $winmapObj - The winmap object to use in the task window (matches a value in
20483 # GA::Client->winmapHash)
20484 #
20485 # Return values
20486 # 'undef' on improper arguments or if the pseudo-window is not opened
20487 # 1 if a pane object is created
20488  
20489 my ($self, $winmapObj, $entryFlag, $check) = @_;
20490  
20491 # Local variables
20492 my ($stripObj, $tableObj, $left, $right, $top, $bottom, $paneObj, $tabObj, $entryObj);
20493  
20494 # Check for improper arguments
20495 if (! defined $winmapObj || defined $check) {
20496  
20497 return $axmud::CLIENT->writeImproper($self->_objClass . '->openPseudoWin', @_);
20498 }
20499  
20500 # Tasks can't create boxes inside 'main' windows if it's a 'main' window shared between
20501 # sessions
20502 if ($axmud::CLIENT->shareMainWinFlag) {
20503  
20504 return undef;
20505 }
20506  
20507 # If there are any holders (GA::Table::Holder) with a suitable ->id, we can use the space
20508 # they occupy, rather than looking for a new space
20509 # Try (for example) 'status_task' first, then 'task'
20510 $stripObj = $self->session->mainWin->tableStripObj;
20511 $tableObj = $stripObj->replaceHolder(
20512 $self->name,
20513 'Games::Axmud::Table::PseudoWin',
20514 undef, # No ->objName
20515 # ->initHash
20516 'frame_title' => $self->prettyName,
20517 'win_type' => 'custom',
20518 'win_name' => $self->prettyName,
20519 'owner' => $self,
20520 'session' => $self->session,
20521 'winmap' => $winmapObj->name,
20522 );
20523  
20524 if (! $tableObj) {
20525  
20526 $stripObj->replaceHolder(
20527 'task',
20528 'Games::Axmud::Table::PseudoWin',
20529 undef, # No ->objName
20530 # ->initHash
20531 'frame_title' => $self->prettyName,
20532 'win_type' => 'custom',
20533 'win_name' => $self->prettyName,
20534 'owner' => $self,
20535 'session' => $self->session,
20536 'winmap' => $winmapObj->name,
20537 );
20538 }
20539  
20540 if (! $tableObj) {
20541  
20542 # Ask the session's 'main' window for the size and position of another table object,
20543 # using the winmap's default winzone size, and check whether space exists for another
20544 # table object
20545 ($left, $right, $top, $bottom) = $stripObj->findPosn();
20546 if (! defined $left) {
20547  
20548 # No room for another table object
20549 return undef;
20550 }
20551  
20552 # Create the GA::Table::PseudoWin object at the specified size and position
20553 $tableObj = $stripObj->addTableObj(
20554 'Games::Axmud::Table::PseudoWin',
20555 $left,
20556 $right,
20557 $top,
20558 $bottom,
20559 undef, # No ->objName
20560 # ->initHash
20561 'frame_title' => $self->prettyName,
20562 'win_type' => 'custom',
20563 'win_name' => $self->prettyName,
20564 'owner' => $self,
20565 'session' => $self->session,
20566 'winmap' => $winmapObj->name,
20567 );
20568 }
20569  
20570 if (! $tableObj) {
20571  
20572 return undef;
20573 }
20574  
20575 # Table object created and enabled
20576 $self->ivPoke('tableObj', $tableObj);
20577 $self->ivPoke('winObj', $tableObj->pseudoWinObj);
20578 $self->ivPoke('taskWinFlag', TRUE);
20579 $self->ivPoke('taskWinEntryFlag', $entryFlag);
20580  
20581 # Add a tab, if required. The TRUE argument indicates window setup
20582 $self->addTab(undef, TRUE);
20583 # Set up the entry box, if present
20584 $self->setupEntry();
20585  
20586 return 1;
20587 }
20588  
20589 sub closeWin {
20590  
20591 # Called by the task's ->main method or by its ->toggleWin method, or by any other code
20592 # Close the task window for this task, if it is open
20593 #
20594 # Expected arguments
20595 # (none besides self)
20596 #
20597 # Return values
20598 # 'undef' on improper arguments or if the window was not closed
20599 # 1 if the window was closed
20600  
20601 my ($self, $check) = @_;
20602  
20603 # Local variables
20604 my $result;
20605  
20606 # Check for improper arguments
20607 if (defined $check) {
20608  
20609 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeWin', @_);
20610 }
20611  
20612 if ($self->tableObj) {
20613  
20614 # Remove a pseudo-window or a pane object inside this session's 'main' window
20615 $result = $self->session->mainWin->tableStripObj->removeTableObj($self->tableObj);
20616 $self->ivUndef('tableObj');
20617 $self->ivUndef('winObj');
20618  
20619 } elsif ($self->winObj) {
20620  
20621 # Remove a 'grid' window
20622 $result = $self->winObj->winDestroy();
20623 $self->ivUndef('winObj');
20624 }
20625  
20626 $self->ivPoke('taskWinFlag', FALSE);
20627 $self->ivPoke('taskWinEntryFlag', FALSE);
20628 $self->ivUndef('defaultTabObj');
20629  
20630 # If the task window could not be closed, or wasn't open in the first place, return 'undef';
20631 # otherwise return 1
20632 return $result;
20633 }
20634  
20635 sub transferWin {
20636  
20637 # Called by the task's ->main and ->reset functions
20638 # Transfers the task window to a new task
20639 #
20640 # Expected arguments
20641 # $newTaskObj - The new task
20642 #
20643 # Return values
20644 # 'undef' on improper arguments
20645 # 1 otherwise
20646  
20647 my ($self, $newTaskObj, $check) = @_;
20648  
20649 # Check for improper arguments
20650 if (! defined $newTaskObj || defined $check) {
20651  
20652 return $axmud::CLIENT->writeImproper($self->_objClass . '->transferWin', @_);
20653 }
20654  
20655 if ($self->winObj && $self->tableObj) {
20656  
20657 # Transfer a pseudo-window inside this session's 'main' window
20658 $newTaskObj->set_winObj($self->winObj);
20659 $newTaskObj->set_tableObj($self->tableObj);
20660 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
20661 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
20662 if ($self->defaultTabObj) {
20663  
20664 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
20665 }
20666  
20667 $newTaskObj->setTaskWinTitle();
20668 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
20669 $newTaskObj->winObj->set_owner($newTaskObj);
20670  
20671 } elsif ($self->winObj) {
20672  
20673 # Transfer a 'grid' window
20674 $newTaskObj->set_winObj($self->winObj);
20675 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
20676 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
20677 if ($self->defaultTabObj) {
20678  
20679 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
20680 }
20681  
20682 $newTaskObj->setTaskWinTitle();
20683 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
20684 $newTaskObj->winObj->set_owner($newTaskObj);
20685 $newTaskObj->winObj->resetUrgent(TRUE);
20686  
20687 } elsif ($self->tableObj) {
20688  
20689 # Remove a pane object inside this session's 'main' window
20690 $newTaskObj->set_tableObj($self->tableObj);
20691 $newTaskObj->set_taskWinFlag($self->taskWinFlag);
20692 $newTaskObj->set_taskWinEntryFlag($self->taskWinEntryFlag);
20693 if ($self->defaultTabObj) {
20694  
20695 $newTaskObj->set_defaultTabObj($self->defaultTabObj);
20696 }
20697  
20698 $newTaskObj->setTaskWinTitle();
20699 $newTaskObj->insertTextThenClear('<task reset>', 'empty');
20700 }
20701  
20702 return 1;
20703 }
20704  
20705 sub addTab {
20706  
20707 # Can be called by any code. During window setup, called by $self->openGridWin,
20708 # ->openPaneWin and ->openPseudoWin
20709 # Adds a tab to the task window's pane object, and updates IVs
20710 #
20711 # Expected arguments
20712 # (none besides $self)
20713 #
20714 # Optional arguments
20715 # $labelText - If defined, the tab label text to use. Ignored when a simple tab is
20716 # created
20717 # $openFlag - Set to TRUE when called during window setup, in which case a tab is not
20718 # opened if $self->tabMode is 'empty'. Set to FALSE (or 'undef') when
20719 # called by anything else, in which case this function treats values of
20720 # $self->tabMode 'empty and 'multi' the same, in other words, for all
20721 # defined values of $self->tabMode, we try to open a tab
20722 #
20723 # Return values
20724 # 'undef' on improper arguments or if no tab is added to the pane object
20725 # Otherwise returns the tab object (GA::Obj::Tab) created
20726  
20727 my ($self, $labelText, $openFlag, $check) = @_;
20728  
20729 # Local variables
20730 my ($paneObj, $tabObj);
20731  
20732 # Check for improper arguments
20733 if (defined $check) {
20734  
20735 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTab', @_);
20736 }
20737  
20738 # Find the pane object (GA::Table::Pane), if one was created
20739 if (! $self->winObj) {
20740 $paneObj = $self->tableObj;
20741 } else {
20742 $paneObj = $self->winObj->findTableObj('pane');
20743 }
20744  
20745 # The type of tab created depends on the value of $self->tabMode
20746 if (
20747 # No pane object exists
20748 ! $paneObj
20749 # Can't create tabs at all, if ->tabMode not set
20750 || ! defined $self->tabMode
20751 # Can't create a simple tab, if one already exists
20752 || ($self->tabMode eq 'simple' && $self->defaultTabObj)
20753 ) {
20754 return undef;
20755 }
20756  
20757 if ($self->tabMode eq 'simple') {
20758  
20759 $tabObj = $paneObj->addSimpleTab(
20760 $self->session,
20761 $self->getColourScheme(),
20762 );
20763  
20764 } elsif (
20765 ($openFlag && $self->tabMode eq 'multi')
20766 || ! $openFlag
20767 ) {
20768 $tabObj = $paneObj->addTab(
20769 $self->session,
20770 $self->getColourScheme(),
20771 undef,
20772 undef,
20773 $labelText,
20774 );
20775 }
20776  
20777 if (! $tabObj) {
20778  
20779 return undef;
20780 }
20781  
20782 if (! $self->defaultTabObj) {
20783  
20784 # The first tab added is the default one
20785 $self->ivPoke('defaultTabObj', $tabObj);
20786 }
20787  
20788 # The default newline behaviour for task windows is to insert a newline character before
20789 # each string displayed, rather than inserting one afterwards (as usual)
20790 $tabObj->textViewObj->set_newLineDefault('before');
20791  
20792 # Mark the pane's textview object as monochrome, if required
20793 if ($self->monochromeFlag) {
20794  
20795 $tabObj->paneObj->applyMonochrome($tabObj);
20796 }
20797  
20798 # Prevent the pane's textview from scrolling downwards
20799 if ($tabObj && $self->noScrollFlag) {
20800  
20801 $tabObj->textViewObj->set_scrollLockType('top');
20802 $tabObj->textViewObj->toggleScrollLock();
20803 }
20804  
20805 # Call a task function when the visible tab changes
20806 $paneObj->set_switchFunc($self->getMethodRef('switchTabCallback'));
20807 $paneObj->set_switchID($self->name);
20808  
20809 # Operation complete
20810 return $tabObj;
20811 }
20812  
20813 sub removeTab {
20814  
20815 # Can be called by any code
20816 # The task window's set up functions add a first tab (or not) to the window, and then other
20817 # parts of the task code are free to call $self->addTab to add more tabs, in which case
20818 # this function can be called to remove them again
20819 # When the task window closes, it's not necessary to call this function at all
20820 #
20821 # Expected arguments
20822 # $arg - So that tasks have flexibility over the way they store the tabs they create,
20823 # $arg can be the tab object (GA::Obj::Tab) or the tab object's ->number
20824 #
20825 # Return values
20826 # 'undef' on improper arguments, if the specified tab no longer exists in the task
20827 # window's pane object (GA::Table::Pane) or if the close operation fails
20828 # 1 if the close operation succeeds
20829  
20830 my ($self, $arg, $check) = @_;
20831  
20832 # Local variables
20833 my ($paneObj, $result);
20834  
20835 # Check for improper arguments
20836 if (defined $check) {
20837  
20838 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupEntry', @_);
20839 }
20840  
20841 # Find the pane object (GA::Table::Pane), if one was created
20842 if (! $self->winObj) {
20843 $paneObj = $self->tableObj;
20844 } else {
20845 $paneObj = $self->winObj->findTableObj('pane');
20846 }
20847  
20848 if (! $paneObj) {
20849  
20850 return undef;
20851 }
20852  
20853 # Find the pane object (GA::Table::Pane)
20854 $paneObj = $self->winObj->findTableObj('pane');
20855  
20856 if ($axmud::CLIENT->intCheck($arg, 0)) {
20857  
20858 $arg = $paneObj->ivShow('tabObjHash', $arg);
20859 if (! defined $arg) {
20860  
20861 # Tab has already been removed
20862 return undef;
20863 }
20864  
20865 } elsif (
20866 ! $paneObj->ivExists('tabObjHash', $arg->number)
20867 || $paneObj->ivShow('tabObjHash', $arg->number) ne $arg
20868 ) {
20869 # Tab has already been removed
20870 return undef;
20871 }
20872  
20873 # Remove the tab
20874 $result = $paneObj->removeTab($arg);
20875  
20876 # Update standard IVs
20877 if ($self->defaultTabObj && $self->defaultTabObj eq $arg) {
20878  
20879 $self->ivUndef('defaultTabObj');
20880 }
20881  
20882 # Operation complete
20883 return $result;
20884 }
20885  
20886 sub setupEntry {
20887  
20888 # Called by $self->openGridWin and ->openPseudoWin (only)
20889 # Sets up the task window's entry box, if it exists
20890 #
20891 # Expected arguments
20892 # (none besides $self)
20893 #
20894 # Return values
20895 # 'undef' on improper arguments or if no entry box exists
20896 # 1 otherwise
20897  
20898 my ($self, $check) = @_;
20899  
20900 # Local variables
20901 my $entryObj;
20902  
20903 # Check for improper arguments
20904 if (defined $check) {
20905  
20906 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupEntry', @_);
20907 }
20908  
20909 if (! $self->winObj) {
20910  
20911 return undef;
20912 }
20913  
20914 # Find the entry for this window, if one was created, and set its callback function. The
20915 # entry box may have been created by a strip object (GA::Strip::Entry) or a table object
20916 # (GA::Table::Entry)
20917 $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
20918 if (! $entryObj) {
20919  
20920 $entryObj = $self->winObj->findTableObj('entry');
20921 }
20922  
20923 if (! $entryObj) {
20924  
20925 $self->ivPoke('taskWinEntryFlag', FALSE);
20926  
20927 return undef;
20928  
20929 } else {
20930  
20931 $self->ivPoke('taskWinEntryFlag', TRUE);
20932 $entryObj->set_func($self->getMethodRef('entryCallback'));
20933 $entryObj->set_id($self->uniqueName);
20934  
20935 return 1;
20936 }
20937 }
20938  
20939 sub setTaskWinTitle {
20940  
20941 # Can be called by any code to set or restore the text in the task window label: the title
20942 # bar for a 'grid' window, or the frame title for a pane object in the session's 'main'
20943 # window
20944 #
20945 # Expected arguments
20946 # (none besides self)
20947 #
20948 # Optional arguments
20949 # $string - A string to add the title bar (if 'undef', the default title is used)
20950 # $flag - If TRUE, $string is added to the usual text; otherwise string replaces
20951 # the usual text
20952 #
20953 # Return values
20954 # 'undef' on improper arguments or if the task window is not open
20955 # 1 if the window was closed
20956  
20957 my ($self, $string, $flag, $check) = @_;
20958  
20959 # Local variables
20960 my $text;
20961  
20962 # Check for improper arguments
20963 if (defined $check) {
20964  
20965 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTaskWinTitle', @_);
20966 }
20967  
20968 # Set the default title bar text for task windows
20969 $text = $self->prettyName;
20970  
20971 # If $string was specified, append it to $text (or overwrite $text)
20972 if (defined $string) {
20973  
20974 if ($flag) {
20975 $text .= ' ' . $string;
20976 } else {
20977 $text = $string;
20978 }
20979 }
20980  
20981 # Update the label
20982 if ($self->tableObj) {
20983  
20984 # Set the frame title (calling a function in GA::Generic::Table)
20985 $self->tableObj->set_frameTitle($text);
20986 return 1;
20987  
20988 } elsif ($self->winObj) {
20989  
20990 # Set the title bar (calling a function in GA::Win::Internal)
20991 $self->winObj->setWinTitle($text);
20992 return 1;
20993  
20994 } else {
20995  
20996 # Task window not open
20997 return undef;
20998 }
20999 }
21000  
21001 # Shortcuts to GA::Obj::TextView for the task's default tab
21002  
21003 sub clearBuffer {
21004  
21005 my ($self, @args) = @_;
21006  
21007 if ($self->defaultTabObj) {
21008 return $self->defaultTabObj->textViewObj->clearBuffer(@args);
21009 } else {
21010 return undef;
21011 }
21012 }
21013  
21014 sub insertText {
21015  
21016 my ($self, @args) = @_;
21017  
21018 if ($self->defaultTabObj) {
21019 return $self->defaultTabObj->textViewObj->insertText(@args);
21020 } else {
21021 return undef;
21022 }
21023 }
21024  
21025 sub insertMultipleText {
21026  
21027 my ($self, @args) = @_;
21028  
21029 if ($self->defaultTabObj) {
21030 return $self->defaultTabObj->textViewObj->insertMultipleText(@args);
21031 } else {
21032 return undef;
21033 }
21034 }
21035  
21036 sub insertWithLinks {
21037  
21038 my ($self, @args) = @_;
21039  
21040 if ($self->defaultTabObj) {
21041 return $self->defaultTabObj->textViewObj->insertWithLinks(@args);
21042 } else {
21043 return undef;
21044 }
21045 }
21046  
21047 sub insertQuick {
21048  
21049 my ($self, @args) = @_;
21050  
21051 if ($self->defaultTabObj) {
21052 return $self->defaultTabObj->textViewObj->insertQuick(@args);
21053 } else {
21054 return undef;
21055 }
21056 }
21057  
21058 sub insertTextThenClear {
21059  
21060 my ($self, @args) = @_;
21061  
21062 if (
21063 ! $self->defaultTabObj
21064 || ! $self->defaultTabObj->textViewObj->insertText(@args)
21065 ) {
21066 return undef;
21067  
21068 } else {
21069  
21070 # The next time text is inserted into the textview's buffer, the buffer is first cleared
21071 # (which removes the '<task reset>' message, if this function was called by
21072 # $slf->transferWin)
21073 $self->defaultTabObj->textViewObj->set_clearAfterInsert();
21074  
21075 return 1;
21076 }
21077 }
21078  
21079 sub showImage {
21080  
21081 my ($self, @args) = @_;
21082  
21083 if ($self->defaultTabObj) {
21084 return $self->defaultTabObj->textViewObj->showImage(@args);
21085 } else {
21086 return undef;
21087 }
21088 }
21089  
21090 # Callbacks
21091  
21092 sub entryCallback {
21093  
21094 # Usually called by a ->signal_connect in GA::Strip::Entry->setEntrySignals or in
21095 # GA::Table::Entry->setActivateEvent, when the user types something in the strip/table
21096 # object's Gtk3::Entry and presses RETURN
21097 # This generic function just displays the typed text in the task window's default tab;
21098 # other tasks can write their own ->entryCallback as required
21099 #
21100 # Expected arguments
21101 # $obj - The strip or table object whose Gtk3::Entry was used
21102 # $entry - The Gtk3::Entry itself
21103 #
21104 # Optional arguments
21105 # $id - A value passed to the table object that identifies the particular
21106 # Gtk3::Entry used (in case the table object uses multiple entries). By
21107 # default, $self->openWin sets $id to the same as $self->uniqueName;
21108 # could be an 'undef' value otherwise
21109 # $text - The text typed in the entry by the user (should not be 'undef')
21110 #
21111 # Return values
21112 # 'undef' on improper arguments
21113 # 1 otherwise
21114  
21115 my ($self, $obj, $entry, $id, $text, $check) = @_;
21116  
21117 # Check for improper arguments
21118 if (! defined $obj || ! defined $entry || defined $check) {
21119  
21120 return $axmud::CLIENT->writeImproper($self->_objClass . '->entryCallback', @_);
21121 }
21122  
21123 if ($self->taskWinFlag && $self->defaultTabObj && $self->defaultTabObj->textViewObj) {
21124  
21125 $self->defaultTabObj->textViewObj->insertText($text, 'after');
21126 }
21127  
21128 return 1;
21129 }
21130  
21131 sub switchTabCallback {
21132  
21133 # Usually called GA::Table::Pane->respondVisibleTab whenever the visible tab in the task
21134 # window changes
21135 # This generic function does nothing; other tasks can write their own ->switchTabCallback
21136 # as required
21137 #
21138 # Expected arguments
21139 # $paneObj - The GA::Table::Pane object for the task window
21140 # $tabObj - The GA::Obj::Tab for the newly-visible tab
21141 #
21142 # Optional arguments
21143 # $id - A value passed by the pane object; for tasks, set to this task's ->name
21144 # (in general, might be 'undef')
21145 #
21146 # Return values
21147 # 'undef' on improper arguments
21148 # 1 otherwise
21149  
21150 my ($self, $paneObj, $tabObj, $id, $check) = @_;
21151  
21152 # Check for improper arguments
21153 if (! defined $paneObj || ! defined $tabObj || defined $check) {
21154  
21155 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchTabCallback', @_);
21156 }
21157  
21158 # (This generic function does nothing)
21159  
21160 return 1;
21161 }
21162  
21163 sub closeTabCallback {
21164  
21165 # Usually called GA::Table::Pane->removeTab whenever a tab in the task window is manually
21166 # closed by the user
21167 # This generic function simpy checks that the closed tab isn't the same one stored in
21168 # $self->defaultTabObj, and resets that IV, if so
21169 #
21170 # Expected arguments
21171 # $paneObj - The GA::Table::Pane object for the task window
21172 # $tabObj - The GA::Obj::Tab for the closed tab
21173 #
21174 # Optional arguments
21175 # $id - A value passed by the pane object; for tasks, set to this task's ->name
21176 # (in general, might be 'undef')
21177 #
21178 # Return values
21179 # 'undef' on improper arguments
21180 # 1 otherwise
21181  
21182 my ($self, $paneObj, $tabObj, $id, $check) = @_;
21183  
21184 # Check for improper arguments
21185 if (! defined $paneObj || ! defined $tabObj || defined $check) {
21186  
21187 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeTabCallback', @_);
21188 }
21189  
21190 if ($self->defaultTabObj && $self->defaultTabObj eq $tabObj) {
21191  
21192 $self->ivUndef('defaultTabObj');
21193 }
21194  
21195 return 1;
21196 }
21197  
21198 # Text-to-speech functions
21199  
21200 sub ttsReadAttrib {
21201  
21202 # Called by GA::Cmd::Read->do and PermRead->do
21203 # Users can use the client command ';read' to interact with individual tasks, typically
21204 # getting them to read out information (e.g. the Status task can read out current health
21205 # points)
21206 # The ';read' command is in the form ';read <attribute>' or ';read <attribute> <value>'.
21207 # The ';read' command looks up the <attribute> in GA::Client->ttsAttribHash, which tells
21208 # it which task to call
21209 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
21210 # do use TTS should include a modified form of this function that decides what to do
21211 # with each <attribute>. If a <value> was also specified, the task can decide whether to
21212 # use it, store it or ignore it
21213 #
21214 # Expected arguments
21215 # $attrib - The TTS attribute specified by the calling function. Must be one of the
21216 # keys in $self->ttsAttribHash
21217 #
21218 # Optional arguments
21219 # $value - The value specified by the calling function (or 'undef' if none was
21220 # specified)
21221 # $noSpecialFlag
21222 # - Set to TRUE when called by GA::Cmd::PermRead->do, in which case only
21223 # this task's hash of attributes is updated. If set to FALSE (or 'undef'),
21224 # something is usually read aloud, too
21225 #
21226 # Return values
21227 # 'undef' on improper arguments or if the $attrib doesn't exist in this task's
21228 # ->ttsAttribHash
21229 # 1 otherwise
21230  
21231 my ($self, $attrib, $value, $noSpecialFlag, $check) = @_;
21232  
21233 # Check for improper arguments
21234 if (! defined $attrib || defined $check) {
21235  
21236 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsReadAttrib', @_);
21237 }
21238  
21239 # TTS attributes are case-insensitive
21240 $attrib = lc($attrib);
21241  
21242 # Check that the specified attribute is actually used by this task (';read' or ';permread'
21243 # should carry out this check, but better safe than sorry)
21244 if (! $self->ivExists('ttsAttribHash', $attrib)) {
21245  
21246 return undef;
21247  
21248 } elsif ($noSpecialFlag) {
21249  
21250 # When called by GA::Cmd::PermRead->do, don't read out anything, just update the hash
21251 # of attributes (when appropriate)
21252 # This generic function doesn't update $self->ttsAttribHash, but other tasks'
21253 # ->ttsReadAttrib should decide which attributes (if any) to update)
21254  
21255 # (no attributes require an update)
21256  
21257 return 1;
21258  
21259 } else {
21260  
21261 # The generic function doesn't have any TTS attributes, but other tasks' ->ttsReadAttrib
21262 # functions should decide what to do here, and return 1
21263  
21264 # (no attributes require a response)
21265  
21266 return 1;
21267 }
21268 }
21269  
21270 sub ttsSwitchFlagAttrib {
21271  
21272 # Called by GA::Cmd::Switch->do and PermSwitch->do
21273 # Users can use the client command ';switch' to interact with individual tasks, typically
21274 # telling them to turn on/off the automatic reading out of information (e.g. the Locator
21275 # task can be told to start or stop reading out room titles as they are received from
21276 # the world)
21277 # The ';switch' command is in the form ';switch <flag_attribute>'. The ';switch' command
21278 # looks up the <flag_attribute> (which is a string, not a TRUE/FALSE value) in
21279 # GA::Session->ttsFlagAttribHash, which tells it which task to call
21280 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
21281 # do use TTS can either inherit this generic function (if all they want to do is toggle
21282 # the TRUE/FALSE values stored in a key-value pair in $self->ttsFlagAttribHash), or else
21283 # they must include a modified form of this function that does something different
21284 #
21285 # Expected arguments
21286 # $flagAttrib - The TTS flag attribute specified by the calling function. Must be one of
21287 # the keys in $self->ttsFlagAttribHash
21288 #
21289 # Optional arguments
21290 # $noSpecialFlag
21291 # - Set to TRUE when called by GA::Cmd::PermSwitch->do, in which case only
21292 # this task's hash of flag attributes is updated. Otherwise set to FALSE
21293 # (or 'undef'), in which case other things can happen when a flag
21294 # attribute is switched. For all built-in tasks, there is no difference
21295 # in behaviour
21296 #
21297 # Return values
21298 # 'undef' on improper arguments or if the $flagAttrib doesn't exist in this task's
21299 # ->ttsFlagAttribHash
21300 # Otherwise returns a confirmation message for the calling function to display
21301  
21302 my ($self, $flagAttrib, $noSpecialFlag, $check) = @_;
21303  
21304 # Local variables
21305 my $msg;
21306  
21307 # Check for improper arguments
21308 if (! defined $flagAttrib || defined $check) {
21309  
21310 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSwitchFlagAttrib', @_);
21311 }
21312  
21313 # TTS flag attributes are case-insensitive
21314 $flagAttrib = lc($flagAttrib);
21315  
21316 # Check that the specified flag attribute is actually used by this task (';switch' or
21317 # ';permswitch' should carry out this check, but better safe than sorry)
21318 if (! $self->ivExists('ttsFlagAttribHash', $flagAttrib)) {
21319  
21320 return undef;
21321  
21322 } else {
21323  
21324 # If a current task performs some kind of action, when a flag attribute is switched,
21325 # the code for the action should be placed here. (Tasks in the global initial
21326 # tasklist can't perform an action, of course.)
21327 if (! $noSpecialFlag) {
21328  
21329 # (no actions to perform)
21330 }
21331  
21332 # The generic task doesn't have any TTS flag attributes, but other tasks'
21333 # ->ttsSwitchFlagAttrib functions should decide what to do here, and return a
21334 # confirmation message
21335 # Usually, that means toggling the TRUE/FALSE values stored in $self->ttsFlagAttribHash
21336 $msg = '\'' . $self->prettyName . '\' flag attribute \'' . $flagAttrib
21337 . '\' switched to ';
21338  
21339 if ($self->ivShow('ttsFlagAttribHash', $flagAttrib)) {
21340  
21341 $self->ivAdd('ttsFlagAttribHash', $flagAttrib, FALSE);
21342 $msg .= 'OFF';
21343  
21344 } else {
21345  
21346 $self->ivAdd('ttsFlagAttribHash', $flagAttrib, TRUE);
21347 $msg .= 'ON';
21348 }
21349  
21350 return $msg;
21351 }
21352 }
21353  
21354 sub ttsSetAlertAttrib {
21355  
21356 # Called by GA::Cmd::Alert->do and PermAlert->do
21357 # Users can use the client command ';alert' to interact with individual tasks, typically
21358 # instructing them to read out information some time later (e.g. the Status task can read
21359 # out an alert when health points drop below a certain level or recover to a certain
21360 # level)
21361 # The ';alert' command is in the form ';alert <alert_attribute>' or
21362 # ';alert <alert_attribute> <value>'. The ';alert' command looks up the <alert_attribute>
21363 # in GA::Session->ttsAlertAttribHash, which tells it which task to call
21364 # Tasks that don't use text-to-speech (TTS) will inherit this generic function. Tasks that
21365 # do use TTS should include a modified form of this function that decides what to do
21366 # with each <alert_attribute>. If a <value> was also specified, the task can decide
21367 # whether to use it, store it or ignore it
21368 #
21369 # Expected arguments
21370 # $alertAttrib - The TTS attribute specified by the calling function. Must be one of
21371 # the keys in $self->ttsAttribHash
21372 #
21373 # Optional arguments
21374 # $value - The value specified by the calling function (or 'undef' if none was
21375 # specified)
21376 # $noSpecialFlag - Set to TRUE when called by GA::Cmd::PermAlert->do, in which case only
21377 # this task's hash of alert attributes is updated. Otherwise set to
21378 # FALSE (or 'undef'), in which case other things can happen when an
21379 # alert is set. For all built-in tasks, there is no difference in
21380 # behaviour
21381 #
21382 # Return values
21383 # 'undef' on improper arguments or if the $attrib doesn't exist in this task's
21384 # ->ttsAlertAttribHash
21385 # Otherwise returns a confirmation message for the calling function to display
21386  
21387 my ($self, $alertAttrib, $value, $noSpecialFlag, $check) = @_;
21388  
21389 # Local variables
21390 my $msg;
21391  
21392 # Check for improper arguments
21393 if (! defined $alertAttrib || defined $check) {
21394  
21395 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSetAlertAttrib', @_);
21396 }
21397  
21398 # TTS attributes are case-insensitive
21399 $alertAttrib = lc($alertAttrib);
21400  
21401 # Check that the specified attribute is actually used by this task (';alert' or ';permalert'
21402 # should carry out this check, but better safe than sorry)
21403 if (! $self->ivExists('ttsAlertAttribHash', $alertAttrib)) {
21404  
21405 return undef;
21406  
21407 } else {
21408  
21409 # If a current task performs some kind of action, when an alert attribute is set, the
21410 # code for the action should be placed here. (Tasks in the global initial tasklist
21411 # can't perform an action, of course.)
21412 if (! $noSpecialFlag) {
21413  
21414 # (no actions to perform)
21415 }
21416  
21417 # The generic task doesn't have any TTS alert attributes, but other tasks'
21418 # ->ttsSetAlertAttrib functions should decide what to do here, and return a
21419 # confirmation message
21420 $msg = 'The generic task can\'t process alert attributes';
21421  
21422 return $msg;
21423 }
21424 }
21425  
21426 sub ttsQuick {
21427  
21428 # Perform a quick call to GA::Client->tts, using this task's TTS settings
21429 # By using this function, rather than calling GA::Client->tts directly, we can use one
21430 # line of code, rather than several
21431 #
21432 # Expected arguments
21433 # $text - The text to read out
21434 #
21435 # Return values
21436 # 'undef' on improper arguments
21437 # 1 otherwise
21438  
21439 my ($self, $text, $check) = @_;
21440  
21441 # Check for improper arguments
21442 if (! defined $text || defined $check) {
21443  
21444 return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsQuick', @_);
21445 }
21446  
21447 $axmud::CLIENT->tts(
21448 $text, # This varies...
21449 'task', # ...but these are always the same
21450 $self->ttsConfig,
21451 $self->session,
21452 );
21453  
21454 return 1;
21455 }
21456  
21457 # Misc functions
21458  
21459 sub getColourScheme {
21460  
21461 # Called by $self->openPaneWin and ->configureWin
21462 # Returns the name of the colour scheme that should be used in a tab in the task window
21463 #
21464 # Expected arguments
21465 # (none besides $self)
21466 #
21467 # Return values
21468 # 'undef' on improper arguments or if the default colour scheme for task windows
21469 # ('custom') should be used
21470 # Otherwise, returns the name of the colour scheme to use
21471  
21472 my ($self, $check) = @_;
21473  
21474 # Local variables
21475 my ($colourScheme, $name);
21476  
21477 # Check for improper arguments
21478 if (defined $check) {
21479  
21480 return $axmud::CLIENT->writeImproper($self->_objClass . '->getColourScheme', @_);
21481 }
21482  
21483 if (
21484 $self->colourScheme
21485 && $axmud::CLIENT->ivExists('colourSchemeHash', $self->colourScheme)
21486 ) {
21487 return $self->colourScheme;
21488  
21489 } else {
21490  
21491 # If a colour scheme exists with the same name as this task, use it; otherwise use the
21492 # default colour scheme for 'custom' windows (by leaving $colourScheme as 'undef')
21493 # For the convenience of the user, check for both 'locator_task' and 'locator'
21494 $name = $self->name;
21495 if ($axmud::CLIENT->ivExists('colourSchemeHash', $name)) {
21496  
21497 return $name;
21498  
21499 } else {
21500  
21501 $name =~ s/_task//;
21502 if ($axmud::CLIENT->ivExists('colourSchemeHash', $name)) {
21503  
21504 return $name;
21505 }
21506 }
21507 }
21508  
21509 # Use the default colour scheme
21510 return undef;
21511 }
21512  
21513 sub returnParameterHash {
21514  
21515 # Can be called by anything
21516 # Returns all of the task's parameters and their values as a hash - thereby stripping all
21517 # task settings and the IVs ->_objName, ->_objClass, ->_parentFile, ->_parentWorld and
21518 # ->_privFlag - for any code that needs it
21519 #
21520 # Expected arguments
21521 # (none besides $self)
21522 #
21523 # Return values
21524 # An empty hash on improper arguments
21525 # Otherwise the hash of task parameters (might be empty if the task has no parameters)
21526  
21527 my ($self, $check) = @_;
21528  
21529 # Local variables
21530 my (
21531 @ivList,
21532 %taskHash, %emptyHash,
21533 );
21534  
21535 # Check for improper arguments
21536 if (defined $check) {
21537  
21538 $axmud::CLIENT->writeImproper($self->_objClass . '->returnParameterHash', @_);
21539 return %emptyHash;
21540 }
21541  
21542 # Compile a list of parameters to show. First import the list of IVs
21543 @ivList = $self->ivList();
21544  
21545 # Convert that list into a hash, preserving both the IV and its value
21546 foreach my $iv (@ivList) {
21547  
21548 $taskHash{$iv} = $self->{$iv};
21549 }
21550  
21551 # Remove all the task settings from %taskHash
21552 foreach my $iv ($axmud::CLIENT->ivKeys('constTaskSettingsHash')) {
21553  
21554 delete $taskHash{$iv};
21555 }
21556  
21557 # Remove the special IVs present in all Axmud Perl objects, leaving only IVs that are
21558 # task parameters
21559 foreach my $iv ($axmud::CLIENT->ivKeys('constIVHash')) {
21560  
21561 delete $taskHash{$iv};
21562 }
21563  
21564 return %taskHash;
21565 }
21566  
21567 ##################
21568 # Accessors - set
21569  
21570 sub set_colourScheme {
21571  
21572 my ($self, $colourScheme, $check) = @_;
21573  
21574 # Local variables
21575 my $paneObj;
21576  
21577 # Check for improper arguments
21578 if (defined $check) {
21579  
21580 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_colourScheme', @_);
21581 }
21582  
21583 $self->ivPoke('colourScheme', $colourScheme); # Can be 'undef'
21584  
21585 if ($self->defaultTabObj && $self->defaultTabObj->paneObj) {
21586  
21587 $self->defaultTabObj->paneObj->applyColourScheme(undef, $self->colourScheme);
21588 }
21589  
21590 return 1;
21591 }
21592  
21593 sub set_defaultTabObj {
21594  
21595 my ($self, $obj, $check) = @_;
21596  
21597 # Check for improper arguments
21598 if (! defined $obj || defined $check) {
21599  
21600 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_defaultTabObj', @_);
21601 }
21602  
21603 $self->ivPoke('defaultTabObj', $obj);
21604  
21605 return 1;
21606 }
21607  
21608 sub set_endStatus {
21609  
21610 my ($self, $endStatus, $check) = @_;
21611  
21612 # Check for improper arguments
21613 if (! defined $endStatus || defined $check) {
21614  
21615 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_endStatus', @_);
21616 }
21617  
21618 $self->ivPoke('endStatus', $endStatus);
21619  
21620 return 1;
21621 }
21622  
21623 sub set_endTime {
21624  
21625 my ($self, $endTime, $check) = @_;
21626  
21627 # Check for improper arguments
21628 if (! defined $endTime || defined $check) {
21629  
21630 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_endTime', @_);
21631 }
21632  
21633 $self->ivPoke('endTime', $endTime);
21634  
21635 return 1;
21636 }
21637  
21638 sub set_hasResetFlag {
21639  
21640 my ($self, $flag, $check) = @_;
21641  
21642 # Check for improper arguments
21643 if (! defined $flag || defined $check) {
21644  
21645 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_hasResetFlag', @_);
21646 }
21647  
21648 if ($flag) {
21649 $self->ivPoke('hasResetFlag', TRUE);
21650 } else {
21651 $self->ivPoke('hasResetFlag', FALSE);
21652 }
21653  
21654 return 1;
21655 }
21656  
21657 sub set_resumeStatus {
21658  
21659 my ($self, $status, $check) = @_;
21660  
21661 # Check for improper arguments
21662 if (defined $check) {
21663  
21664 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_resumeStatus', @_);
21665 }
21666  
21667 if (defined $status) {
21668  
21669 if ($axmud::CLIENT->ivExists('constTaskStatusHash', $status)) {
21670  
21671 $self->ivPoke('resumeStatus', $status);
21672  
21673 } else {
21674  
21675 # Invalid status
21676 return undef;
21677 }
21678  
21679 } else {
21680  
21681 $self->ivUndef('resumeStatus');
21682 }
21683  
21684 return 1;
21685 }
21686  
21687 sub set_requireWinFlag {
21688  
21689 my ($self, $flag, $check) = @_;
21690  
21691 # Check for improper arguments
21692 if (! defined $flag || defined $check) {
21693  
21694 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_requireWinFlag', @_);
21695 }
21696  
21697 if ($flag) {
21698 $self->ivPoke('requireWinFlag', TRUE);
21699 } else {
21700 $self->ivPoke('requireWinFlag', FALSE);
21701 }
21702  
21703 return 1;
21704 }
21705  
21706 sub set_shutdownFlag {
21707  
21708 my ($self, $flag, $check) = @_;
21709  
21710 # Check for improper arguments
21711 if (! defined $flag || defined $check) {
21712  
21713 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_status', @_);
21714 }
21715  
21716 if ($flag) {
21717 $self->ivPoke('shutdownFlag', TRUE);
21718 } else {
21719 $self->ivPoke('shutdownFlag', FALSE);
21720 }
21721  
21722 return 1;
21723 }
21724  
21725 sub set_stage {
21726  
21727 my ($self, $stage, $check) = @_;
21728  
21729 # Check for improper arguments
21730 if (! defined $stage || defined $check) {
21731  
21732 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_stage', @_);
21733 }
21734  
21735 $self->ivPoke('stage', $stage);
21736  
21737 return 1;
21738 }
21739  
21740 sub set_startTime {
21741  
21742 my ($self, $startTime, $check) = @_;
21743  
21744 # Check for improper arguments
21745 if (! defined $startTime || defined $check) {
21746  
21747 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_startTime', @_);
21748 }
21749  
21750 $self->ivPoke('startTime', $startTime);
21751  
21752 return 1;
21753 }
21754  
21755 sub set_startWithWinFlag {
21756  
21757 my ($self, $flag, $check) = @_;
21758  
21759 # Check for improper arguments
21760 if (! defined $flag || defined $check) {
21761  
21762 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_startWithWinFlag', @_);
21763 }
21764  
21765 if ($flag) {
21766 $self->ivPoke('startWithWinFlag', TRUE);
21767 } else {
21768 $self->ivPoke('startWithWinFlag', FALSE);
21769 }
21770  
21771 return 1;
21772 }
21773  
21774 sub set_status {
21775  
21776 my ($self, $status, $check) = @_;
21777  
21778 # Check for improper arguments
21779 if (! defined $status || defined $check) {
21780  
21781 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_status', @_);
21782 }
21783  
21784 if ($axmud::CLIENT->ivExists('constTaskStatusHash', $status)) {
21785  
21786 $self->ivPoke('status', $status);
21787 }
21788  
21789  
21790 return 1;
21791 }
21792  
21793 sub set_tableObj {
21794  
21795 my ($self, $tableObj, $check) = @_;
21796  
21797 # Check for improper arguments
21798 if (defined $check) {
21799  
21800 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tableObj', @_);
21801 }
21802  
21803 $self->ivPoke('tableObj', $tableObj);
21804  
21805 return 1;
21806 }
21807  
21808 sub set_taskWinEntryFlag {
21809  
21810 my ($self, $flag, $check) = @_;
21811  
21812 # Check for improper arguments
21813 if (! defined $flag || defined $check) {
21814  
21815 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_taskWinEntryFlag', @_);
21816 }
21817  
21818 if ($flag) {
21819 $self->ivPoke('taskWinEntryFlag', TRUE);
21820 } else {
21821 $self->ivPoke('taskWinEntryFlag', FALSE);
21822 }
21823  
21824 return 1;
21825 }
21826  
21827 sub set_taskWinFlag {
21828  
21829 my ($self, $flag, $check) = @_;
21830  
21831 # Check for improper arguments
21832 if (! defined $flag || defined $check) {
21833  
21834 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_taskWinFlag', @_);
21835 }
21836  
21837 if ($flag) {
21838 $self->ivPoke('taskWinFlag', TRUE);
21839 } else {
21840 $self->ivPoke('taskWinFlag', FALSE);
21841 }
21842  
21843 return 1;
21844 }
21845  
21846 sub set_ttsConfig {
21847  
21848 my ($self, $configuration, $check) = @_;
21849  
21850 # Check for improper arguments
21851 if (defined $check) {
21852  
21853 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_ttsConfig', @_);
21854 }
21855  
21856 $self->ivPoke('ttsConfig', $configuration);
21857  
21858 return 1;
21859 }
21860  
21861 sub set_ttsHash {
21862  
21863 my ($self, $taskObj, $check) = @_;
21864  
21865 # Check for improper arguments
21866 if (! defined $taskObj || defined $check) {
21867  
21868 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_ttsHash', @_);
21869 }
21870  
21871 $self->ivPoke('ttsAttribHash', $taskObj->ttsAttribHash);
21872 $self->ivPoke('ttsFlagAttribHash', $taskObj->ttsFlagAttribHash);
21873 $self->ivPoke('ttsAlertAttribHash', $taskObj->ttsAlertAttribHash);
21874  
21875 return 1;
21876 }
21877  
21878 sub set_waitForTask {
21879  
21880 my ($self, $waitForTask, $check) = @_;
21881  
21882 # Check for improper arguments
21883 if (! defined $waitForTask || defined $check) {
21884  
21885 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_waitForTask', @_);
21886 }
21887  
21888 $self->ivPoke('waitForTask', $waitForTask);
21889  
21890 return 1;
21891 }
21892  
21893 sub set_winObj {
21894  
21895 my ($self, $winObj, $check) = @_;
21896  
21897 # Check for improper arguments
21898 if (! defined $winObj || defined $check) {
21899  
21900 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winObj', @_);
21901 }
21902  
21903 $self->ivPoke('winObj', $winObj);
21904  
21905 return 1;
21906 }
21907  
21908 sub del_winObj {
21909  
21910 # Called by GA::Win::Generic->winDestroy
21911  
21912 my ($self, $winObj, $check) = @_;
21913  
21914 # Local variables
21915 my $stripObj;
21916  
21917 # Check for improper arguments
21918 if (! defined $winObj || defined $check) {
21919  
21920 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_winObj', @_);
21921 }
21922  
21923 # Do nothing if the task already knows the window is closed, or if the task is shutting down
21924 # anyway
21925 if ($self->winObj && $self->winObj eq $winObj && ! $self->shutdownFlag) {
21926  
21927 # Mark the window as closed
21928 $self->ivUndef('winObj');
21929 $self->ivPoke('taskWinFlag', FALSE);
21930 $self->ivPoke('taskWinEntryFlag', FALSE);
21931 $self->ivUndef('defaultTabObj');
21932  
21933 # For pseudo-windows, this function should probably not be called; nevertheless, if the
21934 # parent table object is still open, close it
21935 if ($winObj->pseudoWinTableObj) {
21936  
21937 $stripObj = $winObj->pseudoWinTableObj->stripObj;
21938 if ($stripObj->ivExists('tableObjHash', $winObj->pseudoWinTableObj->number)) {
21939  
21940 $stripObj->removeTableObj($winObj->pseudoWinTableObj);
21941 }
21942 }
21943  
21944 if ($self->requireWinFlag) {
21945  
21946 # The task should shut down when its window is closed
21947 $self->ivPoke('shutdownFlag', TRUE);
21948 $self->writeText(
21949 'Window for \'' . $self->prettyName . '\' task closed (task will also halt)',
21950 );
21951  
21952 } else {
21953  
21954 # The task can continue without a window
21955 $self->writeText(
21956 'Window for \'' . $self->prettyName . '\' task closed (task will continue)',
21957 );
21958 }
21959 }
21960  
21961 return 1;
21962 }
21963  
21964 ##################
21965 # Accessors - get
21966  
21967 sub session
21968 { $_[0]->{session} }
21969  
21970 sub name
21971 { $_[0]->{name} }
21972  
21973 sub prettyName
21974 { $_[0]->{prettyName} }
21975 sub uniqueName
21976 { $_[0]->{uniqueName} }
21977 sub shortName
21978 { $_[0]->{shortName} }
21979 sub customName
21980 { $_[0]->{customName} }
21981  
21982 sub category
21983 { $_[0]->{category} }
21984 sub descrip
21985 { $_[0]->{descrip} }
21986 sub taskType
21987 { $_[0]->{taskType} }
21988 sub profName
21989 { $_[0]->{profName} }
21990 sub profCategory
21991 { $_[0]->{profCategory} }
21992 sub shortCutIV
21993 { $_[0]->{shortCutIV} }
21994  
21995 sub jealousyFlag
21996 { $_[0]->{jealousyFlag} }
21997 sub requireLocatorFlag
21998 { $_[0]->{requireLocatorFlag} }
21999 sub profSensitivityFlag
22000 { $_[0]->{profSensitivityFlag} }
22001 sub storableFlag
22002 { $_[0]->{storableFlag} }
22003  
22004 sub startTime
22005 { $_[0]->{startTime} }
22006 sub checkTime
22007 { $_[0]->{checkTime} }
22008 sub endStatus
22009 { $_[0]->{endStatus} }
22010 sub endTime
22011 { $_[0]->{endTime} }
22012 sub waitForTask
22013 { $_[0]->{waitForTask} }
22014 sub delayTime
22015 { $_[0]->{delayTime} }
22016  
22017 sub shutdownFlag
22018 { $_[0]->{shutdownFlag} }
22019 sub hasResetFlag
22020 { $_[0]->{hasResetFlag} }
22021 sub status
22022 { $_[0]->{status} }
22023 sub resumeStatus
22024 { $_[0]->{resumeStatus} }
22025 sub activeFlag
22026 { $_[0]->{activeFlag} }
22027 sub stage
22028 { $_[0]->{stage} }
22029  
22030 sub allowWinFlag
22031 { $_[0]->{allowWinFlag} }
22032 sub requireWinFlag
22033 { $_[0]->{requireWinFlag} }
22034 sub startWithWinFlag
22035 { $_[0]->{startWithWinFlag} }
22036 sub winPreferList
22037 { my $self = shift; return @{$self->{winPreferList}}; }
22038 sub winObj
22039 { $_[0]->{winObj} }
22040 sub tableObj
22041 { $_[0]->{tableObj} }
22042 sub taskWinFlag
22043 { $_[0]->{taskWinFlag} }
22044 sub taskWinEntryFlag
22045 { $_[0]->{taskWinEntryFlag} }
22046 sub winmap
22047 { $_[0]->{winmap} }
22048 sub winUpdateFunc
22049 { $_[0]->{winUpdateFunc} }
22050 sub defaultTabObj
22051 { $_[0]->{defaultTabObj} }
22052 sub tabMode
22053 { $_[0]->{tabMode} }
22054 sub monochromeFlag
22055 { $_[0]->{monochromeFlag} }
22056 sub colourScheme
22057 { $_[0]->{colourScheme} }
22058 sub noScrollFlag
22059 { $_[0]->{noScrollFlag} }
22060  
22061 sub ttsFlag
22062 { $_[0]->{ttsFlag} }
22063 sub ttsConfig
22064 { $_[0]->{ttsConfig} }
22065 sub ttsAttribHash
22066 { my $self = shift; return %{$self->{ttsAttribHash}}; }
22067 sub ttsFlagAttribHash
22068 { my $self = shift; return %{$self->{ttsFlagAttribHash}}; }
22069 sub ttsAlertAttribHash
22070 { my $self = shift; return %{$self->{ttsAlertAttribHash}}; }
22071 }
22072  
22073 { package Games::Axmud::Generic::Win;
22074  
22075 use strict;
22076 use warnings;
22077 use diagnostics;
22078  
22079 use Glib qw(TRUE FALSE);
22080  
22081 our @ISA = qw(Games::Axmud);
22082  
22083 ##################
22084 # Constructors
22085  
22086 # sub new {} # Defined in window objects which inherit this one
22087  
22088 ##################
22089 # Methods
22090  
22091 # Standard window object functions
22092  
22093 # sub winSetup {} # Defined in window objects which inherit this one
22094  
22095 # sub winEnable {} # Defined in window objects which inherit this one
22096  
22097 # sub winDisengage {} # Defined in window objects which inherit this one
22098  
22099 # sub winDestroy {} # Defined in window objects which inherit this one
22100  
22101 sub winShowAll {
22102  
22103 # Generic function to update the window itself to make any changes visible
22104 # If some code has called $self->setInvisible, then nothing happens (and the window
22105 # remains invisible)
22106 #
22107 # Expected arguments
22108 # (none besides $self)
22109 #
22110 # Optional arguments
22111 # $string - For debugging purposes. Describes the calling function, e.g.
22112 # ->winShowAll($self->_objClass . '->callingFunction');
22113 #
22114 # Return values
22115 # 'undef' on improper arguments
22116 # 1 otherwise
22117  
22118 my ($self, $string, $check) = @_;
22119  
22120 # Check for improper arguments
22121 if (defined $check) {
22122  
22123 return $axmud::CLIENT->writeImproper($self->_objClass . '->winShowAll', @_);
22124 }
22125  
22126 if ($self->winWidget && $self->visibleFlag) {
22127  
22128 $self->winWidget->show_all();
22129  
22130 # Any textview objects (GA::Obj::TextView) which are waiting to update their size IVs
22131 # can now do so
22132 foreach my $textViewObj ($axmud::CLIENT->desktopObj->ivValues('textViewHash')) {
22133  
22134 if ($textViewObj->sizeUpdateFlag && $textViewObj->winObj eq $self) {
22135  
22136 $textViewObj->updateVisibleSize();
22137 }
22138 }
22139  
22140 # Optionally, write information about the calling function to the terminal (for
22141 # debugging)
22142 # if ($string) {
22143 #
22144 # print "->winShowAll() call from " . $string . " at " . $axmud::CLIENT->getTime()
22145 # . "\n";
22146 #
22147 # } else {
22148 #
22149 # print "->winShowAll() call from unspecified function at "
22150 # . $axmud::CLIENT->getTime() . "\n";
22151 # }
22152 }
22153  
22154 return 1;
22155 }
22156  
22157 sub drawWidgets {
22158  
22159 # Generic function to draw widgets within the window, usually called by $self->winSetup or
22160 # $self->winEnable
22161 #
22162 # Expected arguments
22163 # (none besides $self)
22164 #
22165 # Return values
22166 # 'undef' on improper arguments
22167 # 1 on success
22168  
22169 my ($self, $check) = @_;
22170  
22171 # Check for improper arguments
22172 if (defined $check) {
22173  
22174 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
22175 }
22176  
22177 # (Do nothing)
22178  
22179 return 1;
22180 }
22181  
22182 sub redrawWidgets {
22183  
22184 # Generic function to redraw widgets within the window
22185 #
22186 # Expected arguments
22187 # (none besides $self)
22188 #
22189 # Return values
22190 # 'undef' on improper arguments
22191 # 1 on success
22192  
22193 my ($self, $check) = @_;
22194  
22195 # Check for improper arguments
22196 if (defined $check) {
22197  
22198 return $axmud::CLIENT->writeImproper($self->_objClass . '->redrawWidgets', @_);
22199 }
22200  
22201 # (Do nothing)
22202  
22203 return 1;
22204 }
22205  
22206 # ->signal_connects
22207  
22208 # Other functions
22209  
22210 sub setTitle {
22211  
22212 # Can be called by anything
22213 # Sets the text on this window's title bar
22214 #
22215 # Expected arguments
22216 # $title - The string to use as the window's title
22217 #
22218 # Return values
22219 # 'undef' on improper arguments
22220 # 1 otherwise
22221  
22222 my ($self, $title, $check) = @_;
22223  
22224 # Check for improper arguments
22225 if (! defined $title || defined $check) {
22226  
22227 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTitle', @_);
22228 }
22229  
22230 # (Don't use this function to set titles for pseudo-windows)
22231 if ($self->winWidget eq $self->winBox) {
22232  
22233 $self->winWidget->set_title($title);
22234 }
22235  
22236 return 1;
22237 }
22238  
22239 sub getTitle {
22240  
22241 # Can be called by anything
22242 # Gets the text on this window's title bar
22243 #
22244 # Expected arguments
22245 # (none besides $self)
22246 #
22247 # Return values
22248 # 'undef' on improper arguments
22249 # Otherwise returns the title bar text
22250  
22251 my ($self, $check) = @_;
22252  
22253 # Check for improper arguments
22254 if (defined $check) {
22255  
22256 return $axmud::CLIENT->writeImproper($self->_objClass . '->getTitle', @_);
22257 }
22258  
22259 return $self->winWidget->get_title();
22260  
22261 return 1;
22262 }
22263  
22264 sub setUrgent {
22265  
22266 # Sets this window's urgency hint
22267 #
22268 # Expected arguments
22269 # (none besides $self)
22270 #
22271 # Optional arguments
22272 # $flag - If set to TRUE, this window's urgency hint is only set, if Gtk3 reports that
22273 # it is not currently set. If set to FALSE (or 'undef'), this function sets
22274 # the window's urgency hint regardless
22275 #
22276 # Return values
22277 # 'undef' on improper arguments or if the window's urgency hint is not set
22278 # 1 if the window's urgency hint is set
22279  
22280 my ($self, $flag, $check) = @_;
22281  
22282 # Check for improper arguments
22283 if (defined $check) {
22284  
22285 return $axmud::CLIENT->writeImproper($self->_objClass . '->setUrgent', @_);
22286 }
22287  
22288 if (
22289 $self->winWidget eq $self->winBox
22290 && (! $flag || ! $self->winWidget->get_urgency_hint())
22291 ) {
22292 $self->winWidget->set_urgency_hint(TRUE);
22293  
22294 return 1;
22295  
22296 } else {
22297  
22298 # Hint not set
22299 return undef;
22300 }
22301 }
22302  
22303 sub resetUrgent {
22304  
22305 # Resets this window's urgency hint
22306 #
22307 # Expected arguments
22308 # (none besides $self)
22309 #
22310 # Optional arguments
22311 # $flag - If set to TRUE, this window's urgency hint is only reset, if Gtk3 reports that
22312 # it is currently set. If set to FALSE (or 'undef'), this function resets
22313 # the window's urgency hint regardless
22314 #
22315 # Return values
22316 # 'undef' on improper arguments or if the window's urgency hint is not reset
22317 # 1 if the window's urgency hint is reset
22318  
22319 my ($self, $flag, $check) = @_;
22320  
22321 # Check for improper arguments
22322 if (defined $check) {
22323  
22324 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetUrgent', @_);
22325 }
22326  
22327 if (
22328 $self->winWidget eq $self->winBox
22329 && (! $flag || $self->winWidget->get_urgency_hint())
22330 ) {
22331 $self->winWidget->set_urgency_hint(FALSE);
22332 # The line above doesn't work (in Linux Mint with Cinnamon), so we'll do it the brutal
22333 # way, too
22334 $self->restoreFocus();
22335 if ($self->session) {
22336  
22337 $self->session->mainWin->restoreFocus();
22338 }
22339  
22340 return 1;
22341  
22342 } else {
22343  
22344 # Hint not reset
22345 return undef;
22346 }
22347 }
22348  
22349 sub restoreFocus {
22350  
22351 # Can be called by any function (often after creating a 'dialogue' window or after
22352 # re-stacking 'grid' windows)
22353 # Activates this window object's Gtk3::Window, if it is known. For 'internal' windows,
22354 # returns the focus to the entry box in the 'Games::Axmud::Strip::Entry' strip object, if
22355 # there is one
22356 #
22357 # Expected arguments
22358 # (none besides $self)
22359 #
22360 # Return values
22361 # 'undef' on improper arguments or $self->winWidget is not set
22362 # 1 otherwise
22363  
22364 my ($self, $check) = @_;
22365  
22366 # Local variables
22367 my $stripObj;
22368  
22369 # Check for improper arguments
22370 if (defined $check) {
22371  
22372 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreFocus', @_);
22373 }
22374  
22375 # Activate the Gtk3::Window, if it is known (for pseudo-windows, activate the parent window)
22376 if ($self->winType eq 'external') {
22377  
22378 # Activate the window
22379 $axmud::CLIENT->desktopObj->wmCtrlObj->wmctrl(
22380 '-a',
22381 $self->internalID,
22382 '-i',
22383 );
22384  
22385 } else {
22386  
22387 if (! $self->winWidget) {
22388  
22389 return undef;
22390  
22391 } else {
22392  
22393 $self->winWidget->present();
22394 }
22395  
22396 # For 'internal' windows, returns the focus to the entry box in the
22397 # 'Games::Axmud::Strip::Entry' strip object, if there is one
22398 if (
22399 $self->winType eq 'main'
22400 || $self->winType eq 'protocol'
22401 || $self->winType eq 'custom'
22402 ) {
22403 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
22404 if ($stripObj) {
22405  
22406 $stripObj->entry->grab_focus();
22407 }
22408 }
22409 }
22410  
22411 return 1;
22412 }
22413  
22414 sub setVisible {
22415  
22416 # Can be called by any function
22417 # Makes the Gtk3::Window itself visible, and sets a flag so that calls to $self->winShowAll
22418 # are carried out
22419 #
22420 # Expected arguments
22421 # (none besides $self)
22422 #
22423 # Return values
22424 # 'undef' on improper arguments or $self->winWidget is not set
22425 # 1 otherwise
22426  
22427 my ($self, $check) = @_;
22428  
22429 # Check for improper arguments
22430 if (defined $check) {
22431  
22432 return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisible', @_);
22433 }
22434  
22435 if (! $self->winWidget) {
22436  
22437 return undef;
22438  
22439 } else {
22440  
22441 $self->winWidget->set_visible(TRUE);
22442 $self->ivPoke('visibleFlag', TRUE);
22443  
22444 return 1;
22445 }
22446 }
22447  
22448 sub setInvisible {
22449  
22450 # Can be called by any function
22451 # Makes the Gtk3::Window itself invisible, and sets a flag so that calls to
22452 # $self->winShowAll are ignored until the window is made visible again (via a call to
22453 # $self->setVisible)
22454 #
22455 # Expected arguments
22456 # (none besides $self)
22457 #
22458 # Return values
22459 # 'undef' on improper arguments or $self->winWidget is not set
22460 # 1 otherwise
22461  
22462 my ($self, $check) = @_;
22463  
22464 # Check for improper arguments
22465 if (defined $check) {
22466  
22467 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInvisible', @_);
22468 }
22469  
22470 if (! $self->winWidget) {
22471  
22472 return undef;
22473  
22474 } else {
22475  
22476 $self->winWidget->set_visible(FALSE);
22477 $self->ivPoke('visibleFlag', FALSE);
22478  
22479 return 1;
22480 }
22481 }
22482  
22483 sub minimise {
22484  
22485 # Can be called by anything
22486 # Minimises the window
22487 #
22488 # Expected arguments
22489 # (none besides $self)
22490 #
22491 # Return values
22492 # 'undef' on improper arguments or if the window can't be minimised
22493 # 1 otherwise
22494  
22495 my ($self, $check) = @_;
22496  
22497 # Check for improper arguments
22498 if (defined $check) {
22499  
22500 return $axmud::CLIENT->writeImproper($self->_objClass . '->minimise', @_);
22501 }
22502  
22503 if (! $self->winWidget) {
22504  
22505 return undef;
22506  
22507 } else {
22508  
22509 $self->winWidget->iconify();
22510 return 1
22511 }
22512 }
22513  
22514 sub unminimise {
22515  
22516 # Can be called by anything
22517 # Minimises the window
22518 #
22519 # Expected arguments
22520 # (none besides $self)
22521 #
22522 # Return values
22523 # 'undef' on improper arguments or if the window can't be unminimised
22524 # 1 otherwise
22525  
22526 my ($self, $check) = @_;
22527  
22528 # Check for improper arguments
22529 if (defined $check) {
22530  
22531 return $axmud::CLIENT->writeImproper($self->_objClass . '->unminimise', @_);
22532 }
22533  
22534 if (! $self->winWidget) {
22535  
22536 return undef;
22537  
22538 } else {
22539  
22540 $self->winWidget->deiconify();
22541 # (On Linux, un-minimising the window doesn't work reliably without this line)
22542 $self->winWidget->present();
22543  
22544 return 1
22545 }
22546 }
22547  
22548 sub getBorder {
22549  
22550 # Can be called by anything except 'dialogue' window code, which accesses this function
22551 # throught its parent 'grid' or 'free' window
22552 # Gets the correct border size for this window type
22553 #
22554 # Expected arguments
22555 # (none besides $self)
22556 #
22557 # Return values
22558 # 'undef' on improper arguments
22559 # Otherwise returns the spacing size in pixels
22560  
22561 my ($self, $check) = @_;
22562  
22563 # Check for improper arguments
22564 if (defined $check) {
22565  
22566 return $axmud::CLIENT->writeImproper($self->_objClass . '->getBorder', @_);
22567 }
22568  
22569 if ($self->winCategory eq 'free') {
22570 return $axmud::CLIENT->constFreeBorderPixels;
22571 } elsif ($self->winType eq 'main') {
22572 return $axmud::CLIENT->constMainBorderPixels;
22573 } else {
22574 return $axmud::CLIENT->constGridBorderPixels;
22575 }
22576 }
22577  
22578 sub getSpacing {
22579  
22580 # Can be called by anything except 'dialogue' window code, which accesses this function
22581 # throught its parent 'grid' or 'free' window
22582 # Gets the correct spacing size for this window type
22583 #
22584 # Expected arguments
22585 # (none besides $self)
22586 #
22587 # Return values
22588 # 'undef' on improper arguments
22589 # Otherwise returns the spacing size in pixels
22590  
22591 my ($self, $check) = @_;
22592  
22593 # Check for improper arguments
22594 if (defined $check) {
22595  
22596 return $axmud::CLIENT->writeImproper($self->_objClass . '->getSpacing', @_);
22597 }
22598  
22599 if ($self->winCategory eq 'free') {
22600 return $axmud::CLIENT->constFreeSpacingPixels;
22601 } elsif ($self->winType eq 'main') {
22602 return $axmud::CLIENT->constMainSpacingPixels;
22603 } else {
22604 return $axmud::CLIENT->constGridSpacingPixels;
22605 }
22606 }
22607  
22608 # 'free' windows
22609  
22610 sub createFreeWin {
22611  
22612 # All 'free' windows must have an owner, and the owner must be another window object (which
22613 # can be a 'grid' or a 'free' window object)
22614 # 'dialogue' windows should be created via a call to one of the functions in this generic
22615 # window object (e.g. $self->showMsgDialogue, $self->showComboDialogue, etc)
22616 # All other types of 'free' window should be created via a call to $self->createFreeWin or
22617 # $self->quickFreeWin
22618 #
22619 # Expected arguments
22620 # $packageName - The Perl object for the child 'free' window
22621 #
22622 # Optional arguments
22623 # $owner - The owner. A 'grid' window object (but not an 'external' window) or a
22624 # 'free' window object (but not any other kind of object). If 'undef',
22625 # then this window object is the owner
22626 # $session - The GA::Session from which this function was called. If 'undef',
22627 # the new window's ->session is the same as $owner's session (which
22628 # might be 'undef', too)
22629 # $title - A string to use as the child window's title. If 'undef', a generic
22630 # title is used
22631 # $editObj - The object to be edited in the child window (for 'edit' windows only;
22632 # should be 'undef' for other types of 'free' window)
22633 # $tempFlag - Flag set to TRUE if $editObj is either temporary, or has not yet been
22634 # added to any registry (usually because the user needs to name it
22635 # first). Set to FALSE (or 'undef') otherwise. Ignored if $editObj is
22636 # not specified
22637 # %configHash - Hash containing any number of key-value pairs needed for this
22638 # particular 'free' window; for example, for example,
22639 # GA::PrefWin::TaskStart uses it to specify a task name and type.
22640 # Set to an empty hash if not required
22641 #
22642 # Return values
22643 # 'undef' on improper arguments or if the child 'free' window can't be created
22644 # Otherwise returns the blessed reference to the child window
22645  
22646 my ($self, $packageName, $owner, $session, $title, $editObj, $tempFlag, %configHash) = @_;
22647  
22648 # Local variables
22649 my ($pluginName, $pluginObj, $class, $winObj);
22650  
22651 # Check for improper arguments
22652 if (! defined $packageName) {
22653  
22654 return $axmud::CLIENT->writeImproper($self->_objClass . '->createFreeWin', @_);
22655 }
22656  
22657 # All windows except 'external' and 'dialogue' windows can have a child 'free' window
22658 if ($self->winType eq 'external' || $self->winType eq 'dialogue') {
22659  
22660 return undef;
22661 }
22662  
22663 # If the window package was added by a plugin and the plugin is disabled, don't create the
22664 # window
22665 $pluginName = $axmud::CLIENT->ivShow('pluginFreeWinHash', $packageName);
22666 if ($pluginName) {
22667  
22668 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $pluginName);
22669 if ($pluginObj && ! $pluginObj->enabledFlag) {
22670  
22671 return undef;
22672 }
22673 }
22674  
22675 # If no owner is specified, it's this window
22676 if (! $owner) {
22677  
22678 $owner = $self;
22679  
22680 # If an owner is specified, it must be a window object (inheriting from GA::Generic::Win)
22681 } elsif (! $owner->isa('Games::Axmud::Generic::Win')) {
22682  
22683 return undef;
22684 }
22685  
22686 # If no session is specified, it's the owner's session
22687 if (! $session) {
22688  
22689 $session = $owner->session;
22690 }
22691  
22692 # Create the 'free' window object
22693 $winObj = $packageName->new(
22694 $axmud::CLIENT->desktopObj->freeWinCount,
22695 $self->workspaceObj,
22696 $owner,
22697 $session,
22698 $title,
22699 $editObj,
22700 $tempFlag,
22701 %configHash,
22702 );
22703  
22704 # Check it's any 'free' window besides a 'dialogue' window
22705 if (! $winObj || $winObj->winCategory ne 'free' || $winObj->winType eq 'dialogue') {
22706  
22707 return undef;
22708 }
22709  
22710 # Make the window visible
22711 if (! $winObj->winSetup()) {
22712  
22713 return undef;
22714 }
22715  
22716 if (! $winObj->winEnable()) {
22717  
22718 return undef;
22719 }
22720  
22721 # Update IVs
22722 $axmud::CLIENT->desktopObj->add_freeWin($winObj);
22723 $self->add_childFreeWin($winObj);
22724  
22725 return $winObj;
22726 }
22727  
22728 sub quickFreeWin {
22729  
22730 # Shortcut to $self->createFreeWin, allowing the calling code to specify only the bare
22731 # minimum of arguments
22732 #
22733 # Expected arguments
22734 # $packageName - The Perl object for the child 'free' window
22735 #
22736 # Optional arguments
22737 # $session - The GA::Session from which this function was called. If 'undef',
22738 # the new window's ->session is the same as this window's session
22739 # (which might be 'undef', too)
22740 # %configHash - Hash containing any number of key-value pairs needed for this
22741 # particular 'free' window; for example, for example,
22742 # GA::PrefWin::TaskStart uses it to specify a task name and type.
22743 # Set to an empty hash if not required
22744 #
22745 # Return values
22746 # 'undef' on improper arguments or if the child 'free' window can't be created
22747 # Otherwise returns the blessed reference to the child window
22748  
22749 my ($self, $packageName, $session, %configHash) = @_;
22750  
22751 # Check for improper arguments
22752 if (! defined $packageName) {
22753  
22754 return $axmud::CLIENT->writeImproper($self->_objClass . '->quickFreeWin', @_);
22755 }
22756  
22757 return $self->createFreeWin(
22758 $packageName, # Compulsory
22759 undef,
22760 $session, # May be 'undef'
22761 undef,
22762 undef,
22763 undef,
22764 %configHash,
22765 );
22766 }
22767  
22768 # 'dialogue' windows
22769  
22770 sub closeDialogueWin {
22771  
22772 # Can be called by anything to close a 'dialogue' window early (especially one that won't
22773 # close itself)
22774 # For example, called by GA::Client->start and GA::Session->setupProfiles after an earlier
22775 # call to the 'dialogue' window created by $self->showBusyWin
22776 #
22777 # Expected arguments
22778 # $dialogueWin - The 'dialogue' window to close
22779 #
22780 # Return values
22781 # 'undef' on improper arguments
22782 # 1 otherwise
22783  
22784 my ($self, $dialogueWin, $check) = @_;
22785  
22786 # Check for improper arguments
22787 if (! defined $dialogueWin || defined $check) {
22788  
22789 return $axmud::CLIENT->writeImproper($self->_objClass . '->closeDialogueWin', @_);
22790 }
22791  
22792 # Close the window
22793 $dialogueWin->destroy();
22794  
22795 # For a 'dialogue' window created by $self->showBusyWin, we need to update a GA::Client IV
22796 if ($axmud::CLIENT->busyWin && $axmud::CLIENT->busyWin eq $dialogueWin) {
22797  
22798 $axmud::CLIENT->set_busyWin();
22799 }
22800  
22801 return 1;
22802 }
22803  
22804 sub addDialogueIcon {
22805  
22806 # Called by many of the following functions that open some kind of Gtk3::Dialogue
22807 # Takes the 'dialogue' window's main Gtk3::VBox, and splits it (using a Gtk3::HBox) into
22808 # two, with a standard icon on the left, and a new Gtk3::VBox on the right
22809 # Makes a simple 'dialogue' window look a lot nicer (see $self->showEntryDialogue for an
22810 # example of how it works)
22811 #
22812 # Expected arguments
22813 # $vBox - The 'dialogue' window's main Gtk3::VBox
22814 #
22815 # Optional arguments
22816 # $path - Full filepath to an image file to use; if 'undef' or the file doesn't
22817 # exist, the standard icon is used
22818 # $noFrameFlag - TRUE if the image should be drawn without an enclosing frame, FALSE
22819 # (or 'undef') otherwise. (Set to TRUE when called by
22820 # $self->showMsgDialogue)
22821 #
22822 # Return values
22823 # 'undef' on improper arguments
22824 # Otherwise returns the new VBox, contained within the existing main one
22825  
22826 my ($self, $vBox, $path, $noFrameFlag, $check) = @_;
22827  
22828 # Local variables
22829 my $spacing;
22830  
22831 # Check for improper arguments
22832 if (! defined $vBox || defined $check) {
22833  
22834 return $axmud::CLIENT->writeImproper($self->_objClass . '->addDialogueIcon', @_);
22835 }
22836  
22837 # Set the correct spacing size for 'dialogue' windows
22838 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
22839  
22840 # Draw widgets
22841 my $hBox = Gtk3::HBox->new(FALSE, 0);
22842 $vBox->pack_start($hBox, TRUE, TRUE, 0);
22843  
22844 my $vBox2 = Gtk3::VBox->new(FALSE, 0);
22845 $hBox->pack_start($vBox2, TRUE, TRUE, $spacing);
22846  
22847 my $vBox3 = Gtk3::VBox->new(FALSE, 0);
22848 $hBox->pack_start($vBox3, TRUE, TRUE, $spacing);
22849  
22850 if (! $noFrameFlag) {
22851  
22852 # (This code block is designed for Axmud icons, sized 64x64 and above)
22853 my $frame = Gtk3::Frame->new(undef);
22854 $vBox2->pack_start($frame, FALSE, FALSE, $spacing);
22855 $frame->set_size_request(64, 64);
22856 $frame->set_shadow_type($axmud::CLIENT->constShadowType);
22857  
22858 if (! $path || ! -e $path) {
22859  
22860 $path = $axmud::CLIENT->getDialogueIcon();
22861 }
22862  
22863 my $image = Gtk3::Image->new_from_file($path);
22864 $frame->add($image);
22865  
22866 } else {
22867  
22868 # (This code block is designed for the Gtk dialogue icon replacements, sized 32x32)
22869 $vBox2->set_size_request(48, 48);
22870  
22871 my $image = Gtk3::Image->new_from_file($path);
22872 $vBox2->pack_start($image, FALSE, FALSE, $spacing);
22873 }
22874  
22875 return $vBox3;
22876 }
22877  
22878 sub showMsgDialogue {
22879  
22880 # Can be called by any function
22881 # Creates a standard Gtk3::MessageDialog and returns the response (if any)
22882 #
22883 # Expected arguments
22884 # $title - The title to display, e.g. 'File Save'
22885 # $icon - 'info', 'warning', 'error', 'question'
22886 # $text - The message to display. Can be pango markup text, or just plain text
22887 # $buttonType - 'none', 'ok', 'close', 'cancel', 'yes-no', 'ok-cancel'
22888 #
22889 # Optional arguments
22890 # $defaultResponse
22891 # - If defined, the default button ('yes', 'no', etc)
22892 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
22893 # lines (because the calling function has already added newline
22894 # characters as it requires). If FALSE (or 'undef'), the message
22895 # $text is split into lines of no more than 40 characters
22896 #
22897 # Return values
22898 # 'undef' on improper arguments, or if unrecognised values for $icon and/or $buttonType
22899 # are specified
22900 # Otherwise returns the user response (e.g. returns 'yes' if the user clicks on the 'yes'
22901 # button)
22902  
22903 my ($self, $title, $icon, $text, $buttonType, $defaultResponse, $noSplitFlag, $check) = @_;
22904  
22905 # Local variables
22906 my (
22907 $spacing, $response,
22908 @argList, @list,
22909 %buttonHash,
22910 );
22911  
22912 # Check for improper arguments
22913 if (
22914 ! defined $title || ! defined $icon || ! defined $text || ! defined $buttonType
22915 || defined $check
22916 ) {
22917 return $axmud::CLIENT->writeImproper($self->_objClass . '->showMsgDialogue', @_);
22918 }
22919  
22920 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
22921 # be visible above the new dialogue window)
22922 if ($axmud::CLIENT->busyWin) {
22923  
22924 $self->closeDialogueWin($axmud::CLIENT->busyWin);
22925 }
22926  
22927 # Set the correct spacing size for 'dialogue' windows
22928 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
22929  
22930 # Check that $icon and $buttonType are valid values
22931 if (
22932 $icon ne 'info' && $icon ne 'warning' && $icon ne 'error' && $icon ne 'question'
22933 ) {
22934 return $axmud::CLIENT->writeError(
22935 'Unrecognised value \'' . $icon . '\' for icon argument',
22936 $self->_objClass . '->showMsgDialogue',
22937 );
22938 }
22939  
22940 # Convert $buttonType into an argument list
22941 if ($buttonType eq 'ok') {
22942 @argList = ('gtk-ok', 'ok');
22943 } elsif ($buttonType eq 'close') {
22944 @argList = ('gtk-close', 'close');
22945 } elsif ($buttonType eq 'cancel') {
22946 @argList = ('gtk-cancel', 'cancel');
22947 } elsif ($buttonType eq 'yes-no') {
22948 @argList = ('gtk-no', 'no', 'gtk-yes', 'yes');
22949 } elsif ($buttonType eq 'ok-cancel') {
22950 @argList = ('gtk-cancel', 'cancel', 'gtk-ok', 'ok');
22951 } elsif ($buttonType ne 'none') {
22952  
22953 return $axmud::CLIENT->writeError(
22954 'Unrecognised value \'' . $icon . '\' for button type argument',
22955 $self->_objClass . '->showMsgDialogue',
22956 );
22957 }
22958  
22959 # Show the 'dialogue' window
22960 my $dialogueWin = Gtk3::Dialog->new(
22961 $title,
22962 $self->winWidget,
22963 [qw/modal destroy-with-parent/],
22964 @argList,
22965 );
22966  
22967 $dialogueWin->set_position('center-always');
22968 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
22969  
22970 $dialogueWin->signal_connect('delete-event' => sub {
22971  
22972 $dialogueWin->destroy();
22973 $self->restoreFocus();
22974  
22975 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
22976 # the window is visibly closed)
22977 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showMsgDialogue');
22978 });
22979  
22980 # Set the default response, if specified
22981 if (defined $defaultResponse) {
22982  
22983 $dialogueWin->set_default_response($defaultResponse);
22984 }
22985  
22986 # Add widgets to the 'dialogue' window
22987 my $vBox = $dialogueWin->get_content_area();
22988 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
22989 # Gtk3::VBox on the right, into which we put everything
22990 my $vBox2 = $self->addDialogueIcon(
22991 $vBox,
22992 $axmud::SHARE_DIR . '/icons/replace/dialogue_replace_' . $icon . '.png',
22993 TRUE, # Don't draw the image inside a frame
22994 );
22995  
22996 my $label = Gtk3::Label->new();
22997 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
22998 $label->set_alignment(0, 0);
22999  
23000 # If $text is long, it produces a wider window than was produced in earlier version of Gtk.
23001 # This doesn't look very nice, so split $text into lines with a maximum length
23002 # At the same time, we need to escape any < or > characters, or we'll get a Pango error)
23003 if (! $noSplitFlag) {
23004  
23005 $label->set_markup(
23006 Glib::Markup::escape_text(
23007 $axmud::CLIENT->splitText(
23008 $text,
23009 0, # No maximum rows
23010 $axmud::CLIENT->constDialogueLabelSize,
23011 # Maximum characters per line
23012 FALSE, # No ellipsis required
23013 TRUE, # Don't use hyphens when splitting words
23014 )
23015 ),
23016 );
23017  
23018 } else {
23019  
23020 # Calling function has already added newline characters, so no split required
23021 $label->set_markup(Glib::Markup::escape_text($text));
23022 }
23023  
23024 # For the benefit of visually-impaired users who are using the 'tab' key to switch buttons,
23025 # don't allow the label to receive focus
23026 $label->set_can_focus(FALSE);
23027  
23028 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
23029 # consistently active (don't know why this works; it just does)
23030 $dialogueWin->show_all();
23031 $dialogueWin->present();
23032 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
23033  
23034 # Prepare text-to-speech (TTS) code. Get a hash of possible response buttons, in the form
23035 # $buttonHash{'response'} = Gtk3::Button (if the button is used), or 'undef' (if not)
23036 %buttonHash = (
23037 'ok', $dialogueWin->get_widget_for_response('ok'),
23038 'close', $dialogueWin->get_widget_for_response('close'),
23039 'cancel', $dialogueWin->get_widget_for_response('cancel'),
23040 'yes', $dialogueWin->get_widget_for_response('yes'),
23041 'no', $dialogueWin->get_widget_for_response('no'),
23042 );
23043  
23044 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23045  
23046 # Perform TTS for this window
23047 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
23048 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
23049  
23050 foreach my $response (keys %buttonHash) {
23051  
23052 my $button = $buttonHash{$response};
23053  
23054 if (defined $button) {
23055  
23056 # Handy list of responses that are available in this dialogue
23057 push (@list, $response);
23058  
23059 $button->signal_connect('grab-focus' => sub {
23060  
23061 my $label = $button->get_label();
23062  
23063 # $label is in the form 'gtk-yes', 'gtk-no' etc
23064 $axmud::CLIENT->ttsAddUrgentJob(
23065 substr($label, 4) . ' button',
23066 'dialogue',
23067 # Override other TTS urgent jobs, such as the $title and $text above
23068 TRUE,
23069 );
23070 });
23071 }
23072 }
23073  
23074 # (No need to read this message, if there's only one button)
23075 if (@list == 1) {
23076  
23077 $axmud::CLIENT->ttsAddUrgentJob(
23078 $list[0] . ' button selected',
23079 'dialogue',
23080 );
23081  
23082 } else {
23083  
23084 $axmud::CLIENT->ttsAddUrgentJob(
23085 'Select ' . join (', or, ', @list),
23086 'dialogue',
23087 );
23088 }
23089 }
23090 # (end of TTS code)
23091  
23092 # Get the response
23093 $response = $dialogueWin->run();
23094 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23095  
23096 if ($response && exists $buttonHash{$response}) {
23097  
23098 $axmud::CLIENT->ttsAddUrgentJob(
23099 $response . ' selected',
23100 'dialogue',
23101 TRUE,
23102 );
23103  
23104 } else {
23105  
23106 $axmud::CLIENT->ttsAddUrgentJob(
23107 'Cancelled',
23108 'dialogue',
23109 TRUE,
23110 );
23111 }
23112 }
23113  
23114 # Destroy the window and return the response
23115 $dialogueWin->destroy();
23116 $self->restoreFocus();
23117  
23118 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
23119 # window is visibly closed)
23120 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showMsgDialogue');
23121  
23122 return $response;
23123 }
23124  
23125 sub showFileChooser {
23126  
23127 # Can be called by any function
23128 # Creates a standard Gtk3::FileChooserDialog and returns the response (if any)
23129 #
23130 # Expected arguments
23131 # $title - The title of the window, e.g. 'Select file to load'
23132 # $type - 'open', 'save', 'select-folder', 'create-folder'
23133 #
23134 # Optional arguments
23135 # $arg - If $type = 'open', set the current folder (this behaviour is
23136 # discouraged, but it's sometimes appropriate for Axmud code). If
23137 # $type = 'save', suggest a filename using $arg. Ignored if 'undef' or
23138 # if $type is not 'open' or 'save'
23139 #
23140 # Return values
23141 # 'undef' on improper arguments, if $type is invalid, if the file chooser window can't be
23142 # opened or if no file is selected
23143 # Otherwise returns a path to the selected file
23144  
23145 my ($self, $title, $type, $arg, $check) = @_;
23146  
23147 # Local variables
23148 my $fileName;
23149  
23150 # Check for improper arguments
23151 if (! defined $title || ! defined $type || defined $check) {
23152  
23153 return $axmud::CLIENT->writeImproper($self->_objClass . '->showFileChooser', @_);
23154 }
23155  
23156 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23157 # be visible above the new dialogue window)
23158 if ($axmud::CLIENT->busyWin) {
23159  
23160 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23161 }
23162  
23163 # Check that $type is a valid type
23164 if (
23165 $type ne 'open' && $type ne 'save' && $type ne 'select-folder'
23166 && $type ne 'create-folder'
23167 ) {
23168 return $self->writeError(
23169 'Unrecognised file choose type \'' . $type . '\'',
23170 $self->_objClass . '->showFileChooser',
23171 );
23172 }
23173  
23174 # Open the file chooser window
23175 my $dialogueWin = Gtk3::FileChooserDialog->new(
23176 $title,
23177 $self->winWidget,
23178 $type,
23179 'gtk-cancel' => 'cancel',
23180 'gtk-ok' => 'ok'
23181 );
23182  
23183 if (! $dialogueWin) {
23184  
23185 return undef;
23186 }
23187  
23188 $dialogueWin->set_position('center-always');
23189 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23190  
23191 $dialogueWin->signal_connect('delete-event' => sub {
23192  
23193 $dialogueWin->destroy();
23194 $self->restoreFocus();
23195 });
23196  
23197 if (defined $arg) {
23198  
23199 # If loading a file, set the current folder
23200 if ($type eq 'open') {
23201  
23202 $dialogueWin->set_current_folder($arg);
23203  
23204 # If saving a file, suggest a filename
23205 } elsif ($type eq 'save' && defined $arg) {
23206  
23207 $dialogueWin->set_current_name($arg);
23208 }
23209 }
23210  
23211 # Get the file
23212 if ($dialogueWin->run eq 'ok') {
23213  
23214 $fileName = $dialogueWin->get_filename();
23215 }
23216  
23217 # Close the window
23218 $dialogueWin->destroy();
23219 $self->restoreFocus();
23220  
23221 # For saving, show a confirmation message
23222 if (defined $fileName){
23223  
23224 if (-f $fileName && $type eq 'save') {
23225  
23226 my $choice = $self->showMsgDialogue(
23227 'Replace existing file',
23228 'question',
23229 'Overwrite existing file ' . $fileName . ' ?',
23230 'yes-no',
23231 );
23232  
23233 # If the user selects 'no', return false
23234 if ($choice eq 'no') {
23235  
23236 return undef;
23237 }
23238 }
23239  
23240 # Return the path of the selected file
23241 return $fileName;
23242  
23243 } else {
23244  
23245 # No file selected
23246 return undef;
23247 }
23248 }
23249  
23250 sub showEntryDialogue {
23251  
23252 # Can be called by any function
23253 # Prompts the user to enter some text into the entry box; returns the response if the 'ok'
23254 # button is pressed, but 'undef' if either the cancel button is pressed or the window is
23255 # closed
23256 #
23257 # Expected arguments
23258 # $title - The title to display, e.g. 'File Save'
23259 # $text - The message to display. Can be pango markup text, or just plain text
23260 #
23261 # Optional arguments
23262 # $maxChars - The maximum number of chars allowed in the entry box (if 'undef', no
23263 # maximum)
23264 # $entryText - The initial text to put in the entry box (if 'undef', no initial text)
23265 # $obscureModeFlag
23266 # - If set to TRUE, text in the entry box is obscured. If set to FALSE (or
23267 # 'undef'), text is visible
23268 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
23269 # lines (because the calling function has already added newline
23270 # characters as it requires). If FALSE (or 'undef'), the message
23271 # $text is split into lines of no more than 40 characters
23272 # $singleFlag - Set when called by GA::CLIENT->connectBlind (or by any other code that
23273 # might want to remove the 'Cancel' button). If TRUE, only an 'OK'
23274 # button is used. If FALSE (or 'undef'), both an 'OK' and 'Cancel'
23275 # buttons are used
23276 #
23277 # Return values
23278 # 'undef' on improper arguments or if the user doesn't enter some text
23279 # Otherwise returns the user response (the contents of the entry box)
23280  
23281 my (
23282 $self, $title, $text, $maxChars, $entryText, $obscureModeFlag, $noSplitFlag,
23283 $singleFlag, $check
23284 ) = @_;
23285  
23286 # Local variables
23287 my (
23288 $spacing, $starText, $lastThing, $response, $responseText, $confirmMsg,
23289 %buttonHash,
23290 );
23291  
23292 # Check for improper arguments
23293 if (! defined $title || ! defined $text || defined $check) {
23294  
23295 return $axmud::CLIENT->writeImproper($self->_objClass . '->showEntryDialogue', @_);
23296 }
23297  
23298 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23299 # be visible above the new dialogue window)
23300 if ($axmud::CLIENT->busyWin) {
23301  
23302 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23303 }
23304  
23305 # Set the correct spacing size for 'dialogue' windows
23306 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
23307  
23308 # Show the dialogue window
23309 my $dialogueWin;
23310 if ($singleFlag) {
23311  
23312 $dialogueWin = Gtk3::Dialog->new(
23313 $title,
23314 $self->winWidget,
23315 [qw/modal destroy-with-parent/],
23316 'gtk-ok' => 'accept',
23317 );
23318  
23319 } else {
23320  
23321 $dialogueWin = Gtk3::Dialog->new(
23322 $title,
23323 $self->winWidget,
23324 [qw/modal destroy-with-parent/],
23325 'gtk-cancel' => 'reject',
23326 'gtk-ok' => 'accept',
23327 );
23328 }
23329  
23330 $dialogueWin->set_position('center-always');
23331 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23332  
23333 $dialogueWin->signal_connect('delete-event' => sub {
23334  
23335 $dialogueWin->destroy();
23336 $self->restoreFocus();
23337  
23338 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
23339 # the window is visibly closed)
23340 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryDialogue');
23341 });
23342  
23343 # Add widgets to the 'dialogue' window
23344 my $vBox = $dialogueWin->get_content_area();
23345 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
23346 # Gtk3::VBox on the right, into which we put everything
23347 my $vBox2 = $self->addDialogueIcon($vBox);
23348  
23349 my $label = Gtk3::Label->new();
23350 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
23351 $label->set_alignment(0, 0);
23352 if (! $noSplitFlag) {
23353  
23354 $label->set_markup(
23355 Glib::Markup::escape_text(
23356 $axmud::CLIENT->splitText(
23357 $text,
23358 0, # No maximum rows
23359 $axmud::CLIENT->constDialogueLabelSize,
23360 # Maximum characters per line
23361 FALSE, # No ellipsis required
23362 TRUE, # Don't use hyphens when splitting words
23363 )
23364 ),
23365 );
23366  
23367 } else {
23368  
23369 $label->set_markup(Glib::Markup::escape_text($text));
23370 }
23371  
23372 my $entry = Gtk3::Entry->new();
23373 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
23374 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23375  
23376 $entry->set_max_length($maxChars);
23377 }
23378  
23379 if ($obscureModeFlag) {
23380  
23381 $entry->set_visibility(FALSE);
23382  
23383 if ($entryText) {
23384  
23385 # Set the string to be used to disguise the number of characters in $entryText
23386 $starText = '********';
23387 # Just in case $entryText happens to be the same string, use a different string!
23388 if ($entryText eq $starText) {
23389  
23390 $starText = 'xxxxxxxx';
23391 }
23392  
23393 $entry->set_text($starText);
23394  
23395 } else {
23396  
23397 # (Don't hide the fact that $entryText is an empty string, if it is so)
23398 $starText = '';
23399 }
23400  
23401 } elsif ($entryText) {
23402  
23403 # $obscureModeFlag is not set, so display $entryText
23404 $entry->set_text($entryText);
23405 }
23406  
23407 $entry->signal_connect('button_press_event' => sub {
23408  
23409 # In obscure mode, user can change the entry box's text in two ways - clicking on the
23410 # box itself, in which case this event occurs (and we need to empty the box), or by
23411 # tabbing focus through widgets, until the focus falls onto the box, in which case
23412 # the box is emptied and replaced with the first keypress
23413 if ($obscureModeFlag && defined $starText) {
23414  
23415 $entry->set_text('');
23416 # When this function returns a value (below), we need to know whether the
23417 # obscured text has been modified. Only need to do this once
23418 $starText = undef;
23419 }
23420 });
23421  
23422 $entry->signal_connect('changed' => sub {
23423  
23424 # If the text in the entry box has been modified, then we reset $starText (for the
23425 # reasons described just above)
23426 $starText = undef;
23427 });
23428  
23429 $entry->signal_connect('activate' => sub {
23430  
23431 # Get the entry's text, because the code at the bottom of this function won't be
23432 # able to retrieve it...
23433 $responseText = $entry->get_text();
23434 # ...after we destroy the 'dialogue' window
23435 $dialogueWin->destroy();
23436 $self->restoreFocus();
23437 });
23438  
23439 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
23440 # consistently active (don't know why this works; it just does)
23441 $dialogueWin->show_all();
23442 $dialogueWin->present();
23443 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryDialogue');
23444  
23445 # Prepare text-to-speech (TTS) code. Get a hash of the response buttons, in the form
23446 # $buttonHash{'response'} = Gtk3::Button
23447 $buttonHash{'ok'} = $dialogueWin->get_widget_for_response('accept');
23448 if (! $singleFlag) {
23449  
23450 $buttonHash{'cancel'} = $dialogueWin->get_widget_for_response('reject');
23451 }
23452  
23453 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23454  
23455 # Perform TTS for this window
23456 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
23457 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
23458  
23459 # Read out buttons, when in focus
23460 foreach my $response (keys %buttonHash) {
23461  
23462 my $button = $buttonHash{$response};
23463  
23464 $button->signal_connect('grab-focus' => sub {
23465  
23466 my $label = $button->get_label();
23467  
23468 if (! defined $lastThing || $lastThing ne $button) {
23469  
23470 $axmud::CLIENT->ttsAddUrgentJob(
23471 # ($label is in the form 'gtk-yes', 'gtk-no' etc)
23472 substr($label, 4) . ' button',
23473 'dialogue',
23474 # Override other TTS urgent jobs, such as the $title and $text above
23475 TRUE,
23476 );
23477 }
23478  
23479 # Don't use TTS to read out the same widget consecutively
23480 $lastThing = $button;
23481 });
23482 }
23483  
23484 $entry->signal_connect('grab-focus' => sub {
23485  
23486 # (Don't read anything out the first time, but if the user cycles through the keys
23487 # and returns to the entry, using the tab key, read out something)
23488 if ($lastThing) {
23489  
23490 if (! $entry->get_text()) {
23491  
23492 $axmud::CLIENT->ttsAddUrgentJob(
23493 'Type something here',
23494 'dialogue',
23495 TRUE,
23496 );
23497  
23498 } else {
23499  
23500 $axmud::CLIENT->ttsAddUrgentJob(
23501 'Entered: ' . $entry->get_text(),
23502 'dialogue',
23503 TRUE,
23504 );
23505 }
23506 }
23507  
23508 # Don't use TTS to read out the same widget consecutively
23509 $lastThing = $entry;
23510 });
23511 }
23512  
23513 # Get the response
23514 $response = $dialogueWin->run();
23515 if ($response eq 'accept' || $response eq 'none') {
23516  
23517 # If the user pressed the ENTER key, the entry's ->signal_connect for 'activate' stored
23518 # the entry's text in $responseText, before destroying the window
23519 if (! $responseText) {
23520  
23521 $responseText = $entry->get_text();
23522 }
23523  
23524 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23525  
23526 if ($obscureModeFlag) {
23527  
23528 $axmud::CLIENT->ttsAddUrgentJob(
23529 'Text accepted',
23530 'dialogue',
23531 TRUE,
23532 );
23533  
23534 } else {
23535  
23536 $axmud::CLIENT->ttsAddUrgentJob(
23537 'Entered: ' . $responseText,
23538 'dialogue',
23539 TRUE,
23540 );
23541 }
23542 }
23543  
23544 } else {
23545  
23546 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
23547  
23548 $axmud::CLIENT->ttsAddUrgentJob('Cancelled', 'dialogue', TRUE);
23549 }
23550 }
23551  
23552 # Destroy the window
23553 $dialogueWin->destroy();
23554 $self->restoreFocus();
23555  
23556 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
23557 # window is visibly closed)
23558 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryDialogue');
23559  
23560 # Return the response
23561 if ($obscureModeFlag && defined $starText) {
23562  
23563 # The obscured '********' text has not been modified, so we can return the original
23564 # unmodified $entryText
23565 return $entryText;
23566  
23567 } else {
23568  
23569 # Otherwise, return the contents of the entry box
23570 return $responseText;
23571 }
23572 }
23573  
23574 sub showDoubleEntryDialogue {
23575  
23576 # Can be called by any function
23577 # Similar to $self->showEntryDialogue, but contains two entry boxes; returns the contents of
23578 # both boxes
23579 #
23580 # Expected arguments
23581 # $title - The title to display, e.g. 'File Save'
23582 # $labelText - The label above the first entry box. Can be pango markup text, or just
23583 # plain text
23584 #
23585 # Optional arguments
23586 # $labelText2 - The label above the second entry box. If 'undef', no second label is
23587 # used (but the second entry box is still used)
23588 # $maxChars - The maximum number of chars allowed in both entry boxes (if 'undef',
23589 # no maximum)
23590 # $obscureMode - Sets which of the entry boxes has its text obscured
23591 # - 'default' (or 'undef') - no text is obscured
23592 # - 'first' - first box is obscured
23593 # - 'second' - second box is obscured
23594 # - 'both' - both boxes are obscured
23595 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
23596 # lines (because the calling function has already added newline
23597 # characters as it requires). If FALSE (or 'undef'), the message
23598 # $text is split into lines of no more than 40 characters
23599 #
23600 # Return values
23601 # An empty list on improper arguments or if the user doesn't enter some text in either
23602 # entry box
23603 # Otherwise a list of two elements, containing the text in both entry boxes
23604  
23605 my (
23606 $self, $title, $labelText, $labelText2, $maxChars, $obscureMode, $noSplitFlag, $check
23607 ) = @_;
23608  
23609 # Local variables
23610 my (
23611 $spacing, $response, $responseText, $responseText2,
23612 @emptyList,
23613 );
23614  
23615 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23616 # be visible above the new dialogue window)
23617 if ($axmud::CLIENT->busyWin) {
23618  
23619 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23620 }
23621  
23622 # Set the correct spacing size for 'dialogue' windows
23623 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
23624  
23625 # Check for improper arguments
23626 if (! defined $title || ! defined $labelText || defined $check) {
23627  
23628 $axmud::CLIENT->writeImproper($self->_objClass . '->showDoubleEntryDialogue', @_);
23629 return @emptyList;
23630 }
23631  
23632 # Show the 'dialogue' window
23633 my $dialogueWin = Gtk3::Dialog->new(
23634 $title,
23635 $self->winWidget,
23636 [qw/modal destroy-with-parent/],
23637 'gtk-cancel' => 'reject',
23638 'gtk-ok' => 'accept',
23639 );
23640  
23641 $dialogueWin->set_position('center-always');
23642 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23643  
23644 $dialogueWin->signal_connect('delete-event' => sub {
23645  
23646 $dialogueWin->destroy();
23647 $self->restoreFocus();
23648  
23649 return @emptyList;
23650 });
23651  
23652 # Add widgets to the 'dialogue' window
23653 my $vBox = $dialogueWin->get_content_area();
23654 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
23655 # Gtk3::VBox on the right, into which we put everything
23656 my $vBox2 = $self->addDialogueIcon($vBox);
23657  
23658 # First label and entry
23659 my $label = Gtk3::Label->new();
23660 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
23661 $label->set_alignment(0, 0);
23662 if (! $noSplitFlag) {
23663  
23664 $label->set_markup(
23665 Glib::Markup::escape_text(
23666 $axmud::CLIENT->splitText(
23667 $labelText,
23668 0, # No maximum rows
23669 $axmud::CLIENT->constDialogueLabelSize,
23670 # Maximum characters per line
23671 FALSE, # No ellipsis required
23672 TRUE, # Don't use hyphens when splitting words
23673 )
23674 ),
23675 );
23676  
23677 } else {
23678  
23679 $label->set_markup(Glib::Markup::escape_text($labelText));
23680 }
23681  
23682 my $entry = Gtk3::Entry->new();
23683 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
23684 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23685  
23686 $entry->set_max_length($maxChars);
23687 }
23688  
23689 # Second label and entry
23690 if ($labelText2) {
23691  
23692 my $label2 = Gtk3::Label->new();
23693 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
23694 $label2->set_alignment(0, 0);
23695  
23696 if (! $noSplitFlag) {
23697  
23698 $label2->set_markup(
23699 Glib::Markup::escape_text(
23700 $axmud::CLIENT->splitText(
23701 $labelText2,
23702 0, # No maximum rows
23703 $axmud::CLIENT->constDialogueLabelSize,
23704 # Maximum characters per line
23705 FALSE, # No ellipsis required
23706 TRUE, # Don't use hyphens when splitting words
23707 )
23708 ),
23709 );
23710  
23711 } else {
23712  
23713 $label2->set_markup(Glib::Markup::escape_text($labelText2));
23714 }
23715 }
23716  
23717 my $entry2 = Gtk3::Entry->new();
23718 $vBox2->pack_start($entry2, FALSE, FALSE, $spacing);
23719 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23720  
23721 $entry2->set_max_length($maxChars);
23722 }
23723  
23724 # Obscure text in the entry boxes, if necessary
23725 if ($obscureMode && $obscureMode ne 'default') {
23726  
23727 if ($obscureMode eq 'first' || $obscureMode eq 'both') {
23728  
23729 $entry->set_visibility(FALSE);
23730 }
23731  
23732 if ($obscureMode eq 'second' || $obscureMode eq 'both') {
23733  
23734 $entry2->set_visibility(FALSE);
23735 }
23736 }
23737  
23738 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
23739 # consistently active (don't know why this works; it just does)
23740 $dialogueWin->show_all();
23741 $dialogueWin->present();
23742 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showDoubleEntryDialogue');
23743  
23744 # Get the response. If the user clicked 'cancel', $response will be 'reject'
23745 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
23746 $response = $dialogueWin->run();
23747 if ($response eq 'accept') {
23748  
23749 $responseText = $entry->get_text();
23750 $responseText2 = $entry2->get_text();
23751  
23752 # Destroy the window
23753 $dialogueWin->destroy();
23754 $self->restoreFocus();
23755  
23756 # Return the response
23757 return ($responseText, $responseText2);
23758  
23759 } else {
23760  
23761 # Destroy the window
23762 $dialogueWin->destroy();
23763 $self->restoreFocus();
23764  
23765 # Return the response
23766 return @emptyList;
23767 }
23768 }
23769  
23770 sub showTripleEntryDialogue {
23771  
23772 # Can be called by any function
23773 # Similar to $self->showEntryDialogue, but contains three entry boxes; returns the contents
23774 # of all three boxes
23775 #
23776 # Expected arguments
23777 # $title - The title to display, e.g. 'File Save'
23778 # $labelText - The label above the first entry box. Can be pango markup text, or just
23779 # plain text
23780 #
23781 # Optional arguments
23782 # $labelText2 - The label above the second entry box. If 'undef', no second label is
23783 # used (but the second entry box is still used)
23784 # $labelText3 - The label above the third entry box. If 'undef', no third label is
23785 # used (but the third entry box is still used)
23786 # $maxChars - The maximum number of chars allowed in all entry boxes (if 'undef',
23787 # no maximum)
23788 # $obscureMode - Sets which of the entry boxes has its text obscured
23789 # - 0 (or 'undef') - no text is obscured (000)
23790 # - 1 - first box is obscured (001)
23791 # - 2 - second box is obscured (010)
23792 # - 3 - first/second boxes are obscured (011)
23793 # - 4 - third box is obscured (100)
23794 # - 5 - first/third boxes are obscured (101)
23795 # - 6 - second/third boxes are obscured (110)
23796 # - 7 - all boxes are obscured (111)
23797 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
23798 # lines (because the calling function has already added newline
23799 # characters as it requires). If FALSE (or 'undef'), the message
23800 # $text is split into lines of no more than 40 characters
23801 #
23802 # Return values
23803 # An empty list on improper arguments or if the user doesn't enter some text in either
23804 # entry box
23805 # Otherwise a list of three elements, containing the text in both entry boxes
23806  
23807 my (
23808 $self, $title, $labelText, $labelText2, $labelText3, $maxChars, $obscureMode,
23809 $noSplitFlag, $check,
23810 ) = @_;
23811  
23812 # Local variables
23813 my (
23814 $spacing, $response, $responseText, $responseText2, $responseText3,
23815 @emptyList,
23816 );
23817  
23818 # Check for improper arguments
23819 if (! defined $title || ! defined $labelText || defined $check) {
23820  
23821 $axmud::CLIENT->writeImproper($self->_objClass . '->showTripleEntryDialogue', @_);
23822 return @emptyList;
23823 }
23824  
23825 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
23826 # be visible above the new dialogue window)
23827 if ($axmud::CLIENT->busyWin) {
23828  
23829 $self->closeDialogueWin($axmud::CLIENT->busyWin);
23830 }
23831  
23832 # Set the correct spacing size for 'dialogue' windows
23833 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
23834  
23835 # Show the 'dialogue' window
23836 my $dialogueWin = Gtk3::Dialog->new(
23837 $title,
23838 $self->winWidget,
23839 [qw/modal destroy-with-parent/],
23840 'gtk-cancel' => 'reject',
23841 'gtk-ok' => 'accept',
23842 );
23843  
23844 $dialogueWin->set_position('center-always');
23845 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
23846  
23847 $dialogueWin->signal_connect('delete-event' => sub {
23848  
23849 $dialogueWin->destroy();
23850 $self->restoreFocus();
23851  
23852 return @emptyList;
23853 });
23854  
23855 # Add widgets to the 'dialogue' window
23856 my $vBox = $dialogueWin->get_content_area();
23857 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
23858 # Gtk3::VBox on the right, into which we put everything
23859 my $vBox2 = $self->addDialogueIcon($vBox);
23860  
23861 # First label and entry
23862 my $label = Gtk3::Label->new();
23863 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
23864 $label->set_alignment(0, 0);
23865 if (! $noSplitFlag) {
23866  
23867 $label->set_markup(
23868 Glib::Markup::escape_text(
23869 $axmud::CLIENT->splitText(
23870 $labelText,
23871 0, # No maximum rows
23872 $axmud::CLIENT->constDialogueLabelSize,
23873 # Maximum characters per line
23874 FALSE, # No ellipsis required
23875 TRUE, # Don't use hyphens when splitting words
23876 )
23877 ),
23878 );
23879  
23880 } else {
23881  
23882 $label->set_markup(Glib::Markup::escape_text($labelText));
23883 }
23884  
23885 my $entry = Gtk3::Entry->new();
23886 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
23887 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23888  
23889 $entry->set_max_length($maxChars);
23890 }
23891  
23892 # Second label and entry
23893 if ($labelText2) {
23894  
23895 my $label2 = Gtk3::Label->new();
23896 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
23897 $label2->set_alignment(0, 0);
23898  
23899 if (! $noSplitFlag) {
23900  
23901 $label2->set_markup(
23902 Glib::Markup::escape_text(
23903 $axmud::CLIENT->splitText(
23904 $labelText2,
23905 0, # No maximum rows
23906 $axmud::CLIENT->constDialogueLabelSize,
23907 # Maximum characters per line
23908 FALSE, # No ellipsis required
23909 TRUE, # Don't use hyphens when splitting words
23910 )
23911 ),
23912 );
23913  
23914 } else {
23915  
23916 $label2->set_markup(Glib::Markup::escape_text($labelText2));
23917 }
23918 }
23919  
23920 my $entry2 = Gtk3::Entry->new();
23921 $vBox2->pack_start($entry2, FALSE, FALSE, $spacing);
23922 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23923  
23924 $entry2->set_max_length($maxChars);
23925 }
23926  
23927 # Third label and entry
23928 if ($labelText3) {
23929  
23930 my $label3 = Gtk3::Label->new();
23931 $vBox2->pack_start($label3, FALSE, FALSE, $spacing);
23932 $label3->set_alignment(0, 0);
23933  
23934 if (! $noSplitFlag) {
23935  
23936 $label3->set_markup(
23937 Glib::Markup::escape_text(
23938 $axmud::CLIENT->splitText(
23939 $labelText3,
23940 0, # No maximum rows
23941 $axmud::CLIENT->constDialogueLabelSize,
23942 # Maximum characters per line
23943 FALSE, # No ellipsis required
23944 TRUE, # Don't use hyphens when splitting words
23945 )
23946 ),
23947 );
23948  
23949 } else {
23950  
23951 $label3->set_markup(Glib::Markup::escape_text($labelText3));
23952 }
23953 }
23954  
23955 my $entry3 = Gtk3::Entry->new();
23956 $vBox2->pack_start($entry3, FALSE, FALSE, $spacing);
23957 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
23958  
23959 $entry3->set_max_length($maxChars);
23960 }
23961  
23962 # Obscure text in the entry boxes, if necessary
23963 if ($obscureMode) {
23964  
23965 if ($obscureMode == 1 || $obscureMode == 3 || $obscureMode == 5 || $obscureMode == 7) {
23966  
23967 $entry->set_visibility(FALSE);
23968 }
23969  
23970 if ($obscureMode == 2 || $obscureMode == 3 || $obscureMode >= 6) {
23971  
23972 $entry2->set_visibility(FALSE);
23973 }
23974  
23975 if ($obscureMode >= 4) {
23976  
23977 $entry3->set_visibility(FALSE);
23978 }
23979 }
23980  
23981 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
23982 # consistently active (don't know why this works; it just does)
23983 $dialogueWin->show_all();
23984 $dialogueWin->present();
23985 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showTripleComboDialogue');
23986  
23987 # Get the responses. If the user clicked 'cancel', $response will be 'reject'
23988 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
23989 $response = $dialogueWin->run();
23990 if ($response eq 'accept') {
23991  
23992 $responseText = $entry->get_text();
23993 $responseText2 = $entry2->get_text();
23994 $responseText3 = $entry3->get_text();
23995  
23996 # Destroy the window
23997 $dialogueWin->destroy();
23998 $self->restoreFocus();
23999  
24000 # Return the response
24001 return ($responseText, $responseText2, $responseText3);
24002  
24003 } else {
24004  
24005 # Destroy the window
24006 $dialogueWin->destroy();
24007 $self->restoreFocus();
24008  
24009 # Return the response
24010 return @emptyList;
24011 }
24012 }
24013  
24014 sub showComboDialogue {
24015  
24016 # Can be called by any function
24017 # Shows a short message in a 'dialogue' window with the buttons 'ok' and 'cancel'
24018 # Prompts the user to choose a line from a combobox; returns the chosen line if the 'ok'
24019 # button is pressed, but 'undef' if either the cancel button is pressed or the window is
24020 # closed
24021 #
24022 # Expected arguments
24023 # $title - The title to display, e.g. 'File Save'
24024 # $text - The message to display. Can be pango markup text, or just plain text
24025 #
24026 # Optional arguments
24027 # $listRef - Reference to a list of scalars to be used in the combo box. If
24028 # 'undef', the combo box will be empty
24029 # $singleFlag - Set when called by GA::CLIENT->connectBlind (or by any other code that
24030 # might want to remove the 'Cancel' button). If TRUE, only an 'OK'
24031 # button is used. If FALSE (or 'undef'), both an 'OK' and 'Cancel'
24032 # buttons are used
24033 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24034 # lines (because the calling function has already added newline
24035 # characters as it requires). If FALSE (or 'undef'), the message
24036 # $text is split into lines of no more than 40 characters
24037 #
24038 # Return values
24039 # 'undef' on improper arguments, if the user doesn't choose a line or if @lineList is
24040 # empty
24041 # Otherwise returns the user response (the text of the selected line)
24042  
24043 my ($self, $title, $text, $listRef, $singleFlag, $noSplitFlag, $check) = @_;
24044  
24045 # Local variables
24046 my (
24047 $spacing, $lastThing, $response, $responseText,
24048 %buttonHash,
24049 );
24050  
24051 # Check for improper arguments
24052 if (! defined $title || ! defined $text || defined $check) {
24053  
24054 return $axmud::CLIENT->writeImproper($self->_objClass . '->showComboDialogue', @_);
24055 }
24056  
24057 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24058 # be visible above the new dialogue window)
24059 if ($axmud::CLIENT->busyWin) {
24060  
24061 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24062 }
24063  
24064 # Set the correct spacing size for 'dialogue' windows
24065 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24066  
24067 # If $listRef was not specified, use an empty list
24068 if (! defined $listRef) {
24069  
24070 @$listRef = ();
24071 }
24072  
24073 # Show the 'dialogue' window. If $listRef is empty, don't show a 'cancel' button
24074 my $dialogueWin;
24075 if (! @$listRef || $singleFlag) {
24076  
24077 $dialogueWin = Gtk3::Dialog->new(
24078 $title,
24079 $self->winWidget,
24080 [qw/modal destroy-with-parent/],
24081 'gtk-ok' => 'accept',
24082 );
24083  
24084 } else {
24085  
24086 $dialogueWin = Gtk3::Dialog->new(
24087 $title,
24088 $self->winWidget,
24089 [qw/modal destroy-with-parent/],
24090 'gtk-cancel' => 'reject',
24091 'gtk-ok' => 'accept',
24092 );
24093 }
24094  
24095 $dialogueWin->set_position('center-always');
24096 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24097  
24098 $dialogueWin->signal_connect('delete-event' => sub {
24099  
24100 $dialogueWin->destroy();
24101 $self->restoreFocus();
24102  
24103 # (In case TTS is being used and another 'dialogue' window is about to open, make sure
24104 # the window is visibly closed)
24105 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
24106 });
24107  
24108 # Add widgets to the 'dialogue' window
24109 my $vBox = $dialogueWin->get_content_area();
24110 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24111 # Gtk3::VBox on the right, into which we put everything
24112 my $vBox2 = $self->addDialogueIcon($vBox);
24113  
24114 my $label = Gtk3::Label->new();
24115 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24116 $label->set_alignment(0, 0);
24117  
24118 if (! $noSplitFlag) {
24119  
24120 $label->set_markup(
24121 Glib::Markup::escape_text(
24122 $axmud::CLIENT->splitText(
24123 $text,
24124 0, # No maximum rows
24125 $axmud::CLIENT->constDialogueLabelSize,
24126 # Maximum characters per line
24127 FALSE, # No ellipsis required
24128 TRUE, # Don't use hyphens when splitting words
24129 )
24130 ),
24131 );
24132  
24133 } else {
24134  
24135 $label->set_markup(Glib::Markup::escape_text($text));
24136 }
24137  
24138 my $comboBox = Gtk3::ComboBoxText->new();
24139 $vBox2->pack_start($comboBox, FALSE, FALSE, $spacing);
24140 # Fill the combobox with the specified lines, and display the first line
24141 foreach my $line (@$listRef) {
24142  
24143 $comboBox->append_text($line);
24144 }
24145 $comboBox->set_active(0);
24146  
24147 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24148 # consistently active (don't know why this works; it just does)
24149 $dialogueWin->show_all();
24150 $dialogueWin->present();
24151 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
24152  
24153 # Prepare text-to-speech (TTS) code. Get a hash of the response buttons, in the form
24154 # $buttonHash{'response'} = Gtk3::Button
24155 $buttonHash{'ok'} = $dialogueWin->get_widget_for_response('accept');
24156 if (@$listRef && ! $singleFlag) {
24157  
24158 $buttonHash{'cancel'} = $dialogueWin->get_widget_for_response('reject');
24159 }
24160  
24161 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24162  
24163 # Perform TTS for this window
24164 $axmud::CLIENT->ttsAddUrgentJob($title, 'dialogue');
24165 $axmud::CLIENT->ttsAddUrgentJob($text, 'dialogue');
24166  
24167 # Read out buttons, when in focus
24168 foreach my $response (keys %buttonHash) {
24169  
24170 my $button = $buttonHash{$response};
24171  
24172 $button->signal_connect('grab-focus' => sub {
24173  
24174 my $label = $button->get_label();
24175  
24176 if (! defined $lastThing || $lastThing ne $button) {
24177  
24178 $axmud::CLIENT->ttsAddUrgentJob(
24179 # ($label is in the form 'gtk-yes', 'gtk-no' etc)
24180 substr($label, 4) . ' button',
24181 'dialogue',
24182 # Override other TTS urgent jobs, such as the $title and $text above
24183 TRUE,
24184 );
24185 }
24186  
24187 # Don't use TTS to read out the same button label consecutively
24188 $lastThing = $button;
24189 });
24190 }
24191  
24192 # Intercept page up/page down, and make it skip 10 lines, rather than going to the
24193 # top/bottom
24194 $comboBox->signal_connect('key-press-event' => sub {
24195  
24196 my ($widget, $event) = @_;
24197  
24198 # Local variables
24199 my ($keycode, $standard, $index);
24200  
24201 # Get the system keycode for this keypress
24202 $keycode = Gtk3::Gdk::keyval_name($event->keyval);
24203 # Translate it into a standard Axmud keycode
24204 $standard = $axmud::CLIENT->reverseKeycode($keycode);
24205  
24206 if ($standard eq 'page_up' || $standard eq 'page_down') {
24207  
24208 $index = $comboBox->get_active();
24209 if ($index > -1) {
24210  
24211 if ($standard eq 'page_up') {
24212  
24213 $index -= 10;
24214 if ($index < 0) {
24215  
24216 $index = 0;
24217 }
24218  
24219 } else {
24220  
24221 $index += 10;
24222 if ($index >= (scalar @$listRef)) {
24223  
24224 $index = (scalar @$listRef) - 1;
24225 }
24226 }
24227  
24228 $comboBox->set_active($index);
24229  
24230 # Return 1 to show that we have interfered with this keypress
24231 return 1;
24232 }
24233 }
24234  
24235 # Return 'undef' to show that we haven't interfered with this keypress
24236 return undef;
24237 });
24238  
24239 # Read out selected items
24240 $comboBox->signal_connect('key-release-event' => sub {
24241  
24242 my $text = $comboBox->get_active_text();
24243  
24244 # (Use tab/cursor keys to nagivate the widgets)
24245 if (! defined $lastThing || $lastThing ne $text) {
24246  
24247 $axmud::CLIENT->ttsAddUrgentJob(
24248 $text . ' selected',
24249 'dialogue',
24250 TRUE,
24251 );
24252 }
24253  
24254 # Don't use TTS to read out the same combo item consecutively
24255 $lastThing = $text;
24256  
24257 return undef;
24258 });
24259  
24260 $comboBox->signal_connect('changed' => sub {
24261  
24262 my $text = $comboBox->get_active_text();
24263  
24264 # (Use the mouse to focus on the combobox)
24265 if (! defined $lastThing || $lastThing ne $text) {
24266  
24267 $axmud::CLIENT->ttsAddUrgentJob(
24268 $text . ' selected',
24269 'dialogue',
24270 TRUE,
24271 );
24272 }
24273  
24274 # Don't use TTS to read out the same combo item consecutively
24275 $lastThing = $text;
24276  
24277 return undef;
24278 });
24279  
24280 # Make sure that the first item in the combobox has been read out
24281 if (! defined $lastThing || (@$listRef && $lastThing ne $$listRef[0])) {
24282  
24283 if (@$listRef) {
24284  
24285 $axmud::CLIENT->ttsAddUrgentJob(
24286 $$listRef[0] . ' selected',
24287 'dialogue',
24288 );
24289  
24290 } else {
24291  
24292 $axmud::CLIENT->ttsAddUrgentJob(
24293 'There is nothing to select',
24294 'dialogue',
24295 );
24296 }
24297 }
24298  
24299 # Don't use TTS to read out the same combo item consecutively
24300 if (@$listRef) {
24301  
24302 $lastThing = $$listRef[0];
24303 }
24304 }
24305  
24306 # Get the response
24307 $response = $dialogueWin->run();
24308 if ($response eq 'accept') {
24309  
24310 $responseText = $comboBox->get_active_text();
24311  
24312 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24313  
24314 $axmud::CLIENT->ttsAddUrgentJob(
24315 $responseText . ' entered',
24316 'dialogue',
24317 TRUE,
24318 );
24319 }
24320  
24321 } else {
24322  
24323 if ($axmud::CLIENT->systemAllowTTSFlag && $axmud::CLIENT->ttsDialogueFlag) {
24324  
24325 $axmud::CLIENT->ttsAddUrgentJob('Cancelled', 'dialogue', TRUE);
24326 }
24327 }
24328  
24329 # Destroy the window
24330 $dialogueWin->destroy();
24331 $self->restoreFocus();
24332  
24333 # (In case TTS is being used and another 'dialogue' window is about to open, make sure the
24334 # window is visibly closed)
24335 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showComboDialogue');
24336  
24337 return $responseText;
24338 }
24339  
24340 sub showDoubleComboDialogue {
24341  
24342 # Can be called by any function
24343 # Similar to $self->showDoubleEntryDialogue, but contains two combo boxes; returns the
24344 # contents of both boxes
24345 #
24346 # Expected arguments
24347 # $title - The title to display, e.g. 'File Save'
24348 #
24349 # Optional arguments
24350 # $labelText - The label above the first combo box. Can be pango markup text, or just
24351 # plain text. If 'undef', no first label is used (but the combo box is
24352 # still used)
24353 # $labelText2 - The label above the second combo box. If 'undef', no second label is
24354 # used (but the combo box is still used)
24355 # $listRef - Reference to a list of scalars to be used in the first combo box. If
24356 # 'undef', the first combo box will be empty
24357 # $listRef2 - Reference to a list of scalars to be used in the second combo box. If
24358 # 'undef', the second combo box will be empty
24359 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24360 # lines (because the calling function has already added newline
24361 # characters as it requires). If FALSE (or 'undef'), the message
24362 # $text is split into lines of no more than 40 characters
24363 #
24364 # Return values
24365 # An empty list on improper arguments
24366 # Otherwise a list of two elements, containing the contents of the two combo boxes
24367  
24368 my ($self, $title, $labelText, $labelText2, $listRef, $listRef2, $noSplitFlag, $check) = @_;
24369  
24370 # Local variables
24371 my (
24372 $spacing, $response, $responseText, $responseText2,
24373 @emptyList,
24374 );
24375  
24376 # Check for improper arguments
24377 if (! defined $title || defined $check) {
24378  
24379 $axmud::CLIENT->writeImproper($self->_objClass . '->showDoubleComboDialogue', @_);
24380 return @emptyList;
24381 }
24382  
24383 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24384 # be visible above the new dialogue window)
24385 if ($axmud::CLIENT->busyWin) {
24386  
24387 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24388 }
24389  
24390 # Set the correct spacing size for 'dialogue' windows
24391 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24392  
24393 # If $listRef/$listRef2 were not specified, use empty lists
24394 if (! defined $listRef) {
24395  
24396 @$listRef = ();
24397 }
24398  
24399 if (! defined $listRef2) {
24400  
24401 @$listRef2 = ();
24402 }
24403  
24404 # Show the 'dialogue' window
24405 my $dialogueWin = Gtk3::Dialog->new(
24406 $title,
24407 $self->winWidget,
24408 [qw/modal destroy-with-parent/],
24409 'gtk-cancel' => 'reject',
24410 'gtk-ok' => 'accept',
24411 );
24412  
24413 $dialogueWin->set_position('center-always');
24414 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24415  
24416 $dialogueWin->signal_connect('delete-event' => sub {
24417  
24418 $dialogueWin->destroy();
24419 $self->restoreFocus();
24420  
24421 return @emptyList;
24422 });
24423  
24424 # Add widgets to the 'dialogue' window
24425 my $vBox = $dialogueWin->get_content_area();
24426 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24427 # Gtk3::VBox on the right, into which we put everything
24428 my $vBox2 = $self->addDialogueIcon($vBox);
24429  
24430 # First label (optional) and combo (not optional)
24431 my $label;
24432 if ($labelText) {
24433  
24434 $label = Gtk3::Label->new();
24435 $label->set_alignment(0, 0);
24436  
24437 if (! $noSplitFlag) {
24438  
24439 $label->set_markup(
24440 Glib::Markup::escape_text(
24441 $axmud::CLIENT->splitText(
24442 $labelText,
24443 0, # No maximum rows
24444 $axmud::CLIENT->constDialogueLabelSize,
24445 # Maximum characters per line
24446 FALSE, # No ellipsis required
24447 TRUE, # Don't use hyphens when splitting words
24448 )
24449 ),
24450 );
24451  
24452 } else {
24453  
24454 $label->set_markup(Glib::Markup::escape_text($labelText));
24455 }
24456  
24457 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24458 }
24459  
24460 my $combo = Gtk3::ComboBoxText->new();
24461 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
24462  
24463 # Fill the combo box with the specified lines, and display the first line
24464 if (@$listRef) {
24465  
24466 foreach my $line (@$listRef) {
24467  
24468 $combo->append_text($line);
24469 }
24470  
24471 $combo->set_active(0);
24472 }
24473  
24474 # Second label (optional) and combo (not optional)
24475 my $label2;
24476 if ($labelText2) {
24477  
24478 $label2 = Gtk3::Label->new();
24479 $label2->set_alignment(0, 0);
24480  
24481 if (! $noSplitFlag) {
24482  
24483 $label2->set_markup(
24484 Glib::Markup::escape_text(
24485 $axmud::CLIENT->splitText(
24486 $labelText2,
24487 0, # No maximum rows
24488 $axmud::CLIENT->constDialogueLabelSize,
24489 # Maximum characters per line
24490 FALSE, # No ellipsis required
24491 TRUE, # Don't use hyphens when splitting words
24492 )
24493 ),
24494 );
24495  
24496 } else {
24497  
24498 $label2->set_markup(Glib::Markup::escape_text($labelText2));
24499 }
24500  
24501 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
24502 }
24503  
24504 my $combo2 = Gtk3::ComboBoxText->new();
24505 $vBox2->pack_start($combo2, FALSE, FALSE, $spacing);
24506  
24507 # Fill the combo box with the specified lines, and display the first line
24508 if (@$listRef2) {
24509  
24510 foreach my $line (@$listRef2) {
24511  
24512 $combo2->append_text($line);
24513 }
24514  
24515 $combo2->set_active(0);
24516 }
24517  
24518 # Display the 'dialogue' window
24519 $dialogueWin->show_all();
24520 $dialogueWin->present();
24521  
24522 # Get the response. If the user clicked 'cancel', $response will be 'reject'
24523 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
24524 $response = $dialogueWin->run();
24525 if ($response eq 'accept') {
24526  
24527 $responseText = $combo->get_active_text();
24528 $responseText2 = $combo2->get_active_text();
24529  
24530 # Destroy the window
24531 $dialogueWin->destroy();
24532 $self->restoreFocus();
24533  
24534 # Return the response
24535 return ($responseText, $responseText2);
24536  
24537 } else {
24538  
24539 # Destroy the window
24540 $dialogueWin->destroy();
24541 $self->restoreFocus();
24542  
24543 # Return the response
24544 return @emptyList;
24545 }
24546 }
24547  
24548 sub showEntryComboDialogue {
24549  
24550 # Can be called by any function
24551 # Similar to $self->showDoubleEntryDialogue, but contains an entry box above a combo box;
24552 # returns the contents of both boxes
24553 # Optionally displays a combo above an entry box, but note that the order of the arguments
24554 # remains unchanged
24555 #
24556 # Expected arguments
24557 # $title - The title to display, e.g. 'File Save'
24558 #
24559 # Optional arguments
24560 # $labelText - The label above the entry box. Can be pango markup text, or just plain
24561 # text. If 'undef', no first label is used (but the entry box is still
24562 # used)
24563 # $labelText2 - The label above the combo box. If 'undef', no second label is used
24564 # (but the combo box is still used)
24565 # $listRef - Reference to a list of scalars to be used in the combo box. If
24566 # 'undef', the combo box will be empty
24567 # $maxChars - The maximum number of chars allowed in the entry box (if 'undef', no
24568 # maximum)
24569 # $reverseFlag - If set to TRUE, shows a combo above an entry box; if set to FALSE (or
24570 # 'undef'), shows an entry above a combo box
24571 # $quickFlag - If set to TRUE, pressing the ENTER key while the cursor is in the
24572 # entry box closes the window; FALSE or 'undef' if the user must
24573 # actually click the 'OK' or 'Cancel' buttons
24574 # buttons are used
24575 # $noSplitFlag - If TRUE, the message $text is not automatically split into shorter
24576 # lines (because the calling function has already added newline
24577 # characters as it requires). If FALSE (or 'undef'), the message
24578 # $text is split into lines of no more than 40 characters
24579 #
24580 # Return values
24581 # An empty list on improper arguments or if the user doesn't enter some text in the entry
24582 # box
24583 # Otherwise a list of two elements, containing the contents of the entry box and the
24584 # active contents of the combo box
24585  
24586 my (
24587 $self, $title, $labelText, $labelText2, $listRef, $maxChars, $reverseFlag, $quickFlag,
24588 $noSplitFlag, $check,
24589 ) = @_;
24590  
24591 # Local variables
24592 my (
24593 $spacing, $response, $responseText, $responseText2,
24594 @emptyList,
24595 );
24596  
24597 # Check for improper arguments
24598 if (! defined $title || defined $check) {
24599  
24600 $axmud::CLIENT->writeImproper($self->_objClass . '->showEntryComboDialogue', @_);
24601 return @emptyList;
24602 }
24603  
24604 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24605 # be visible above the new dialogue window)
24606 if ($axmud::CLIENT->busyWin) {
24607  
24608 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24609 }
24610  
24611 # Set the correct spacing size for 'dialogue' windows
24612 $spacing = $axmud::CLIENT->constFreeSpacingPixels;
24613  
24614 # If $listRef was not specified, use an empty list
24615 if (! defined $listRef) {
24616  
24617 @$listRef = ();
24618 }
24619  
24620 # Show the 'dialogue' window
24621 my $dialogueWin = Gtk3::Dialog->new(
24622 $title,
24623 $self->winWidget,
24624 [qw/modal destroy-with-parent/],
24625 'gtk-cancel' => 'reject',
24626 'gtk-ok' => 'accept',
24627 );
24628  
24629 $dialogueWin->set_position('center-always');
24630 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24631  
24632 $dialogueWin->signal_connect('delete-event' => sub {
24633  
24634 $dialogueWin->destroy();
24635 $self->restoreFocus();
24636  
24637 return @emptyList;
24638 });
24639  
24640 # Add widgets to the 'dialogue' window
24641 my $vBox = $dialogueWin->get_content_area();
24642 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
24643 # Gtk3::VBox on the right, into which we put everything
24644 my $vBox2 = $self->addDialogueIcon($vBox);
24645  
24646 # First label (optional) and entry (not optional)
24647 my $label;
24648 if ($labelText) {
24649  
24650 $label = Gtk3::Label->new();
24651 $label->set_alignment(0, 0);
24652  
24653 if (! $noSplitFlag) {
24654  
24655 $label->set_markup(
24656 Glib::Markup::escape_text(
24657 $axmud::CLIENT->splitText(
24658 $labelText,
24659 0, # No maximum rows
24660 $axmud::CLIENT->constDialogueLabelSize,
24661 # Maximum characters per line
24662 FALSE, # No ellipsis required
24663 TRUE, # Don't use hyphens when splitting words
24664 )
24665 ),
24666 );
24667  
24668 } else {
24669  
24670 $label->set_markup(Glib::Markup::escape_text($labelText));
24671 }
24672  
24673 }
24674  
24675 my $entry = Gtk3::Entry->new();
24676 if (defined $maxChars && $axmud::CLIENT->intCheck($maxChars, 1)) {
24677  
24678 $entry->set_max_length($maxChars);
24679 }
24680  
24681 # Second label (optional) and combo (not optional)
24682 my $label2;
24683 if ($labelText2) {
24684  
24685 $label2 = Gtk3::Label->new();
24686 $label2->set_alignment(0, 0);
24687  
24688 if (! $noSplitFlag) {
24689  
24690 $label2->set_markup(
24691 Glib::Markup::escape_text(
24692 $axmud::CLIENT->splitText(
24693 $labelText2,
24694 0, # No maximum rows
24695 $axmud::CLIENT->constDialogueLabelSize,
24696 # Maximum characters per line
24697 FALSE, # No ellipsis required
24698 TRUE, # Don't use hyphens when splitting words
24699 )
24700 ),
24701 );
24702  
24703 } else {
24704  
24705 $label2->set_markup(Glib::Markup::escape_text($labelText2));
24706 }
24707 }
24708  
24709 my $combo = Gtk3::ComboBoxText->new();
24710 # Fill the combo box with the specified lines, and display the first line
24711 if (@$listRef) {
24712  
24713 foreach my $line (@$listRef) {
24714  
24715 $combo->append_text($line);
24716 }
24717  
24718 $combo->set_active(0);
24719 }
24720  
24721 # Arrange the entry and combo in the specified order
24722 if (! $reverseFlag) {
24723  
24724 if ($labelText) {
24725  
24726 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24727 }
24728  
24729 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
24730  
24731 if ($labelText2) {
24732  
24733 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
24734 }
24735  
24736 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
24737  
24738 } else {
24739  
24740 if ($labelText2) {
24741  
24742 $vBox2->pack_start($label2, FALSE, FALSE, $spacing);
24743 }
24744  
24745 $vBox2->pack_start($combo, FALSE, FALSE, $spacing);
24746  
24747 if ($labelText) {
24748  
24749 $vBox2->pack_start($label, FALSE, FALSE, $spacing);
24750 }
24751  
24752 $vBox2->pack_start($entry, FALSE, FALSE, $spacing);
24753 }
24754  
24755 if ($quickFlag) {
24756  
24757 $entry->signal_connect('activate' => sub {
24758  
24759 $responseText = $entry->get_text();
24760 $responseText2 = $combo->get_active_text();
24761  
24762 # Destroy the window
24763 $dialogueWin->destroy();
24764 });
24765 }
24766  
24767 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
24768 # consistently active (don't know why this works; it just does)
24769 $dialogueWin->show_all();
24770 $dialogueWin->present();
24771 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showEntryComboDialogue');
24772  
24773 # Get the response. If the user clicked 'cancel', $response will be 'reject'
24774 # Otherwise, user clicked 'ok', and we need to get the contents of the two boxes
24775 $response = $dialogueWin->run();
24776 if (defined $responseText) {
24777  
24778 # (User pressed their ENTER key when $quickFlag is TRUE)
24779  
24780 # Destroy the window
24781 $dialogueWin->destroy();
24782 $self->restoreFocus();
24783  
24784 # Return the response
24785 return ($responseText, $responseText2);
24786  
24787 } elsif ($response eq 'accept' || defined $responseText) {
24788  
24789 $responseText = $entry->get_text();
24790 $responseText2 = $combo->get_active_text();
24791  
24792 # Destroy the window
24793 $dialogueWin->destroy();
24794 $self->restoreFocus();
24795  
24796 # Return the response
24797 return ($responseText, $responseText2);
24798  
24799 } else {
24800  
24801 # Destroy the window
24802 $dialogueWin->destroy();
24803 $self->restoreFocus();
24804  
24805 # Return the response
24806 return @emptyList;
24807 }
24808 }
24809  
24810 sub showColourSelectionDialogue {
24811  
24812 # Can be called by any function
24813 # Creates a standard Gtk3::ColorSelectionDialog and returns the response (if any)
24814 #
24815 # Expected arguments
24816 # $title - The title to display, e.g. 'Select colour'
24817 #
24818 # Optional arguments
24819 # $initialColour - The initial colour to use, in the form '#FFFFFF'. If not specified,
24820 # the dialogue's default colour ('#FFFFFF') is used
24821 #
24822 # Return values
24823 # 'undef' on expected arguments or if the user doesn't close the 'dialogue' window by
24824 # clicking the 'ok' button
24825 # Otherwise, returns the colour selected, in the form '#FFFFFF'
24826  
24827 my ($self, $title, $initialColour, $check) = @_;
24828  
24829 # Local variables
24830 my ($colorSelectionObj, $red, $green, $blue, $colorObj, $response, $hex);
24831  
24832 # Check for improper arguments
24833 if (! defined $title || defined $check) {
24834  
24835 return $axmud::CLIENT->writeImproper(
24836 $self->_objClass . '->showColourSelectionDialogue',
24837 @_,
24838 );
24839 }
24840  
24841 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24842 # be visible above the new dialogue window)
24843 if ($axmud::CLIENT->busyWin) {
24844  
24845 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24846 }
24847  
24848 # Show the 'dialogue' window
24849 my $dialogueWin = Gtk3::ColorSelectionDialog->new($title);
24850 $dialogueWin->set_transient_for($self->winWidget);
24851  
24852 $dialogueWin->set_position('center-always');
24853 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24854  
24855 $colorSelectionObj = $dialogueWin->get_color_selection();
24856  
24857 if ($initialColour) {
24858  
24859 # Split a string like '#FFFFFF' into three seperate colours (red, green and blue),
24860 # convert them to decimals (in the range 0-255), and then convert that to a range of
24861 # 0-65535 - which is what Gtk3::Gdk::Color expects
24862 $red = hex(substr($initialColour, 1, 2)) * 257;
24863 $green = hex(substr($initialColour, 3, 2)) * 257;
24864 $blue = hex(substr($initialColour, 5, 2)) * 257;
24865  
24866 $colorObj = Gtk3::Gdk::Color->new($red, $green, $blue, 0);
24867  
24868 # Tell the Gtk3::ColorSelectionDialog to use this colour, initially
24869 $colorSelectionObj->set_current_color($colorObj);
24870 }
24871  
24872 # Get the response
24873 $response = $dialogueWin->run();
24874 if ($response eq 'ok') {
24875  
24876 # This is probably not the best way of converting #ffff25812581 to #FF2525, but it will
24877 # have to do, for now
24878 $hex = '#' . uc(
24879 sprintf('%02x', int($colorSelectionObj->get_current_color->red() / 256))
24880 . sprintf('%02x', int($colorSelectionObj->get_current_color->green() / 256))
24881 . sprintf('%02x', int($colorSelectionObj->get_current_color->blue() / 256))
24882 );
24883 }
24884  
24885 # Destroy the window
24886 $dialogueWin->destroy();
24887  
24888 # Return the colour (or 'undef' if no colour was selected)
24889 return $hex;
24890 }
24891  
24892 sub showFontSelectionDialogue {
24893  
24894 # Can be called by any function
24895 # Creates a standard Gtk3::FontSelectionDialog and returns the response (if any)
24896 #
24897 # Expected arguments
24898 # $title - The title to display, e.g. 'Select font'
24899 #
24900 # Optional arguments
24901 # $initialFont - The initial font and size to use, a string in the form 'Monospace 10'
24902 #
24903 # Return values
24904 # 'undef' on expected arguments or if the user doesn't close the 'dialogue' window by
24905 # clicking the 'ok' button
24906 # Otherwise, returns the font selected as a string in the form 'Monospace 10'
24907  
24908 my ($self, $title, $initialFont, $check) = @_;
24909  
24910 # Local variables
24911 my ($response, $newFont);
24912  
24913 # Check for improper arguments
24914 if (! defined $title || defined $check) {
24915  
24916 return $axmud::CLIENT->writeImproper(
24917 $self->_objClass . '->showFontSelectionDialogue',
24918 @_,
24919 );
24920 }
24921  
24922 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
24923 # be visible above the new dialogue window)
24924 if ($axmud::CLIENT->busyWin) {
24925  
24926 $self->closeDialogueWin($axmud::CLIENT->busyWin);
24927 }
24928  
24929 # Show the 'dialogue' window
24930 my $dialogueWin = Gtk3::FontChooserDialog->new($title, $self->winWidget);
24931 $dialogueWin->set_position('center-always');
24932 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24933  
24934 if ($initialFont) {
24935  
24936 $dialogueWin->set_font($initialFont);
24937 }
24938  
24939 # Get the response
24940 $response = $dialogueWin->run();
24941 if ($response eq 'ok') {
24942  
24943 # Get the selected font
24944 $newFont = $dialogueWin->get_font();
24945 }
24946  
24947 # Close the 'dialogue' window
24948 $dialogueWin->destroy();
24949  
24950 # Return the font (or 'undef' if no font was selected)
24951 return $newFont;
24952 }
24953  
24954 sub promptRoomFlag {
24955  
24956 # Called by GA::EditWin::WorldModel->roomFlags1Tab
24957 # Prompts the user for the attributes of a new custom room flag
24958 #
24959 # Expected arguments
24960 # (none besides $self)
24961 #
24962 # Return values
24963 # An empty list on improper arguments or if the user closes the window without clicking
24964 # the 'OK' button
24965 # Otherwise returns a list in the form
24966 # (name, short_name, descrip, colour)
24967 # ...roughly corresponding to IVs in the new GA::Obj::RoomFlag object
24968  
24969 my ($self, $check) = @_;
24970  
24971 # Local variables
24972 my (
24973 $colour, $response,
24974 @emptyList, @returnList,
24975 );
24976  
24977 # Check for improper arguments
24978 if (defined $check) {
24979  
24980 $axmud::CLIENT->writeImproper($self->_objClass . '->promptRoomFlag', @_);
24981 return @emptyList;
24982 }
24983  
24984 # Show the 'dialogue' window
24985 my $dialogueWin = Gtk3::Dialog->new(
24986 'Add custom room flag',
24987 $self->winWidget,
24988 [qw/modal destroy-with-parent/],
24989 'gtk-cancel' => 'reject',
24990 'gtk-ok' => 'accept',
24991 );
24992  
24993 $dialogueWin->set_position('center-always');
24994 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
24995  
24996 $dialogueWin->signal_connect('delete-event' => sub {
24997  
24998 $dialogueWin->destroy();
24999 $self->restoreFocus();
25000  
25001 return @emptyList;
25002 });
25003  
25004 # Add widgets to the 'dialogue' window
25005 my $vBox = $dialogueWin->get_content_area();
25006 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25007 # Gtk3::VBox on the right, into which we put everything
25008 my $vBox2 = $self->addDialogueIcon($vBox);
25009  
25010 # Need a grid as it's the quicket way to draw the room flag colour
25011 my $grid = Gtk3::Grid->new();
25012 $vBox2->pack_start($grid, TRUE, TRUE, $axmud::CLIENT->constFreeSpacingPixels);
25013 $grid->set_column_spacing($axmud::CLIENT->constFreeSpacingPixels);
25014 $grid->set_row_spacing($axmud::CLIENT->constFreeSpacingPixels);
25015  
25016 # Name
25017 my $label = Gtk3::Label->new();
25018 $grid->attach($label, 0, 0, 3, 1);
25019 $label->set_alignment(0, 0);
25020 $label->set_markup('Room flag name (max 16 chars)');
25021  
25022 my $entry = Gtk3::Entry->new();
25023 $grid->attach($entry, 0, 1, 3, 1);
25024 $entry->set_width_chars(16);
25025 $entry->set_max_length(16);
25026  
25027 # Short name
25028 my $label2 = Gtk3::Label->new();
25029 $grid->attach($label2, 0, 2, 3, 1);
25030 $label2->set_alignment(0, 0);
25031 $label2->set_markup('Short name (max 2 chars)');
25032  
25033 my $entry2 = Gtk3::Entry->new();
25034 $grid->attach($entry2, 0, 3, 3, 1);
25035 $entry2->set_width_chars(2);
25036 $entry2->set_max_length(2);
25037  
25038 # Description
25039 my $label3 = Gtk3::Label->new();
25040 $grid->attach($label3, 0, 4, 3, 1);
25041 $label3->set_alignment(0, 0);
25042 $label3->set_markup('Description');
25043  
25044 my $entry3 = Gtk3::Entry->new();
25045 $grid->attach($entry3, 0, 5, 3, 1);
25046  
25047 # Colour
25048 $colour = '#FFFFFF'; # Default new colour is white
25049  
25050 my $label4 = Gtk3::Label->new();
25051 $grid->attach($label4, 0, 6, 1, 1);
25052 $label4->set_markup('Use colour');
25053 $label4->set_alignment(0, 0.5);
25054  
25055 my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid,
25056 $colour,
25057 undef, # No neutral colour
25058 1, 2, 6, 7,
25059 );
25060  
25061 my $button = Gtk3::Button->new('Set');
25062 $grid->attach($button, 2, 6, 1, 1);
25063 $button->signal_connect('clicked' => sub {
25064  
25065 my $choice = $self->showColourSelectionDialogue(
25066 'Colour',
25067 $colour,
25068 );
25069  
25070 if ($choice) {
25071  
25072 $colour = $choice;
25073 $canvasObj = $self->fillSimpleCanvas($canvas, $canvasObj, $colour);
25074 }
25075 });
25076  
25077 # Display the dialogue window
25078 $vBox->show_all();
25079  
25080 # If the user clicked 'cancel', $response will be 'reject'
25081 $response = $dialogueWin->run();
25082  
25083 if ($response ne 'accept') {
25084  
25085 $dialogueWin->destroy();
25086 $self->restoreFocus();
25087  
25088 return @emptyList;
25089  
25090 # Otherwise, user clicked 'ok'
25091 } else {
25092  
25093 @returnList = ($entry->get_text(), $entry2->get_text(), $entry3->get_text(), $colour);
25094  
25095 $dialogueWin->destroy();
25096 $self->restoreFocus();
25097  
25098 return @returnList;
25099 }
25100 }
25101  
25102 sub showIrreversibleTest {
25103  
25104 # Called by GA::Cmd::ToggleIrreversible->do
25105 # Shows a 'dialogue' window with a non-functional button that contains both an icon and
25106 # some text, to test whether the user's system allows both (some systems will show only
25107 # the text)
25108 #
25109 # Expected arguments
25110 # (none besides $self)
25111 #
25112 # Return values
25113 # 'undef' on improper arguments or if the user closes the 'dialogue' window
25114 # 1 otherwise
25115  
25116 my ($self, $check) = @_;
25117  
25118 # Check for improper arguments
25119 if (defined $check) {
25120  
25121 return $axmud::CLIENT->writeImproper($self->_objClass . '->showIrreversibleTest', @_);
25122 }
25123  
25124 # If an earlier call to $self->showBusyWin created a popup window, close it (otherwise it'll
25125 # be visible above the new dialogue window)
25126 if ($axmud::CLIENT->busyWin) {
25127  
25128 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25129 }
25130  
25131 # Show the 'dialogue' window
25132 my $dialogueWin = Gtk3::Dialog->new(
25133 'Irreversible icon test',
25134 $self->winWidget,
25135 [qw/modal destroy-with-parent/],
25136 'gtk-ok' => 'accept',
25137 );
25138  
25139 $dialogueWin->set_position('center-always');
25140 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25141  
25142 $dialogueWin->signal_connect('delete-event' => sub {
25143  
25144 $dialogueWin->destroy();
25145 $self->restoreFocus();
25146  
25147 return undef;
25148 });
25149  
25150 # Add widgets to the 'dialogue' window
25151 my $vBox = $dialogueWin->get_content_area();
25152 # The call to ->addDialogueIcon splits $vBox in two, with an icon on the left, and a new
25153 # Gtk3::VBox on the right, into which we put everything
25154 my $vBox2 = $self->addDialogueIcon($vBox);
25155  
25156 my $label = Gtk3::Label->new();
25157 $vBox2->pack_start($label, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25158 $label->set_alignment(0, 0);
25159 $label->set_markup(
25160 "<i>If button icons are available on your\nsystem, the button below contains\nboth an"
25161 . " icon and some text</i>"
25162 );
25163  
25164 my $button = Gtk3::Button->new('Hello world!');
25165 $vBox2->pack_start($button, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25166  
25167 my $image = Gtk3::Image->new_from_file(
25168 $axmud::SHARE_DIR . '/icons/system/irreversible.png',
25169 );
25170  
25171 $button->set_image($image);
25172  
25173 my $label2 = Gtk3::Label->new();
25174 $vBox2->pack_start($label2, FALSE, FALSE, $axmud::CLIENT->constFreeSpacingPixels);
25175 $label2->set_alignment(0, 0);
25176 $label2->set_markup(
25177 "<i>Click 'OK' to end the test</i>"
25178 );
25179  
25180 # Display the 'dialogue' window. Without this combination of Gtk calls, the window is not
25181 # consistently active (don't know why this works; it just does)
25182 $dialogueWin->show_all();
25183 $dialogueWin->present();
25184 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showIrreversibleTest');
25185  
25186 # If the user clicked 'cancel', $response will be 'reject'
25187 # Otherwise, user clicked 'ok', and we might need to add initial tasks
25188 $dialogueWin->run();
25189 $dialogueWin->destroy();
25190 $self->restoreFocus();
25191  
25192 return 1;
25193 }
25194  
25195 sub showBusyWin {
25196  
25197 # Displays a temporary popup window (still an Axmud 'dialogue' window)
25198 # By default, displays the Axmud icon and the caption 'Loading...', but the calling function
25199 # can specify a different logo and caption, if required
25200 # The popup window must be closed by the calling function, when no longer required (via a
25201 # call to $self->closeDialogueWin)
25202 #
25203 # Expected arguments
25204 # (none besides $self)
25205 #
25206 # Optional arguments
25207 # $path - Path of the file containing the image to show as an icon. If not
25208 # specified, the standard Axmud icon
25209 # $caption - A short piece of text to show next to the image. If not specified, the
25210 # caption 'Loading...' is used
25211 #
25212 # Return values
25213 # 'undef' on improper arguments or if the window is not opened
25214 # 1 otherwise
25215  
25216 my ($self, $path, $caption, $check) = @_;
25217  
25218 # Check for improper arguments
25219 if (defined $check) {
25220  
25221 return $axmud::CLIENT->writeImproper($self->_objClass . '->showBusyWin', @_);
25222 }
25223  
25224 # Don't show the popup window at all, if not allowed
25225 if (! $axmud::CLIENT->allowBusyWinFlag) {
25226  
25227 return undef;
25228 }
25229  
25230 # Only one of these temporary popup windows can exist at a time. If one already exists,
25231 # close it
25232 if ($axmud::CLIENT->busyWin) {
25233  
25234 $self->closeDialogueWin($axmud::CLIENT->busyWin);
25235 }
25236  
25237 # Set the file path and caption text, if not specified
25238 if (! defined $path || ! (-e $path)) {
25239  
25240 $path = $axmud::CLIENT->getDialogueIcon('medium');
25241 }
25242  
25243 if (! $caption) {
25244  
25245 $caption = 'Loading...';
25246 }
25247  
25248 # Show the window widget
25249 my $dialogueWin = Gtk3::Window->new('popup');
25250 $dialogueWin->set_position('center-always');
25251 $dialogueWin->set_icon_list($axmud::CLIENT->desktopObj->{dialogueWinIconList});
25252 $dialogueWin->set_title($axmud::SCRIPT);
25253 $dialogueWin->set_border_width(0);
25254 $dialogueWin->set_transient_for($self->winWidget);
25255  
25256 $dialogueWin->signal_connect('delete-event' => sub {
25257  
25258 $dialogueWin->destroy();
25259 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showBusyWin');
25260 });
25261  
25262 # Add widgets to the 'dialogue' window
25263 my $frame = Gtk3::Frame->new();
25264 $dialogueWin->add($frame);
25265  
25266 my $hBox = Gtk3::HBox->new(FALSE, 0);
25267 $frame->add($hBox);
25268 $hBox->set_border_width(10);
25269  
25270 my $image = Gtk3::Image->new_from_file($path);
25271 $hBox->pack_start($image, FALSE, FALSE, 5);
25272  
25273 my $label = Gtk3::Label->new();
25274 $hBox->pack_start($label, FALSE, FALSE, 5);
25275 $label->set_markup('<i><big>' . $caption . '</big></i>');
25276 $label->set_alignment(0.5, 0.5);
25277  
25278 $dialogueWin->show_all();
25279  
25280 # For some reason, during certain operations the icon and text are not shown in the
25281 # window; the following lines make them appear
25282 $dialogueWin->present();
25283 # Update Gtk3's events queue
25284 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showBusyWin');
25285 # Update the Client IV
25286 $axmud::CLIENT->set_busyWin($dialogueWin);
25287  
25288 return $dialogueWin;
25289 }
25290  
25291 # Functions to add widgets to a Gtk3::Grid
25292  
25293 sub addLabel {
25294  
25295 # Adds a Gtk3::Label at the specified position in a Gtk3::Grid
25296 #
25297 # Example calls:
25298 # my $label = $self->addLabel($grid, 'Some plain text',
25299 # 0, 6, 0, 1);
25300 # my $label = $self->addLabel($grid, '<b>Some pango markup text</b>',
25301 # 0, 6, 0, 1,
25302 # 0, 0.5);
25303 #
25304 # Expected arguments
25305 # $grid - The Gtk3::Grid itself
25306 # $text - The text to display (plain text or pango markup text)
25307 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25308 # - The position of the label in the table
25309 #
25310 # Optional arguments
25311 # $alignLeft, $alignRight
25312 # - Used in the call to ->set_alignment; two values in the range 0-1
25313 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
25314 #
25315 # Return values
25316 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25317 # Otherwise the Gtk3::Label created
25318  
25319 my (
25320 $self, $grid, $text, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $alignLeft,
25321 $alignRight, $check
25322 ) = @_;
25323  
25324 # Check for improper arguments
25325 if (
25326 ! defined $grid || ! defined $text || ! defined $leftAttach || ! defined $rightAttach
25327 || ! defined $topAttach || ! defined $bottomAttach || defined $check
25328 ) {
25329 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
25330 }
25331  
25332 # Check that the position in the table makes sense
25333 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25334  
25335 return undef;
25336 }
25337  
25338 # Set default alignment, if none specified
25339 if (! defined $alignLeft) {
25340  
25341 $alignLeft = 0;
25342 }
25343  
25344 if (! defined $alignRight) {
25345  
25346 $alignRight = 0.5;
25347 }
25348  
25349 # Create the label
25350 my $label = Gtk3::Label->new();
25351 $label->set_markup($text);
25352  
25353 # Set its alignment
25354 $label->set_alignment($alignLeft, $alignRight);
25355  
25356 # Add the label to the grid
25357 $label->set_hexpand(TRUE);
25358 $label->set_vexpand(FALSE);
25359 $grid->attach(
25360 $label,
25361 $leftAttach,
25362 $topAttach,
25363 ($rightAttach - $leftAttach),
25364 ($bottomAttach - $topAttach),
25365 );
25366  
25367 return $label;
25368 }
25369  
25370 sub addButton {
25371  
25372 # Adds a Gtk3::Button at the specified position in a Gtk3::Grid
25373 # NB This function does not contain a ->signal_connect method - the calling function must
25374 # specify its own one
25375 #
25376 # Example calls:
25377 # my $button = $self->addButton($grid, \&buttonClicked, 'button_label', 'tooltips',
25378 # 0, 6, 0, 1);
25379 # my $button = $self->addButton($grid, undef, 'button_label', 'tooltips',
25380 # 0, 6, 0, 1);
25381 # my $button = $self->addButton($grid, \&buttonClicked, 'button_label', '',
25382 # 0, 6, 0, 1);
25383 #
25384 # The referenced function (if specified) receives an argument list in the form:
25385 # ($self, button_widget)
25386 #
25387 # Expected arguments
25388 # $grid - The Gtk3::Grid itself
25389 # $funcRef - Reference to the function to call when the button is clicked. If 'undef',
25390 # it's up to the calling function to create a ->signal_connect method
25391 # $label - The label text displayed on the button
25392 # $tooltips - Tooltips to use for the button; empty strings are not used
25393 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25394 # - The position of the button in the table
25395 #
25396 # Return values
25397 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25398 # Otherwise the Gtk3::Button created
25399  
25400 my (
25401 $self, $grid, $funcRef, $label, $tooltips, $leftAttach, $rightAttach, $topAttach,
25402 $bottomAttach, $check,
25403 ) = @_;
25404  
25405 # Local variables
25406 my $current;
25407  
25408 # Check for improper arguments
25409 if (
25410 ! defined $grid || ! defined $label || ! defined $tooltips || ! defined $leftAttach
25411 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
25412 || defined $check
25413 ) {
25414 return $axmud::CLIENT->writeImproper($self->_objClass . '->addButton', @_);
25415 }
25416  
25417 # Check that the position in the table makes sense
25418 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25419  
25420 return undef;
25421 }
25422  
25423 # Create the button
25424 my $button = Gtk3::Button->new($label);
25425  
25426 # Use tooltips, if any were specified
25427 if ($tooltips) {
25428  
25429 $button->set_tooltip_text($tooltips);
25430 }
25431  
25432 # If a callback function was specified, apply it
25433 if ($funcRef) {
25434  
25435 $button->signal_connect('clicked' => sub {
25436  
25437 &$funcRef($self, $button);
25438 });
25439 }
25440  
25441 # Add the button to the grid
25442 $button->set_hexpand(TRUE);
25443 $button->set_vexpand(FALSE);
25444 $grid->attach(
25445 $button,
25446 $leftAttach,
25447 $topAttach,
25448 ($rightAttach - $leftAttach),
25449 ($bottomAttach - $topAttach),
25450 );
25451  
25452 return $button;
25453 }
25454  
25455 sub addCheckButton {
25456  
25457 # Adds a Gtk3::CheckButton with an accompanying label at the specified position in a
25458 # Gtk3::Grid
25459 # NB This function does not contain a ->signal_connect method - the calling function must
25460 # specify its own one
25461 #
25462 # Example calls:
25463 # my $checkButton = $self->addCheckButton($grid, 'Click me', \&buttonClicked, TRUE, TRUE,
25464 # 0, 6, 0, 1);
25465 # my $checkButton = $self->addCheckButton($grid, undef, \&buttonClicked, TRUE, TRUE,
25466 # 0, 6, 0, 1);
25467 #
25468 # The referenced function (if specified) receives an argument list in the form:
25469 # ($self, button_widget, button_selected_flag)
25470 #
25471 # Expected arguments
25472 # $grid - The Gtk3::Grid itself
25473 # $name - A 'name' for the checkbutton (displayed next to the button); if 'undef',
25474 # no name is displayed
25475 # $funcRef - Reference to the function to call when the button is toggled. If 'undef',
25476 # it's up to the calling function to create a ->signal_connect method
25477 # $selectFlag - Flag set to FALSE if the checkbutton shouldn't be selected initially, TRUE
25478 # if it should be selected initially
25479 # $stateFlag - Flag set to FALSE if the checkbutton's state should be 'insensitive',
25480 # TRUE if it should be 'normal'
25481 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25482 # - The position of the checkbutton in the table
25483 #
25484 # Return values
25485 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25486 # Otherwise the Gtk3::CheckButton created
25487  
25488 my (
25489 $self, $grid, $name, $funcRef, $selectFlag, $stateFlag, $leftAttach, $rightAttach,
25490 $topAttach, $bottomAttach, $check,
25491 ) = @_;
25492  
25493 # Check for improper arguments
25494 if (
25495 ! defined $grid || ! defined $selectFlag || ! defined $stateFlag
25496 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
25497 || ! defined $bottomAttach || defined $check
25498 ) {
25499 return $axmud::CLIENT->writeImproper($self->_objClass . '->addCheckButton', @_);
25500 }
25501  
25502 # Check that the position in the table makes sense
25503 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25504  
25505 return undef;
25506 }
25507  
25508 # Create the check button
25509 my $checkButton;
25510 if (defined $name && $name ne '') {
25511 $checkButton = Gtk3::CheckButton->new_with_label($name);
25512 } else {
25513 $checkButton = Gtk3::CheckButton->new();
25514 }
25515  
25516 # Set the checkbutton's initial value
25517 $checkButton->set_active($selectFlag);
25518  
25519 # Make the checkbutton insensitive, if $stateFlag is FALSE
25520 if (! $stateFlag) {
25521  
25522 $checkButton->set_state('insensitive');
25523 }
25524  
25525 # If a callback function was specified, apply it
25526 if ($funcRef) {
25527  
25528 $checkButton->signal_connect('toggled' => sub {
25529  
25530 &$funcRef($self, $checkButton, $checkButton->get_active());
25531 });
25532 }
25533  
25534 # Add the check button to the grid
25535 $checkButton->set_hexpand(TRUE);
25536 $checkButton->set_vexpand(FALSE);
25537 $grid->attach(
25538 $checkButton,
25539 $leftAttach,
25540 $topAttach,
25541 ($rightAttach - $leftAttach),
25542 ($bottomAttach - $topAttach),
25543 );
25544  
25545 return $checkButton;
25546 }
25547  
25548 sub addRadioButton {
25549  
25550 # Adds a Gtk3::RadioButton at the specified position in a Gtk3::Grid
25551 # NB This function does not contain a ->signal_connect method - the calling function must
25552 # specify its own one
25553 #
25554 # Example calls:
25555 # my ($group, $button) = $self->addRadioButton(
25556 # $grid, \&buttonClicked, undef, $name,
25557 # TRUE, TRUE,
25558 # 0, 6, 0, 1);
25559 # my ($group2, $button2) = $self->addRadioButton(
25560 # $grid, undef, $group, $name,
25561 # FALSE, TRUE,
25562 # 0, 6, 0, 1, 0, 0.5);
25563 #
25564 # The referenced function (if specified) receives an argument list in the form:
25565 # ($self, button_widget)
25566 #
25567 # Expected arguments
25568 # $grid - The Gtk3::Grid itself
25569 # $funcRef - Reference to the function to call when the button becomes active
25570 # (selected). If 'undef', it's up to the calling function to create a
25571 # ->signal_connect method
25572 # $group - Reference to the radio button group created, when the first button in the
25573 # group was added (if set to 'undef', this is the first button, and a
25574 # group will be created for it)
25575 # $name - A 'name' for the radio button (displayed next to the button); if 'undef',
25576 # no name is displayed
25577 # $selectFlag - Flag set to FALSE if the radio button shouldn't be selected initially,
25578 # TRUE if it should be selected initially
25579 # $stateFlag - Flag set to FALSE if the radiobutton's state should be 'insensitive',
25580 # TRUE if it should be 'normal'
25581 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25582 # - The position of the radiobutton in the table
25583 #
25584 # Optional arguments
25585 # $alignLeft, $alignRight
25586 # - Used in the call to ->set_alignment; two values in the range 0-1
25587 # - If not specified, $alignLeft is set to 0, $alignRight to 0.5
25588 #
25589 # Return values
25590 # An empty list on improper arguments or if the widget's position in the Gtk3::Grid is
25591 # invalid
25592 # Otherwise a list containing two elements: the radio button $group and the
25593 # Gtk3::RadioButton created
25594  
25595 my (
25596 $self, $grid, $funcRef, $group, $name, $selectFlag, $stateFlag, $leftAttach,
25597 $rightAttach, $topAttach, $bottomAttach, $alignLeft, $alignRight, $check,
25598 ) = @_;
25599  
25600 # Local variables
25601 my @emptyList;
25602  
25603 # Check for improper arguments
25604 if (
25605 ! defined $grid || ! defined $selectFlag || ! defined $stateFlag
25606 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
25607 || ! defined $bottomAttach || defined $check
25608 ) {
25609 $axmud::CLIENT->writeImproper($self->_objClass . '->addRadioButton', @_);
25610 return @emptyList;
25611 }
25612  
25613 # Check that the position in the table makes sense
25614 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25615  
25616 return @emptyList;
25617 }
25618  
25619 # Set default alignment, if none specified
25620 if (! defined $alignLeft) {
25621  
25622 $alignLeft = 0;
25623 }
25624 if (! defined $alignRight) {
25625  
25626 $alignRight = 0.5;
25627 }
25628  
25629 # Create the radio button
25630 my $radioButton = Gtk3::RadioButton->new();
25631 # Add it to the existing group, if one was specified
25632 if (defined $group) {
25633  
25634 $radioButton->set_group($group);
25635 }
25636  
25637 # Set the radiobutton's initial value
25638 $radioButton->set_active($selectFlag);
25639  
25640 # Give the radio button a name, if one was specified
25641 if ($name) {
25642  
25643 $radioButton->set_label($name);
25644 }
25645  
25646 # Make the radiobutton insensitive, if $stateFlag is FALSE
25647 if (! $stateFlag) {
25648  
25649 $radioButton->set_state('insensitive');
25650 }
25651  
25652 # Set radiobutton's alignment
25653 $radioButton->set_alignment($alignLeft, $alignRight);
25654  
25655 # If a callback function was specified, apply it
25656 if ($funcRef) {
25657  
25658 $radioButton->signal_connect('toggled' => sub {
25659  
25660 # Only call the function if this radio button has been selected
25661 if ($radioButton->get_active()) {
25662  
25663 &$funcRef($self, $radioButton);
25664 }
25665 });
25666 }
25667  
25668 # Add the radio button to the grid
25669 $radioButton->set_hexpand(FALSE);
25670 $radioButton->set_vexpand(FALSE);
25671 $grid->attach(
25672 $radioButton,
25673 $leftAttach,
25674 $topAttach,
25675 ($rightAttach - $leftAttach),
25676 ($bottomAttach - $topAttach),
25677 );
25678  
25679 return ($radioButton->get_group(), $radioButton);
25680 }
25681  
25682 sub addEntry {
25683  
25684 # Adds a Gtk3::Entry at the specified position in a Gtk3::Grid
25685 # NB This function does not contain a ->signal_connect method - the calling function must
25686 # specify its own one
25687 #
25688 # Example calls:
25689 # my $entry = $self->addEntry($grid, \&returnPressed, $value, TRUE,
25690 # 0, 6, 0, 1);
25691 # my $entry = $self->addEntry($grid, undef, $value, FALSE,
25692 # 0, 6, 0, 1, 16, 16);
25693 #
25694 # The referenced function (if specified) receives an argument list in the form:
25695 # ($self, entry_widget, entry_text)
25696 #
25697 # Expected arguments
25698 # $grid - The Gtk3::Grid itself
25699 # $funcRef - Reference to the function to call when the user types something in the
25700 # entry and presses 'return'. If 'undef', it's up to the calling function
25701 # to create a ->signal_connect method
25702 # $value - The initial contents of the entry box. Set to 'undef' if you want it to be
25703 # empty
25704 # $stateFlag - Flag set to FALSE if the entry box's state should be 'insensitive', TRUE
25705 # if it should be 'normal'
25706 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25707 # - The position of the entry box in the table
25708 #
25709 # Optional arguments
25710 # $widthChars - The width of the box, in chars ('undef' if maximum not needed)
25711 # $maxChars - The maximum no. chars allowed in the box ('undef' if maximum not needed)
25712 #
25713 # Return values
25714 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25715 # Otherwise the Gtk3::Entry created
25716  
25717 my (
25718 $self, $grid, $funcRef, $value, $stateFlag, $leftAttach, $rightAttach, $topAttach,
25719 $bottomAttach, $widthChars, $maxChars, $check,
25720 ) = @_;
25721  
25722 # Check for improper arguments
25723 if (
25724 ! defined $grid || ! defined $stateFlag || ! defined $leftAttach
25725 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
25726 || defined $check
25727 ) {
25728 return $axmud::CLIENT->writeImproper($self->_objClass . '->addEntry', @_);
25729 }
25730  
25731 # Check that the position in the table makes sense
25732 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25733  
25734 return undef;
25735 }
25736  
25737 # Create the entry
25738 my $entry = Gtk3::Entry->new();
25739  
25740 # Set the entry's value
25741 if ($value) {
25742  
25743 $entry->set_text($value);
25744 }
25745  
25746 # Make the entry insensitive, if $stateFlag is FALSE
25747 if (! $stateFlag) {
25748  
25749 $entry->set_state('insensitive');
25750 }
25751  
25752 # Set the width, if specified
25753 if (defined $widthChars) {
25754  
25755 $entry->set_width_chars($widthChars);
25756 }
25757  
25758 # Set the maximum number of characters, if specified
25759 if (defined $maxChars) {
25760  
25761 $entry->set_max_length($maxChars);
25762 }
25763  
25764 # If a callback function was specified, apply it
25765 if ($funcRef) {
25766  
25767 $entry->signal_connect('activate' => sub {
25768  
25769 &$funcRef($self, $entry, $entry->get_text());
25770 });
25771 }
25772  
25773 # Add the entry to the grid
25774 $entry->set_hexpand(TRUE);
25775 $entry->set_vexpand(FALSE);
25776 $grid->attach(
25777 $entry,
25778 $leftAttach,
25779 $topAttach,
25780 ($rightAttach - $leftAttach),
25781 ($bottomAttach - $topAttach),
25782 );
25783  
25784 return $entry;
25785 }
25786  
25787 sub addComboBox {
25788  
25789 # Adds a Gtk3::ComboBox at the specified position in a Gtk3::Grid
25790 # NB This function does not contain a ->signal_connect method - the calling function must
25791 # specify its own one
25792 #
25793 # Example calls:
25794 # my $comboBox = $self->addComboBox(
25795 # $grid, \&itemSelected, \@comboList, 'some_title', TRUE,
25796 # 0, 6, 0, 1);
25797 # my $comboBox = $self->addComboBox(
25798 # $grid, undef, \@comboList, '', FALSE,
25799 # 0, 6, 0, 1);
25800 #
25801 # The referenced function (if specified) receives an argument list in the form:
25802 # ($self, combo_box_widget, selected_text)
25803 #
25804 # Expected arguments
25805 # $grid - The Gtk3::Grid itself
25806 # $funcRef - Reference to the function to call when the user selects something in
25807 # the combobox. If 'undef', it's up to the calling function to create
25808 # a ->signal_connect method
25809 # $listRef - Reference to a list with initial values (can be an empty list)
25810 # $title - A string used as a title, e.g. 'Choose your favourite colour' - if
25811 # 'undef', a title isn't used (use an empty string for an initially-
25812 # empty combobox)
25813 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25814 # - The position of the combo box in the table
25815 #
25816 # Return values
25817 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25818 # Otherwise the Gtk3::ComboBox created
25819  
25820 my (
25821 $self, $grid, $funcRef, $listRef, $title, $leftAttach, $rightAttach, $topAttach,
25822 $bottomAttach, $check,
25823 ) = @_;
25824  
25825 # Check for improper arguments
25826 if (
25827 ! defined $grid || ! defined $listRef || ! defined $leftAttach
25828 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
25829 || defined $check
25830 ) {
25831 return $axmud::CLIENT->writeImproper($self->_objClass . '->addComboBox', @_);
25832 }
25833  
25834 # Check that the position in the table makes sense
25835 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25836  
25837 return undef;
25838 }
25839  
25840 # Create the combobox
25841 my $comboBox = Gtk3::ComboBoxText->new();
25842  
25843 # Populate the combobox
25844 if (defined $title) {
25845  
25846 # The first item in the combobox list is a title
25847 $comboBox->append_text($title);
25848 }
25849  
25850 foreach my $item (@$listRef) {
25851  
25852 $comboBox->append_text($item);
25853 }
25854  
25855 $comboBox->set_active(0);
25856  
25857 # If a callback function was specified, apply it
25858 if ($funcRef) {
25859  
25860 $comboBox->signal_connect('changed' => sub {
25861  
25862 my $text = $comboBox->get_active_text();
25863  
25864 # If the user has selected the title, ignore it
25865 if (! defined $title || $text ne $title) {
25866  
25867 &$funcRef($self, $comboBox, $text);
25868 }
25869 });
25870 }
25871  
25872 # Add the combobox to the grid
25873 $comboBox->set_hexpand(TRUE);
25874 $comboBox->set_vexpand(FALSE);
25875 $grid->attach(
25876 $comboBox,
25877 $leftAttach,
25878 $topAttach,
25879 ($rightAttach - $leftAttach),
25880 ($bottomAttach - $topAttach),
25881 );
25882  
25883 return $comboBox;
25884 }
25885  
25886 sub addTextView {
25887  
25888 # Adds a Gtk3::TextView at the specified position in a Gtk3::Grid
25889 # NB This function does not contain a ->signal_connect method - the calling function must
25890 # specify its own one
25891 #
25892 # Example calls:
25893 # my $textView = $self->addTextView($grid, $self->winType, undef, undef, TRUE,
25894 # 0, 6, 0, 1);
25895 # my $textView = $self->addTextView($grid, undef, undef, "Hello\nworld", FALSE,
25896 # 0, 6, 0, 1,
25897 # -1, 120);
25898 #
25899 # The referenced function (if specified) receives an argument list in the form:
25900 # ($self, textview_widget, buffer_widget, buffer_text)
25901 # ...where 'buffer_text' is a string containing one or more lines, separated by newline
25902 # characters
25903 #
25904 # Expected arguments
25905 # $grid - The Gtk3::Grid itself
25906 # $colourScheme - The name of the colour scheme to use (matches a key in
25907 # GA::Client->colourSchemeHash; you should normally use the window
25908 # type, as in the example above). If 'undef', the system's
25909 # preferred colours/fonts are used. If the specified colour scheme
25910 # doesn't exist, the colour scheme matching the window type is used
25911 # $funcRef - Reference to the function to call when the user edits the contents of
25912 # the textview. If 'undef', it's up to the calling function to create
25913 # a ->signal_connect method
25914 # $string - String composed of one or lines separated by newline characters. If
25915 # 'undef', the textview is initially empty
25916 # $editableFlag - Flag set to TRUE if the textView should be editable, FALSE if it
25917 # shouldn't be editable
25918 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
25919 # - The position of the textview in the table
25920 #
25921 # Optional arguments
25922 # $width, $height
25923 # - The width and height (in pixels) of the frame containing the list. If
25924 # specified, values of -1 mean 'don't set this value'. The default values
25925 # are (-1, -1)
25926 #
25927 # Return values
25928 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
25929 # Otherwise the Gtk3::TextView created (inside a Gtk::ScrolledWindow)
25930  
25931 my (
25932 $self, $grid, $colourScheme, $funcRef, $string, $editableFlag, $leftAttach,
25933 $rightAttach, $topAttach, $bottomAttach, $width, $height, $check,
25934 ) = @_;
25935  
25936 # Check for improper arguments
25937 if (
25938 ! defined $grid || ! defined $editableFlag || ! defined $leftAttach
25939 || ! defined $rightAttach || ! defined $topAttach || ! defined $bottomAttach
25940 || defined $check
25941 ) {
25942 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTextView', @_);
25943 }
25944  
25945 # Check that the position in the table makes sense
25946 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
25947  
25948 return undef;
25949 }
25950  
25951 # Set defaults
25952 if (! defined $width) {
25953  
25954 $width = -1; # Let Gtk3 set the width
25955 }
25956  
25957 if (! defined $height) {
25958  
25959 $height = -1; # Let Gtk3 set the height
25960 }
25961  
25962 # Creating a containing Gtk3::ScrolledWindow
25963 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
25964 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
25965 $scroll->set_policy('automatic', 'automatic');
25966 $scroll->set_size_request($width, $height);
25967 # $scroll->set_border_width($self->spacingPixels);
25968  
25969 # Create a textview and apply a CSS style
25970 my $textView = Gtk3::TextView->new();
25971 $scroll->add($textView);
25972 my $buffer = Gtk3::TextBuffer->new();
25973 $textView->set_buffer($buffer);
25974 $textView->set_cursor_visible(FALSE);
25975  
25976 if ($string) {
25977  
25978 $buffer->set_text(join("\n", $string));
25979 }
25980  
25981 # Make the textview editable or not editable
25982 $textView->set_editable($editableFlag);
25983  
25984 # Apply a CSS style to the textview
25985 if (defined $colourScheme && $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
25986 $axmud::CLIENT->desktopObj->setTextViewStyle($colourScheme, $textView);
25987 } else {
25988 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winType, $textView);
25989 }
25990  
25991 # If a callback function was specified, apply it
25992 if ($funcRef) {
25993  
25994 $buffer->signal_connect('changed' => sub {
25995  
25996 &$funcRef(
25997 $self,
25998 $textView,
25999 $buffer,
26000 $axmud::CLIENT->desktopObj->bufferGetText($buffer),
26001 );
26002 });
26003 }
26004  
26005 # Add the textview to the grid
26006 $scroll->set_hexpand(TRUE);
26007 $scroll->set_vexpand(TRUE);
26008 $grid->attach(
26009 $scroll,
26010 $leftAttach,
26011 $topAttach,
26012 ($rightAttach - $leftAttach),
26013 ($bottomAttach - $topAttach),
26014 );
26015  
26016 return $textView;
26017 }
26018  
26019 sub addSimpleList {
26020  
26021 # Adds a GA::Obj::SimpleList at the specified position in a Gtk3::Grid
26022 # NB This function does not contain a ->signal_connect method - the calling function must
26023 # specify its own one
26024 #
26025 # Example calls:
26026 # my $slWidget = $self->addSimpleList($grid, \@columnList, $dataRef, TRUE,
26027 # 0, 6, 0, 1);
26028 # my $slWidget = $self->addSimpleList($grid, \@columnList, undef, FALSE,
26029 # 0, 6, 0, 1,
26030 # -1, 120);
26031 #
26032 # Expected arguments
26033 # $grid - The Gtk3::Grid itself
26034 # $columnListRef - Reference to a list of column headings and types, in the form
26035 # ('heading', 'column_type', 'heading', 'column_type'...)
26036 # - 'column_type' is one of the column types specified by
26037 # GA::Obj::SimpleList, e.g. 'scalar', 'int'
26038 # $dataRef - Reference to a list of values, used to fill the simple list. If
26039 # 'undef', it's up to the calling function to add data
26040 # $editableFlag - Flag set to TRUE if columns containing boolean values should be
26041 # editable, FALSE if not
26042 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26043 # - The position of the simple list in the table
26044 #
26045 # Optional arguments
26046 # $width, $height - The width and height (in pixels) of the scroller containing the list.
26047 # If specified, values of -1 mean 'don't set this value'. The default
26048 # values are (-1, -1)
26049 #
26050 # Return values
26051 # 'undef' on improper arguments or if the widget's position in the Gtk3::Grid is invalid
26052 # Otherwise the GA::Obj::SimpleList created
26053  
26054 my (
26055 $self, $grid, $columnListRef, $dataRef, $editableFlag, $leftAttach, $rightAttach,
26056 $topAttach, $bottomAttach, $width, $height, $check,
26057 ) = @_;
26058  
26059 # Local variables
26060 my (
26061 $refType, $count,
26062 @columnList,
26063 );
26064  
26065 # Check for improper arguments
26066 if (
26067 ! defined $grid || ! defined $columnListRef || ! defined $editableFlag
26068 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
26069 || ! defined $bottomAttach || defined $check
26070 ) {
26071 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleList', @_);
26072 }
26073  
26074 # Check that the position in the table makes sense
26075 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26076  
26077 return undef;
26078 }
26079  
26080 # Set defaults
26081 if (! defined $width) {
26082  
26083 $width = -1; # Let Gtk3 set the width
26084 }
26085  
26086 if (! defined $height) {
26087  
26088 $height = -1; # Let Gtk3 set the height
26089 }
26090  
26091 # Dereference the list of columns
26092 @columnList = @$columnListRef;
26093  
26094 # Add a simple list
26095 my $frame = Gtk3::Frame->new(undef);
26096 $frame->set_border_width(0);
26097  
26098 my $scroller = Gtk3::ScrolledWindow->new();
26099 $frame->add($scroller);
26100 $scroller->set_shadow_type($axmud::CLIENT->constShadowType);
26101 $scroller->set_policy('automatic', 'automatic');
26102 $scroller->set_border_width(0);
26103 $scroller->set_size_request($width, $height);
26104  
26105 my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList);
26106 $scroller->add($slWidget);
26107  
26108 # No interactive searches required
26109 $slWidget->set_enable_search(FALSE);
26110  
26111 # Fill the columns with data (if any was provided)
26112 if (defined $dataRef) {
26113  
26114 if (ref($dataRef) eq 'HASH') {
26115  
26116 # Sort the hash by key, before adding it to the simple list
26117 $self->resetSortListData($slWidget, $dataRef);
26118  
26119 } else {
26120  
26121 # Assume that the list/hash IV can be displayed in its current order
26122 $self->resetListData($slWidget, $dataRef, (scalar @columnList / 2));
26123 }
26124 }
26125  
26126 # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, so
26127 # that the user can't click them on and off (if specified)
26128 if (! $editableFlag) {
26129  
26130 $count = -1;
26131 do {
26132  
26133 my $title = shift @columnList;
26134 my $type = shift @columnList;
26135  
26136 $count++;
26137  
26138 if ($type eq 'bool') {
26139  
26140 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
26141 $cellRenderer->set(activatable => FALSE);
26142 }
26143  
26144 } until (! @columnList);
26145 }
26146  
26147 # Add the simple list to the grid
26148 $frame->set_hexpand(TRUE);
26149 $frame->set_vexpand(TRUE);
26150 $grid->attach(
26151 $frame,
26152 $leftAttach,
26153 $topAttach,
26154 ($rightAttach - $leftAttach),
26155 ($bottomAttach - $topAttach),
26156 );
26157  
26158 return $slWidget;
26159 }
26160  
26161 sub addImage {
26162  
26163 # Adds a Gtk3::Image from a specified file, inside a frame (optionally using scrollbars) at
26164 # the specified position in a Gtk3::Grid
26165 #
26166 # Example calls:
26167 # my ($image, $frame, $viewPort) = $self->addImage($grid, $filePath, $pixBuffer, TRUE,
26168 # 128, 128,
26169 # 0, 12, 1, 12);
26170 # my ($image, $frame) = $self->addImage($grid, undef, undef, FALSE,
26171 # 128, 128,
26172 # 0, 12, 1, 12);
26173 #
26174 # Expected arguments
26175 # $grid - The Gtk3::Grid itself
26176 # $filePath - Full path to the file containing the image to be displayed (or 'undef'
26177 # if not using a file)
26178 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
26179 # if not using a pixbuf)
26180 # $scrollFlag - Flag set to TRUE if the image's viewport should use scrollbars,
26181 # FALSE if not
26182 # $width, $height - The size of the frame in which the image is shown (in pixels)
26183 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26184 # - The position of the frame in the table
26185 #
26186 # Return values
26187 # An empty list on improper arguments or if a $filePath is specified which doesn't exist
26188 # Otherwise returns a list in the form
26189 # (Gtk3_image, Gtk3_frame, Gtk3_viewport)
26190 # NB If neither $filePath nor $pixBuffer are specified, or if the Gtk3::Image can't be
26191 # created, the 'Gtk3_image' return value will be set to 'undef'
26192 # NB If $scrollFlag is FALSE, the 'Gtk3_viewport' return value will be set to 'undef'
26193  
26194 my (
26195 $self, $grid, $filePath, $pixBuffer, $scrollFlag, $width, $height, $leftAttach,
26196 $rightAttach, $topAttach, $bottomAttach, $check,
26197 ) = @_;
26198  
26199 # Local variables
26200 my @emptyList;
26201  
26202 # Check for improper arguments
26203 if (
26204 ! defined $grid || ! defined $scrollFlag || ! defined $width || ! defined $height
26205 || ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
26206 || ! defined $bottomAttach || defined $check
26207 ) {
26208 $axmud::CLIENT->writeImproper($self->_objClass . '->addImage', @_);
26209 return @emptyList;
26210 }
26211  
26212 # Check that the position in the table makes sense, and that filename (if specified) exists
26213 if (
26214 ! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)
26215 || (defined $filePath && ! -e $filePath)
26216 ) {
26217 return @emptyList;
26218 }
26219  
26220 # Create a frame
26221 my $frame = Gtk3::Frame->new(undef);
26222 $frame->set_border_width(3);
26223 $frame->set_size_request($width, $height);
26224  
26225 # Create the Gtk3::Image
26226 my $image;
26227 if ($filePath) {
26228 $image = Gtk3::Image->new_from_file($filePath);
26229 } elsif ($pixBuffer) {
26230 $image = Gtk3::Image->new_from_pixbuf($pixBuffer);
26231 }
26232  
26233 my $viewPort;
26234 if ($scrollFlag) {
26235  
26236 # Create a scrolled window
26237 my $scroller = Gtk3::ScrolledWindow->new();
26238 $scroller->set_border_width(3);
26239  
26240 # Create a viewport
26241 my $viewPort = Gtk3::Viewport->new(undef, undef);
26242  
26243 # If a Gtk3::Image was created, add it to the viewport
26244 if ($image) {
26245  
26246 $viewPort->add($image);
26247 }
26248  
26249 # Add the viewport to the scrolled window
26250 $scroller->add($viewPort);
26251 # Add the scrolled window to the frame
26252 $frame->add($scroller);
26253  
26254 } else {
26255  
26256 # If a Gtk3::Image was created, add it to the frame
26257 if ($image) {
26258  
26259 $frame->add($image);
26260 }
26261 }
26262  
26263 # Add the frame to the table (even if a Gtk3::Image wasn't created)
26264 $frame->set_hexpand(FALSE);
26265 $frame->set_vexpand(FALSE);
26266 $grid->attach(
26267 $frame,
26268 $leftAttach,
26269 $topAttach,
26270 ($rightAttach - $leftAttach),
26271 ($bottomAttach - $topAttach),
26272 );
26273  
26274 return ($image, $frame, $viewPort);
26275 }
26276  
26277 sub changeImage {
26278  
26279 # Changes the image shown as the result of a call to $self->addImage
26280 #
26281 # Expected arguments
26282 # (none besides $self)
26283 #
26284 # Optional arguments
26285 # $viewPort - The Gtk3::Viewport which contains the image ('undef' if no scrolling
26286 # viewport was used)
26287 # $frame - The Gtk3::Frame which contains the image ('undef' if a scrolling
26288 # viewport was used; ignored if $viewPort is defined)
26289 # $oldImage - The Gtk3::Image it currently contains. If it contains no image, set to
26290 # 'undef'
26291 # $filePath - Full path to the file containing the image to be displayed (or 'undef' if
26292 # not using a file)
26293 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
26294 # if not using a pixbuf)
26295 #
26296 # Return values
26297 # 'undef' on improper arguments, if the specified file doesn't exist or if a Gtk3::Image
26298 # can't be created
26299 # Otherwise returns the Gtk3::Image created, or 'undef' if none is created
26300  
26301 my ($self, $viewPort, $frame, $oldImage, $filePath, $pixBuffer, $check) = @_;
26302  
26303 # Check for improper arguments
26304 if ((! defined $viewPort && ! defined $frame) || defined $check) {
26305  
26306 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeImage', @_);
26307 }
26308  
26309 # Create a new Gtk3::Image
26310 my $newImage;
26311 if ($filePath) {
26312 $newImage = Gtk3::Image->new_from_file($filePath);
26313 } elsif ($pixBuffer) {
26314 $newImage = Gtk3::Image->new_from_pixbuf($pixBuffer);
26315 }
26316  
26317 if ($viewPort) {
26318  
26319 # Remove the old image from its viewport, if an old image was specified
26320 if ($oldImage) {
26321  
26322 $axmud::CLIENT->desktopObj->removeWidget($viewPort, $oldImage);
26323 }
26324  
26325 # Add the new image to the viewport, if a new image was created
26326 if ($newImage) {
26327  
26328 $viewPort->add($newImage);
26329 }
26330  
26331 } else {
26332  
26333 # Remove the old image from its frame, if an old image was specified
26334 if ($oldImage) {
26335  
26336 $axmud::CLIENT->desktopObj->removeWidget($frame, $oldImage);
26337 }
26338  
26339 # Add the new image to the frame, if a new image was created
26340 if ($newImage) {
26341  
26342 $frame->add($newImage);
26343 }
26344 }
26345  
26346 # Update the window to show the changes
26347 $self->winShowAll($self->_objClass . '->changeImage');
26348  
26349 return $newImage; # May be 'undef'
26350 }
26351  
26352 sub addSimpleImage {
26353  
26354 # Adds a Gtk3::Image from a specified file at the specified position in a Gtk3::Grid (but
26355 # not inside a frame: call ->addImage to do that)
26356 #
26357 # Example calls:
26358 # my $image = $self->addImage($grid, $filePath, $pixBuffer,
26359 # 0, 12, 1, 12);
26360 # my $image = $self->addImage($grid, undef, undef,
26361 # 0, 12, 1, 12);
26362 #
26363 # Expected arguments
26364 # $grid - The Gtk3::Grid itself
26365 # $filePath - Full path to the file containing the image to be displayed (or 'undef'
26366 # if not using a file)
26367 # $pixBuffer - A Gtk3::Gdk::Pixbuf containing the image to be displayed (or 'undef'
26368 # if not using a pixbuf)
26369 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26370 # - The position of the frame in the table
26371 #
26372 # Return values
26373 # 'undef' on improper arguments or if a $filePath is specified which doesn't exist
26374 # Otherwise the Gtk3::Image created
26375  
26376 my (
26377 $self, $grid, $filePath, $pixBuffer, $leftAttach, $rightAttach, $topAttach,
26378 $bottomAttach, $check,
26379 ) = @_;
26380  
26381 # Check for improper arguments
26382 if (
26383 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
26384 || ! defined $topAttach || ! defined $bottomAttach || defined $check
26385 ) {
26386 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleImage', @_);
26387 }
26388  
26389 # Check that the position in the table makes sense, and that filename (if specified) exists
26390 if (
26391 ! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)
26392 || (defined $filePath && ! -e $filePath)
26393 ) {
26394 return undef;
26395 }
26396  
26397 # Create the Gtk3::Image
26398 my $image;
26399 if ($filePath) {
26400 $image = Gtk3::Image->new_from_file($filePath);
26401 } elsif ($pixBuffer) {
26402 $image = Gtk3::Image->new_from_pixbuf($pixBuffer);
26403 }
26404  
26405 if ($image) {
26406  
26407 # Add the image to the grid
26408 $image->set_hexpand(FALSE);
26409 $image->set_vexpand(FALSE);
26410 $grid->attach(
26411 $image,
26412 $leftAttach,
26413 $topAttach,
26414 ($rightAttach - $leftAttach),
26415 ($bottomAttach - $topAttach),
26416 );
26417 }
26418  
26419 return $image;
26420 }
26421  
26422 sub addSimpleCanvas {
26423  
26424 # Adds a GooCanvas2::Canvas to the table which is painted using a single colour
26425 # Call $self->fillSimpleCanvas to change the colour. Use ->addDrawingCanvas for more
26426 # complex drawing operations
26427 #
26428 # Example calls:
26429 # my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid, '#FF0000', '#FFFFFF',
26430 # 6, 7, 6, 7,
26431 # 50, 50);
26432 # my ($frame, $canvas, $canvasObj) = $self->addSimpleCanvas($grid, 'red', undef,
26433 # 6, 7, 6, 7);
26434 #
26435 # Expected arguments
26436 # $grid - The Gtk3::Grid displayed in the current tab
26437 # $colour - The initial colour of the canvas. Can be any valid Axmud colour tag
26438 # (e.g. 'red', 'x255', '#FF0000')
26439 # $noColour - If $colour is not specified or if it is invalid, this colour is used.
26440 # If $noColour is also not specified or invalid, then no colour is
26441 # drawn (no canvas object is drawn on the canvas)
26442 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26443 # - The position of the canvas in the table
26444 #
26445 # Optional arguments
26446 # $width, $height - The size, in pixels, of the canvas. If not specified, a default size
26447 # is applied that should fill the containing frame (assuming a
26448 # Gtk3::Grid using horizontal rows)
26449 #
26450 # Return values
26451 # An empty list on improper arguments or if the table coordinates don't make sense
26452 # Otherwise, a list in the form
26453 # (Gtk3::Frame, GooCanvas2::Canvas, GooCanvas2::CanvasRect)
26454 # ...where the last value will be 'undef' if no colour was drawn
26455  
26456 my (
26457 $self, $grid, $colour, $noColour, $leftAttach, $rightAttach, $topAttach, $bottomAttach,
26458 $width, $height, $check
26459 ) = @_;
26460  
26461 # Local variables
26462 my (
26463 $type, $canvasObj,
26464 @emptyList,
26465 );
26466  
26467 # Check for improper arguments
26468 if (
26469 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
26470 || ! defined $topAttach || ! defined $bottomAttach || defined $check
26471 ) {
26472 $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleCanvas', @_);
26473 return @emptyList;
26474 }
26475  
26476 # Check that the position in table makes sense
26477 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26478  
26479 return @emptyList;
26480 }
26481  
26482 # Use default $colour/width/height, if not specified
26483 if ($colour) {
26484  
26485 ($type) = $axmud::CLIENT->checkColourTags($colour);
26486 }
26487  
26488 if (! $colour || ! $type ) {
26489  
26490 # Check the neutral colour
26491 if ($noColour) {
26492  
26493 ($type) = $axmud::CLIENT->checkColourTags($noColour);
26494 }
26495  
26496 if (! $type) {
26497  
26498 # No colour is drawn
26499 $colour = undef;
26500  
26501 } else {
26502  
26503 # Use the neutral colour
26504 $colour = $noColour;
26505 }
26506 }
26507  
26508 # Make sure we have an RGB tag, not a different kind of colour tag
26509 if ($colour) {
26510  
26511 $colour = $axmud::CLIENT->returnRGBColour($colour);
26512 }
26513  
26514 # Use default width/height, if values not specified
26515 if (! defined $width) {
26516  
26517 $width = 30;
26518 }
26519  
26520 if (! defined $height) {
26521  
26522 $height = 30;
26523 }
26524  
26525 # # Create a frame
26526 # my $frame = Gtk3::Frame->new(undef);
26527 # $frame->set_border_width(0);
26528 # $frame->set_size_request($width, $height);
26529 #
26530 # # Create the canvas
26531 # my $canvas = GooCanvas2::Canvas->new();
26532 # $frame->add($canvas);
26533 # $canvas->set_size_request($width, $height);
26534 # $canvas->set_bounds(0, 0, $width, $height);
26535  
26536 # Create the canvas
26537 my $canvas = GooCanvas2::Canvas->new();
26538 $canvas->set_size_request($width, $height);
26539 $canvas->set_bounds(0, 0, $width, $height);
26540  
26541 # An ugly hack to make sure the canvas is centred in its frame - put the canvas inside an
26542 # HBox and a VBox
26543 my $hBox =Gtk3::HBox->new();
26544 $hBox->pack_start($canvas, TRUE, FALSE, 0);
26545  
26546 my $vBox = Gtk3::VBox->new();
26547 $vBox->pack_start($hBox, TRUE, FALSE, 0);
26548  
26549 # Create a frame
26550 my $frame = Gtk3::Frame->new(undef);
26551 $frame->add($vBox);
26552 $frame->set_border_width(0);
26553 $frame->set_size_request($width, $height);
26554  
26555 # Add the frame to the table
26556 $frame->set_hexpand(FALSE);
26557 $frame->set_vexpand(FALSE);
26558 $grid->attach(
26559 $frame,
26560 $leftAttach,
26561 $topAttach,
26562 ($rightAttach - $leftAttach),
26563 ($bottomAttach - $topAttach),
26564 );
26565  
26566 # Fill the canvas with colour (if a colour was specified)
26567 if ($colour) {
26568  
26569 $canvasObj
26570 = $self->fillSimpleCanvas($canvas, undef, $colour, $noColour, $width, $height);
26571 }
26572  
26573 return ($frame, $canvas, $canvasObj);
26574 }
26575  
26576 sub fillSimpleCanvas {
26577  
26578 # Sets the background colour of the canvas drawn in the earlier call to
26579 # $self->addSimpleCanvas
26580 #
26581 # Expected arguments
26582 # $canvas - The existing GooCanvas2::Canvas
26583 #
26584 # Optional arguments
26585 # $oldObj - The existing GooCanvas2::CanvasRect, if there is one. Set to 'undef'
26586 # if this function is being called by $self->addSimpleCanvas, or if no
26587 # colour was drawn on the earlier call to ->addSimpleCanvas
26588 # $colour - The colour to draw on the canvas. Can be any valid Axmud colour tag
26589 # (e.g. 'red', 'x255', '#FF0000')
26590 # $noColour - If $colour is not specified or if it is invalid, this colour is used.
26591 # If $noColour is also not specified or invalid, then no colour is
26592 # drawn (no canvas object is drawn on the canvas)
26593 #
26594 # Optional arguments
26595 # $width, $height - The size, in pixels, of the canvas. If not specified, a default size
26596 # is applied that should fill the containing frame (assuming a
26597 # Gtk3::Grid using horizontal rows)
26598 #
26599 # Return values
26600 # 'undef' on improper arguments
26601 # The replacement GooCanvas2::CanvasRect otherwise
26602  
26603 my ($self, $canvas, $oldObj, $colour, $noColour, $width, $height, $check) = @_;
26604  
26605 # Local variables
26606 my ($type, $partX, $partY, $canvasObj);
26607  
26608 # Check for improper arguments
26609 if (! defined $canvas || defined $check) {
26610  
26611 return $axmud::CLIENT->writeImproper($self->_objClass . '->fillSimpleCanvas', @_);
26612 }
26613  
26614 # Use default $colour/width/height, if not specified
26615 if ($colour) {
26616  
26617 ($type) = $axmud::CLIENT->checkColourTags($colour);
26618 }
26619  
26620 if (! $colour || ! $type ) {
26621  
26622 # Check the neutral colour
26623 if ($noColour) {
26624  
26625 ($type) = $axmud::CLIENT->checkColourTags($noColour);
26626 }
26627  
26628 if (! $type) {
26629  
26630 # No colour is drawn
26631 $colour = undef;
26632  
26633 } else {
26634  
26635 # Use the neutral colour
26636 $colour = $noColour;
26637 }
26638 }
26639  
26640 # Make sure we have an RGB tag, not a different kind of colour tag
26641 if ($colour) {
26642  
26643 $colour = $axmud::CLIENT->returnRGBColour($colour);
26644 }
26645  
26646 # Use default width/height, if values not specified
26647 if (! defined $width) {
26648  
26649 $width = 30;
26650 }
26651  
26652 if (! defined $height) {
26653  
26654 $height = 30;
26655 }
26656  
26657 # Destroy the old background rectangle, if there is one
26658 if ($oldObj) {
26659  
26660 $oldObj->remove();
26661 }
26662  
26663 # Draw the canvas object (if a colour was specified)
26664 if ($colour) {
26665  
26666 $canvasObj = GooCanvas2::CanvasRect->new(
26667 'parent' => $canvas->get_root_item(),
26668 'x' => 0,
26669 'y' => 0,
26670 'width' => $width,
26671 'height' => $height,
26672 # 'line-width' => 2,
26673 'stroke-color' => $colour,
26674 'fill-color' => $colour,
26675 );
26676  
26677 $canvasObj->lower();
26678 }
26679  
26680 # Drawing complete
26681 return $canvasObj;
26682 }
26683  
26684 sub addDrawingCanvas {
26685  
26686 # Adds a GooCanvas2::Canvas to the table for general drawing operations. For painting a
26687 # canvas as a single colour, use $self->addSimpleCanvas instead
26688 #
26689 # Example calls:
26690 # $self->addDrawingCanvas($grid,
26691 # undef, undef,
26692 # FALSE, FALSE,
26693 # 0, 12, 1, 12);
26694 # $self->addDrawingCanvas($grid,
26695 # 'motionFunc', 'clickFunc',
26696 # TRUE, TRUE,
26697 # 0, 12, 1, 12,
26698 # 500, 500);
26699 #
26700 # Expected arguments
26701 # $grid - The tab's Gtk3::Grid object
26702 # $clickFunc - A function to call whenever the user clicks on the canvas (which emits
26703 # the 'button-press-event' signal). If 'undef', the signal is ignored
26704 # ignored
26705 # $motionFunc - A function to call whenever mouse motion over the canvas is detected
26706 # which emits the 'motion-notify-event' signal). If 'undef', the
26707 # signal is ignored
26708 # $scrollHorizFlag, $scrollVertFlag
26709 # - Flags set to TRUE if the scolled window, in which the canvas appears,
26710 # scrolls; set to FALSE (or 'undef') otherwise
26711 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26712 # - The position of the canvas in the table
26713 #
26714 # Optional arguments
26715 # $width, $height - The width and height of the canvas, in pixels. If not specified,
26716 # a default size of 300x200 is used
26717 #
26718 # Return values
26719 # 'undef' on improper arguments, or if a drawing canvas can't be created
26720 # Otherwise returns the GooCanvas2::Canvas created
26721  
26722 my (
26723 $self, $grid, $clickFunc, $motionFunc, $scrollHorizFlag, $scrollVertFlag, $leftAttach,
26724 $rightAttach, $topAttach, $bottomAttach, $width, $height, $check
26725 ) = @_;
26726  
26727 # Check for improper arguments
26728 if (
26729 ! defined $grid || ! defined $leftAttach || ! defined $rightAttach
26730 || ! defined $topAttach || ! defined $bottomAttach || defined $check
26731 ) {
26732 return $axmud::CLIENT->writeImproper($self->_objClass . '->addDrawingCanvas', @_);
26733 }
26734  
26735 # Check that the position in the table makes sense
26736 if (! $self->checkPosn($leftAttach, $rightAttach, $topAttach, $bottomAttach)) {
26737  
26738 return undef;
26739 }
26740  
26741 # Set default width/height, if necessary
26742 if (! defined $width) {
26743  
26744 $width = 300;
26745 }
26746  
26747 if (! defined $height) {
26748  
26749 $height = 200;
26750 }
26751  
26752 # Create a frame containing a scrolled window
26753 my $frame = Gtk3::Frame->new(undef);
26754 $frame->set_shadow_type($axmud::CLIENT->constShadowType);
26755  
26756 my $scrolledWin = Gtk3::ScrolledWindow->new();
26757 $frame->add($scrolledWin);
26758 $scrolledWin->set_size_request($width, $height);
26759 $scrolledWin->set_border_width(3);
26760  
26761 my $viewPort = Gtk3::Viewport->new(undef,undef);
26762 $scrolledWin->add($viewPort);
26763  
26764 # Set its scrolling policy
26765 if ($scrollHorizFlag && $scrollVertFlag) {
26766 $scrolledWin->set_policy('always','always');
26767 } elsif ($scrollHorizFlag) {
26768 $scrolledWin->set_policy('always', 'never');
26769 } elsif ($scrollVertFlag) {
26770 $scrolledWin->set_policy('never', 'always');
26771 } else {
26772 $scrolledWin->set_policy('never', 'never');
26773 }
26774  
26775 # Add the frame to the table
26776 $frame->set_hexpand(FALSE);
26777 $frame->set_vexpand(FALSE);
26778 $grid->attach(
26779 $frame,
26780 $leftAttach,
26781 $topAttach,
26782 ($rightAttach - $leftAttach),
26783 ($bottomAttach - $topAttach),
26784 );
26785  
26786 # Create the GooCanvas2 inside an event box (to detect the user's mouse)
26787 my $eventBox = Gtk3::EventBox->new();
26788 $viewPort->add($eventBox);
26789 $eventBox->add_events(['pointer-motion-mask', 'pointer-motion-hint-mask']);
26790  
26791 my $canvasWidget = GooCanvas2::Canvas->new();
26792 $eventBox->add($canvasWidget);
26793 $canvasWidget->set_size_request($width, $height);
26794 $canvasWidget->set_bounds(0, 0, $width, $height);
26795  
26796 # Detect mouse clicks over the drawing area
26797 $eventBox->signal_connect ('button-press-event' => sub {
26798  
26799 my ($widget, $event) = @_;
26800  
26801 if (! $clickFunc) {
26802  
26803 return undef;
26804  
26805 } else {
26806  
26807 # Inform the specified function of the co-ords of the mouse above the canvas
26808 return $self->$clickFunc($event->x, $event->y);
26809 }
26810 });
26811  
26812 # Detect mouse motion over the drawing area
26813 $eventBox->signal_connect ('motion-notify-event' => sub {
26814  
26815 my ($widget, $event) = @_;
26816  
26817 if (! $motionFunc) {
26818  
26819 return undef;
26820  
26821 } else {
26822  
26823 # Inform the specified function of the co-ords of the mouse above the canvas
26824 return $self->$motionFunc($event->x, $event->y);
26825 }
26826 });
26827  
26828 return $canvasWidget;
26829 }
26830  
26831 # Support functions for adding widgets
26832  
26833 sub checkPosn {
26834  
26835 # Called by $self->addLabel, etc
26836 # Checks the position of a widget in the Gtk3::Grid, to make sure the coordinates make
26837 # sense (that the right coordinate isn't lower than the left coordinate, for example)
26838 #
26839 # Expected arguments
26840 # $leftAttach, $rightAttach, $topAttach, $bottomAttach
26841 # - The coordinates of the object in the page's table
26842 #
26843 # Return values
26844 # 'undef' on improper arguments or if the coordinates don't make sense
26845 # 1 otherwise
26846  
26847 my ($self, $leftAttach, $rightAttach, $topAttach, $bottomAttach, $check) = @_;
26848  
26849 # Check for improper arguments
26850 if (
26851 ! defined $leftAttach || ! defined $rightAttach || ! defined $topAttach
26852 || ! defined $bottomAttach || defined $check
26853 ) {
26854 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPosn', @_);
26855 }
26856  
26857 # Check coordinates
26858 if (
26859 $leftAttach < 0 || $topAttach < 0
26860 || $rightAttach < $leftAttach || $bottomAttach < $topAttach
26861 ) {
26862 return $self->writeWarning(
26863 'Bad table coordinates in \'' . $self->winType . '\' window: '
26864 . $leftAttach . ' '
26865 . $rightAttach . ' '
26866 . $topAttach . ' '
26867 . $bottomAttach,
26868 $self->_objClass . '->checkPosn',
26869 );
26870  
26871 } else {
26872  
26873 return 1;
26874 }
26875 }
26876  
26877 # Data accessors
26878  
26879 sub resetListData {
26880  
26881 # Replaces the data stored in a GA::Obj::SimpleList with the data stored in the specified
26882 # list
26883 #
26884 # Expected arguments
26885 # $slWidget - Reference to a GA::Obj::SimpleList
26886 # $listRef - Reference to a list which contains the replacement data
26887 # $number - The list is split into groups (e.g. the elements of
26888 # GA::Profile::World->barPatternList are split into groups of 6); $number
26889 # is the size of the group (6 in that example)
26890 #
26891 # Return values
26892 # 'undef' on improper arguments
26893 # 1 otherwise
26894  
26895 my ($self, $slWidget, $listRef, $number, $check) = @_;
26896  
26897 # Local variables
26898 my @dataList;
26899  
26900 # Check for improper arguments
26901 if (! defined $slWidget || ! defined $listRef || ! defined $number || defined $check) {
26902  
26903 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetListData_listIV', @_);
26904 }
26905  
26906 if (@$listRef) {
26907  
26908 # Insert the replacement data
26909 do {
26910  
26911 my @groupList;
26912  
26913 for (my $count = 0; $count < $number; $count++) {
26914  
26915 push (@groupList, shift @$listRef);
26916 }
26917  
26918 push (@dataList, \@groupList);
26919  
26920 } until (! @$listRef);
26921  
26922 @{$slWidget->{data}} = @dataList;
26923  
26924 } else {
26925  
26926 # Replacement data list is empty
26927 @{$slWidget->{data}} = ();
26928 }
26929  
26930 return 1;
26931 }
26932  
26933 sub resetSortListData {
26934  
26935 # Replaces the data stored in a GA::Obj::SimpleList with the data stored in the specified
26936 # list which we assume represents a hash in the form (key, value, key, value...)
26937 #
26938 # Expected arguments
26939 # $slWidget - Reference to a GA::Obj::SimpleList
26940 # $listRef - Reference to a list which contains the replacement data
26941 #
26942 # Return values
26943 # 'undef' on improper arguments
26944 # 1 otherwise
26945  
26946 my ($self, $slWidget, $listRef, $check) = @_;
26947  
26948 # Local variables
26949 my (
26950 @dataList,
26951 %hash,
26952 );
26953  
26954 # Check for improper arguments
26955 if (! defined $slWidget || ! defined $listRef || defined $check) {
26956  
26957 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetSortListData', @_);
26958 }
26959  
26960 if (@$listRef) {
26961  
26962 # Assuming the contents of the list reference contains a hash flattened into a list,
26963 # convert that data to a hash
26964 %hash = @$listRef;
26965  
26966 # Insert the replacement data
26967 foreach my $key (sort {lc($a) cmp lc($b)} (keys %hash)) {
26968  
26969 push (@dataList, [$key, $hash{$key}]);
26970 }
26971  
26972 @{$slWidget->{data}} = @dataList;
26973  
26974 } else {
26975  
26976 # Replacement data list is empty
26977 @{$slWidget->{data}} = ();
26978 }
26979  
26980 return 1;
26981 }
26982  
26983 sub getSimpleListData {
26984  
26985 # Get items of data from specified cells in the currently selected row of a simple list
26986 #
26987 # Expected arguments
26988 # $slWidget - The GA::Obj::SimpleList
26989 # @columnList - A list of column numbers on the simple list, e.g. the list (0, 2, 3)
26990 # represents the first, third and fourth columns.
26991 #
26992 # Return values
26993 # An empty list on improper arguments or if no row in the simple list is currently
26994 # selected
26995 # Otherwise, returns a list containing the items of data on the selected row, in the
26996 # specified columns
26997  
26998 my ($self, $slWidget, @columnList) = @_;
26999  
27000 # Local variables
27001 my (
27002 $index, $rowRef,
27003 @emptyList, @dataList,
27004 );
27005  
27006 # Check for improper arguments
27007 if (! defined $slWidget || ! @columnList) {
27008  
27009 $axmud::CLIENT->writeImproper($self->_objClass . '->getSimpleListData', @_);
27010 return @emptyList;
27011 }
27012  
27013 # Get the currently selected row's number (if any)
27014 ($index) = $slWidget->get_selected_indices();
27015 if (defined $index) {
27016  
27017 # Get the selected row itself
27018 $rowRef = ${$slWidget->{data}}[$index];
27019  
27020 # Get items of data from this row
27021 foreach my $column (@columnList) {
27022  
27023 push (@dataList, $$rowRef[$column]);
27024 }
27025 }
27026  
27027 return @dataList;
27028 }
27029  
27030 ##################
27031 # Accessors - set
27032  
27033 sub add_childDestroy {
27034  
27035 # Called by anything
27036  
27037 my ($self, $winObj, $func, $argListRef, $check) = @_;
27038  
27039 # Local variables
27040 my $listRef;
27041  
27042 # Check for improper arguments
27043 if (! defined $winObj || ! defined $func || ! defined $argListRef || defined $check) {
27044  
27045 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_childDestroy', @_);
27046 }
27047  
27048 if (! $self->ivExists('childFreeWinHash', $winObj->number)) {
27049  
27050 return undef;
27051  
27052 } else {
27053  
27054 if ($self->ivExists('childDestroyHash', $winObj->number)) {
27055  
27056 $listRef = $self->ivShow('childDestroyHash', $winObj->number);
27057 push (@$listRef, $func, $argListRef);
27058  
27059 } else {
27060  
27061 $self->ivAdd(
27062 'childDestroyHash',
27063 $winObj->number,
27064 [$func, $argListRef],
27065 );
27066 }
27067  
27068 return 1;
27069 }
27070 }
27071  
27072 sub add_childFreeWin {
27073  
27074 # Called by $self->createFreeWin
27075  
27076 my ($self, $obj, $check) = @_;
27077  
27078 # Check for improper arguments
27079 if (! defined $obj || defined $check) {
27080  
27081 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_childFreeWin', @_);
27082 }
27083  
27084 $self->ivAdd('childFreeWinHash', $obj->number, $obj);
27085  
27086 return 1;
27087 }
27088  
27089 sub del_childFreeWin {
27090  
27091 # Called by GA::Generic::FreeWin->winDestroy
27092  
27093 my ($self, $obj, $check) = @_;
27094  
27095 # Local variables
27096 my $listRef;
27097  
27098 # Check for improper arguments
27099 if (! defined $obj || defined $check) {
27100  
27101 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_childFreeWin', @_);
27102 }
27103  
27104 if (! $self->ivExists('childFreeWinHash', $obj->number)) {
27105  
27106 return undef;
27107  
27108 } else {
27109  
27110 # Call some of this window's own functions to obj->number various widgets/IVs
27111 $listRef = $self->ivShow('childDestroyHash', $obj->number);
27112 if (defined $listRef) {
27113  
27114 do {
27115  
27116 my ($func, $argListRef);
27117  
27118 $func = shift @$listRef;
27119 $argListRef = shift @$listRef;
27120  
27121 if (defined $func && defined $argListRef) {
27122  
27123 $self->$func(@$argListRef);
27124 }
27125  
27126 } until (! @$listRef);
27127 }
27128  
27129 # Update IVs
27130 $self->ivDelete('childFreeWinHash', $obj->number);
27131 $self->ivDelete('childDestroyHash', $obj->number);
27132  
27133 return 1;
27134 }
27135 }
27136  
27137 sub set_enabledFlag {
27138  
27139 my ($self, $flag, $check) = @_;
27140  
27141 # Check for improper arguments
27142 if (! defined $flag || defined $check) {
27143  
27144 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_);
27145 }
27146  
27147 if ($flag) {
27148 $self->ivPoke('enabledFlag', TRUE);
27149 } else {
27150 $self->ivPoke('enabledFlag', FALSE);
27151 }
27152  
27153 return 1;
27154 }
27155  
27156 sub set_owner {
27157  
27158 my ($self, $owner, $check) = @_;
27159  
27160 # Check for improper arguments
27161 if (defined $check) {
27162  
27163 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_owner', @_);
27164 }
27165  
27166 $self->ivPoke('owner', $owner);
27167  
27168 return 1;
27169 }
27170  
27171 sub set_session {
27172  
27173 my ($self, $session, $check) = @_;
27174  
27175 # Check for improper arguments
27176 if (defined $check) {
27177  
27178 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_session', @_);
27179 }
27180  
27181 $self->ivPoke('session', $session);
27182  
27183 return 1;
27184 }
27185  
27186 sub set_winBox {
27187  
27188 my ($self, $winBox, $check) = @_;
27189  
27190 # Check for improper arguments
27191 if (defined $check) {
27192  
27193 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winBox', @_);
27194 }
27195  
27196 $self->ivPoke('winBox', $winBox);
27197  
27198 return 1;
27199 }
27200  
27201 sub set_winWidget {
27202  
27203 my ($self, $winWidget, $check) = @_;
27204  
27205 # Check for improper arguments
27206 if (defined $check) {
27207  
27208 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winWidget', @_);
27209 }
27210  
27211 $self->ivPoke('winWidget', $winWidget);
27212  
27213 return 1;
27214 }
27215  
27216 sub set_workspaceObj {
27217  
27218 my ($self, $workspaceObj, $check) = @_;
27219  
27220 # Check for improper arguments
27221 if (! defined $workspaceObj || defined $check) {
27222  
27223 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceObj', @_);
27224 }
27225  
27226 $self->ivPoke('workspaceObj', $workspaceObj);
27227  
27228 return 1;
27229 }
27230  
27231 sub set_workspaceGridObj {
27232  
27233 my ($self, $gridObj, $check) = @_;
27234  
27235 # Check for improper arguments
27236 if (! defined $gridObj || defined $check) {
27237  
27238 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_workspaceGridObj', @_);
27239 }
27240  
27241 $self->ivPoke('workspaceGridObj', $gridObj);
27242  
27243 return 1;
27244 }
27245  
27246 ##################
27247 # Accessors - get
27248  
27249 sub number
27250 { $_[0]->{number} }
27251 sub winCategory
27252 { $_[0]->{winCategory} }
27253 sub winType
27254 { $_[0]->{winType} }
27255 sub winName
27256 { $_[0]->{winName} }
27257 sub workspaceObj
27258 { $_[0]->{workspaceObj} }
27259 sub owner
27260 { $_[0]->{owner} }
27261 sub session
27262 { $_[0]->{session} }
27263 sub pseudoCmdMode
27264 { $_[0]->{pseudoCmdMode} }
27265  
27266 sub winWidget
27267 { $_[0]->{winWidget} }
27268 sub winBox
27269 { $_[0]->{winBox} }
27270 sub enabledFlag
27271 { $_[0]->{enabledFlag} }
27272 sub visibleFlag
27273 { $_[0]->{visibleFlag} }
27274 sub childFreeWinHash
27275 { my $self = shift; return %{$self->{childFreeWinHash}}; }
27276 sub childDestroyHash
27277 { my $self = shift; return %{$self->{childDestroyHash}}; }
27278  
27279 sub packingBox
27280 { $_[0]->{packingBox} }
27281 }
27282  
27283 { package Games::Axmud::Generic::WizWin;
27284  
27285 use strict;
27286 use warnings;
27287 use diagnostics;
27288  
27289 use Glib qw(TRUE FALSE);
27290  
27291 our @ISA = qw(
27292 Games::Axmud::Generic::FreeWin Games::Axmud::Generic::Win Games::Axmud
27293 );
27294  
27295 ##################
27296 # Constructors
27297  
27298 sub new {
27299  
27300 # Called by GA::Generic::Win->createFreeWin
27301 # Creates a new instance of a 'wiz' window
27302 #
27303 # Expected arguments
27304 # $number - Unique number for this window object
27305 # $workspaceObj - The GA::Obj::Workspace handling the workspace in which this window
27306 # should be created
27307 # $owner - The owner; a 'grid' window object (but not an 'external' window) or a
27308 # 'free' window object. When this window opens/closes, the owner is
27309 # informed via calls to its ->add_childFreeWin / ->del_childFreeWin
27310 # functions
27311 #
27312 # Optional arguments
27313 # $session - The GA::Session from which this function was called. 'undef' if the
27314 # calling function didn't specify a session and $owner's ->session IV
27315 # is also 'undef'
27316 # $title - A string to use as the window title. If 'undef', a generic title is
27317 # used
27318 # $editObj - Ignored if set
27319 # $tempFlag - Ignored if set
27320 # %configHash - Hash containing any number of key-value pairs needed for this
27321 # particular 'wiz' window; for example, for example,
27322 # GA::PrefWin::TaskStart uses it to specify a task name and type. Set
27323 # to an empty hash if not required
27324 # - This type of window object recognises these initialisation settings:
27325 #
27326 # ...
27327 #
27328 # Return values
27329 # 'undef' on improper arguments
27330 # Blessed reference to the newly-created object on success
27331  
27332 my (
27333 $class, $number, $workspaceObj, $owner, $session, $title, $editObj, $tempFlag,
27334 %configHash,
27335 ) = @_;
27336  
27337 # Check for improper arguments
27338 if (! defined $class || ! defined $number || ! defined $workspaceObj || ! defined $owner) {
27339  
27340 return $axmud::CLIENT->writeImproper($class . '->new', @_);
27341 }
27342  
27343 # Set the values to use for some standard window IVs
27344 if (! $title) {
27345  
27346 $title = 'Wizard window';
27347 }
27348  
27349 # Setup
27350 my $self = {
27351 _objName => 'wiz_win_' . $number,
27352 _objClass => $class,
27353 _parentFile => undef, # No parent file object
27354 _parentWorld => undef, # No parent file object
27355 _privFlag => TRUE, # All IVs are private
27356  
27357 # Standard window object IVs
27358 # --------------------------
27359  
27360 # Unique number for this window object
27361 number => $number,
27362 # The window category - 'grid' or 'free'
27363 winCategory => 'free',
27364 # The window type, any of the keys in GA::Client->constFreeWinTypeHash
27365 winType => 'wiz',
27366 # A name for the window (for 'config' windows, the same as the window type)
27367 winName => 'wiz',
27368 # The GA::Obj::Workspace object for the workspace in which this window is created
27369 workspaceObj => $workspaceObj,
27370 # The owner; a 'grid' window object (but not an 'external' window) or a 'free' window
27371 # object. When this window opens/closes, the owner is informed via calls to its
27372 # ->add_childFreeWin / ->del_childFreeWin functions
27373 owner => $owner,
27374 # The GA::Session from which this function was called. 'undef' if the calling function
27375 # didn't specify a session and $owner's ->session IV is also 'undef'
27376 session => $session,
27377 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
27378 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
27379 # displayed in a 'dialogue' window)
27380 pseudoCmdMode => 'win_error',
27381  
27382 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
27383 # parent 'main' window's Gtk3::Window
27384 # The code should use this IV when it wants to do something to the window itself
27385 # (minimise it, make it active, etc)
27386 winWidget => undef,
27387 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
27388 # the parent GA::Table::PseudoWin table object
27389 # The code should use this IV when it wants to add, modify or remove widgets inside the
27390 # window itself
27391 winBox => undef,
27392 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
27393 # FALSE if not
27394 enabledFlag => FALSE,
27395 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
27396 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
27397 visibleFlag => TRUE,
27398 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
27399 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
27400 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
27401 childFreeWinHash => {},
27402 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
27403 # window is informed via a call to $self->del_childFreeWin
27404 # When the child is destroyed, this window might want to call some of its own functions
27405 # to update various widgets and/or IVs, in which case this window adds an entry to
27406 # this hash; a hash in the form
27407 # $childDestroyHash{unique_number} = list_reference
27408 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
27409 # reference to a list in groups of 2, in the form
27410 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
27411 childDestroyHash => {},
27412  
27413 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
27414 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
27415 # area)
27416 packingBox => undef, # Gtk3::VBox
27417  
27418 # Standard IVs for 'free' windows
27419  
27420 # The window's default size, in pixels
27421 widthPixels => $axmud::CLIENT->customFreeWinWidth,
27422 heightPixels => $axmud::CLIENT->customFreeWinHeight,
27423 # Default border/item spacing sizes used in the window, in pixels
27424 borderPixels => $axmud::CLIENT->constFreeBorderPixels,
27425 spacingPixels => $axmud::CLIENT->constFreeSpacingPixels,
27426  
27427 # A string to use as the window title. If 'undef', a generic title is used
27428 title => $title,
27429 # Hash containing any number of key-value pairs needed for this particular 'wiz'
27430 # window; for example, for example, GA::PrefWin::TaskStart uses it to specify a task
27431 # name and type. Set to an empty hash if not required
27432 configHash => {%configHash},
27433  
27434 # Standard IVs for 'wiz' windows
27435  
27436 # Widgets
27437 scroller => undef, # Gtk3::ScrolledWindow
27438 hAdjustment => undef, # Gtk3::Adjustment
27439 vAdjustment => undef, # Gtk3::Adjustment
27440 grid => undef, # Gtk3::Grid
27441 hBox => undef, # Gtk3::HBox
27442 nextButton => undef, # Gtk3::Button
27443 previousButton => undef, # Gtk3::Button
27444 cancelButton => undef, # Gtk3::Button
27445  
27446 # Three flags that can be set by any page, to prevent one of three buttons from being
27447 # made sensitive (temporarily)
27448 disableNextButtonFlag => FALSE,
27449 disablePreviousButtonFlag => FALSE,
27450 disableCancelButtonFlag => FALSE,
27451  
27452 # The names of pages, in order of appearance
27453 pageList => [
27454 # 'example', # Corresponds to function $self->examplePage
27455 # 'example2',
27456 # 'example3',
27457 ],
27458 # The number of the current page (first page is 0)
27459 currentPage => 0,
27460  
27461 # Two hashes for using the 'Next' / 'Previous' buttons to skip around the pages, rather
27462 # than going to the actual next or previous page (as normal)
27463 # The current page should add an entry to the hash, if necessary; the entry is removed
27464 # by ->buttonPrevious or ->buttonNext as soon as either button is clicked
27465 # Hashes in the form
27466 # $hash{current_page_number} = page_number_if_button_clicked
27467 # NB The first page's number is 0, so the fourth page will be page 3, not page 4
27468 specialNextButtonHash => {},
27469 specialPreviousButtonHash => {},
27470 };
27471  
27472 # Bless the object into existence
27473 bless $self, $class;
27474  
27475 return $self;
27476 }
27477  
27478 ##################
27479 # Methods
27480  
27481 # Standard window object functions
27482  
27483 # sub winSetup {} # Inherited from GA::Generic::FreeWin
27484  
27485 sub winEnable {
27486  
27487 # Called by GA::Generic::Win->createFreeWin, after the call to $self->winSetup
27488 # After the Gtk3::Window has been setup and moved into position, makes it visible
27489 #
27490 # Expected arguments
27491 # (none besides $self)
27492 #
27493 # Return values
27494 # 'undef' on improper arguments
27495 # 1 on success
27496  
27497 my ($self, $check) = @_;
27498  
27499 # Check for improper arguments
27500 if (defined $check) {
27501  
27502 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
27503 }
27504  
27505 # Make the window appear on the desktop
27506 $self->winShowAll($self->_objClass . '->winEnable');
27507 $self->ivPoke('enabledFlag', TRUE);
27508  
27509 # This type of window is usually unique to its GA::Session (only one can be open at any
27510 # time, per session); inform the session it has opened
27511 # Exception - if $self->session isn't set at all (presumably because there are no sessions
27512 # running), then there's no-one to inform
27513 if ($self->session) {
27514  
27515 $self->session->set_wizWin($self);
27516 }
27517  
27518 return 1;
27519 }
27520  
27521 # sub winDesengage {} # Inherited from GA::Generic::FreeWin
27522  
27523 sub winDestroy {
27524  
27525 # Can be called by anything
27526 # Updates IVs
27527 #
27528 # Expected arguments
27529 # (none besides $self)
27530 #
27531 # Return values
27532 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
27533 # been destroyed
27534 # 1 on success
27535  
27536 my ($self, $check) = @_;
27537  
27538 # Check for improper arguments
27539 if (defined $check) {
27540  
27541 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
27542 }
27543  
27544 if (! $self->winBox) {
27545  
27546 # Window already destroyed in a previous call to this function
27547 return undef;
27548 }
27549  
27550 # Close any 'free' windows for which this window is a parent
27551 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
27552  
27553 $winObj->winDestroy();
27554 }
27555  
27556 # Destroy the Gtk3::Window
27557 eval { $self->winBox->destroy(); };
27558 if ($@) {
27559  
27560 # Window can't be destroyed
27561 return undef;
27562  
27563 } else {
27564  
27565 $self->ivUndef('winWidget');
27566 $self->ivUndef('winBox');
27567 }
27568  
27569 # Inform the owner and the desktop object of this 'free' window's demise
27570 $axmud::CLIENT->desktopObj->del_freeWin($self);
27571 if ($self->owner) {
27572  
27573 $self->owner->del_childFreeWin($self);
27574 }
27575  
27576 # This type of window is usually unique to its GA::Session (only one can be open at any
27577 # time, per session); inform the session it has closed
27578 # Exception - if $self->session isn't set at all (presumably because there are no sessions
27579 # running), then there's no-one to inform
27580 if ($self->session) {
27581  
27582 $self->session->set_wizWin();
27583 }
27584  
27585 return 1;
27586 }
27587  
27588 # sub winShowAll {} # Inherited from GA::Generic::Win
27589  
27590 sub drawWidgets {
27591  
27592 # Called by $self->winSetup
27593 # Sets up the 'wiz' window with its standard widgets
27594 #
27595 # Expected arguments
27596 # (none besides $self)
27597 #
27598 # Return values
27599 # 'undef' on improper arguments
27600 # 1 otherwise
27601  
27602 my ($self, $check) = @_;
27603  
27604 # Check for improper arguments
27605 if (defined $check) {
27606  
27607 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
27608 }
27609  
27610 # Create a packing box
27611 my $packingBox = Gtk3::VBox->new(FALSE, 0);
27612 $self->winBox->add($packingBox);
27613 $packingBox->set_border_width(0);
27614  
27615 # Add a grid (inside a scrolled window) in the higher area
27616 my $frame = Gtk3::Frame->new(undef);
27617 $packingBox->pack_start($frame, TRUE, TRUE, 0);
27618 $frame->set_border_width($self->spacingPixels);
27619  
27620 my $scroller = Gtk3::ScrolledWindow->new(undef, undef);
27621 $frame->add($scroller);
27622 $scroller->set_policy('automatic', 'automatic');
27623 $scroller->set_border_width(0);
27624  
27625 my $grid = Gtk3::Grid->new();
27626 $scroller->add_with_viewport($grid);
27627 $grid->set_column_spacing($self->spacingPixels);
27628 $grid->set_row_spacing($self->spacingPixels);
27629 $grid->set_border_width($self->borderPixels);
27630  
27631 # Add a button strip at the bottom, in a horizontal packing box
27632 my $hBox = Gtk3::HBox->new(FALSE, 0);
27633 $packingBox->pack_end($hBox, FALSE, FALSE, 5);
27634  
27635 # Create 'Next'/'Previous'/'Cancel' buttons
27636 my ($nextButton, $previousButton, $cancelButton) = $self->enableButtons($hBox);
27637  
27638 # Update IVs
27639 $self->ivPoke('packingBox', $packingBox);
27640 $self->ivPoke('scroller', $scroller);
27641 $self->ivPoke('hAdjustment', $scroller->get_hadjustment());
27642 $self->ivPoke('vAdjustment', $scroller->get_vadjustment());
27643 $self->ivPoke('grid', $grid);
27644 $self->ivPoke('hBox', $hBox);
27645 $self->ivPoke('nextButton', $nextButton);
27646 $self->ivPoke('previousButton', $previousButton);
27647 $self->ivPoke('cancelButton', $cancelButton);
27648  
27649 # Set up the grid with its initial contents
27650 $self->setupGrid();
27651  
27652 return 1;
27653 }
27654  
27655 # sub redrawWidgets {} # Inherited from GA::Generic::Win
27656  
27657 # ->signal_connects
27658  
27659 # Other functions
27660  
27661 sub enableButtons {
27662  
27663 # Called by $self->drawWidgets
27664 # Creates the Next/Previous/Cancel buttons at the bottom of the window
27665 # Individual 'wiz' windows almost always inherit the generic ->winEnable method, but can
27666 # use their own $self->enableButtons (rather than inherit this one) if they need
27667 # a different set of buttons
27668 #
27669 # Expected arguments
27670 # $hBox - The horizontal packing box in which the buttons live (not yet stored as
27671 # an IV)
27672 #
27673 # Return values
27674 # An empty list on improper arguments
27675 # Otherwise, a list containing the three Gtk::Button objects created
27676  
27677 my ($self, $hBox, $check) = @_;
27678  
27679 # Local variables
27680 my @emptyList;
27681  
27682 # Check for improper arguments
27683 if (! defined $hBox || defined $check) {
27684  
27685 $axmud::CLIENT->writeImproper($self->_objClass . '->enableButtons', @_);
27686 return @emptyList;
27687 }
27688  
27689 # Create the Next button - which also acts as a 'Finish' button once the user has
27690 # finished making changes
27691 my $nextButton = Gtk3::Button->new('Next');
27692 $hBox->pack_end($nextButton, FALSE, FALSE, $self->borderPixels);
27693 $nextButton->get_child->set_width_chars(10);
27694 $nextButton->signal_connect('clicked' => sub {
27695  
27696 $self->buttonNext();
27697 });
27698 $nextButton->set_tooltip_text('Move on to the next page');
27699  
27700 # Create the Previous button
27701 my $prevButton = Gtk3::Button->new('Previous');
27702 $hBox->pack_end($prevButton, FALSE, FALSE, $self->spacingPixels);
27703 $prevButton->get_child->set_width_chars(10);
27704 $prevButton->signal_connect('clicked' => sub {
27705  
27706 $self->buttonPrevious();
27707 });
27708 $prevButton->set_tooltip_text('Go back to the previous page');
27709 $prevButton->set_sensitive(FALSE); # Because 1st page is showing, starts desensitised
27710  
27711 # Create the Cancel button
27712 my $cancelButton = Gtk3::Button->new('Cancel');
27713 $hBox->pack_start($cancelButton, FALSE, FALSE, $self->borderPixels);
27714 $cancelButton->get_child->set_width_chars(10);
27715 $cancelButton->signal_connect('clicked' => sub {
27716  
27717 $self->buttonCancel();
27718 });
27719 $cancelButton->set_tooltip_text('Cancel changes and close this window');
27720  
27721 return ($nextButton, $prevButton, $cancelButton);
27722 }
27723  
27724 sub setupGrid {
27725  
27726 # Called by $self->winEnable
27727 # Creates the first page for the wizard (not really necessary to have a whole function
27728 # dedicated to this task, but having one keeps the design of 'wiz' windows consistent
27729 # with the design of 'edit'/'pref' windows)
27730 #
27731 # Expected arguments
27732 # (none besides $self)
27733 #
27734 # Return values
27735 # 'undef' on improper arguments
27736 # 1 otherwise
27737  
27738 my ($self, $check) = @_;
27739  
27740 # Local variables
27741 my ($func, $rows);
27742  
27743 # Check for improper arguments
27744 if (defined $check) {
27745  
27746 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupGrid', @_);
27747 }
27748  
27749 # Get the name of the function for the first page
27750 $func = $self->ivIndex('pageList', $self->currentPage) . 'Page';
27751 # Call the function
27752 $rows = $self->$func();
27753  
27754 return 1;
27755 }
27756  
27757 sub updateGrid {
27758  
27759 # Called by $self->buttonPrevious and ->buttonNext
27760 # Changes the page currently visible in the 'wiz' window
27761 #
27762 # Expected arguments
27763 # (none besides $self)
27764 #
27765 # Return values
27766 # 'undef' on improper arguments
27767 # 1 otherwise
27768  
27769 my ($self, $check) = @_;
27770  
27771 # Local variables
27772 my ($func, $rows);
27773  
27774 # Check for improper arguments
27775 if (defined $check) {
27776  
27777 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGrid', @_);
27778 }
27779  
27780 # Empty the grid used for the existing page
27781 foreach my $widget ($self->grid->get_children()) {
27782  
27783 $axmud::CLIENT->desktopObj->removeWidget($self->grid, $widget);
27784 }
27785  
27786 # Get the name of the function for the new current page
27787 $func = $self->ivIndex('pageList', $self->currentPage) . 'Page';
27788 # Call the function
27789 $rows = $self->$func();
27790  
27791 # Set button sensititives ($self->disableNextButtonFlag, etc, override the usual rules, if
27792 # they are set)
27793  
27794 # If it's the first page, the 'Previous' button must not be sensitive
27795 if ($self->currentPage == 0) {
27796  
27797 $self->previousButton->set_sensitive(FALSE);
27798  
27799 if (! $self->disableNextButtonFlag) {
27800 $self->nextButton->set_sensitive(TRUE);
27801 } else {
27802 $self->nextButton->set_sensitive(FALSE);
27803 }
27804  
27805 # Make sure the 'Next' button has the right label
27806 $self->nextButton->set_label('Next');
27807 $self->nextButton->get_child->set_width_chars(10);
27808  
27809 # If it's the last page, the 'Next' button must be converted to a 'Finish' button
27810 } elsif ($self->currentPage >= ((scalar $self->pageList) - 1)) {
27811  
27812 if (! $self->disablePreviousButtonFlag) {
27813 $self->previousButton->set_sensitive(TRUE);
27814 } else {
27815 $self->previousButton->set_sensitive(FALSE);
27816 }
27817  
27818 $self->nextButton->set_sensitive(TRUE);
27819 $self->nextButton->set_label('Finish');
27820 $self->nextButton->get_child->set_width_chars(10);
27821  
27822 # For all other pages, both buttons are sensitised
27823 } else {
27824  
27825 if (! $self->disableNextButtonFlag) {
27826 $self->nextButton->set_sensitive(TRUE);
27827 } else {
27828 $self->nextButton->set_sensitive(FALSE);
27829 }
27830  
27831 if (! $self->disablePreviousButtonFlag) {
27832 $self->previousButton->set_sensitive(TRUE);
27833 } else {
27834 $self->previousButton->set_sensitive(FALSE);
27835 }
27836  
27837 # Make sure the 'Next' button has the right label
27838 $self->nextButton->set_label('Next');
27839 $self->nextButton->get_child->set_width_chars(10);
27840 }
27841  
27842 # Reset the disable flags. It's up to individual pages to set them, when they're needed
27843 $self->ivPoke('disableNextButtonFlag', FALSE);
27844 $self->ivPoke('disablePreviousButtonFlag', FALSE);
27845 $self->ivPoke('disableCancelButtonFlag', FALSE);
27846  
27847 # Make sure the window has scrolled to the top
27848 $self->hAdjustment->set_value(0);
27849 $self->vAdjustment->set_value(0);
27850  
27851 # Make the page visible
27852 $self->winShowAll($self->_objClass . '->updateGrid');
27853  
27854 return 1;
27855 }
27856  
27857 sub saveChanges {
27858  
27859 # Generic ->saveChanges function which doesn't do anything other than to close the 'wiz'
27860 # window
27861 # Each 'wiz' window should have its own ->saveChanges function
27862 #
27863 # Expected arguments
27864 # (none besides $self)
27865 #
27866 # Return values
27867 # 'undef' on improper arguments
27868 # 1 otherwise
27869  
27870 my ($self, $check) = @_;
27871  
27872 # Check for improper arguments
27873 if (defined $check) {
27874  
27875 return $axmud::CLIENT->writeImproper($self->_objClass . '->saveChanges', @_);
27876 }
27877  
27878 # Close the 'wiz' window
27879 $self->winDestroy();
27880  
27881 return 1;
27882 }
27883  
27884 sub getPageString {
27885  
27886 # Can be called by any ->XXXPage function
27887 # Returns a string in the format 'page a/b', where 'a' is the number of the current page,
27888 # and 'b' the number of the last page
27889 #
27890 # Expected arguments
27891 # (none besides $self)
27892 #
27893 # Return values
27894 # 'undef' on improper arguments
27895 # 1 otherwise
27896  
27897 my ($self, $check) = @_;
27898  
27899 # Check for improper arguments
27900 if (defined $check) {
27901  
27902 return $axmud::CLIENT->writeImproper($self->_objClass . '->getPageString', @_);
27903 }
27904  
27905 return 'Page ' . ($self->currentPage + 1) . '/' . (scalar $self->pageList);
27906 }
27907  
27908 # Standard callbacks
27909  
27910 sub buttonCancel {
27911  
27912 # 'Cancel' button callback
27913 #
27914 # Expected arguments
27915 # (none besides $self)
27916 #
27917 # Return values
27918 # 'undef' on improper arguments
27919 # 1 otherwise
27920  
27921 my ($self, $check) = @_;
27922  
27923 # Check for improper arguments
27924 if (defined $check) {
27925  
27926 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonCancel', @_);
27927 }
27928  
27929 # Close the window
27930 $self->winDestroy();
27931  
27932 return 1;
27933 }
27934  
27935 sub buttonPrevious {
27936  
27937 # 'Previous' button callback
27938 #
27939 # Expected arguments
27940 # (none besides $self)
27941 #
27942 # Return values
27943 # 'undef' on improper arguments
27944 # 1 otherwise
27945  
27946 my ($self, $check) = @_;
27947  
27948 # Check for improper arguments
27949 if (defined $check) {
27950  
27951 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonPrevious', @_);
27952 }
27953  
27954 # Reset the hash of functions to call when a child window is closed, ready for it to be
27955 # refilled
27956 $self->ivEmpty('childDestroyHash');
27957  
27958 # Has a special rule been set for the current page?
27959 if ($self->ivExists('specialPreviousButtonHash', $self->currentPage)) {
27960  
27961 # Go to the specified page, instead of the next one
27962 $self->ivPoke(
27963 'currentPage',
27964 $self->ivShow('specialPreviousButtonHash', $self->currentPage),
27965 );
27966  
27967 } elsif ($self->currentPage > 0) {
27968  
27969 # Just go to the previous page (unless, for some unlikely reason, we're already there)
27970 $self->ivDecrement('currentPage');
27971 }
27972  
27973 # Cancel any special rules - it's up to the new page to set them, as and when required
27974 $self->ivEmpty('specialNextButtonHash');
27975 $self->ivEmpty('specialPreviousButtonHash');
27976  
27977 # Display the page
27978 $self->updateGrid();
27979  
27980 return 1;
27981 }
27982  
27983 sub buttonNext {
27984  
27985 # 'Next' button callback
27986 #
27987 # Expected arguments
27988 # (none besides $self)
27989 #
27990 # Return values
27991 # 'undef' on improper arguments
27992 # 1 otherwise
27993  
27994 my ($self, $check) = @_;
27995  
27996 # Check for improper arguments
27997 if (defined $check) {
27998  
27999 return $axmud::CLIENT->writeImproper($self->_objClass . '->buttonNext', @_);
28000 }
28001  
28002 # If we're on the last page, the 'Finish' button has been clicked
28003 if ($self->currentPage >= ((scalar $self->pageList) - 1)) {
28004  
28005 $self->saveChanges();
28006  
28007 # Otherwise, it's the 'Next' button. Set the next page
28008 } else {
28009  
28010 # Reset the hash of functions to call when a child window is closed, ready for it to be
28011 # refilled
28012 $self->ivEmpty('childDestroyHash');
28013  
28014 # Has a special rule been set for the current page?
28015 if ($self->ivExists('specialNextButtonHash', $self->currentPage)) {
28016  
28017 # Go to the specified page, instead of the next one
28018 $self->ivPoke(
28019 'currentPage',
28020 $self->ivShow('specialNextButtonHash', $self->currentPage),
28021 );
28022  
28023 } else {
28024  
28025 # Just go to the next page
28026 $self->ivIncrement('currentPage');
28027 }
28028  
28029 # Cancel any special rules - it's up to the new page to set them, as and when required
28030 $self->ivEmpty('specialNextButtonHash');
28031 $self->ivEmpty('specialPreviousButtonHash');
28032  
28033 # Display the page
28034 $self->updateGrid();
28035 }
28036  
28037 return 1;
28038 }
28039  
28040 ##################
28041 # Accessors - set
28042  
28043 ##################
28044 # Accessors - get
28045  
28046 sub scroller
28047 { $_[0]->{scroller} }
28048 sub hAdjustment
28049 { $_[0]->{hAdjustment} }
28050 sub vAdjustment
28051 { $_[0]->{vAdjustment} }
28052 sub grid
28053 { $_[0]->{grid} }
28054 sub hBox
28055 { $_[0]->{hBox} }
28056 sub nextButton
28057 { $_[0]->{nextButton} }
28058 sub previousButton
28059 { $_[0]->{previousButton} }
28060 sub cancelButton
28061 { $_[0]->{cancelButton} }
28062  
28063 sub disableNextButtonFlag
28064 { $_[0]->{disableNextButtonFlag} }
28065 sub disablePreviousButtonFlag
28066 { $_[0]->{disablePreviousButtonFlag} }
28067 sub disableCancelButtonFlag
28068 { $_[0]->{disableCancelButtonFlag} }
28069  
28070 sub pageList
28071 { my $self = shift; return @{$self->{pageList}}; }
28072 sub currentPage
28073 { $_[0]->{currentPage} }
28074  
28075 sub specialNextButtonHash
28076 { my $self = shift; return %{$self->{specialNextButtonHash}}; }
28077 sub specialPreviousButtonHash
28078 { my $self = shift; return %{$self->{specialPreviousButtonHash}}; }
28079 }
28080  
28081 # Package must return a true value
28082 1